Re: [PATCH] Replace freopen with open/dup2 when daemonizing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Chrissie,
there is small typo in comment, but when fixed, it's ACK.

Honza

Christine Caulfield napsal(a):
> This patch replaces the existing freopen method of
> forcing stdin/out/err to /dev/null with the more
> usual system of open/dup2.
> 
> While I don' tlike posting patches I don't understand,
             ^^^ TYPO

> this patch seems to fix a problem where stdout/err get
> assigned to system causing double logging output
> on systemd.
> 
> Signed-off-by: Christine Caulfield <ccaulfie@xxxxxxxxxx>
> ---
>  exec/main.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/exec/main.c b/exec/main.c
> index 370dfc8..d8ad94d 100644
> --- a/exec/main.c
> +++ b/exec/main.c
> @@ -398,7 +398,7 @@ static void priv_drop (void)
>  
>  static void corosync_tty_detach (void)
>  {
> -	FILE *r;
> +	int devnull;
>  
>  	/*
>  	 * Disconnect from TTY if this is not a debug run
> @@ -424,16 +424,13 @@ static void corosync_tty_detach (void)
>  	/*
>  	 * Map stdin/out/err to /dev/null.
>  	 */
> -	r = freopen("/dev/null", "r", stdin);
> -	if (r == NULL) {
> +	devnull = open("/dev/null", O_RDWR);
> +	if (devnull == -1) {
>  		corosync_exit_error (COROSYNC_DONE_STD_TO_NULL_REDIR);
>  	}
> -	r = freopen("/dev/null", "a", stderr);
> -	if (r == NULL) {
> -		corosync_exit_error (COROSYNC_DONE_STD_TO_NULL_REDIR);
> -	}
> -	r = freopen("/dev/null", "a", stdout);
> -	if (r == NULL) {
> +
> +	if (dup2(devnull, 0) < 0 || dup2(devnull, 1) < 0
> +	    || dup2(devnull, 2) < 0) {
>  		corosync_exit_error (COROSYNC_DONE_STD_TO_NULL_REDIR);
>  	}
>  }
> 

_______________________________________________
discuss mailing list
discuss@xxxxxxxxxxxx
http://lists.corosync.org/mailman/listinfo/discuss




[Index of Archives]     [Linux Clusters]     [Corosync Project]     [Linux USB Devel]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Linux Kernel]     [Linux SCSI]     [X.Org]

  Powered by Linux