From bcec484fa50155589573470c14fe63fc94d6438a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 1 Jun 2010 12:21:35 +0100 Subject: [PATCH] do not regard everything as a child just because we daemonised --- duct.c | 4 ++-- help.c | 11 +++++++---- innduct.h | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/duct.c b/duct.c index 2ea2d4a..55b9877 100644 --- a/duct.c +++ b/duct.c @@ -556,13 +556,13 @@ int main(int argc, char **argv) { dup2(null,2); xclose(null, "/dev/null original fd",0); - pid_t child1= xfork("daemonise first fork"); + pid_t child1= xfork_bare("daemonise first fork"); if (child1) _exit(0); pid_t sid= setsid(); if (sid == -1) sysdie("setsid failed"); - pid_t child2= xfork("daemonise second fork"); + pid_t child2= xfork_bare("daemonise second fork"); if (child2) _exit(0); } diff --git a/help.c b/help.c index 34b1018..8a47c3f 100644 --- a/help.c +++ b/help.c @@ -127,12 +127,15 @@ void xclose_perhaps(int *fd, const char *what, const char *what2) { *fd=0; } -pid_t xfork(const char *what) { - pid_t child; - - child= fork(); +pid_t xfork_bare(const char *what) { + pid_t child= fork(); if (child==-1) sysdie("cannot fork for %s",what); dbg("forked %s %ld", what, (unsigned long)child); + return child; +} + +pid_t xfork(const char *what) { + pid_t child= xfork_bare(what); if (!child) postfork(); return child; } diff --git a/innduct.h b/innduct.h index 00be640..ddd17e6 100644 --- a/innduct.h +++ b/innduct.h @@ -327,7 +327,8 @@ char *xasprintf(const char *fmt, ...) PRINTF(1,2); int close_perhaps(int *fd); void xclose(int fd, const char *what, const char *what2); void xclose_perhaps(int *fd, const char *what, const char *what2); -pid_t xfork(const char *what); +pid_t xfork(const char *what); /* also runs postfork in child */ +pid_t xfork_bare(const char *what); void on_fd_read_except(int fd, oop_call_fd callback); void cancel_fd_read_except(int fd); -- 2.30.2