diff --git a/radicle-httpd/src/commands/web.rs b/radicle-httpd/src/commands/web.rs index 3229ebf5..866f9d65 100644 --- a/radicle-httpd/src/commands/web.rs +++ b/radicle-httpd/src/commands/web.rs @@ -192,6 +192,8 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { } if options.open { + #[cfg(any(target_os = "freebsd", target_os = "windows"))] + let cmd_name = "echo"; #[cfg(target_os = "macos")] let cmd_name = "open"; #[cfg(target_os = "linux")] diff --git a/radicle-node/src/main.rs b/radicle-node/src/main.rs index cc99ea94..af50a3d2 100644 --- a/radicle-node/src/main.rs +++ b/radicle-node/src/main.rs @@ -120,7 +120,7 @@ fn execute() -> anyhow::Result<()> { config.node.listen.clone() }; - if let Err(e) = radicle::io::set_file_limit(config.node.limits.max_open_files as u64) { + if let Err(e) = radicle::io::set_file_limit(config.node.limits.max_open_files) { log::warn!(target: "node", "Unable to set process open file limit: {e}"); } diff --git a/radicle/src/io.rs b/radicle/src/io.rs index 86a6db7e..8af88728 100644 --- a/radicle/src/io.rs +++ b/radicle/src/io.rs @@ -1,9 +1,25 @@ +use std::fmt; use std::io; use libc::{getrlimit, rlimit, setrlimit, RLIMIT_NOFILE}; +#[cfg(not(target_os = "freebsd"))] +type Int = u64; +#[cfg(target_os = "freebsd")] +type Int = i64; + /// Sets the open file limit to the given value, or the maximum allowed value. -pub fn set_file_limit(n: u64) -> io::Result { +pub fn set_file_limit(n: N) -> io::Result +where + N: Copy + fmt::Display, + Int: TryFrom, +{ + let Ok(n) = Int::try_from(n) else { + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + format!("invalid file limit '{n}'"), + )); + }; let mut rlim = rlimit { rlim_cur: 0, // Initial soft limit value rlim_max: 0, // Initial hard limit value