feat: add helpers for getting and using activation tokens in applets

refactor(applet): connect to privileged socket if available

cleanup
This commit is contained in:
Ashley Wulber 2023-11-14 16:55:06 -05:00 committed by Ashley Wulber
parent c9554a8740
commit ef5b6fb44a
9 changed files with 310 additions and 8 deletions

31
src/process.rs Normal file
View file

@ -0,0 +1,31 @@
use std::process::{exit, Command, Stdio};
use nix::sys::wait::waitpid;
use nix::unistd::{fork, ForkResult};
/// Performs a double fork with setsid to spawn and detach a command.
pub fn spawn(mut command: Command) {
command
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null());
unsafe {
match fork() {
Ok(ForkResult::Parent { child }) => {
let _res = waitpid(Some(child), None);
}
Ok(ForkResult::Child) => {
let _res = nix::unistd::setsid();
let _res = command.spawn();
exit(0);
}
Err(why) => {
println!("failed to fork and spawn command: {}", why.desc());
}
}
}
}