]> granicus.if.org Git - procps-ng/commitdiff
whattime: Show 0 minutes in pretty output
authorKyle Laker <lakerka@dukes.jmu.edu>
Thu, 23 Mar 2017 14:53:55 +0000 (10:53 -0400)
committerCraig Small <csmall@enc.com.au>
Sat, 23 Sep 2017 07:32:29 +0000 (17:32 +1000)
When supplying the -p command to uptime, it does not display any
sections where the value is less than 1; however, after a reboot, this
causes the command to just output "up". Showing 0 minutes when the
system has been up for less than a minute makes it clear a reboot just
occurred.

proc/whattime.c

index eb345fb1c371dd53b31930eb5683aa7ea979be1e..10e78c3f3de5d8c36cc3f702976192d9393c002b 100644 (file)
@@ -146,10 +146,10 @@ char *sprint_uptime(int human_readable) {
       comma += 1;
     }
 
-    if (upminutes) {
-      pos += sprintf(buf + pos, "%s%d %s", comma > 0 ? ", " : "", upminutes,
-                     upminutes > 1 ? "minutes" : "minute");
-      comma += 1;
+    if (upminutes || (!upminutes && uptime_secs < 60)) {
+        pos += sprintf(buf + pos, "%s%d %s", comma > 0 ? ", " : "", upminutes,
+                       upminutes != 1 ? "minutes" : "minute");
+        comma += 1;
     }
   }