Commit Diff


commit - 64c44899f96ed7d0340507b1d3f310b198f04b39
commit + c6b1d112887e139711143d2f6948b788f7502a37
blob - 4d59ee624b6ece9c5272a292ba3f21eea6d1cb7d
blob + d0490dd0d7296458eb055fdedc681d76dd95a5ff
--- src/lib.rs
+++ src/lib.rs
@@ -1,3 +1,2 @@
 pub mod metrics;
 pub mod s6;
-mod tai;
blob - a273441350861a0f2df0a2e164ed9813cbb408fb
blob + 37137fc0b6e9254269ed80581913e61985e16f47
--- src/s6.rs
+++ src/s6.rs
@@ -1,19 +1,21 @@
 use std::{
     ffi::OsStr,
-    fs::{File, OpenOptions},
-    io::{self, ErrorKind, Read},
+    fs::OpenOptions,
+    io::{self, ErrorKind},
     os::{
         fd::{AsFd, AsRawFd, BorrowedFd},
         unix::{fs::OpenOptionsExt, process::ExitStatusExt},
     },
     path::{Path, PathBuf},
-    process::ExitStatus,
     ptr::addr_of_mut,
     time::Duration,
 };
 
-use crate::tai::Tain;
+mod status;
+mod tai;
 
+use status::SvStatus;
+
 fn locked(fd: BorrowedFd) -> io::Result<bool> {
     let mut flock = libc::flock {
         l_type: libc::F_RDLCK as libc::c_short,
@@ -29,44 +31,6 @@ fn locked(fd: BorrowedFd) -> io::Result<bool> {
     }
 }
 
-struct SvStatus {
-    stamp: Duration,
-    ready_stamp: Duration,
-    pid: u64,
-    wait_status: ExitStatus,
-    paused: bool,
-    finishing: bool,
-    want_up: bool,
-    ready: bool,
-}
-
-impl From<[u8; 35]> for SvStatus {
-    fn from(pack: [u8; 35]) -> Self {
-        Self {
-            stamp: Tain::from_be_bytes(pack[0..12].try_into().expect("12 bytes")).into(),
-            ready_stamp: Tain::from_be_bytes(pack[12..24].try_into().expect("12 bytes")).into(),
-            pid: u64::from_be_bytes(pack[24..32].try_into().expect("8 bytes")),
-            wait_status: 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,
-            want_up: pack[34] & 4 == 4,
-            ready: pack[34] & 8 == 8,
-        }
-    }
-}
-
-impl TryFrom<File> for SvStatus {
-    type Error = io::Error;
-
-    fn try_from(mut file: File) -> Result<Self, Self::Error> {
-        let mut pack = [0; 35];
-        file.read_exact(&mut pack)?;
-        Ok(SvStatus::from(pack))
-    }
-}
-
 pub struct SupervisedStatus {
     pub up: bool,
     pub wanted_up: bool,
blob - /dev/null
blob + 95e8a09b35b088df992cb69353a86cdbda243fc5 (mode 644)
--- /dev/null
+++ src/s6/status.rs
@@ -0,0 +1,47 @@
+use std::{
+    fs::File,
+    io::{self, Read},
+    os::unix::process::ExitStatusExt,
+    process::ExitStatus,
+    time::Duration,
+};
+
+use super::tai::Tain;
+
+pub(super) struct SvStatus {
+    pub stamp: Duration,
+    pub ready_stamp: Duration,
+    pub pid: u64,
+    pub wait_status: ExitStatus,
+    pub paused: bool,
+    pub finishing: bool,
+    pub want_up: bool,
+    pub ready: bool,
+}
+
+impl From<[u8; 35]> for SvStatus {
+    fn from(pack: [u8; 35]) -> Self {
+        Self {
+            stamp: Tain::from_be_bytes(pack[0..12].try_into().expect("12 bytes")).into(),
+            ready_stamp: Tain::from_be_bytes(pack[12..24].try_into().expect("12 bytes")).into(),
+            pid: u64::from_be_bytes(pack[24..32].try_into().expect("8 bytes")),
+            wait_status: 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,
+            want_up: pack[34] & 4 == 4,
+            ready: pack[34] & 8 == 8,
+        }
+    }
+}
+
+impl TryFrom<File> for SvStatus {
+    type Error = io::Error;
+
+    fn try_from(mut file: File) -> Result<Self, Self::Error> {
+        let mut pack = [0; 35];
+        file.read_exact(&mut pack)?;
+        Ok(SvStatus::from(pack))
+    }
+}
blob - /dev/null
blob + becc759a36616afb1054bb276b82aa6b12787674 (mode 644)
--- /dev/null
+++ src/s6/tai.rs
@@ -0,0 +1,31 @@
+use std::time::Duration;
+
+struct Tai(u64);
+
+impl Tai {
+    const MAGIC: u64 = 4611686018427387904;
+    const EPOCH: u64 = Self::MAGIC + 10;
+    fn from_be_bytes(pack: [u8; 8]) -> Self {
+        Self(u64::from_be_bytes(pack))
+    }
+}
+
+pub(crate) struct Tain {
+    sec: Tai,
+    nano: u32,
+}
+
+impl Tain {
+    pub(crate) fn from_be_bytes(pack: [u8; 12]) -> Self {
+        Self {
+            sec: Tai::from_be_bytes(pack[0..8].try_into().expect("8 bytes")),
+            nano: u32::from_be_bytes(pack[8..12].try_into().expect("4 bytes")),
+        }
+    }
+}
+
+impl From<Tain> for Duration {
+    fn from(tain: Tain) -> Self {
+        Self::new(tain.sec.0 - Tai::EPOCH, tain.nano)
+    }
+}
blob - becc759a36616afb1054bb276b82aa6b12787674 (mode 644)
blob + /dev/null
--- src/tai.rs
+++ /dev/null
@@ -1,31 +0,0 @@
-use std::time::Duration;
-
-struct Tai(u64);
-
-impl Tai {
-    const MAGIC: u64 = 4611686018427387904;
-    const EPOCH: u64 = Self::MAGIC + 10;
-    fn from_be_bytes(pack: [u8; 8]) -> Self {
-        Self(u64::from_be_bytes(pack))
-    }
-}
-
-pub(crate) struct Tain {
-    sec: Tai,
-    nano: u32,
-}
-
-impl Tain {
-    pub(crate) fn from_be_bytes(pack: [u8; 12]) -> Self {
-        Self {
-            sec: Tai::from_be_bytes(pack[0..8].try_into().expect("8 bytes")),
-            nano: u32::from_be_bytes(pack[8..12].try_into().expect("4 bytes")),
-        }
-    }
-}
-
-impl From<Tain> for Duration {
-    fn from(tain: Tain) -> Self {
-        Self::new(tain.sec.0 - Tai::EPOCH, tain.nano)
-    }
-}