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);
}
*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;
}
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);