ctdb-tools: When in test mode set process group in top-level ctdb tool
authorMartin Schwenke <martin@meltin.net>
Fri, 7 Feb 2020 05:11:23 +0000 (16:11 +1100)
committerAmitay Isaacs <amitay@samba.org>
Mon, 10 Feb 2020 04:07:39 +0000 (04:07 +0000)
If ctdbd hangs when shutting down in post-test clean-up then killing
the process group can kill the test.  When in test mode, create a
process group but only in the top-level ctdb tool - the natgw and lvs
helpers also run the ctdb tool.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tools/ctdb.c

index c157838018e2d5967fd40096df4b467598d10587..c464c91a4cf8f9e934dfaf493b6f0584b9ef0049 100644 (file)
@@ -6301,6 +6301,7 @@ int main(int argc, const char *argv[])
        const char **extra_argv;
        int extra_argc;
        const struct ctdb_cmd *cmd;
+       const char *test_mode;
        int loglevel;
        bool ok;
        int ret = 0;
@@ -6375,6 +6376,16 @@ int main(int argc, const char *argv[])
        }
        debuglevel_set(loglevel);
 
+       /* Stop process group kill in alarm_handler() from killing tests */
+       test_mode = getenv("CTDB_TEST_MODE");
+       if (test_mode != NULL) {
+               const char *have_setpgid = getenv("CTDB_TOOL_SETPGID");
+               if (have_setpgid == NULL) {
+                       setpgid(0, 0);
+                       setenv("CTDB_TOOL_SETPGID", "1", 1);
+               }
+       }
+
        signal(SIGALRM, alarm_handler);
        alarm(options.maxruntime);