wok-current diff busybox/stuff/busybox-1.7.3-script.u @ rev 285
Busybox: add script
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Feb 26 23:37:59 2008 +0000 (2008-02-26) |
parents | |
children | 4b37234fc0be |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/busybox/stuff/busybox-1.7.3-script.u Tue Feb 26 23:37:59 2008 +0000 1.3 @@ -0,0 +1,358 @@ 1.4 +--- busybox-1.7.3/include/applets.h 1.5 ++++ busybox-1.7.3/include/applets.h 1.6 +@@ -284,6 +284,7 @@ 1.7 + USE_RUNSV(APPLET(runsv, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) 1.8 + USE_RUNSVDIR(APPLET(runsvdir, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) 1.9 + USE_RX(APPLET(rx, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) 1.10 ++USE_SCRIPT(APPLET(script, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) 1.11 + USE_SED(APPLET(sed, _BB_DIR_BIN, _BB_SUID_NEVER)) 1.12 + USE_SELINUXENABLED(APPLET(selinuxenabled, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) 1.13 + USE_SEQ(APPLET_NOFORK(seq, seq, _BB_DIR_USR_BIN, _BB_SUID_NEVER, seq)) 1.14 + 1.15 +--- busybox-1.7.3/include/libbb.h 1.16 ++++ busybox-1.7.3/include/libbb.h 1.17 +@@ -225,6 +225,7 @@ 1.18 + int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData, int depth), 1.19 + void* userData, unsigned depth); 1.20 + extern int device_open(const char *device, int mode); 1.21 ++extern int getpty(char *line, int size); 1.22 + extern int get_console_fd(void); 1.23 + extern char *find_block_device(const char *path); 1.24 + /* bb_copyfd_XX print read/write errors and return -1 if they occur */ 1.25 + 1.26 +--- busybox-1.7.3/libbb/Kbuild 1.27 ++++ busybox-1.7.3/libbb/Kbuild 1.28 +@@ -38,6 +38,7 @@ 1.29 + lib-y += get_last_path_component.o 1.30 + lib-y += get_line_from_file.o 1.31 + lib-y += getopt32.o 1.32 ++lib-y += getpty.o 1.33 + lib-y += herror_msg.o 1.34 + lib-y += herror_msg_and_die.o 1.35 + lib-y += human_readable.o 1.36 + 1.37 +--- busybox-1.7.3/libbb/getpty.c 1.38 ++++ busybox-1.7.3/libbb/getpty.c 1.39 +@@ -0,0 +1,56 @@ 1.40 ++/* vi: set sw=4 ts=4: */ 1.41 ++/* 1.42 ++ * Mini getpty implementation for busybox 1.43 ++ * Bjorn Wesen, Axis Communications AB (bjornw@axis.com) 1.44 ++ * 1.45 ++ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 1.46 ++ */ 1.47 ++ 1.48 ++#include "libbb.h" 1.49 ++ 1.50 ++int getpty(char *line, int size) 1.51 ++{ 1.52 ++ int p; 1.53 ++#if ENABLE_FEATURE_DEVPTS 1.54 ++ p = open("/dev/ptmx", O_RDWR); 1.55 ++ if (p > 0) { 1.56 ++ const char *name; 1.57 ++ grantpt(p); 1.58 ++ unlockpt(p); 1.59 ++ name = ptsname(p); 1.60 ++ if (!name) { 1.61 ++ bb_perror_msg("ptsname error (is /dev/pts mounted?)"); 1.62 ++ return -1; 1.63 ++ } 1.64 ++ safe_strncpy(line, name, size); 1.65 ++ return p; 1.66 ++ } 1.67 ++#else 1.68 ++ struct stat stb; 1.69 ++ int i; 1.70 ++ int j; 1.71 ++ 1.72 ++ strcpy(line, "/dev/ptyXX"); 1.73 ++ 1.74 ++ for (i = 0; i < 16; i++) { 1.75 ++ line[8] = "pqrstuvwxyzabcde"[i]; 1.76 ++ line[9] = '0'; 1.77 ++ if (stat(line, &stb) < 0) { 1.78 ++ continue; 1.79 ++ } 1.80 ++ for (j = 0; j < 16; j++) { 1.81 ++ line[9] = j < 10 ? j + '0' : j - 10 + 'a'; 1.82 ++ if (DEBUG) 1.83 ++ fprintf(stderr, "Trying to open device: %s\n", line); 1.84 ++ p = open(line, O_RDWR | O_NOCTTY); 1.85 ++ if (p >= 0) { 1.86 ++ line[5] = 't'; 1.87 ++ return p; 1.88 ++ } 1.89 ++ } 1.90 ++ } 1.91 ++#endif /* FEATURE_DEVPTS */ 1.92 ++ return -1; 1.93 ++} 1.94 ++ 1.95 ++ 1.96 + 1.97 +--- busybox-1.7.3/miscutils/Config.in 1.98 ++++ busybox-1.7.3/miscutils/Config.in 1.99 +@@ -329,6 +329,12 @@ 1.100 + help 1.101 + Receive files using the Xmodem protocol. 1.102 + 1.103 ++config SCRIPT 1.104 ++ bool "script" 1.105 ++ default n 1.106 ++ help 1.107 ++ The script makes typescript of terminal session. 1.108 ++ 1.109 + config STRINGS 1.110 + bool "strings" 1.111 + default n 1.112 + 1.113 +--- busybox-1.7.3/networking/telnetd.c 1.114 ++++ busybox-1.7.3/networking/telnetd.c 1.115 +@@ -162,54 +162,6 @@ 1.116 + return memmove(ptr - num_totty, ptr0, num_totty); 1.117 + } 1.118 + 1.119 +- 1.120 +-static int 1.121 +-getpty(char *line, int size) 1.122 +-{ 1.123 +- int p; 1.124 +-#if ENABLE_FEATURE_DEVPTS 1.125 +- p = open("/dev/ptmx", O_RDWR); 1.126 +- if (p > 0) { 1.127 +- const char *name; 1.128 +- grantpt(p); 1.129 +- unlockpt(p); 1.130 +- name = ptsname(p); 1.131 +- if (!name) { 1.132 +- bb_perror_msg("ptsname error (is /dev/pts mounted?)"); 1.133 +- return -1; 1.134 +- } 1.135 +- safe_strncpy(line, name, size); 1.136 +- return p; 1.137 +- } 1.138 +-#else 1.139 +- struct stat stb; 1.140 +- int i; 1.141 +- int j; 1.142 +- 1.143 +- strcpy(line, "/dev/ptyXX"); 1.144 +- 1.145 +- for (i = 0; i < 16; i++) { 1.146 +- line[8] = "pqrstuvwxyzabcde"[i]; 1.147 +- line[9] = '0'; 1.148 +- if (stat(line, &stb) < 0) { 1.149 +- continue; 1.150 +- } 1.151 +- for (j = 0; j < 16; j++) { 1.152 +- line[9] = j < 10 ? j + '0' : j - 10 + 'a'; 1.153 +- if (DEBUG) 1.154 +- fprintf(stderr, "Trying to open device: %s\n", line); 1.155 +- p = open(line, O_RDWR | O_NOCTTY); 1.156 +- if (p >= 0) { 1.157 +- line[5] = 't'; 1.158 +- return p; 1.159 +- } 1.160 +- } 1.161 +- } 1.162 +-#endif /* FEATURE_DEVPTS */ 1.163 +- return -1; 1.164 +-} 1.165 +- 1.166 +- 1.167 + static void 1.168 + send_iac(struct tsession *ts, unsigned char command, int option) 1.169 + { 1.170 + 1.171 +--- busybox-1.7.3/util-linux/script.c 1.172 ++++ busybox-1.7.3/util-linux/script.c 1.173 +@@ -0,0 +1,157 @@ 1.174 ++/* vi: set sw=4 ts=4: */ 1.175 ++/* 1.176 ++ * script implementation for busybox 1.177 ++ * 1.178 ++ * pascal.bellard@ads-lu.com 1.179 ++ * 1.180 ++ * Based on code from util-linux v 2.12r 1.181 ++ * Copyright (c) 1980 1.182 ++ * The Regents of the University of California. All rights reserved. 1.183 ++ * 1.184 ++ * Licensed under GPLv2 or later, see file License in this tarball for details. 1.185 ++ */ 1.186 ++ 1.187 ++#include <getopt.h> 1.188 ++#include "libbb.h" 1.189 ++ 1.190 ++struct globals { 1.191 ++ int parent, qflg; 1.192 ++ struct termios tt; 1.193 ++ const char *fname; 1.194 ++}; 1.195 ++#define G (*ptr_to_globals) 1.196 ++#define parent (G.parent ) 1.197 ++#define qflg (G.qflg ) 1.198 ++#define tt (G.tt ) 1.199 ++#define fname (G.fname ) 1.200 ++#define INIT_G() do { \ 1.201 ++ PTR_TO_GLOBALS = xzalloc(sizeof(G)); \ 1.202 ++ fname = "typescript"; \ 1.203 ++} while (0) 1.204 ++ 1.205 ++static void done(void) 1.206 ++{ 1.207 ++ if (parent) { 1.208 ++ tcsetattr(0, TCSAFLUSH, &tt); 1.209 ++ if (qflg == 0) printf("Script done, file is %s\n", fname); 1.210 ++ } 1.211 ++ exit(0); 1.212 ++} 1.213 ++ 1.214 ++static void finish(int sig) 1.215 ++{ 1.216 ++ (void) sig; 1.217 ++ done(); 1.218 ++} 1.219 ++ 1.220 ++#if ENABLE_GETOPT_LONG 1.221 ++static const char getopt_longopts[] ALIGN1 = 1.222 ++ "append\0" No_argument "a" 1.223 ++ "command\0" Required_argument "c" 1.224 ++ "flush\0" No_argument "f" 1.225 ++ "quiet\0" No_argument "q" 1.226 ++ ; 1.227 ++#endif 1.228 ++ 1.229 ++int script_main(int argc, char *argv[]); 1.230 ++int script_main(int argc, char *argv[]) 1.231 ++{ 1.232 ++ int opt, child, pty; 1.233 ++ int mode = O_CREAT|O_TRUNC|O_WRONLY; 1.234 ++ struct termios rtt; 1.235 ++ const char *shell; 1.236 ++ struct winsize win; 1.237 ++ char line[32]; 1.238 ++ char *cflg = NULL, shell_arg[] = "-i"; 1.239 ++ 1.240 ++ INIT_G(); 1.241 ++#if ENABLE_GETOPT_LONG 1.242 ++ applet_long_options = getopt_longopts; 1.243 ++#endif 1.244 ++ opt = getopt32(argv, "ac:fq", &cflg); 1.245 ++ if (opt & 1) { 1.246 ++ mode = O_CREAT|O_APPEND|O_WRONLY; 1.247 ++ } 1.248 ++ if (opt & 2) { 1.249 ++ shell_arg[1] = 'c'; 1.250 ++ } 1.251 ++#define fflg (opt & 4) 1.252 ++ if (opt & 8) { 1.253 ++ qflg++; 1.254 ++ } 1.255 ++ argc -= optind; 1.256 ++ argv += optind; 1.257 ++ if (argc > 0) { 1.258 ++ if (--argc > 0) { 1.259 ++ bb_show_usage(); 1.260 ++ } 1.261 ++ fname = argv[0]; 1.262 ++ } 1.263 ++ shell = getenv("SHELL"); 1.264 ++ if (shell == NULL) { 1.265 ++ shell = _PATH_BSHELL; 1.266 ++ } 1.267 ++ pty = getpty(line,sizeof(line)); 1.268 ++ if (pty < 0) { 1.269 ++ bb_perror_msg_and_die("Out of pty's"); 1.270 ++ } 1.271 ++ tcgetattr(0, &tt); 1.272 ++ ioctl(0, TIOCGWINSZ, (char *)&win); 1.273 ++ if (qflg == 0) { 1.274 ++ printf("Script started, file is %s\n", fname); 1.275 ++ } 1.276 ++ 1.277 ++ rtt = tt; 1.278 ++ cfmakeraw(&rtt); 1.279 ++ rtt.c_lflag &= ~ECHO; 1.280 ++ tcsetattr(0, TCSAFLUSH, &rtt); 1.281 ++ 1.282 ++ signal(SIGCHLD, finish); /* catch SIGTERM of children */ 1.283 ++ parent = fork(); /* use pid as flag meaning 'I am the parent process' */ 1.284 ++ if (parent < 0) { 1.285 ++ bb_perror_msg_and_die("fork"); 1.286 ++ } 1.287 ++ if (parent) { /* parent: link mainshell stdin to pty master input */ 1.288 ++ /* endless copy: stdin will not be closed */ 1.289 ++ bb_copyfd_eof(0, pty); 1.290 ++ /* not reached, but maybe bb_copyfd_eof behaviour will change ? */ 1.291 ++ done(); 1.292 ++ } 1.293 ++ else { 1.294 ++ child = fork(); 1.295 ++ if (child < 0) { 1.296 ++ bb_perror_msg_and_die("fork"); 1.297 ++ } 1.298 ++ if (child) { 1.299 ++ /* child1: link pty master output to mainshell stdout and file */ 1.300 ++ int count, fdscript; 1.301 ++ char buf[256]; 1.302 ++ close(0); 1.303 ++ fdscript = xopen(fname, mode); 1.304 ++ /* copy until pty is close, i.e. child2 exits */ 1.305 ++ while ((count = read(pty, buf, sizeof(buf))) > 0) { 1.306 ++ write(1, buf, count); 1.307 ++ write(fdscript, buf, count); 1.308 ++ if (fflg) { 1.309 ++ fsync(fdscript); 1.310 ++ } 1.311 ++ } 1.312 ++ done(); 1.313 ++ } 1.314 ++ else { /* child2: link subshell input, output, error to pty slave */ 1.315 ++ close(pty); /* close master */ 1.316 ++ pty = xopen(line, O_RDWR); /* open slave */ 1.317 ++ tcsetattr(pty, TCSAFLUSH, &tt); 1.318 ++ ioctl(pty, TIOCSWINSZ, (char *)&win); 1.319 ++ setsid(); 1.320 ++ ioctl(pty, TIOCSCTTY, 0); 1.321 ++ xmove_fd(pty, 0); 1.322 ++ xdup2(0, 1); 1.323 ++ xdup2(0, 2); 1.324 ++ execl(shell, strrchr(shell, '/') + 1, shell_arg, cflg, NULL); 1.325 ++ bb_perror_msg_and_die(shell); 1.326 ++ } 1.327 ++ } 1.328 ++ /* not reached */ 1.329 ++ return 0; 1.330 ++} 1.331 + 1.332 +--- busybox-1.7.3/util-linux/Kbuild 1.333 ++++ busybox-1.7.3/util-linux/Kbuild 1.334 +@@ -26,6 +26,7 @@ 1.335 + lib-$(CONFIG_PIVOT_ROOT) +=pivot_root.o 1.336 + lib-$(CONFIG_RDATE) +=rdate.o 1.337 + lib-$(CONFIG_READPROFILE) +=readprofile.o 1.338 ++lib-$(CONFIG_SCRIPT) +=script.o 1.339 + lib-$(CONFIG_SETARCH) +=setarch.o 1.340 + lib-$(CONFIG_SWAPONOFF) +=swaponoff.o 1.341 + lib-$(CONFIG_SWITCH_ROOT) +=switch_root.o 1.342 +patch bug... 1.343 +--- busybox-1.7.3/include/usage.h 1.344 ++++ busybox-1.7.3/include/usage.h 1.345 +@@ -2931,5 +2931,15 @@ 1.346 + #define rx_example_usage \ 1.347 + "$ rx /tmp/foo\n" 1.348 + 1.349 ++#define script_trivial_usage \ 1.350 ++ "[-afq] [-c COMMAND] [file]" 1.351 ++#define script_full_usage \ 1.352 ++ "Options:\n" \ 1.353 ++ " -a append the output to file or typescript\n" \ 1.354 ++ " -c COMMAND run the COMMAND rather than an interactive shell.\n" \ 1.355 ++ " -f flush output after each write\n" \ 1.356 ++ " -q quiet." 1.357 ++ 1.358 ++ 1.359 + #define sed_trivial_usage \ 1.360 + "[-efinr] pattern [files...]" 1.361 +patch bug...