Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ jobs:
- uses: Swatinem/rust-cache@v2
- name: Check native macOS carrier
run: cargo check --locked --workspace
- name: Test native macOS pending continuations
- name: Test native macOS carrier
env:
TMPDIR: ${{ runner.temp }}/lore-tests
RUST_TEST_THREADS: 1
run: |
mkdir -p "$TMPDIR"
chmod 700 "$TMPDIR"
cargo test --locked --test pending_pages
cargo test --locked
LORE_RS="$PWD/target/debug/lore-rs" sh scripts/test-native-launcher.sh
test:
runs-on: ubuntu-latest
# The whole suite runs in about a second; anything approaching this
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__/
dist/
*.egg-info/
/target/
3 changes: 2 additions & 1 deletion rust/lore-core/src/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,8 @@ mod tests {
assert_eq!(for_sessions(&cfg, &request).unwrap()["complete"], true);
}
}
#[cfg(unix)]
// APFS refuses non-UTF-8 file names, so this fixture cannot be created on macOS.
#[cfg(target_os = "linux")]
#[test]
fn non_utf8_json_stem_makes_every_session_summary_incomplete() {
use std::os::unix::ffi::OsStringExt;
Expand Down
30 changes: 25 additions & 5 deletions rust/lore-core/src/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn required(args: &[String]) -> bool {
a[0] == "--event" && matches!(a[1].as_str(), "pre-compact" | "session-end")
})
}
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "macos"))]
pub fn enter_worker() -> Result<bool> {
let Some(raw) = std::env::var_os("LORE_NATIVE_SUPERVISOR_PID") else {
return Ok(false);
Expand All @@ -56,9 +56,12 @@ pub fn enter_worker() -> Result<bool> {
worker_parent_lost as *const () as libc::sighandler_t,
);
}
#[cfg(target_os = "linux")]
if unsafe { libc::prctl(libc::PR_SET_PDEATHSIG, libc::SIGTERM) } != 0 {
return Err(Error::Untrusted);
}
#[cfg(target_os = "macos")]
watch_parent(pid);
if unsafe { libc::getppid() } != pid {
unsafe {
libc::kill(-libc::getpgrp(), libc::SIGKILL);
Expand All @@ -67,7 +70,7 @@ pub fn enter_worker() -> Result<bool> {
std::env::remove_var("LORE_NATIVE_SUPERVISOR_PID");
Ok(true)
}
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "macos"))]
pub fn run(args: &[String]) -> Result<i32> {
use std::os::unix::process::CommandExt;
let background = std::env::var("LORE_NATIVE_BACKGROUND_REVIEW").is_ok_and(|v| v == "1");
Expand All @@ -91,6 +94,7 @@ pub fn run(args: &[String]) -> Result<i32> {
} else {
None
};
#[cfg(target_os = "linux")]
if unsafe { libc::prctl(libc::PR_SET_CHILD_SUBREAPER, 1) } != 0 {
return Err(Error::Untrusted);
}
Expand All @@ -109,7 +113,11 @@ pub fn run(args: &[String]) -> Result<i32> {
.stderr(Stdio::inherit());
unsafe {
command.pre_exec(move || {
if libc::setpgid(0, 0) != 0 || libc::prctl(libc::PR_SET_PDEATHSIG, libc::SIGTERM) != 0 {
if libc::setpgid(0, 0) != 0 {
return Err(std::io::Error::last_os_error());
}
#[cfg(target_os = "linux")]
if libc::prctl(libc::PR_SET_PDEATHSIG, libc::SIGTERM) != 0 {
return Err(std::io::Error::last_os_error());
}
if libc::getppid() != parent {
Expand Down Expand Up @@ -154,6 +162,8 @@ pub fn run(args: &[String]) -> Result<i32> {
let status = child.wait();
// Subreaper ownership admits escaped provider grandchildren too. Reparented
// children are our children, so none can be an unrelated reused PID.
// shortcut: macOS has no subreaper or /proc, so a grandchild that left the
// process group is not reaped; upgrade with kqueue process tracking if needed.
let children = std::path::PathBuf::from(format!("/proc/{parent}/task/{parent}/children"));
let cleanup_deadline = Instant::now() + Duration::from_secs(3);
loop {
Expand Down Expand Up @@ -186,11 +196,21 @@ pub fn run(args: &[String]) -> Result<i32> {
}
Ok(status?.code().unwrap_or(1))
}
#[cfg(not(target_os = "linux"))]
#[cfg(target_os = "macos")]
fn watch_parent(parent: libc::pid_t) {
const PARENT_POLL: Duration = Duration::from_millis(100);
std::thread::spawn(move || loop {
if unsafe { libc::getppid() } != parent {
worker_parent_lost(libc::SIGTERM);
}
std::thread::sleep(PARENT_POLL);
});
}
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
pub fn enter_worker() -> Result<bool> {
Ok(false)
}
#[cfg(not(target_os = "linux"))]
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
pub fn run(_args: &[String]) -> Result<i32> {
Err(Error::Unsupported)
}