From vova@express.ru  Thu Sep 20 04:20:04 2001
Return-Path: <vova@express.ru>
Received: from vbook.express.ru (asplinux.ru [195.133.213.194])
	by hub.freebsd.org (Postfix) with ESMTP
	id C42FA37B409; Thu, 20 Sep 2001 04:20:03 -0700 (PDT)
Received: from vova by vbook.express.ru with local (Exim 3.31 #2)
	id 15k1tE-0000r2-00; Thu, 20 Sep 2001 15:21:08 +0400
Message-Id: <E15k1tE-0000r2-00@vbook.express.ru>
Date: Thu, 20 Sep 2001 15:21:08 +0400
From: Vladimir B.Grebenschikov <vova@express.ru>
Sender: "Vladimir B. Grebenschikov" <vova@express.ru>
Reply-To: Vladimir B.Grebenschikov <vova@express.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc: freebsd-hackers@freebsd.org
Subject: uptime and w utilities lie about real uptime
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         30680
>Category:       bin
>Synopsis:       uptime and w utilities lie about real uptime
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    cjc
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 20 04:30:03 PDT 2001
>Closed-Date:    Thu Sep 27 17:27:20 PDT 2001
>Last-Modified:  Thu Sep 27 17:29:04 PDT 2001
>Originator:     Vladimir B. Grebenschikov
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
TSB "Russian Express"
>Environment:
System: FreeBSD vbook.express.ru 5.0-CURRENT FreeBSD 5.0-CURRENT #0: Wed Sep 19 20:26:25 MSD 2001 root@vbook.express.ru:/usr/src.local/sys/i386/compile/VBOOK i386

>Description:

	Just after very fast boot uptimealways shows more than 30 sec.

	looking to src/usr/bin/w/w.c:

        if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 &&
            boottime.tv_sec != 0) {
                uptime = now - boottime.tv_sec;
                uptime += 30;
====================== ^^^^^
                days = uptime / 86400;
                uptime %= 86400;
                hrs = uptime / 3600;
                uptime %= 3600;
                mins = uptime / 60;
                secs = uptime % 60;
                (void)printf(" up");


why utility increases uptime on 30 seconds ??
Is any real reasons for it ?

>How-To-Repeat:
	Boot and run uptime
>Fix:

--- src/usr.bin/w.c.orig    Thu Sep 20 15:20:01 2001
+++ src/usr.bin/w.c Thu Sep 20 15:20:11 2001
@@ -450,7 +450,6 @@
        if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 &&
            boottime.tv_sec != 0) {
                uptime = now - boottime.tv_sec;
-               uptime += 30;
                days = uptime / 86400;
                uptime %= 86400;
                hrs = uptime / 3600;
>Release-Note:
>Audit-Trail:

From: David Malone <dwmalone@maths.tcd.ie>
To: "Vladimir B.Grebenschikov" <vova@express.ru>
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.
 
 	David.

From: "Crist J. Clark" <cristjc@earthlink.net>
To: David Malone <dwmalone@maths.tcd.ie>
Cc: FreeBSD-gnats-submit@freebsd.org,
	"Vladimir B.Grebenschikov" <vova@express.ru>
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 <dwmalone@maths.tcd.ie>
 > To: "Vladimir B.Grebenschikov" <vova@express.ru>
 > 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
State-Changed-From-To: open->analyzed 
State-Changed-By: cjc 
State-Changed-When: Thu Sep 20 12:26:01 PDT 2001 
State-Changed-Why:  
Fix being committed to CURRENT. 


Responsible-Changed-From-To: freebsd-bugs->cjc 
Responsible-Changed-By: cjc 
Responsible-Changed-When: Thu Sep 20 12:26:01 PDT 2001 
Responsible-Changed-Why:  
Made the fix in my repo doing some checks and will commit. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=30680 

From: Bruce Evans <bde@zeta.org.au>
To: "Crist J. Clark" <cristjc@earthlink.net>
Cc: <freebsd-gnats-submit@FreeBSD.ORG>
Subject: Re: bin/30680: uptime and w utilities lie about real uptime
Date: Fri, 21 Sep 2001 06:10:26 +1000 (EST)

 On Thu, 20 Sep 2001, Crist J. Clark wrote:
 
 >  On Thu, Sep 20, 2001 at 05:40:05AM -0700, David Malone wrote:
 >  >  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.
 
 Just add 30 in the one place where it is needed:
 
 		    mins = (uptime + 30) / 60;
 
 Bruce
 

From: "Crist J. Clark" <cristjc@earthlink.net>
To: Bruce Evans <bde@zeta.org.au>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/30680: uptime and w utilities lie about real uptime
Date: Thu, 20 Sep 2001 14:17:35 -0700

 On Thu, Sep 20, 2001 at 01:20:01PM -0700, Bruce Evans wrote:
 >  On Thu, 20 Sep 2001, Crist J. Clark wrote:
 >  >  On Thu, Sep 20, 2001 at 05:40:05AM -0700, David Malone wrote:
 >  >  >  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.
 >  
 >  Just add 30 in the one place where it is needed:
 >  
 >  		    mins = (uptime + 30) / 60;
 
 That won't actually work correctly. For example, if you were at,
 
   1 day 23:59:45
 
 Just adding the 30 seconds when calculating 'mins' would produce,
 
   1 day 23:00
 
 Instead of the correct,
 
   2 days 00:00
 
 -- 
 Crist J. Clark                           cjclark@alum.mit.edu
State-Changed-From-To: analyzed->closed 
State-Changed-By: cjc 
State-Changed-When: Thu Sep 27 17:27:20 PDT 2001 
State-Changed-Why:  
Fix MFC'ed into STABLE. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=30680 
>Unformatted:
