Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
daemon: Display error message when binding to locked socket
Browse files Browse the repository at this point in the history
  • Loading branch information
Profpatsch committed May 29, 2019
1 parent a5f0696 commit b94bf20
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/ops/daemon.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Run a BuildLoop for `shell.nix`, watching for input file changes.
//! Can be used together with `direnv`.
use crate::build_loop::{self, BuildLoop};
use crate::ops::{ok, OpResult};
use crate::ops::{ok, ExitError, OpResult};
use crate::project::Project;
use crate::roots::Roots;
use crate::socket::communicate::listener;
Expand All @@ -27,9 +27,14 @@ pub struct StartBuild {
pub fn main() -> OpResult {
let socket_path = ::socket::path::SocketPath::from(Path::new(SOCKET_FILE_NAME));
// TODO: move listener into Daemon struct?
let listener = listener::Listener::new(&socket_path)
// TODO
.unwrap();
let listener = listener::Listener::new(&socket_path).map_err(|e| match e {
::socket::path::BindError::OtherProcessListening => ExitError::errmsg(format!(
"Another daemon is already listening on the socket at {}.",
socket_path.display()
)),
e => panic!(e),
})?;

// TODO: set up socket path, make it settable by the user
let (mut daemon, build_messages_rx) = Daemon::new();

Expand Down Expand Up @@ -120,7 +125,7 @@ pub fn ping(rw: ReadWriter<Ping, NoMessage>, build_chan: mpsc::Sender<StartBuild
// TODO: read timeout
let ping: Result<Ping, ReadError> = rw.read(&Timeout::Infinite);
match ping {
Err(e) => eprintln!("didn’t receive a ping!! {:?}", e),
Err(e) => debug!("didn’t receive a ping!! {:?}", e),
Ok(p) => {
eprintln!("pinged with {}", p.nix_file.display());
build_chan
Expand Down
1 change: 1 addition & 0 deletions src/socket/communicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::socket::{ReadWriteError, ReadWriter, Timeout};
#[derive(Serialize, Deserialize)]
pub enum CommunicationType {
/// Ping the daemon from a project to tell it to watch & evaluate
// TODO: rename to BuildProject or something?
Ping,
// /// Listen for events on the daemon
// DaemonListener,
Expand Down
5 changes: 5 additions & 0 deletions src/socket/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ impl<'a> SocketPath<'a> {
SocketPath(socket_path)
}

/// Display the underlying `Path`.
pub fn display(&self) -> std::path::Display {
self.0.display()
}

/// Return lockfile path.
pub fn lockfile(&self) -> PathBuf {
self.0.with_file_name({
Expand Down

0 comments on commit b94bf20

Please sign in to comment.