#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);
+}
if (switch_root_init) {
args[0] = switch_root_init;
- (void) execv(args[0], (char* const*) args);
+ (void) execve(args[0], (char* const*) args, saved_env);
log_warning_errno(errno, "Failed to execute configured init, trying fallback: %m");
}
args[0] = "/bin/sh";
args[1] = NULL;
- (void) execv(args[0], (char* const*) args);
+ (void) execve(args[0], (char* const*) args, saved_env);
log_error_errno(errno, "Failed to execute /bin/sh, giving up: %m");
} else
log_warning_errno(r, "Failed to execute /sbin/init, giving up: %m");
/* 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();
+
/* Make sure that if the user says "syslog" we actually log to the journal. */
log_set_upgrade_syslog_to_journal(true);