Browse Source

Verify initial existence of target processes

In Netlink mode, if a target process does not exist, we end up
waiting indefinitely for it.  To avoid that, try sending a nul
signal to the target process(es) before actually waiting for
Netlink proc events.
develop
Damien Goutte-Gattat 8 years ago
parent
commit
486b4371fc
  1. 13
      src/wait4pid.c

13
src/wait4pid.c

@ -24,6 +24,7 @@
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <sys/socket.h>
#include <linux/netlink.h>
#include <linux/connector.h>
@ -124,6 +125,9 @@ wait4pid(pid_t pid)
if ( ! listener_set && wait4pid_init() == -1 )
return -1;
if ( kill(pid, 0) == -1 && errno == ESRCH )
return -1;
while ( do_recv(sock, buf, sizeof(buf), 0) > 0 ) {
payload = (struct cn_proc_msg *) NLMSG_DATA(buf);
if ( payload->evt.what == PROC_EVENT_EXIT
@ -139,17 +143,20 @@ wait4pid(pid_t pid)
int
wait4all(pid_t *pids, size_t len)
{
int ec, nproc;
int ec, nproc, i;
struct cn_proc_msg *payload;
char buf[NLMSG_SPACE(sizeof(struct cn_proc_msg))];
if ( ! listener_set && wait4pid_init() == -1 )
return -1;
for ( i = 0; i < len; i++ ) {
if ( kill(pids[i], 0) == -1 && errno == ESRCH )
return -1;
}
nproc = len;
while ( nproc > 0 ) {
int i;
if ( do_recv(sock, buf, sizeof(buf), 0) <= 0 )
return -1;

Loading…
Cancel
Save