aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2024-04-20 10:34:48 -0400
committerJesse Luehrs <doy@tozt.net>2024-04-20 11:18:52 -0400
commit5c473555cb2069f26a66d7c1e14f54a051a14948 (patch)
treed3607f042aaa8776b0f270c1ab866416e860d8d3 /src/bin
parentbdf255d8efca18feed9dbe99d6166012821b8768 (diff)
downloadrbw-5c473555cb2069f26a66d7c1e14f54a051a14948.tar.gz
rbw-5c473555cb2069f26a66d7c1e14f54a051a14948.zip
bump deps
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/rbw-agent/daemon.rs26
-rw-r--r--src/bin/rbw/actions.rs14
2 files changed, 17 insertions, 23 deletions
diff --git a/src/bin/rbw-agent/daemon.rs b/src/bin/rbw-agent/daemon.rs
index 4957c28..640d5e2 100644
--- a/src/bin/rbw-agent/daemon.rs
+++ b/src/bin/rbw-agent/daemon.rs
@@ -1,22 +1,16 @@
+use std::os::fd::AsRawFd as _;
+
pub struct StartupAck {
- writer: std::os::unix::io::RawFd,
+ writer: std::os::unix::io::OwnedFd,
}
impl StartupAck {
- pub fn ack(&self) -> anyhow::Result<()> {
- nix::unistd::write(self.writer, &[0])?;
- nix::unistd::close(self.writer)?;
+ pub fn ack(self) -> anyhow::Result<()> {
+ nix::unistd::write(&self.writer, &[0])?;
Ok(())
}
}
-impl Drop for StartupAck {
- fn drop(&mut self) {
- // best effort close here, can't do better in a destructor
- let _ = nix::unistd::close(self.writer);
- }
-}
-
pub fn daemonize() -> anyhow::Result<StartupAck> {
let stdout = std::fs::OpenOptions::new()
.append(true)
@@ -34,18 +28,18 @@ pub fn daemonize() -> anyhow::Result<StartupAck> {
.stderr(stderr);
let res = match daemonize.execute() {
daemonize::Outcome::Parent(_) => {
+ drop(w);
+ let mut buf = [0; 1];
// 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();
+ nix::unistd::read(r.as_raw_fd(), &mut buf).unwrap();
+ drop(r);
std::process::exit(0);
}
daemonize::Outcome::Child(res) => res,
};
- let _ = nix::unistd::close(r);
+ drop(r);
match res {
Ok(_) => (),
diff --git a/src/bin/rbw/actions.rs b/src/bin/rbw/actions.rs
index e0e7a2e..a13c58b 100644
--- a/src/bin/rbw/actions.rs
+++ b/src/bin/rbw/actions.rs
@@ -33,9 +33,9 @@ pub fn quit() -> anyhow::Result<()> {
std::fs::File::open(pidfile)?.read_to_string(&mut pid)?;
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)
- }),
+ tty: nix::unistd::ttyname(std::io::stdin()).ok().and_then(
+ |p| p.to_str().map(std::string::ToString::to_string),
+ ),
action: rbw::protocol::Action::Quit,
})?;
wait_for_exit(pid);
@@ -57,7 +57,7 @@ pub fn decrypt(
) -> anyhow::Result<String> {
let mut sock = connect()?;
sock.send(&rbw::protocol::Request {
- tty: nix::unistd::ttyname(0)
+ tty: nix::unistd::ttyname(std::io::stdin())
.ok()
.and_then(|p| p.to_str().map(std::string::ToString::to_string)),
action: rbw::protocol::Action::Decrypt {
@@ -82,7 +82,7 @@ pub fn encrypt(
) -> anyhow::Result<String> {
let mut sock = connect()?;
sock.send(&rbw::protocol::Request {
- tty: nix::unistd::ttyname(0)
+ tty: nix::unistd::ttyname(std::io::stdin())
.ok()
.and_then(|p| p.to_str().map(std::string::ToString::to_string)),
action: rbw::protocol::Action::Encrypt {
@@ -110,7 +110,7 @@ pub fn clipboard_store(text: &str) -> anyhow::Result<()> {
pub fn version() -> anyhow::Result<u32> {
let mut sock = connect()?;
sock.send(&rbw::protocol::Request {
- tty: nix::unistd::ttyname(0)
+ tty: nix::unistd::ttyname(std::io::stdin())
.ok()
.and_then(|p| p.to_str().map(std::string::ToString::to_string)),
action: rbw::protocol::Action::Version,
@@ -130,7 +130,7 @@ fn simple_action(action: rbw::protocol::Action) -> anyhow::Result<()> {
let mut sock = connect()?;
sock.send(&rbw::protocol::Request {
- tty: nix::unistd::ttyname(0)
+ tty: nix::unistd::ttyname(std::io::stdin())
.ok()
.and_then(|p| p.to_str().map(std::string::ToString::to_string)),
action,