app-list: Use double-fork spawn
This commit is contained in:
parent
99da3eda4a
commit
e1d1a09aac
3 changed files with 36 additions and 2 deletions
|
|
@ -785,7 +785,7 @@ impl cosmic::Application for CosmicAppList {
|
||||||
WaylandUpdate::ActivationToken { token, exec } => {
|
WaylandUpdate::ActivationToken { token, exec } => {
|
||||||
let mut exec = shlex::Shlex::new(&exec);
|
let mut exec = shlex::Shlex::new(&exec);
|
||||||
let mut cmd = match exec.next() {
|
let mut cmd = match exec.next() {
|
||||||
Some(cmd) if !cmd.contains('=') => tokio::process::Command::new(cmd),
|
Some(cmd) if !cmd.contains('=') => std::process::Command::new(cmd),
|
||||||
_ => return Command::none(),
|
_ => return Command::none(),
|
||||||
};
|
};
|
||||||
for arg in exec {
|
for arg in exec {
|
||||||
|
|
@ -798,7 +798,9 @@ impl cosmic::Application for CosmicAppList {
|
||||||
cmd.env("XDG_ACTIVATION_TOKEN", &token);
|
cmd.env("XDG_ACTIVATION_TOKEN", &token);
|
||||||
cmd.env("DESKTOP_STARTUP_ID", &token);
|
cmd.env("DESKTOP_STARTUP_ID", &token);
|
||||||
}
|
}
|
||||||
let _ = cmd.spawn();
|
tokio::task::spawn_blocking(|| {
|
||||||
|
crate::process::spawn(cmd);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
mod app;
|
mod app;
|
||||||
mod config;
|
mod config;
|
||||||
mod localize;
|
mod localize;
|
||||||
|
mod process;
|
||||||
mod wayland_handler;
|
mod wayland_handler;
|
||||||
mod wayland_subscription;
|
mod wayland_subscription;
|
||||||
|
|
||||||
|
|
|
||||||
31
cosmic-app-list/src/process.rs
Normal file
31
cosmic-app-list/src/process.rs
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue