Commit Diff


commit - 494084c5ac76057d8bc76837244b6e350ca247ca
commit + f41a8ff739d22ac29d0fd238f209a0f68995c9d9
blob - 67a751a473f26c94c0e2d154bb46fb2e47aa1702
blob + c9dd9c521a76cc3c9d97cb208735a71cc227070d
--- src/s6.rs
+++ src/s6.rs
@@ -4,9 +4,10 @@ use std::{
     io::{self, ErrorKind, Read},
     os::{
         fd::{AsFd, AsRawFd, BorrowedFd},
-        unix::fs::OpenOptionsExt,
+        unix::{fs::OpenOptionsExt, process::ExitStatusExt},
     },
     path::{Path, PathBuf},
+    process::ExitStatus,
     ptr::addr_of_mut,
 };
 
@@ -27,7 +28,7 @@ fn locked(fd: BorrowedFd) -> io::Result<bool> {
 
 struct SvStatus {
     pid: u64,
-    wstat: u16,
+    wstat: ExitStatus,
     paused: bool,
     finishing: bool,
     wantup: bool,
@@ -38,7 +39,9 @@ impl From<[u8; 35]> for SvStatus {
     fn from(pack: [u8; 35]) -> Self {
         Self {
             pid: u64::from_be_bytes(pack[24..32].try_into().expect("8 bytes")),
-            wstat: u16::from_be_bytes(pack[32..34].try_into().expect("2 bytes")),
+            wstat: ExitStatus::from_raw(u16::from_be_bytes(
+                pack[32..34].try_into().expect("2 bytes"),
+            ) as i32),
             paused: pack[34] & 1 == 1,
             finishing: pack[34] & 2 == 2,
             wantup: pack[34] & 4 == 4,
@@ -106,7 +109,6 @@ impl ServiceDir {
                 .custom_flags(libc::O_CLOEXEC)
                 .open(&path)
                 .and_then(SvStatus::try_from)?;
-            let wstat = status.wstat.into();
             assert!(path.pop());
             assert!(path.pop());
             path.push("down");
@@ -119,17 +121,13 @@ impl ServiceDir {
                 pid: status.pid,
                 exitcode: if status.pid != 0 && !status.finishing {
                     None
-                } else if libc::WIFEXITED(wstat) {
-                    Some(libc::WEXITSTATUS(wstat))
                 } else {
-                    None
+                    status.wstat.code()
                 },
                 signum: if status.pid != 0 && !status.finishing {
                     None
-                } else if libc::WIFSIGNALED(wstat) {
-                    Some(libc::WTERMSIG(wstat))
                 } else {
-                    None
+                    status.wstat.signal()
                 },
                 normallyup,
             }))