ksud: fix build

This commit is contained in:
tiann
2023-04-04 15:09:53 +08:00
parent 693d827144
commit 8f910fbb75

View File

@@ -65,6 +65,12 @@ fn set_identity(uid: u32) {
} }
} }
#[cfg(not(unix))]
pub fn root_shell() -> Result<()> {
unimplemented!()
}
#[cfg(unix)]
pub fn root_shell() -> Result<()> { pub fn root_shell() -> Result<()> {
// we are root now, this was set in kernel! // we are root now, this was set in kernel!
let args: Vec<String> = std::env::args().collect(); let args: Vec<String> = std::env::args().collect();
@@ -161,7 +167,6 @@ pub fn root_shell() -> Result<()> {
} }
let mut uid = 0; // default uid = 0(root) let mut uid = 0; // default uid = 0(root)
#[cfg(unix)]
if free_idx < matches.free.len() { if free_idx < matches.free.len() {
let name = &matches.free[free_idx]; let name = &matches.free[free_idx];
uid = unsafe { uid = unsafe {
@@ -182,7 +187,6 @@ pub fn root_shell() -> Result<()> {
let mut command = &mut Command::new(&shell); let mut command = &mut Command::new(&shell);
#[cfg(unix)]
if !preserve_env { if !preserve_env {
// This is actually incorrect, i don't know why. // This is actually incorrect, i don't know why.
// command = command.env_clear(); // command = command.env_clear();
@@ -204,8 +208,6 @@ pub fn root_shell() -> Result<()> {
} }
} }
#[cfg(unix)]
{
// escape from the current cgroup and become session leader // escape from the current cgroup and become session leader
command = command.process_group(0); command = command.process_group(0);
command = unsafe { command = unsafe {
@@ -225,7 +227,6 @@ pub fn root_shell() -> Result<()> {
std::result::Result::Ok(()) std::result::Result::Ok(())
}) })
}; };
}
command = command.args(args).arg0(arg0); command = command.args(args).arg0(arg0);
Err(command.exec().into()) Err(command.exec().into())