diff --git a/src/conf.c b/src/conf.c index 3cefbd0f..e2e95b2d 100644 --- a/src/conf.c +++ b/src/conf.c @@ -545,6 +545,23 @@ static void parse_env(char *line) *end-- = 0; } + /* strip any leading 'set ' */ + end = key; + if (!strncmp(key, "set", 3)) + end += 3; + + /* check key, no spaces allowed */ + while (*end && isspace(*end)) + end++; + key = end; + while (*end && !isspace(*end)) + end++; + if (*end != 0) { + warnx("'%s=%s': not a valid identifier", key, val); + return; /* invalid key */ + } + + dbg("Global env '%s'='%s'", key, val); setenv(key, val, 1); node = malloc(sizeof(*node)); diff --git a/src/service.c b/src/service.c index 30f7ffe0..6f6f506b 100644 --- a/src/service.c +++ b/src/service.c @@ -471,6 +471,22 @@ static void source_env(svc_t *svc) *end-- = 0; } + /* strip any leading 'set ' */ + end = key; + if (!strncmp(key, "set", 3)) + end += 3; + + /* check key, no spaces allowed */ + while (*end && isspace(*end)) + end++; + key = end; + while (*end && !isspace(*end)) + end++; + if (*end != 0) { + warnx("'%s=%s': not a valid identifier", key, val); + continue; /* invalid key */ + } + switch (wordexp(value, &we, 0)) { case 0: for (i = 0, *val = 0; i < we.we_wordc; i++) { diff --git a/test/global-envs.sh b/test/global-envs.sh index 0528ca14..5dfb25d5 100755 --- a/test/global-envs.sh +++ b/test/global-envs.sh @@ -2,6 +2,11 @@ set -eu TEST_DIR=$(dirname "$0") +# shellcheck disable=SC2034 +BOOTSTRAP="foo=bar\n\ +set COLORTERM=yes\n\ +b aq=oroszoe\n\ +baz=qux" test_setup() { @@ -19,13 +24,14 @@ test_teardown() # shellcheck source=/dev/null . "$TEST_DIR/lib/setup.sh" +say "Waiting for runlevel 2" +sleep 2 + #run "initctl debug" -say "Add custom envs to $FINIT_CONF ..." -run "echo 'foo=bar' > $FINIT_CONF" -run "echo 'baz=qux' >> $FINIT_CONF" say "Add service stanza to $FINIT_CONF ..." run "echo 'service serv -np -e foo:bar -- Verify foo=bar' >> $FINIT_CONF" +#run "cat $FINIT_CONF" say 'Reload Finit' run "initctl reload"