]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb: Use str_list_add_printf() in debug_locks_args()
authorVolker Lendecke <vl@samba.org>
Thu, 19 Sep 2024 15:32:42 +0000 (17:32 +0200)
committerVolker Lendecke <vl@samba.org>
Fri, 20 Sep 2024 17:13:37 +0000 (17:13 +0000)
Saves lines, str_list_add_printf takes care of NULL checks

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Noel Power <noel.power@suse.com>
ctdb/server/ctdb_lock.c

index 4f04563d863759ea863ff3d3c89968d9d6d53d2b..d526413454ed6f5d7828866e28b4f5c6efe8e22f 100644 (file)
@@ -496,47 +496,22 @@ fail:
 
 }
 
-static const char **debug_locks_args(TALLOC_CTX *mem_ctx, struct lock_context *lock_ctx)
+static char **debug_locks_args(TALLOC_CTX *mem_ctx,
+                              struct lock_context *lock_ctx)
 {
-       const char **args = NULL;
-       int tdb_flags;
-       int nargs, i;
-
-       /* Program, lock helper PID, db|record, tdb path, fcntl|mutex, NULL */
-       nargs = 6;
-
-       args = talloc_array(mem_ctx, const char *, nargs);
-       if (args == NULL) {
-               return NULL;
-       }
-
-       args[0] = talloc_strdup(args, "debug_locks");
-       args[1] = talloc_asprintf(args, "%d", lock_ctx->child);
-
-       if (lock_ctx->type == LOCK_RECORD) {
-               args[2] = talloc_strdup(args, "RECORD");
-       } else {
-               args[2] = talloc_strdup(args, "DB");
-       }
-
-       args[3] = talloc_strdup(args, lock_ctx->ctdb_db->db_path);
-
-       tdb_flags = tdb_get_flags(lock_ctx->ctdb_db->ltdb->tdb);
-       if (tdb_flags & TDB_MUTEX_LOCKING) {
-               args[4] = talloc_strdup(args, "MUTEX");
-       } else {
-               args[4] = talloc_strdup(args, "FCNTL");
-       }
-
-       args[5] = NULL;
-
-       for (i=0; i<nargs-1; i++) {
-               if (args[i] == NULL) {
-                       talloc_free(args);
-                       return NULL;
-               }
-       }
-
+       int tdb_flags = tdb_get_flags(lock_ctx->ctdb_db->ltdb->tdb);
+       char **args = str_list_make_empty(mem_ctx);
+
+       str_list_add_printf(&args, "debug_locks");
+       str_list_add_printf(&args, "%d", lock_ctx->child);
+       str_list_add_printf(&args,
+                           "%s",
+                           (lock_ctx->type == LOCK_RECORD) ? "RECORD" : "DB");
+       str_list_add_printf(&args, "%s", lock_ctx->ctdb_db->db_path);
+
+       str_list_add_printf(&args,
+                           (tdb_flags & TDB_MUTEX_LOCKING) ? "MUTEX"
+                                                           : "FCNTL");
        return args;
 }
 
@@ -556,7 +531,7 @@ static void ctdb_lock_timeout_handler(struct tevent_context *ev,
        double elapsed_time;
        bool skip;
        char *keystr;
-       const char **args;
+       char **args;
        bool ok;
 
        lock_ctx = talloc_get_type_abort(private_data, struct lock_context);
@@ -611,7 +586,7 @@ lock_debug:
        if (args != NULL) {
                pid = vfork();
                if (pid == 0) {
-                       execvp(debug_locks, discard_const(args));
+                       execvp(debug_locks, args);
                        _exit(0);
                }
                talloc_free(args);