From root@site.uottawa.ca  Thu Nov 10 13:53:32 2005
Return-Path: <root@site.uottawa.ca>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 30FDE16A41F
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 10 Nov 2005 13:53:32 +0000 (GMT)
	(envelope-from root@site.uottawa.ca)
Received: from mail.site.uottawa.ca (mail.site.uottawa.ca [137.122.89.142])
	by mx1.FreeBSD.org (Postfix) with ESMTP id B45D643D45
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 10 Nov 2005 13:53:31 +0000 (GMT)
	(envelope-from root@site.uottawa.ca)
Received: from grdsav.site.uottawa.ca (grdsav.site.uottawa.ca [137.122.90.179])
	by mail.site.uottawa.ca (8.9.3/8.9.3) with ESMTP id IAA61031
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 10 Nov 2005 08:53:29 -0500 (EST)
Received: (from root@localhost)
	by grdsav.site.uottawa.ca (8.13.4/8.13.4/Submit) id jAADrUU1013725;
	Thu, 10 Nov 2005 08:53:30 -0500 (EST)
	(envelope-from root)
Message-Id: <200511101353.jAADrUU1013725@grdsav.site.uottawa.ca>
Date: Thu, 10 Nov 2005 08:53:30 -0500 (EST)
From: Keith White <Keith.White@site.uottawa.ca>
Reply-To: Keith White <Keith.White@site.uottawa.ca>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] bin/rup displays incorrect date and uptime on sparc64 platform
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         88788
>Category:       bin
>Synopsis:       [patch] rup(1) displays incorrect date and uptime on sparc64 platform
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    philip
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 10 14:00:24 GMT 2005
>Closed-Date:    Sun Dec 04 18:26:56 GMT 2005
>Last-Modified:  Sun Dec 04 18:26:56 GMT 2005
>Originator:     Keith White
>Release:        6.0-RELEASE sparc64
>Organization:
SITE, University of Ottawa
>Environment:
System: FreeBSD grdsav.site.uottawa.ca 6.0-RELEASE FreeBSD 6.0-RELEASE #1: Wed Nov  9 10:27:29 EST 2005     root@grdsav.site.uottawa.ca:/usr/obj/usr/src/sys/ULTRA5  sparc64


	
>Description:
"rup" displays incorrect date and uptime when run on the sparc64 platform
(and presumably on other 64-bit time_t platforms).

The RPC rstat network packet uses 32-bit time_t.  src/usr.bin/rup.c
uses gmtime() and localtime() to decode the time_t values.  On the
sparc64 platform these functions expect a 64-bit time_t so the
returned values displayed by rup are incorrect.

>How-To-Repeat:

$ uname -rp
6.0-RELEASE sparc64
$ rup
a.site.uottawa.   2:43pm  up   0 day, 54 mins,  load average: 0.00 0.09 0.16
b.site.uottawa.   5:03am  up  41 days,   2:37,  load average: 0.01 0.01 0.02
c.site.uottawa.  11:30pm  up 117 days,  15:01,  load average: 0.00 0.00 0.00
d.site.uottawa.   9:28pm  up 237 days,  20:41,  load average: 0.00 0.00 0.01
e.site.uottawa.  10:51am  up  18 days,  20:52,  load average: 0.02 0.01 0.02
f.site.uottawa.   8:11pm  up 238 days,   8:43,  load average: 0.90 0.41 0.12
g.site.uottawa.   1:21am  up  21 days,   6:45,  load average: 0.01 0.01 0.02
h.site.uottawa.  10:26pm  up 274 days,  17:18,  load average: 0.00 0.00 0.00
i.site.uottawa.   4:45am  up  37 days,39 mins,  load average: 0.02 0.00 0.00

	
>Fix:

The following patch fixes the problem on sparc64 platforms.
Tested on both sparc64 (6.0-RELEASE) and i386 (6.0-RELEASE).

--- rup.patch begins here ---
--- src/usr.bin/rup/rup.c.orig	Sat May 21 05:55:07 2005
+++ src/usr.bin/rup/rup.c	Wed Nov  9 14:16:37 2005
@@ -101,6 +101,7 @@
 	struct hostent *hp;
 	char *host;
 	statstime *host_stat = (statstime *)replyp;
+	time_t tmp_time_t;
 
 	if (search_host(raddrp->sin_addr))
 		return(0);
@@ -118,13 +119,26 @@
 
 	printf("%-*s\t", HOST_WIDTH, host);
 
-	tmp_time = localtime((time_t *)&host_stat->curtime.tv_sec);
-	host_time = *tmp_time;
-
-	host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
-
-	tmp_time = gmtime((time_t *)&host_stat->curtime.tv_sec);
-	host_uptime = *tmp_time;
+	if (sizeof(time_t) == sizeof(host_stat->curtime.tv_sec)) {
+		tmp_time = localtime((time_t *)&host_stat->curtime.tv_sec);
+		host_time = *tmp_time;
+
+		host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
+
+		tmp_time = gmtime((time_t *)&host_stat->curtime.tv_sec);
+		host_uptime = *tmp_time;
+	}
+	else {			/* non-32-bit time_t */
+		tmp_time_t = host_stat->curtime.tv_sec;
+		tmp_time = localtime(&tmp_time_t);
+		host_time = *tmp_time;
+
+		host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
+
+		tmp_time_t = host_stat->curtime.tv_sec;
+		tmp_time = gmtime(&tmp_time_t);
+		host_uptime = *tmp_time;
+	}
 
 	#define updays (host_stat->curtime.tv_sec  / 86400)
 	if (host_uptime.tm_yday != 0)
--- rup.patch ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->philip 
Responsible-Changed-By: philip 
Responsible-Changed-When: Sun Dec 4 18:25:55 GMT 2005 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=88788 
State-Changed-From-To: open->closed 
State-Changed-By: philip 
State-Changed-When: Sun Dec 4 18:26:55 GMT 2005 
State-Changed-Why:  
Committed. Thanks! 

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