1 /*
2     dtach - A simple program that emulates the detach feature of screen.
3     Copyright (C) 2001, 2004-2016 Ned T. Crigler
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19 #ifndef dtach_h
20 #define dtach_h
21 
22 #include <config.h>
23 
24 #include <errno.h>
25 #include <fcntl.h>
26 #include <signal.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 
31 #if TIME_WITH_SYS_TIME
32 #include <sys/time.h>
33 #include <time.h>
34 #else
35 #if HAVE_SYS_TIME_H
36 #include <sys/time.h>
37 #else
38 #include <time.h>
39 #endif
40 #endif
41 
42 #ifdef HAVE_PTY_H
43 #include <pty.h>
44 #endif
45 
46 #ifdef HAVE_UTIL_H
47 #include <util.h>
48 #endif
49 
50 #ifdef HAVE_LIBUTIL_H
51 #include <libutil.h>
52 #endif
53 
54 #ifdef HAVE_STROPTS_H
55 #include <stropts.h>
56 #endif
57 
58 #ifdef HAVE_UNISTD_H
59 #include <unistd.h>
60 #endif
61 
62 #ifdef HAVE_SYS_IOCTL_H
63 #include <sys/ioctl.h>
64 #endif
65 
66 #ifdef HAVE_SYS_RESOURCE_H
67 #include <sys/resource.h>
68 #endif
69 
70 #include <termios.h>
71 #include <sys/select.h>
72 #include <sys/stat.h>
73 #include <sys/socket.h>
74 #include <sys/un.h>
75 
76 #ifndef S_ISREG
77 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
78 #endif
79 
80 #ifndef S_ISSOCK
81 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
82 #endif
83 
84 extern char *progname, *sockname;
85 extern int detach_char, no_suspend, redraw_method;
86 extern struct termios orig_term;
87 extern int dont_have_tty;
88 
89 enum
90 {
91 	MSG_PUSH	= 0,
92 	MSG_ATTACH	= 1,
93 	MSG_DETACH	= 2,
94 	MSG_WINCH	= 3,
95 	MSG_REDRAW	= 4,
96 };
97 
98 enum
99 {
100 	REDRAW_UNSPEC	= 0,
101 	REDRAW_NONE	= 1,
102 	REDRAW_CTRL_L	= 2,
103 	REDRAW_WINCH	= 3,
104 };
105 
106 /* The client to master protocol. */
107 struct packet
108 {
109 	unsigned char type;
110 	unsigned char len;
111 	union
112 	{
113 		unsigned char buf[sizeof(struct winsize)];
114 		struct winsize ws;
115 	} u;
116 };
117 
118 /*
119 ** The master sends a simple stream of text to the attaching clients, without
120 ** any protocol. This might change back to the packet based protocol in the
121 ** future. In the meantime, however, we minimize the amount of data sent back
122 ** and forth between the client and the master. BUFSIZE is the size of the
123 ** buffer used for the text stream.
124 */
125 #define BUFSIZE 4096
126 
127 /* This hopefully moves to the bottom of the screen */
128 #define EOS "\033[999H"
129 
130 int attach_main(int noerror);
131 int master_main(char **argv, int waitattach, int dontfork);
132 int push_main(void);
133 
134 #ifdef sun
135 #define BROKEN_MASTER
136 #endif
137 #endif
138