|
|
|
@ -9,7 +9,7 @@ use libc::{
|
|
|
|
|
setuid,
|
|
|
|
|
};
|
|
|
|
|
use tokio::{
|
|
|
|
|
runtime::{Runtime, Handle},
|
|
|
|
|
runtime::Runtime,
|
|
|
|
|
task::JoinHandle,
|
|
|
|
|
};
|
|
|
|
|
use std::{
|
|
|
|
@ -182,45 +182,47 @@ fn detach_closure_internal<F: FnOnce(Parent) -> Fu + Send + 'static, Fu: Future>
|
|
|
|
|
let child = unsafe{fork()};
|
|
|
|
|
if child == 0 {
|
|
|
|
|
// Is child
|
|
|
|
|
let _ =std::thread::spawn(move || { //Any unwind will be caught here
|
|
|
|
|
let mut rt = Runtime::new().unwrap_or_else(|_| std::process::exit(1)); //Immediately exit if runtime cannot be created.
|
|
|
|
|
rt.block_on(async move {
|
|
|
|
|
|
|
|
|
|
use tokio::prelude::*;
|
|
|
|
|
let complete = || {
|
|
|
|
|
async {
|
|
|
|
|
unsafe {
|
|
|
|
|
if let Ok(_) = ttx.write_u32(!0u32).await
|
|
|
|
|
{
|
|
|
|
|
into(Parent{pid: libc::getppid(),comm:comm_c}).await;
|
|
|
|
|
{
|
|
|
|
|
let _ =std::thread::spawn(move || { //Any unwind will be caught here
|
|
|
|
|
let mut rt = Runtime::new().unwrap_or_else(|_| std::process::exit(1)); //Immediately exit if runtime cannot be created.
|
|
|
|
|
rt.block_on(async move {
|
|
|
|
|
|
|
|
|
|
use tokio::prelude::*;
|
|
|
|
|
let complete = || {
|
|
|
|
|
async {
|
|
|
|
|
unsafe {
|
|
|
|
|
if let Ok(_) = ttx.write_u32(!0u32).await
|
|
|
|
|
{
|
|
|
|
|
into(Parent{pid: libc::getppid(),comm:comm_c}).await;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
|
loop {
|
|
|
|
|
if let Some(as_uid) = as_uid {
|
|
|
|
|
// Set UID
|
|
|
|
|
if setuid(as_uid) != 0 {
|
|
|
|
|
let _ = ttx.write_u32(Error::SetUid.into()).await;
|
|
|
|
|
break;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
|
loop {
|
|
|
|
|
if let Some(as_uid) = as_uid {
|
|
|
|
|
// Set UID
|
|
|
|
|
if setuid(as_uid) != 0 {
|
|
|
|
|
let _ = ttx.write_u32(Error::SetUid.into()).await;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if let Some(as_gid) = as_gid {
|
|
|
|
|
// Set GID
|
|
|
|
|
if setgid(as_gid) != 0 {
|
|
|
|
|
let _ = ttx.write_u32(Error::SetGid.into()).await;
|
|
|
|
|
break;
|
|
|
|
|
if let Some(as_gid) = as_gid {
|
|
|
|
|
// Set GID
|
|
|
|
|
if setgid(as_gid) != 0 {
|
|
|
|
|
let _ = ttx.write_u32(Error::SetGid.into()).await;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
complete().await;
|
|
|
|
|
break;
|
|
|
|
|
complete().await;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}).join();
|
|
|
|
|
});
|
|
|
|
|
}).join();
|
|
|
|
|
}
|
|
|
|
|
std::process::exit(0);
|
|
|
|
|
} else if child > 0 {
|
|
|
|
|
// Fork succeeded
|
|
|
|
|