Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to daemonize 0.5.0 to get rid of boxfnonce #403

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion boringtun-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ documentation = "https://docs.rs/boringtun/0.5.2/boringtun/"
edition = "2021"

[dependencies]
daemonize = "0.4.1"
daemonize = "0.5.0"
clap = { version = "3.1.6", features = ["env"] }
tracing = "0.1.40"
tracing-subscriber = "0.3.9"
Expand Down
26 changes: 15 additions & 11 deletions boringtun-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use boringtun::device::drop_privileges::drop_privileges;
use boringtun::device::{DeviceConfig, DeviceHandle};
use clap::{Arg, Command};
use daemonize::Daemonize;
use daemonize::{Daemonize, Outcome};
use std::fs::File;
use std::os::unix::net::UnixDatagram;
use std::process::exit;
Expand Down Expand Up @@ -118,24 +118,28 @@ fn main() {
.with_ansi(false)
.init();

let daemonize = Daemonize::new()
.working_directory("/tmp")
.exit_action(move || {
let daemonize = Daemonize::new().working_directory("/tmp");

match daemonize.execute() {
Outcome::Parent(Ok(_)) => {
// In parent process, child forked ok
let mut b = [0u8; 1];
if sock2.recv(&mut b).is_ok() && b[0] == 1 {
println!("BoringTun started successfully");
exit(0);
} else {
eprintln!("BoringTun failed to start");
exit(1);
};
});

match daemonize.start() {
Ok(_) => tracing::info!("BoringTun started successfully"),
Err(e) => {
tracing::error!(error = ?e);
}
}
Outcome::Parent(Err(e)) => {
eprintln!("BoringTun failed to start - Fork error: {}", e);
exit(1);
}
Outcome::Child(_) => {
// In child process, we'll continue below with code that is common with foreground exec
tracing::info!("BoringTun started");
}
}
} else {
tracing_subscriber::fmt()
Expand Down