Skip to content

Commit

Permalink
Fix #377: expand service env:file variables
Browse files Browse the repository at this point in the history
This change allows us to support constructs like this:

    RUNDIR=/var/run/somesvc
    DAEMON_ARGS=--workdir $RUNDIR --other-args...

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
  • Loading branch information
troglobit committed Oct 30, 2023
1 parent 50e587f commit 68f44f7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ static void source_env(svc_t *svc)
len = sizeof(buf);
while (fgets(line, len, fp)) {
char *key = chomp(line);
wordexp_t we = { 0 };
char *value, *end;

/* skip any leading whitespace */
Expand Down Expand Up @@ -466,7 +467,19 @@ static void source_env(svc_t *svc)
*end-- = 0;
}

setenv(key, value, 1);
switch (wordexp(value, &we, 0)) {
case 0:
setenv(key, we.we_wordv[0], 1);
wordfree(&we);
break;

case WRDE_NOSPACE:
wordfree(&we);
/* fallthrough */
default:
setenv(key, value, 1);
break;
}
}

fclose(fp);
Expand Down

0 comments on commit 68f44f7

Please sign in to comment.