Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/procps/ps.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.