diff options
author | Himbeer <himbeerserverde@gmail.com> | 2024-02-19 14:33:24 +0100 |
---|---|---|
committer | Himbeer <himbeerserverde@gmail.com> | 2024-02-19 14:33:24 +0100 |
commit | aa4c57bf7a94b9419fd62721a632bc4fb21c2621 (patch) | |
tree | 1aec29e1e093cc0af498365ddfacc9f128d0a9ed | |
parent | 49a05d4999125134ba9643e8046929181bfd9fca (diff) |
Revert "remove broken daemonization"
This reverts commit d301670b3e3843b4a878738f0f81c13f63028e2a.
The daemonization likely wasn't broken to begin with,
it's just that inheriting closed stdio to btrfs processes
most definitely is what causes them to fail.
-rw-r--r-- | Cargo.lock | 11 | ||||
-rw-r--r-- | hbakd/Cargo.toml | 2 | ||||
-rw-r--r-- | hbakd/src/main.rs | 31 |
3 files changed, 41 insertions, 3 deletions
@@ -309,6 +309,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] +name = "fork" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf2ca97a59201425e7ee4d197c9c4fea282fe87a97d666a580bda889b95b8e88" +dependencies = [ + "libc", +] + +[[package]] name = "generic-array" version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -369,7 +378,9 @@ dependencies = [ name = "hbakd" version = "0.3.0-dev" dependencies = [ + "clap", "ctrlc", + "fork", "hbak_common", "thiserror", ] diff --git a/hbakd/Cargo.toml b/hbakd/Cargo.toml index 7d4a520..0ee1260 100644 --- a/hbakd/Cargo.toml +++ b/hbakd/Cargo.toml @@ -6,6 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4.4.18", features = ["derive"] } ctrlc = { version = "3.4.2", features = ["termination"] } hbak_common = { path = "../hbak_common" } +fork = "0.1.22" thiserror = "1.0" diff --git a/hbakd/src/main.rs b/hbakd/src/main.rs index 21f803d..51ae4d9 100644 --- a/hbakd/src/main.rs +++ b/hbakd/src/main.rs @@ -29,10 +29,35 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex}; use std::{cmp, io, thread}; +use clap::Parser; +use fork::{daemon, Fork}; + +#[derive(Debug, Parser)] +#[command(author, version, about, long_about = None)] +/// Background process to serve push and pull requests. +struct Args { + /// Stay attached to the terminal instead of daemonizing. + #[arg(short, long)] + debug: bool, +} + fn main() { - match serve() { - Ok(_) => {} - Err(e) => eprintln!("Error: {}", e), + let args = Args::parse(); + + if args.debug { + match serve() { + Ok(_) => {} + Err(e) => eprintln!("Error: {}", e), + } + } else { + match daemon(false, false) { + Ok(Fork::Parent(_)) => {} + Ok(Fork::Child) => match serve() { + Ok(_) => {} + Err(e) => eprintln!("Error: {}", e), + }, + Err(e) => eprintln!("Error: {}", io::Error::from_raw_os_error(e)), + } } } |