From 67905e2d7c6ee273b753af22fb22de0ebec918c1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 26 Jul 2011 13:42:12 +0200 Subject: *: work around sysinfo.h versus linux/*.h problems Signed-off-by: Denys Vlasenko --- procps/free.c | 3 +++ procps/ps.c | 3 +++ procps/uptime.c | 4 ++++ 3 files changed, 10 insertions(+) (limited to 'procps') diff --git a/procps/free.c b/procps/free.c index ca753134c..47f2fc3b2 100644 --- a/procps/free.c +++ b/procps/free.c @@ -22,6 +22,9 @@ //usage: "Total: 386144 257128 129016\n" #include "libbb.h" +#ifdef __linux__ +# include +#endif struct globals { unsigned mem_unit; diff --git a/procps/ps.c b/procps/ps.c index 7537118f6..dcc0f7bd4 100644 --- a/procps/ps.c +++ b/procps/ps.c @@ -62,6 +62,9 @@ enum { MAX_WIDTH = 2*1024 }; #if ENABLE_DESKTOP +#ifdef __linux__ +# include +#endif #include /* for times() */ #ifndef AT_CLKTCK # define AT_CLKTCK 17 diff --git a/procps/uptime.c b/procps/uptime.c index 1a7da46a3..74323625d 100644 --- a/procps/uptime.c +++ b/procps/uptime.c @@ -25,6 +25,10 @@ //usage: " 1:55pm up 2:30, load average: 0.09, 0.04, 0.00\n" #include "libbb.h" +#ifdef __linux__ +# include +#endif + #ifndef FSHIFT # define FSHIFT 16 /* nr of bits of precision */ -- cgit v1.2.3-55-g6feb From d91b13806f41131fe55ece6027fa762f5da016ac Mon Sep 17 00:00:00 2001 From: Pere Orga Date: Tue, 9 Aug 2011 04:09:17 +0200 Subject: uptime: add config flag to allow displaying the number of users currently logged on Signed-off-by: Pere Orga Signed-off-by: Denys Vlasenko --- procps/Config.src | 9 --------- procps/uptime.c | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 13 deletions(-) (limited to 'procps') 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 Enables the ps -T option, showing of threads in pstree, and 'h' command in top. -config UPTIME - bool "uptime" - default y - select PLATFORM_LINUX #sysinfo() - help - uptime gives a one line display of the current time, how long - the system has been running, how many users are currently logged - on, and the system load averages for the past 1, 5, and 15 minutes. - config WATCH bool "watch" 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 @@ * Licensed under GPLv2, see file LICENSE in this source tree. */ -/* This version of uptime doesn't display the number of users on the system, - * since busybox init doesn't mess with utmp. For folks using utmp that are - * just dying to have # of users reported, feel free to write it as some type - * of CONFIG_FEATURE_UTMP_SUPPORT #define +/* 2011 Pere Orga + * + * Added FEATURE_UPTIME_UTMP_SUPPORT flag. */ /* getopt not needed */ +//config:config UPTIME +//config: bool "uptime" +//config: default y +//config: select PLATFORM_LINUX #sysinfo() +//config: help +//config: uptime gives a one line display of the current time, how long +//config: the system has been running, how many users are currently logged +//config: on, and the system load averages for the past 1, 5, and 15 minutes. +//config: +//config:config FEATURE_UPTIME_UTMP_SUPPORT +//config: bool "Support for showing the number of users" +//config: default y +//config: depends on UPTIME && FEATURE_UTMP +//config: help +//config: Makes uptime display the number of users currently logged on. + //usage:#define uptime_trivial_usage //usage: "" //usage:#define uptime_full_usage "\n\n" @@ -64,6 +79,18 @@ int uptime_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) else printf("%d min, ", upminutes); +#if ENABLE_FEATURE_UPTIME_UTMP_SUPPORT +{ + struct utmp *ut; + int users = 0; + while ((ut = getutent())) { + if ((ut->ut_type == USER_PROCESS) && (ut->ut_name[0] != '\0')) + users++; + } + printf("%d users, ", users); +} +#endif + printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n", LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]), LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]), -- cgit v1.2.3-55-g6feb From 5845a06c9ed8c16200942d1fba581db90a451cc6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 10 Aug 2011 13:00:04 +0200 Subject: uptime: more compatible output was: 12:59:35 up 1:57, 4 users, load average: 0.11, 0.20, 0.53 is: 12:59:37 up 1:57, 4 users, load average: 0.11, 0.20, 0.53 While at it, switched code to unsigned division. Based on patch by Pere Orga . Signed-off-by: Denys Vlasenko --- procps/uptime.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'procps') diff --git a/procps/uptime.c b/procps/uptime.c index c3a2740e1..778812a6f 100644 --- a/procps/uptime.c +++ b/procps/uptime.c @@ -48,15 +48,15 @@ #ifndef FSHIFT # define FSHIFT 16 /* nr of bits of precision */ #endif -#define FIXED_1 (1<> FSHIFT) -#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) +#define FIXED_1 (1 << FSHIFT) /* 1.0 as fixed-point */ +#define LOAD_INT(x) (unsigned)((x) >> FSHIFT) +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100) int uptime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int uptime_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) { - int updays, uphours, upminutes; + unsigned updays, uphours, upminutes; struct sysinfo info; struct tm *current_time; time_t current_secs; @@ -66,32 +66,32 @@ int uptime_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) sysinfo(&info); - printf(" %02d:%02d:%02d up ", + printf(" %02u:%02u:%02u up ", current_time->tm_hour, current_time->tm_min, current_time->tm_sec); - updays = (int) info.uptime / (60*60*24); + updays = (unsigned) info.uptime / (unsigned)(60*60*24); if (updays) - printf("%d day%s, ", updays, (updays != 1) ? "s" : ""); - upminutes = (int) info.uptime / 60; - uphours = (upminutes / 60) % 24; + printf("%u day%s, ", updays, (updays != 1) ? "s" : ""); + upminutes = (unsigned) info.uptime / (unsigned)60; + uphours = (upminutes / (unsigned)60) % (unsigned)24; upminutes %= 60; if (uphours) - printf("%2d:%02d, ", uphours, upminutes); + printf("%2u:%02u", uphours, upminutes); else - printf("%d min, ", upminutes); + printf("%u min", upminutes); #if ENABLE_FEATURE_UPTIME_UTMP_SUPPORT -{ - struct utmp *ut; - int users = 0; - while ((ut = getutent())) { - if ((ut->ut_type == USER_PROCESS) && (ut->ut_name[0] != '\0')) - users++; + { + struct utmp *ut; + unsigned users = 0; + while ((ut = getutent()) != NULL) { + if ((ut->ut_type == USER_PROCESS) && (ut->ut_name[0] != '\0')) + users++; + } + printf(", %u users", users); } - printf("%d users, ", users); -} #endif - printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n", + printf(", load average: %u.%02u, %u.%02u, %u.%02u\n", LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]), LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]), LOAD_INT(info.loads[2]), LOAD_FRAC(info.loads[2])); -- cgit v1.2.3-55-g6feb