1 diff --git a/dtach.1 b/dtach.1
2 index 699925c..da376b0 100644
5 @@ -13,6 +13,9 @@ dtach \- simple program that emulates the detach feature of screen.
8 .I <socket> <options> <command...>
11 +.I <socket> <options> <command...>
15 @@ -92,7 +95,14 @@ Creates a new session, without attaching to it. A new session is created in
16 which the specified program is executed.
18 does not try to attach to the newly created session, however, and exits
20 +instead (it daemonizes in the background).
23 +Creates a new session, without attaching to it. A new session is created in
24 +which the specified program is executed.
26 +does not try to attach to the newly created session, however, and waits for
27 +the program to exit instead (it runs in foreground).
31 diff --git a/dtach.h b/dtach.h
32 index f2f4951..d30bb19 100644
35 @@ -129,6 +129,7 @@ struct packet
37 int attach_main(int noerror);
38 int master_main(char **argv, int waitattach);
39 +int master_main_inprocess(char **argv, int waitattach);
43 diff --git a/main.c b/main.c
44 index ade242a..5615302 100644
47 @@ -61,7 +61,9 @@ usage()
48 "\t\t does not exist, running the specified command.\n"
49 " -c\t\tCreate a new socket and run the specified command.\n"
50 " -n\t\tCreate a new socket and run the specified command "
52 + "detached (daemonized, in bagkground).\n"
53 + " -N\t\tCreate a new socket and run the specified command "
54 + "detached (non-daemonized, in foreground).\n"
56 " -e <char>\tSet the detach character to <char>, defaults "
58 @@ -102,7 +104,7 @@ main(int argc, char **argv)
61 else if (mode != 'a' && mode != 'c' && mode != 'n' &&
63 + mode != 'N' && mode != 'A')
65 printf("%s: Invalid mode '-%c'\n", progname, mode);
66 printf("Try '%s --help' for more information.\n",
67 @@ -215,7 +217,7 @@ main(int argc, char **argv)
71 - if (dont_have_tty && mode != 'n')
72 + if (dont_have_tty && (mode != 'n' && mode != 'N'))
74 printf("%s: Attaching to a session requires a terminal.\n",
76 @@ -236,6 +238,8 @@ main(int argc, char **argv)
79 return master_main(argv, 0);
80 + else if (mode == 'N')
81 + return master_main_inprocess(argv, 0);
84 if (master_main(argv, 1) != 0)
85 diff --git a/master.c b/master.c
86 index 88b85f5..38cfe04 100644
89 @@ -507,6 +507,33 @@ master_process(int s, char **argv, int waitattach, int statusfd)
93 +master_main_inprocess(char **argv, int waitattach)
97 + /* Use a default redraw method if one hasn't been specified yet. */
98 + if (redraw_method == REDRAW_UNSPEC)
99 + redraw_method = REDRAW_CTRL_L;
101 + /* Create the unix domain socket. */
102 + s = create_socket(sockname);
105 + printf("%s: %s: %s\n", progname, sockname, strerror(errno));
109 +#if defined(F_SETFD) && defined(FD_CLOEXEC)
110 + fcntl(s, F_SETFD, FD_CLOEXEC);
113 + /* Child - this becomes the master */
114 + master_process(s, argv, waitattach, dup(2));
120 master_main(char **argv, int waitattach)
122 int fd[2] = {-1, -1};