radicle: Fix file limit setting for FreeBSD
On FreeBSD systems, the file limits are of type `i64` in comparison to `u64` on Linux systems. Also fix `rad web` command name on Windows and FreeBSD. Co-authored-by: cloudhead <cloudhead@radicle.xyz> Co-authored-by: Shawn Webb <shawn.webb@hardenedbsd.org>
This commit is contained in:
parent
860f1dc867
commit
d46b0b6d11
|
|
@ -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")]
|
||||
|
|
|
|||
|
|
@ -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}");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<u64> {
|
||||
pub fn set_file_limit<N>(n: N) -> io::Result<Int>
|
||||
where
|
||||
N: Copy + fmt::Display,
|
||||
Int: TryFrom<N>,
|
||||
{
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue