From: José Bollo Date: Tue, 29 Aug 2017 12:09:22 +0000 (+0200) Subject: afb-config Copies the values of option --exec X-Git-Tag: eel/4.99.1~43 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=7dfbf0230218f8bac9b37326421c24547d22bbd8;p=src%2Fapp-framework-binder.git afb-config Copies the values of option --exec Not copying is not possible if the name of the process is changed. Change-Id: I52122c84234ac275975dae47c23c9d7240b82df8 Signed-off-by: José Bollo --- 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: