Don't work init if user is 0:0
This commit is contained in:
1 parent
0dac80b487
commit
5b2acfa526
1 file changed
+4
@@ -353,6 +353,9 @@ fn exec_command(argv: &[String], user: Option<UserSpec>) -> ! {
|
||||
let c_prog = cstrings[0].clone();
|
||||
let c_refs: Vec<&CString> = cstrings.iter().collect();
|
||||
|
||||
// If UserSpec is 0:0, don't fork.
|
||||
let user = user.filter(|u| !u.uid.is_root() || u.gid != Gid::from_raw(0));
|
||||
|
||||
match user {
|
||||
None => {
|
||||
// No privilege drop: exec directly, PID 1 becomes the command.
|
||||
@@ -362,6 +365,7 @@ fn exec_command(argv: &[String], user: Option<UserSpec>) -> ! {
|
||||
std::process::exit(1);
|
||||
}
|
||||
Some(user) => {
|
||||
warn(&format!("dropping privileges to {}:{}", user.uid, user.gid));
|
||||
// Drop privileges in a child so PID 1 (root) can poweroff afterwards.
|
||||
match unsafe { fork() } {
|
||||
Ok(ForkResult::Child) => {
|
||||
|
||||
Reference in new issue
Block a user