From owner-freebsd-bugs Thu Sep 20 12:10: 8 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id BE9CA37B414 for ; Thu, 20 Sep 2001 12:10:02 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.4/8.11.4) id f8KJA2D66277; Thu, 20 Sep 2001 12:10:02 -0700 (PDT) (envelope-from gnats) Date: Thu, 20 Sep 2001 12:10:02 -0700 (PDT) Message-Id: <200109201910.f8KJA2D66277@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: "Crist J. Clark" Subject: Re: bin/30680: uptime and w utilities lie about real uptime Reply-To: "Crist J. Clark" Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR bin/30680; it has been noted by GNATS. From: "Crist J. Clark" To: David Malone Cc: FreeBSD-gnats-submit@freebsd.org, "Vladimir B.Grebenschikov" Subject: Re: bin/30680: uptime and w utilities lie about real uptime Date: Thu, 20 Sep 2001 12:04:50 -0700 On Thu, Sep 20, 2001 at 05:40:05AM -0700, David Malone wrote: > The following reply was made to PR bin/30680; it has been noted by GNATS. > > From: David Malone > To: "Vladimir B.Grebenschikov" > Cc: FreeBSD-gnats-submit@freebsd.org, freebsd-hackers@freebsd.org > Subject: Re: bin/30680: uptime and w utilities lie about real uptime > Date: Thu, 20 Sep 2001 13:31:49 +0100 > > On Thu, Sep 20, 2001 at 03:21:08PM +0400, Vladimir B.Grebenschikov wrote: > > why utility increases uptime on 30 seconds ?? > > Is any real reasons for it ? > > It adds 30 because it wants to round the number of minutes to the > nearest minute, instead of rounding down. Unfortunately this isn't > a sensible thing to do if you are also going to display the number > of seconds. The only time this is noticed is when the time is printed in seconds. This should fix it, Index: src/usr.bin/w/w.c =================================================================== RCS file: /export/ncvs/src/usr.bin/w/w.c,v retrieving revision 1.48 diff -u -r1.48 w.c --- src/usr.bin/w/w.c 2001/07/26 19:20:13 1.48 +++ src/usr.bin/w/w.c 2001/09/20 19:00:57 @@ -452,13 +452,15 @@ if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && boottime.tv_sec != 0) { uptime = now - boottime.tv_sec; + /* Round to nearest minute. */ uptime += 30; days = uptime / 86400; uptime %= 86400; hrs = uptime / 3600; uptime %= 3600; mins = uptime / 60; - secs = uptime % 60; + /* Undo rounding to calculate uptime in seconds. */ + secs = (uptime - 30) % 60; (void)printf(" up"); if (days > 0) (void)printf(" %d day%s,", days, days > 1 ? "s" : ""); I will commit the fix later unless someone has comments. -- Crist J. Clark cjclark@alum.mit.edu To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message