Avril 4 years ago
parent 9c2d31353a
commit 9dbaa04263
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -6,7 +6,7 @@ pub fn print_stats()
{ {
use recolored::Colorize; use recolored::Colorize;
lazy_static! { lazy_static! {
static ref AUTHORS: String = env!("CARGO_PKG_AUTHORS").replace( ":", ", "); static ref AUTHORS: &'static str = Box::leak(env!("CARGO_PKG_AUTHORS").replace( ":", ", ").into_boxed_str());
}; };

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

Loading…
Cancel
Save