From 8dc946ae953c7d0d3f9c6c90c0aa78d6f17e0cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sat, 28 Nov 2020 02:35:29 +0100 Subject: check if mumd instance is running before starting --- mumd/src/main.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'mumd/src') 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::>>().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::(1); // crypt state should always be consumed before sending a new one -- cgit v1.2.1