]> git.pld-linux.org Git - projects/rc-scripts.git/commitdiff
fix daemon --fork uses
authorKrzysztof Mazur <krzysiek@podlesie.net>
Thu, 26 Nov 2015 08:21:44 +0000 (09:21 +0100)
committerElan Ruusamäe <glen@delfi.ee>
Thu, 10 Dec 2015 20:24:19 +0000 (22:24 +0200)
Recent rewrite of the daemon function (the commit
8714ffa414c8f182efa0bddf96486d99b89651bd: "daemon: rewrite $@ to
modify command, use runuser instead of su) broke support for --fork
without --makepid. Previously shells's '&' have been used to fork a new
process. Now the '&' is dropped. The --fork uses setsid to run a program
in a new session.  The setsid forks only if the current process is a
group leader (the progess group is equal to the process pid), which is
not true. As a result the new process is not forked and initlog waits
for deamon to stop (infinitely).  With --makepid everything works because
the makepid helper performs fork (using shell's '&').

Because the --makepid implies --fork, fix it by always using makepid
helper when --fork is used, and use /dev/null as pid file if --makepid
is not used.

---
Hi Elan,

I've just found another bug in rc-scripts after recent updates. The
"/etc/init.d/vsftpd start" stopped working. The initlog (PID 19735)
just forks, and starts a /usr/bin/setsid, which just execs to vsftpd
(without fork), and the initlog infinitely waits for vsftpd stop die:

[pid 19735] clone(child_stack=0, [...]) = 19736
[...]
[pid 19736] execve("/usr/bin/setsid", ["/usr/bin/setsid", "/usr/sbin/vsftpd"], [/* 25 vars */]) = 0
[...]
[pid 19736] getpgrp()                   = 19638
[pid 19736] getpid()                    = 19736
[pid 19736] setsid()                    = 19736
[pid 19736] execve("/usr/sbin/vsftpd", ["/usr/sbin/vsftpd"], [/* 25 vars */]) = 0
[...]
[pid 19735] wait4(19736, 0x7ffe0fd2c638, WNOHANG, NULL) = 0
[pid 19735] nanosleep({0, 500000}, NULL) = 0
[pid 19735] poll([{fd=3, events=POLLIN|POLLPRI}, {fd=5, events=POLLIN|POLLPRI}], 2, 500) = 0 (Timeout)
[pid 19735] wait4(19736, 0x7ffe0fd2c638, WNOHANG, NULL) = 0

Best regards,
Krzysiek

lib/functions

index 501cac9fc1e5e34cac1a5ff62c19f6f3536a4955..f9538d2401202c6f6c9fd1430695a88a1482028e 100644 (file)
@@ -690,13 +690,12 @@ _daemon_exec() {
                        --exec "$prog" \
                        -- "$@"
        else
-
-               if [ "$makepid" ] && [ "$pidfile" ]; then
-                       export PIDFILE="$pidfile"
-                       set -- /lib/rc-scripts/makepid "$@"
-               fi
-
                if [ "$fork" = "1" ]; then
+                       export PIDFILE="/dev/null"
+                       if [ "$makepid" ] && [ "$pidfile" ]; then
+                               export PIDFILE="$pidfile"
+                       fi
+                       set -- /lib/rc-scripts/makepid "$@"
                        set -- /usr/bin/setsid "$@"
                fi
                if [ -n "$user" -a "$user" != "root" ]; then
This page took 0.230796 seconds and 4 git commands to generate.