mirror of
https://github.com/usestrix/firewall.git
synced 2026-11-09 18:08:49 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2d9062ba3 |
No files matched your search
@@ -26,6 +26,7 @@ use std::net::{IpAddr, Ipv4Addr};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tracing_appender::rolling::{RollingFileAppender, Rotation};
|
use tracing_appender::rolling::{RollingFileAppender, Rotation};
|
||||||
|
use windows::Win32::Foundation::ERROR_GEN_FAILURE;
|
||||||
use windows_service::service::*;
|
use windows_service::service::*;
|
||||||
use windows_service::service_control_handler::{
|
use windows_service::service_control_handler::{
|
||||||
self, ServiceControlHandlerResult, ServiceStatusHandle,
|
self, ServiceControlHandlerResult, ServiceStatusHandle,
|
||||||
@@ -73,8 +74,12 @@ fn run_until_stopped() -> Result<(), BoxError> {
|
|||||||
| ServiceControl::Shutdown
|
| ServiceControl::Shutdown
|
||||||
| ServiceControl::Pause
|
| ServiceControl::Pause
|
||||||
| ServiceControl::Continue => {
|
| ServiceControl::Continue => {
|
||||||
let _ = control_sender.send(control);
|
// Answered once handled, so a failed pause fails the caller's ControlService.
|
||||||
ServiceControlHandlerResult::NoError
|
let (reply, handled) = tokio::sync::oneshot::channel();
|
||||||
|
let _ = control_sender.send((control, reply));
|
||||||
|
handled
|
||||||
|
.blocking_recv()
|
||||||
|
.unwrap_or(ServiceControlHandlerResult::NoError)
|
||||||
}
|
}
|
||||||
ServiceControl::Interrogate => ServiceControlHandlerResult::NoError,
|
ServiceControl::Interrogate => ServiceControlHandlerResult::NoError,
|
||||||
_ => ServiceControlHandlerResult::NotImplemented,
|
_ => ServiceControlHandlerResult::NotImplemented,
|
||||||
@@ -89,16 +94,26 @@ fn run_until_stopped() -> Result<(), BoxError> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Only pausing removes our hosts entries; a stop or crash keeps them, failing closed.
|
// Only pausing removes our hosts entries; a stop or crash keeps them, failing closed.
|
||||||
while let Some(control) = control_receiver.recv().await {
|
while let Some((control, reply)) = control_receiver.recv().await {
|
||||||
let (hosts, state) = match control {
|
let (hosts, state) = match control {
|
||||||
ServiceControl::Pause => (&[][..], ServiceState::Paused),
|
ServiceControl::Pause => (&[][..], ServiceState::Paused),
|
||||||
ServiceControl::Continue => (&hosts[..], ServiceState::Running),
|
ServiceControl::Continue => (&hosts[..], ServiceState::Running),
|
||||||
_ => break,
|
_ => break,
|
||||||
};
|
};
|
||||||
match write_hosts_entries(hosts) {
|
let result = match write_hosts_entries(hosts) {
|
||||||
Ok(()) => set_status(&status, state, false)?,
|
Ok(()) => {
|
||||||
Err(error) => tracing::error!(%error, "could not rewrite the hosts file"),
|
set_status(&status, state, false)?;
|
||||||
}
|
ServiceControlHandlerResult::NoError
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
tracing::error!(%error, "could not rewrite the hosts file");
|
||||||
|
let code = error
|
||||||
|
.raw_os_error()
|
||||||
|
.map_or(ERROR_GEN_FAILURE.0, |code| code as u32);
|
||||||
|
ServiceControlHandlerResult::Other(code)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let _ = reply.send(result);
|
||||||
}
|
}
|
||||||
Ok::<_, BoxError>(())
|
Ok::<_, BoxError>(())
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -144,7 +144,11 @@ impl Tray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show_error(error: BoxError) {
|
fn show_error(error: BoxError) {
|
||||||
let text = HSTRING::from(error.to_string());
|
let text = match error.source() {
|
||||||
|
Some(source) => format!("{error}: {source}"),
|
||||||
|
None => error.to_string(),
|
||||||
|
};
|
||||||
|
let text = HSTRING::from(text);
|
||||||
unsafe { MessageBoxW(None, &text, w!("Strix Firewall"), MB_ICONERROR) };
|
unsafe { MessageBoxW(None, &text, w!("Strix Firewall"), MB_ICONERROR) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user