www.nico.schottelius.org/software/cinit/browse_source/cinit-0.3pre2/serv/sig_child.c
Nico Schottelius 423ba10303 import cinit from unix.schottelius.org
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-09-16 12:53:45 +02:00

35 lines
828 B
C

/* cinit
* (c) 2005 Nico Schottelius (nico-linux-cinit at schottelius.org)
* We are called, when a child dies. Remove it.
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include "cinit.h"
/***********************************************************************
* sig_child
* collect the children
* FIXME: check whether we've race conditions when reciieving multiiple
* signals
* Perhaps disable listening to sig_child in meantime?
*/
void sig_child(int tmp)
{
struct listitem *svc;
do {
/* check if it's a watched child */
tmp = waitpid(-1, &tmp, WNOHANG);
/* restart service, if we are watching it */
svc = list_search_pid((pid_t) tmp);
if( svc != NULL ) {
svc->pid = exec_svc(svc->abs_path, CMD_START_SVC);
}
} while( tmp > 0);
}