Skip to content

Commit e578e73

Browse files
committed
single_instance: upgrade dependencies
1 parent 8ea4add commit e578e73

4 files changed

Lines changed: 19 additions & 27 deletions

File tree

Cargo.lock

Lines changed: 9 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ indexmap = { version = "2" }
7676
libc = "0.2"
7777
memchr = "2"
7878
mime = "0.3"
79+
nix = { version = "0.31", features = ["socket"] }
7980
nom = "7"
8081
paste = { git = "https://github.com/dtolnay/paste", ref = "6a302522990cbfd9de4e0c61d91854622f7b2999" }
8182
rand = "0.9"

single_instance/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ path = "./single_instance.rs"
1010
thiserror = { workspace = true }
1111

1212
[target.'cfg(unix)'.dependencies]
13-
libc = "0.2"
14-
nix = { version = "0.23.0" }
13+
libc = { workspace = true }
14+
nix = { workspace = true }

single_instance/single_instance.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,15 @@ pub use self::inner::*;
4444

4545
#[cfg(any(target_os = "linux", target_os = "android"))]
4646
mod inner {
47-
use std::os::unix::prelude::RawFd;
47+
use std::os::unix::io::{AsRawFd, OwnedFd};
4848

49-
use nix::{
50-
sys::socket::{self, UnixAddr},
51-
unistd,
52-
};
49+
use nix::sys::socket::{self, UnixAddr};
5350

5451
use super::Error;
5552

5653
/// A struct representing one running instance.
5754
pub struct SingleInstance {
58-
maybe_sock: Option<RawFd>,
55+
maybe_sock: Option<OwnedFd>,
5956
}
6057

6158
impl SingleInstance {
@@ -71,7 +68,7 @@ mod inner {
7168
None,
7269
)?;
7370

74-
let maybe_sock = match socket::bind(sock, &socket::SockAddr::Unix(addr)) {
71+
let maybe_sock = match socket::bind(sock.as_raw_fd(), &addr) {
7572
Ok(()) => Some(sock),
7673
Err(nix::errno::Errno::EADDRINUSE) => None,
7774
Err(e) => return Err(e.into()),
@@ -90,9 +87,9 @@ mod inner {
9087

9188
impl Drop for SingleInstance {
9289
fn drop(&mut self) {
93-
if let Some(sock) = self.maybe_sock {
94-
// Intentionally discard any close errors.
95-
let _ = unistd::close(sock);
90+
// OwnedFd closes the file descriptor automatically on drop.
91+
if let Some(sock) = self.maybe_sock.take() {
92+
drop(sock);
9693
}
9794
}
9895
}

0 commit comments

Comments
 (0)