chiark / gitweb /
daemon: wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 25 Sep 2022 11:18:17 +0000 (12:18 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 25 Sep 2022 12:01:05 +0000 (13:01 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Cargo.lock
Cargo.toml
server/daemon.rs [new file with mode: 0644]
server/server.rs

index ace1cf0275f5285699d9af0a97cba633d85999c3..912669d51d6ca36edb0bbf4fa7650d338d546a5d 100644 (file)
@@ -48,9 +48,9 @@ dependencies = [
 
 [[package]]
 name = "autocfg"
-version = "1.0.1"
+version = "1.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
+checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
 
 [[package]]
 name = "backtrace"
@@ -447,6 +447,7 @@ dependencies = [
  "log",
  "memchr",
  "mime",
+ "nix",
  "parking_lot",
  "pin-project-lite",
  "regex",
@@ -674,6 +675,15 @@ version = "2.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc"
 
+[[package]]
+name = "memoffset"
+version = "0.6.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
+dependencies = [
+ "autocfg",
+]
+
 [[package]]
 name = "mime"
 version = "0.3.16"
@@ -730,6 +740,20 @@ dependencies = [
  "tempfile",
 ]
 
+[[package]]
+name = "nix"
+version = "0.25.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e322c04a9e3440c327fca7b6c8a63e6890a32fa2ad689db972425f07e0d22abb"
+dependencies = [
+ "autocfg",
+ "bitflags",
+ "cfg-if",
+ "libc",
+ "memoffset",
+ "pin-utils",
+]
+
 [[package]]
 name = "ntapi"
 version = "0.3.6"
index 55cf429a85748c02f0ce08cb60d6ed774117c2cf..005aaa6f337cece8809e739e4742ece4630b9ebe 100644 (file)
@@ -43,6 +43,7 @@ regex = "1.5"
 lazy_static = "1.4"
 log = "0.4"
 memchr = "2"
+nix = "0.25"
 pin-project-lite = "0.2"
 sha2 = "0.9"
 structopt = "0.3"
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 => { }
+    }
+  }
+*/
+}
index 00e1b6db0152ad3cb1f2b8a55979b0f764cf1ee7..285270ade6703a9a633db9422094a4ed3033a7d0 100644 (file)
@@ -4,6 +4,7 @@
 
 use hippotat::prelude::*;
 
+mod daemon;
 mod suser;
 mod slocal;
 mod sweb;