Browse Source

Factorize struct definition

develop
Damien Goutte-Gattat 8 years ago
parent
commit
32b9bbefe9
  1. 23
      src/wait4pid.c

23
src/wait4pid.c

@ -97,15 +97,17 @@ wait4pid_init(void)
return 0;
}
struct __attribute__ ((__packed__)) cn_proc_msg {
struct cn_msg msg;
struct proc_event evt;
};
int
wait4pid(pid_t pid)
{
int ec;
struct __attribute__ ((__packed__)) payload_t {
struct cn_msg msg;
struct proc_event evt;
} *payload;
char buf[NLMSG_SPACE(sizeof(struct payload_t))];
struct cn_proc_msg *payload;
char buf[NLMSG_SPACE(sizeof(struct cn_proc_msg))];
if ( ! listener_set && wait4pid_init() == -1 )
return -1;
@ -118,7 +120,7 @@ wait4pid(pid_t pid)
return -1;
}
payload = (struct payload_t *) NLMSG_DATA(buf);
payload = (struct cn_proc_msg *) NLMSG_DATA(buf);
if ( payload->evt.what == PROC_EVENT_EXIT
&& payload->evt.event_data.exit.process_pid == pid ) {
ec = payload->evt.event_data.exit.exit_code / 256;
@ -133,11 +135,8 @@ int
wait4all(pid_t *pids, size_t len)
{
int ec, nproc;
struct __attribute__ ((__packed__)) payload_t {
struct cn_msg msg;
struct proc_event evt;
} *payload;
char buf[NLMSG_SPACE(sizeof(struct payload_t))];
struct cn_proc_msg *payload;
char buf[NLMSG_SPACE(sizeof(struct cn_proc_msg))];
if ( ! listener_set && wait4pid_init() == -1 )
return -1;
@ -153,7 +152,7 @@ wait4all(pid_t *pids, size_t len)
return -1;
}
payload = (struct payload_t *) NLMSG_DATA(buf);
payload = (struct cn_proc_msg *) NLMSG_DATA(buf);
if ( payload->evt.what != PROC_EVENT_EXIT )
continue;

Loading…
Cancel
Save