wok annotate busybox/stuff/busybox-1.12.0-replay.u @ rev 5095

Up: xorg-xf86-video-intel; update DEPENDS
author Rohit Joshi <jozee@slitaz.org>
date Mon Mar 15 18:17:01 2010 +0000 (2010-03-15)
parents 63bb627de1fb
children
rev   line source
pascal@3214 1 --- busybox-1.12.0/util-linux/script.c
pascal@3214 2 +++ busybox-1.12.0/util-linux/script.c
pascal@3214 3 @@ -36,6 +36,15 @@
pascal@3214 4 const char *shell;
pascal@3214 5 char shell_opt[] = "-i";
pascal@3214 6 char *shell_arg = NULL;
pascal@3214 7 + enum {
pascal@3214 8 + OPT_a = (1 << 0),
pascal@3214 9 + OPT_c = (1 << 1),
pascal@3214 10 + OPT_f = (1 << 2),
pascal@3214 11 + OPT_q = (1 << 3),
pascal@3214 12 +#if ENABLE_REPLAY
pascal@3214 13 + OPT_t = (1 << 4),
pascal@3214 14 +#endif
pascal@3214 15 + };
pascal@3214 16
pascal@3214 17 #if ENABLE_GETOPT_LONG
pascal@3214 18 static const char getopt_longopts[] ALIGN1 =
pascal@3214 19 @@ -43,25 +52,28 @@
pascal@3214 20 "command\0" Required_argument "c"
pascal@3214 21 "flush\0" No_argument "f"
pascal@3214 22 "quiet\0" No_argument "q"
pascal@3214 23 +# if ENABLE_REPLAY
pascal@3214 24 + "timing\0" No_argument "t"
pascal@3214 25 +# endif
pascal@3214 26 ;
pascal@3214 27
pascal@3214 28 applet_long_options = getopt_longopts;
pascal@3214 29 #endif
pascal@3214 30 opt_complementary = "?1"; /* max one arg */
pascal@3214 31 - opt = getopt32(argv, "ac:fq", &shell_arg);
pascal@3214 32 + opt = getopt32(argv, "ac:fq" USE_REPLAY("t") , &shell_arg);
pascal@3214 33 //argc -= optind;
pascal@3214 34 argv += optind;
pascal@3214 35 if (argv[0]) {
pascal@3214 36 fname = argv[0];
pascal@3214 37 }
pascal@3214 38 mode = O_CREAT|O_TRUNC|O_WRONLY;
pascal@3214 39 - if (opt & 1) {
pascal@3214 40 + if (opt & OPT_a) {
pascal@3214 41 mode = O_CREAT|O_APPEND|O_WRONLY;
pascal@3214 42 }
pascal@3214 43 - if (opt & 2) {
pascal@3214 44 + if (opt & OPT_c) {
pascal@3214 45 shell_opt[1] = 'c';
pascal@3214 46 }
pascal@3214 47 - if (!(opt & 8)) { /* not -q */
pascal@3214 48 + if (!(opt & OPT_q)) {
pascal@3214 49 printf("Script started, file is %s\n", fname);
pascal@3214 50 }
pascal@3214 51 shell = getenv("SHELL");
pascal@3214 52 @@ -97,6 +109,10 @@
pascal@3214 53 #define buf bb_common_bufsiz1
pascal@3214 54 struct pollfd pfd[2];
pascal@3214 55 int outfd, count, loop;
pascal@3214 56 +#if ENABLE_REPLAY
pascal@3214 57 + struct timeval tv;
pascal@3214 58 + double oldtime=time(NULL), newtime;
pascal@3214 59 +#endif
pascal@3214 60
pascal@3214 61 outfd = xopen(fname, mode);
pascal@3214 62 pfd[0].fd = pty;
pascal@3214 63 @@ -118,15 +134,27 @@
pascal@3214 64 }
pascal@3214 65 if (pfd[0].revents) {
pascal@3214 66 errno = 0;
pascal@3214 67 +#if ENABLE_REPLAY
pascal@3214 68 + if (opt & OPT_t) {
pascal@3214 69 + gettimeofday(&tv, NULL);
pascal@3214 70 + }
pascal@3214 71 +#endif
pascal@3214 72 count = safe_read(pty, buf, sizeof(buf));
pascal@3214 73 if (count <= 0 && errno != EAGAIN) {
pascal@3214 74 /* err/eof from pty: exit */
pascal@3214 75 goto restore;
pascal@3214 76 }
pascal@3214 77 if (count > 0) {
pascal@3214 78 +#if ENABLE_REPLAY
pascal@3214 79 + if (opt & OPT_t) {
pascal@3214 80 + newtime = tv.tv_sec + (double) tv.tv_usec / 1000000;
pascal@3214 81 + fprintf(stderr, "%f %i\n", newtime - oldtime, count);
pascal@3214 82 + oldtime = newtime;
pascal@3214 83 + }
pascal@3214 84 +#endif
pascal@3214 85 full_write(STDOUT_FILENO, buf, count);
pascal@3214 86 full_write(outfd, buf, count);
pascal@3214 87 - if (opt & 4) { /* -f */
pascal@3214 88 + if (opt & OPT_f) {
pascal@3214 89 fsync(outfd);
pascal@3214 90 }
pascal@3214 91 }
pascal@3214 92 @@ -158,7 +186,7 @@
pascal@3214 93 restore:
pascal@3214 94 if (attr_ok == 0)
pascal@3214 95 tcsetattr(0, TCSAFLUSH, &tt);
pascal@3214 96 - if (!(opt & 8)) /* not -q */
pascal@3214 97 + if (!(opt & OPT_q))
pascal@3214 98 printf("Script done, file is %s\n", fname);
pascal@3214 99 return EXIT_SUCCESS;
pascal@3214 100 }
pascal@3214 101
pascal@3214 102 --- busybox-1.12.0/util-linux/Config.in
pascal@3214 103 +++ busybox-1.12.0/util-linux/Config.in
pascal@3214 104 @@ -719,6 +719,13 @@
pascal@3214 105 help
pascal@3214 106 This allows you to parse /proc/profile for basic profiling.
pascal@3214 107
pascal@3214 108 +config REPLAY
pascal@3214 109 + bool "replay"
pascal@3214 110 + default n
pascal@3214 111 + help
pascal@3214 112 + This program replays a typescript, using timing information
pascal@3214 113 + given by script -t.
pascal@3214 114 +
pascal@3214 115 config RTCWAKE
pascal@3214 116 bool "rtcwake"
pascal@3214 117 default n
pascal@3214 118
pascal@3214 119 --- busybox-1.12.0/util-linux/Kbuild
pascal@3214 120 +++ busybox-1.12.0/util-linux/Kbuild
pascal@3214 121 @@ -28,6 +28,7 @@
pascal@3214 122 lib-$(CONFIG_RDATE) += rdate.o
pascal@3214 123 lib-$(CONFIG_RDEV) += rdev.o
pascal@3214 124 lib-$(CONFIG_READPROFILE) += readprofile.o
pascal@3214 125 +lib-$(CONFIG_REPLAY) += replay.o
pascal@3214 126 lib-$(CONFIG_RTCWAKE) += rtcwake.o
pascal@3214 127 lib-$(CONFIG_SCRIPT) += script.o
pascal@3214 128 lib-$(CONFIG_SETARCH) += setarch.o
pascal@3214 129
pascal@3214 130 --- busybox-1.12.0/include/applets.h
pascal@3214 131 +++ busybox-1.12.0/include/applets.h
pascal@3214 132 @@ -294,6 +294,7 @@
pascal@3214 133 USE_REALPATH(APPLET(realpath, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
pascal@3214 134 USE_HALT(APPLET_ODDNAME(reboot, halt, _BB_DIR_SBIN, _BB_SUID_NEVER, reboot))
pascal@3214 135 USE_RENICE(APPLET(renice, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
pascal@3214 136 +USE_REPLAY(APPLET(replay, _BB_DIR_BIN, _BB_SUID_NEVER))
pascal@3214 137 USE_RESET(APPLET(reset, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
pascal@3214 138 USE_RESIZE(APPLET(resize, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
pascal@3214 139 USE_RESTORECON(APPLET_ODDNAME(restorecon, setfiles, _BB_DIR_SBIN, _BB_SUID_NEVER, restorecon))
pascal@3214 140
pascal@3214 141 --- busybox-1.12.0/include/usage.h
pascal@3214 142 +++ busybox-1.12.0/include/usage.h
pascal@3214 143 @@ -3244,6 +3244,11 @@
pascal@3214 144 "\n -g Process group id(s)" \
pascal@3214 145 "\n -u Process user name(s) and/or id(s)" \
pascal@3214 146
pascal@3214 147 +#define replay_trivial_usage \
pascal@3214 148 + "timingfile [typescript [divisor]]"
pascal@3214 149 +#define replay_full_usage "\n\n" \
pascal@3214 150 + "Play back typescripts, using timing information"
pascal@3214 151 +
pascal@3214 152 #define reset_trivial_usage \
pascal@3214 153 ""
pascal@3214 154 #define reset_full_usage "\n\n" \
pascal@3214 155 @@ -3426,13 +3431,20 @@
pascal@3214 156
pascal@3214 157 #define script_trivial_usage \
pascal@3214 158 "[-afq] [-c COMMAND] [OUTFILE]"
pascal@3214 159 -#define script_full_usage "\n\n" \
pascal@3214 160 +#define script_full_usage_base "\n\n" \
pascal@3214 161 "Options:" \
pascal@3214 162 "\n -a Append output" \
pascal@3214 163 "\n -c Run COMMAND, not shell" \
pascal@3214 164 "\n -f Flush output after each write" \
pascal@3214 165 "\n -q Quiet" \
pascal@3214 166
pascal@3214 167 +#ifdef USE_REPLAY
pascal@3214 168 +#define script_full_usage script_full_usage_base \
pascal@3214 169 + "\n -t Send timing to stderr"
pascal@3214 170 +#else
pascal@3214 171 +#define script_full_usage script_full_usage_base
pascal@3214 172 +#endif
pascal@3214 173 +
pascal@3214 174 #define sed_trivial_usage \
pascal@3214 175 "[-efinr] pattern [files...]"
pascal@3214 176 #define sed_full_usage "\n\n" \
pascal@3214 177
pascal@3214 178 --- busybox-1.12.0/util-linux/replay.c
pascal@3214 179 +++ busybox-1.12.0/util-linux/replay.c
pascal@3214 180 @@ -0,0 +1,41 @@
pascal@3214 181 +/* vi: set sw=4 ts=4: */
pascal@3214 182 +/*
pascal@3214 183 + * replay - play back typescripts, using timing information
pascal@3214 184 + *
pascal@3214 185 + * pascal.bellard@ads-lu.com
pascal@3214 186 + *
pascal@3214 187 + * Licensed under GPLv2 or later, see file License in this tarball for details.
pascal@3214 188 + *
pascal@3214 189 + */
pascal@3214 190 +
pascal@3214 191 +#include "libbb.h"
pascal@3214 192 +
pascal@3214 193 +int replay_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
pascal@3214 194 +int replay_main(int argc, char **argv)
pascal@3214 195 +{
pascal@3214 196 + const char *script = "typescript";
pascal@3214 197 + double delay, factor = 1000000.0;
pascal@3214 198 + int fd;
pascal@3214 199 + long count;
pascal@3214 200 + FILE *tfp;
pascal@3214 201 +
pascal@3214 202 + switch (argc) {
pascal@3214 203 + case 4: factor /= atof(argv[3]);
pascal@3214 204 + case 3: script = argv[2];
pascal@3214 205 + case 2: break;
pascal@3214 206 + default:
pascal@3214 207 + bb_show_usage();
pascal@3214 208 + }
pascal@3214 209 +
pascal@3214 210 + tfp = xfopen_for_read(argv[1]);
pascal@3214 211 + fd = open(script, O_RDONLY);
pascal@3214 212 + while (fscanf(tfp, "%lf %ld\n", &delay, &count) == 2) {
pascal@3214 213 + usleep(delay * factor);
pascal@3214 214 + bb_copyfd_exact_size(fd, STDOUT_FILENO, count);
pascal@3214 215 + }
pascal@3214 216 +#if ENABLE_FEATURE_CLEAN_UP
pascal@3214 217 + close(fd);
pascal@3214 218 + fclose(tfp);
pascal@3214 219 +#endif
pascal@3214 220 + return EXIT_SUCCESS;
pascal@3214 221 +}