summaryrefslogtreecommitdiffstats
path: root/debian/patches/75_22-Fix-daemon-startup.-Bug-2930.patch
blob: 2a3434f8b0b17716cb2dc1ae5eadbc1570b48be4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
From 221321d2c51b83d1feced80ecd6c2fe33ec5456c Mon Sep 17 00:00:00 2001
From: Jeremy Harris <jgh146exb@wizmail.org>
Date: Thu, 3 Nov 2022 20:08:25 +0000
Subject: [PATCH 1/2] Fix daemon startup.  Bug 2930

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

--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -16,10 +16,14 @@
       Find and fix by Jasen Betts.
 
 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
 -----------------
 
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -1744,19 +1744,23 @@
   {
   /* If the parent process of this one has pid == 1, we are re-initializing the
   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;
     }
   }
 
 /* We are now in the disconnected, daemon process (unless debugging). Set up
 the listening sockets if required. */
@@ -2090,11 +2094,11 @@
 	      {				/* found; append port to list */
 	      for (p = i2->log; *p; ) p++;	/* end of existing string */
 	      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);
 	      ipa->log = NULL;
 	      break;