From 503a9b9b6c798134bf1daef452d14d95398aed94 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 28 Apr 2026 14:07:19 +0800 Subject: [PATCH] added -f for foreground --- Cargo.toml | 1 + src/bin/punchnet/main.rs | 12 +++++++++++- src/utils/command.rs | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8cf0f78..a116ddb 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,6 +75,7 @@ depends = "$auto" assets = [ # executable ["target/release/punchnet", "usr/local/punchnet/punchnet", "755"], + ["punchnet.service", "etc/systemd/system/punchnet.service", "755"], # lib ["libtuntap.so", "usr/lib/", "755"], ] diff --git a/src/bin/punchnet/main.rs b/src/bin/punchnet/main.rs index 2a6c35b..a25c6be 100755 --- a/src/bin/punchnet/main.rs +++ b/src/bin/punchnet/main.rs @@ -315,6 +315,7 @@ fn main() { let cmd = CommandLineInput2::parse(); // println!("port is {}", cmd.port); + let mut should_daemonize = true; match &cmd.cmd { Commands::Login(user) => { let rt = Runtime::new().unwrap(); @@ -402,12 +403,21 @@ fn main() { }); process::exit(0); } + Commands::AutoRun(runinfo) => { + if runinfo.foreground { + should_daemonize = false; + } + } + Commands::Start(startinfo) => { + if startinfo.foreground { + should_daemonize = false; + } + } _other => { // just fall through to next code } } - let should_daemonize = true; #[cfg(not(target_os = "windows"))] if should_daemonize { diff --git a/src/utils/command.rs b/src/utils/command.rs index db827df..fff6fe3 100755 --- a/src/utils/command.rs +++ b/src/utils/command.rs @@ -67,6 +67,9 @@ pub struct StartArguments { // take over dns or not if change /etc/resolv.conf #[arg(long)] pub take_dns: bool, + + #[arg(short)] + pub foreground: bool, } #[derive(Args, Debug)] @@ -110,6 +113,9 @@ pub struct AutoRunArgument { // take over dns or not if change /etc/resolv.conf #[arg(long)] pub take_dns: bool, + + #[arg(short)] + pub foreground: bool, } #[derive(Args, Debug)]