Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
Fix build on FreeBSD/HardenedBSD
Merged shawn.webb opened 1 year ago

I’m not entirely sure that the inode changes will work on Linux. But this commit fixes the Radicle build for these applications:

  1. radicle-cli
  2. radicle-httpd
  3. radicle-node
  4. radicle-remote-helper
  5. radicle-tools

Signed-off-by: Shawn Webb shawn.webb@hardenedbsd.org

3 files changed +20 -2 860f1dc8 d46b0b6d
modified 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(target_os = "freebsd")]
+
        let cmd_name = "echo";
        #[cfg(target_os = "macos")]
        let cmd_name = "open";
        #[cfg(target_os = "linux")]
modified 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}");
    }

modified 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<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