daemonize
daemonize copied to clipboard
Fix waitpid to return the child exit code
- The
child_ret
returned by currentwaitpid
is the status information of the child process, NOT the exit code.
https://github.com/knsd/daemonize/blob/8a87c0b9e5568d2d57284d68e18ea5f24dcad5fb/daemonize/src/lib.rs#L443-L447
We can get the exit code with libc::WEXITSTATUS
.
- I try to lock the pid_file before
perform_fork
inexecute_child
, or the child will always exit with 0, and the parent also exit with 0.
Add a note here:
extern crate daemonize;
fn main() {
daemonize::Daemonize::new()
.working_directory(".")
.pid_file("pid")
.start()
.expect("daemonize failed");
loop {
std::thread::sleep(std::time::Duration::from_secs(1));
}
}
And cargo run
twice
$ cargo run
$ echo $?
0
$ cargo run
thread 'main' panicked at 'daemonize failed: Error { kind: LockPidfile(35) }', my-test/src/main.rs:8:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
$ echo $?
0 # 0 again, should be non-zero