Hi,
The following patch will make w(1) always print the word "up" before the
uptime. Currently "up" is not printed if uptime is less than a minute.
I ran into this with a script that parses the output from w(1), and it
got confused by "10:08AM 45 secs" as it was looking for the word "up" to
anchor its parsing.
Kind regards,
+ Kimmo
--- w.c.orig 2021-11-28 16:33:09.275819897 +0200
+++ w.c 2021-11-28 16:33:48.395149662 +0200
@@ -441,6 +441,7 @@ pr_header(time_t *nowp, int nusers)
* Print how long system has been up.
*/
if (clock_gettime(CLOCK_BOOTTIME, &boottime) != -1) {
+ (void)printf(" up");
uptime = boottime.tv_sec;
if (uptime > 59) {
uptime += 30;
@@ -449,7 +450,6 @@ pr_header(time_t *nowp, int nusers)
hrs = uptime / SECSPERHOUR;
uptime %= SECSPERHOUR;
mins = uptime / 60;
- (void)printf(" up");
if (days > 0)
(void)printf(" %d day%s,", days,
days > 1 ? "s" : "");