From snabb@tiktik.epipe.com  Thu Jun 17 09:39:02 2010
Return-Path: <snabb@tiktik.epipe.com>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id AADAA1065673
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 17 Jun 2010 09:39:02 +0000 (UTC)
	(envelope-from snabb@tiktik.epipe.com)
Received: from tiktik.epipe.com (tiktik.epipe.com [IPv6:2001:470:8940:10::1])
	by mx1.freebsd.org (Postfix) with ESMTP id 461B78FC1F
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 17 Jun 2010 09:39:02 +0000 (UTC)
Received: from tiktik.epipe.com (localhost [127.0.0.1])
	by tiktik.epipe.com (8.14.3/8.14.3) with ESMTP id o5H9cwYC079617
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 17 Jun 2010 09:39:01 GMT
	(envelope-from snabb@tiktik.epipe.com)
Received: (from snabb@localhost)
	by tiktik.epipe.com (8.14.3/8.14.3/Submit) id o5H9crpt079616;
	Thu, 17 Jun 2010 09:38:53 GMT
	(envelope-from snabb)
Message-Id: <201006170938.o5H9crpt079616@tiktik.epipe.com>
Date: Thu, 17 Jun 2010 09:38:53 GMT
From: Janne Snabb <snabb@epipe.com>
Reply-To: Janne Snabb <snabb@epipe.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] top(1) lies about system uptime
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         147934
>Category:       bin
>Synopsis:       [patch] top(1) lies about system uptime
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    brucec
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 17 09:40:03 UTC 2010
>Closed-Date:    Sat Sep 11 14:47:23 UTC 2010
>Last-Modified:  Sat Sep 11 14:47:23 UTC 2010
>Originator:     Janne Snabb <snabb@epipe.com>
>Release:        FreeBSD 8.0-RELEASE-p1 i386
>Organization:
EPIPE Communications
>Environment:
This bug applies to any recent FreeBSD version on any architecture up
to -CURRENT.
>Description:
The top(1) utility lies about system uptime. It consistently reports
30 seconds longer system uptime than what the reality is.

This is because the code for calculating the uptime has been probably
blindly copied from usr.bin/w/w.c which has "uptime += 30" for
rounding purposes (as w(1) and uptime(1) commands typically do not report
seconds when reporting the uptime, unlike top(1)).

Note that the PR bin/127633 will introduce the same problem again if it
is committed.
>How-To-Repeat:
Run top(1) and compare its output about the uptime to the output
of the following command:

sysctl kern.boottime | perl -ne '/= (\d+),/; print gmtime(time - $1) . "\n";'

The above perl one-liner uses gmtime() for formatting the uptime,
which requires a bit of interpretation, but the basic idea is to
substract the boot time from the current time to find out the current
uptime, and then compare that to top(1) output.
>Fix:


