Skip to content

Commit

Permalink
os-posix: reorder parent notification for -daemonize
Browse files Browse the repository at this point in the history
Put "success" parent reporting in os_setup_post() to after
all other initializers which may also fail, to the very end,
so more possible failure cases are reported properly to the
calling process.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
  • Loading branch information
Michael Tokarev committed Nov 2, 2014
1 parent fee78fd commit 25cec2b
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions os-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,6 @@ void os_setup_post(void)
int fd = 0;

if (daemonize) {
uint8_t status = 0;
ssize_t len;

do {
len = write(daemon_pipe, &status, 1);
} while (len < 0 && errno == EINTR);
if (len != 1) {
exit(1);
}
if (chdir("/")) {
perror("not able to chdir to /");
exit(1);
Expand All @@ -278,11 +269,21 @@ void os_setup_post(void)
change_process_uid();

if (daemonize) {
uint8_t status = 0;
ssize_t len;

dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);

close(fd);

do {
len = write(daemon_pipe, &status, 1);
} while (len < 0 && errno == EINTR);
if (len != 1) {
exit(1);
}
}
}

Expand Down

0 comments on commit 25cec2b

Please sign in to comment.