On Wed, Nov 29, 2017 at 12:05:43AM +0100, PiBa-NL wrote:
> Hi List,
>

Hi Pieter,
 
> Made a patch that makes the master-worker detach from tty when it is 
> also combined with daemon mode to allow a script to start haproxy with 
> daemon mode, closing stdout so the calling process knows when to stop 
> reading from it and allow the master to properly daemonize.
> 

> diff --git a/src/haproxy.c b/src/haproxy.c
> index c3c8281..a811577 100644
> --- a/src/haproxy.c
> +++ b/src/haproxy.c
> @@ -2648,6 +2648,13 @@ int main(int argc, char **argv)
>       }
>  
>       if (global.mode & (MODE_DAEMON | MODE_MWORKER)) {
> +             if ((!(global.mode & MODE_QUIET) || (global.mode & 
> MODE_VERBOSE)) &&
> +                     ((global.mode & (MODE_DAEMON | MODE_MWORKER)) == 
> (MODE_DAEMON | MODE_MWORKER))) {
> +                     /* detach from the tty, this is required to properly 
> daemonize. */
> +                     fclose(stdin); fclose(stdout); fclose(stderr);
> +                     global.mode &= ~MODE_VERBOSE;
> +                     global.mode |= MODE_QUIET; /* ensure that we won't say 
> anything from now */
> +             }
>               struct proxy *px;
>               struct peers *curpeers;
>               int ret = 0;

I need to check that again later, in my opinion it should be done after the
pipe() so we don't inherit the 0 and 1 FDs in the pipe, we also need to rely on
setsid() to do a proper tty detach. This is already done in -D mode without -W, 
maybe
this part of the code should me moved elsewhere, but we have to be careful not
to break the daemon mode w/o mworker.


-- 
William Lallemand

Reply via email to