--- contrib-top-display-c.diff begins here ---
--- contrib/top/display.c.orig	2009-10-25 01:10:29.000000000 +0000
+++ contrib/top/display.c	2010-06-17 08:44:04.000000000 +0000
@@ -1271,11 +1271,10 @@
     time_t uptime;
     int days, hrs, mins, secs;
 
     if (bt->tv_sec != -1) {
 	uptime = *tod - bt->tv_sec;
-	uptime += 30;
 	days = uptime / 86400;
 	uptime %= 86400;
 	hrs = uptime / 3600;
 	uptime %= 3600;
 	mins = uptime / 60;
--- contrib-top-display-c.diff ends here ---


>Release-Note:
>Audit-Trail:

From: Janne Snabb <snabb@epipe.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/147934: This bug was reported to upstream
Date: Thu, 17 Jun 2010 11:17:06 +0000 (UTC)

 FYI
 
 I reported this bug upstream to the top developer:
 
 https://sourceforge.net/tracker/?func=detail&atid=536042&aid=3017534&group_id=72892
 
 However it seems unclear if unixtop is still maintained by William
 LeFebvre (wnl) or abandoned as I do not see any activity in the
 couple of past years.
 
 The latest release of top (3.8beta1) as well as the subversion trunk
 still includes this bug.
 
 --
 Janne Snabb / EPIPE Communications
 snabb@epipe.com - http://epipe.com/
Responsible-Changed-From-To: freebsd-bugs->brucec  
Responsible-Changed-By: brucec 
Responsible-Changed-When: Sun Aug 8 09:50:57 UTC 2010 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=147934 

From: Chip Camden <sterling@camdensoftware.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/147934: [patch] top(1) lies about system uptime
Date: Sat, 7 Aug 2010 21:49:32 -0700

 Verified failing condition, applied patch to 8.1-RELEASE sources,
 verified fixed.
 
 Good to commit.
 
 -- 
 Sterling (Chip) Camden    | sterling@camdensoftware.com | 2048D/3A978E4F
 http://camdensoftware.com | http://chipstips.com        | http://chipsquips.com
State-Changed-From-To: open->patched  
State-Changed-By: brucec 
State-Changed-When: Tue Aug 17 09:53:03 UTC 2010 
State-Changed-Why:  
Fixed in r211419. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=147934 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/147934: commit references a PR
Date: Tue, 17 Aug 2010 09:51:17 +0000 (UTC)

 Author: brucec
 Date: Tue Aug 17 09:51:08 2010
 New Revision: 211419
 URL: http://svn.freebsd.org/changeset/base/211419
 
 Log:
   Since top displays the uptime including seconds, there is no need to add 30
   onto it, which may have been used for rounding purposes in other utilities.
   
   PR:	bin/147934
   Submitted by:	Janne Snabb <snabb at epipe.com>
   Approved by:	rrs (mentor)
   MFC after:	2 weeks
 
 Modified:
   head/contrib/top/display.c
 
 Modified: head/contrib/top/display.c
 ==============================================================================
 --- head/contrib/top/display.c	Tue Aug 17 09:42:50 2010	(r211418)
 +++ head/contrib/top/display.c	Tue Aug 17 09:51:08 2010	(r211419)
 @@ -1273,7 +1273,6 @@ time_t *tod;
  
      if (bt->tv_sec != -1) {
  	uptime = *tod - bt->tv_sec;
 -	uptime += 30;
  	days = uptime / 86400;
  	uptime %= 86400;
  	hrs = uptime / 3600;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/147934: commit references a PR
Date: Sat, 11 Sep 2010 14:26:24 +0000 (UTC)

 Author: brucec
 Date: Sat Sep 11 14:26:18 2010
 New Revision: 212470
 URL: http://svn.freebsd.org/changeset/base/212470
 
 Log:
   MFC r211419:
   
   Since top displays the uptime including seconds, there is no need to add 30
   onto it, which may have been used for rounding purposes in other utilities.
   
   PR:		bin/147934
   Submitted by:	Janne Snabb <snabb at epipe.com>
   Approved by:	rrs (mentor)
 
 Modified:
   stable/8/contrib/top/display.c
 Directory Properties:
   stable/8/contrib/top/   (props changed)
   stable/8/contrib/top/install-sh   (props changed)
 
 Modified: stable/8/contrib/top/display.c
 ==============================================================================
 --- stable/8/contrib/top/display.c	Sat Sep 11 14:21:02 2010	(r212469)
 +++ stable/8/contrib/top/display.c	Sat Sep 11 14:26:18 2010	(r212470)
 @@ -1273,7 +1273,6 @@ time_t *tod;
  
      if (bt->tv_sec != -1) {
  	uptime = *tod - bt->tv_sec;
 -	uptime += 30;
  	days = uptime / 86400;
  	uptime %= 86400;
  	hrs = uptime / 3600;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/147934: commit references a PR
Date: Sat, 11 Sep 2010 14:29:36 +0000 (UTC)

 Author: brucec
 Date: Sat Sep 11 14:29:31 2010
 New Revision: 212471
 URL: http://svn.freebsd.org/changeset/base/212471
 
 Log:
   MFC r211419:
   
   Since top displays the uptime including seconds, there is no need to add 30
   onto it, which may have been used for rounding purposes in other utilities.
   
   PR:		bin/147934
   Submitted by:	Janne Snabb <snabb at epipe.com>
   Approved by:	rrs (mentor)
 
 Modified:
   stable/7/contrib/top/display.c
 Directory Properties:
   stable/7/contrib/top/   (props changed)
 
 Modified: stable/7/contrib/top/display.c
 ==============================================================================
 --- stable/7/contrib/top/display.c	Sat Sep 11 14:26:18 2010	(r212470)
 +++ stable/7/contrib/top/display.c	Sat Sep 11 14:29:31 2010	(r212471)
 @@ -1273,7 +1273,6 @@ time_t *tod;
  
      if (bt->tv_sec != -1) {
  	uptime = *tod - bt->tv_sec;
 -	uptime += 30;
  	days = uptime / 86400;
  	uptime %= 86400;
  	hrs = uptime / 3600;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed  
State-Changed-By: brucec 
State-Changed-When: Sat Sep 11 14:47:08 UTC 2010 
State-Changed-Why:  
Merged to stable/7 and stable/8. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=147934 
>Unformatted:
