aboutsummaryrefslogtreecommitdiff
path: root/procps/ps.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2013-02-07 14:25:54 +0000
committerRon Yorston <rmy@pobox.com>2013-02-07 14:25:54 +0000
commitb604585914e032b28bef3e337a978e56a9069cda (patch)
treeb2ee0a3fb38d10397c602d0fe215ea3bbbf334c0 /procps/ps.c
parent0eda07c7ff8cf1fc11bc1bda5383f884d7adf031 (diff)
parentba76b7a40b929878833731f76306b1c977cc8650 (diff)
downloadbusybox-w32-b604585914e032b28bef3e337a978e56a9069cda.tar.gz
busybox-w32-b604585914e032b28bef3e337a978e56a9069cda.tar.bz2
busybox-w32-b604585914e032b28bef3e337a978e56a9069cda.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'procps/ps.c')
-rw-r--r--procps/ps.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/procps/ps.c b/procps/ps.c
index e14356482..0dfda2039 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -70,7 +70,7 @@
70enum { MAX_WIDTH = 2*1024 }; 70enum { 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
73static long get_uptime(void) 73static 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,7 @@ 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 unsigned long seconds_since_boot;
142#endif 145#endif
143} FIX_ALIASING; 146} FIX_ALIASING;
144#define G (*(struct globals*)&bb_common_bufsiz1) 147#define G (*(struct globals*)&bb_common_bufsiz1)
@@ -149,14 +152,13 @@ struct globals {
149#define buffer (G.buffer ) 152#define buffer (G.buffer )
150#define terminal_width (G.terminal_width ) 153#define terminal_width (G.terminal_width )
151#define kernel_HZ (G.kernel_HZ ) 154#define kernel_HZ (G.kernel_HZ )
152#define seconds_since_boot (G.seconds_since_boot)
153#define INIT_G() do { } while (0) 155#define INIT_G() do { } while (0)
154 156
155#if ENABLE_FEATURE_PS_TIME 157#if ENABLE_FEATURE_PS_TIME
156/* for ELF executables, notes are pushed before environment and args */ 158/* for ELF executables, notes are pushed before environment and args */
157static ptrdiff_t find_elf_note(ptrdiff_t findme) 159static uintptr_t find_elf_note(uintptr_t findme)
158{ 160{
159 ptrdiff_t *ep = (ptrdiff_t *) environ; 161 uintptr_t *ep = (uintptr_t *) environ;
160 162
161 while (*ep++) 163 while (*ep++)
162 continue; 164 continue;
@@ -222,7 +224,6 @@ static inline unsigned get_HZ_by_waiting(void)
222 224
223static unsigned get_kernel_HZ(void) 225static unsigned get_kernel_HZ(void)
224{ 226{
225
226 if (kernel_HZ) 227 if (kernel_HZ)
227 return kernel_HZ; 228 return kernel_HZ;
228 229
@@ -231,7 +232,7 @@ static unsigned get_kernel_HZ(void)
231 if (kernel_HZ == (unsigned)-1) 232 if (kernel_HZ == (unsigned)-1)
232 kernel_HZ = get_HZ_by_waiting(); 233 kernel_HZ = get_HZ_by_waiting();
233 234
234 seconds_since_boot = get_uptime(); 235 G.seconds_since_boot = get_uptime();
235 236
236 return kernel_HZ; 237 return kernel_HZ;
237} 238}
@@ -350,7 +351,7 @@ static void func_etime(char *buf, int size, const procps_status_t *ps)
350 351
351 mm = ps->start_time / get_kernel_HZ(); 352 mm = ps->start_time / get_kernel_HZ();
352 /* must be after get_kernel_HZ()! */ 353 /* must be after get_kernel_HZ()! */
353 mm = seconds_since_boot - mm; 354 mm = G.seconds_since_boot - mm;
354 ss = mm % 60; 355 ss = mm % 60;
355 mm /= 60; 356 mm /= 60;
356 snprintf(buf, size+1, "%3lu:%02u", mm, ss); 357 snprintf(buf, size+1, "%3lu:%02u", mm, ss);
@@ -598,7 +599,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv)
598 // -o col1,col2,col3=header 599 // -o col1,col2,col3=header
599 // Select which columns to display 600 // Select which columns to display
600 /* We allow (and ignore) most of the above. FIXME. 601 /* We allow (and ignore) most of the above. FIXME.
601 * -T is picked for threads (POSIX hasn't it standardized). 602 * -T is picked for threads (POSIX hasn't standardized it).
602 * procps v3.2.7 supports -T and shows tids as SPID column, 603 * procps v3.2.7 supports -T and shows tids as SPID column,
603 * it also supports -L where it shows tids as LWP column. 604 * it also supports -L where it shows tids as LWP column.
604 */ 605 */
@@ -609,7 +610,9 @@ int ps_main(int argc UNUSED_PARAM, char **argv)
609 parse_o(llist_pop(&opt_o)); 610 parse_o(llist_pop(&opt_o));
610 } while (opt_o); 611 } while (opt_o);
611 } else { 612 } else {
612 /* Below: parse_o() needs char*, NOT const char*, can't give it default_o */ 613 /* Below: parse_o() needs char*, NOT const char*,
614 * can't pass it constant string. Need to make a copy first.
615 */
613#if ENABLE_SELINUX 616#if ENABLE_SELINUX
614 if (!(opt & OPT_Z) || !is_selinux_enabled()) { 617 if (!(opt & OPT_Z) || !is_selinux_enabled()) {
615 /* no -Z or no SELinux: do not show LABEL */ 618 /* no -Z or no SELinux: do not show LABEL */
@@ -663,7 +666,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
663 }; 666 };
664#if ENABLE_FEATURE_PS_LONG 667#if ENABLE_FEATURE_PS_LONG
665 time_t now = now; 668 time_t now = now;
666 long uptime; 669 unsigned long uptime;
667#endif 670#endif
668 /* If we support any options, parse argv */ 671 /* If we support any options, parse argv */
669#if ENABLE_SELINUX || ENABLE_FEATURE_SHOW_THREADS || ENABLE_FEATURE_PS_WIDE || ENABLE_FEATURE_PS_LONG 672#if ENABLE_SELINUX || ENABLE_FEATURE_SHOW_THREADS || ENABLE_FEATURE_PS_WIDE || ENABLE_FEATURE_PS_LONG