public inbox for gentoo-proxy-maint@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-proxy-maint] Checking before reinventing wheel: init script not waiting for child processes
@ 2016-06-01 20:02 Philippe Chaintreuil
  2016-06-02  7:02 ` Sam Jorna
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Chaintreuil @ 2016-06-01 20:02 UTC (permalink / raw
  To: gentoo-proxy-maint

Hello,

     I'm looking at a bug [1] that is complaining that an init script 
doesn't wait for the child processes of the daemon to exit before it 
returns.

     I just wanted to make sure that there's not a standard/existing 
methodology that does this before I start adding custom code.
     I guess I should also make sure that this isn't something the 
hive-mind thinks should be punted upstream.  (I've looked at the source 
code, and the interrupt handler just loops through the child pids and 
exits, it doesn't wait on the pids.)

     My plan of attack is (pseudo code):

=========================================================
# Grab PIDs before we kill off the daemon
child_pids = $(pgrep -p ${PIDFILE})
# terminate daemon
start-stop-daemon [...]
# Loop until all done, check once a second
tries = 30
keep_waiting = 1
while [ ${tries} > 30 && ${keep_waiting} ] ; do
    # Can't kill all pids in one call because kill -0
    # returns 1 if any of the pids have exited.
    keep_waiting = 0
    for child_pid in ${child_pids} ; do
       # ping to see if the pid is still around
       # will return 0 if pid is still around
       kill -0 ${child_pid}
       if $? eq 0 ; then
          keep_waiting = 1
          break
       fi
    done

    if [ ${keep_waiting} ]; then
       sleep 1
    fi
done
if [ ${keep_waiting} ] ; then
    # Output warning that child pids are still on the loose.
fi
=========================================================

     Feel free to suggest better methods/tweaks.

     Thanks for the guidance.

             -- Philippe "Peep" Chaintreuil


[1] https://bugs.gentoo.org/show_bug.cgi?id=322025


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-06-02 12:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-01 20:02 [gentoo-proxy-maint] Checking before reinventing wheel: init script not waiting for child processes Philippe Chaintreuil
2016-06-02  7:02 ` Sam Jorna
2016-06-02 12:09   ` Philippe Chaintreuil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox