Subject: bin/2889: /usr/bin/w displays incorrect login time
To: None <gnats-bugs@gnats.netbsd.org>
From: Dave Huang <khym@bga.com>
List: netbsd-bugs
Date: 10/23/1996 20:00:13
>Number: 2889
>Category: bin
>Synopsis: /usr/bin/w displays incorrect login time
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: bin-bug-people (Utility Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Oct 23 18:05:00 1996
>Last-Modified:
>Originator: Dave Huang
>Organization:
Name: Dave Huang | Mammal, mammal / their names are called /
INet: khym@bga.com | they raise a paw / the bat, the cat /
FurryMUCK: Dahan | dolphin and dog / koala bear and hog -- TMBG
Dahan: Hani G Y+C 20 Y++ L+++ W- C++ T++ A+ E+ S++ V++ F- Q+++ P+ B+ PA+ PL++
>Release: October 22, 1996
>Environment:
System: NetBSD host4.alterity.com 1.2A NetBSD 1.2A (SPIFF) #53: Fri Oct 18 11:25:44 CDT 1996 khym@dahan.metonymy.com:/usr/src/sys/arch/i386/compile/SPIFF i386
>Description:
The w program always shows the current time in the LOGIN@ column. This
is because the pr_attime() function in pr_time.c calls localtime()
twice, assuming it'll get a different value each time. However,
localtime() returns a pointer to the same static buffer each time, and
each call overwrites the result of the previous call.
>How-To-Repeat:
Run /usr/bin/w and see that the LOGIN@ time is always the current
time.
>Fix:
--- /usr/src/usr.bin/w/pr_time.c Mon Oct 14 11:59:08 1996
+++ /usr/src.local/usr.bin/w/pr_time.c Wed Oct 23 19:48:49 1996
@@ -62,12 +62,14 @@
time_t *started, *now;
{
static char buf[256];
- struct tm *tp, *tpnow;
+ struct tm *tp;
time_t diff;
char fmt[20];
+ int yday_now;
+ tp = localtime(now);
+ yday_now = tp->tm_yday;
tp = localtime(started);
- tpnow = localtime(now);
diff = *now - *started;
/* If more than a week, use day-month-year. */
@@ -75,7 +77,7 @@
(void)strcpy(fmt, "%d%b%y");
/* If not today, use day-hour-am/pm. */
- else if (tp->tm_yday != tpnow->tm_yday) {
+ else if (tp->tm_yday != yday_now) {
(void)strcpy(fmt, __CONCAT("%a%", "I%p"));
}
>Audit-Trail:
>Unformatted: