]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: startup: change session/process group settings
authorWilliam Lallemand <wlallemand@haproxy.com>
Wed, 4 Jul 2018 13:31:23 +0000 (15:31 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 4 Jul 2018 17:29:56 +0000 (19:29 +0200)
Change the way the process groups are set. Indeed setsid() was called
for every processes which caused the worker to have a different process
group than the master.

This patch behave in a better way:

- In daemon mode only, each child do a setsid()
- In master worker + daemon mode, the setsid() is done in the master before
forking the children
- In any foreground mode, we don't do a setsid()

Could be backported in 1.8 but the master-worker mode is mostly used
with systemd which rely on cgroups so that won't affect much people.

src/haproxy.c

index 4101cefa1b29e484f70e7fc85042cefc6eee8fd3..e19d89abfb95a7f57969135873ab54576f1f886e 100644 (file)
@@ -2775,10 +2775,10 @@ int main(int argc, char **argv)
                                ha_alert("[%s.main()] Cannot fork.\n", argv[0]);
                                protocol_unbind_all();
                                exit(1); /* there has been an error */
-                       }
-                       /* parent leave to daemonize */
-                       if (ret > 0)
+                       } else if (ret > 0) { /* parent leave to daemonize */
                                exit(0);
+                       } else /* change the process group ID in the child (master process) */
+                               setsid();
                }
 
                if (global.mode & MODE_MWORKER) {
@@ -2880,7 +2880,6 @@ int main(int argc, char **argv)
 
                                        global.mode &= ~MODE_VERBOSE;
                                        global.mode |= MODE_QUIET; /* ensure that we won't say anything from now */
-                                       setsid();
                                }
 
                                mworker_wait();
@@ -3005,7 +3004,8 @@ int main(int argc, char **argv)
                        global.mode |= MODE_QUIET; /* ensure that we won't say anything from now */
                }
                pid = getpid(); /* update child's pid */
-               setsid();
+               if (!(global.mode & MODE_MWORKER)) /* in mworker mode we don't want a new pgid for the children */
+                       setsid();
                fork_poller();
        }