From 7dfbf0230218f8bac9b37326421c24547d22bbd8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Tue, 29 Aug 2017 14:09:22 +0200 Subject: [PATCH] afb-config Copies the values of option --exec MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Not copying is not possible if the name of the process is changed. Change-Id: I52122c84234ac275975dae47c23c9d7240b82df8 Signed-off-by: José Bollo --- src/afb-config.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/afb-config.c b/src/afb-config.c index d906bcb7..0bfd9d4c 100644 --- a/src/afb-config.c +++ b/src/afb-config.c @@ -393,6 +393,31 @@ static void noarg(int optc) } } +static char **make_exec(char **argv) +{ + char **result, *iter; + size_t length; + int i; + + length = 0; + for (i = 0 ; argv[i] ; i++) + length += strlen(argv[i]) + 1; + + result = malloc(length + ((unsigned)(i + 1)) * sizeof *result); + if (result == NULL) { + ERROR("can't alloc memory"); + exit(1); + } + + iter = (char*)&result[i+1]; + for (i = 0 ; argv[i] ; i++) { + result[i] = iter; + iter = stpcpy(iter, argv[i]) + 1; + } + result[i] = NULL; + return result; +} + /*--------------------------------------------------------- | Parse option and launch action +--------------------------------------------------------- */ @@ -565,8 +590,8 @@ static void parse_arguments(int argc, char **argv, struct afb_config *config) break; case SET_EXEC: - config->exec = &argv[optind]; - optind = argc; + config->exec = make_exec(&argv[optind]); + optind = argc; /* stop option scanning */ break; case SET_RNDTOKEN: -- 2.16.6