ctdb-tools: Remember PID of helper subprocess
authorMartin Schwenke <martin@meltin.net>
Tue, 7 Jan 2020 04:26:21 +0000 (15:26 +1100)
committerMartin Schwenke <martin@meltin.net>
Thu, 13 Jan 2022 21:56:33 +0000 (08:56 +1100)
No behaviour change for now, just a change of variable.

Signed-off-by: Martin Schwenke <martin@meltin.net>
ctdb/tools/ctdb.c

index 8370e11f8e6829312a521337a676f727be9ded71..14d0caf160d44fccdea5a398c3c37f18ad34a5c9 100644 (file)
@@ -77,6 +77,8 @@ struct ctdb_context {
        uint64_t srvid;
 };
 
+static pid_t helper_pid;
+
 static void usage(const char *command);
 
 /*
@@ -647,7 +649,6 @@ static int str_to_data(const char *str, size_t len, TALLOC_CTX *mem_ctx,
 static int run_helper(TALLOC_CTX *mem_ctx, const char *command,
                      const char *path, int argc, const char **argv)
 {
-       pid_t pid;
        int save_errno, status, ret;
        const char **new_argv;
        int i;
@@ -663,8 +664,8 @@ static int run_helper(TALLOC_CTX *mem_ctx, const char *command,
        }
        new_argv[argc+1] = NULL;
 
-       pid = fork();
-       if (pid < 0) {
+       helper_pid = fork();
+       if (helper_pid < 0) {
                save_errno = errno;
                talloc_free(new_argv);
                fprintf(stderr, "Failed to fork %s (%s) - %s\n",
@@ -672,7 +673,7 @@ static int run_helper(TALLOC_CTX *mem_ctx, const char *command,
                return save_errno;
        }
 
-       if (pid == 0) {
+       if (helper_pid == 0) {
                ret = execv(path, discard_const(new_argv));
                if (ret == -1) {
                        _exit(64+errno);
@@ -683,7 +684,7 @@ static int run_helper(TALLOC_CTX *mem_ctx, const char *command,
 
        talloc_free(new_argv);
 
-       ret = waitpid(pid, &status, 0);
+       ret = waitpid(helper_pid, &status, 0);
        if (ret == -1) {
                save_errno = errno;
                fprintf(stderr, "waitpid() failed for %s - %s\n",