From b7b508c76553448dcbf33d8779f4285d8948df64 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 6 Mar 2015 14:05:23 +1100 Subject: [PATCH] ctdb-daemon: Use statically allocated arrays for helper paths The use of talloc with a static variable is somewhat confusing. Statically allocate an array and use ctdb_set_helper() instead. Signed-off-by: Martin Schwenke Reviewed-by: Volker Lendecke --- ctdb/server/ctdb_lock.c | 37 +++++++++++++------------------------ ctdb/server/eventscript.c | 15 ++++++--------- 2 files changed, 19 insertions(+), 33 deletions(-) diff --git a/ctdb/server/ctdb_lock.c b/ctdb/server/ctdb_lock.c index c5a2b98bfe8..f5928343df4 100644 --- a/ctdb/server/ctdb_lock.c +++ b/ctdb/server/ctdb_lock.c @@ -482,7 +482,7 @@ static void ctdb_lock_timeout_handler(struct tevent_context *ev, struct timeval current_time, void *private_data) { - static const char * debug_locks = NULL; + static char debug_locks[PATH_MAX+1] = ""; struct lock_context *lock_ctx; struct ctdb_context *ctdb; pid_t pid; @@ -510,16 +510,10 @@ static void ctdb_lock_timeout_handler(struct tevent_context *ev, elapsed_time)); } - /* Fire a child process to find the blocking process. */ - if (debug_locks == NULL) { - debug_locks = getenv("CTDB_DEBUG_LOCKS"); - if (debug_locks == NULL) { - debug_locks = talloc_asprintf(ctdb, - "%s/debug_locks.sh", - getenv("CTDB_BASE")); - } - } - if (debug_locks != NULL) { + if (ctdb_set_helper("lock debugging helper", + debug_locks, sizeof(debug_locks), + "CTDB_DEBUG_LOCKS", + getenv("CTDB_BASE"), "debug_locks.sh")) { pid = vfork(); if (pid == 0) { execl(debug_locks, debug_locks, NULL); @@ -529,7 +523,7 @@ static void ctdb_lock_timeout_handler(struct tevent_context *ev, } else { DEBUG(DEBUG_WARNING, (__location__ - " Unable to setup lock debugging - no memory?\n")); + " Unable to setup lock debugging\n")); } /* Back-off logging if lock is not obtained for a long time */ @@ -754,20 +748,15 @@ static void ctdb_lock_schedule(struct ctdb_context *ctdb) struct lock_context *lock_ctx; int ret, argc; TALLOC_CTX *tmp_ctx; - const char *helper = CTDB_HELPER_BINDIR "/ctdb_lock_helper"; - static const char *prog = NULL; + static char prog[PATH_MAX+1] = ""; const char **args; - if (prog == NULL) { - const char *t; - - t = getenv("CTDB_LOCK_HELPER"); - if (t != NULL) { - prog = talloc_strdup(ctdb, t); - } else { - prog = talloc_strdup(ctdb, helper); - } - CTDB_NO_MEMORY_VOID(ctdb, prog); + if (!ctdb_set_helper("lock helper", + prog, sizeof(prog), + "CTDB_LOCK_HELPER", + CTDB_HELPER_BINDIR, "ctdb_lock_helper")) { + ctdb_die(ctdb, __location__ + " Unable to set lock helper\n"); } /* Find a lock context with requests */ diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index eaa6a20d31a..d77612150c3 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -261,7 +261,7 @@ failed: static void ctdb_event_script_handler(struct event_context *ev, struct fd_event *fde, uint16_t flags, void *p); -static const char *helper_prog = NULL; +static char helper_prog[PATH_MAX+1] = ""; static int fork_child_for_script(struct ctdb_context *ctdb, struct ctdb_event_script_state *state) @@ -271,15 +271,12 @@ static int fork_child_for_script(struct ctdb_context *ctdb, struct ctdb_script_wire *current = get_current_script(state); int argc; const char **argv; - static const char *helper = CTDB_HELPER_BINDIR "/ctdb_event_helper"; - if (helper_prog == NULL) { - const char *t = getenv("CTDB_EVENT_HELPER"); - if (t != NULL) { - helper_prog = t; - } else { - helper_prog = helper; - } + if (!ctdb_set_helper("event helper", helper_prog, sizeof(helper_prog), + "CTDB_EVENT_HELPER", + CTDB_HELPER_BINDIR, "ctdb_event_helper")) { + ctdb_die(ctdb, __location__ + " Unable to set event helper\n"); } current->start = timeval_current();