summaryrefslogtreecommitdiff
path: root/os-posix.c
diff options
context:
space:
mode:
authorMichael Tokarev <mjt@tls.msk.ru>2014-10-30 17:47:46 +0300
committerMichael Tokarev <mjt@tls.msk.ru>2014-11-02 10:04:34 +0300
commit25cec2b896a977565ca04e5c649aab8c6e48bda8 (patch)
treeab6118211c4a00a0b2c60f075ba4562ff05d58c8 /os-posix.c
parentfee78fd6d2f8dfdfd447a33c34323dd5bd3193a2 (diff)
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: Michael Tokarev <mjt@tls.msk.ru> Reviewed-by: Gonglei <arei.gonglei@huawei.com>
Diffstat (limited to 'os-posix.c')
-rw-r--r--os-posix.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/os-posix.c b/os-posix.c
index 52e989797d..ba091f1530 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -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);
+ }
}
}