mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
eventscript: clean up forked handler event code
Write the whole int through the pipe, rather than quietly cutting it off. Also, use -2 as the result if the read fails; -1 comes from many paths if the child fails before running the script. Add a comment about why we don't need to check the write. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 6804f880436645b52c09a78fa300377fa8058d0e)
This commit is contained in:
parent
e6b69fa760
commit
8723045c61
@ -609,9 +609,10 @@ 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);
|
||||
struct ctdb_context *ctdb = state->ctdb;
|
||||
signed char rt = 0;
|
||||
int rt;
|
||||
|
||||
read(state->fd[0], &rt, sizeof(rt));
|
||||
if (read(state->fd[0], &rt, sizeof(rt)) != sizeof(rt))
|
||||
rt = -2;
|
||||
|
||||
DEBUG(DEBUG_INFO,(__location__ " Eventscript %s finished with state %d\n", state->options, rt));
|
||||
|
||||
@ -824,12 +825,14 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
|
||||
}
|
||||
|
||||
if (state->child == 0) {
|
||||
signed char rt;
|
||||
int rt;
|
||||
|
||||
close(state->fd[0]);
|
||||
set_close_on_exec(state->fd[1]);
|
||||
|
||||
rt = ctdb_event_script_v(ctdb, state->options);
|
||||
/* We must be able to write PIPEBUF bytes at least; if this
|
||||
somehow fails, the read above will be short. */
|
||||
write(state->fd[1], &rt, sizeof(rt));
|
||||
close(state->fd[1]);
|
||||
_exit(rt);
|
||||
|
Loading…
Reference in New Issue
Block a user