1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-13 17:18:18 +03:00

service: set env var for stop/reload commands

This commit is contained in:
Lennart Poettering 2010-07-08 00:47:35 +02:00
parent 9c2d9caab2
commit 2105e76a77

View File

@ -1328,8 +1328,8 @@ static int service_spawn(
pid_t pid; pid_t pid;
int r; int r;
int *fds = NULL, *fdsbuf = NULL; int *fds = NULL, *fdsbuf = NULL;
unsigned n_fds = 0; unsigned n_fds = 0, n_env = 0;
char **argv = NULL, **env = NULL; char **argv = NULL, **final_env = NULL, **our_env = NULL;
assert(s); assert(s);
assert(c); assert(c);
@ -1362,63 +1362,64 @@ static int service_spawn(
goto fail; goto fail;
} }
if (set_notify_socket) { if (!(our_env = new0(char*, 3))) {
char *t; r = -ENOMEM;
goto fail;
}
if (asprintf(&t, "NOTIFY_SOCKET=@%s", s->meta.manager->notify_socket) < 0) { if (set_notify_socket)
if (asprintf(our_env + n_env++, "NOTIFY_SOCKET=@%s", s->meta.manager->notify_socket) < 0) {
r = -ENOMEM; r = -ENOMEM;
goto fail; goto fail;
} }
env = strv_env_set(s->meta.manager->environment, t); if (s->main_pid > 0)
free(t); if (asprintf(our_env + n_env++, "MAINPID=%lu", (unsigned long) s->main_pid) < 0) {
if (!env) {
r = -ENOMEM; r = -ENOMEM;
goto fail; goto fail;
} }
} else
env = s->meta.manager->environment; if (!(final_env = strv_env_merge(2,
s->meta.manager->environment,
our_env,
NULL))) {
r = -ENOMEM;
goto fail;
}
r = exec_spawn(c, r = exec_spawn(c,
argv, argv,
&s->exec_context, &s->exec_context,
fds, n_fds, fds, n_fds,
env, final_env,
apply_permissions, apply_permissions,
apply_chroot, apply_chroot,
s->meta.manager->confirm_spawn, s->meta.manager->confirm_spawn,
s->meta.cgroup_bondings, s->meta.cgroup_bondings,
&pid); &pid);
strv_free(argv);
argv = NULL;
if (set_notify_socket)
strv_free(env);
env = NULL;
if (r < 0) if (r < 0)
goto fail; goto fail;
if (fdsbuf)
free(fdsbuf);
if ((r = unit_watch_pid(UNIT(s), pid)) < 0) if ((r = unit_watch_pid(UNIT(s), pid)) < 0)
/* FIXME: we need to do something here */ /* FIXME: we need to do something here */
goto fail; goto fail;
free(fdsbuf);
strv_free(argv);
strv_free(our_env);
strv_free(final_env);
*_pid = pid; *_pid = pid;
return 0; return 0;
fail: fail:
free(fds); free(fdsbuf);
strv_free(argv); strv_free(argv);
strv_free(our_env);
if (set_notify_socket) strv_free(final_env);
strv_free(env);
if (timeout) if (timeout)
unit_unwatch_timer(UNIT(s), &s->timer_watch); unit_unwatch_timer(UNIT(s), &s->timer_watch);