Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/procps
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (8 years ago)
- Location:
- branches/3.3
- Files:
-
- 3 added
- 15 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/procps/free.c
r3232 r3621 23 23 24 24 #include "libbb.h" 25 #include "common_bufsiz.h" 25 26 #ifdef __linux__ 26 27 # include <sys/sysinfo.h> … … 36 37 #endif 37 38 } FIX_ALIASING; 38 #define G (*(struct globals*) &bb_common_bufsiz1)39 #define INIT_G() do { } while (0)39 #define G (*(struct globals*)bb_common_bufsiz1) 40 #define INIT_G() do { setup_common_bufsiz(); } while (0) 40 41 41 42 … … 45 46 } 46 47 48 static unsigned long parse_cached_kb(void) 49 { 50 char buf[60]; /* actual lines we expect are ~30 chars or less */ 51 FILE *fp; 52 unsigned long cached = 0; 53 54 fp = xfopen_for_read("/proc/meminfo"); 55 while (fgets(buf, sizeof(buf), fp) != NULL) { 56 if (sscanf(buf, "Cached: %lu %*s\n", &cached) == 1) 57 break; 58 } 59 if (ENABLE_FEATURE_CLEAN_UP) 60 fclose(fp); 61 62 return cached; 63 } 47 64 48 65 int free_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; … … 50 67 { 51 68 struct sysinfo info; 69 unsigned long long cached; 52 70 53 71 INIT_G(); … … 74 92 } 75 93 #endif 76 77 sysinfo(&info); 78 79 /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */ 80 G.mem_unit = (info.mem_unit ? info.mem_unit : 1); 81 82 printf(" %13s%13s%13s%13s%13s\n", 94 printf(" %11s%11s%11s%11s%11s%11s\n" 95 "Mem: ", 83 96 "total", 84 97 "used", 85 98 "free", 86 "shared", "buffers" /* swap and total don't have these columns */ 87 /* procps version 3.2.8 also shows "cached" column, but 88 * sysinfo() does not provide this value, need to parse 89 * /proc/meminfo instead and get "Cached: NNN kB" from there. 90 */ 99 "shared", "buffers", "cached" /* swap and total don't have these columns */ 91 100 ); 92 101 93 #define FIELDS_5 "%13llu%13llu%13llu%13llu%13llu\n" 94 #define FIELDS_3 (FIELDS_5 + 2*6) 95 #define FIELDS_2 (FIELDS_5 + 3*6) 102 sysinfo(&info); 103 /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */ 104 G.mem_unit = (info.mem_unit ? info.mem_unit : 1); 105 /* Extract cached from /proc/meminfo and convert to mem_units */ 106 cached = ((unsigned long long) parse_cached_kb() * 1024) / G.mem_unit; 96 107 97 printf("Mem: "); 98 printf(FIELDS_5, 99 scale(info.totalram), 100 scale(info.totalram - info.freeram), 101 scale(info.freeram), 102 scale(info.sharedram), 103 scale(info.bufferram) 108 #define FIELDS_6 "%11llu%11llu%11llu%11llu%11llu%11llu\n" 109 #define FIELDS_3 (FIELDS_6 + 3*6) 110 #define FIELDS_2 (FIELDS_6 + 4*6) 111 112 printf(FIELDS_6, 113 scale(info.totalram), //total 114 scale(info.totalram - info.freeram), //used 115 scale(info.freeram), //free 116 scale(info.sharedram), //shared 117 scale(info.bufferram), //buffers 118 scale(cached) //cached 104 119 ); 105 120 /* Show alternate, more meaningful busy/free numbers by counting 106 * buffer cache as free memory (make it "-/+ buffers/cache" 107 * if/when we add support for "cached" column): */ 108 printf("-/+ buffers: "); 121 * buffer cache as free memory. */ 122 printf("-/+ buffers/cache:"); 123 cached += info.freeram; 124 cached += info.bufferram; 109 125 printf(FIELDS_2, 110 scale(info.totalram - info.freeram - info.bufferram),111 scale( info.freeram + info.bufferram)126 scale(info.totalram - cached), //used 127 scale(cached) //free 112 128 ); 113 129 #if BB_MMU 114 printf("Swap: ");130 printf("Swap: "); 115 131 printf(FIELDS_3, 116 scale(info.totalswap), 117 scale(info.totalswap - info.freeswap), 118 scale(info.freeswap) 132 scale(info.totalswap), //total 133 scale(info.totalswap - info.freeswap), //used 134 scale(info.freeswap) //free 119 135 ); 120 136 #endif -
branches/3.3/mindi-busybox/procps/fuser.c
r3232 r3621 19 19 20 20 #include "libbb.h" 21 #include "common_bufsiz.h" 21 22 22 23 #define MAX_LINE 255 … … 44 45 int killsig; 45 46 } FIX_ALIASING; 46 #define G (*(struct globals*) &bb_common_bufsiz1)47 #define G (*(struct globals*)bb_common_bufsiz1) 47 48 #define INIT_G() do { \ 49 setup_common_bufsiz(); \ 48 50 G.mypid = getpid(); \ 49 51 G.killsig = SIGKILL; \ -
branches/3.3/mindi-busybox/procps/iostat.c
r3232 r3621 110 110 }; 111 111 112 static ALWAYS_INLINE unsigned get_user_hz(void)113 {114 return sysconf(_SC_CLK_TCK);115 }116 117 112 static ALWAYS_INLINE int this_is_smp(void) 118 113 { … … 148 143 /* %X: time representation for the current locale */ 149 144 strftime(buf, sizeof(buf), "%x %X", &G.tmtime); 150 p rintf("%s\n",buf);145 puts(buf); 151 146 } 152 147 … … 415 410 416 411 /* Get number of clock ticks per sec */ 417 G.clk_tck = get_user_hz();412 G.clk_tck = bb_clk_tck(); 418 413 419 414 /* Determine number of CPUs */ -
branches/3.3/mindi-busybox/procps/kill.c
r3232 r3621 61 61 */ 62 62 63 int kill_main(int argc , char **argv)63 int kill_main(int argc UNUSED_PARAM, char **argv) 64 64 { 65 65 char *arg; … … 80 80 81 81 /* Parse any options */ 82 argc--;83 82 arg = *++argv; 84 83 85 if ( argc < 1|| arg[0] != '-') {84 if (!arg || arg[0] != '-') { 86 85 goto do_it_now; 87 86 } … … 92 91 * We try to mimic what kill from coreutils-6.8 does */ 93 92 if (arg[1] == 'l' && arg[2] == '\0') { 94 if (argc == 1) { 93 arg = *++argv; 94 if (!arg) { 95 95 /* Print the whole signal list */ 96 96 print_signames(); … … 98 98 } 99 99 /* -l <sig list> */ 100 while ((arg = *++argv)){100 do { 101 101 if (isdigit(arg[0])) { 102 102 signo = bb_strtou(arg, NULL, 10); … … 119 119 printf("%d\n", signo); 120 120 } 121 }122 /* If they specified -l, we are all done */121 arg = *++argv; 122 } while (arg); 123 123 return EXIT_SUCCESS; 124 124 } … … 128 128 quiet = 1; 129 129 arg = *++argv; 130 argc--; 131 if (argc < 1) 130 if (!arg) 132 131 bb_show_usage(); 133 132 if (arg[0] != '-') … … 141 140 goto do_it_now; 142 141 143 if (argc > 1 && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */ 144 argc--; 142 if (argv[1] && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */ 145 143 arg = *++argv; 146 144 } /* else it must be -SIG */ … … 151 149 } 152 150 arg = *++argv; 153 argc--;154 151 155 152 do_it_now: … … 159 156 pid_t sid; 160 157 procps_status_t* p = NULL; 161 int ret = 0; 158 /* compat: exitcode 2 is "no one was signaled" */ 159 int ret = 2; 162 160 163 161 /* Find out our session id */ … … 168 166 /* Signal all processes except those in our session */ 169 167 while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_SID)) != NULL) { 170 int i;168 char **args; 171 169 172 170 if (p->sid == (unsigned)sid 171 || p->sid == 0 /* compat: kernel thread, don't signal it */ 173 172 || p->pid == (unsigned)pid 174 173 || p->pid == 1 … … 179 178 /* All remaining args must be -o PID options. 180 179 * Check p->pid against them. */ 181 for (i = 0; i < argc; i++) { 180 args = argv; 181 while (*args) { 182 182 pid_t omit; 183 183 184 arg = argv[i];184 arg = *args++; 185 185 if (arg[0] != '-' || arg[1] != 'o') { 186 186 bb_error_msg("bad option '%s'", arg); … … 189 189 } 190 190 arg += 2; 191 if (!arg[0] && argv[++i])192 arg = argv[i];191 if (!arg[0] && *args) 192 arg = *args++; 193 193 omit = bb_strtoi(arg, NULL, 10); 194 194 if (errno) { … … 201 201 } 202 202 kill(p->pid, signo); 203 ret = 0; 203 204 dont_kill: ; 204 205 } … … 211 212 212 213 /* Pid or name is required for kill/killall */ 213 if ( argc < 1) {214 if (!arg) { 214 215 bb_error_msg("you need to specify whom to kill"); 215 216 return EXIT_FAILURE; … … 218 219 if (killall) { 219 220 /* Looks like they want to do a killall. Do that */ 220 while (arg){221 do { 221 222 pid_t* pidList; 222 223 … … 241 242 free(pidList); 242 243 arg = *++argv; 243 } 244 } while (arg); 244 245 return errors; 245 246 } -
branches/3.3/mindi-busybox/procps/mpstat.c
r3232 r3621 523 523 char buf[1024]; 524 524 525 fp = fopen_for_read(PROCFS_STAT); 526 if (!fp) 527 return; 525 fp = xfopen_for_read(PROCFS_STAT); 528 526 529 527 while (fgets(buf, sizeof(buf), fp)) { 530 528 //bb_error_msg("/proc/stat:'%s'", buf); 531 if ( strncmp(buf, "intr ", 5) == 0) {529 if (is_prefixed_with(buf, "intr ")) { 532 530 /* Read total number of IRQs since system boot */ 533 531 sscanf(buf + 5, "%"FMT_DATA"u", &irq->irq_nr); … … 645 643 unsigned long uptime_sec, decimal; 646 644 647 fp = fopen_for_read(PROCFS_UPTIME); 648 if (!fp) 649 return; 645 fp = xfopen_for_read(PROCFS_UPTIME); 650 646 if (fgets(buf, sizeof(buf), fp)) { 651 647 if (sscanf(buf, "%lu.%lu", &uptime_sec, &decimal) == 2) { … … 776 772 /* Initialization */ 777 773 778 /* Get number of clock ticks per sec */779 static ALWAYS_INLINE unsigned get_hz(void)780 {781 return sysconf(_SC_CLK_TCK);782 }783 784 774 static void alloc_struct(int cpus) 785 775 { … … 874 864 875 865 /* Get number of clock ticks per sec */ 876 G.hz = get_hz();866 G.hz = bb_clk_tck(); 877 867 878 868 /* Calculate number of interrupts per processor */ -
branches/3.3/mindi-busybox/procps/nmeter.c
r3232 r3621 22 22 //usage: "Monitor system in real time" 23 23 //usage: "\n" 24 //usage: "\n -d MSEC Milliseconds between updates (default:1000)"24 //usage: "\n -d MSEC Milliseconds between updates, default:1000, none:-1" 25 25 //usage: "\n" 26 26 //usage: "\nFormat specifiers:" … … 54 54 55 55 #include "libbb.h" 56 #include "common_bufsiz.h" 56 57 57 58 typedef unsigned long long ullong; … … 84 85 // 1 if sample delay is not an integer fraction of a second 85 86 smallint need_seconds; 87 char final_char; 86 88 char *cur_outbuf; 87 const char *final_str;88 89 int delta; 89 intdeltanz;90 unsigned deltanz; 90 91 struct timeval tv; 91 92 #define first_proc_file proc_stat … … 102 103 #define need_seconds (G.need_seconds ) 103 104 #define cur_outbuf (G.cur_outbuf ) 104 #define final_str (G.final_str )105 #define delta (G.delta )106 #define deltanz (G.deltanz )107 105 #define tv (G.tv ) 108 106 #define proc_stat (G.proc_stat ) … … 112 110 #define proc_diskstats (G.proc_diskstats ) 113 111 #define proc_sys_fs_filenr (G.proc_sys_fs_filenr) 112 #define outbuf bb_common_bufsiz1 114 113 #define INIT_G() do { \ 114 setup_common_bufsiz(); \ 115 115 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 116 116 cur_outbuf = outbuf; \ 117 final_str = "\n"; \118 deltanz =delta = 1000000; \117 G.final_char = '\n'; \ 118 G.deltanz = G.delta = 1000000; \ 119 119 } while (0) 120 121 // We depend on this being a char[], not char* - we take sizeof() of it122 #define outbuf bb_common_bufsiz1123 120 124 121 static inline void reset_outbuf(void) … … 143 140 static void put(const char *s) 144 141 { 145 int sz = strlen(s);146 i f (sz > outbuf + sizeof(outbuf) - cur_outbuf)147 sz = outbuf + sizeof(outbuf) - cur_outbuf;148 memcpy(cur_outbuf, s, sz);149 cur_outbuf += sz;142 char *p = cur_outbuf; 143 int sz = outbuf + COMMON_BUFSIZE - p; 144 while (*s && --sz >= 0) 145 *p++ = *s++; 146 cur_outbuf = p; 150 147 } 151 148 152 149 static void put_c(char c) 153 150 { 154 if (cur_outbuf < outbuf + sizeof(outbuf))151 if (cur_outbuf < outbuf + COMMON_BUFSIZE) 155 152 *cur_outbuf++ = c; 156 153 } … … 209 206 } 210 207 211 enum conv_type { conv_decimal, conv_slash }; 208 enum conv_type { 209 conv_decimal = 0, 210 conv_slash = 1 211 }; 212 212 213 213 // Reads decimal values from line. Values start after key, for example: 214 214 // "cpu 649369 0 341297 4336769..." - key is "cpu" here. 215 // Values are stored in vec[]. arg_ptr has list of positions216 // we are interested in: for example: 1,2,5 - we want 1st, 2nd and 5th value.217 static int vrdval(const char* p, const char* key, 218 enum conv_type conv, ullong *vec, va_list arg_ptr) 219 { 220 int indexline; 221 int indexnext;215 // Values are stored in vec[]. 216 // posbits is a bit lit of positions we are interested in. 217 // for example: 00100110 - we want 1st, 2nd and 5th value. 218 // posbits.bit0 encodes conversion type. 219 static int rdval(const char* p, const char* key, ullong *vec, long posbits) 220 { 221 unsigned curpos; 222 222 223 223 p = strstr(p, key); … … 225 225 226 226 p += strlen(key); 227 indexline = 1; 228 indexnext = va_arg(arg_ptr, int); 227 curpos = 1 << 1; 229 228 while (1) { 230 229 while (*p == ' ' || *p == '\t') p++; 231 230 if (*p == '\n' || *p == '\0') break; 232 231 233 if ( indexline == indexnext) { // read this value234 *vec++ = conv==conv_decimal ?232 if (curpos & posbits) { // read this value 233 *vec++ = (posbits & 1) == conv_decimal ? 235 234 strtoull(p, NULL, 10) : 236 235 read_after_slash(p); 237 indexnext = va_arg(arg_ptr, int); 236 posbits -= curpos; 237 if (posbits <= 1) 238 return 0; 238 239 } 239 while (*p > ' ') p++; // skip over value 240 indexline++; 240 while (*p > ' ') // skip over the value 241 p++; 242 curpos <<= 1; 241 243 } 242 244 return 0; 243 245 } 244 246 245 // Parses files with lines like "cpu0 21727 0 15718 1813856 9461 10485 0 0": 246 // rdval(file_contents, "string_to_find", result_vector, value#, value#...) 247 // value# start with 1 248 static int rdval(const char* p, const char* key, ullong *vec, ...) 249 { 250 va_list arg_ptr; 247 // Parses files with lines like "... ... ... 3/148 ...." 248 static int rdval_loadavg(const char* p, ullong *vec, long posbits) 249 { 251 250 int result; 252 253 va_start(arg_ptr, vec); 254 result = vrdval(p, key, conv_decimal, vec, arg_ptr); 255 va_end(arg_ptr); 256 257 return result; 258 } 259 260 // Parses files with lines like "... ... ... 3/148 ...." 261 static int rdval_loadavg(const char* p, ullong *vec, ...) 262 { 263 va_list arg_ptr; 264 int result; 265 266 va_start(arg_ptr, vec); 267 result = vrdval(p, "", conv_slash, vec, arg_ptr); 268 va_end(arg_ptr); 269 251 result = rdval(p, "", vec, posbits | conv_slash); 270 252 return result; 271 253 } … … 334 316 335 317 /* see http://en.wikipedia.org/wiki/Tera */ 336 smart_ulltoa4(ul, buf, " kmgtpezy"); 337 buf[4] = '\0'; 318 smart_ulltoa4(ul, buf, " kmgtpezy")[0] = '\0'; 338 319 put(buf); 339 320 } 340 341 321 342 322 #define S_STAT(a) \ … … 361 341 } 362 342 363 static s_stat* init_delay(const char *param) 364 { 365 delta = strtoul(param, NULL, 0) * 1000; /* param can be "" */ 366 deltanz = delta > 0 ? delta : 1; 367 need_seconds = (1000000%deltanz) != 0; 343 static s_stat* init_cr(const char *param UNUSED_PARAM) 344 { 345 G.final_char = '\r'; 368 346 return NULL; 369 347 } 370 371 static s_stat* init_cr(const char *param UNUSED_PARAM)372 {373 final_str = "\r";374 return (s_stat*)0;375 }376 377 348 378 349 // user nice system idle iowait irq softirq (last 3 only in 2.6) … … 383 354 ullong old[CPU_FIELDCNT]; 384 355 int bar_sz; 385 char *bar;356 char bar[1]; 386 357 S_STAT_END(cpu_stat) 387 388 358 389 359 static void FAST_FUNC collect_cpu(cpu_stat *s) … … 397 367 int i; 398 368 399 if (rdval(get_file(&proc_stat), "cpu ", data, 1, 2, 3, 4, 5, 6, 7)) { 369 if (rdval(get_file(&proc_stat), "cpu ", data, 0 370 | (1 << 1) 371 | (1 << 2) 372 | (1 << 3) 373 | (1 << 4) 374 | (1 << 5) 375 | (1 << 6) 376 | (1 << 7)) 377 ) { 400 378 put_question_marks(bar_sz); 401 379 return; … … 440 418 } 441 419 442 443 420 static s_stat* init_cpu(const char *param) 444 421 { 445 422 int sz; 446 cpu_stat *s = xzalloc(sizeof(*s)); 447 s->collect = collect_cpu; 423 cpu_stat *s; 448 424 sz = strtoul(param, NULL, 0); /* param can be "" */ 449 425 if (sz < 10) sz = 10; 450 426 if (sz > 1000) sz = 1000; 451 s ->bar = xzalloc(sz+1);427 s = xzalloc(sizeof(*s) + sz); 452 428 /*s->bar[sz] = '\0'; - xzalloc did it */ 453 429 s->bar_sz = sz; 454 return (s_stat*)s;455 } 456 430 s->collect = collect_cpu; 431 return (s_stat*)s; 432 } 457 433 458 434 S_STAT(int_stat) … … 466 442 ullong old; 467 443 468 if (rdval(get_file(&proc_stat), "intr", data, s->no)) {444 if (rdval(get_file(&proc_stat), "intr", data, 1 << s->no)) { 469 445 put_question_marks(4); 470 446 return; … … 490 466 } 491 467 492 493 468 S_STAT(ctx_stat) 494 469 ullong old; … … 500 475 ullong old; 501 476 502 if (rdval(get_file(&proc_stat), "ctxt", data, 1 )) {477 if (rdval(get_file(&proc_stat), "ctxt", data, 1 << 1)) { 503 478 put_question_marks(4); 504 479 return; … … 518 493 } 519 494 520 521 495 S_STAT(blk_stat) 522 496 const char* lookfor; … … 532 506 i = rdval_diskstats(get_file(&proc_diskstats), data); 533 507 } else { 534 i = rdval(get_file(&proc_stat), s->lookfor, data, 1, 2); 508 i = rdval(get_file(&proc_stat), s->lookfor, data, 0 509 | (1 << 1) 510 | (1 << 2) 511 ); 535 512 // Linux 2.4 reports bio in Kbytes, convert to sectors: 536 513 data[0] *= 2; … … 561 538 } 562 539 563 564 540 S_STAT(fork_stat) 565 541 ullong old; … … 570 546 ullong data[1]; 571 547 572 if (rdval_loadavg(get_file(&proc_loadavg), data, 4)) {548 if (rdval_loadavg(get_file(&proc_loadavg), data, 1 << 4)) { 573 549 put_question_marks(4); 574 550 return; … … 582 558 ullong old; 583 559 584 if (rdval(get_file(&proc_stat), "processes", data, 1 )) {560 if (rdval(get_file(&proc_stat), "processes", data, 1 << 1)) { 585 561 put_question_marks(4); 586 562 return; … … 604 580 } 605 581 606 607 582 S_STAT(if_stat) 608 583 ullong old[4]; … … 616 591 int i; 617 592 618 if (rdval(get_file(&proc_net_dev), s->device_colon, data, 1, 3, 9, 11)) { 593 if (rdval(get_file(&proc_net_dev), s->device_colon, data, 0 594 | (1 << 1) 595 | (1 << 3) 596 | (1 << 9) 597 | (1 << 11)) 598 ) { 619 599 put_question_marks(10); 620 600 return; … … 645 625 return (s_stat*)s; 646 626 } 647 648 627 649 628 S_STAT(mem_stat) … … 694 673 ullong m_slab = 0; 695 674 696 if (rdval(get_file(&proc_meminfo), "MemTotal:", &m_total, 1 )) {675 if (rdval(get_file(&proc_meminfo), "MemTotal:", &m_total, 1 << 1)) { 697 676 put_question_marks(4); 698 677 return; … … 703 682 } 704 683 705 if (rdval(proc_meminfo.file, "MemFree:", &m_free , 1 )706 || rdval(proc_meminfo.file, "Buffers:", &m_bufs , 1 )707 || rdval(proc_meminfo.file, "Cached:", &m_cached, 1 )708 || rdval(proc_meminfo.file, "Slab:", &m_slab , 1 )684 if (rdval(proc_meminfo.file, "MemFree:", &m_free , 1 << 1) 685 || rdval(proc_meminfo.file, "Buffers:", &m_bufs , 1 << 1) 686 || rdval(proc_meminfo.file, "Cached:", &m_cached, 1 << 1) 687 || rdval(proc_meminfo.file, "Slab:", &m_slab , 1 << 1) 709 688 ) { 710 689 put_question_marks(4); … … 729 708 } 730 709 731 732 710 S_STAT(swp_stat) 733 711 S_STAT_END(swp_stat) … … 737 715 ullong s_total[1]; 738 716 ullong s_free[1]; 739 if (rdval(get_file(&proc_meminfo), "SwapTotal:", s_total, 1 )740 || rdval(proc_meminfo.file, "SwapFree:" , s_free, 1 )717 if (rdval(get_file(&proc_meminfo), "SwapTotal:", s_total, 1 << 1) 718 || rdval(proc_meminfo.file, "SwapFree:" , s_free, 1 << 1) 741 719 ) { 742 720 put_question_marks(4); … … 753 731 } 754 732 755 756 733 S_STAT(fd_stat) 757 734 S_STAT_END(fd_stat) … … 761 738 ullong data[2]; 762 739 763 if (rdval(get_file(&proc_sys_fs_filenr), "", data, 1, 2)) { 740 if (rdval(get_file(&proc_sys_fs_filenr), "", data, 0 741 | (1 << 1) 742 | (1 << 2)) 743 ) { 764 744 put_question_marks(4); 765 745 return; … … 776 756 } 777 757 778 779 758 S_STAT(time_stat) 780 intprec;781 intscale;759 unsigned prec; 760 unsigned scale; 782 761 S_STAT_END(time_stat) 783 762 … … 786 765 char buf[sizeof("12:34:56.123456")]; 787 766 struct tm* tm; 788 intus = tv.tv_usec + s->scale/2;767 unsigned us = tv.tv_usec + s->scale/2; 789 768 time_t t = tv.tv_sec; 790 769 … … 827 806 } 828 807 829 830 808 typedef s_stat* init_func(const char *param); 831 809 832 // Deprecated %NNNd is to be removed, -d MSEC supersedes it 833 static const char options[] ALIGN1 = "ncmsfixptbdr"; 810 static const char options[] ALIGN1 = "ncmsfixptbr"; 834 811 static init_func *const init_functions[] = { 835 812 init_if, … … 843 820 init_time, 844 821 init_blk, 845 init_delay,846 822 init_cr 847 823 }; … … 866 842 } 867 843 868 if (getopt32(argv, "d:", &opt_d)) 869 init_delay(opt_d); 844 if (getopt32(argv, "d:", &opt_d)) { 845 G.delta = xatoi(opt_d) * 1000; 846 G.deltanz = G.delta > 0 ? G.delta : 1; 847 need_seconds = (1000000 % G.deltanz) != 0; 848 } 870 849 argv += optind; 871 850 … … 922 901 last = s; 923 902 } else { 924 // % NNNNd or %r option. remove it from string925 strcpy(prev + strlen(prev), cur);903 // %r option. remove it from string 904 overlapping_strcpy(prev + strlen(prev), cur); 926 905 cur = prev; 927 906 } … … 941 920 collect_info(first); 942 921 reset_outbuf(); 943 if ( delta >= 0) {922 if (G.delta >= 0) { 944 923 gettimeofday(&tv, NULL); 945 usleep( delta > 1000000 ? 1000000 : delta - tv.tv_usec%deltanz);924 usleep(G.delta > 1000000 ? 1000000 : G.delta - tv.tv_usec % G.deltanz); 946 925 } 947 926 … … 949 928 gettimeofday(&tv, NULL); 950 929 collect_info(first); 951 put (final_str);930 put_c(G.final_char); 952 931 print_outbuf(); 953 932 … … 957 936 // TODO: detect and avoid useless updates 958 937 // (like: nothing happens except time) 959 if ( delta >= 0) {938 if (G.delta >= 0) { 960 939 int rem; 961 940 // can be commented out, will sacrifice sleep time precision a bit 962 941 gettimeofday(&tv, NULL); 963 942 if (need_seconds) 964 rem = delta - ((ullong)tv.tv_sec*1000000 + tv.tv_usec) %deltanz;943 rem = G.delta - ((ullong)tv.tv_sec*1000000 + tv.tv_usec) % G.deltanz; 965 944 else 966 rem = delta - tv.tv_usec%deltanz;945 rem = G.delta - (unsigned)tv.tv_usec % G.deltanz; 967 946 // Sometimes kernel wakes us up just a tiny bit earlier than asked 968 947 // Do not go to very short sleep in this case 969 if (rem < delta/128) {970 rem += delta;948 if (rem < (unsigned)G.delta / 128) { 949 rem += G.delta; 971 950 } 972 951 usleep(rem); -
branches/3.3/mindi-busybox/procps/pgrep.c
r3232 r3621 66 66 if (pgrep) { 67 67 if (option_mask32 & (1 << OPTBIT_L)) /* OPT_LIST */ 68 printf("% d%s\n", pid, cmd);68 printf("%u %s\n", pid, cmd); 69 69 else 70 printf("% d\n", pid);70 printf("%u\n", pid); 71 71 } else 72 72 kill(pid, signo); … … 129 129 130 130 if (argv[0]) 131 xregcomp(&re_buffer, argv[0], REG_EXTENDED | REG_NOSUB);131 xregcomp(&re_buffer, argv[0], OPT_ANCHOR ? REG_EXTENDED : (REG_EXTENDED|REG_NOSUB)); 132 132 133 133 matched_pid = 0; -
branches/3.3/mindi-busybox/procps/pmap.c
r3232 r3621 21 21 //usage: "[-xq] PID" 22 22 //usage:#define pmap_full_usage "\n\n" 23 //usage: "Display detailedprocess memory usage"23 //usage: "Display process memory usage" 24 24 //usage: "\n" 25 25 //usage: "\n -x Show details" … … 67 67 char buf[256]; 68 68 69 read_cmdline(buf, sizeof(buf), pid, "no such process");69 read_cmdline(buf, sizeof(buf), pid, NULL); 70 70 printf("%u: %s\n", (int)pid, buf); 71 71 -
branches/3.3/mindi-busybox/procps/powertop.c
r3232 r3621 361 361 362 362 name = p; 363 strchrnul(name, '\n')[0] = '\0';363 chomp(p); 364 364 /* Save description of the interrupt */ 365 365 if (nr >= 20000) … … 459 459 //} 460 460 461 if ( strncmp(func, "tick_nohz_", 10) == 0)462 continue; 463 if ( strncmp(func, "tick_setup_sched_timer", 20) == 0)461 if (is_prefixed_with(func, "tick_nohz_")) 462 continue; 463 if (is_prefixed_with(func, "tick_setup_sched_timer")) 464 464 continue; 465 465 //if (strcmp(process, "powertop") == 0) … … 471 471 } 472 472 473 strchrnul(p, '\n')[0] = '\0';473 chomp(p); 474 474 475 475 // 46D\01136\0kondemand/1\0do_dbs_timer (delayed_work_timer_fn) … … 592 592 return; 593 593 594 printf("Your CPU supports the following C-states:");594 printf("Your %s the following C-states: ", "CPU supports"); 595 595 i = 0; 596 596 while (edx) { … … 603 603 604 604 /* Print BIOS C-States */ 605 printf("Your BIOS reports the following C-states:");605 printf("Your %s the following C-states: ", "BIOS reports"); 606 606 for (i = 0; i < ARRAY_SIZE(bios_table); i++) 607 607 if (bios_table[i]) … … 628 628 char strbuf6[6]; 629 629 630 strbuf6[5] = '\0';631 630 puts("\nTop causes for wakeups:"); 632 631 for (i = 0; i < G.lines_cnt; i++) { … … 640 639 if (G.lines[i].disk_count) 641 640 c = 'D';*/ 642 smart_ulltoa5(G.lines[i].count, strbuf6, " KMGTPEZY") ;641 smart_ulltoa5(G.lines[i].count, strbuf6, " KMGTPEZY")[0] = '\0'; 643 642 printf(/*" %5.1f%% (%s)%c %s\n"*/ 644 643 " %5.1f%% (%s) %s\n", … … 676 675 //usage: "" 677 676 //usage:#define powertop_full_usage "\n\n" 678 //usage: "Analyze power consumption on Intel-based laptops \n"677 //usage: "Analyze power consumption on Intel-based laptops" 679 678 680 679 int powertop_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; … … 706 705 G.total_cpus = get_cpu_count(); 707 706 708 p rintf("Collecting data for "DEFAULT_SLEEP_STR" seconds\n");707 puts("Collecting data for "DEFAULT_SLEEP_STR" seconds"); 709 708 710 709 #if ENABLE_FEATURE_USE_TERMIOS -
branches/3.3/mindi-busybox/procps/ps.c
r3232 r3621 63 63 64 64 #include "libbb.h" 65 #include "common_bufsiz.h" 65 66 #ifdef __linux__ 66 67 # include <sys/sysinfo.h> … … 71 72 72 73 #if ENABLE_FEATURE_PS_TIME || ENABLE_FEATURE_PS_LONG 73 static long get_uptime(void)74 static unsigned long get_uptime(void) 74 75 { 75 76 #ifdef __linux__ … … 79 80 return info.uptime; 80 81 #elif 1 81 char buf[64]; 82 long uptime; 82 unsigned long uptime; 83 char buf[sizeof(uptime)*3 + 2]; 84 /* /proc/uptime is "UPTIME_SEC.NN IDLE_SEC.NN\n" 85 * (where IDLE is cumulative over all CPUs) 86 */ 83 87 if (open_read_close("/proc/uptime", buf, sizeof(buf)) <= 0) 84 bb_perror_msg_and_die("can't read %s", "/proc/uptime");88 bb_perror_msg_and_die("can't read '%s'", "/proc/uptime"); 85 89 buf[sizeof(buf)-1] = '\0'; 86 sscanf(buf, "%l ", &uptime);90 sscanf(buf, "%lu", &uptime); 87 91 return uptime; 88 92 #else … … 139 143 #if ENABLE_FEATURE_PS_TIME 140 144 unsigned kernel_HZ; 141 unsigned long longseconds_since_boot;145 unsigned long seconds_since_boot; 142 146 #endif 143 147 } FIX_ALIASING; 144 #define G (*(struct globals*) &bb_common_bufsiz1)148 #define G (*(struct globals*)bb_common_bufsiz1) 145 149 #define out (G.out ) 146 150 #define out_cnt (G.out_cnt ) … … 150 154 #define terminal_width (G.terminal_width ) 151 155 #define kernel_HZ (G.kernel_HZ ) 152 #define seconds_since_boot (G.seconds_since_boot) 153 #define INIT_G() do { } while (0) 156 #define INIT_G() do { setup_common_bufsiz(); } while (0) 154 157 155 158 #if ENABLE_FEATURE_PS_TIME 156 159 /* for ELF executables, notes are pushed before environment and args */ 157 static ptrdiff_t find_elf_note(ptrdiff_t findme)158 { 159 ptrdiff_t *ep = (ptrdiff_t *) environ;160 static uintptr_t find_elf_note(uintptr_t findme) 161 { 162 uintptr_t *ep = (uintptr_t *) environ; 160 163 161 164 while (*ep++) … … 223 226 static unsigned get_kernel_HZ(void) 224 227 { 225 226 228 if (kernel_HZ) 227 229 return kernel_HZ; … … 232 234 kernel_HZ = get_HZ_by_waiting(); 233 235 234 seconds_since_boot = get_uptime();236 G.seconds_since_boot = get_uptime(); 235 237 236 238 return kernel_HZ; … … 299 301 300 302 /* see http://en.wikipedia.org/wiki/Tera */ 301 smart_ulltoa4(u, buf4, " mgtpezy"); 302 buf4[4] = '\0'; 303 smart_ulltoa4(u, buf4, " mgtpezy")[0] = '\0'; 303 304 sprintf(buf, "%.*s", size, buf4); 304 305 } … … 351 352 mm = ps->start_time / get_kernel_HZ(); 352 353 /* must be after get_kernel_HZ()! */ 353 mm = seconds_since_boot - mm;354 mm = G.seconds_since_boot - mm; 354 355 ss = mm % 60; 355 356 mm /= 60; … … 589 590 // Select which columns to display 590 591 /* We allow (and ignore) most of the above. FIXME. 591 * -T is picked for threads (POSIX hasn't it standardized).592 * -T is picked for threads (POSIX hasn't standardized it). 592 593 * procps v3.2.7 supports -T and shows tids as SPID column, 593 594 * it also supports -L where it shows tids as LWP column. … … 600 601 } while (opt_o); 601 602 } else { 602 /* Below: parse_o() needs char*, NOT const char*, can't give it default_o */ 603 /* Below: parse_o() needs char*, NOT const char*, 604 * can't pass it constant string. Need to make a copy first. 605 */ 603 606 #if ENABLE_SELINUX 604 607 if (!(opt & OPT_Z) || !is_selinux_enabled()) { … … 621 624 terminal_width = MAX_WIDTH; 622 625 if (isatty(1)) { 623 get_terminal_width_height(0, &terminal_width, NULL);626 terminal_width = get_terminal_width(0); 624 627 if (--terminal_width > MAX_WIDTH) 625 628 terminal_width = MAX_WIDTH; … … 653 656 }; 654 657 #if ENABLE_FEATURE_PS_LONG 655 time_t now = now; 656 longuptime;658 time_t now = now; /* for compiler */ 659 unsigned long uptime = uptime; 657 660 #endif 658 661 /* If we support any options, parse argv */ … … 671 674 terminal_width = (w_count == 1) ? 132 : MAX_WIDTH; 672 675 } else { 673 get_terminal_width_height(0, &terminal_width, NULL);676 terminal_width = get_terminal_width(0); 674 677 /* Go one less... */ 675 678 if (--terminal_width > MAX_WIDTH) … … 738 741 { 739 742 char buf6[6]; 740 smart_ulltoa5(p->vsz, buf6, " mgtpezy"); 741 buf6[5] = '\0'; 743 smart_ulltoa5(p->vsz, buf6, " mgtpezy")[0] = '\0'; 742 744 #if ENABLE_FEATURE_PS_LONG 743 745 if (opts & OPT_l) { … … 750 752 struct tm *tm = localtime(&start); 751 753 752 smart_ulltoa5(p->rss, bufr, " mgtpezy"); 753 bufr[5] = '\0'; 754 smart_ulltoa5(p->rss, bufr, " mgtpezy")[0] = '\0'; 754 755 755 756 if (p->tty_major == 136) … … 787 788 { 788 789 int sz = terminal_width - len; 789 char buf[sz + 1]; 790 read_cmdline(buf, sz, p->pid, p->comm); 791 puts(buf); 790 if (sz >= 0) { 791 char buf[sz + 1]; 792 read_cmdline(buf, sz, p->pid, p->comm); 793 puts(buf); 794 } 792 795 } 793 796 } -
branches/3.3/mindi-busybox/procps/renice.c
r3232 r3621 21 21 22 22 //usage:#define renice_trivial_usage 23 //usage: " {{-n INCREMENT} | PRIORITY} [[-p | -g | -u] ID...]"23 //usage: "[-n] PRIORITY [[-p | -g | -u] ID...]..." 24 24 //usage:#define renice_full_usage "\n\n" 25 //usage: "Change scheduling priority for a running process\n" 26 //usage: "\n -n Adjust current nice value (smaller is faster)" 27 //usage: "\n -p Process id(s) (default)" 28 //usage: "\n -g Process group id(s)" 29 //usage: "\n -u Process user name(s) and/or id(s)" 25 //usage: "Change scheduling priority of a running process\n" 26 //usage: "\n -n Add PRIORITY to current nice value" 27 //usage: "\n Without -n, nice value is set to PRIORITY" 28 //usage: "\n -p Process ids (default)" 29 //usage: "\n -g Process group ids" 30 //usage: "\n -u Process user names" 30 31 31 32 #include "libbb.h" -
branches/3.3/mindi-busybox/procps/sysctl.c
r3232 r3621 130 130 if (fd < 0) { 131 131 switch (errno) { 132 case EACCES: 133 /* Happens for write-only settings, e.g. net.ipv6.route.flush */ 134 goto end; 132 135 case ENOENT: 133 136 if (option_mask32 & FLAG_SHOW_KEY_ERRORS) -
branches/3.3/mindi-busybox/procps/top.c
r3232 r3621 106 106 107 107 #include "libbb.h" 108 #include "common_bufsiz.h" 108 109 109 110 … … 184 185 }; //FIX_ALIASING; - large code growth 185 186 enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) }; 186 #define G (*(struct globals*)&bb_common_bufsiz1) 187 struct BUG_bad_size { 188 char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1]; 189 char BUG_line_buf_too_small[LINE_BUF_SIZE > 80 ? 1 : -1]; 190 }; 187 #define G (*(struct globals*)bb_common_bufsiz1) 191 188 #define top (G.top ) 192 189 #define ntop (G.ntop ) … … 205 202 #define total_pcpu (G.total_pcpu ) 206 203 #define line_buf (G.line_buf ) 207 #define INIT_G() do { } while (0) 204 #define INIT_G() do { \ 205 setup_common_bufsiz(); \ 206 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ 207 BUILD_BUG_ON(LINE_BUF_SIZE <= 80); \ 208 } while (0) 208 209 209 210 enum { … … 265 266 { 266 267 #if !ENABLE_FEATURE_TOP_SMP_CPU 267 static const char fmt[] = "cpu %llu %llu %llu %llu %llu %llu %llu %llu";268 static const char fmt[] ALIGN1 = "cpu %llu %llu %llu %llu %llu %llu %llu %llu"; 268 269 #else 269 static const char fmt[] = "cp%*s %llu %llu %llu %llu %llu %llu %llu %llu";270 static const char fmt[] ALIGN1 = "cp%*s %llu %llu %llu %llu %llu %llu %llu %llu"; 270 271 #endif 271 272 int ret; … … 295 296 prev_jif = cur_jif; 296 297 if (read_cpu_jiffy(fp, &cur_jif) < 4) 297 bb_error_msg_and_die("can't read /proc/stat");298 bb_error_msg_and_die("can't read '%s'", "/proc/stat"); 298 299 299 300 #if !ENABLE_FEATURE_TOP_SMP_CPU … … 500 501 #endif 501 502 503 enum { 504 MI_MEMTOTAL, 505 MI_MEMFREE, 506 MI_MEMSHARED, 507 MI_SHMEM, 508 MI_BUFFERS, 509 MI_CACHED, 510 MI_SWAPTOTAL, 511 MI_SWAPFREE, 512 MI_DIRTY, 513 MI_WRITEBACK, 514 MI_ANONPAGES, 515 MI_MAPPED, 516 MI_SLAB, 517 MI_MAX 518 }; 519 520 static void parse_meminfo(unsigned long meminfo[MI_MAX]) 521 { 522 static const char fields[] ALIGN1 = 523 "MemTotal\0" 524 "MemFree\0" 525 "MemShared\0" 526 "Shmem\0" 527 "Buffers\0" 528 "Cached\0" 529 "SwapTotal\0" 530 "SwapFree\0" 531 "Dirty\0" 532 "Writeback\0" 533 "AnonPages\0" 534 "Mapped\0" 535 "Slab\0"; 536 char buf[60]; /* actual lines we expect are ~30 chars or less */ 537 FILE *f; 538 int i; 539 540 memset(meminfo, 0, sizeof(meminfo[0]) * MI_MAX); 541 f = xfopen_for_read("meminfo"); 542 while (fgets(buf, sizeof(buf), f) != NULL) { 543 char *c = strchr(buf, ':'); 544 if (!c) 545 continue; 546 *c = '\0'; 547 i = index_in_strings(fields, buf); 548 if (i >= 0) 549 meminfo[i] = strtoul(c+1, NULL, 10); 550 } 551 fclose(f); 552 } 553 502 554 static unsigned long display_header(int scr_width, int *lines_rem_p) 503 555 { 504 FILE *fp; 505 char buf[80]; 506 char scrbuf[80]; 507 unsigned long total, used, mfree, shared, buffers, cached; 508 509 /* read memory info */ 510 fp = xfopen_for_read("meminfo"); 511 512 /* 513 * Old kernels (such as 2.4.x) had a nice summary of memory info that 514 * we could parse, however this is gone entirely in 2.6. Try parsing 515 * the old way first, and if that fails, parse each field manually. 516 * 517 * First, we read in the first line. Old kernels will have bogus 518 * strings we don't care about, whereas new kernels will start right 519 * out with MemTotal: 520 * -- PFM. 521 */ 522 if (fscanf(fp, "MemTotal: %lu %s\n", &total, buf) != 2) { 523 fgets(buf, sizeof(buf), fp); /* skip first line */ 524 525 fscanf(fp, "Mem: %lu %lu %lu %lu %lu %lu", 526 &total, &used, &mfree, &shared, &buffers, &cached); 527 /* convert to kilobytes */ 528 used /= 1024; 529 mfree /= 1024; 530 shared /= 1024; 531 buffers /= 1024; 532 cached /= 1024; 533 total /= 1024; 534 } else { 535 /* 536 * Revert to manual parsing, which incidentally already has the 537 * sizes in kilobytes. This should be safe for both 2.4 and 538 * 2.6. 539 */ 540 fscanf(fp, "MemFree: %lu %s\n", &mfree, buf); 541 542 /* 543 * MemShared: is no longer present in 2.6. Report this as 0, 544 * to maintain consistent behavior with normal procps. 545 */ 546 if (fscanf(fp, "MemShared: %lu %s\n", &shared, buf) != 2) 547 shared = 0; 548 549 fscanf(fp, "Buffers: %lu %s\n", &buffers, buf); 550 fscanf(fp, "Cached: %lu %s\n", &cached, buf); 551 552 used = total - mfree; 553 } 554 fclose(fp); 555 556 /* output memory info */ 556 char scrbuf[100]; /* [80] was a bit too low on 8Gb ram box */ 557 char *buf; 558 unsigned long meminfo[MI_MAX]; 559 560 parse_meminfo(meminfo); 561 562 /* Output memory info */ 557 563 if (scr_width > (int)sizeof(scrbuf)) 558 564 scr_width = sizeof(scrbuf); 559 565 snprintf(scrbuf, scr_width, 560 566 "Mem: %luK used, %luK free, %luK shrd, %luK buff, %luK cached", 561 used, mfree, shared, buffers, cached); 562 /* go to top & clear to the end of screen */ 567 meminfo[MI_MEMTOTAL] - meminfo[MI_MEMFREE], 568 meminfo[MI_MEMFREE], 569 meminfo[MI_MEMSHARED] + meminfo[MI_SHMEM], 570 meminfo[MI_BUFFERS], 571 meminfo[MI_CACHED]); 572 /* Go to top & clear to the end of screen */ 563 573 printf(OPT_BATCH_MODE ? "%s\n" : "\033[H\033[J%s\n", scrbuf); 564 574 (*lines_rem_p)--; 565 575 566 /* Display CPU time split as percentage of total time 567 * This displays either a cumulative line or one line per CPU 576 /* Display CPU time split as percentage of total time. 577 * This displays either a cumulative line or one line per CPU. 568 578 */ 569 579 display_cpus(scr_width, scrbuf, lines_rem_p); 570 580 571 /* read load average as a string */ 572 buf[0] = '\0'; 573 open_read_close("loadavg", buf, sizeof(buf) - 1); 574 buf[sizeof(buf) - 1] = '\n'; 575 *strchr(buf, '\n') = '\0'; 576 snprintf(scrbuf, scr_width, "Load average: %s", buf); 581 /* Read load average as a string */ 582 buf = stpcpy(scrbuf, "Load average: "); 583 open_read_close("loadavg", buf, sizeof(scrbuf) - sizeof("Load average: ")); 584 scrbuf[scr_width - 1] = '\0'; 585 strchrnul(buf, '\n')[0] = '\0'; 577 586 puts(scrbuf); 578 587 (*lines_rem_p)--; 579 588 580 return total;589 return meminfo[MI_MEMTOTAL]; 581 590 } 582 591 … … 678 687 sprintf(vsz_str_buf, "%6ldm", s->vsz/1024); 679 688 else 680 sprintf(vsz_str_buf, "%7l d", s->vsz);689 sprintf(vsz_str_buf, "%7lu", s->vsz); 681 690 /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */ 682 691 col = snprintf(line_buf, scr_width, … … 782 791 static void display_topmem_header(int scr_width, int *lines_rem_p) 783 792 { 784 enum { 785 TOTAL = 0, MFREE, BUF, CACHE, 786 SWAPTOTAL, SWAPFREE, DIRTY, 787 MWRITE, ANON, MAP, SLAB, 788 NUM_FIELDS 789 }; 790 static const char match[NUM_FIELDS][12] = { 791 "\x09" "MemTotal:", // TOTAL 792 "\x08" "MemFree:", // MFREE 793 "\x08" "Buffers:", // BUF 794 "\x07" "Cached:", // CACHE 795 "\x0a" "SwapTotal:", // SWAPTOTAL 796 "\x09" "SwapFree:", // SWAPFREE 797 "\x06" "Dirty:", // DIRTY 798 "\x0a" "Writeback:", // MWRITE 799 "\x0a" "AnonPages:", // ANON 800 "\x07" "Mapped:", // MAP 801 "\x05" "Slab:", // SLAB 802 }; 803 char meminfo_buf[4 * 1024]; 804 const char *Z[NUM_FIELDS]; 805 unsigned i; 806 int sz; 807 808 for (i = 0; i < NUM_FIELDS; i++) 809 Z[i] = "?"; 810 811 /* read memory info */ 812 sz = open_read_close("meminfo", meminfo_buf, sizeof(meminfo_buf) - 1); 813 if (sz >= 0) { 814 char *p = meminfo_buf; 815 meminfo_buf[sz] = '\0'; 816 /* Note that fields always appear in the match[] order */ 817 for (i = 0; i < NUM_FIELDS; i++) { 818 char *found = strstr(p, match[i] + 1); 819 if (found) { 820 /* Cut "NNNN" out of " NNNN kb" */ 821 char *s = skip_whitespace(found + match[i][0]); 822 p = skip_non_whitespace(s); 823 *p++ = '\0'; 824 Z[i] = s; 825 } 826 } 827 } 793 unsigned long meminfo[MI_MAX]; 794 795 parse_meminfo(meminfo); 828 796 829 797 snprintf(line_buf, LINE_BUF_SIZE, 830 "Mem total:%s anon:%s map:%s free:%s", 831 Z[TOTAL], Z[ANON], Z[MAP], Z[MFREE]); 798 "Mem total:%lu anon:%lu map:%lu free:%lu", 799 meminfo[MI_MEMTOTAL], 800 meminfo[MI_ANONPAGES], 801 meminfo[MI_MAPPED], 802 meminfo[MI_MEMFREE]); 832 803 printf(OPT_BATCH_MODE ? "%.*s\n" : "\033[H\033[J%.*s\n", scr_width, line_buf); 833 804 834 805 snprintf(line_buf, LINE_BUF_SIZE, 835 " slab:%s buf:%s cache:%s dirty:%s write:%s", 836 Z[SLAB], Z[BUF], Z[CACHE], Z[DIRTY], Z[MWRITE]); 806 " slab:%lu buf:%lu cache:%lu dirty:%lu write:%lu", 807 meminfo[MI_SLAB], 808 meminfo[MI_BUFFERS], 809 meminfo[MI_CACHED], 810 meminfo[MI_DIRTY], 811 meminfo[MI_WRITEBACK]); 837 812 printf("%.*s\n", scr_width, line_buf); 838 813 839 814 snprintf(line_buf, LINE_BUF_SIZE, 840 "Swap total:%s free:%s", // TODO: % used? 841 Z[SWAPTOTAL], Z[SWAPFREE]); 815 "Swap total:%lu free:%lu", // TODO: % used? 816 meminfo[MI_SWAPTOTAL], 817 meminfo[MI_SWAPFREE]); 842 818 printf("%.*s\n", scr_width, line_buf); 843 819 … … 848 824 { 849 825 /* see http://en.wikipedia.org/wiki/Tera */ 850 smart_ulltoa5(ul, buf, " mgtpezy"); 851 buf[5] = ' '; 826 smart_ulltoa5(ul, buf, " mgtpezy")[0] = ' '; 852 827 } 853 828 … … 857 832 #define MIN_WIDTH sizeof(HDR_STR) 858 833 const topmem_status_t *s = topmem + G_scroll_ofs; 834 char *cp, ch; 859 835 860 836 display_topmem_header(scr_width, &lines_rem); 837 861 838 strcpy(line_buf, HDR_STR " COMMAND"); 862 line_buf[11 + sort_field * 6] = "^_"[inverted]; 839 /* Mark the ^FIELD^ we sort by */ 840 cp = &line_buf[5 + sort_field * 6]; 841 ch = "^_"[inverted]; 842 cp[6] = ch; 843 do *cp++ = ch; while (*cp == ' '); 844 863 845 printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, line_buf); 864 846 lines_rem--; … … 919 901 static unsigned handle_input(unsigned scan_mask, unsigned interval) 920 902 { 921 struct pollfd pfd[1];922 923 903 if (option_mask32 & OPT_EOF) { 924 904 /* EOF on stdin ("top </dev/null") */ … … 926 906 return scan_mask; 927 907 } 928 929 pfd[0].fd = 0;930 pfd[0].events = POLLIN;931 908 932 909 while (1) { … … 1205 1182 while ((p = procps_scan(p, scan_mask)) != NULL) { 1206 1183 int n; 1207 #if ENABLE_FEATURE_TOPMEM 1208 if (scan_mask != TOPMEM_MASK) 1209 #endif 1210 { 1184 1185 IF_FEATURE_TOPMEM(if (scan_mask != TOPMEM_MASK)) { 1211 1186 n = ntop; 1212 1187 top = xrealloc_vector(top, 6, ntop++); … … 1248 1223 } 1249 1224 1250 if (scan_mask != TOPMEM_MASK) {1225 IF_FEATURE_TOPMEM(if (scan_mask != TOPMEM_MASK)) { 1251 1226 #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE 1252 1227 if (!prev_hist_count) { … … 1262 1237 qsort(top, ntop, sizeof(top_status_t), (void*)(sort_function[0])); 1263 1238 #endif 1239 display_process_list(G.lines, col); 1264 1240 } 1265 1241 #if ENABLE_FEATURE_TOPMEM 1266 1242 else { /* TOPMEM */ 1267 1243 qsort(topmem, ntop, sizeof(topmem_status_t), (void*)topmem_sort); 1268 }1269 #endif1270 if (scan_mask != TOPMEM_MASK)1271 display_process_list(G.lines, col);1272 #if ENABLE_FEATURE_TOPMEM1273 else1274 1244 display_topmem_process_list(G.lines, col); 1245 } 1275 1246 #endif 1276 1247 clearmems(); … … 1281 1252 #else 1282 1253 scan_mask = handle_input(scan_mask, interval); 1283 #endif /* FEATURE_USE_TERMIOS */1254 #endif 1284 1255 } /* end of "while (not Q)" */ 1285 1256 -
branches/3.3/mindi-busybox/procps/uptime.c
r3232 r3621 82 82 #if ENABLE_FEATURE_UPTIME_UTMP_SUPPORT 83 83 { 84 struct utmp *ut;84 struct utmpx *ut; 85 85 unsigned users = 0; 86 while ((ut = getut ent()) != NULL) {87 if ((ut->ut_type == USER_PROCESS) && (ut->ut_ name[0] != '\0'))86 while ((ut = getutxent()) != NULL) { 87 if ((ut->ut_type == USER_PROCESS) && (ut->ut_user[0] != '\0')) 88 88 users++; 89 89 } -
branches/3.3/mindi-busybox/procps/watch.c
r3232 r3621 70 70 if (!(opt & 0x2)) { // no -t 71 71 const unsigned time_len = sizeof("1234-67-90 23:56:89"); 72 time_t t;73 72 74 73 // STDERR_FILENO is procps3 compat: 75 74 // "watch ls 2>/dev/null" does not detect tty size 76 get_terminal_width_height(STDERR_FILENO, &new_width, NULL);75 new_width = get_terminal_width(STDERR_FILENO); 77 76 if (new_width != width) { 78 77 width = new_width; … … 80 79 header = xasprintf("Every %us: %-*s", period, (int)width, cmd); 81 80 } 82 time(&t); 83 if (time_len < width) 84 strftime(header + width - time_len, time_len, 85 "%Y-%m-%d %H:%M:%S", localtime(&t)); 81 if (time_len < width) { 82 strftime_YYYYMMDDHHMMSS( 83 header + width - time_len, 84 time_len, 85 /*time_t*:*/ NULL 86 ); 87 } 86 88 87 89 // compat: empty line between header and cmd output
Note:
See TracChangeset
for help on using the changeset viewer.