prehor / amavisd-milter

Milter interface for the amavis spam filter engine.
BSD 3-Clause "New" or "Revised" License
8 stars 4 forks source link

Fork after initializing milter socket #2

Closed prehor closed 5 years ago

prehor commented 5 years ago

Moved from amavisd-milter-users mailing list.

From: Matus UHLAR - fantomas uhlar@fa... - 2019-01-04 14:45:07

On 04.01.19 15:29, Matus UHLAR - fantomas wrote:

amavisd-milter 1.6.1 does daemonize, and opens milter socket after that, exiting if it returns error

We want to change the socket permissions after daemon is started, and this order of commands makes it problematic, e.g. debian bug 854180 (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=854180)

the daemon() should be called after calling smfi_opensocket().

This would also make possible to return error in case of impossibility to create socket, so the caller knows it failed.

this patch moves the daemonising section after opening socket. I have tried with amavisd-milter 1.6.1 and 1.5.0, works nicely.

you can find it at test.fantomas.sk/amavisd-milter-main.c.patch

--- main.c.orig 2013-04-22 02:36:12.000000000 +0200
+++ main.c  2019-01-04 15:35:29.486854008 +0100
@@ -379,17 +379,6 @@
    }
     }

-    /* Run in the background */
-    if (daemonize) {
-   if (daemon(1, 1) != -1) {
-       daemonized = 1;
-   } else {
-       logmsg(LOG_ERR, "could not fork daemon process: %s",
-       strerror(errno));
-       exit(EX_OSERR);
-   }
-    }
-
     /* Connect to milter socket */
 #ifdef HAVE_SMFI_SETBACKLOG
     if (mlfi_socket_backlog > 0) {
@@ -406,6 +395,17 @@
     }
 #endif

+    /* Run in the background */
+    if (daemonize) {
+   if (daemon(1, 1) != -1) {
+       daemonized = 1;
+   } else {
+       logmsg(LOG_ERR, "could not fork daemon process: %s",
+       strerror(errno));
+       exit(EX_OSERR);
+   }
+    }
+
     /* Greetings message */
     logmsg(LOG_WARNING, "starting %s %s on socket %s", progname, VERSION,
    mlfi_socket);

-- Matus UHLAR - fantomas, uhlar@... ; http://www.fantomas.sk/ Warning: I wish NOT to receive e-mail advertising to this address. Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu. If Barbie is so popular, why do you have to buy her friends?