From cedf60155e95de5c0b1d57838842b4d0509e79ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Fri, 15 Oct 2021 02:59:13 +0200 Subject: [PATCH] aquatic_udp: add privdrop failsafe timeout --- aquatic_udp/src/lib/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/aquatic_udp/src/lib/lib.rs b/aquatic_udp/src/lib/lib.rs index 4322006..b44bb33 100644 --- a/aquatic_udp/src/lib/lib.rs +++ b/aquatic_udp/src/lib/lib.rs @@ -26,6 +26,8 @@ pub fn run(config: Config) -> ::anyhow::Result<()> { let num_bound_sockets = start_workers(config.clone(), state.clone())?; if config.privileges.drop_privileges { + let mut counter = 0usize; + loop { let sockets = num_bound_sockets.load(Ordering::SeqCst); @@ -39,6 +41,12 @@ pub fn run(config: Config) -> ::anyhow::Result<()> { } ::std::thread::sleep(Duration::from_millis(10)); + + counter += 1; + + if counter == 500 { + panic!("Sockets didn't bind in time for privilege drop."); + } } }