diff --git a/sapi/fpm/fpm/fpm_events.c b/sapi/fpm/fpm/fpm_events.c index 4cc56067bfc6..77f481120ae1 100644 --- a/sapi/fpm/fpm/fpm_events.c +++ b/sapi/fpm/fpm/fpm_events.c @@ -480,11 +480,14 @@ void fpm_event_loop(int err) /* {{{ */ void fpm_event_fire(struct fpm_event_s *ev) /* {{{ */ { - if (!ev || !ev->callback) { + if (!ev || !ev->ptr_callback) { return; } - - (*ev->callback)( (struct fpm_event_s *) ev, ev->which, ev->arg); + if (ev->pid) { + (*ev->pid_callback)( (struct fpm_event_s *) ev, ev->which, ev->pid); + } else { + (*ev->ptr_callback)( (struct fpm_event_s *) ev, ev->which, ev->arg); + } } /* }}} */ @@ -495,13 +498,27 @@ int fpm_event_set(struct fpm_event_s *ev, int fd, int flags, void (*callback)(st } memset(ev, 0, sizeof(struct fpm_event_s)); ev->fd = fd; - ev->callback = callback; + ev->ptr_callback = callback; ev->arg = arg; ev->flags = flags; return 0; } /* }}} */ +int fpm_event_set_with_pid(struct fpm_event_s *ev, int fd, int flags, void (*callback)(struct fpm_event_s *, short, pid_t pid), pid_t pid) /* {{{ */ +{ + if (!ev || !callback || fd < -1) { + return -1; + } + memset(ev, 0, sizeof(struct fpm_event_s)); + ev->fd = fd; + ev->pid_callback = callback; + ev->pid = pid; + ev->flags = flags; + return 0; +} +/* }}} */ + int fpm_event_add(struct fpm_event_s *ev, unsigned long int frequency) /* {{{ */ { struct timeval now; diff --git a/sapi/fpm/fpm/fpm_events.h b/sapi/fpm/fpm/fpm_events.h index 5cc2b942ed25..57b77a63d8d8 100644 --- a/sapi/fpm/fpm/fpm_events.h +++ b/sapi/fpm/fpm/fpm_events.h @@ -14,11 +14,15 @@ struct fpm_event_s { int fd; /* not set with FPM_EV_TIMEOUT */ struct timeval timeout; /* next time to trigger */ struct timeval frequency; - void (*callback)(struct fpm_event_s *, short, void *); + union { + void (*ptr_callback)(struct fpm_event_s *, short, void *); + void (*pid_callback)(struct fpm_event_s *, short, pid_t pid); + }; void *arg; int flags; int index; /* index of the fd in the ufds array */ short which; /* type of event */ + pid_t pid; }; typedef struct fpm_event_queue_s { @@ -41,6 +45,7 @@ void fpm_event_loop(int err); void fpm_event_fire(struct fpm_event_s *ev); int fpm_event_init_main(void); int fpm_event_set(struct fpm_event_s *ev, int fd, int flags, void (*callback)(struct fpm_event_s *, short, void *), void *arg); +int fpm_event_set_with_pid(struct fpm_event_s *ev, int fd, int flags, void (*callback)(struct fpm_event_s *, short, pid_t pid), pid_t pid); int fpm_event_add(struct fpm_event_s *ev, unsigned long int timeout); int fpm_event_del(struct fpm_event_s *ev); int fpm_event_pre_init(char *machanism); diff --git a/sapi/fpm/fpm/fpm_stdio.c b/sapi/fpm/fpm/fpm_stdio.c index 78326924acd9..e79247b8efc1 100644 --- a/sapi/fpm/fpm/fpm_stdio.c +++ b/sapi/fpm/fpm/fpm_stdio.c @@ -166,7 +166,7 @@ int fpm_stdio_flush_child(void) return write(STDERR_FILENO, FPM_STDIO_CMD_FLUSH, sizeof(FPM_STDIO_CMD_FLUSH)); } -static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg) /* {{{ */ +static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, pid_t pid) /* {{{ */ { static const int max_buf_size = 1024; int fd = ev->fd; @@ -178,10 +178,10 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg) int read_fail = 0, create_log_stream; struct zlog_stream *log_stream; - if (!arg) { + if (!pid) { return; } - child = fpm_child_find((intptr_t) arg); + child = fpm_child_find(pid); if (!child) { return; } @@ -330,10 +330,10 @@ int fpm_stdio_parent_use_pipes(struct fpm_child_s *child) /* {{{ */ child->fd_stdout = fd_stdout[0]; child->fd_stderr = fd_stderr[0]; - fpm_event_set(&child->ev_stdout, child->fd_stdout, FPM_EV_READ, fpm_stdio_child_said, (void *) (intptr_t) child->pid); + fpm_event_set_with_pid(&child->ev_stdout, child->fd_stdout, FPM_EV_READ, fpm_stdio_child_said, child->pid); fpm_event_add(&child->ev_stdout, 0); - fpm_event_set(&child->ev_stderr, child->fd_stderr, FPM_EV_READ, fpm_stdio_child_said, (void *) (intptr_t) child->pid); + fpm_event_set_with_pid(&child->ev_stderr, child->fd_stderr, FPM_EV_READ, fpm_stdio_child_said, child->pid); fpm_event_add(&child->ev_stderr, 0); return 0; }