From owner-freebsd-bugs@FreeBSD.ORG Thu Jun 17 09:40:04 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 49B08106567A for ; Thu, 17 Jun 2010 09:40:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 0BEA48FC22 for ; Thu, 17 Jun 2010 09:40:04 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o5H9e3lc023673 for ; Thu, 17 Jun 2010 09:40:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o5H9e3i1023672; Thu, 17 Jun 2010 09:40:03 GMT (envelope-from gnats) Resent-Date: Thu, 17 Jun 2010 09:40:03 GMT Resent-Message-Id: <201006170940.o5H9e3i1023672@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Janne Snabb Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AADAA1065673 for ; 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 ; 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 ; 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 To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/147934: [patch] top(1) lies about system uptime X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Janne Snabb List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jun 2010 09:40:04 -0000 >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 >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: