1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2025-04-14 17:53:03 -04:00

Error when failed to create socket with --daemon

The daemon without socket is not that useful.
This commit is contained in:
Kirill Chibisov 2025-01-14 00:03:52 +03:00 committed by GitHub
parent 05368ea6a7
commit bc3b7a2c1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 10 deletions

View file

@ -10,6 +10,10 @@ Notable changes to the `alacritty_terminal` crate are documented in its
## 0.16.0-dev
### Changed
- Error out when socket fails to create with `--daemon`
## 0.15.0
### Added

View file

@ -19,7 +19,10 @@ use crate::event::{Event, EventType};
const ALACRITTY_SOCKET_ENV: &str = "ALACRITTY_SOCKET";
/// Create an IPC socket.
pub fn spawn_ipc_socket(options: &Options, event_proxy: EventLoopProxy<Event>) -> Option<PathBuf> {
pub fn spawn_ipc_socket(
options: &Options,
event_proxy: EventLoopProxy<Event>,
) -> IoResult<PathBuf> {
// Create the IPC socket and export its path as env.
let socket_path = options.socket.clone().unwrap_or_else(|| {
@ -28,13 +31,7 @@ pub fn spawn_ipc_socket(options: &Options, event_proxy: EventLoopProxy<Event>) -
path
});
let listener = match UnixListener::bind(&socket_path) {
Ok(listener) => listener,
Err(err) => {
warn!("Unable to create socket: {:?}", err);
return None;
},
};
let listener = UnixListener::bind(&socket_path)?;
env::set_var(ALACRITTY_SOCKET_ENV, socket_path.as_os_str());
if options.daemon {
@ -80,7 +77,7 @@ pub fn spawn_ipc_socket(options: &Options, event_proxy: EventLoopProxy<Event>) -
}
});
Some(socket_path)
Ok(socket_path)
}
/// Send a message to the active Alacritty socket.

View file

@ -183,7 +183,14 @@ fn alacritty(mut options: Options) -> Result<(), Box<dyn Error>> {
// Create the IPC socket listener.
#[cfg(unix)]
let socket_path = if config.ipc_socket() {
ipc::spawn_ipc_socket(&options, window_event_loop.create_proxy())
match ipc::spawn_ipc_socket(&options, window_event_loop.create_proxy()) {
Ok(path) => Some(path),
Err(err) if options.daemon => return Err(err.into()),
Err(err) => {
log::warn!("Unable to create socket: {:?}", err);
None
},
}
} else {
None
};