cloud storage client
git clone https://git.lucas.co/cce-cloud.git
fix: launched apps survive a daemon restart
App-menu launches were direct children in cce-cloud.service's cgroup,
so every service restart silently killed every app the user had ever
launched from the menu. KillMode=process restricts the stop signal to
the daemon itself (systemd kills by cgroup, which no setsid/double-fork
escapes), and process_group(0) on the spawn keeps a terminal ^C from
reaching launched apps when the daemon is run by hand.
Co-Authored-By: Claude Fable 5 <[email protected]>
cce-cloud.service | 4 ++++
src/main.rs | 8 ++++++++
2 files changed, 12 insertions(+)
diff --git a/cce-cloud.service b/cce-cloud.service
index 71f1ef7..7165873 100644
--- a/cce-cloud.service
+++ b/cce-cloud.service
@@ -8,6 +8,10 @@ Type=simple
ExecStart=%h/.local/bin/cce-cloud --daemon
Restart=on-failure
RestartSec=3
+# The daemon spawns the user's app-menu launches as children; with the
+# default control-group kill mode a service restart silently kills every
+# app ever launched from the menu. Only signal the daemon itself.
+KillMode=process
Environment=RUST_LOG=info
# App launches inherit this PATH; without %h/.local/bin, desktop entries
# with bare Exec names fail to spawn.
diff --git a/src/main.rs b/src/main.rs
index 0329fb4..d9f6abd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -451,6 +451,12 @@ fn sort_apps_by_history(apps: &mut Vec<AppInfo>) {
}
fn spawn_command(cmd: &str) {
+ // Launched apps must outlive this daemon: process_group(0) moves them out
+ // of our process group so a terminal ^C (manual daemon run) doesn't kill
+ // them, and cce-cloud.service sets KillMode=process so a service restart
+ // doesn't cgroup-kill them either (systemd kills by cgroup, which no
+ // amount of setsid/double-fork escapes).
+ use std::os::unix::process::CommandExt;
if let Ok(file) = std::fs::OpenOptions::new()
.create(true)
.append(true)
@@ -462,6 +468,7 @@ fn spawn_command(cmd: &str) {
std::process::Command::new("sh")
.arg("-c")
.arg(cmd)
+ .process_group(0)
.stdout(f.try_clone().unwrap())
.stderr(f)
.spawn()
@@ -470,6 +477,7 @@ fn spawn_command(cmd: &str) {
std::process::Command::new("sh")
.arg("-c")
.arg(cmd)
+ .process_group(0)
.spawn()
.ok();
}