summaryrefslogtreecommitdiffhomepage
path: root/mullvad-daemon/src/rpc_uniqueness_check.rs
blob: 89e08eb47f885f93dc4b7df39b21df87e180b3fb (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::MullvadProxyClient;
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 MullvadProxyClient::new().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
        }
    }
}