Skip to content

Commit

Permalink
Minor refactor, split out pre/post envs
Browse files Browse the repository at this point in the history
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
  • Loading branch information
troglobit committed Feb 7, 2022
1 parent f930953 commit fd9f204
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,14 @@ static void service_kill_script(svc_t *svc)
kill(-svc->pid, SIGKILL);
}

/*
* Shared env vars for both pre: and post: scripts
*/
static void set_pre_post_envs(svc_t *svc)
{
setenv("SERVICE_IDENT", svc_ident(svc, NULL, 0), 1);
}

static void service_pre_script(svc_t *svc)
{
svc->pid = service_fork(svc);
Expand All @@ -1564,7 +1572,7 @@ static void service_pre_script(svc_t *svc)
NULL
};

setenv("SERVICE_IDENT", svc_ident(svc, NULL, 0), 1);
set_pre_post_envs(svc);
execvp(_PATH_BSHELL, argv);
_exit(EX_OSERR);
}
Expand Down Expand Up @@ -1593,7 +1601,7 @@ static void service_post_script(svc_t *svc)
rc = WEXITSTATUS(svc->status);
sig = WTERMSIG(svc->status);

setenv("SERVICE_IDENT", svc_ident(svc, NULL, 0), 1);
set_pre_post_envs(svc);

if (WIFEXITED(svc->status)) {
char val[4];
Expand Down

0 comments on commit fd9f204

Please sign in to comment.