diff options
author | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2008-07-09 14:02:54 +1000 |
---|---|---|
committer | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2008-07-09 14:02:54 +1000 |
commit | 334db8ccba7203d6985e7d4681809241e54d3c40 (patch) | |
tree | 1afced0504cb695fb94041708f963a6e84f50b78 /ctdb/server/eventscript.c | |
parent | 0fba2e36b186b38dbde29a724bf9e3c4e836cd12 (diff) | |
download | samba-334db8ccba7203d6985e7d4681809241e54d3c40.tar.gz samba-334db8ccba7203d6985e7d4681809241e54d3c40.tar.xz samba-334db8ccba7203d6985e7d4681809241e54d3c40.zip |
proper waitpid() fix.
remove all waitpid() calls and use the event system to trap sigchld
(This used to be ctdb commit 77458b2b6b51b2970c12b0e5b097088d3fb9d358)
Diffstat (limited to 'ctdb/server/eventscript.c')
-rw-r--r-- | ctdb/server/eventscript.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index 54d914b35c..1d42b2be49 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -210,18 +210,16 @@ static void ctdb_event_script_handler(struct event_context *ev, struct fd_event { struct ctdb_event_script_state *state = talloc_get_type(p, struct ctdb_event_script_state); - int status = -1; void (*callback)(struct ctdb_context *, int, void *) = state->callback; void *private_data = state->private_data; struct ctdb_context *ctdb = state->ctdb; + signed char rt = -1; + + read(state->fd[0], &rt, sizeof(rt)); - waitpid(state->child, &status, 0); - if (status != -1) { - status = WEXITSTATUS(status); - } talloc_set_destructor(state, NULL); talloc_free(state); - callback(ctdb, status, private_data); + callback(ctdb, rt, private_data); ctdb->event_script_timeouts = 0; } @@ -293,7 +291,6 @@ static int event_script_destructor(struct ctdb_event_script_state *state) { DEBUG(DEBUG_ERR,(__location__ " Sending SIGTERM to child pid:%d\n", state->child)); kill(state->child, SIGTERM); - waitpid(state->child, NULL, 0); return 0; } @@ -336,13 +333,18 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb, } if (state->child == 0) { + signed char rt; + close(state->fd[0]); if (ctdb->do_setsched) { ctdb_restore_scheduler(ctdb); } set_close_on_exec(state->fd[1]); - ret = ctdb_event_script_v(ctdb, state->options); - _exit(ret); + rt = ctdb_event_script_v(ctdb, state->options); + while ((ret = write(state->fd[1], &rt, sizeof(rt))) != sizeof(rt)) { + sleep(1); + } + _exit(rt); } talloc_set_destructor(state, event_script_destructor); |