From: Ian Jackson Date: Sun, 25 Sep 2022 11:18:17 +0000 (+0100) Subject: daemon: wip X-Git-Tag: hippotat/1.0.0~65 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=5c1f4bb58baafd29af00e244a4c1ba092c2fdafb;p=hippotat.git daemon: wip Signed-off-by: Ian Jackson --- diff --git a/Cargo.lock b/Cargo.lock index ace1cf0..912669d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 55cf429..005aaa6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 index 0000000..4294eda --- /dev/null +++ b/server/daemon.rs @@ -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 nix::Result { + 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 => { } + } + } +*/ +} diff --git a/server/server.rs b/server/server.rs index 00e1b6d..285270a 100644 --- a/server/server.rs +++ b/server/server.rs @@ -4,6 +4,7 @@ use hippotat::prelude::*; +mod daemon; mod suser; mod slocal; mod sweb;