wok view busybox/stuff/busybox-1.12.0-replay.u @ rev 3771

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