mirror of
https://github.com/troglobit/finit.git
synced 2026-10-30 12:50:34 +00:00
Fix #248: source env:file also in pre:post: scripts
This change basically add this for pre/post scripts:
sh -ac '. /path/to/env; exec ./pre-post.sh'
Meaning the env file can be a simple foo=bar file, which Finit reads and
call setenv() on all variables, and the user do not need to call export
on all variables -- additionally, any functions defined in an env file
can be used by the pre-post scripts, but are ignored by Finit. I.e.,
the service only gets the variables set, no functions.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
6f2a124240
commit
e2d1930e6c
1 file changed
+19
-13
+19
-13
@@ -1621,20 +1621,11 @@ static void service_kill_script(svc_t *svc)
|
|||||||
static void set_pre_post_envs(svc_t *svc, const char *type)
|
static void set_pre_post_envs(svc_t *svc, const char *type)
|
||||||
{
|
{
|
||||||
char buf[25 + 256] = "/etc/default:/etc/conf.d";
|
char buf[25 + 256] = "/etc/default:/etc/conf.d";
|
||||||
const char *fn = svc_getenv(svc);
|
|
||||||
const char *exist = "0";
|
|
||||||
|
|
||||||
setenv("SERVICE_TYPE", svc_typestr(svc), 1);
|
setenv("SERVICE_TYPE", svc_typestr(svc), 1);
|
||||||
setenv("SERVICE_IDENT", svc_ident(svc, NULL, 0), 1);
|
setenv("SERVICE_IDENT", svc_ident(svc, NULL, 0), 1);
|
||||||
setenv("SERVICE_SCRIPT_TYPE", type, 1);
|
setenv("SERVICE_SCRIPT_TYPE", type, 1);
|
||||||
|
|
||||||
if (fn) {
|
|
||||||
setenv("SERVICE_ENV_FILE", fn, 1);
|
|
||||||
if (!access(fn, R_OK))
|
|
||||||
exist = "1";
|
|
||||||
}
|
|
||||||
setenv("SERVICE_ENV_FILE_EXIST", exist, 1);
|
|
||||||
|
|
||||||
#ifdef FINIT_SYSCONFIG
|
#ifdef FINIT_SYSCONFIG
|
||||||
strlcat(buf, ":", sizeof(buf));
|
strlcat(buf, ":", sizeof(buf));
|
||||||
strlcat(buf, FINIT_SYSCONFIG, sizeof(buf));
|
strlcat(buf, FINIT_SYSCONFIG, sizeof(buf));
|
||||||
@@ -1651,12 +1642,20 @@ static void service_pre_script(svc_t *svc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (svc->pid == 0) {
|
if (svc->pid == 0) {
|
||||||
|
char buf[CMD_SIZE];
|
||||||
char *argv[4] = {
|
char *argv[4] = {
|
||||||
"sh",
|
"sh",
|
||||||
"-c",
|
"-ac",
|
||||||
svc->pre_script,
|
buf,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
char *env_file;
|
||||||
|
|
||||||
|
env_file = svc_getenv(svc);
|
||||||
|
if (env_file)
|
||||||
|
snprintf(buf, sizeof(buf), ". %s; exec %s", env_file, svc->pre_script);
|
||||||
|
else
|
||||||
|
strlcpy(buf, svc->pre_script, sizeof(buf));
|
||||||
|
|
||||||
set_pre_post_envs(svc, "pre");
|
set_pre_post_envs(svc, "pre");
|
||||||
execvp(_PATH_BSHELL, argv);
|
execvp(_PATH_BSHELL, argv);
|
||||||
@@ -1676,17 +1675,24 @@ static void service_post_script(svc_t *svc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (svc->pid == 0) {
|
if (svc->pid == 0) {
|
||||||
|
char buf[CMD_SIZE];
|
||||||
char *argv[4] = {
|
char *argv[4] = {
|
||||||
"sh",
|
"sh",
|
||||||
"-c",
|
"-ac",
|
||||||
svc->post_script,
|
buf,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
char *env_file;
|
||||||
int rc, sig;
|
int rc, sig;
|
||||||
|
|
||||||
rc = WEXITSTATUS(svc->status);
|
rc = WEXITSTATUS(svc->status);
|
||||||
sig = WTERMSIG(svc->status);
|
sig = WTERMSIG(svc->status);
|
||||||
|
|
||||||
|
env_file = svc_getenv(svc);
|
||||||
|
if (env_file)
|
||||||
|
snprintf(buf, sizeof(buf), ". %s; exec %s", env_file, svc->post_script);
|
||||||
|
else
|
||||||
|
strlcpy(buf, svc->post_script, sizeof(buf));
|
||||||
set_pre_post_envs(svc, "post");
|
set_pre_post_envs(svc, "post");
|
||||||
|
|
||||||
if (WIFEXITED(svc->status)) {
|
if (WIFEXITED(svc->status)) {
|
||||||
|
|||||||
Reference in new issue
Block a user