diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2018-05-17 02:51:49 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2018-05-18 15:28:07 +0200 |
| commit | ecf2bee1359594a9dbc1c9860b8558f631ec9548 (patch) | |
| tree | d342efca18f432a9e125635559a4044aa6f64228 | |
| parent | 2f6ff40339c506620efbacb45ba648351467057b (diff) | |
| download | mullvadvpn-ecf2bee1359594a9dbc1c9860b8558f631ec9548.tar.xz mullvadvpn-ecf2bee1359594a9dbc1c9860b8558f631ec9548.zip | |
Add --cache-dir argument to daemon
| -rw-r--r-- | mullvad-daemon/src/cli.rs | 10 | ||||
| -rw-r--r-- | mullvad-daemon/src/main.rs | 15 | ||||
| -rw-r--r-- | mullvad-daemon/src/system_service.rs | 8 |
3 files changed, 27 insertions, 6 deletions
diff --git a/mullvad-daemon/src/cli.rs b/mullvad-daemon/src/cli.rs index 4d424a31f2..1ee12d7b2f 100644 --- a/mullvad-daemon/src/cli.rs +++ b/mullvad-daemon/src/cli.rs @@ -10,6 +10,7 @@ pub struct Config { pub log_file: Option<PathBuf>, pub tunnel_log_file: Option<PathBuf>, pub resource_dir: Option<PathBuf>, + pub cache_dir: Option<PathBuf>, pub log_stdout_timestamps: bool, pub run_as_service: bool, pub register_service: bool, @@ -27,6 +28,7 @@ pub fn get_config() -> Config { let log_file = matches.value_of_os("log_file").map(PathBuf::from); let tunnel_log_file = matches.value_of_os("tunnel_log_file").map(PathBuf::from); let resource_dir = matches.value_of_os("resource_dir").map(PathBuf::from); + let cache_dir = matches.value_of_os("cache_dir").map(PathBuf::from); let log_stdout_timestamps = !matches.is_present("disable_stdout_timestamps"); let run_as_service = cfg!(windows) && matches.is_present("run_as_service"); @@ -37,6 +39,7 @@ pub fn get_config() -> Config { log_file, tunnel_log_file, resource_dir, + cache_dir, log_stdout_timestamps, run_as_service, register_service, @@ -76,6 +79,13 @@ fn create_app() -> App<'static, 'static> { .help("Uses the given directory to read needed resources, such as certificates."), ) .arg( + Arg::with_name("cache_dir") + .long("cache-dir") + .takes_value(true) + .value_name("DIR") + .help("Uses the given directory to read and write cache."), + ) + .arg( Arg::with_name("disable_stdout_timestamps") .long("disable-stdout-timestamps") .help("Don't log timestamps when logging to stdout, useful when running as a systemd service") diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index 463b4173fe..14a8fe8067 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -217,13 +217,16 @@ struct Daemon { } impl Daemon { - pub fn new(tunnel_log: Option<PathBuf>, resource_dir: PathBuf) -> Result<Self> { + pub fn new( + tunnel_log: Option<PathBuf>, + resource_dir: PathBuf, + cache_dir: PathBuf, + ) -> Result<Self> { ensure!( !rpc_uniqueness_check::is_another_instance_running(), ErrorKind::DaemonIsAlreadyRunning ); - let cache_dir = cache::get_cache_dir()?; let mut rpc_manager = mullvad_rpc::MullvadRpcFactory::with_cache_dir(&cache_dir); let (rpc_handle, http_handle, tokio_remote) = @@ -243,7 +246,6 @@ impl Daemon { let (tx, rx) = mpsc::channel(); let management_interface_broadcaster = Self::start_management_interface(tx.clone(), cache_dir)?; - let state = TunnelState::NotRunning; let target_state = TargetState::Unsecured; Ok(Daemon { @@ -890,7 +892,12 @@ fn run_standalone(config: cli::Config) -> Result<()> { } let resource_dir = config.resource_dir.unwrap_or_else(|| get_resource_dir()); - let daemon = Daemon::new(config.tunnel_log_file, resource_dir) + let cache_dir = match config.cache_dir { + Some(cache_dir) => cache_dir, + None => cache::get_cache_dir()?, + }; + + let daemon = Daemon::new(config.tunnel_log_file, resource_dir, cache_dir) .chain_err(|| "Unable to initialize daemon")?; let shutdown_handle = daemon.shutdown_handle(); diff --git a/mullvad-daemon/src/system_service.rs b/mullvad-daemon/src/system_service.rs index 0bee0cba24..0cc53f3522 100644 --- a/mullvad-daemon/src/system_service.rs +++ b/mullvad-daemon/src/system_service.rs @@ -72,8 +72,12 @@ fn run_service(_arguments: Vec<OsString>) -> Result<()> { .set_pending_start(Duration::from_secs(1)) .unwrap(); - let resource_dir = get_resource_dir(); - let daemon = Daemon::new(config.tunnel_log_file, resource_dir) + let resource_dir = config.resource_dir.unwrap_or_else(|| get_resource_dir()); + let cache_dir = match config.cache_dir { + Some(cache_dir) => cache_dir, + None => ::cache::get_cache_dir()?, + }; + let daemon = Daemon::new(config.tunnel_log_file, resource_dir, cache_dir) .chain_err(|| "Unable to initialize daemon")?; let shutdown_handle = daemon.shutdown_handle(); |
