Allow word-splitting for exit hook.
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 15 Oct 2017 18:29:39 +0000 (20:29 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Tue, 7 Nov 2017 20:21:11 +0000 (21:21 +0100)
All hooks except the exit hook are run via dss_exec_cmdline_pid(),
which performs word splitting to create the argument vector for
exec(2). For the exit hook, however, we build the argument vector
manually, so the command line for the exit hook is not split.

This commit removes this inconsistency. However, we can't use
dss_exec_cmdline_pid() here because we need to append the error string
which caused dss to exit to the argument vector as a single argument,
and this string may well contain whitespace characters.

Hence we run split_args() on the argument to --exit-hook to obtain
an argument vector, append the error string as another element,
and then run dss_exec().

dss.c

diff --git a/dss.c b/dss.c
index 3e626ab0113b1890277da115ea6c735dbdb690d7..a65967c07e41785c165deffefc69bc02fe80bef3 100644 (file)
--- a/dss.c
+++ b/dss.c
@@ -1500,15 +1500,18 @@ out:
 
 static void exit_hook(int exit_code)
 {
-       const char *argv[3];
        pid_t pid;
-
-       argv[0] = OPT_STRING_VAL(DSS, EXIT_HOOK);
-       argv[1] = dss_strerror(-exit_code);
-       argv[2] = NULL;
-
-       DSS_NOTICE_LOG(("executing %s %s\n", argv[0], argv[1]));
-       dss_exec(&pid, argv[0], (char **)argv);
+       char **argv, *tmp = dss_strdup(OPT_STRING_VAL(DSS, EXIT_HOOK));
+       unsigned n = split_args(tmp, &argv, " \t");
+
+       n++;
+       argv = dss_realloc(argv, (n + 1) * sizeof(char *));
+       argv[n - 1] = dss_strdup(dss_strerror(-exit_code));
+       argv[n] = NULL;
+       dss_exec(&pid, argv[0], argv);
+       free(argv[n - 1]);
+       free(argv);
+       free(tmp);
 }
 
 static void lock_dss_or_die(void)