diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-07-02 10:03:36 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-07-02 10:03:36 -0300 |
| commit | e314782c8407e2c14c834e2a75f4854a37a172c7 (patch) | |
| tree | f9067afb33553594415e4bc7f69113c7788db67b | |
| parent | b559a99f5d171bd4c271741dda675e6eb9baa5bc (diff) | |
| parent | 0ce53bd8b9db3c57922a54be2a2a4d11deab51d6 (diff) | |
| download | mullvadvpn-e314782c8407e2c14c834e2a75f4854a37a172c7.tar.xz mullvadvpn-e314782c8407e2c14c834e2a75f4854a37a172c7.zip | |
Merge branch 'log-init-errors'
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | mullvad-daemon/src/main.rs | 29 |
2 files changed, 23 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 10714c0d76..7d33d0a0b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Line wrap the file at 100 chars. Th - Automatic rotation of the daemon log. The existing log is renamed to `daemon.old.log` on daemon startup. - Add `status listen` subcommand in the CLI to continuously monitor the tunnel state. +- Log errors present in initialization sequence to the log file. #### macOS - Add colors to terminal output. diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index 37bfcb56a9..d5e50f88b0 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -85,13 +85,13 @@ use talpid_types::net::{TunnelEndpoint, TunnelEndpointData, TunnelOptions}; error_chain!{ errors { + LogError(msg: &'static str) { + description("Error setting up log") + display("Error setting up log: {}", msg) + } 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") } @@ -834,12 +834,27 @@ impl Drop for Daemon { } -quick_main!(run); +fn main() { + ::std::process::exit(match run() { + Ok(_) => 0, + Err(error) => { + if let &ErrorKind::LogError(_) = error.kind() { + eprintln!("{}", error.display_chain()); + } else { + error!("{}", error.display_chain()); + } + 1 + } + }); +} fn run() -> Result<()> { let config = cli::get_config(); let log_dir = if config.log_to_file { - Some(mullvad_paths::log_dir().chain_err(|| "Unable to get log directory")?) + Some( + mullvad_paths::log_dir() + .chain_err(|| ErrorKind::LogError("Unable to get log directory"))?, + ) } else { None }; @@ -849,7 +864,7 @@ fn run() -> Result<()> { config.log_level, log_file.as_ref(), config.log_stdout_timestamps, - ).chain_err(|| "Unable to initialize logger")?; + ).chain_err(|| ErrorKind::LogError("Unable to initialize logger"))?; log_version(); if let Some(ref log_dir) = log_dir { info!("Logging to {}", log_dir.display()); |
