Skip to content

Commit

Permalink
disable daemonize on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-jq committed Apr 29, 2024
1 parent bc512c6 commit b320f91
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/g3-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ cfg-if.workspace = true
slog = { workspace = true, features = ["max_level_trace", "release_max_level_info"] }
slog-scope = "4"
slog-stdlog = "4.1"
daemonize = "0.5"
futures-util.workspace = true
async-trait.workspace = true
yaml-rust.workspace = true
Expand Down Expand Up @@ -48,6 +47,9 @@ g3-http = { workspace = true, optional = true }
[target.'cfg(target_os = "linux")'.dependencies]
g3-journal.workspace = true

[target.'cfg(unix)'.dependencies]
daemonize = "0.5"

[features]
default = []
register = ["g3-yaml/http", "dep:http", "dep:serde_json", "dep:g3-http"]
Expand Down
9 changes: 8 additions & 1 deletion lib/g3-daemon/src/daemonize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use std::fs::OpenOptions;

use anyhow::anyhow;
use daemonize::Daemonize;
use log::debug;

use crate::opts::DaemonArgs;
Expand All @@ -30,7 +29,10 @@ pub fn check_enter(args: &DaemonArgs) -> anyhow::Result<()> {
Ok(())
}

#[cfg(unix)]
fn enter(args: &DaemonArgs) -> anyhow::Result<()> {
use daemonize::Daemonize;

let stdout = OpenOptions::new().write(true).open("/dev/null")?;
let stderr = OpenOptions::new().write(true).open("/dev/null")?;
let mut daemonize = Daemonize::new()
Expand All @@ -44,3 +46,8 @@ fn enter(args: &DaemonArgs) -> anyhow::Result<()> {

daemonize.start().map_err(|e| anyhow!("daemonize: {e}"))
}

#[cfg(windows)]
fn enter(_args: &DaemonArgs) -> anyhow::Result<()> {
Err(anyhow!("daemon mode is not implemented on Windows"))
}

0 comments on commit b320f91

Please sign in to comment.