wok-stable annotate busybox/stuff/busybox-1.7.3-script.u @ rev 287

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