From 45602a35ba1cbec189ae4468019063417f371b4f Mon Sep 17 00:00:00 2001 From: Martin <18033781+mdyring@users.noreply.github.com> Date: Tue, 14 Jul 2026 08:56:05 +0200 Subject: [PATCH] Various FreeBSD improvements (#3219) * Fix permission denied (/var/run/stalwart.pid) on FreeBSD install * Remove jemalloc dependency on FreeBSD (which is already using jemalloc) * Enabling binding to privileged ports on FreeBSD --- crates/main/Cargo.toml | 2 +- crates/main/src/main.rs | 4 ++-- install.sh | 13 ++++++++----- tests/Cargo.toml | 2 +- tests/src/lib.rs | 4 ++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/crates/main/Cargo.toml b/crates/main/Cargo.toml index 33706d2d..af335c49 100644 --- a/crates/main/Cargo.toml +++ b/crates/main/Cargo.toml @@ -40,7 +40,7 @@ migration = { path = "../migration" } tokio = { version = "1.47", features = ["full"] } rustls = { version = "0.23.5", default-features = false, features = ["std", "aws_lc_rs", "tls12"] } -[target.'cfg(not(target_env = "msvc"))'.dependencies] +[target.'cfg(not(any(target_env = "msvc", target_os = "freebsd")))'.dependencies] jemallocator = "0.5.0" [features] diff --git a/crates/main/src/main.rs b/crates/main/src/main.rs index d71e341e..6162b564 100644 --- a/crates/main/src/main.rs +++ b/crates/main/src/main.rs @@ -23,10 +23,10 @@ use utils::wait_for_shutdown; #[cfg(feature = "dev_mode")] pub mod test_data; -#[cfg(not(target_env = "msvc"))] +#[cfg(not(any(target_env = "msvc", target_os = "freebsd")))] use jemallocator::Jemalloc; -#[cfg(not(target_env = "msvc"))] +#[cfg(not(any(target_env = "msvc", target_os = "freebsd")))] #[global_allocator] static GLOBAL: Jemalloc = Jemalloc; diff --git a/install.sh b/install.sh index d137b456..49b3b958 100644 --- a/install.sh +++ b/install.sh @@ -486,7 +486,8 @@ desc="Stalwart Server" load_rc_config \$name : \${stalwart_enable:="NO"} -: \${stalwart_user:="${_user}"} +: \${stalwart_runas_user:="${_user}"} +: \${stalwart_runas_group:="${_user}"} : \${stalwart_config:="${_config}"} : \${stalwart_envfile:="${_env}"} : \${stalwart_logfile:="${_log_dir}/stalwart.log"} @@ -495,7 +496,7 @@ load_rc_config \$name pidfile="/var/run/stalwart.pid" procname="${_bin}" command="/usr/sbin/daemon" -command_args="-f -o \${stalwart_logfile} -p \${pidfile} -u \${stalwart_user} ${_bin} --config=\${stalwart_config}" +command_args="-f -o \${stalwart_logfile} -p \${pidfile} ${_bin} --config=\${stalwart_config}" sig_stop="INT" start_precmd="stalwart_precmd" @@ -507,10 +508,12 @@ stalwart_precmd() . "\${stalwart_envfile}" set +a fi - ulimit -n "\${stalwart_fdlimit}" - # Binding privileged ports (25/443/465/993/...) as a non-root user - # requires: sysctl net.inet.ip.portrange.reservedhigh=0 + # Stalwart binds its listeners as root, then setuid()s to this account + export RUN_AS_USER="\${stalwart_runas_user}" + export RUN_AS_GROUP="\${stalwart_runas_group}" + + ulimit -n "\${stalwart_fdlimit}" } run_rc_command "\$1" diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 5b883d9a..1be17f3e 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -89,5 +89,5 @@ time = "0.3" testcontainers = { version = "0.27", features = ["reusable-containers"] } rust-s3 = { version = "0.37", default-features = false, features = ["tokio-rustls-tls"] } -[target.'cfg(not(target_env = "msvc"))'.dependencies] +[target.'cfg(not(any(target_env = "msvc", target_os = "freebsd")))'.dependencies] jemallocator = "0.5.0" diff --git a/tests/src/lib.rs b/tests/src/lib.rs index 3e3c2546..d3057da5 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -6,10 +6,10 @@ #[cfg(test)] use ::store::registry::bootstrap::Bootstrap; -#[cfg(not(target_env = "msvc"))] +#[cfg(not(any(target_env = "msvc", target_os = "freebsd")))] use jemallocator::Jemalloc; -#[cfg(not(target_env = "msvc"))] +#[cfg(not(any(target_env = "msvc", target_os = "freebsd")))] #[global_allocator] static GLOBAL: Jemalloc = Jemalloc;