diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2019-07-22 20:09:36 +0100 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2019-07-25 18:05:50 +0100 |
| commit | 63fce125ca7d13727374ed2a12aaf4c478b0cb83 (patch) | |
| tree | 95238fc3204f912aabf3d5b1ef71ef70875093eb | |
| parent | 6fc6930756bde3be42c38526f514d94efac55e72 (diff) | |
| download | mullvadvpn-63fce125ca7d13727374ed2a12aaf4c478b0cb83.tar.xz mullvadvpn-63fce125ca7d13727374ed2a12aaf4c478b0cb83.zip | |
Add shutdown callbacks to daemon
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 5a1901e941..076ef3341c 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -238,6 +238,7 @@ pub struct Daemon<L: EventListener = ManagementInterfaceEventBroadcaster> { last_generated_relay: Option<Relay>, last_generated_bridge_relay: Option<Relay>, version: String, + shutdown_callbacks: Vec<Box<dyn FnOnce()>>, } impl Daemon<ManagementInterfaceEventBroadcaster> { @@ -416,6 +417,7 @@ where last_generated_bridge_relay: None, version, wireguard_key_manager, + shutdown_callbacks: vec![], }; daemon.ensure_wireguard_keys_for_current_account(); @@ -442,6 +444,9 @@ where break; } } + for cb in self.shutdown_callbacks.into_iter() { + cb(); + } Ok(()) } @@ -970,9 +975,11 @@ where // Shut the daemon down. self.trigger_shutdown_event(); - if !failed { - Self::oneshot_send(tx, (), "factory_reset response"); - } + self.shutdown_callbacks.push(Box::new(move || { + if !failed { + Self::oneshot_send(tx, (), "factory_reset response"); + } + })); } fn on_update_relay_settings(&mut self, tx: oneshot::Sender<()>, update: RelaySettingsUpdate) { |
