chiark / gitweb /
do not regard everything as a child just because we daemonised
authorIan Jackson <ian@chiark.greenend.org.uk>
Tue, 1 Jun 2010 11:21:35 +0000 (12:21 +0100)
committerIan Jackson <ian@chiark.greenend.org.uk>
Tue, 1 Jun 2010 11:21:35 +0000 (12:21 +0100)
duct.c
help.c
innduct.h

diff --git a/duct.c b/duct.c
index 2ea2d4afbd59d80313af2763efb5bef517a0b9c3..55b98772da9d9f533ead5e1a4754add0ad9ef7b9 100644 (file)
--- 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 34b1018661ab7f29dee8d4711ed40ce42d98c5b5..8a47c3f4c16e2d0bacc8206ada933ae91d3e7c3b 100644 (file)
--- 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;
 }
index 00be640f73a33aca2e15ab2202cee214d6dab8df..ddd17e69c59050b979bec2e8c131bd4869e11221 100644 (file)
--- 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);