aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-08-29 14:09:22 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-08-29 14:09:22 +0200
commit7dfbf0230218f8bac9b37326421c24547d22bbd8 (patch)
treed7095dd362434f07bc4c81cd9a74732fd312ec54
parentd2b117d1e0c043414e04e9f39fac799f0382064a (diff)
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 <jose.bollo@iot.bzh>
-rw-r--r--src/afb-config.c29
1 files 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: