diff options
| author | Pascal Bellard <pascal.bellard@ads-lu.com> | 2010-06-28 15:50:22 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-28 15:51:01 +0200 |
| commit | ff37799dfe0e6e8fb9b971a2aeb4076d8a3784ec (patch) | |
| tree | 61705ab230d6ba9b0d625f6087c39bc2dea0a679 | |
| parent | 7d1201c5d7014365fb7e3d9da58f5e3fe0a1edc8 (diff) | |
| download | busybox-w32-ff37799dfe0e6e8fb9b971a2aeb4076d8a3784ec.tar.gz busybox-w32-ff37799dfe0e6e8fb9b971a2aeb4076d8a3784ec.tar.bz2 busybox-w32-ff37799dfe0e6e8fb9b971a2aeb4076d8a3784ec.zip | |
conspy: code shrink
function old new delta
conspy_main 1446 1444 -2
screen_read_close 114 108 -6
screen_char 299 293 -6
Signed-off-by: Pascal Bellard <pascal.bellard@ads-lu.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | include/usage.src.h | 10 | ||||
| -rw-r--r-- | init/bootchartd.c | 31 | ||||
| -rw-r--r-- | miscutils/conspy.c | 123 |
3 files changed, 78 insertions, 86 deletions
diff --git a/include/usage.src.h b/include/usage.src.h index 6d17ab571..53ee7943a 100644 --- a/include/usage.src.h +++ b/include/usage.src.h | |||
| @@ -163,16 +163,6 @@ INSERT | |||
| 163 | #define blkid_full_usage "\n\n" \ | 163 | #define blkid_full_usage "\n\n" \ |
| 164 | "Print UUIDs of all filesystems" | 164 | "Print UUIDs of all filesystems" |
| 165 | 165 | ||
| 166 | #define bootchartd_trivial_usage \ | ||
| 167 | "start [PROG ARGS]|stop|init" | ||
| 168 | #define bootchartd_full_usage "\n\n" \ | ||
| 169 | "Create /var/log/bootchart.tgz with boot chart data\n" \ | ||
| 170 | "\nOptions:" \ | ||
| 171 | "\nstart: start background logging; with PROG, run PROG, then kill logging with USR1" \ | ||
| 172 | "\nstop: send USR1 to all bootchartd processes" \ | ||
| 173 | "\ninit: start background logging; stop when getty/xdm is seen (for init scripts)" \ | ||
| 174 | "\nUnder PID 1: as init, then exec $bootchart_init, /init, /sbin/init" \ | ||
| 175 | |||
| 176 | #define brctl_trivial_usage \ | 166 | #define brctl_trivial_usage \ |
| 177 | "COMMAND [BRIDGE [INTERFACE]]" | 167 | "COMMAND [BRIDGE [INTERFACE]]" |
| 178 | #define brctl_full_usage "\n\n" \ | 168 | #define brctl_full_usage "\n\n" \ |
diff --git a/init/bootchartd.c b/init/bootchartd.c index f7de13e2f..4e15da4e8 100644 --- a/init/bootchartd.c +++ b/init/bootchartd.c | |||
| @@ -156,7 +156,7 @@ static int dump_procs(FILE *fp, int look_for_login_process) | |||
| 156 | continue; | 156 | continue; |
| 157 | p++; | 157 | p++; |
| 158 | strchrnul(p, ')')[0] = '\0'; | 158 | strchrnul(p, ')')[0] = '\0'; |
| 159 | /* If is gdm, kdm or a getty? */ | 159 | /* Is it gdm, kdm or a getty? */ |
| 160 | if (((p[0] == 'g' || p[0] == 'k' || p[0] == 'x') && p[1] == 'd' && p[2] == 'm') | 160 | if (((p[0] == 'g' || p[0] == 'k' || p[0] == 'x') && p[1] == 'd' && p[2] == 'm') |
| 161 | || strstr(p, "getty") | 161 | || strstr(p, "getty") |
| 162 | ) { | 162 | ) { |
| @@ -258,13 +258,12 @@ static void finalize(char *tempdir, const char *prog) | |||
| 258 | fprintf(header_fp, "profile.process = %s\n", prog); | 258 | fprintf(header_fp, "profile.process = %s\n", prog); |
| 259 | 259 | ||
| 260 | fputs("version = "BC_VERSION_STR"\n", header_fp); | 260 | fputs("version = "BC_VERSION_STR"\n", header_fp); |
| 261 | |||
| 262 | if (ENABLE_FEATURE_BOOTCHARTD_BLOATED_HEADER) { | 261 | if (ENABLE_FEATURE_BOOTCHARTD_BLOATED_HEADER) { |
| 263 | char *hostname; | 262 | char *hostname; |
| 264 | char *kcmdline; | 263 | char *kcmdline; |
| 265 | time_t t; | 264 | time_t t; |
| 266 | struct tm tm_time; | 265 | struct tm tm_time; |
| 267 | /* x2 for possible localized data */ | 266 | /* x2 for possible localized weekday/month names */ |
| 268 | char date_buf[sizeof("Mon Jun 21 05:29:03 CEST 2010") * 2]; | 267 | char date_buf[sizeof("Mon Jun 21 05:29:03 CEST 2010") * 2]; |
| 269 | struct utsname unamebuf; | 268 | struct utsname unamebuf; |
| 270 | 269 | ||
| @@ -313,16 +312,16 @@ static void finalize(char *tempdir, const char *prog) | |||
| 313 | */ | 312 | */ |
| 314 | } | 313 | } |
| 315 | 314 | ||
| 316 | /* Usage: | 315 | //usage:#define bootchartd_trivial_usage |
| 317 | * bootchartd start [PROG ARGS]: start logging in background, USR1 stops it. | 316 | //usage: "start [PROG ARGS]|stop|init" |
| 318 | * With PROG, runs PROG, then kills background logging. | 317 | //usage:#define bootchartd_full_usage "\n\n" |
| 319 | * bootchartd stop: same as "killall -USR1 bootchartd" | 318 | //usage: "Create /var/log/bootchart.tgz with boot chart data\n" |
| 320 | * bootchartd init: start logging in background | 319 | //usage: "\nOptions:" |
| 321 | * Stop when getty/gdm is seen (if AUTO_STOP_LOGGER = yes). | 320 | //usage: "\nstart: start background logging; with PROG, run PROG, then kill logging with USR1" |
| 322 | * Meant to be used from init scripts. | 321 | //usage: "\nstop: send USR1 to all bootchartd processes" |
| 323 | * bootchartd (pid==1): as init, but then execs $bootchart_init, /init, /sbin/init | 322 | //usage: "\ninit: start background logging; stop when getty/xdm is seen (for init scripts)" |
| 324 | * Meant to be used as kernel's init process. | 323 | //usage: "\nUnder PID 1: as init, then exec $bootchart_init, /init, /sbin/init" |
| 325 | */ | 324 | |
| 326 | int bootchartd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 325 | int bootchartd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 327 | int bootchartd_main(int argc UNUSED_PARAM, char **argv) | 326 | int bootchartd_main(int argc UNUSED_PARAM, char **argv) |
| 328 | { | 327 | { |
| @@ -358,7 +357,7 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv) | |||
| 358 | cmd = CMD_PID1; | 357 | cmd = CMD_PID1; |
| 359 | } | 358 | } |
| 360 | 359 | ||
| 361 | /* Here we are in START or INIT state */ | 360 | /* Here we are in START, INIT or CMD_PID1 state */ |
| 362 | 361 | ||
| 363 | /* Read config file: */ | 362 | /* Read config file: */ |
| 364 | sample_period_us = 200 * 1000; | 363 | sample_period_us = 200 * 1000; |
| @@ -422,7 +421,7 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv) | |||
| 422 | execl(bootchart_init, bootchart_init, NULL); | 421 | execl(bootchart_init, bootchart_init, NULL); |
| 423 | execl("/init", "init", NULL); | 422 | execl("/init", "init", NULL); |
| 424 | execl("/sbin/init", "init", NULL); | 423 | execl("/sbin/init", "init", NULL); |
| 425 | bb_perror_msg_and_die("can't exec '%s'", "/sbin/init"); | 424 | bb_perror_msg_and_die("can't execute '%s'", "/sbin/init"); |
| 426 | } | 425 | } |
| 427 | 426 | ||
| 428 | if (cmd == CMD_START && argv[2]) { /* "start PROG ARGS" */ | 427 | if (cmd == CMD_START && argv[2]) { /* "start PROG ARGS" */ |
| @@ -432,7 +431,7 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv) | |||
| 432 | if (pid == 0) { /* child */ | 431 | if (pid == 0) { /* child */ |
| 433 | argv += 2; | 432 | argv += 2; |
| 434 | execvp(argv[0], argv); | 433 | execvp(argv[0], argv); |
| 435 | bb_perror_msg_and_die("can't exec '%s'", argv[0]); | 434 | bb_perror_msg_and_die("can't execute '%s'", argv[0]); |
| 436 | } | 435 | } |
| 437 | /* parent */ | 436 | /* parent */ |
| 438 | waitpid(pid, NULL, 0); | 437 | waitpid(pid, NULL, 0); |
diff --git a/miscutils/conspy.c b/miscutils/conspy.c index 11105f0b8..6f2f0255c 100644 --- a/miscutils/conspy.c +++ b/miscutils/conspy.c | |||
| @@ -56,31 +56,33 @@ struct globals { | |||
| 56 | int size; | 56 | int size; |
| 57 | int x, y; | 57 | int x, y; |
| 58 | int kbd_fd; | 58 | int kbd_fd; |
| 59 | unsigned width; | 59 | int vcsa_fd; |
| 60 | unsigned height; | ||
| 61 | unsigned col; | ||
| 62 | unsigned line; | ||
| 63 | int ioerror_count; | 60 | int ioerror_count; |
| 64 | int key_count; | 61 | int key_count; |
| 65 | int escape_count; | 62 | int escape_count; |
| 66 | int nokeys; | 63 | int nokeys; |
| 67 | int current; | 64 | int current; |
| 68 | int vcsa_fd; | 65 | // cached local tty parameters |
| 69 | uint16_t last_attr; | 66 | unsigned width; |
| 70 | uint8_t last_bold; | 67 | unsigned height; |
| 71 | uint8_t last_blink; | 68 | unsigned col; |
| 72 | uint8_t last_fg; | 69 | unsigned line; |
| 73 | uint8_t last_bg; | ||
| 74 | char attrbuf[sizeof("\033[0;1;5;30;40m")]; | ||
| 75 | smallint curoff; | 70 | smallint curoff; |
| 71 | uint8_t last_attr; | ||
| 72 | uint8_t force_attr_change; | ||
| 73 | char attrbuf[sizeof("\033[0;1;5;30;40m")]; | ||
| 74 | // remote console | ||
| 76 | struct screen_info remote; | 75 | struct screen_info remote; |
| 76 | // saved local tty terminfo | ||
| 77 | struct termios term_orig; | 77 | struct termios term_orig; |
| 78 | }; | 78 | }; |
| 79 | 79 | ||
| 80 | #define G (*ptr_to_globals) | 80 | #define G (*ptr_to_globals) |
| 81 | #define INIT_G() do { \ | 81 | #define INIT_G() do { \ |
| 82 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ | 82 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ |
| 83 | strcpy((char*)&G.last_attr, "\xff\xff\xff\xff\xff\xff" "\033["); \ | 83 | G.attrbuf[0] = '\033'; \ |
| 84 | G.attrbuf[1] = '['; \ | ||
| 85 | G.force_attr_change = 0xff; \ | ||
| 84 | } while (0) | 86 | } while (0) |
| 85 | 87 | ||
| 86 | enum { | 88 | enum { |
| @@ -100,7 +102,6 @@ static void screen_read_close(void) | |||
| 100 | char *data = G.data + G.current; | 102 | char *data = G.data + G.current; |
| 101 | 103 | ||
| 102 | xread(G.vcsa_fd, data, G.size); | 104 | xread(G.vcsa_fd, data, G.size); |
| 103 | G.last_attr = 0; | ||
| 104 | for (i = 0; i < G.remote.lines; i++) { | 105 | for (i = 0; i < G.remote.lines; i++) { |
| 105 | for (j = 0; j < G.remote.cols; j++, NEXT(data)) { | 106 | for (j = 0; j < G.remote.cols; j++, NEXT(data)) { |
| 106 | unsigned x = j - G.x; // if will catch j < G.x too | 107 | unsigned x = j - G.x; // if will catch j < G.x too |
| @@ -117,9 +118,12 @@ static void screen_read_close(void) | |||
| 117 | 118 | ||
| 118 | static void screen_char(char *data) | 119 | static void screen_char(char *data) |
| 119 | { | 120 | { |
| 120 | uint8_t attr = ATTR(data); | 121 | if (!BW) { |
| 122 | uint8_t attr = ATTR(data); | ||
| 123 | //uint8_t attr = ATTR(data) >> 1; // for framebuffer console | ||
| 124 | uint8_t attr_diff = (G.last_attr ^ attr) | G.force_attr_change; | ||
| 121 | 125 | ||
| 122 | if (!BW && G.last_attr != attr) { | 126 | if (attr_diff) { |
| 123 | // Attribute layout for VGA compatible text videobuffer: | 127 | // Attribute layout for VGA compatible text videobuffer: |
| 124 | // blinking text | 128 | // blinking text |
| 125 | // |red bkgd | 129 | // |red bkgd |
| @@ -143,51 +147,49 @@ static void screen_char(char *data) | |||
| 143 | // green text | 147 | // green text |
| 144 | // blue text | 148 | // blue text |
| 145 | // text 8th bit | 149 | // text 8th bit |
| 146 | // converting RGB color bit triad to BGR: | 150 | // converting RGB color bit triad to BGR: |
| 147 | static const char color[8] = "04261537"; | 151 | static const char color[8] = "04261537"; |
| 148 | char *ptr; | 152 | const uint8_t fg_mask = 0x07, bold_mask = 0x08; |
| 149 | uint8_t fg, bold, bg, blink; | 153 | const uint8_t bg_mask = 0x70, blink_mask = 0x80; |
| 150 | 154 | char *ptr; | |
| 151 | G.last_attr = attr; | 155 | |
| 152 | 156 | ptr = G.attrbuf + 2; /* skip "ESC [" */ | |
| 153 | //attr >>= 1; // for framebuffer console | 157 | |
| 154 | ptr = G.attrbuf + sizeof("\033[")-1; | 158 | // (G.last_attr & ~attr) has 1 only where |
| 155 | fg = (attr & 0x07); | 159 | // G.last_attr has 1 but attr has 0. |
| 156 | bold = (attr & 0x08); | 160 | // Here we check whether we have transition |
| 157 | bg = (attr & 0x70); | 161 | // bold->non-bold or blink->non-blink: |
| 158 | blink = (attr & 0x80); | 162 | if ((G.last_attr & ~attr) & (bold_mask | blink_mask)) { |
| 159 | if (G.last_bold > bold || G.last_blink > blink) { | 163 | *ptr++ = '0'; // "reset all attrs" |
| 160 | G.last_bold = G.last_blink = 0; | 164 | *ptr++ = ';'; |
| 161 | G.last_bg = 0xff; | 165 | // must set fg & bg, maybe need to set bold or blink: |
| 162 | *ptr++ = '0'; | 166 | attr_diff = attr | ~(bold_mask | blink_mask); |
| 163 | *ptr++ = ';'; | 167 | } |
| 164 | } | 168 | G.force_attr_change = 0; |
| 165 | if (G.last_bold != bold) { | 169 | G.last_attr = attr; |
| 166 | G.last_bold = bold; | 170 | if (attr_diff & bold_mask) { |
| 167 | *ptr++ = '1'; | 171 | *ptr++ = '1'; |
| 168 | *ptr++ = ';'; | 172 | *ptr++ = ';'; |
| 169 | } | 173 | } |
| 170 | if (G.last_blink != blink) { | 174 | if (attr_diff & blink_mask) { |
| 171 | G.last_blink = blink; | 175 | *ptr++ = '5'; |
| 172 | *ptr++ = '5'; | 176 | *ptr++ = ';'; |
| 173 | *ptr++ = ';'; | 177 | } |
| 174 | } | 178 | if (attr_diff & fg_mask) { |
| 175 | if (G.last_fg != fg) { | 179 | *ptr++ = '3'; |
| 176 | G.last_fg = fg; | 180 | *ptr++ = color[attr & fg_mask]; |
| 177 | *ptr++ = '3'; | 181 | *ptr++ = ';'; |
| 178 | *ptr++ = color[fg]; | 182 | } |
| 179 | *ptr++ = ';'; | 183 | if (attr_diff & bg_mask) { |
| 180 | } | 184 | *ptr++ = '4'; |
| 181 | if (G.last_bg != bg) { | 185 | *ptr++ = color[(attr & bg_mask) >> 4]; |
| 182 | G.last_bg = bg; | 186 | *ptr++ = ';'; |
| 183 | *ptr++ = '4'; | 187 | } |
| 184 | *ptr++ = color[bg >> 4]; | 188 | if (ptr != G.attrbuf + 2) { |
| 185 | *ptr++ = ';'; | 189 | ptr[-1] = 'm'; |
| 186 | } | 190 | *ptr = '\0'; |
| 187 | if (ptr != G.attrbuf + sizeof("\033[")-1) { | 191 | fputs(G.attrbuf, stdout); |
| 188 | ptr[-1] = 'm'; | 192 | } |
| 189 | *ptr = '\0'; | ||
| 190 | fputs(G.attrbuf, stdout); | ||
| 191 | } | 193 | } |
| 192 | } | 194 | } |
| 193 | putchar(CHAR(data)); | 195 | putchar(CHAR(data)); |
| @@ -402,6 +404,7 @@ int conspy_main(int argc UNUSED_PARAM, char **argv) | |||
| 402 | termbuf.c_cc[VMIN] = 1; | 404 | termbuf.c_cc[VMIN] = 1; |
| 403 | termbuf.c_cc[VTIME] = 0; | 405 | termbuf.c_cc[VTIME] = 0; |
| 404 | tcsetattr(G.kbd_fd, TCSANOW, &termbuf); | 406 | tcsetattr(G.kbd_fd, TCSANOW, &termbuf); |
| 407 | |||
| 405 | poll_timeout_ms = 250; | 408 | poll_timeout_ms = 250; |
| 406 | while (1) { | 409 | while (1) { |
| 407 | struct pollfd pfd; | 410 | struct pollfd pfd; |
