wok view busybox/stuff/busybox-1.7.3-script.u @ rev 1201

squirrelmail: enable default plugins
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Aug 08 16:12:50 2008 +0000 (2008-08-08)
parents b19d783ba624
children
line source
1 --- busybox-1.7.3/include/applets.h
2 +++ busybox-1.7.3/include/applets.h
3 @@ -284,6 +284,7 @@
4 USE_RUNSV(APPLET(runsv, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
5 USE_RUNSVDIR(APPLET(runsvdir, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
6 USE_RX(APPLET(rx, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
7 +USE_SCRIPT(APPLET(script, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
8 USE_SED(APPLET(sed, _BB_DIR_BIN, _BB_SUID_NEVER))
9 USE_SELINUXENABLED(APPLET(selinuxenabled, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
10 USE_SEQ(APPLET_NOFORK(seq, seq, _BB_DIR_USR_BIN, _BB_SUID_NEVER, seq))
12 --- busybox-1.7.3/include/libbb.h
13 +++ busybox-1.7.3/include/libbb.h
14 @@ -225,6 +225,7 @@
15 int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData, int depth),
16 void* userData, unsigned depth);
17 extern int device_open(const char *device, int mode);
18 +extern int getpty(char *line, int size);
19 extern int get_console_fd(void);
20 extern char *find_block_device(const char *path);
21 /* bb_copyfd_XX print read/write errors and return -1 if they occur */
23 --- busybox-1.7.3/libbb/Kbuild
24 +++ busybox-1.7.3/libbb/Kbuild
25 @@ -38,6 +38,7 @@
26 lib-y += get_last_path_component.o
27 lib-y += get_line_from_file.o
28 lib-y += getopt32.o
29 +lib-y += getpty.o
30 lib-y += herror_msg.o
31 lib-y += herror_msg_and_die.o
32 lib-y += human_readable.o
34 --- busybox-1.7.3/libbb/getpty.c
35 +++ busybox-1.7.3/libbb/getpty.c
36 @@ -0,0 +1,56 @@
37 +/* vi: set sw=4 ts=4: */
38 +/*
39 + * Mini getpty implementation for busybox
40 + * Bjorn Wesen, Axis Communications AB (bjornw@axis.com)
41 + *
42 + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
43 + */
44 +
45 +#include "libbb.h"
46 +
47 +int getpty(char *line, int size)
48 +{
49 + int p;
50 +#if ENABLE_FEATURE_DEVPTS
51 + p = open("/dev/ptmx", O_RDWR);
52 + if (p > 0) {
53 + const char *name;
54 + grantpt(p);
55 + unlockpt(p);
56 + name = ptsname(p);
57 + if (!name) {
58 + bb_perror_msg("ptsname error (is /dev/pts mounted?)");
59 + return -1;
60 + }
61 + safe_strncpy(line, name, size);
62 + return p;
63 + }
64 +#else
65 + struct stat stb;
66 + int i;
67 + int j;
68 +
69 + strcpy(line, "/dev/ptyXX");
70 +
71 + for (i = 0; i < 16; i++) {
72 + line[8] = "pqrstuvwxyzabcde"[i];
73 + line[9] = '0';
74 + if (stat(line, &stb) < 0) {
75 + continue;
76 + }
77 + for (j = 0; j < 16; j++) {
78 + line[9] = j < 10 ? j + '0' : j - 10 + 'a';
79 + if (DEBUG)
80 + fprintf(stderr, "Trying to open device: %s\n", line);
81 + p = open(line, O_RDWR | O_NOCTTY);
82 + if (p >= 0) {
83 + line[5] = 't';
84 + return p;
85 + }
86 + }
87 + }
88 +#endif /* FEATURE_DEVPTS */
89 + return -1;
90 +}
91 +
92 +
94 --- busybox-1.7.3/miscutils/Config.in
95 +++ busybox-1.7.3/miscutils/Config.in
96 @@ -329,6 +329,12 @@
97 help
98 Receive files using the Xmodem protocol.
100 +config SCRIPT
101 + bool "script"
102 + default n
103 + help
104 + The script makes typescript of terminal session.
105 +
106 config STRINGS
107 bool "strings"
108 default n
110 --- busybox-1.7.3/networking/telnetd.c
111 +++ busybox-1.7.3/networking/telnetd.c
112 @@ -162,54 +162,6 @@
113 return memmove(ptr - num_totty, ptr0, num_totty);
114 }
116 -
117 -static int
118 -getpty(char *line, int size)
119 -{
120 - int p;
121 -#if ENABLE_FEATURE_DEVPTS
122 - p = open("/dev/ptmx", O_RDWR);
123 - if (p > 0) {
124 - const char *name;
125 - grantpt(p);
126 - unlockpt(p);
127 - name = ptsname(p);
128 - if (!name) {
129 - bb_perror_msg("ptsname error (is /dev/pts mounted?)");
130 - return -1;
131 - }
132 - safe_strncpy(line, name, size);
133 - return p;
134 - }
135 -#else
136 - struct stat stb;
137 - int i;
138 - int j;
139 -
140 - strcpy(line, "/dev/ptyXX");
141 -
142 - for (i = 0; i < 16; i++) {
143 - line[8] = "pqrstuvwxyzabcde"[i];
144 - line[9] = '0';
145 - if (stat(line, &stb) < 0) {
146 - continue;
147 - }
148 - for (j = 0; j < 16; j++) {
149 - line[9] = j < 10 ? j + '0' : j - 10 + 'a';
150 - if (DEBUG)
151 - fprintf(stderr, "Trying to open device: %s\n", line);
152 - p = open(line, O_RDWR | O_NOCTTY);
153 - if (p >= 0) {
154 - line[5] = 't';
155 - return p;
156 - }
157 - }
158 - }
159 -#endif /* FEATURE_DEVPTS */
160 - return -1;
161 -}
162 -
163 -
164 static void
165 send_iac(struct tsession *ts, unsigned char command, int option)
166 {
168 --- busybox-1.7.3/util-linux/script.c
169 +++ busybox-1.7.3/util-linux/script.c
170 @@ -0,0 +1,157 @@
171 +/* vi: set sw=4 ts=4: */
172 +/*
173 + * script implementation for busybox
174 + *
175 + * pascal.bellard@ads-lu.com
176 + *
177 + * Based on code from util-linux v 2.12r
178 + * Copyright (c) 1980
179 + * The Regents of the University of California. All rights reserved.
180 + *
181 + * Licensed under GPLv2 or later, see file License in this tarball for details.
182 + */
183 +
184 +#include <getopt.h>
185 +#include "libbb.h"
186 +
187 +struct globals {
188 + int parent, qflg;
189 + struct termios tt;
190 + const char *fname;
191 +};
192 +#define G (*ptr_to_globals)
193 +#define parent (G.parent )
194 +#define qflg (G.qflg )
195 +#define tt (G.tt )
196 +#define fname (G.fname )
197 +#define INIT_G() do { \
198 + PTR_TO_GLOBALS = xzalloc(sizeof(G)); \
199 + fname = "typescript"; \
200 +} while (0)
201 +
202 +static void done(void)
203 +{
204 + if (parent) {
205 + tcsetattr(0, TCSAFLUSH, &tt);
206 + if (qflg == 0) printf("Script done, file is %s\n", fname);
207 + }
208 + exit(0);
209 +}
210 +
211 +static void finish(int sig)
212 +{
213 + (void) sig;
214 + done();
215 +}
216 +
217 +#if ENABLE_GETOPT_LONG
218 +static const char getopt_longopts[] ALIGN1 =
219 + "append\0" No_argument "a"
220 + "command\0" Required_argument "c"
221 + "flush\0" No_argument "f"
222 + "quiet\0" No_argument "q"
223 + ;
224 +#endif
225 +
226 +int script_main(int argc, char *argv[]);
227 +int script_main(int argc, char *argv[])
228 +{
229 + int opt, child, pty;
230 + int mode = O_CREAT|O_TRUNC|O_WRONLY;
231 + struct termios rtt;
232 + const char *shell;
233 + struct winsize win;
234 + char line[32];
235 + char *cflg = NULL, shell_arg[] = "-i";
236 +
237 + INIT_G();
238 +#if ENABLE_GETOPT_LONG
239 + applet_long_options = getopt_longopts;
240 +#endif
241 + opt = getopt32(argv, "ac:fq", &cflg);
242 + if (opt & 1) {
243 + mode = O_CREAT|O_APPEND|O_WRONLY;
244 + }
245 + if (opt & 2) {
246 + shell_arg[1] = 'c';
247 + }
248 +#define fflg (opt & 4)
249 + if (opt & 8) {
250 + qflg++;
251 + }
252 + argc -= optind;
253 + argv += optind;
254 + if (argc > 0) {
255 + if (--argc > 0) {
256 + bb_show_usage();
257 + }
258 + fname = argv[0];
259 + }
260 + shell = getenv("SHELL");
261 + if (shell == NULL) {
262 + shell = _PATH_BSHELL;
263 + }
264 + pty = getpty(line,sizeof(line));
265 + if (pty < 0) {
266 + bb_perror_msg_and_die("Out of pty's");
267 + }
268 + tcgetattr(0, &tt);
269 + ioctl(0, TIOCGWINSZ, (char *)&win);
270 + if (qflg == 0) {
271 + printf("Script started, file is %s\n", fname);
272 + }
273 +
274 + rtt = tt;
275 + cfmakeraw(&rtt);
276 + rtt.c_lflag &= ~ECHO;
277 + tcsetattr(0, TCSAFLUSH, &rtt);
278 +
279 + signal(SIGCHLD, finish); /* catch SIGTERM of children */
280 + parent = fork(); /* use pid as flag meaning 'I am the parent process' */
281 + if (parent < 0) {
282 + bb_perror_msg_and_die("fork");
283 + }
284 + if (parent) { /* parent: link mainshell stdin to pty master input */
285 + /* endless copy: stdin will not be closed */
286 + bb_copyfd_eof(0, pty);
287 + /* not reached, but maybe bb_copyfd_eof behaviour will change ? */
288 + done();
289 + }
290 + else {
291 + child = fork();
292 + if (child < 0) {
293 + bb_perror_msg_and_die("fork");
294 + }
295 + if (child) {
296 + /* child1: link pty master output to mainshell stdout and file */
297 + int count, fdscript;
298 + char buf[256];
299 + close(0);
300 + fdscript = xopen(fname, mode);
301 + /* copy until pty is close, i.e. child2 exits */
302 + while ((count = read(pty, buf, sizeof(buf))) > 0) {
303 + write(1, buf, count);
304 + write(fdscript, buf, count);
305 + if (fflg) {
306 + fsync(fdscript);
307 + }
308 + }
309 + done();
310 + }
311 + else { /* child2: link subshell input, output, error to pty slave */
312 + close(pty); /* close master */
313 + pty = xopen(line, O_RDWR); /* open slave */
314 + tcsetattr(pty, TCSAFLUSH, &tt);
315 + ioctl(pty, TIOCSWINSZ, (char *)&win);
316 + setsid();
317 + ioctl(pty, TIOCSCTTY, 0);
318 + xmove_fd(pty, 0);
319 + xdup2(0, 1);
320 + xdup2(0, 2);
321 + execl(shell, strrchr(shell, '/') + 1, shell_arg, cflg, NULL);
322 + bb_perror_msg_and_die(shell);
323 + }
324 + }
325 + /* not reached */
326 + return 0;
327 +}
329 --- busybox-1.7.3/util-linux/Kbuild
330 +++ busybox-1.7.3/util-linux/Kbuild
331 @@ -26,6 +26,7 @@
332 lib-$(CONFIG_PIVOT_ROOT) +=pivot_root.o
333 lib-$(CONFIG_RDATE) +=rdate.o
334 lib-$(CONFIG_READPROFILE) +=readprofile.o
335 +lib-$(CONFIG_SCRIPT) +=script.o
336 lib-$(CONFIG_SETARCH) +=setarch.o
337 lib-$(CONFIG_SWAPONOFF) +=swaponoff.o
338 lib-$(CONFIG_SWITCH_ROOT) +=switch_root.o
339 patch bug...
340 --- busybox-1.7.3/include/usage.h
341 +++ busybox-1.7.3/include/usage.h
342 @@ -2931,5 +2931,15 @@
343 #define rx_example_usage \
344 "$ rx /tmp/foo\n"
346 +#define script_trivial_usage \
347 + "[-afq] [-c COMMAND] [file]"
348 +#define script_full_usage \
349 + "Options:\n" \
350 + " -a append the output to file or typescript\n" \
351 + " -c COMMAND run the COMMAND rather than an interactive shell.\n" \
352 + " -f flush output after each write\n" \
353 + " -q quiet."
354 +
355 +
356 #define sed_trivial_usage \
357 "[-efinr] pattern [files...]"