chiark / gitweb /
daemon: wip
[hippotat.git] / server / daemon.rs
diff --git a/server/daemon.rs b/server/daemon.rs
new file mode 100644 (file)
index 0000000..4294eda
--- /dev/null
@@ -0,0 +1,75 @@
+// Copyright 2021-2022 Ian Jackson and contributors to Hippotat
+// SPDX-License-Identifier: GPL-3.0-or-later
+// There is NO WARRANTY.
+
+#![allow(unused_imports)]
+#![allow(dead_code)]
+
+use std::io::IoSlice;
+
+use extend::ext;
+
+use nix::errno::*;
+use nix::unistd::*;
+use nix::sys::uio::*;
+
+pub struct Daemoniser {
+}
+
+fn crashv(ms: &[IoSlice<'_>]) -> ! {
+  unsafe {
+    let _ = writev(2, ms);
+    libc::_exit(18);
+  }
+}
+  
+macro_rules! crashv { { $( $m:expr ),* $(,)? } => { {
+  let ms = [
+    "hippotatd: ",
+    $( $m, )*
+    "\n",
+  ];
+  let ms = ms.map(|m| IoSlice::new(m.as_bytes()));
+  crashv(&ms)
+} } }
+
+fn crash(m: &str) -> ! {
+  crashv!(m)
+}
+fn crashe(m: &str, en: Errno) -> ! {
+  crashv!(m, ": ", en.desc())
+}
+
+#[ext]
+impl<T> nix::Result<T> {
+  fn context(self, m: &str) -> T {
+    match self {
+      Ok(y) => y,
+      Err(en) => crashe(m, en),
+    }
+  }
+}
+
+impl Daemoniser {
+/*
+  pub fn phase1() -> Self {
+    unsafe {
+      let (st_read, st_write) = pipe().context("pipe");
+
+      mstch fork().context("fork (1)") {
+        ForkResult::Parent { child } => {
+          let _ = close(st_write);
+          let mut buf = [0u8];
+          loop {
+            match read(st_read, &mut buf) {
+              Ok(0) => {
+                 
+
+            let r = 
+        },
+
+        ForkResult::Child => { }
+    }
+  }
+*/
+}