updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / dtach-patched / foreground.diff
blob6dc89e56b8cb18d39f798fe5801fee13d481999b
1 diff --git a/dtach.1 b/dtach.1
2 index 699925c..da376b0 100644
3 --- a/dtach.1
4 +++ b/dtach.1
5 @@ -13,6 +13,9 @@ dtach \- simple program that emulates the detach feature of screen.
6 .br
7 .B dtach \-n
8 .I <socket> <options> <command...>
9 +.br
10 +.B dtach \-N
11 +.I <socket> <options> <command...>
13 .SH DESCRIPTION
14 .B dtach
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.
17 .B dtach
18 does not try to attach to the newly created session, however, and exits
19 -instead.
20 +instead (it daemonizes in the background).
21 +.TP
22 +.B \-N
23 +Creates a new session, without attaching to it. A new session is created in
24 +which the specified program is executed.
25 +.B dtach
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).
29 .PP
30 .SS OPTIONS
31 diff --git a/dtach.h b/dtach.h
32 index f2f4951..d30bb19 100644
33 --- a/dtach.h
34 +++ b/dtach.h
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);
41 #ifdef sun
42 #define BROKEN_MASTER
43 diff --git a/main.c b/main.c
44 index ade242a..5615302 100644
45 --- a/main.c
46 +++ b/main.c
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 "
51 - "detached.\n"
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"
55 "Options:\n"
56 " -e <char>\tSet the detach character to <char>, defaults "
57 "to ^\\.\n"
58 @@ -102,7 +104,7 @@ main(int argc, char **argv)
59 if (mode == '?')
60 usage();
61 else if (mode != 'a' && mode != 'c' && mode != 'n' &&
62 - mode != 'A')
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)
68 dont_have_tty = 1;
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",
75 progname);
76 @@ -236,6 +238,8 @@ main(int argc, char **argv)
78 else if (mode == 'n')
79 return master_main(argv, 0);
80 + else if (mode == 'N')
81 + return master_main_inprocess(argv, 0);
82 else if (mode == 'c')
84 if (master_main(argv, 1) != 0)
85 diff --git a/master.c b/master.c
86 index 88b85f5..38cfe04 100644
87 --- a/master.c
88 +++ b/master.c
89 @@ -507,6 +507,33 @@ master_process(int s, char **argv, int waitattach, int statusfd)
92 int
93 +master_main_inprocess(char **argv, int waitattach)
95 + int s;
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);
103 + if (s < 0)
105 + printf("%s: %s: %s\n", progname, sockname, strerror(errno));
106 + return 1;
109 +#if defined(F_SETFD) && defined(FD_CLOEXEC)
110 + fcntl(s, F_SETFD, FD_CLOEXEC);
111 +#endif
113 + /* Child - this becomes the master */
114 + master_process(s, argv, waitattach, dup(2));
116 + return 0;
119 +int
120 master_main(char **argv, int waitattach)
122 int fd[2] = {-1, -1};