summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJoakim Hulthe <joakim@hulthe.net>2024-03-20 14:14:15 +0100
committerJoakim Hulthe <joakim@hulthe.net>2024-03-21 15:03:43 +0100
commitc839f8ffa533d0669f07753597ef743a14f052df (patch)
treede2a9d74fe10c989130eba56d882b16cbe5e609f
parentcd16808d188f32739e09cab005408c774c9c60ef (diff)
downloadmullvadvpn-c839f8ffa533d0669f07753597ef743a14f052df.tar.xz
mullvadvpn-c839f8ffa533d0669f07753597ef743a14f052df.zip
Do uniqueness check when starting windows service
-rw-r--r--mullvad-daemon/src/main.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs
index 1dc194ef6a..a8f4d6ecc4 100644
--- a/mullvad-daemon/src/main.rs
+++ b/mullvad-daemon/src/main.rs
@@ -48,10 +48,9 @@ fn run() -> Result<(), String> {
match config.command {
cli::Command::Daemon => {
- if runtime.block_on(rpc_uniqueness_check::is_another_instance_running()) {
- return Err("Another instance of the daemon is already running".into());
- }
-
+ // uniqueness check must happen before logging initializaton,
+ // as initializing logs will rotate any existing log file.
+ runtime.block_on(assert_unique())?;
let log_dir = init_daemon_logging(config)?;
log::trace!("Using configuration: {:?}", config);
@@ -70,6 +69,7 @@ fn run() -> Result<(), String> {
#[cfg(target_os = "windows")]
cli::Command::RunAsService => {
init_logger(config, None)?;
+ runtime.block_on(assert_unique())?;
system_service::run()
}
@@ -88,6 +88,14 @@ fn run() -> Result<(), String> {
}
}
+/// Check that there's not another daemon currently running.
+async fn assert_unique() -> Result<(), &'static str> {
+ if rpc_uniqueness_check::is_another_instance_running().await {
+ return Err("Another instance of the daemon is already running");
+ }
+ Ok(())
+}
+
/// Initialize logging to stderr and to file (if configured).
fn init_daemon_logging(config: &cli::Config) -> Result<Option<PathBuf>, String> {
let log_dir = get_log_dir(config)?;