Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/browser/daemon/process.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::os::unix::process::CommandExt;
use std::path::PathBuf;
use std::time::Duration;

Expand Down Expand Up @@ -107,7 +108,10 @@ pub fn spawn_daemon(

let params_json = serde_json::to_string(params)?;

// Shell tools may clean up their process group when a command returns.
// Keep the daemon reachable by subsequent CLI invocations in other tools.
let child = std::process::Command::new(exe)
.process_group(0)
.args(["__daemon", "--session-name", session_name])
.env("STEEL_DAEMON_PARAMS", params_json)
.stdin(std::process::Stdio::null())
Expand Down
13 changes: 13 additions & 0 deletions tests/browser_device_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl Drop for Fixture {
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
#[allow(unsafe_code)] // read-only process-group query for our own daemon PID
async fn device_auth_uses_bearer_and_normalizes_root_query_before_native_cdp() {
use std::os::unix::fs::PermissionsExt;
let api = MockServer::start().await;
Expand Down Expand Up @@ -133,6 +134,18 @@ async fn device_auth_uses_bearer_and_normalizes_root_query_before_native_cdp() {
"{}",
String::from_utf8_lossy(&start.stdout)
);
let daemon_pid: libc::pid_t =
std::fs::read_to_string(fixture.home.path().join("daemon-test.pid"))
.unwrap()
.trim()
.parse()
.unwrap();
// SAFETY: getpgid only queries the known child process; it sends no signal.
let daemon_group = unsafe { libc::getpgid(daemon_pid) };
assert_eq!(
daemon_group, daemon_pid,
"daemon must have its own group to survive shell-tool cleanup"
);
assert_eq!(
*seen.lock().unwrap(),
["/?sessionId=test-session&token=synthetic-connect-token"]
Expand Down