diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-12-22 22:14:05 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-12-22 22:19:03 +0100 |
commit | 09812eb764b440651f3ff4cb5d37bd343f800560 (patch) | |
tree | 75a7a86e915c814ded076cd0efc84d20018ff13b /src/core/execute.c | |
parent | 565a9388f261c6e459e1726e358284ff687ec941 (diff) |
sd-daemon: introduce sd_watchdog_enabled() for parsing $WATCHDOG_USEC
Also, introduce a new environment variable named $WATCHDOG_PID which
cotnains the PID of the process that is supposed to send the keep-alive
events. This is similar how $LISTEN_FDS and $LISTEN_PID work together,
and protects against confusing processes further down the process tree
due to inherited environment.
Diffstat (limited to 'src/core/execute.c')
-rw-r--r-- | src/core/execute.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/core/execute.c b/src/core/execute.c index 4265717895..9b33ec0ec5 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -1020,6 +1020,7 @@ static void do_idle_pipe_dance(int idle_pipe[4]) { static int build_environment( ExecContext *c, unsigned n_fds, + usec_t watchdog_usec, const char *home, const char *username, const char *shell, @@ -1032,7 +1033,7 @@ static int build_environment( assert(c); assert(ret); - our_env = new(char*, 8); + our_env = new0(char*, 10); if (!our_env) return -ENOMEM; @@ -1046,6 +1047,16 @@ static int build_environment( our_env[n_env++] = x; } + if (watchdog_usec > 0) { + if (asprintf(&x, "WATCHDOG_PID=%lu", (unsigned long) getpid()) < 0) + return -ENOMEM; + our_env[n_env++] = x; + + if (asprintf(&x, "WATCHDOG_USEC=%llu", (unsigned long long) watchdog_usec) < 0) + return -ENOMEM; + our_env[n_env++] = x; + } + if (home) { x = strappend("HOME=", home); if (!x) @@ -1084,7 +1095,7 @@ static int build_environment( } our_env[n_env++] = NULL; - assert(n_env <= 8); + assert(n_env <= 10); *ret = our_env; our_env = NULL; @@ -1104,6 +1115,7 @@ int exec_spawn(ExecCommand *command, CGroupControllerMask cgroup_supported, const char *cgroup_path, const char *unit_id, + usec_t watchdog_usec, int idle_pipe[4], ExecRuntime *runtime, pid_t *ret) { @@ -1560,7 +1572,7 @@ int exec_spawn(ExecCommand *command, } } - err = build_environment(context, n_fds, home, username, shell, &our_env); + err = build_environment(context, n_fds, watchdog_usec, home, username, shell, &our_env); if (r < 0) { r = EXIT_MEMORY; goto fail_child; |