#include "set.h"
#include "signal-util.h"
#include "stat-util.h"
-#include "static-destruct.h"
#include "string-util.h"
#include "strv.h"
#include "time-util.h"
int saved_argc = 0;
char **saved_argv = NULL;
-char **saved_env = NULL;
static int saved_in_initrd = -1;
-STATIC_DESTRUCTOR_REGISTER(saved_env, strv_freep);
-
bool kexec_loaded(void) {
_cleanup_free_ char *s = NULL;
if (r < 0)
log_debug_errno(r, "Failed to turn off coredumps, ignoring: %m");
}
-
-void save_env(void) {
- saved_env = strv_copy(environ);
-}
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);
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,
/* 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);
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