From ab833461a0845e633cd392fe9b0ede86b42b9a64 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 21 Sep 2021 20:29:50 -0500 Subject: [PATCH] Add load average to uptime -p. This is already the non-machine-readable version, most scripts ignore extra fields on the end they don't recognize, and busybox doesn't even recognize -p. --- toys/other/uptime.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/toys/other/uptime.c b/toys/other/uptime.c index c7adf473..6c0c8052 100644 --- a/toys/other/uptime.c +++ b/toys/other/uptime.c @@ -57,25 +57,24 @@ void uptime_main(void) if (FLAG(p)) { weeks = days/7; days %= 7; - xprintf("up %d week%s, %d day%s, %d hour%s, %d minute%s\n", + xprintf("up %d week%s, %d day%s, %d hour%s, %d minute%s, ", weeks, (weeks!=1)?"s":"", days, (days!=1)?"s":"", hours, (hours!=1)?"s":"", minutes, (minutes!=1)?"s":""); - return; - } + } else { + xprintf(" %02d:%02d:%02d up ", tm->tm_hour, tm->tm_min, tm->tm_sec); + if (days) xprintf("%d day%s, ", days, (days!=1)?"s":""); + if (hours) xprintf("%2d:%02d, ", hours, minutes); + else printf("%d min, ", minutes); - xprintf(" %02d:%02d:%02d up ", tm->tm_hour, tm->tm_min, tm->tm_sec); - if (days) xprintf("%d day%s, ", days, (days!=1)?"s":""); - if (hours) xprintf("%2d:%02d, ", hours, minutes); - else printf("%d min, ", minutes); - - // Obtain info about logged on users - setutxent(); - while ((entry = getutxent())) if (entry->ut_type == USER_PROCESS) users++; - endutxent(); + // Obtain info about logged on users + setutxent(); + while ((entry = getutxent())) if (entry->ut_type == USER_PROCESS) users++; + endutxent(); + printf(" %d user%s, ", users, (users!=1) ? "s" : ""); + } - printf(" %d user%s, ", users, (users!=1) ? "s" : ""); printf(" load average: %.02f, %.02f, %.02f\n", info.loads[0]/65536.0, info.loads[1]/65536.0, info.loads[2]/65536.0); } -- 2.39.2