diff options
author | Pere Orga <gotrunks@gmail.com> | 2011-08-09 04:09:17 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-08-09 04:09:17 +0200 |
commit | d91b13806f41131fe55ece6027fa762f5da016ac (patch) | |
tree | 58f56e6a1c0f31794bb1e435f1d4fba2456156ee | |
parent | 7485086f1eca78998d6cd31b0ce18a8a8ea3fc35 (diff) | |
download | busybox-w32-d91b13806f41131fe55ece6027fa762f5da016ac.tar.gz busybox-w32-d91b13806f41131fe55ece6027fa762f5da016ac.tar.bz2 busybox-w32-d91b13806f41131fe55ece6027fa762f5da016ac.zip |
uptime: add config flag to allow displaying the number of users currently logged on
Signed-off-by: Pere Orga <gotrunks@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | procps/Config.src | 9 | ||||
-rw-r--r-- | procps/uptime.c | 35 |
2 files changed, 31 insertions, 13 deletions
diff --git a/procps/Config.src b/procps/Config.src index 3e7df0b81..570b026da 100644 --- a/procps/Config.src +++ b/procps/Config.src | |||
@@ -194,15 +194,6 @@ config FEATURE_SHOW_THREADS | |||
194 | Enables the ps -T option, showing of threads in pstree, | 194 | Enables the ps -T option, showing of threads in pstree, |
195 | and 'h' command in top. | 195 | and 'h' command in top. |
196 | 196 | ||
197 | config UPTIME | ||
198 | bool "uptime" | ||
199 | default y | ||
200 | select PLATFORM_LINUX #sysinfo() | ||
201 | help | ||
202 | uptime gives a one line display of the current time, how long | ||
203 | the system has been running, how many users are currently logged | ||
204 | on, and the system load averages for the past 1, 5, and 15 minutes. | ||
205 | |||
206 | config WATCH | 197 | config WATCH |
207 | bool "watch" | 198 | bool "watch" |
208 | default y | 199 | default y |
diff --git a/procps/uptime.c b/procps/uptime.c index 74323625d..c3a2740e1 100644 --- a/procps/uptime.c +++ b/procps/uptime.c | |||
@@ -7,14 +7,29 @@ | |||
7 | * Licensed under GPLv2, see file LICENSE in this source tree. | 7 | * Licensed under GPLv2, see file LICENSE in this source tree. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | /* This version of uptime doesn't display the number of users on the system, | 10 | /* 2011 Pere Orga <gotrunks@gmail.com> |
11 | * since busybox init doesn't mess with utmp. For folks using utmp that are | 11 | * |
12 | * just dying to have # of users reported, feel free to write it as some type | 12 | * Added FEATURE_UPTIME_UTMP_SUPPORT flag. |
13 | * of CONFIG_FEATURE_UTMP_SUPPORT #define | ||
14 | */ | 13 | */ |
15 | 14 | ||
16 | /* getopt not needed */ | 15 | /* getopt not needed */ |
17 | 16 | ||
17 | //config:config UPTIME | ||
18 | //config: bool "uptime" | ||
19 | //config: default y | ||
20 | //config: select PLATFORM_LINUX #sysinfo() | ||
21 | //config: help | ||
22 | //config: uptime gives a one line display of the current time, how long | ||
23 | //config: the system has been running, how many users are currently logged | ||
24 | //config: on, and the system load averages for the past 1, 5, and 15 minutes. | ||
25 | //config: | ||
26 | //config:config FEATURE_UPTIME_UTMP_SUPPORT | ||
27 | //config: bool "Support for showing the number of users" | ||
28 | //config: default y | ||
29 | //config: depends on UPTIME && FEATURE_UTMP | ||
30 | //config: help | ||
31 | //config: Makes uptime display the number of users currently logged on. | ||
32 | |||
18 | //usage:#define uptime_trivial_usage | 33 | //usage:#define uptime_trivial_usage |
19 | //usage: "" | 34 | //usage: "" |
20 | //usage:#define uptime_full_usage "\n\n" | 35 | //usage:#define uptime_full_usage "\n\n" |
@@ -64,6 +79,18 @@ int uptime_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
64 | else | 79 | else |
65 | printf("%d min, ", upminutes); | 80 | printf("%d min, ", upminutes); |
66 | 81 | ||
82 | #if ENABLE_FEATURE_UPTIME_UTMP_SUPPORT | ||
83 | { | ||
84 | struct utmp *ut; | ||
85 | int users = 0; | ||
86 | while ((ut = getutent())) { | ||
87 | if ((ut->ut_type == USER_PROCESS) && (ut->ut_name[0] != '\0')) | ||
88 | users++; | ||
89 | } | ||
90 | printf("%d users, ", users); | ||
91 | } | ||
92 | #endif | ||
93 | |||
67 | printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n", | 94 | printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n", |
68 | LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]), | 95 | LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]), |
69 | LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]), | 96 | LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]), |