-/*
- Check a child (the pointer data is actually an integer, the PID of
- that child. A non-zero return value means that the child has exited
- and can be removed from our list.
-*/
-int check_child(void *data)
-{
- pid_t pid;
- int status;
-cp
- pid = (pid_t) data;
- pid = waitpid(pid, &status, WNOHANG);
- if(WIFEXITED(status))
- {
- if(WIFSIGNALED(status)) /* Child was killed by a signal */
- {
- syslog(LOG_ERR, _("Child with PID %d was killed by signal %d (%s)"),
- pid, WTERMSIG(status), strsignal(WTERMSIG(status)));
- return -1;
- }
- if(WEXITSTATUS(status) != 0)
- {
- syslog(LOG_INFO, _("Child with PID %d exited with code %d"),
- WEXITSTATUS(status));
- }
- return -1;
+ if(waitpid(pid, &status, 0) == pid)
+ {
+ if(WIFEXITED(status)) /* Child exited by itself */
+ {
+ if(WEXITSTATUS(status))
+ {
+ syslog(LOG_ERR, _("Process %d (%s) exited with non-zero status %d"), pid, name, WEXITSTATUS(status));
+ return -1;
+ }
+ else
+ return 0;
+ }
+ else if(WIFSIGNALED(status)) /* Child was killed by a signal */
+ {
+ syslog(LOG_ERR, _("Process %d (%s) was killed by signal %d (%s)"),
+ pid, name, WTERMSIG(status), strsignal(WTERMSIG(status)));
+ return -1;
+ }
+ else /* Something strange happened */
+ {
+ syslog(LOG_ERR, _("Process %d (%s) terminated abnormaly"), pid, name);
+ return -1;
+ }
+ }
+ else
+ {
+ syslog(LOG_ERR, _("System call `%s' failed: %m"), "waitpid");
+ return -1;
+ }