pid1: restore the original environment passed by the kernel when switching to a new system manager
PID1 may modified the environment passed by the kernel when it starts
running. Commit 9d48671c62 unset $HOME for
example.
In case PID1 is going to switch to a new root and execute a new system manager
which is not systemd, we should restore the original environment as the new
manager might expect some variables to be set by default (more specifically
$HOME).
This commit is contained in:
committed by
Zbigniew Jędrzejewski-Szmek
parent
694566454a
commit
a5cede8c24
@@ -39,6 +39,7 @@
|
||||
#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"
|
||||
@@ -49,8 +50,11 @@
|
||||
|
||||
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;
|
||||
|
||||
@@ -298,3 +302,7 @@ void disable_coredumps(void) {
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to turn off coredumps, ignoring: %m");
|
||||
}
|
||||
|
||||
void save_env(void) {
|
||||
saved_env = strv_copy(environ);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user