Subject: bin/4880: rup is wrong for uptimes over a year
To: None <gnats-bugs@gnats.netbsd.org>
From: Eric Fischer <eric@fudge.uchicago.edu>
List: netbsd-bugs
Date: 01/23/1998 14:54:49
>Number:         4880
>Category:       bin
>Synopsis:       rup gets uptimes over a year wrong
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jan 23 13:05:00 1998
>Last-Modified:
>Originator:     Eric Fischer
>Organization:
The University of Chicago
>Release:        1.2
>Environment:
	
System: NetBSD fudge 1.2 NetBSD 1.2 (FUDGE) #7: Sun Jan 19 16:26:56 CST 1997 eric@fudge:/usr/people/eric/usrsrc/sys/arch/sparc/compile/FUDGE sparc


>Description:

The uptimes given by rup are modulo one year.

>How-To-Repeat:

ars1# uptime
  2:51pm  up 405 days,  3:39,  1 user,  load average: 0.06, 0.18, 0.00

$ rup ars1
ars1                     up  40 days,   3:39,  load average: 0.06 0.18 0.00

>Fix:

Don't assume gmtime() is going to give you a reasonable printed
representation of a time difference when the times are more than
a year apart.

diff -rc ../../../src/usr.bin/rup/rup.c ./rup.c
*** ../../../src/usr.bin/rup/rup.c	Sat Feb  5 08:58:14 1994
--- ./rup.c	Fri Jan 23 14:48:51 1998
***************
*** 189,194 ****
--- 189,195 ----
  	struct tm host_uptime;
  	char days_buf[16];
  	char hours_buf[16];
+ 	int updays;
  
  	printf("%-*.*s", HOST_WIDTH, HOST_WIDTH, host);
  
***************
*** 197,208 ****
  
  	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 (host_uptime.tm_yday != 0)
! 		sprintf(days_buf, "%3d day%s, ", host_uptime.tm_yday,
! 			(host_uptime.tm_yday > 1) ? "s" : "");
  	else
  		days_buf[0] = '\0';
  
--- 198,216 ----
  
  	host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
  
+ 	/*
+ 	 * given enough leap seconds, this will be wrong, but
+ 	 * it's a lot closer to being right than just looking
+ 	 * at the day of the year.
+ 	 */
+ 	updays = host_stat->curtime.tv_sec / 60 / 60 / 24;
+ 
  	tmp_time = gmtime((time_t *)&host_stat->curtime.tv_sec);
  	host_uptime = *tmp_time;
  
! 	if (updays != 0)
! 		sprintf(days_buf, "%3d day%s, ", updays,
! 			(updays > 1) ? "s" : "");
  	else
  		days_buf[0] = '\0';
  
Only in .: rup.cat1
Only in .: rup.diffs
Only in .: rup.o
>Audit-Trail:
>Unformatted: