aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
Diffstat (limited to 'procps')
-rw-r--r--procps/Config.src2
-rw-r--r--procps/Kbuild.src4
-rw-r--r--procps/kill.c49
-rw-r--r--procps/nmeter.c2
-rw-r--r--procps/pgrep.c1
-rw-r--r--procps/pidof.c8
-rw-r--r--procps/powertop.c28
-rw-r--r--procps/ps.c24
-rw-r--r--procps/pstree.c4
-rw-r--r--procps/top.c42
-rw-r--r--procps/uptime.c4
11 files changed, 92 insertions, 76 deletions
diff --git a/procps/Config.src b/procps/Config.src
index eb4760752..35fef2eda 100644
--- a/procps/Config.src
+++ b/procps/Config.src
@@ -8,7 +8,7 @@ menu "Process Utilities"
8INSERT 8INSERT
9 9
10config FEATURE_SHOW_THREADS 10config FEATURE_SHOW_THREADS
11 bool "Support for showing threads in ps/pstree/top" 11 bool "Support thread display in ps/pstree/top"
12 default y 12 default y
13 depends on PS || TOP || PSTREE 13 depends on PS || TOP || PSTREE
14 help 14 help
diff --git a/procps/Kbuild.src b/procps/Kbuild.src
index e7adc7340..6b4fb7470 100644
--- a/procps/Kbuild.src
+++ b/procps/Kbuild.src
@@ -7,7 +7,3 @@
7lib-y:= 7lib-y:=
8 8
9INSERT 9INSERT
10
11lib-$(CONFIG_ASH) += kill.o # used for built-in kill by ash
12lib-$(CONFIG_SH_IS_ASH) += kill.o # used for built-in kill by ash
13lib-$(CONFIG_BASH_IS_ASH) += kill.o # used for built-in kill by ash
diff --git a/procps/kill.c b/procps/kill.c
index 57a33bcaa..7ae5beead 100644
--- a/procps/kill.c
+++ b/procps/kill.c
@@ -33,7 +33,8 @@
33//config: the script it was called from. 33//config: the script it was called from.
34 34
35//applet:IF_KILL(APPLET(kill, BB_DIR_BIN, BB_SUID_DROP)) 35//applet:IF_KILL(APPLET(kill, BB_DIR_BIN, BB_SUID_DROP))
36//applet:IF_KILLALL(APPLET_ODDNAME(killall, kill, BB_DIR_USR_BIN, BB_SUID_DROP, killall)) 36// APPLET_ODDNAME:name main location suid_type help
37//applet:IF_KILLALL( APPLET_ODDNAME(killall, kill, BB_DIR_USR_BIN, BB_SUID_DROP, killall))
37//applet:IF_KILLALL5(APPLET_ODDNAME(killall5, kill, BB_DIR_USR_SBIN, BB_SUID_DROP, killall5)) 38//applet:IF_KILLALL5(APPLET_ODDNAME(killall5, kill, BB_DIR_USR_SBIN, BB_SUID_DROP, killall5))
38 39
39//kbuild:lib-$(CONFIG_KILL) += kill.o 40//kbuild:lib-$(CONFIG_KILL) += kill.o
@@ -92,28 +93,34 @@
92 * This is needed to avoid collision with kill -9 ... syntax 93 * This is needed to avoid collision with kill -9 ... syntax
93 */ 94 */
94 95
96//kbuild:lib-$(CONFIG_ASH_JOB_CONTROL) += kill.o
97//kbuild:lib-$(CONFIG_HUSH_KILL) += kill.o
98
99#define SH_KILL (ENABLE_ASH_JOB_CONTROL || ENABLE_HUSH_KILL)
100/* If shells want to have "kill", for ifdefs it's like ENABLE_KILL=1 */
101#if SH_KILL
102# undef ENABLE_KILL
103# define ENABLE_KILL 1
104#endif
105#define KILL_APPLET_CNT (ENABLE_KILL + ENABLE_KILLALL + ENABLE_KILLALL5)
106
95int kill_main(int argc UNUSED_PARAM, char **argv) 107int kill_main(int argc UNUSED_PARAM, char **argv)
96{ 108{
97 char *arg; 109 char *arg;
98 pid_t pid; 110 pid_t pid;
99 int signo = SIGTERM, errors = 0, quiet = 0; 111 int signo = SIGTERM, errors = 0, quiet = 0;
100#if ENABLE_KILL && !ENABLE_KILLALL && !ENABLE_KILLALL5 112
101# define killall 0 113#if KILL_APPLET_CNT == 1
102# define killall5 0 114# define is_killall ENABLE_KILLALL
103#elif !ENABLE_KILL && ENABLE_KILLALL && !ENABLE_KILLALL5 115# define is_killall5 ENABLE_KILLALL5
104# define killall 1
105# define killall5 0
106#elif !ENABLE_KILL && !ENABLE_KILLALL && ENABLE_KILLALL5
107# define killall 0
108# define killall5 1
109#else 116#else
110/* How to determine who we are? find 3rd char from the end: 117/* How to determine who we are? find 3rd char from the end:
111 * kill, killall, killall5 118 * kill, killall, killall5
112 * ^i ^a ^l - it's unique 119 * ^i ^a ^l - it's unique
113 * (checking from the start is complicated by /bin/kill... case) */ 120 * (checking from the start is complicated by /bin/kill... case) */
114 const char char3 = argv[0][strlen(argv[0]) - 3]; 121 const char char3 = argv[0][strlen(argv[0]) - 3];
115# define killall (ENABLE_KILLALL && char3 == 'a') 122# define is_killall (ENABLE_KILLALL && char3 == 'a')
116# define killall5 (ENABLE_KILLALL5 && char3 == 'l') 123# define is_killall5 (ENABLE_KILLALL5 && char3 == 'l')
117#endif 124#endif
118 125
119 /* Parse any options */ 126 /* Parse any options */
@@ -162,7 +169,7 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
162 } 169 }
163 170
164 /* The -q quiet option */ 171 /* The -q quiet option */
165 if (killall && arg[1] == 'q' && arg[2] == '\0') { 172 if (is_killall && arg[1] == 'q' && arg[2] == '\0') {
166 quiet = 1; 173 quiet = 1;
167 arg = *++argv; 174 arg = *++argv;
168 if (!arg) 175 if (!arg)
@@ -174,7 +181,7 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
174 arg++; /* skip '-' */ 181 arg++; /* skip '-' */
175 182
176 /* -o PID? (if present, it always is at the end of command line) */ 183 /* -o PID? (if present, it always is at the end of command line) */
177 if (killall5 && arg[0] == 'o') 184 if (is_killall5 && arg[0] == 'o')
178 goto do_it_now; 185 goto do_it_now;
179 186
180 if (argv[1] && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */ 187 if (argv[1] && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */
@@ -190,7 +197,7 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
190 do_it_now: 197 do_it_now:
191 pid = getpid(); 198 pid = getpid();
192 199
193 if (killall5) { 200 if (is_killall5) {
194 pid_t sid; 201 pid_t sid;
195 procps_status_t* p = NULL; 202 procps_status_t* p = NULL;
196 /* compat: exitcode 2 is "no one was signaled" */ 203 /* compat: exitcode 2 is "no one was signaled" */
@@ -248,13 +255,14 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
248 return ret; 255 return ret;
249 } 256 }
250 257
258#if ENABLE_KILL || ENABLE_KILLALL
251 /* Pid or name is required for kill/killall */ 259 /* Pid or name is required for kill/killall */
252 if (!arg) { 260 if (!arg) {
253 bb_error_msg("you need to specify whom to kill"); 261 bb_error_msg("you need to specify whom to kill");
254 return EXIT_FAILURE; 262 return EXIT_FAILURE;
255 } 263 }
256 264
257 if (killall) { 265 if (!ENABLE_KILL || is_killall) {
258 /* Looks like they want to do a killall. Do that */ 266 /* Looks like they want to do a killall. Do that */
259 do { 267 do {
260 pid_t* pidList; 268 pid_t* pidList;
@@ -282,10 +290,12 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
282 } while (arg); 290 } while (arg);
283 return errors; 291 return errors;
284 } 292 }
293#endif
285 294
295#if ENABLE_KILL
286 /* Looks like they want to do a kill. Do that */ 296 /* Looks like they want to do a kill. Do that */
287 while (arg) { 297 while (arg) {
288#if ENABLE_ASH || ENABLE_HUSH 298# if SH_KILL
289 /* 299 /*
290 * We need to support shell's "hack formats" of 300 * We need to support shell's "hack formats" of
291 * " -PRGP_ID" (yes, with a leading space) 301 * " -PRGP_ID" (yes, with a leading space)
@@ -307,7 +317,7 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
307 } 317 }
308 arg = end; /* can only point to ' ' or '\0' now */ 318 arg = end; /* can only point to ' ' or '\0' now */
309 } 319 }
310#else 320# else /* ENABLE_KILL but !SH_KILL */
311 pid = bb_strtoi(arg, NULL, 10); 321 pid = bb_strtoi(arg, NULL, 10);
312 if (errno) { 322 if (errno) {
313 bb_error_msg("invalid number '%s'", arg); 323 bb_error_msg("invalid number '%s'", arg);
@@ -316,8 +326,9 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
316 bb_perror_msg("can't kill pid %d", (int)pid); 326 bb_perror_msg("can't kill pid %d", (int)pid);
317 errors++; 327 errors++;
318 } 328 }
319#endif 329# endif
320 arg = *++argv; 330 arg = *++argv;
321 } 331 }
322 return errors; 332 return errors;
333#endif
323} 334}
diff --git a/procps/nmeter.c b/procps/nmeter.c
index 3eac2d3b2..05bf0a08c 100644
--- a/procps/nmeter.c
+++ b/procps/nmeter.c
@@ -24,7 +24,7 @@
24//usage: "\n -d MSEC Milliseconds between updates, default:1000, none:-1" 24//usage: "\n -d MSEC Milliseconds between updates, default:1000, none:-1"
25//usage: "\n" 25//usage: "\n"
26//usage: "\nFormat specifiers:" 26//usage: "\nFormat specifiers:"
27//usage: "\n %Nc or %[cN] CPU. N - bar size (default:10)" 27//usage: "\n %Nc or %[cN] CPU. N - bar size (default 10)"
28//usage: "\n (displays: S:system U:user N:niced D:iowait I:irq i:softirq)" 28//usage: "\n (displays: S:system U:user N:niced D:iowait I:irq i:softirq)"
29//usage: "\n %[nINTERFACE] Network INTERFACE" 29//usage: "\n %[nINTERFACE] Network INTERFACE"
30//usage: "\n %m Allocated memory" 30//usage: "\n %m Allocated memory"
diff --git a/procps/pgrep.c b/procps/pgrep.c
index ac82b5156..e932a32bc 100644
--- a/procps/pgrep.c
+++ b/procps/pgrep.c
@@ -19,6 +19,7 @@
19//config: Send signals to processes by name. 19//config: Send signals to processes by name.
20 20
21//applet:IF_PGREP(APPLET(pgrep, BB_DIR_USR_BIN, BB_SUID_DROP)) 21//applet:IF_PGREP(APPLET(pgrep, BB_DIR_USR_BIN, BB_SUID_DROP))
22// APPLET_ODDNAME:name main location suid_type help
22//applet:IF_PKILL(APPLET_ODDNAME(pkill, pgrep, BB_DIR_USR_BIN, BB_SUID_DROP, pkill)) 23//applet:IF_PKILL(APPLET_ODDNAME(pkill, pgrep, BB_DIR_USR_BIN, BB_SUID_DROP, pkill))
23 24
24//kbuild:lib-$(CONFIG_PGREP) += pgrep.o 25//kbuild:lib-$(CONFIG_PGREP) += pgrep.o
diff --git a/procps/pidof.c b/procps/pidof.c
index 069adb7a4..b64f0cbd6 100644
--- a/procps/pidof.c
+++ b/procps/pidof.c
@@ -14,18 +14,18 @@
14//config: those id's on the standard output. 14//config: those id's on the standard output.
15//config: 15//config:
16//config:config FEATURE_PIDOF_SINGLE 16//config:config FEATURE_PIDOF_SINGLE
17//config: bool "Enable argument for single shot (-s)" 17//config: bool "Enable single shot (-s)"
18//config: default y 18//config: default y
19//config: depends on PIDOF 19//config: depends on PIDOF
20//config: help 20//config: help
21//config: Support argument '-s' for returning only the first pid found. 21//config: Support '-s' for returning only the first pid found.
22//config: 22//config:
23//config:config FEATURE_PIDOF_OMIT 23//config:config FEATURE_PIDOF_OMIT
24//config: bool "Enable argument for omitting pids (-o)" 24//config: bool "Enable omitting pids (-o PID)"
25//config: default y 25//config: default y
26//config: depends on PIDOF 26//config: depends on PIDOF
27//config: help 27//config: help
28//config: Support argument '-o' for omitting the given pids in output. 28//config: Support '-o PID' for omitting the given pid(s) in output.
29//config: The special pid %PPID can be used to name the parent process 29//config: The special pid %PPID can be used to name the parent process
30//config: of the pidof, in other words the calling shell or shell script. 30//config: of the pidof, in other words the calling shell or shell script.
31 31
diff --git a/procps/powertop.c b/procps/powertop.c
index ce85f4191..413806836 100644
--- a/procps/powertop.c
+++ b/procps/powertop.c
@@ -18,6 +18,14 @@
18//config: default y 18//config: default y
19//config: help 19//config: help
20//config: Analyze power consumption on Intel-based laptops 20//config: Analyze power consumption on Intel-based laptops
21//config:
22//config:config FEATURE_POWERTOP_INTERACTIVE
23//config: bool "Accept keyboard commands"
24//config: default y
25//config: depends on POWERTOP
26//config: help
27//config: Without this, powertop will only refresh display every 10 seconds.
28//config: No keyboard commands will work, only ^C to terminate.
21 29
22// XXX This should be configurable 30// XXX This should be configurable
23#define ENABLE_FEATURE_POWERTOP_PROCIRQ 1 31#define ENABLE_FEATURE_POWERTOP_PROCIRQ 1
@@ -82,7 +90,7 @@ struct globals {
82 ullong last_usage[MAX_CSTATE_COUNT]; 90 ullong last_usage[MAX_CSTATE_COUNT];
83 ullong start_duration[MAX_CSTATE_COUNT]; 91 ullong start_duration[MAX_CSTATE_COUNT];
84 ullong last_duration[MAX_CSTATE_COUNT]; 92 ullong last_duration[MAX_CSTATE_COUNT];
85#if ENABLE_FEATURE_USE_TERMIOS 93#if ENABLE_FEATURE_POWERTOP_INTERACTIVE
86 struct termios init_settings; 94 struct termios init_settings;
87#endif 95#endif
88}; 96};
@@ -91,7 +99,7 @@ struct globals {
91 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 99 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
92} while (0) 100} while (0)
93 101
94#if ENABLE_FEATURE_USE_TERMIOS 102#if ENABLE_FEATURE_POWERTOP_INTERACTIVE
95static void reset_term(void) 103static void reset_term(void)
96{ 104{
97 tcsetattr_stdin_TCSANOW(&G.init_settings); 105 tcsetattr_stdin_TCSANOW(&G.init_settings);
@@ -682,8 +690,7 @@ int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
682 ullong cur_usage[MAX_CSTATE_COUNT]; 690 ullong cur_usage[MAX_CSTATE_COUNT];
683 ullong cur_duration[MAX_CSTATE_COUNT]; 691 ullong cur_duration[MAX_CSTATE_COUNT];
684 char cstate_lines[MAX_CSTATE_COUNT + 2][64]; 692 char cstate_lines[MAX_CSTATE_COUNT + 2][64];
685#if ENABLE_FEATURE_USE_TERMIOS 693#if ENABLE_FEATURE_POWERTOP_INTERACTIVE
686 struct termios new_settings;
687 struct pollfd pfd[1]; 694 struct pollfd pfd[1];
688 695
689 pfd[0].fd = 0; 696 pfd[0].fd = 0;
@@ -706,15 +713,12 @@ int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
706 713
707 puts("Collecting data for "DEFAULT_SLEEP_STR" seconds"); 714 puts("Collecting data for "DEFAULT_SLEEP_STR" seconds");
708 715
709#if ENABLE_FEATURE_USE_TERMIOS 716#if ENABLE_FEATURE_POWERTOP_INTERACTIVE
710 tcgetattr(0, (void *)&G.init_settings); 717 /* Turn on unbuffered input; turn off echoing, ^C ^Z etc */
711 memcpy(&new_settings, &G.init_settings, sizeof(new_settings)); 718 set_termios_to_raw(STDIN_FILENO, &G.init_settings, TERMIOS_CLEAR_ISIG);
712 /* Turn on unbuffered input, turn off echoing */ 719 bb_signals(BB_FATAL_SIGS, sig_handler);
713 new_settings.c_lflag &= ~(ISIG | ICANON | ECHO | ECHONL);
714 /* So we don't forget to reset term settings */ 720 /* So we don't forget to reset term settings */
715 atexit(reset_term); 721 atexit(reset_term);
716 bb_signals(BB_FATAL_SIGS, sig_handler);
717 tcsetattr_stdin_TCSANOW(&new_settings);
718#endif 722#endif
719 723
720 /* Collect initial data */ 724 /* Collect initial data */
@@ -739,7 +743,7 @@ int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
739 int i; 743 int i;
740 744
741 G.cant_enable_timer_stats |= start_timer(); /* 1 on error */ 745 G.cant_enable_timer_stats |= start_timer(); /* 1 on error */
742#if !ENABLE_FEATURE_USE_TERMIOS 746#if !ENABLE_FEATURE_POWERTOP_INTERACTIVE
743 sleep(DEFAULT_SLEEP); 747 sleep(DEFAULT_SLEEP);
744#else 748#else
745 if (safe_poll(pfd, 1, DEFAULT_SLEEP * 1000) > 0) { 749 if (safe_poll(pfd, 1, DEFAULT_SLEEP * 1000) > 0) {
diff --git a/procps/ps.c b/procps/ps.c
index 902811f31..f7242f2d5 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -32,19 +32,10 @@
32//config: Adds fields PPID, RSS, START, TIME & TTY 32//config: Adds fields PPID, RSS, START, TIME & TTY
33//config: 33//config:
34//config:config FEATURE_PS_TIME 34//config:config FEATURE_PS_TIME
35//config: bool "Enable time and elapsed time output" 35//config: bool "Support -o time and -o etime output specifiers"
36//config: default y 36//config: default y
37//config: depends on PS && DESKTOP 37//config: depends on PS && DESKTOP
38//config: select PLATFORM_LINUX 38//config: select PLATFORM_LINUX
39//config: help
40//config: Support -o time and -o etime output specifiers.
41//config:
42//config:config FEATURE_PS_ADDITIONAL_COLUMNS
43//config: bool "Enable additional ps columns"
44//config: default y
45//config: depends on PS && DESKTOP
46//config: help
47//config: Support -o rgroup, -o ruser, -o nice output specifiers.
48//config: 39//config:
49//config:config FEATURE_PS_UNUSUAL_SYSTEMS 40//config:config FEATURE_PS_UNUSUAL_SYSTEMS
50//config: bool "Support Linux prior to 2.4.0 and non-ELF systems" 41//config: bool "Support Linux prior to 2.4.0 and non-ELF systems"
@@ -53,6 +44,11 @@
53//config: help 44//config: help
54//config: Include support for measuring HZ on old kernels and non-ELF systems 45//config: Include support for measuring HZ on old kernels and non-ELF systems
55//config: (if you are on Linux 2.4.0+ and use ELF, you don't need this) 46//config: (if you are on Linux 2.4.0+ and use ELF, you don't need this)
47//config:
48//config:config FEATURE_PS_ADDITIONAL_COLUMNS
49//config: bool "Support -o rgroup, -o ruser, -o nice specifiers"
50//config: default y
51//config: depends on PS && DESKTOP
56 52
57//applet:IF_PS(APPLET(ps, BB_DIR_BIN, BB_SUID_DROP)) 53//applet:IF_PS(APPLET(ps, BB_DIR_BIN, BB_SUID_DROP))
58 54
@@ -628,7 +624,9 @@ int ps_main(int argc UNUSED_PARAM, char **argv)
628 procps_status_t *p; 624 procps_status_t *p;
629 llist_t* opt_o = NULL; 625 llist_t* opt_o = NULL;
630 char default_o[sizeof(DEFAULT_O_STR)]; 626 char default_o[sizeof(DEFAULT_O_STR)];
627#if ENABLE_SELINUX || ENABLE_FEATURE_SHOW_THREADS
631 int opt; 628 int opt;
629#endif
632 enum { 630 enum {
633 OPT_Z = (1 << 0), 631 OPT_Z = (1 << 0),
634 OPT_o = (1 << 1), 632 OPT_o = (1 << 1),
@@ -658,7 +656,11 @@ int ps_main(int argc UNUSED_PARAM, char **argv)
658 * procps v3.2.7 supports -T and shows tids as SPID column, 656 * procps v3.2.7 supports -T and shows tids as SPID column,
659 * it also supports -L where it shows tids as LWP column. 657 * it also supports -L where it shows tids as LWP column.
660 */ 658 */
661 opt = getopt32(argv, "Zo:*aAdefl"IF_FEATURE_SHOW_THREADS("T"), &opt_o); 659#if ENABLE_SELINUX || ENABLE_FEATURE_SHOW_THREADS
660 opt =
661#endif
662 getopt32(argv, "Zo:*aAdefl"IF_FEATURE_SHOW_THREADS("T"), &opt_o);
663
662 if (opt_o) { 664 if (opt_o) {
663 do { 665 do {
664 parse_o(llist_pop(&opt_o)); 666 parse_o(llist_pop(&opt_o));
diff --git a/procps/pstree.c b/procps/pstree.c
index c5fb83688..f97e99639 100644
--- a/procps/pstree.c
+++ b/procps/pstree.c
@@ -357,7 +357,9 @@ static void handle_thread(const char *comm, pid_t pid, pid_t ppid, uid_t uid)
357static void mread_proc(void) 357static void mread_proc(void)
358{ 358{
359 procps_status_t *p = NULL; 359 procps_status_t *p = NULL;
360#if ENABLE_FEATURE_SHOW_THREADS
360 pid_t parent = 0; 361 pid_t parent = 0;
362#endif
361 int flags = PSSCAN_COMM | PSSCAN_PID | PSSCAN_PPID | PSSCAN_UIDGID | PSSCAN_TASKS; 363 int flags = PSSCAN_COMM | PSSCAN_PID | PSSCAN_PPID | PSSCAN_UIDGID | PSSCAN_TASKS;
362 364
363 while ((p = procps_scan(p, flags)) != NULL) { 365 while ((p = procps_scan(p, flags)) != NULL) {
@@ -368,7 +370,9 @@ static void mread_proc(void)
368#endif 370#endif
369 { 371 {
370 add_proc(p->comm, p->pid, p->ppid, p->uid/*, 0*/); 372 add_proc(p->comm, p->pid, p->ppid, p->uid/*, 0*/);
373#if ENABLE_FEATURE_SHOW_THREADS
371 parent = p->pid; 374 parent = p->pid;
375#endif
372 } 376 }
373 } 377 }
374} 378}
diff --git a/procps/top.c b/procps/top.c
index 71207bac1..ff2fddeea 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -56,6 +56,14 @@
56//config: The top program provides a dynamic real-time view of a running 56//config: The top program provides a dynamic real-time view of a running
57//config: system. 57//config: system.
58//config: 58//config:
59//config:config FEATURE_TOP_INTERACTIVE
60//config: bool "Accept keyboard commands"
61//config: default y
62//config: depends on TOP
63//config: help
64//config: Without this, top will only refresh display every 5 seconds.
65//config: No keyboard commands will work, only ^C to terminate.
66//config:
59//config:config FEATURE_TOP_CPU_USAGE_PERCENTAGE 67//config:config FEATURE_TOP_CPU_USAGE_PERCENTAGE
60//config: bool "Show CPU per-process usage percentage" 68//config: bool "Show CPU per-process usage percentage"
61//config: default y 69//config: default y
@@ -158,7 +166,7 @@ struct globals {
158 smallint smp_cpu_info; /* one/many cpu info lines? */ 166 smallint smp_cpu_info; /* one/many cpu info lines? */
159#endif 167#endif
160 unsigned lines; /* screen height */ 168 unsigned lines; /* screen height */
161#if ENABLE_FEATURE_USE_TERMIOS 169#if ENABLE_FEATURE_TOP_INTERACTIVE
162 struct termios initial_settings; 170 struct termios initial_settings;
163 int scroll_ofs; 171 int scroll_ofs;
164#define G_scroll_ofs G.scroll_ofs 172#define G_scroll_ofs G.scroll_ofs
@@ -181,7 +189,7 @@ struct globals {
181 jiffy_counts_t *cpu_jif, *cpu_prev_jif; 189 jiffy_counts_t *cpu_jif, *cpu_prev_jif;
182 int num_cpus; 190 int num_cpus;
183#endif 191#endif
184#if ENABLE_FEATURE_USE_TERMIOS 192#if ENABLE_FEATURE_TOP_INTERACTIVE
185 char kbd_input[KEYCODE_BUFFER_SIZE]; 193 char kbd_input[KEYCODE_BUFFER_SIZE];
186#endif 194#endif
187 char line_buf[80]; 195 char line_buf[80];
@@ -220,7 +228,7 @@ enum {
220#define OPT_BATCH_MODE (option_mask32 & OPT_b) 228#define OPT_BATCH_MODE (option_mask32 & OPT_b)
221 229
222 230
223#if ENABLE_FEATURE_USE_TERMIOS 231#if ENABLE_FEATURE_TOP_INTERACTIVE
224static int pid_sort(top_status_t *P, top_status_t *Q) 232static int pid_sort(top_status_t *P, top_status_t *Q)
225{ 233{
226 /* Buggy wrt pids with high bit set */ 234 /* Buggy wrt pids with high bit set */
@@ -725,8 +733,7 @@ static void clearmems(void)
725 top = NULL; 733 top = NULL;
726} 734}
727 735
728#if ENABLE_FEATURE_USE_TERMIOS 736#if ENABLE_FEATURE_TOP_INTERACTIVE
729
730static void reset_term(void) 737static void reset_term(void)
731{ 738{
732 if (!OPT_BATCH_MODE) 739 if (!OPT_BATCH_MODE)
@@ -738,8 +745,7 @@ static void sig_catcher(int sig)
738 reset_term(); 745 reset_term();
739 kill_myself_with_sig(sig); 746 kill_myself_with_sig(sig);
740} 747}
741 748#endif /* FEATURE_TOP_INTERACTIVE */
742#endif /* FEATURE_USE_TERMIOS */
743 749
744/* 750/*
745 * TOPMEM support 751 * TOPMEM support
@@ -894,7 +900,7 @@ enum {
894 EXIT_MASK = (unsigned)-1, 900 EXIT_MASK = (unsigned)-1,
895}; 901};
896 902
897#if ENABLE_FEATURE_USE_TERMIOS 903#if ENABLE_FEATURE_TOP_INTERACTIVE
898static unsigned handle_input(unsigned scan_mask, unsigned interval) 904static unsigned handle_input(unsigned scan_mask, unsigned interval)
899{ 905{
900 if (option_mask32 & OPT_EOF) { 906 if (option_mask32 & OPT_EOF) {
@@ -1043,7 +1049,7 @@ static unsigned handle_input(unsigned scan_mask, unsigned interval)
1043//usage: "\n""Read the status of all processes from /proc each SECONDS" 1049//usage: "\n""Read the status of all processes from /proc each SECONDS"
1044//usage: "\n""and display a screenful of them." 1050//usage: "\n""and display a screenful of them."
1045//usage: "\n" 1051//usage: "\n"
1046//usage: IF_FEATURE_USE_TERMIOS( 1052//usage: IF_FEATURE_TOP_INTERACTIVE(
1047//usage: "Keys:" 1053//usage: "Keys:"
1048//usage: "\n"" N/M" 1054//usage: "\n"" N/M"
1049//usage: IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE("/P") 1055//usage: IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE("/P")
@@ -1091,9 +1097,6 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1091 unsigned interval; 1097 unsigned interval;
1092 char *str_interval, *str_iterations; 1098 char *str_interval, *str_iterations;
1093 unsigned scan_mask = TOP_MASK; 1099 unsigned scan_mask = TOP_MASK;
1094#if ENABLE_FEATURE_USE_TERMIOS
1095 struct termios new_settings;
1096#endif
1097 1100
1098 INIT_G(); 1101 INIT_G();
1099 1102
@@ -1141,13 +1144,10 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1141 if (OPT_BATCH_MODE) { 1144 if (OPT_BATCH_MODE) {
1142 option_mask32 |= OPT_EOF; 1145 option_mask32 |= OPT_EOF;
1143 } 1146 }
1144#if ENABLE_FEATURE_USE_TERMIOS 1147#if ENABLE_FEATURE_TOP_INTERACTIVE
1145 else { 1148 else {
1146 tcgetattr(0, (void *) &initial_settings); 1149 /* Turn on unbuffered input; turn off echoing, ^C ^Z etc */
1147 memcpy(&new_settings, &initial_settings, sizeof(new_settings)); 1150 set_termios_to_raw(STDIN_FILENO, &initial_settings, TERMIOS_CLEAR_ISIG);
1148 /* unbuffered input, turn off echo */
1149 new_settings.c_lflag &= ~(ISIG | ICANON | ECHO | ECHONL);
1150 tcsetattr_stdin_TCSANOW(&new_settings);
1151 } 1151 }
1152 1152
1153 bb_signals(BB_FATAL_SIGS, sig_catcher); 1153 bb_signals(BB_FATAL_SIGS, sig_catcher);
@@ -1165,14 +1165,12 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1165 } else { 1165 } else {
1166 G.lines = 24; /* default */ 1166 G.lines = 24; /* default */
1167 col = 79; 1167 col = 79;
1168#if ENABLE_FEATURE_USE_TERMIOS
1169 /* We output to stdout, we need size of stdout (not stdin)! */ 1168 /* We output to stdout, we need size of stdout (not stdin)! */
1170 get_terminal_width_height(STDOUT_FILENO, &col, &G.lines); 1169 get_terminal_width_height(STDOUT_FILENO, &col, &G.lines);
1171 if (G.lines < 5 || col < 10) { 1170 if (G.lines < 5 || col < 10) {
1172 sleep(interval); 1171 sleep(interval);
1173 continue; 1172 continue;
1174 } 1173 }
1175#endif
1176 if (col > LINE_BUF_SIZE - 2) 1174 if (col > LINE_BUF_SIZE - 2)
1177 col = LINE_BUF_SIZE - 2; 1175 col = LINE_BUF_SIZE - 2;
1178 } 1176 }
@@ -1247,7 +1245,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1247 clearmems(); 1245 clearmems();
1248 if (iterations >= 0 && !--iterations) 1246 if (iterations >= 0 && !--iterations)
1249 break; 1247 break;
1250#if !ENABLE_FEATURE_USE_TERMIOS 1248#if !ENABLE_FEATURE_TOP_INTERACTIVE
1251 sleep(interval); 1249 sleep(interval);
1252#else 1250#else
1253 scan_mask = handle_input(scan_mask, interval); 1251 scan_mask = handle_input(scan_mask, interval);
@@ -1255,7 +1253,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1255 } /* end of "while (not Q)" */ 1253 } /* end of "while (not Q)" */
1256 1254
1257 bb_putchar('\n'); 1255 bb_putchar('\n');
1258#if ENABLE_FEATURE_USE_TERMIOS 1256#if ENABLE_FEATURE_TOP_INTERACTIVE
1259 reset_term(); 1257 reset_term();
1260#endif 1258#endif
1261 if (ENABLE_FEATURE_CLEAN_UP) { 1259 if (ENABLE_FEATURE_CLEAN_UP) {
diff --git a/procps/uptime.c b/procps/uptime.c
index 436193925..8e8956c0f 100644
--- a/procps/uptime.c
+++ b/procps/uptime.c
@@ -21,11 +21,11 @@
21//config: on, and the system load averages for the past 1, 5, and 15 minutes. 21//config: on, and the system load averages for the past 1, 5, and 15 minutes.
22//config: 22//config:
23//config:config FEATURE_UPTIME_UTMP_SUPPORT 23//config:config FEATURE_UPTIME_UTMP_SUPPORT
24//config: bool "Support for showing the number of users" 24//config: bool "Show the number of users"
25//config: default y 25//config: default y
26//config: depends on UPTIME && FEATURE_UTMP 26//config: depends on UPTIME && FEATURE_UTMP
27//config: help 27//config: help
28//config: Makes uptime display the number of users currently logged on. 28//config: Display the number of users currently logged on.
29 29
30//applet:IF_UPTIME(APPLET(uptime, BB_DIR_USR_BIN, BB_SUID_DROP)) 30//applet:IF_UPTIME(APPLET(uptime, BB_DIR_USR_BIN, BB_SUID_DROP))
31 31