diff options
-rw-r--r-- | procps/ps.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/procps/ps.c b/procps/ps.c index efc087ee5..5f7372263 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -70,7 +70,7 @@ | |||
70 | enum { MAX_WIDTH = 2*1024 }; | 70 | enum { MAX_WIDTH = 2*1024 }; |
71 | 71 | ||
72 | #if ENABLE_FEATURE_PS_TIME || ENABLE_FEATURE_PS_LONG | 72 | #if ENABLE_FEATURE_PS_TIME || ENABLE_FEATURE_PS_LONG |
73 | static long get_uptime(void) | 73 | static unsigned long get_uptime(void) |
74 | { | 74 | { |
75 | #ifdef __linux__ | 75 | #ifdef __linux__ |
76 | struct sysinfo info; | 76 | struct sysinfo info; |
@@ -78,12 +78,15 @@ static long get_uptime(void) | |||
78 | return 0; | 78 | return 0; |
79 | return info.uptime; | 79 | return info.uptime; |
80 | #elif 1 | 80 | #elif 1 |
81 | char buf[64]; | 81 | unsigned long uptime; |
82 | long uptime; | 82 | char buf[sizeof(uptime)*3 + 2]; |
83 | /* /proc/uptime is "UPTIME_SEC.NN IDLE_SEC.NN\n" | ||
84 | * (where IDLE is cumulative over all CPUs) | ||
85 | */ | ||
83 | if (open_read_close("/proc/uptime", buf, sizeof(buf)) <= 0) | 86 | if (open_read_close("/proc/uptime", buf, sizeof(buf)) <= 0) |
84 | bb_perror_msg_and_die("can't read %s", "/proc/uptime"); | 87 | bb_perror_msg_and_die("can't read '%s'", "/proc/uptime"); |
85 | buf[sizeof(buf)-1] = '\0'; | 88 | buf[sizeof(buf)-1] = '\0'; |
86 | sscanf(buf, "%l", &uptime); | 89 | sscanf(buf, "%lu", &uptime); |
87 | return uptime; | 90 | return uptime; |
88 | #else | 91 | #else |
89 | struct timespec ts; | 92 | struct timespec ts; |
@@ -138,7 +141,10 @@ struct globals { | |||
138 | unsigned terminal_width; | 141 | unsigned terminal_width; |
139 | #if ENABLE_FEATURE_PS_TIME | 142 | #if ENABLE_FEATURE_PS_TIME |
140 | unsigned kernel_HZ; | 143 | unsigned kernel_HZ; |
141 | unsigned long long seconds_since_boot; | 144 | /* used to be long long, but 64 bits is enough |
145 | * (long long may become 128 bits in the future): | ||
146 | */ | ||
147 | uint64_t seconds_since_boot; | ||
142 | #endif | 148 | #endif |
143 | } FIX_ALIASING; | 149 | } FIX_ALIASING; |
144 | #define G (*(struct globals*)&bb_common_bufsiz1) | 150 | #define G (*(struct globals*)&bb_common_bufsiz1) |
@@ -149,14 +155,13 @@ struct globals { | |||
149 | #define buffer (G.buffer ) | 155 | #define buffer (G.buffer ) |
150 | #define terminal_width (G.terminal_width ) | 156 | #define terminal_width (G.terminal_width ) |
151 | #define kernel_HZ (G.kernel_HZ ) | 157 | #define kernel_HZ (G.kernel_HZ ) |
152 | #define seconds_since_boot (G.seconds_since_boot) | ||
153 | #define INIT_G() do { } while (0) | 158 | #define INIT_G() do { } while (0) |
154 | 159 | ||
155 | #if ENABLE_FEATURE_PS_TIME | 160 | #if ENABLE_FEATURE_PS_TIME |
156 | /* for ELF executables, notes are pushed before environment and args */ | 161 | /* for ELF executables, notes are pushed before environment and args */ |
157 | static ptrdiff_t find_elf_note(ptrdiff_t findme) | 162 | static uintptr_t find_elf_note(uintptr_t findme) |
158 | { | 163 | { |
159 | ptrdiff_t *ep = (ptrdiff_t *) environ; | 164 | uintptr_t *ep = (uintptr_t *) environ; |
160 | 165 | ||
161 | while (*ep++) | 166 | while (*ep++) |
162 | continue; | 167 | continue; |
@@ -222,7 +227,6 @@ static inline unsigned get_HZ_by_waiting(void) | |||
222 | 227 | ||
223 | static unsigned get_kernel_HZ(void) | 228 | static unsigned get_kernel_HZ(void) |
224 | { | 229 | { |
225 | |||
226 | if (kernel_HZ) | 230 | if (kernel_HZ) |
227 | return kernel_HZ; | 231 | return kernel_HZ; |
228 | 232 | ||
@@ -231,7 +235,7 @@ static unsigned get_kernel_HZ(void) | |||
231 | if (kernel_HZ == (unsigned)-1) | 235 | if (kernel_HZ == (unsigned)-1) |
232 | kernel_HZ = get_HZ_by_waiting(); | 236 | kernel_HZ = get_HZ_by_waiting(); |
233 | 237 | ||
234 | seconds_since_boot = get_uptime(); | 238 | G.seconds_since_boot = get_uptime(); |
235 | 239 | ||
236 | return kernel_HZ; | 240 | return kernel_HZ; |
237 | } | 241 | } |
@@ -350,7 +354,7 @@ static void func_etime(char *buf, int size, const procps_status_t *ps) | |||
350 | 354 | ||
351 | mm = ps->start_time / get_kernel_HZ(); | 355 | mm = ps->start_time / get_kernel_HZ(); |
352 | /* must be after get_kernel_HZ()! */ | 356 | /* must be after get_kernel_HZ()! */ |
353 | mm = seconds_since_boot - mm; | 357 | mm = G.seconds_since_boot - mm; |
354 | ss = mm % 60; | 358 | ss = mm % 60; |
355 | mm /= 60; | 359 | mm /= 60; |
356 | snprintf(buf, size+1, "%3lu:%02u", mm, ss); | 360 | snprintf(buf, size+1, "%3lu:%02u", mm, ss); |
@@ -588,7 +592,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv) | |||
588 | // -o col1,col2,col3=header | 592 | // -o col1,col2,col3=header |
589 | // Select which columns to display | 593 | // Select which columns to display |
590 | /* We allow (and ignore) most of the above. FIXME. | 594 | /* We allow (and ignore) most of the above. FIXME. |
591 | * -T is picked for threads (POSIX hasn't it standardized). | 595 | * -T is picked for threads (POSIX hasn't standardized it). |
592 | * procps v3.2.7 supports -T and shows tids as SPID column, | 596 | * procps v3.2.7 supports -T and shows tids as SPID column, |
593 | * it also supports -L where it shows tids as LWP column. | 597 | * it also supports -L where it shows tids as LWP column. |
594 | */ | 598 | */ |
@@ -599,7 +603,9 @@ int ps_main(int argc UNUSED_PARAM, char **argv) | |||
599 | parse_o(llist_pop(&opt_o)); | 603 | parse_o(llist_pop(&opt_o)); |
600 | } while (opt_o); | 604 | } while (opt_o); |
601 | } else { | 605 | } else { |
602 | /* Below: parse_o() needs char*, NOT const char*, can't give it default_o */ | 606 | /* Below: parse_o() needs char*, NOT const char*, |
607 | * can't pass it constant string. Need to make a copy first. | ||
608 | */ | ||
603 | #if ENABLE_SELINUX | 609 | #if ENABLE_SELINUX |
604 | if (!(opt & OPT_Z) || !is_selinux_enabled()) { | 610 | if (!(opt & OPT_Z) || !is_selinux_enabled()) { |
605 | /* no -Z or no SELinux: do not show LABEL */ | 611 | /* no -Z or no SELinux: do not show LABEL */ |
@@ -653,7 +659,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
653 | }; | 659 | }; |
654 | #if ENABLE_FEATURE_PS_LONG | 660 | #if ENABLE_FEATURE_PS_LONG |
655 | time_t now = now; | 661 | time_t now = now; |
656 | long uptime; | 662 | unsigned long uptime; |
657 | #endif | 663 | #endif |
658 | /* If we support any options, parse argv */ | 664 | /* If we support any options, parse argv */ |
659 | #if ENABLE_SELINUX || ENABLE_FEATURE_SHOW_THREADS || ENABLE_FEATURE_PS_WIDE || ENABLE_FEATURE_PS_LONG | 665 | #if ENABLE_SELINUX || ENABLE_FEATURE_SHOW_THREADS || ENABLE_FEATURE_PS_WIDE || ENABLE_FEATURE_PS_LONG |