diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-05-02 08:51:10 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-05-09 09:55:32 -0300 |
| commit | 48a9fa0d3d6386a8dc1dbf10c5b3d04d7a9a40b7 (patch) | |
| tree | eee48408ceb782a3eb761ba25a1162e82c0eed4c | |
| parent | 7ec89cd6874695563d27cb62305e2f54b09cc100 (diff) | |
| download | mullvadvpn-48a9fa0d3d6386a8dc1dbf10c5b3d04d7a9a40b7.tar.xz mullvadvpn-48a9fa0d3d6386a8dc1dbf10c5b3d04d7a9a40b7.zip | |
Use program data directory for logs on Windows
Also use the same log file names as on other platforms.
| -rw-r--r-- | mullvad-daemon/src/main.rs | 7 | ||||
| -rw-r--r-- | mullvad-daemon/src/system_service.rs | 32 |
2 files changed, 26 insertions, 13 deletions
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index e0059b2091..a4c2eb1466 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -95,6 +95,10 @@ error_chain!{ NoCacheDir { description("Unable to create cache directory") } + #[cfg(windows)] + NoLogDir { + description("Unable to create log directory") + } DaemonIsAlreadyRunning { description("Another instance of the daemon is already running") } @@ -135,6 +139,9 @@ static APP_INFO: AppInfo = AppInfo { author: "Mullvad", }; +#[cfg(windows)] +static PRODUCT_NAME: &str = "Mullvad VPN"; + /// All events that can happen in the daemon. Sent from various threads and exposed interfaces. pub enum DaemonEvent { diff --git a/mullvad-daemon/src/system_service.rs b/mullvad-daemon/src/system_service.rs index af170247d1..a141b2a191 100644 --- a/mullvad-daemon/src/system_service.rs +++ b/mullvad-daemon/src/system_service.rs @@ -1,7 +1,8 @@ #![cfg(windows)] use std::ffi::OsString; -use std::path::PathBuf; +use std::fs; +use std::path::Path; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{mpsc, Arc}; use std::time::Duration; @@ -19,7 +20,7 @@ use windows_service::service_control_handler::{ use windows_service::service_dispatcher; use windows_service::service_manager::{ServiceManager, ServiceManagerAccess}; -use super::{get_resource_dir, Daemon, DaemonShutdownHandle, Result, ResultExt}; +use super::{get_resource_dir, Daemon, DaemonShutdownHandle, ErrorKind, Result, ResultExt}; static SERVICE_NAME: &'static str = "MullvadVPN"; static SERVICE_DISPLAY_NAME: &'static str = "Mullvad VPN Service"; @@ -216,21 +217,26 @@ pub fn install_service() -> Result<()> { let service_manager = ServiceManager::local_computer(None::<&str>, manager_access) .chain_err(|| "Unable to connect to service manager")?; service_manager - .create_service(get_service_info(), ServiceAccess::empty()) + .create_service(get_service_info()?, ServiceAccess::empty()) .map(|_| ()) .chain_err(|| "Unable to create a service") } -fn get_service_info() -> ServiceInfo { - let windows_directory = ::std::env::var_os("WINDIR").unwrap(); - let service_log_file = PathBuf::from(&windows_directory) - .join("Temp") - .join("mullvad-service.log"); - let tunnel_log_file = PathBuf::from(&windows_directory) - .join("Temp") - .join("mullvad-openvpn.log"); +fn get_service_info() -> Result<ServiceInfo> { + let program_data_directory_string = + ::std::env::var_os("ALLUSERSPROFILE").ok_or_else(|| ErrorKind::NoLogDir)?; + let program_data_directory = Path::new(&program_data_directory_string); + let log_directory = program_data_directory.join(::PRODUCT_NAME); + let service_log_file = log_directory.join("backend.log"); + let tunnel_log_file = log_directory.join("openvpn.log"); - ServiceInfo { + if let Err(error) = fs::create_dir(log_directory) { + if error.kind() != io::ErrorKind::AlreadyExists { + return Err(error).chain_err(|| ErrorKind::NoLogDir); + } + } + + Ok(ServiceInfo { name: OsString::from(SERVICE_NAME), display_name: OsString::from(SERVICE_DISPLAY_NAME), service_type: SERVICE_TYPE, @@ -247,5 +253,5 @@ fn get_service_info() -> ServiceInfo { ], account_name: None, // run as System account_password: None, - } + }) } |
