eventscript: clean up forked handler event code
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 24 Nov 2009 00:30:13 +0000 (11:00 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 24 Nov 2009 00:30:13 +0000 (11:00 +1030)
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>
server/eventscript.c

index 1e76cd6920be5d379a6219bd8690857ee0bba5a0..010da12cdf1aea4416f85e561ef0bb0614af39fd 100644 (file)
@@ -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));
 
@@ -825,12 +826,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);