diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-08-10 13:00:04 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-08-10 13:00:04 +0200 |
commit | 5845a06c9ed8c16200942d1fba581db90a451cc6 (patch) | |
tree | 2e5b4279d745d6220eebdbf7d325e5373d53ea69 | |
parent | 47b03368f34d45a3787e261189d7157b3a63dd29 (diff) | |
download | busybox-w32-5845a06c9ed8c16200942d1fba581db90a451cc6.tar.gz busybox-w32-5845a06c9ed8c16200942d1fba581db90a451cc6.tar.bz2 busybox-w32-5845a06c9ed8c16200942d1fba581db90a451cc6.zip |
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 <gotrunks@gmail.com>.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | procps/uptime.c | 40 |
1 files changed, 20 insertions, 20 deletions
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 @@ | |||
48 | #ifndef FSHIFT | 48 | #ifndef FSHIFT |
49 | # define FSHIFT 16 /* nr of bits of precision */ | 49 | # define FSHIFT 16 /* nr of bits of precision */ |
50 | #endif | 50 | #endif |
51 | #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */ | 51 | #define FIXED_1 (1 << FSHIFT) /* 1.0 as fixed-point */ |
52 | #define LOAD_INT(x) ((x) >> FSHIFT) | 52 | #define LOAD_INT(x) (unsigned)((x) >> FSHIFT) |
53 | #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) | 53 | #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100) |
54 | 54 | ||
55 | 55 | ||
56 | int uptime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 56 | int uptime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
57 | int uptime_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | 57 | int uptime_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
58 | { | 58 | { |
59 | int updays, uphours, upminutes; | 59 | unsigned updays, uphours, upminutes; |
60 | struct sysinfo info; | 60 | struct sysinfo info; |
61 | struct tm *current_time; | 61 | struct tm *current_time; |
62 | time_t current_secs; | 62 | time_t current_secs; |
@@ -66,32 +66,32 @@ int uptime_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
66 | 66 | ||
67 | sysinfo(&info); | 67 | sysinfo(&info); |
68 | 68 | ||
69 | printf(" %02d:%02d:%02d up ", | 69 | printf(" %02u:%02u:%02u up ", |
70 | 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); |
71 | updays = (int) info.uptime / (60*60*24); | 71 | updays = (unsigned) info.uptime / (unsigned)(60*60*24); |
72 | if (updays) | 72 | if (updays) |
73 | printf("%d day%s, ", updays, (updays != 1) ? "s" : ""); | 73 | printf("%u day%s, ", updays, (updays != 1) ? "s" : ""); |
74 | upminutes = (int) info.uptime / 60; | 74 | upminutes = (unsigned) info.uptime / (unsigned)60; |
75 | uphours = (upminutes / 60) % 24; | 75 | uphours = (upminutes / (unsigned)60) % (unsigned)24; |
76 | upminutes %= 60; | 76 | upminutes %= 60; |
77 | if (uphours) | 77 | if (uphours) |
78 | printf("%2d:%02d, ", uphours, upminutes); | 78 | printf("%2u:%02u", uphours, upminutes); |
79 | else | 79 | else |
80 | printf("%d min, ", upminutes); | 80 | printf("%u min", upminutes); |
81 | 81 | ||
82 | #if ENABLE_FEATURE_UPTIME_UTMP_SUPPORT | 82 | #if ENABLE_FEATURE_UPTIME_UTMP_SUPPORT |
83 | { | 83 | { |
84 | struct utmp *ut; | 84 | struct utmp *ut; |
85 | int users = 0; | 85 | unsigned users = 0; |
86 | while ((ut = getutent())) { | 86 | while ((ut = getutent()) != NULL) { |
87 | if ((ut->ut_type == USER_PROCESS) && (ut->ut_name[0] != '\0')) | 87 | if ((ut->ut_type == USER_PROCESS) && (ut->ut_name[0] != '\0')) |
88 | users++; | 88 | users++; |
89 | } | ||
90 | printf(", %u users", users); | ||
89 | } | 91 | } |
90 | printf("%d users, ", users); | ||
91 | } | ||
92 | #endif | 92 | #endif |
93 | 93 | ||
94 | printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n", | 94 | printf(", load average: %u.%02u, %u.%02u, %u.%02u\n", |
95 | LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]), | 95 | LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]), |
96 | LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]), | 96 | LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]), |
97 | LOAD_INT(info.loads[2]), LOAD_FRAC(info.loads[2])); | 97 | LOAD_INT(info.loads[2]), LOAD_FRAC(info.loads[2])); |