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

Fix waitpid to return the child exit code #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 7 additions & 7 deletions daemonize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,16 +374,16 @@ impl<T> Daemonize<T> {
set_sid()?;
libc::umask(self.umask.inner);

if perform_fork()?.is_some() {
exit(0)
};

let pid_file_fd = self
.pid_file
.clone()
.map(|pid_file| create_pid_file(pid_file))
.transpose()?;

if perform_fork()?.is_some() {
exit(0)
};

redirect_standard_streams(self.stdin, self.stdout, self.stderr)?;

let uid = self.user.map(|user| get_user(user)).transpose()?;
Expand Down Expand Up @@ -441,9 +441,9 @@ unsafe fn perform_fork() -> Result<Option<libc::pid_t>, ErrorKind> {
}

unsafe fn waitpid(pid: libc::pid_t) -> Result<libc::c_int, ErrorKind> {
let mut child_ret = 0;
check_err(libc::waitpid(pid, &mut child_ret, 0), ErrorKind::Wait)?;
Ok(child_ret)
let mut child_stat = 0;
check_err(libc::waitpid(pid, &mut child_stat, 0), ErrorKind::Wait)?;
Ok(libc::WEXITSTATUS(child_stat))
}

unsafe fn set_sid() -> Result<(), ErrorKind> {
Expand Down