Browse Source

Merge branch 'feature/kevent' into develop

develop
Damien Goutte-Gattat 8 years ago
parent
commit
3459884247
  1. 2
      configure.ac
  2. 44
      src/wait4pid.c

2
configure.ac

@ -22,6 +22,8 @@ dnl Check for possible mechanism, default is kill
backend="kill"
AC_CHECK_HEADERS([linux/netlink.h],
[backend=Netlink])
AC_CHECK_HEADERS([sys/event.h],
[backend=Kevent])
AM_CONDITIONAL([HAVE_NETLINK], [test x$ac_cv_header_linux_netlink_h = xyes])
AC_CHECK_HEADERS([linux/filter.h])

44
src/wait4pid.c

@ -20,7 +20,7 @@
#include <config.h>
#endif
#ifdef HAVE_LINUX_NETLINK_H
#if defined HAVE_LINUX_NETLINK_H /* Netlink */
#include <string.h>
#include <unistd.h>
@ -241,7 +241,45 @@ wait4all(pid_t *pids, size_t len)
return ec;
}
#else /* HAVE_LINUX_NETLINK_H */
#elif defined HAVE_SYS_EVENT_H /* BSD Kevent */
#include <sys/event.h>
#include <xmem.h>
int
wait4all(pid_t *pids, size_t len)
{
int fd, i, nproc, ec;
struct kevent *evts, evt;
if ( (fd = kqueue()) == -1 )
return -1;
evts = xmalloc(sizeof(struct kevent) * len);
for ( i = 0; i < len; i++ ) {
EV_SET(evts[i], pids[i], EVFILT_PROC, EV_ENABLE, NOTE_EXIT, 0, 0):
}
i = kevent(fd, evts, len, NULL, 0, 0);
free(evts);
if ( i == -1 )
return -1;
nproc = len;
ec = 0;
while ( nproc > 0 ) {
if ( kevent(fd, NULL, 0, &evt, 1, 0) <= 0 )
return -1;
if ( evt->ident == pids[len - 1] )
ec = evt->data;
nproc -= 1;
}
return ec;
}
#else /* Fallback */
#include <time.h>
#include <signal.h>
@ -270,4 +308,4 @@ wait4all(pid_t *pids, size_t len)
return 0;
}
#endif /* ! HAVE_LINUX_NETLINK_H */
#endif
Loading…
Cancel
Save