From: Andre Noll Date: Sun, 15 Oct 2017 18:29:39 +0000 (+0200) Subject: Allow word-splitting for exit hook. X-Git-Tag: v1.0.0~8^2 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=7277dbda6f036a3953d794305cad6a3bc51c67b4;p=dss.git Allow word-splitting for exit hook. 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(). --- diff --git a/dss.c b/dss.c index 3e626ab..a65967c 100644 --- 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)