[projects/rc-scripts] fix daemon --fork uses
glen
glen at pld-linux.org
Thu Dec 10 21:30:18 CET 2015
commit 7f7f7c7dbb36bfa3f7f84e60854cd0f334ff4296
Author: Krzysztof Mazur <krzysiek at podlesie.net>
Date: Thu Nov 26 09:21:44 2015 +0100
fix daemon --fork uses
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 | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
---
diff --git a/lib/functions b/lib/functions
index 501cac9..f9538d2 100644
--- a/lib/functions
+++ b/lib/functions
@@ -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
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/rc-scripts.git/commitdiff/7f7f7c7dbb36bfa3f7f84e60854cd0f334ff4296
More information about the pld-cvs-commit
mailing list