Browse Source

Return the exit code from the waited process

develop
Damien Goutte-Gattat 9 years ago
parent
commit
2d32e1dd9b
  1. 6
      src/wait4.c
  2. 7
      src/wait4pid.c

6
src/wait4.c

@ -82,7 +82,7 @@ get_integer_or_die(const char *arg)
int
main(int argc, char **argv)
{
int c, pid;
int c, pid, ec;
struct option options[] = {
{ "help", 0, NULL, 'h' },
@ -113,8 +113,8 @@ main(int argc, char **argv)
pid = get_integer_or_die(argv[optind]);
if ( wait4pid(pid) == -1 )
if ( (ec = wait4pid(pid)) == -1 )
err(EXIT_FAILURE, "cannot wait for process %d", pid);
return EXIT_SUCCESS;
return ec;
}

7
src/wait4pid.c

@ -98,6 +98,7 @@ wait4pid_init(void)
int
wait4pid(pid_t pid)
{
int ec;
struct __attribute__ ((__packed__)) payload_t {
struct cn_msg msg;
struct proc_event evt;
@ -110,9 +111,11 @@ wait4pid(pid_t pid)
while ( recv(sock, buf, sizeof(buf), 0) > 0 ) {
payload = (struct payload_t *) NLMSG_DATA(buf);
if ( payload->evt.what == PROC_EVENT_EXIT
&& payload->evt.event_data.exit.process_pid == pid )
&& payload->evt.event_data.exit.process_pid == pid ) {
ec = payload->evt.event_data.exit.exit_code / 256;
break;
}
}
return 0;
return ec;
}

Loading…
Cancel
Save