diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-05-30 18:39:45 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-05-30 18:39:45 +0000 |
commit | 9717b953f4b788882d8d500ec225531bfc23c0ea (patch) | |
tree | dee52f6323d64c8911399d3362e0f22b83c9b6c7 /usr.bin/w/w.c | |
parent | f4668397cb48593e6a75d31ddc2ceee4bc89d76f (diff) |
if less than 60 secs of uptime, say so
Diffstat (limited to 'usr.bin/w/w.c')
-rw-r--r-- | usr.bin/w/w.c | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c index ad8e160126b..e09213c7820 100644 --- a/usr.bin/w/w.c +++ b/usr.bin/w/w.c @@ -1,4 +1,4 @@ -/* $OpenBSD: w.c,v 1.16 1997/04/01 07:58:40 millert Exp $ */ +/* $OpenBSD: w.c,v 1.17 1997/05/30 18:39:44 deraadt Exp $ */ /*- * Copyright (c) 1980, 1991, 1993, 1994 @@ -400,28 +400,31 @@ pr_header(nowp, nusers) mib[0] = CTL_KERN; mib[1] = KERN_BOOTTIME; size = sizeof(boottime); - if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && - boottime.tv_sec != 0) { + if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1) { uptime = now - boottime.tv_sec; - uptime += 30; - days = uptime / SECSPERDAY; - uptime %= SECSPERDAY; - hrs = uptime / SECSPERHOUR; - uptime %= SECSPERHOUR; - mins = uptime / SECSPERMIN; - (void)printf(" up"); - if (days > 0) - (void)printf(" %d day%s,", days, days > 1 ? "s" : ""); - if (hrs > 0 && mins > 0) - (void)printf(" %2d:%02d,", hrs, mins); - else { - if (hrs > 0) - (void)printf(" %d hr%s,", - hrs, hrs > 1 ? "s" : ""); - if (mins > 0 || (days == 0 && hrs == 0)) - (void)printf(" %d min%s,", - mins, mins != 1 ? "s" : ""); - } + if (boottime.tv_sec > 59) { + uptime += 30; + days = uptime / SECSPERDAY; + uptime %= SECSPERDAY; + hrs = uptime / SECSPERHOUR; + uptime %= SECSPERHOUR; + mins = uptime / SECSPERMIN; + (void)printf(" up"); + if (days > 0) + (void)printf(" %d day%s,", days, + days > 1 ? "s" : ""); + if (hrs > 0 && mins > 0) + (void)printf(" %2d:%02d,", hrs, mins); + else { + if (hrs > 0) + (void)printf(" %d hr%s,", + hrs, hrs > 1 ? "s" : ""); + if (mins > 0 || (days == 0 && hrs == 0)) + (void)printf(" %d min%s,", + mins, mins != 1 ? "s" : ""); + } + } else + printf(" %d seconds,", uptime); } /* Print number of users logged in to system */ |