1 |
Hello, |
2 |
|
3 |
I'm looking at a bug [1] that is complaining that an init script |
4 |
doesn't wait for the child processes of the daemon to exit before it |
5 |
returns. |
6 |
|
7 |
I just wanted to make sure that there's not a standard/existing |
8 |
methodology that does this before I start adding custom code. |
9 |
I guess I should also make sure that this isn't something the |
10 |
hive-mind thinks should be punted upstream. (I've looked at the source |
11 |
code, and the interrupt handler just loops through the child pids and |
12 |
exits, it doesn't wait on the pids.) |
13 |
|
14 |
My plan of attack is (pseudo code): |
15 |
|
16 |
========================================================= |
17 |
# Grab PIDs before we kill off the daemon |
18 |
child_pids = $(pgrep -p ${PIDFILE}) |
19 |
# terminate daemon |
20 |
start-stop-daemon [...] |
21 |
# Loop until all done, check once a second |
22 |
tries = 30 |
23 |
keep_waiting = 1 |
24 |
while [ ${tries} > 30 && ${keep_waiting} ] ; do |
25 |
# Can't kill all pids in one call because kill -0 |
26 |
# returns 1 if any of the pids have exited. |
27 |
keep_waiting = 0 |
28 |
for child_pid in ${child_pids} ; do |
29 |
# ping to see if the pid is still around |
30 |
# will return 0 if pid is still around |
31 |
kill -0 ${child_pid} |
32 |
if $? eq 0 ; then |
33 |
keep_waiting = 1 |
34 |
break |
35 |
fi |
36 |
done |
37 |
|
38 |
if [ ${keep_waiting} ]; then |
39 |
sleep 1 |
40 |
fi |
41 |
done |
42 |
if [ ${keep_waiting} ] ; then |
43 |
# Output warning that child pids are still on the loose. |
44 |
fi |
45 |
========================================================= |
46 |
|
47 |
Feel free to suggest better methods/tweaks. |
48 |
|
49 |
Thanks for the guidance. |
50 |
|
51 |
-- Philippe "Peep" Chaintreuil |
52 |
|
53 |
|
54 |
[1] https://bugs.gentoo.org/show_bug.cgi?id=322025 |