eventscript: fix bug when script is aborted
authorRusty Russell <rusty@rustcorp.com.au>
Fri, 18 Dec 2009 03:43:09 +0000 (14:13 +1030)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Fri, 18 Dec 2009 03:48:41 +0000 (14:48 +1100)
Another corner case when we terminate running monitor scripts to run
something else: logging can flush the output and we write to a NULL
pointer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
server/eventscript.c

index 481b47a97ac6e880caa7a6779634b9364a5478dd..9ce9cee484401ff42a3cd3993b079e5f4a2458dd 100644 (file)
@@ -87,9 +87,16 @@ static void log_event_script_output(const char *str, uint16_t len, void *p)
 {
        struct ctdb_event_script_state *state
                = talloc_get_type(p, struct ctdb_event_script_state);
-       struct ctdb_script_wire *current = get_current_script(state);
+       struct ctdb_script_wire *current;
        unsigned int slen, min;
 
+       /* We may have been aborted to run something else.  Discard */
+       if (state->scripts == NULL) {
+               return;
+       }
+
+       current = get_current_script(state);
+
        /* Append, but don't overfill buffer.  It starts zero-filled. */
        slen = strlen(current->output);
        min = MIN(len, sizeof(current->output) - slen - 1);