Browse Source

Add do_recv helper function

This function takes care of recalling recv if it fails because
the call has been interrupted.
develop
Damien Goutte-Gattat 9 years ago
parent
commit
6da91e34f3
  1. 31
      src/wait4pid.c

31
src/wait4pid.c

@ -102,6 +102,18 @@ struct __attribute__ ((__packed__)) cn_proc_msg {
struct proc_event evt;
};
static int
do_recv(int sock, void *buf, size_t len, int flags)
{
int ret;
do {
ret = recv(sock, buf, len, flags);
} while ( ret == -1 && errno == EINTR );
return ret;
}
int
wait4pid(pid_t pid)
{
@ -112,14 +124,7 @@ wait4pid(pid_t pid)
if ( ! listener_set && wait4pid_init() == -1 )
return -1;
while ( 1 ) {
if ( (ec = recv(sock, buf, sizeof(buf), 0)) <= 0 ) {
if ( ec == -1 && errno == EINTR )
continue;
else
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
&& payload->evt.event_data.exit.process_pid == pid ) {
@ -143,14 +148,10 @@ wait4all(pid_t *pids, size_t len)
nproc = len;
while ( nproc > 0 ) {
int ret, i;
int i;
if ( (ret = recv(sock, buf, sizeof(buf), 0)) <= 0 ) {
if ( ret == -1 && errno == EINTR )
continue;
else
return -1;
}
if ( do_recv(sock, buf, sizeof(buf), 0) <= 0 )
return -1;
payload = (struct cn_proc_msg *) NLMSG_DATA(buf);
if ( payload->evt.what != PROC_EVENT_EXIT )

Loading…
Cancel
Save