提交 25cec2b8 编写于 作者: M Michael Tokarev

os-posix: reorder parent notification for -daemonize

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: NMichael Tokarev <mjt@tls.msk.ru>
Reviewed-by: NGonglei <arei.gonglei@huawei.com>
上级 fee78fd6
......@@ -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);
......@@ -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);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册