aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-03-22 15:48:57 +0000
committerRon Yorston <rmy@pobox.com>2012-03-22 15:48:57 +0000
commit9db164d6e39050d09f38288c6045cd2a2cbf6d63 (patch)
treeea5dc2d28d15da0de25c197ed7d059c3656af1a0 /procps
parent1118c95535ea51961437089fc3dece5ab4ea7e1b (diff)
parentd84b175cb6948eb17f847313bf912174e2f934e1 (diff)
downloadbusybox-w32-9db164d6e39050d09f38288c6045cd2a2cbf6d63.tar.gz
busybox-w32-9db164d6e39050d09f38288c6045cd2a2cbf6d63.tar.bz2
busybox-w32-9db164d6e39050d09f38288c6045cd2a2cbf6d63.zip
Merge commit 'd84b175cb6948eb17f847313bf912174e2f934e1' into merge
Conflicts: include/platform.h
Diffstat (limited to 'procps')
-rw-r--r--procps/Config.src9
-rw-r--r--procps/free.c3
-rw-r--r--procps/ps.c3
-rw-r--r--procps/uptime.c63
4 files changed, 53 insertions, 25 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
197config 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
206config WATCH 197config WATCH
207 bool "watch" 198 bool "watch"
208 default y 199 default y
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 @@
22//usage: "Total: 386144 257128 129016\n" 22//usage: "Total: 386144 257128 129016\n"
23 23
24#include "libbb.h" 24#include "libbb.h"
25#ifdef __linux__
26# include <sys/sysinfo.h>
27#endif
25 28
26struct globals { 29struct globals {
27 unsigned mem_unit; 30 unsigned mem_unit;
diff --git a/procps/ps.c b/procps/ps.c
index 41124279d..af57f7aee 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -62,6 +62,9 @@ enum { MAX_WIDTH = 2*1024 };
62 62
63#if ENABLE_DESKTOP 63#if ENABLE_DESKTOP
64 64
65#ifdef __linux__
66# include <sys/sysinfo.h>
67#endif
65#include <sys/times.h> /* for times() */ 68#include <sys/times.h> /* for times() */
66#ifndef AT_CLKTCK 69#ifndef AT_CLKTCK
67# define AT_CLKTCK 17 70# define AT_CLKTCK 17
diff --git a/procps/uptime.c b/procps/uptime.c
index 1a7da46a3..778812a6f 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"
@@ -25,19 +40,23 @@
25//usage: " 1:55pm up 2:30, load average: 0.09, 0.04, 0.00\n" 40//usage: " 1:55pm up 2:30, load average: 0.09, 0.04, 0.00\n"
26 41
27#include "libbb.h" 42#include "libbb.h"
43#ifdef __linux__
44# include <sys/sysinfo.h>
45#endif
46
28 47
29#ifndef FSHIFT 48#ifndef FSHIFT
30# define FSHIFT 16 /* nr of bits of precision */ 49# define FSHIFT 16 /* nr of bits of precision */
31#endif 50#endif
32#define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */ 51#define FIXED_1 (1 << FSHIFT) /* 1.0 as fixed-point */
33#define LOAD_INT(x) ((x) >> FSHIFT) 52#define LOAD_INT(x) (unsigned)((x) >> FSHIFT)
34#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) 53#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
35 54
36 55
37int uptime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 56int uptime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
38int uptime_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) 57int uptime_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
39{ 58{
40 int updays, uphours, upminutes; 59 unsigned updays, uphours, upminutes;
41 struct sysinfo info; 60 struct sysinfo info;
42 struct tm *current_time; 61 struct tm *current_time;
43 time_t current_secs; 62 time_t current_secs;
@@ -47,20 +66,32 @@ int uptime_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
47 66
48 sysinfo(&info); 67 sysinfo(&info);
49 68
50 printf(" %02d:%02d:%02d up ", 69 printf(" %02u:%02u:%02u up ",
51 current_time->tm_hour, current_time->tm_min, current_time->tm_sec); 70 current_time->tm_hour, current_time->tm_min, current_time->tm_sec);
52 updays = (int) info.uptime / (60*60*24); 71 updays = (unsigned) info.uptime / (unsigned)(60*60*24);
53 if (updays) 72 if (updays)
54 printf("%d day%s, ", updays, (updays != 1) ? "s" : ""); 73 printf("%u day%s, ", updays, (updays != 1) ? "s" : "");
55 upminutes = (int) info.uptime / 60; 74 upminutes = (unsigned) info.uptime / (unsigned)60;
56 uphours = (upminutes / 60) % 24; 75 uphours = (upminutes / (unsigned)60) % (unsigned)24;
57 upminutes %= 60; 76 upminutes %= 60;
58 if (uphours) 77 if (uphours)
59 printf("%2d:%02d, ", uphours, upminutes); 78 printf("%2u:%02u", uphours, upminutes);
60 else 79 else
61 printf("%d min, ", upminutes); 80 printf("%u min", upminutes);
81
82#if ENABLE_FEATURE_UPTIME_UTMP_SUPPORT
83 {
84 struct utmp *ut;
85 unsigned users = 0;
86 while ((ut = getutent()) != NULL) {
87 if ((ut->ut_type == USER_PROCESS) && (ut->ut_name[0] != '\0'))
88 users++;
89 }
90 printf(", %u users", users);
91 }
92#endif
62 93
63 printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n", 94 printf(", load average: %u.%02u, %u.%02u, %u.%02u\n",
64 LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]), 95 LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]),
65 LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]), 96 LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]),
66 LOAD_INT(info.loads[2]), LOAD_FRAC(info.loads[2])); 97 LOAD_INT(info.loads[2]), LOAD_FRAC(info.loads[2]));