bin/88788: [patch] bin/rup displays incorrect date and uptime on sparc64 platform

Keith White Keith.White at site.uottawa.ca
Thu Nov 10 06:00:43 PST 2005


>Number:         88788
>Category:       bin
>Synopsis:       [patch] bin/rup displays incorrect date and uptime on sparc64 platform
>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 Nov 10 14:00:24 GMT 2005
>Closed-Date:
>Last-Modified:
>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 at 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:
>Unformatted:


More information about the freebsd-bugs mailing list