49 |
unsigned long long seconds_since_boot; |
unsigned long long seconds_since_boot; |
50 |
#endif |
#endif |
51 |
char default_o[sizeof(DEFAULT_O_STR)]; |
char default_o[sizeof(DEFAULT_O_STR)]; |
52 |
}; |
} FIX_ALIASING; |
53 |
#define G (*(struct globals*)&bb_common_bufsiz1) |
#define G (*(struct globals*)&bb_common_bufsiz1) |
54 |
#define out (G.out ) |
#define out (G.out ) |
55 |
#define out_cnt (G.out_cnt ) |
#define out_cnt (G.out_cnt ) |
142 |
if (kernel_HZ == (unsigned)-1) |
if (kernel_HZ == (unsigned)-1) |
143 |
kernel_HZ = get_HZ_by_waiting(); |
kernel_HZ = get_HZ_by_waiting(); |
144 |
|
|
145 |
//if (open_read_close("/proc/uptime", buf, sizeof(buf) <= 0) |
//if (open_read_close("/proc/uptime", buf, sizeof(buf)) <= 0) |
146 |
// bb_perror_msg_and_die("can't read %s", "/proc/uptime"); |
// bb_perror_msg_and_die("can't read %s", "/proc/uptime"); |
147 |
//buf[sizeof(buf)-1] = '\0'; |
//buf[sizeof(buf)-1] = '\0'; |
148 |
///sscanf(buf, "%llu", &seconds_since_boot); |
///sscanf(buf, "%llu", &seconds_since_boot); |
232 |
snprintf(buf, size+1, "%u,%u", ps->tty_major, ps->tty_minor); |
snprintf(buf, size+1, "%u,%u", ps->tty_major, ps->tty_minor); |
233 |
} |
} |
234 |
|
|
|
|
|
235 |
#if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS |
#if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS |
236 |
|
|
237 |
static void func_rgroup(char *buf, int size, const procps_status_t *ps) |
static void func_rgroup(char *buf, int size, const procps_status_t *ps) |
249 |
sprintf(buf, "%*d", size, ps->niceness); |
sprintf(buf, "%*d", size, ps->niceness); |
250 |
} |
} |
251 |
|
|
252 |
#endif /* FEATURE_PS_ADDITIONAL_COLUMNS */ |
#endif |
253 |
|
|
254 |
#if ENABLE_FEATURE_PS_TIME |
#if ENABLE_FEATURE_PS_TIME |
255 |
|
|
256 |
static void func_etime(char *buf, int size, const procps_status_t *ps) |
static void func_etime(char *buf, int size, const procps_status_t *ps) |
257 |
{ |
{ |
258 |
/* elapsed time [[dd-]hh:]mm:ss; here only mm:ss */ |
/* elapsed time [[dd-]hh:]mm:ss; here only mm:ss */ |
278 |
mm /= 60; |
mm /= 60; |
279 |
snprintf(buf, size+1, "%3lu:%02u", mm, ss); |
snprintf(buf, size+1, "%3lu:%02u", mm, ss); |
280 |
} |
} |
281 |
|
|
282 |
#endif |
#endif |
283 |
|
|
284 |
#if ENABLE_SELINUX |
#if ENABLE_SELINUX |
338 |
static const ps_out_t* find_out_spec(const char *name) |
static const ps_out_t* find_out_spec(const char *name) |
339 |
{ |
{ |
340 |
unsigned i; |
unsigned i; |
341 |
|
#if ENABLE_DESKTOP |
342 |
|
char buf[ARRAY_SIZE(out_spec)*7 + 1]; |
343 |
|
char *p = buf; |
344 |
|
#endif |
345 |
|
|
346 |
for (i = 0; i < ARRAY_SIZE(out_spec); i++) { |
for (i = 0; i < ARRAY_SIZE(out_spec); i++) { |
347 |
if (!strncmp(name, out_spec[i].name6, 6)) |
if (strncmp(name, out_spec[i].name6, 6) == 0) |
348 |
return &out_spec[i]; |
return &out_spec[i]; |
349 |
|
#if ENABLE_DESKTOP |
350 |
|
p += sprintf(p, "%.6s,", out_spec[i].name6); |
351 |
|
#endif |
352 |
} |
} |
353 |
bb_error_msg_and_die("bad -o argument '%s'", name); |
#if ENABLE_DESKTOP |
354 |
|
p[-1] = '\0'; |
355 |
|
bb_error_msg_and_die("bad -o argument '%s', supported arguments: %s", name, buf); |
356 |
|
#else |
357 |
|
bb_error_msg_and_die("bad -o argument '%s'"); |
358 |
|
#endif |
359 |
} |
} |
360 |
|
|
361 |
static void parse_o(char* opt) |
static void parse_o(char* opt) |
553 |
int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
554 |
{ |
{ |
555 |
procps_status_t *p; |
procps_status_t *p; |
|
int len; |
|
556 |
int psscan_flags = PSSCAN_PID | PSSCAN_UIDGID |
int psscan_flags = PSSCAN_PID | PSSCAN_UIDGID |
557 |
| PSSCAN_STATE | PSSCAN_VSZ | PSSCAN_COMM; |
| PSSCAN_STATE | PSSCAN_VSZ | PSSCAN_COMM; |
558 |
#if !ENABLE_FEATURE_PS_WIDE |
unsigned terminal_width IF_NOT_FEATURE_PS_WIDE(= 79); |
559 |
enum { terminal_width = 79 }; |
enum { |
560 |
#else |
OPT_Z = (1 << 0) * ENABLE_SELINUX, |
561 |
unsigned terminal_width; |
OPT_T = (1 << ENABLE_SELINUX) * ENABLE_FEATURE_SHOW_THREADS, |
562 |
#endif |
}; |
563 |
|
int opts = 0; |
564 |
#if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX |
/* If we support any options, parse argv */ |
565 |
int opts; |
#if ENABLE_SELINUX || ENABLE_FEATURE_SHOW_THREADS || ENABLE_FEATURE_PS_WIDE |
566 |
# if ENABLE_FEATURE_PS_WIDE |
# if ENABLE_FEATURE_PS_WIDE |
567 |
|
/* -w is a bit complicated */ |
568 |
int w_count = 0; |
int w_count = 0; |
569 |
opt_complementary = "-:ww"; |
opt_complementary = "-:ww"; |
570 |
opts = getopt32(argv, IF_SELINUX("Z")IF_FEATURE_SHOW_THREADS("T")"w", &w_count); |
opts = getopt32(argv, IF_SELINUX("Z")IF_FEATURE_SHOW_THREADS("T")"w", &w_count); |
579 |
if (--terminal_width > MAX_WIDTH) |
if (--terminal_width > MAX_WIDTH) |
580 |
terminal_width = MAX_WIDTH; |
terminal_width = MAX_WIDTH; |
581 |
} |
} |
582 |
# else /* only ENABLE_SELINUX */ |
# else |
583 |
opts = getopt32(argv, "Z"IF_FEATURE_SHOW_THREADS("T")); |
/* -w is not supported, only -Z and/or -T */ |
584 |
|
opt_complementary = "-"; |
585 |
|
opts = getopt32(argv, IF_SELINUX("Z")IF_FEATURE_SHOW_THREADS("T")); |
586 |
# endif |
# endif |
587 |
# if ENABLE_SELINUX |
#endif |
588 |
if ((opts & 1) && is_selinux_enabled()) |
|
589 |
|
#if ENABLE_SELINUX |
590 |
|
if ((opts & OPT_Z) && is_selinux_enabled()) { |
591 |
psscan_flags = PSSCAN_PID | PSSCAN_CONTEXT |
psscan_flags = PSSCAN_PID | PSSCAN_CONTEXT |
592 |
| PSSCAN_STATE | PSSCAN_COMM; |
| PSSCAN_STATE | PSSCAN_COMM; |
|
# endif |
|
|
# if ENABLE_FEATURE_SHOW_THREADS |
|
|
if (opts & (1 << ENABLE_SELINUX)) |
|
|
psscan_flags |= PSSCAN_TASKS; |
|
|
# endif |
|
|
#endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */ |
|
|
|
|
|
if (psscan_flags & PSSCAN_CONTEXT) |
|
593 |
puts(" PID CONTEXT STAT COMMAND"); |
puts(" PID CONTEXT STAT COMMAND"); |
594 |
else |
} else |
595 |
|
#endif |
596 |
|
{ |
597 |
puts(" PID USER VSZ STAT COMMAND"); |
puts(" PID USER VSZ STAT COMMAND"); |
598 |
|
} |
599 |
|
if (opts & OPT_T) { |
600 |
|
psscan_flags |= PSSCAN_TASKS; |
601 |
|
} |
602 |
|
|
603 |
p = NULL; |
p = NULL; |
604 |
while ((p = procps_scan(p, psscan_flags)) != NULL) { |
while ((p = procps_scan(p, psscan_flags)) != NULL) { |
605 |
|
int len; |
606 |
#if ENABLE_SELINUX |
#if ENABLE_SELINUX |
607 |
if (psscan_flags & PSSCAN_CONTEXT) { |
if (psscan_flags & PSSCAN_CONTEXT) { |
608 |
len = printf("%5u %-32.32s %s ", |
len = printf("%5u %-32.32s %s ", |
638 |
return EXIT_SUCCESS; |
return EXIT_SUCCESS; |
639 |
} |
} |
640 |
|
|
641 |
#endif /* ENABLE_DESKTOP */ |
#endif /* !ENABLE_DESKTOP */ |