summaryrefslogtreecommitdiff
path: root/master.c
diff options
context:
space:
mode:
authorNed T. Crigler <crigler@users.sourceforge.net>2014-08-03 22:24:47 -0700
committerNed T. Crigler <crigler@users.sourceforge.net>2014-08-04 12:46:30 -0700
commitc7b68ae3fa3f8b367b0b8201e5ab3d0323363ee4 (patch)
treed90d15d8554563ed84eb6a9f32e604245a97930d /master.c
parent8527d8e8765d2e19f118f915cec3301b1c6cf5ea (diff)
Add dtach -N.
dtach -N is similar to dtach -n, except dtach will not daemonize. Based on patches by Ciprian Dorin Craciun and Frank Hunleth.
Diffstat (limited to 'master.c')
-rw-r--r--master.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/master.c b/master.c
index 62ecf10..9f51da0 100644
--- a/master.c
+++ b/master.c
@@ -543,7 +543,7 @@ master_process(int s, char **argv, int waitattach, int statusfd)
}
int
-master_main(char **argv, int waitattach)
+master_main(char **argv, int waitattach, int dontfork)
{
int fd[2] = {-1, -1};
int s;
@@ -566,7 +566,16 @@ master_main(char **argv, int waitattach)
/* If FD_CLOEXEC works, create a pipe and use it to report any errors
** that occur while trying to execute the program. */
- if (pipe(fd) >= 0)
+ if (dontfork)
+ {
+ fd[1] = dup(2);
+ if (fcntl(fd[1], F_SETFD, FD_CLOEXEC) < 0)
+ {
+ close(fd[1]);
+ fd[1] = -1;
+ }
+ }
+ else if (pipe(fd) >= 0)
{
if (fcntl(fd[0], F_SETFD, FD_CLOEXEC) < 0 ||
fcntl(fd[1], F_SETFD, FD_CLOEXEC) < 0)
@@ -578,6 +587,12 @@ master_main(char **argv, int waitattach)
}
#endif
+ if (dontfork)
+ {
+ master_process(s, argv, waitattach, fd[1]);
+ return 0;
+ }
+
/* Fork off so we can daemonize and such */
pid = fork();
if (pid < 0)