wok 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 74b7951d4d6d
children 83a60b321c15
files busybox/receipt busybox/stuff/busybox-1.7.3-script.u busybox/stuff/busybox-1.7.3.config
line diff
     1.1 --- a/busybox/receipt	Tue Feb 26 15:39:41 2008 +0000
     1.2 +++ b/busybox/receipt	Tue Feb 26 23:37:59 2008 +0000
     1.3 @@ -16,6 +16,7 @@
     1.4  {
     1.5      patch -p0 < stuff/$PACKAGE-$VERSION-hexdump.u
     1.6      patch -p0 < stuff/$PACKAGE-$VERSION-df.u
     1.7 +    patch -p0 < stuff/$PACKAGE-$VERSION-script.u
     1.8      cp stuff/$PACKAGE-$VERSION.config $PACKAGE-$VERSION/.config
     1.9      cd $PACKAGE-$VERSION
    1.10      make oldconfig
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/busybox/stuff/busybox-1.7.3-script.u	Tue Feb 26 23:37:59 2008 +0000
     2.3 @@ -0,0 +1,358 @@
     2.4 +--- busybox-1.7.3/include/applets.h
     2.5 ++++ busybox-1.7.3/include/applets.h
     2.6 +@@ -284,6 +284,7 @@
     2.7 + USE_RUNSV(APPLET(runsv, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
     2.8 + USE_RUNSVDIR(APPLET(runsvdir, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
     2.9 + USE_RX(APPLET(rx, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
    2.10 ++USE_SCRIPT(APPLET(script, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
    2.11 + USE_SED(APPLET(sed, _BB_DIR_BIN, _BB_SUID_NEVER))
    2.12 + USE_SELINUXENABLED(APPLET(selinuxenabled, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
    2.13 + USE_SEQ(APPLET_NOFORK(seq, seq, _BB_DIR_USR_BIN, _BB_SUID_NEVER, seq))
    2.14 +
    2.15 +--- busybox-1.7.3/include/libbb.h
    2.16 ++++ busybox-1.7.3/include/libbb.h
    2.17 +@@ -225,6 +225,7 @@
    2.18 + 	int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData, int depth),
    2.19 + 	void* userData, unsigned depth);
    2.20 + extern int device_open(const char *device, int mode);
    2.21 ++extern int getpty(char *line, int size);
    2.22 + extern int get_console_fd(void);
    2.23 + extern char *find_block_device(const char *path);
    2.24 + /* bb_copyfd_XX print read/write errors and return -1 if they occur */
    2.25 +
    2.26 +--- busybox-1.7.3/libbb/Kbuild
    2.27 ++++ busybox-1.7.3/libbb/Kbuild
    2.28 +@@ -38,6 +38,7 @@
    2.29 + lib-y += get_last_path_component.o
    2.30 + lib-y += get_line_from_file.o
    2.31 + lib-y += getopt32.o
    2.32 ++lib-y += getpty.o
    2.33 + lib-y += herror_msg.o
    2.34 + lib-y += herror_msg_and_die.o
    2.35 + lib-y += human_readable.o
    2.36 +
    2.37 +--- busybox-1.7.3/libbb/getpty.c
    2.38 ++++ busybox-1.7.3/libbb/getpty.c
    2.39 +@@ -0,0 +1,56 @@
    2.40 ++/* vi: set sw=4 ts=4: */
    2.41 ++/*
    2.42 ++ * Mini getpty implementation for busybox
    2.43 ++ * Bjorn Wesen, Axis Communications AB (bjornw@axis.com)
    2.44 ++ *
    2.45 ++ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
    2.46 ++ */
    2.47 ++
    2.48 ++#include "libbb.h"
    2.49 ++
    2.50 ++int getpty(char *line, int size)
    2.51 ++{
    2.52 ++	int p;
    2.53 ++#if ENABLE_FEATURE_DEVPTS
    2.54 ++	p = open("/dev/ptmx", O_RDWR);
    2.55 ++	if (p > 0) {
    2.56 ++		const char *name;
    2.57 ++		grantpt(p);
    2.58 ++		unlockpt(p);
    2.59 ++		name = ptsname(p);
    2.60 ++		if (!name) {
    2.61 ++			bb_perror_msg("ptsname error (is /dev/pts mounted?)");
    2.62 ++			return -1;
    2.63 ++		}
    2.64 ++		safe_strncpy(line, name, size);
    2.65 ++		return p;
    2.66 ++	}
    2.67 ++#else
    2.68 ++	struct stat stb;
    2.69 ++	int i;
    2.70 ++	int j;
    2.71 ++
    2.72 ++	strcpy(line, "/dev/ptyXX");
    2.73 ++
    2.74 ++	for (i = 0; i < 16; i++) {
    2.75 ++		line[8] = "pqrstuvwxyzabcde"[i];
    2.76 ++		line[9] = '0';
    2.77 ++		if (stat(line, &stb) < 0) {
    2.78 ++			continue;
    2.79 ++		}
    2.80 ++		for (j = 0; j < 16; j++) {
    2.81 ++			line[9] = j < 10 ? j + '0' : j - 10 + 'a';
    2.82 ++			if (DEBUG)
    2.83 ++				fprintf(stderr, "Trying to open device: %s\n", line);
    2.84 ++			p = open(line, O_RDWR | O_NOCTTY);
    2.85 ++			if (p >= 0) {
    2.86 ++				line[5] = 't';
    2.87 ++				return p;
    2.88 ++			}
    2.89 ++		}
    2.90 ++	}
    2.91 ++#endif /* FEATURE_DEVPTS */
    2.92 ++	return -1;
    2.93 ++}
    2.94 ++
    2.95 ++
    2.96 +
    2.97 +--- busybox-1.7.3/miscutils/Config.in
    2.98 ++++ busybox-1.7.3/miscutils/Config.in
    2.99 +@@ -329,6 +329,12 @@
   2.100 + 	help
   2.101 + 	  Receive files using the Xmodem protocol.
   2.102 + 
   2.103 ++config SCRIPT
   2.104 ++	bool "script"
   2.105 ++	default n
   2.106 ++	help
   2.107 ++	  The script makes typescript of terminal session.
   2.108 ++
   2.109 + config STRINGS
   2.110 + 	bool "strings"
   2.111 + 	default n
   2.112 +
   2.113 +--- busybox-1.7.3/networking/telnetd.c
   2.114 ++++ busybox-1.7.3/networking/telnetd.c
   2.115 +@@ -162,54 +162,6 @@
   2.116 + 	return memmove(ptr - num_totty, ptr0, num_totty);
   2.117 + }
   2.118 + 
   2.119 +-
   2.120 +-static int
   2.121 +-getpty(char *line, int size)
   2.122 +-{
   2.123 +-	int p;
   2.124 +-#if ENABLE_FEATURE_DEVPTS
   2.125 +-	p = open("/dev/ptmx", O_RDWR);
   2.126 +-	if (p > 0) {
   2.127 +-		const char *name;
   2.128 +-		grantpt(p);
   2.129 +-		unlockpt(p);
   2.130 +-		name = ptsname(p);
   2.131 +-		if (!name) {
   2.132 +-			bb_perror_msg("ptsname error (is /dev/pts mounted?)");
   2.133 +-			return -1;
   2.134 +-		}
   2.135 +-		safe_strncpy(line, name, size);
   2.136 +-		return p;
   2.137 +-	}
   2.138 +-#else
   2.139 +-	struct stat stb;
   2.140 +-	int i;
   2.141 +-	int j;
   2.142 +-
   2.143 +-	strcpy(line, "/dev/ptyXX");
   2.144 +-
   2.145 +-	for (i = 0; i < 16; i++) {
   2.146 +-		line[8] = "pqrstuvwxyzabcde"[i];
   2.147 +-		line[9] = '0';
   2.148 +-		if (stat(line, &stb) < 0) {
   2.149 +-			continue;
   2.150 +-		}
   2.151 +-		for (j = 0; j < 16; j++) {
   2.152 +-			line[9] = j < 10 ? j + '0' : j - 10 + 'a';
   2.153 +-			if (DEBUG)
   2.154 +-				fprintf(stderr, "Trying to open device: %s\n", line);
   2.155 +-			p = open(line, O_RDWR | O_NOCTTY);
   2.156 +-			if (p >= 0) {
   2.157 +-				line[5] = 't';
   2.158 +-				return p;
   2.159 +-			}
   2.160 +-		}
   2.161 +-	}
   2.162 +-#endif /* FEATURE_DEVPTS */
   2.163 +-	return -1;
   2.164 +-}
   2.165 +-
   2.166 +-
   2.167 + static void
   2.168 + send_iac(struct tsession *ts, unsigned char command, int option)
   2.169 + {
   2.170 +
   2.171 +--- busybox-1.7.3/util-linux/script.c
   2.172 ++++ busybox-1.7.3/util-linux/script.c
   2.173 +@@ -0,0 +1,157 @@
   2.174 ++/* vi: set sw=4 ts=4: */
   2.175 ++/*
   2.176 ++ * script implementation for busybox
   2.177 ++ *
   2.178 ++ * pascal.bellard@ads-lu.com
   2.179 ++ *
   2.180 ++ * Based on code from util-linux v 2.12r
   2.181 ++ * Copyright (c) 1980
   2.182 ++ *	The Regents of the University of California.  All rights reserved.
   2.183 ++ *
   2.184 ++ * Licensed under GPLv2 or later, see file License in this tarball for details.
   2.185 ++ */
   2.186 ++
   2.187 ++#include <getopt.h>
   2.188 ++#include "libbb.h"
   2.189 ++
   2.190 ++struct globals {
   2.191 ++	int	parent, qflg;
   2.192 ++	struct termios tt;
   2.193 ++	const char *fname;
   2.194 ++};
   2.195 ++#define G (*ptr_to_globals)
   2.196 ++#define parent    (G.parent )
   2.197 ++#define qflg      (G.qflg   )
   2.198 ++#define tt        (G.tt     )
   2.199 ++#define fname     (G.fname  )
   2.200 ++#define INIT_G() do { \
   2.201 ++	PTR_TO_GLOBALS = xzalloc(sizeof(G)); \
   2.202 ++	fname = "typescript"; \
   2.203 ++} while (0)
   2.204 ++
   2.205 ++static void done(void)
   2.206 ++{
   2.207 ++	if (parent) {
   2.208 ++		tcsetattr(0, TCSAFLUSH, &tt);
   2.209 ++		if (qflg == 0) printf("Script done, file is %s\n", fname);
   2.210 ++	}
   2.211 ++	exit(0);
   2.212 ++}
   2.213 ++
   2.214 ++static void finish(int sig)
   2.215 ++{
   2.216 ++	(void) sig;
   2.217 ++	done();
   2.218 ++}
   2.219 ++
   2.220 ++#if ENABLE_GETOPT_LONG
   2.221 ++static const char getopt_longopts[] ALIGN1 =
   2.222 ++	"append\0"  No_argument       "a"
   2.223 ++	"command\0" Required_argument "c"
   2.224 ++	"flush\0"   No_argument       "f"
   2.225 ++	"quiet\0"   No_argument       "q"
   2.226 ++	;
   2.227 ++#endif
   2.228 ++
   2.229 ++int script_main(int argc, char *argv[]);
   2.230 ++int script_main(int argc, char *argv[])
   2.231 ++{
   2.232 ++	int opt, child, pty;
   2.233 ++	int mode = O_CREAT|O_TRUNC|O_WRONLY;
   2.234 ++	struct termios rtt;
   2.235 ++	const char	*shell;
   2.236 ++	struct	winsize win;
   2.237 ++	char	line[32];
   2.238 ++	char *cflg = NULL, shell_arg[] = "-i";
   2.239 ++
   2.240 ++	INIT_G();
   2.241 ++#if ENABLE_GETOPT_LONG
   2.242 ++	applet_long_options = getopt_longopts;
   2.243 ++#endif
   2.244 ++	opt = getopt32(argv, "ac:fq", &cflg);
   2.245 ++	if (opt & 1) {
   2.246 ++		mode = O_CREAT|O_APPEND|O_WRONLY;
   2.247 ++	}
   2.248 ++	if (opt & 2) {
   2.249 ++		shell_arg[1] = 'c';
   2.250 ++	}
   2.251 ++#define fflg (opt & 4)
   2.252 ++	if (opt & 8) {
   2.253 ++		qflg++;
   2.254 ++	}
   2.255 ++	argc -= optind;
   2.256 ++	argv += optind;
   2.257 ++	if (argc > 0) {
   2.258 ++		if (--argc > 0) {
   2.259 ++			bb_show_usage();
   2.260 ++		}
   2.261 ++		fname = argv[0];
   2.262 ++	}
   2.263 ++	shell = getenv("SHELL");
   2.264 ++	if (shell == NULL) {
   2.265 ++		shell = _PATH_BSHELL;
   2.266 ++	}
   2.267 ++	pty = getpty(line,sizeof(line));
   2.268 ++	if (pty < 0) {
   2.269 ++		bb_perror_msg_and_die("Out of pty's");
   2.270 ++	}
   2.271 ++	tcgetattr(0, &tt);
   2.272 ++	ioctl(0, TIOCGWINSZ, (char *)&win);
   2.273 ++	if (qflg == 0) {
   2.274 ++		printf("Script started, file is %s\n", fname);
   2.275 ++	}
   2.276 ++
   2.277 ++	rtt = tt;
   2.278 ++	cfmakeraw(&rtt);
   2.279 ++	rtt.c_lflag &= ~ECHO;
   2.280 ++	tcsetattr(0, TCSAFLUSH, &rtt);
   2.281 ++
   2.282 ++	signal(SIGCHLD, finish); /* catch SIGTERM of children */
   2.283 ++	parent = fork(); /* use pid as flag meaning 'I am the parent process' */
   2.284 ++	if (parent < 0) {
   2.285 ++		bb_perror_msg_and_die("fork");
   2.286 ++	}
   2.287 ++	if (parent) { /* parent: link mainshell stdin to pty master input */
   2.288 ++		/* endless copy: stdin will not be closed */
   2.289 ++		bb_copyfd_eof(0, pty);
   2.290 ++		/* not reached, but maybe bb_copyfd_eof behaviour will change ? */
   2.291 ++		done();
   2.292 ++	}
   2.293 ++	else {
   2.294 ++		child = fork();
   2.295 ++		if (child < 0) {
   2.296 ++			bb_perror_msg_and_die("fork");
   2.297 ++		}
   2.298 ++		if (child) { 
   2.299 ++			/* child1: link pty master output to mainshell stdout and file */
   2.300 ++			int		count, fdscript;
   2.301 ++			char	buf[256];
   2.302 ++			close(0);
   2.303 ++			fdscript = xopen(fname, mode);
   2.304 ++			/* copy until pty is close, i.e. child2 exits */
   2.305 ++			while ((count = read(pty, buf, sizeof(buf))) > 0) {
   2.306 ++				write(1, buf, count);
   2.307 ++				write(fdscript, buf, count);
   2.308 ++				if (fflg) {
   2.309 ++					fsync(fdscript);
   2.310 ++				}
   2.311 ++			}
   2.312 ++			done();
   2.313 ++		}
   2.314 ++		else { /* child2: link subshell input, output, error to pty slave */
   2.315 ++			close(pty);					/* close master */
   2.316 ++			pty = xopen(line, O_RDWR);	/* open slave */
   2.317 ++			tcsetattr(pty, TCSAFLUSH, &tt);
   2.318 ++			ioctl(pty, TIOCSWINSZ, (char *)&win);
   2.319 ++			setsid();
   2.320 ++			ioctl(pty, TIOCSCTTY, 0);
   2.321 ++			xmove_fd(pty, 0);
   2.322 ++			xdup2(0, 1);
   2.323 ++			xdup2(0, 2);
   2.324 ++			execl(shell, strrchr(shell, '/') + 1, shell_arg, cflg, NULL);
   2.325 ++			bb_perror_msg_and_die(shell);
   2.326 ++		}
   2.327 ++	}
   2.328 ++	/* not reached */
   2.329 ++	return 0;
   2.330 ++}
   2.331 +
   2.332 +--- busybox-1.7.3/util-linux/Kbuild
   2.333 ++++ busybox-1.7.3/util-linux/Kbuild
   2.334 +@@ -26,6 +26,7 @@
   2.335 + lib-$(CONFIG_PIVOT_ROOT)	+=pivot_root.o
   2.336 + lib-$(CONFIG_RDATE)		+=rdate.o
   2.337 + lib-$(CONFIG_READPROFILE)	+=readprofile.o
   2.338 ++lib-$(CONFIG_SCRIPT)		+=script.o
   2.339 + lib-$(CONFIG_SETARCH)		+=setarch.o
   2.340 + lib-$(CONFIG_SWAPONOFF)		+=swaponoff.o
   2.341 + lib-$(CONFIG_SWITCH_ROOT)	+=switch_root.o
   2.342 +patch bug...   
   2.343 +--- busybox-1.7.3/include/usage.h
   2.344 ++++ busybox-1.7.3/include/usage.h
   2.345 +@@ -2931,5 +2931,15 @@
   2.346 + #define rx_example_usage \
   2.347 +        "$ rx /tmp/foo\n"
   2.348 + 
   2.349 ++#define script_trivial_usage \
   2.350 ++	"[-afq] [-c COMMAND] [file]"
   2.351 ++#define script_full_usage \
   2.352 ++       "Options:\n" \
   2.353 ++       "	-a		append the output to file or typescript\n" \
   2.354 ++       "	-c COMMAND	run the COMMAND rather than an interactive shell.\n" \
   2.355 ++       "	-f		flush output after each write\n" \
   2.356 ++       "	-q		quiet."
   2.357 ++       
   2.358 ++
   2.359 + #define sed_trivial_usage \
   2.360 +        "[-efinr] pattern [files...]"
   2.361 +patch bug...   
     3.1 --- a/busybox/stuff/busybox-1.7.3.config	Tue Feb 26 15:39:41 2008 +0000
     3.2 +++ b/busybox/stuff/busybox-1.7.3.config	Tue Feb 26 23:37:59 2008 +0000
     3.3 @@ -1,7 +1,7 @@
     3.4  #
     3.5  # Automatically generated make config: don't edit
     3.6  # Busybox version: 1.7.3
     3.7 -# Mon Feb 25 17:23:15 2008
     3.8 +# Wed Feb 27 00:11:33 2008
     3.9  #
    3.10  CONFIG_HAVE_DOT_CONFIG=y
    3.11  
    3.12 @@ -524,6 +524,7 @@
    3.13  # CONFIG_READAHEAD is not set
    3.14  # CONFIG_RUNLEVEL is not set
    3.15  # CONFIG_RX is not set
    3.16 +CONFIG_SCRIPT=y
    3.17  CONFIG_STRINGS=y
    3.18  CONFIG_SETSID=y
    3.19  # CONFIG_TASKSET is not set