Skip to content

Commit f6f7d70

Browse files
Remove direct libc dependency from orchestrator-process and environmentd (#35929)
## Summary - **orchestrator-process**: Replace `libc::{SIGABRT, SIGBUS, SIGILL, SIGSEGV, SIGTRAP}` with `nix::sys::signal::Signal` variants (nix already a dependency) - **environmentd**: Replace `libc::raise` with `nix::sys::signal::raise` and `libc::c_int` with `std::ffi::c_int` Both crates already depend on `nix` which re-exports these via safe APIs. No new dependencies added. ## Test plan - [x] `cargo check -p mz-orchestrator-process -p mz-environmentd` passes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Jason Hernandez <7144515+jasonhernandez@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fef5c18 commit f6f7d70

5 files changed

Lines changed: 14 additions & 16 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/environmentd/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ include_dir.workspace = true
3636
ipnet.workspace = true
3737
itertools.workspace = true
3838
jsonwebtoken.workspace = true
39-
libc.workspace = true
4039
maplit.workspace = true
4140
mime.workspace = true
4241
mz-alloc = { path = "../alloc" }

src/environmentd/src/environmentd/sys.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//! System support functions.
1111
1212
use anyhow::Context;
13-
use nix::errno;
1413
use nix::sys::signal;
1514
use tracing::trace;
1615

@@ -131,7 +130,7 @@ pub fn enable_termination_signal_cleanup() -> Result<(), anyhow::Error> {
131130
}
132131

133132
unsafe extern "C" {
134-
fn __llvm_profile_write_file() -> libc::c_int;
133+
fn __llvm_profile_write_file() -> std::ffi::c_int;
135134
}
136135

137136
extern "C" fn handle_sigusr2_signal(_: i32) {
@@ -149,9 +148,6 @@ extern "C" fn handle_termination_signal(signum: i32) {
149148
unsafe { signal::sigaction(signum.try_into().unwrap(), &action) }
150149
.unwrap_or_else(|_| panic!("failed to uninstall handler for {}", signum));
151150

152-
let ret = unsafe { libc::raise(signum) };
153-
if ret == -1 {
154-
let errno = errno::Errno::from_raw(errno::Errno::last_raw());
155-
panic!("failed to re-raise signal {}: {}", signum, errno);
156-
}
151+
signal::raise(signum.try_into().unwrap())
152+
.unwrap_or_else(|e| panic!("failed to re-raise signal {}: {}", signum, e));
157153
}

src/orchestrator-process/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ chrono.workspace = true
1717
futures.workspace = true
1818
hex.workspace = true
1919
itertools.workspace = true
20-
libc.workspace = true
2120
maplit.workspace = true
2221
mz-orchestrator = { path = "../orchestrator", default-features = false }
2322
mz-ore = { path = "../ore", default-features = false, features = ["async", "network"] }

src/orchestrator-process/src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use chrono::{DateTime, Utc};
3030
use futures::StreamExt;
3131
use futures::stream::{BoxStream, FuturesUnordered};
3232
use itertools::Itertools;
33-
use libc::{SIGABRT, SIGBUS, SIGILL, SIGSEGV, SIGTRAP};
3433
use maplit::btreemap;
3534
use mz_orchestrator::scheduling_config::ServiceSchedulingConfig;
3635
use mz_orchestrator::{
@@ -43,6 +42,7 @@ use mz_ore::error::ErrorExt;
4342
use mz_ore::netio::UnixSocketAddr;
4443
use mz_ore::result::ResultExt;
4544
use mz_ore::task::AbortOnDropHandle;
45+
use nix::sys::signal::Signal;
4646
use scopeguard::defer;
4747
use serde::Serialize;
4848
use sha1::{Digest, Sha1};
@@ -1037,10 +1037,16 @@ fn did_process_crash(status: ExitStatus) -> bool {
10371037
// Likely not exhaustive. Feel free to add additional tests for other
10381038
// indications of a crashed child process, as those conditions are
10391039
// discovered.
1040-
matches!(
1041-
status.signal(),
1042-
Some(SIGABRT | SIGBUS | SIGSEGV | SIGTRAP | SIGILL)
1043-
)
1040+
status.signal().is_some_and(|s| {
1041+
matches!(
1042+
Signal::try_from(s),
1043+
Ok(Signal::SIGABRT
1044+
| Signal::SIGBUS
1045+
| Signal::SIGSEGV
1046+
| Signal::SIGTRAP
1047+
| Signal::SIGILL)
1048+
)
1049+
})
10441050
}
10451051

10461052
async fn write_pid_file(pid_file: &Path, pid: Pid) -> Result<(), anyhow::Error> {

0 commit comments

Comments
 (0)