mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 02:35:31 +00:00
udp, http: move privilege drop code into aquatic_common
This commit is contained in:
parent
ead7650d41
commit
d6d5cc78b7
11 changed files with 72 additions and 87 deletions
|
|
@ -16,7 +16,6 @@ pub mod glommio;
|
|||
pub mod mio;
|
||||
|
||||
use config::Config;
|
||||
use privdrop::PrivDrop;
|
||||
|
||||
pub const APP_NAME: &str = "aquatic_udp: UDP BitTorrent tracker";
|
||||
|
||||
|
|
@ -28,36 +27,4 @@ pub fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
mio::run(config)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn drop_privileges_after_socket_binding(
|
||||
config: &Config,
|
||||
num_bound_sockets: Arc<AtomicUsize>,
|
||||
) -> anyhow::Result<()> {
|
||||
if config.privileges.drop_privileges {
|
||||
let mut counter = 0usize;
|
||||
|
||||
loop {
|
||||
let sockets = num_bound_sockets.load(Ordering::SeqCst);
|
||||
|
||||
if sockets == config.socket_workers {
|
||||
PrivDrop::default()
|
||||
.chroot(config.privileges.chroot_path.clone())
|
||||
.user(config.privileges.user.clone())
|
||||
.apply()?;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
::std::thread::sleep(Duration::from_millis(10));
|
||||
|
||||
counter += 1;
|
||||
|
||||
if counter == 500 {
|
||||
panic!("Sockets didn't bind in time for privilege drop.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue