summaryrefslogtreecommitdiff
path: root/src/core/main.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2019-11-03 22:46:42 +0900
committerGitHub <noreply@github.com>2019-11-03 22:46:42 +0900
commit5e467d74ad0c87f1f5e1a1e58bdce7b1971dd7a3 (patch)
treee47264610a5b1db5c056b3770f2c6e6849433708 /src/core/main.c
parent0ccdaa79ca69a40e4ad8b3e63b1236734751452e (diff)
parentdfaf16ebed8b5be645c645623f1593db5f5d0ba0 (diff)
downloadsystemd-5e467d74ad0c87f1f5e1a1e58bdce7b1971dd7a3.tar.gz
Merge pull request #13909 from poettering/env-copy-pid
Fixes for the "saved_env" copy logic
Diffstat (limited to 'src/core/main.c')
-rw-r--r--src/core/main.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/core/main.c b/src/core/main.c
index 7c814f3237..3545fde71d 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -146,6 +146,9 @@ static OOMPolicy arg_default_oom_policy;
static CPUSet arg_cpu_affinity;
static NUMAPolicy arg_numa_policy;
+/* A copy of the original environment block */
+static char **saved_env = NULL;
+
static int parse_configuration(const struct rlimit *saved_rlimit_nofile,
const struct rlimit *saved_rlimit_memlock);
@@ -2353,6 +2356,17 @@ static bool early_skip_setup_check(int argc, char *argv[]) {
return found_deserialize; /* When we are deserializing, then we are reexecuting, hence avoid the extensive setup */
}
+static int save_env(void) {
+ char **l;
+
+ l = strv_copy(environ);
+ if (!l)
+ return -ENOMEM;
+
+ strv_free_and_replace(saved_env, l);
+ return 0;
+}
+
int main(int argc, char *argv[]) {
dual_timestamp initrd_timestamp = DUAL_TIMESTAMP_NULL, userspace_timestamp = DUAL_TIMESTAMP_NULL, kernel_timestamp = DUAL_TIMESTAMP_NULL,
@@ -2391,9 +2405,13 @@ int main(int argc, char *argv[]) {
/* Save the original command line */
save_argc_argv(argc, argv);
- /* Save the original environment as we might need to restore it if we're requested to
- * execute another system manager later. */
- save_env();
+ /* Save the original environment as we might need to restore it if we're requested to execute another
+ * system manager later. */
+ r = save_env();
+ if (r < 0) {
+ error_message = "Failed to copy environment block";
+ goto finish;
+ }
/* Make sure that if the user says "syslog" we actually log to the journal. */
log_set_upgrade_syslog_to_journal(true);
@@ -2681,6 +2699,8 @@ finish:
arg_serialization = safe_fclose(arg_serialization);
fds = fdset_free(fds);
+ saved_env = strv_free(saved_env);
+
#if HAVE_VALGRIND_VALGRIND_H
/* If we are PID 1 and running under valgrind, then let's exit
* here explicitly. valgrind will only generate nice output on