summaryrefslogtreecommitdiffhomepage
path: root/mullvad-daemon/src/rpc_uniqueness_check.rs
blob: 76d524c7652c6fd1b942c1a7a745e6b2aea66508 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use mullvad_management_interface::new_rpc_client;
use talpid_types::ErrorExt;

/// Checks if there is another instance of the daemon running.
///
/// Tries to connect to another daemon and perform a simple RPC call. If it fails, assumes the
/// other daemon has stopped.
pub async fn is_another_instance_running() -> bool {
    match new_rpc_client().await {
        Ok(_) => true,
        Err(error) => {
            let msg =
                "Failed to locate/connect to another daemon instance, assuming there isn't one";
            if log::log_enabled!(log::Level::Trace) {
                log::trace!("{}\n{}", msg, error.display_chain());
            } else {
                log::debug!("{}", msg);
            }
            false
        }
    }
}