From 2e17b0ecddffb8590c4e8b9afaf1767ef7e8f89c Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 13 Aug 2014 14:46:31 +1000 Subject: ctdb-locking: Add argc parameter to lock_helper_args() To make this sane, also add an argv parameter and change the return type to bool. Anticipating a subsequent change, make the type of argv match what is needed by vfork_with_logging() and cast it when passing to execv(). This also means changing the type of the name member of struct db_namelist. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- ctdb/server/ctdb_lock.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/ctdb/server/ctdb_lock.c b/ctdb/server/ctdb_lock.c index e1a9fed772..47bba74e8b 100644 --- a/ctdb/server/ctdb_lock.c +++ b/ctdb/server/ctdb_lock.c @@ -549,7 +549,7 @@ static int db_count_handler(struct ctdb_db_context *ctdb_db, uint32_t priority, } struct db_namelist { - char **names; + const char **names; int n; }; @@ -564,10 +564,12 @@ static int db_name_handler(struct ctdb_db_context *ctdb_db, uint32_t priority, return 0; } -static char **lock_helper_args(TALLOC_CTX *mem_ctx, struct lock_context *lock_ctx, int fd) +static bool lock_helper_args(TALLOC_CTX *mem_ctx, + struct lock_context *lock_ctx, int fd, + int *argc, const char ***argv) { struct ctdb_context *ctdb = lock_ctx->ctdb; - char **args = NULL; + const char **args = NULL; int nargs, i; int priority; struct db_namelist list; @@ -597,9 +599,9 @@ static char **lock_helper_args(TALLOC_CTX *mem_ctx, struct lock_context *lock_ct /* Add extra argument for null termination */ nargs++; - args = talloc_array(mem_ctx, char *, nargs); + args = talloc_array(mem_ctx, const char *, nargs); if (args == NULL) { - return NULL; + return false; } args[0] = talloc_strdup(args, "ctdb_lock_helper"); @@ -645,11 +647,13 @@ static char **lock_helper_args(TALLOC_CTX *mem_ctx, struct lock_context *lock_ct for (i=0; ifd[1]); - if (args == NULL) { + if (!lock_helper_args(tmp_ctx, lock_ctx, lock_ctx->fd[1], + &argc, &args)) { DEBUG(DEBUG_ERR, ("Failed to create lock helper args\n")); close(lock_ctx->fd[0]); close(lock_ctx->fd[1]); @@ -783,7 +787,7 @@ static void ctdb_lock_schedule(struct ctdb_context *ctdb) /* Child process */ if (lock_ctx->child == 0) { - ret = execv(prog, args); + ret = execv(prog, (char * const*) args); if (ret < 0) { DEBUG(DEBUG_ERR, ("Failed to execute helper %s (%d, %s)\n", prog, errno, strerror(errno))); -- cgit