Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Jun 2010 09:38:53 GMT
From:      Janne Snabb <snabb@epipe.com>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/147934: [patch] top(1) lies about system uptime
Message-ID:  <201006170938.o5H9crpt079616@tiktik.epipe.com>
Resent-Message-ID: <201006170940.o5H9e3i1023672@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         147934
>Category:       bin
>Synopsis:       [patch] top(1) lies about system uptime
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 17 09:40:03 UTC 2010
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006170938.o5H9crpt079616>