diff options
author | Jesse Luehrs <doy@tozt.net> | 2023-03-09 20:43:27 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2023-03-09 20:55:01 -0500 |
commit | be2e4aa459222a8194163fff92ccbedcafd6cb19 (patch) | |
tree | 79ee6a74f8061ccf46b09baaf8715f56e2f2f3fb /src/bin | |
parent | 7729e435241f16e4707fe858c6ace15bd6049c34 (diff) | |
download | rbw-be2e4aa459222a8194163fff92ccbedcafd6cb19.tar.gz rbw-be2e4aa459222a8194163fff92ccbedcafd6cb19.zip |
bump deps
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/rbw-agent/daemon.rs | 31 | ||||
-rw-r--r-- | src/bin/rbw/actions.rs | 2 |
2 files changed, 19 insertions, 14 deletions
diff --git a/src/bin/rbw-agent/daemon.rs b/src/bin/rbw-agent/daemon.rs index 22862dd..8cb9998 100644 --- a/src/bin/rbw-agent/daemon.rs +++ b/src/bin/rbw-agent/daemon.rs @@ -30,32 +30,37 @@ pub fn daemonize() -> anyhow::Result<StartupAck> { .open(rbw::dirs::agent_stderr_file())?; let (r, w) = nix::unistd::pipe()?; - let res = daemonize::Daemonize::new() + let daemonize = daemonize::Daemonize::new() .pid_file(rbw::dirs::pid_file()) .stdout(stdout) - .stderr(stderr) - .exit_action(move || { + .stderr(stderr); + let res = match daemonize.execute() { + daemonize::Outcome::Parent(_) => { // unwraps are necessary because not really a good way to handle // errors here otherwise let _ = nix::unistd::close(w); let mut buf = [0; 1]; nix::unistd::read(r, &mut buf).unwrap(); nix::unistd::close(r).unwrap(); - }) - .start(); + std::process::exit(0); + } + daemonize::Outcome::Child(res) => res, + }; + let _ = nix::unistd::close(r); match res { Ok(_) => (), Err(e) => { - match e { - daemonize::DaemonizeError::LockPidfile(_) => { - // this means that there is already an agent running, so - // return a special exit code to allow the cli to detect - // this case and not error out - std::process::exit(23); - } - _ => panic!("failed to daemonize: {e}"), + // XXX super gross, but daemonize removed the ability to match + // on specific error types for some reason? + if e.to_string().contains("unable to lock pid file") { + // this means that there is already an agent running, so + // return a special exit code to allow the cli to detect + // this case and not error out + std::process::exit(23); + } else { + panic!("failed to daemonize: {e}"); } } } diff --git a/src/bin/rbw/actions.rs b/src/bin/rbw/actions.rs index 7ca0ef9..29cd6fe 100644 --- a/src/bin/rbw/actions.rs +++ b/src/bin/rbw/actions.rs @@ -31,7 +31,7 @@ pub fn quit() -> anyhow::Result<()> { let pidfile = rbw::dirs::pid_file(); let mut pid = String::new(); std::fs::File::open(pidfile)?.read_to_string(&mut pid)?; - let pid = nix::unistd::Pid::from_raw(pid.parse()?); + let pid = nix::unistd::Pid::from_raw(pid.trim_end().parse()?); sock.send(&rbw::protocol::Request { tty: nix::unistd::ttyname(0).ok().and_then(|p| { p.to_str().map(std::string::ToString::to_string) |