library: suppress zero 'days' under the <uptime.h> API
The former whattime logic used to suppress that 'days' output when the system had been up less than 24 hours. But since the refactor for newlib, '0 days' was always output under those conditions. So this commit restores the former expected behavior of suppressing that item. [ plus an erroneous calculation of uphours was fixed ] [ and the clang warnings shown below were also fixed ] Reference(s): proc/uptime.c:74:10: warning: unused variable 'buf' [-Wunused-variable] char buf[256]; ^ proc/uptime.c:131:58: warning: data argument not used by format string [-Wformat-extra-args] pos += sprintf(upbuf + pos, "%d min, ", uphours, upminutes); ~~~~~~~~~~ ^ proc/uptime.c:175:15: warning: expression result unused [-Wunused-value] comma +1; ~~~~~ ^~ Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
bb04019510
commit
34395be330
@ -71,7 +71,6 @@ PROCPS_EXPORT int procps_uptime(
|
|||||||
{
|
{
|
||||||
double up=0, idle=0;
|
double up=0, idle=0;
|
||||||
char *savelocale;
|
char *savelocale;
|
||||||
char buf[256];
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
if ((fp = fopen(UPTIME_FILE, "r")) == NULL)
|
if ((fp = fopen(UPTIME_FILE, "r")) == NULL)
|
||||||
@ -122,19 +121,22 @@ PROCPS_EXPORT char *procps_uptime_sprint(void)
|
|||||||
uphours = ((int) uptime_secs / (60*60)) % 24;
|
uphours = ((int) uptime_secs / (60*60)) % 24;
|
||||||
upminutes = ((int) uptime_secs / (60)) % 60;
|
upminutes = ((int) uptime_secs / (60)) % 60;
|
||||||
|
|
||||||
pos = sprintf(upbuf, " %02d:%02d:%02d up %d %s, ",
|
pos = sprintf(upbuf, " %02d:%02d:%02d up ",
|
||||||
realtime->tm_hour, realtime->tm_min, realtime->tm_sec,
|
realtime->tm_hour, realtime->tm_min, realtime->tm_sec);
|
||||||
updays, (updays != 1) ? "days" : "day");
|
|
||||||
|
if (updays)
|
||||||
|
pos += sprintf(upbuf + pos, "%d %s", updays, (updays > 1) ? "days" : "day");
|
||||||
|
|
||||||
if (uphours)
|
if (uphours)
|
||||||
pos += sprintf(upbuf + pos, "%2d:%02d, ", uphours, upminutes);
|
pos += sprintf(upbuf + pos, "%2d:%02d, ", uphours, upminutes);
|
||||||
else
|
else
|
||||||
pos += sprintf(upbuf + pos, "%d min, ", uphours, upminutes);
|
pos += sprintf(upbuf + pos, "%d min, ", upminutes);
|
||||||
|
|
||||||
users = count_users();
|
users = count_users();
|
||||||
procps_loadavg(&av1, &av5, &av15);
|
procps_loadavg(&av1, &av5, &av15);
|
||||||
|
|
||||||
pos += sprintf(upbuf + pos, "%2d user%s, load average: %.2f, %.2f, %.2f",
|
pos += sprintf(upbuf + pos, "%2d %s, load average: %.2f, %.2f, %.2f",
|
||||||
users, users == 1 ? "" : "s",
|
users, users > 1 ? "users" : "user",
|
||||||
av1, av5, av15);
|
av1, av5, av15);
|
||||||
|
|
||||||
return upbuf;
|
return upbuf;
|
||||||
@ -164,7 +166,7 @@ PROCPS_EXPORT char *procps_uptime_sprint_short(void)
|
|||||||
upyears = ((int) uptime_secs / (60*60*24*365)) % 10;
|
upyears = ((int) uptime_secs / (60*60*24*365)) % 10;
|
||||||
upweeks = ((int) uptime_secs / (60*60*24*7)) % 52;
|
upweeks = ((int) uptime_secs / (60*60*24*7)) % 52;
|
||||||
updays = ((int) uptime_secs / (60*60*24)) % 7;
|
updays = ((int) uptime_secs / (60*60*24)) % 7;
|
||||||
uphours = ((int) uptime_secs / (60*24)) % 24;
|
uphours = ((int) uptime_secs / (60*60)) % 24;
|
||||||
upminutes = ((int) uptime_secs / (60)) % 60;
|
upminutes = ((int) uptime_secs / (60)) % 60;
|
||||||
|
|
||||||
strcat(shortbuf, "up ");
|
strcat(shortbuf, "up ");
|
||||||
@ -172,7 +174,7 @@ PROCPS_EXPORT char *procps_uptime_sprint_short(void)
|
|||||||
if (updecades) {
|
if (updecades) {
|
||||||
pos += sprintf(shortbuf + pos, "%d %s",
|
pos += sprintf(shortbuf + pos, "%d %s",
|
||||||
updecades, updecades > 1 ? "decades" : "decade");
|
updecades, updecades > 1 ? "decades" : "decade");
|
||||||
comma +1;
|
comma += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (upyears) {
|
if (upyears) {
|
||||||
|
Loading…
Reference in New Issue
Block a user