diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-11-28 02:35:29 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-11-28 02:35:29 +0100 |
| commit | 8dc946ae953c7d0d3f9c6c90c0aa78d6f17e0cf9 (patch) | |
| tree | 5ca3f3301971ff431a4be7f4f6def3889decd75c /mumd | |
| parent | ca6e909df09131e9e73f7089f43cdd459d24fd7b (diff) | |
| download | mum-8dc946ae953c7d0d3f9c6c90c0aa78d6f17e0cf9.tar.gz | |
check if mumd instance is running before starting
Diffstat (limited to 'mumd')
| -rw-r--r-- | mumd/src/main.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/mumd/src/main.rs b/mumd/src/main.rs index b83299f..c0caa77 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -8,7 +8,7 @@ use crate::network::ConnectionInfo; use crate::state::State; use futures::join; -use ipc_channel::ipc::{IpcOneShotServer, IpcSender}; +use ipc_channel::ipc::{self, IpcOneShotServer, IpcSender}; use log::*; use mumble_protocol::control::ControlPacket; use mumble_protocol::crypt::ClientCryptState; @@ -25,6 +25,22 @@ async fn main() { setup_logger(std::io::stderr(), true); notify::init(); + // check if another instance is live + let (tx_client, rx_client) = + ipc::channel::<mumlib::error::Result<Option<CommandResponse>>>().unwrap(); + if let Ok(server_name) = fs::read_to_string(mumlib::SOCKET_PATH) { + if let Ok(tx0) = IpcSender::connect(server_name) { + if tx0.send((Command::Ping, tx_client)).is_ok() { + if matches!(rx_client.recv().unwrap(), Ok(Some(CommandResponse::Pong))) { + error!("Another instance of mumd is already running"); + return; + } else { + warn!("Ping with no response. Continuing..."); + } + } + } + } + // Oneshot channel for setting UDP CryptState from control task // For simplicity we don't deal with re-syncing, real applications would have to. let (crypt_state_sender, crypt_state_receiver) = mpsc::channel::<ClientCryptState>(1); // crypt state should always be consumed before sending a new one |
