diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-07-17 14:24:42 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-07-17 14:24:42 +0200 |
| commit | a388b166c6617fb6899a3d6156f481fbc1ae0bdb (patch) | |
| tree | 3a616470fb02245b75e6ee8191cace791f6aa32c | |
| parent | 0d5827f2d9be38e7c48deed7427feb189f13fcd6 (diff) | |
| parent | 04e514b6f452e13602e33d57f8ae262348d15a6b (diff) | |
| download | mullvadvpn-a388b166c6617fb6899a3d6156f481fbc1ae0bdb.tar.xz mullvadvpn-a388b166c6617fb6899a3d6156f481fbc1ae0bdb.zip | |
Merge branch 'notify-scm-on-init-error'
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | mullvad-daemon/src/system_service.rs | 25 |
2 files changed, 16 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 10c76b6b7a..8c471a2a16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,8 @@ Line wrap the file at 100 chars. Th - Hide the app icon from taskbar. - Autohide the main window on focus loss. - Loosen up firewall rules to allow incoming requests on tunnel interface. +- Properly stop the service, announcing errors to the system, in the event of initialization or + runtime error. ## [2018.2-beta1] - 2018-07-02 diff --git a/mullvad-daemon/src/system_service.rs b/mullvad-daemon/src/system_service.rs index 6c2098b1ce..5f3b1299b4 100644 --- a/mullvad-daemon/src/system_service.rs +++ b/mullvad-daemon/src/system_service.rs @@ -43,7 +43,6 @@ pub fn handle_service_main(arguments: Vec<OsString>) { } fn run_service(_arguments: Vec<OsString>) -> Result<()> { - let config = cli::get_config(); let (event_tx, event_rx) = mpsc::channel(); // Register service event handler @@ -68,20 +67,24 @@ fn run_service(_arguments: Vec<OsString>) -> Result<()> { .set_pending_start(Duration::from_secs(1)) .unwrap(); - let daemon = ::create_daemon(config)?; - let shutdown_handle = daemon.shutdown_handle(); + let config = cli::get_config(); + let result = ::create_daemon(config).and_then(|daemon| { + let shutdown_handle = daemon.shutdown_handle(); - // Register monitor that translates `ServiceControl` to Daemon events - start_event_monitor(persistent_service_status.clone(), shutdown_handle, event_rx); + // Register monitor that translates `ServiceControl` to Daemon events + start_event_monitor(persistent_service_status.clone(), shutdown_handle, event_rx); - persistent_service_status.set_running().unwrap(); + persistent_service_status.set_running().unwrap(); - let result = daemon.run(); + daemon.run() + }); - // TODO: report correct exit code back after running a daemon. - persistent_service_status - .set_stopped(ServiceExitCode::default()) - .unwrap(); + let exit_code = match result { + Ok(_) => ServiceExitCode::default(), + Err(_) => ServiceExitCode::ServiceSpecific(1), + }; + + persistent_service_status.set_stopped(exit_code).unwrap(); result } |
