Skip to content

Commit 175d841

Browse files
committed
Canonicalize socket path
1 parent b1dba49 commit 175d841

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎src/start.rs‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::pin::Pin;
55
use core::task::{Context, Poll};
66
use std::os::unix::net::UnixListener as StdUnixListener;
77
use std::path::PathBuf;
8-
use std::{io, process};
8+
use std::{fs, io, process};
99

1010
use async_compat::Compat;
1111
use futures::Stream;
@@ -33,6 +33,7 @@ pub struct StartArgs {
3333

3434
enum StartError {
3535
BindSocket(io::Error),
36+
CanonicalizeSocketPath(PathBuf, io::Error),
3637
ConnectToCache(CacheConnectError),
3738
CreatePipe(nix::Error),
3839
DaemonDidntStart,
@@ -81,9 +82,14 @@ fn start_inner(args: StartArgs) -> Result<(), StartError> {
8182
Ok(_more_than_one) => unreachable!("child writes 1 byte"),
8283
}
8384

85+
let socket_path =
86+
fs::canonicalize(&args.socket).map_err(|err| {
87+
StartError::CanonicalizeSocketPath(args.socket, err)
88+
})?;
89+
8490
println!(
8591
"Started daemon with process ID {child}, listening on {}",
86-
args.socket.display()
92+
socket_path.display()
8793
);
8894
},
8995

@@ -163,6 +169,13 @@ impl fmt::Display for StartError {
163169
Self::BindSocket(io_error) => {
164170
write!(f, "Couldn't bind to Unix domain socket: {io_error}")
165171
},
172+
Self::CanonicalizeSocketPath(path, io_err) => {
173+
write!(
174+
f,
175+
"Couldn't canonicalize '{}': {io_err}",
176+
path.display()
177+
)
178+
},
166179
Self::ConnectToCache(error) => error.fmt(f),
167180
Self::CreatePipe(error) => {
168181
write!(f, "Couldn't create pipe: {error}")

0 commit comments

Comments
 (0)