[exim-cvs] Fix daemon startup. Bug 2930

Inizio della pagina
Delete this message
Reply to this message
Autore: Exim Git Commits Mailing List
Data:  
To: exim-cvs
Oggetto: [exim-cvs] Fix daemon startup. Bug 2930
Gitweb: https://git.exim.org/exim.git/commitdiff/221321d2c51b83d1feced80ecd6c2fe33ec5456c
Commit:     221321d2c51b83d1feced80ecd6c2fe33ec5456c
Parent:     faf3b3fa5ec908ec8bce570fb8b2b4c3864ec035
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Thu Nov 3 20:08:25 2022 +0000
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Thu Nov 3 21:10:58 2022 +0000


    Fix daemon startup.  Bug 2930


    Broken-by: 7d5055276a
---
 doc/doc-txt/ChangeLog | 4 ++++
 src/src/daemon.c      | 8 ++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)


diff --git a/doc/doc-txt/ChangeLog b/doc/doc-txt/ChangeLog
index 2ca0f7e00..3942e25f0 100644
--- a/doc/doc-txt/ChangeLog
+++ b/doc/doc-txt/ChangeLog
@@ -50,6 +50,10 @@ JH/11 OpenSSL: fix for ancient clients needing TLS support for versions earlier
 HS/01 Bug 2728: Introduce EDITME option "DMARC_API" to work around incompatible
       API changes in libopendmarc.


+JH/12 Bug 2930: Fix daemon startup.  When started from any process apart from
+      pid 1, in the normal "background daemon" mode, having to drop process-
+      group leadership also lost track of needing to create listener sockets.
+


Exim version 4.96
-----------------
diff --git a/src/src/daemon.c b/src/src/daemon.c
index 54725e07d..8446f81cb 100644
--- a/src/src/daemon.c
+++ b/src/src/daemon.c
@@ -1776,15 +1776,19 @@ if (f.background_daemon)
daemon as the result of a SIGHUP. In this case, there is no need to do
anything, because the controlling terminal has long gone. Otherwise, fork, in
case current process is a process group leader (see 'man setsid' for an
- explanation) before calling setsid(). */
+ explanation) before calling setsid().
+ All other forks want daemon_listen cleared. Rather than blow a register, jsut
+ restore it here. */

   if (getppid() != 1)
     {
+    BOOL daemon_listen = f.daemon_listen;
     pid_t pid = exim_fork(US"daemon");
     if (pid < 0) log_write(0, LOG_MAIN|LOG_PANIC_DIE,
       "fork() failed when starting daemon: %s", strerror(errno));
     if (pid > 0) exit(EXIT_SUCCESS);      /* in parent process, just exit */
     (void)setsid();                       /* release controlling terminal */
+    f.daemon_listen = daemon_listen;
     }
   }


@@ -2122,7 +2126,7 @@ else if (f.daemon_listen)
           if (*--p == '}') *p = '\0';    /* drop EOL */
           while (isdigit(*--p)) ;        /* char before port */


-          i2->log = *p == ':'        /* no list yet? */
+          i2->log = *p == ':'        /* no list yet?     { */
         ? string_sprintf("%.*s{%s,%d}",
           (int)(p - i2->log + 1), i2->log, p+1, ipa->port)
         : string_sprintf("%s,%d}", i2->log, ipa->port);