equal
deleted
inserted
replaced
37 * |
37 * |
38 * 2000-07-30 Per Andreas Buer <per@linpro.no> - added "q"-option |
38 * 2000-07-30 Per Andreas Buer <per@linpro.no> - added "q"-option |
39 */ |
39 */ |
40 |
40 |
41 /* |
41 /* |
42 * tcpscript - Modified from script - 2007 Lluis Batlle i Rossell |
42 * tcpscript - Modified from 'script' - 2007 Lluis Batlle i Rossell |
43 */ |
43 */ |
44 #include <stdio.h> |
44 #include <stdio.h> |
45 #include <stdlib.h> |
45 #include <stdlib.h> |
46 #include <sys/types.h> |
46 #include <sys/types.h> |
47 #include <sys/stat.h> |
47 #include <sys/stat.h> |
95 int limit_conns = 1; |
95 int limit_conns = 1; |
96 |
96 |
97 enum { |
97 enum { |
98 MAXCONNS = 10 |
98 MAXCONNS = 10 |
99 }; |
99 }; |
|
100 static int accept_socket; |
|
101 const char version[] = "0.1"; |
100 |
102 |
101 int conns[MAXCONNS]; |
103 int conns[MAXCONNS]; |
102 int nconns = 0; |
104 int nconns = 0; |
103 |
105 |
104 static char *progname; |
106 static char *progname; |
138 progname = p+1; |
140 progname = p+1; |
139 |
141 |
140 |
142 |
141 if (argc == 2) { |
143 if (argc == 2) { |
142 if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) { |
144 if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) { |
143 printf("%s, modification of 'script', by %s\n", |
145 printf("%s %s, modification of 'script' by %s\n", |
144 progname, "Lluis Batlle i Rossell 2007"); |
146 progname, version, |
|
147 "Lluis Batlle i Rossell 2007"); |
145 return 0; |
148 return 0; |
146 } |
149 } |
147 } |
150 } |
148 |
151 |
149 while ((ch = getopt(argc, argv, "c:qp:l:")) != -1) |
152 while ((ch = getopt(argc, argv, "c:qp:l:")) != -1) |
174 shell = _PATH_BSHELL; |
177 shell = _PATH_BSHELL; |
175 |
178 |
176 getmaster(); |
179 getmaster(); |
177 fixtty(); |
180 fixtty(); |
178 |
181 |
|
182 accept_socket = listen_tcp(); |
|
183 |
179 (void) signal(SIGCHLD, finish); |
184 (void) signal(SIGCHLD, finish); |
180 child = fork(); |
185 child = fork(); |
181 if (child < 0) { |
186 if (child < 0) { |
182 perror("fork"); |
187 perror("fork"); |
183 fail(); |
188 fail(); |
189 fail(); |
194 fail(); |
190 } |
195 } |
191 if (child) |
196 if (child) |
192 dooutput(); |
197 dooutput(); |
193 else |
198 else |
|
199 { |
|
200 close(accept_socket); |
194 doshell(); |
201 doshell(); |
|
202 } |
195 } else |
203 } else |
|
204 { |
|
205 close(accept_socket); |
196 (void) signal(SIGWINCH, resize); |
206 (void) signal(SIGWINCH, resize); |
|
207 } |
197 doinput(); |
208 doinput(); |
198 |
209 |
199 return 0; |
210 return 0; |
200 } |
211 } |
201 |
212 |
234 kill(child, SIGWINCH); |
245 kill(child, SIGWINCH); |
235 } |
246 } |
236 |
247 |
237 void fatal() |
248 void fatal() |
238 { |
249 { |
|
250 done(); |
239 exit(-1); |
251 exit(-1); |
240 } |
252 } |
241 |
253 |
242 int set_reusable(int s) |
254 int set_reusable(int s) |
243 { |
255 { |
329 #endif |
341 #endif |
330 fd_set read_set; |
342 fd_set read_set; |
331 fd_set should_read_set; |
343 fd_set should_read_set; |
332 fd_set tcp_set; |
344 fd_set tcp_set; |
333 |
345 |
334 accept_socket = listen_tcp(); |
|
335 FD_ZERO(&should_read_set); |
346 FD_ZERO(&should_read_set); |
336 FD_SET(accept_socket, &should_read_set); |
347 FD_SET(accept_socket, &should_read_set); |
337 FD_SET(master, &should_read_set); |
348 FD_SET(master, &should_read_set); |
338 nconns = 0; |
349 nconns = 0; |
339 (void) signal(SIGWINCH, sig_resize_clients); |
350 (void) signal(SIGWINCH, sig_resize_clients); |