From 9c45d9ad13fdf439d44d7443ae75da15ea0223ed Mon Sep 17 00:00:00 2001 From: Sam Varshavchik Date: Mon, 19 Aug 2013 16:39:41 -0400 Subject: Initial checkin Imported from subversion report, converted to git. Updated all paths in scripts and makefiles, reflecting the new directory hierarchy. --- waitlib/waitlib2.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 waitlib/waitlib2.c (limited to 'waitlib/waitlib2.c') diff --git a/waitlib/waitlib2.c b/waitlib/waitlib2.c new file mode 100644 index 0000000..52dfc26 --- /dev/null +++ b/waitlib/waitlib2.c @@ -0,0 +1,114 @@ +/* +** Copyright 2000-2006 Double Precision, Inc. +** See COPYING for distribution information. +*/ + +#include "config.h" +#include "waitlib.h" +#include +#include +#include +#include +#if HAVE_UNISTD_H +#include +#endif + + +static pid_t *static_pid_buf=0; + +static void start_reaper(pid_t pid, int exit_stat) +{ +} + +static RETSIGTYPE start_reap(int signum) +{ + wait_reap(start_reaper, start_reap); + +#if RETSIGTYPE != void + return (0); +#endif +} + +void wait_forchild( void (*)(pid_t, int), /* Reaper */ + RETSIGTYPE (*)(int)); /* Signal handler stub */ + +int wait_startchildren(unsigned nchildren, pid_t **pidptr) +{ +int pipefd[2]; +pid_t p; +unsigned i; + + if (!pidptr) + { + if (static_pid_buf) free(static_pid_buf); + static_pid_buf=0; + pidptr= &static_pid_buf; + } + + if (*pidptr == 0 && (*pidptr=malloc(nchildren * sizeof(pid_t))) == 0) + return (-1); + + if (pipe(pipefd) < 0) return (-1); + + signal(SIGCHLD, start_reap); + wait_block(); + for (i=0; i= nchildren) return (0); + + switch ((pidptr[i]=fork())) { + case 0: + wait_restore(); /* Just in case */ + return (1); + case -1: + return (-1); + default: + break; + } + return (0); +} -- cgit v1.2.3