From 565b2cda11690550560bdd41fcfad826d1ae4a3d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 18 Dec 2009 14:13:09 +1030 Subject: [PATCH] eventscript: fix bug when script is aborted 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 (This used to be ctdb commit eb22c34bccc8a04fcf63efa2bc48d9788709382e) --- ctdb/server/eventscript.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index 481b47a97ac..9ce9cee4844 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -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);