Path: ccsf.homeunix.org!ccsf.homeunix.org!news1.wakwak.com!nf2.xephion.ne.jp!nf1.xephion.ne.jp!onion.ish.org!news.daionet.gr.jp!news.yamada.gr.jp!news.media.kyoto-u.ac.jp!nide
From: nide@ics.nara-wu.ac.jp (NIDE Naoyuki)
Newsgroups: fj.os.linux
Subject: Re: w command shows odd idle time
Date: Fri, 17 Sep 2004 11:24:00 GMT
Organization: Public NNTP Service, Kyoto University, JAPAN
Lines: 92
Message-ID: <040917202400.M0230587@asakaze.ics.nara-wu.ac.jp>
References: <040913222111.M0109018@azusa.ics.nara-wu.ac.jp>
NNTP-Posting-Host: asakaze.ics.nara-wu.ac.jp
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit
X-Trace: caraway.media.kyoto-u.ac.jp 1095420240 10399 160.11.185.12 (17 Sep 2004 11:24:00 GMT)
X-Complaints-To: news@news.media.kyoto-u.ac.jp
NNTP-Posting-Date: Fri, 17 Sep 2004 11:24:00 +0000 (UTC)
X-Newsreader: mnews [version 1.22PL7] 2003-09/29(Mon)
Xref: ccsf.homeunix.org fj.os.linux:1547

In article <040913222111.M0109018@azusa.ics.nara-wu.ac.jp>, I write:
>   Debian$B$N(BWoody$B$r;H$C$F$$$k$N$G$9$,!"(Bprocps$B$N(Bw$B%3%^%s%I$,$7$P$7$PJQ$J(B
> IDLE time$B$rI=<($7$^$9!#!D(B

  $BH?1~$,$J$$$H$$$&$3$H$O$&$A$@$1$J$s$G$9$+$M$(!DJL$K%$%s%9%H!<%k;~$K6E$C(B
$B$?:Y9)$H$+$7$F$J$$$N$G!"B>$G$bF1$8$3$H$,5/$-$F$F$bIT;W5D$O$J$$$H;W$C$F$$(B
$B$?$s$G$9$,!#(B
  $B$H$j$"$($:$O$3$N7o$X$N%Q%C%A$r:n$C$F$_$?$N$G=P$7$H$-$^$9!#(BIDLE time$B$r!"(B
$B8=:_;~9o$H(B{tty$B$N(Batime$B$H(Butmp$B$+$iF@$?(Blogin time$B$H$N?7$7$$J}(B}$B$H$N:9$+$iF@$k(B
$B$h$&$KD>$7$F$$$^$9!#(B

  $B$^$:$O(BDebian$B$N(Bwoody$BMQ%Q%C%A(B

------------------------------------------------------------------------
diff -ru procps-2.0.7.orig/w.c procps-2.0.7/w.c
--- procps-2.0.7.orig/w.c	Mon Sep 13 23:46:02 2004
+++ procps-2.0.7/w.c	Mon Sep 13 23:48:45 2004
@@ -90,11 +90,11 @@
 }
 
 /**** stat the device file to get an idle time */
-static time_t idletime(char *tty) {
+static time_t idletime(char *tty, time_t logt) {
     struct stat sbuf;
     if (stat(tty, &sbuf) != 0)
 	return 0;
-    return time(NULL) - sbuf.st_atime;
+    return time(NULL) - (sbuf.st_atime < logt ? logt : sbuf.st_atime);
 }
 
 /***** 7 character formatted login time */
@@ -195,7 +195,7 @@
 	if (*u->ut_line == ':')			/* idle unknown for xdm logins */
 	    printf(" ?xdm? ");
 	else
-	    print_time_ival7(idletime(tty), 0, stdout);
+	    print_time_ival7(idletime(tty, u->ut_time), 0, stdout);
 	print_time_ival7(jcpu/Hertz, (jcpu%Hertz)*(100./Hertz), stdout);
 	if (best) {
 	    int pcpu = best->utime + best->stime;
@@ -209,7 +209,7 @@
 	if (*u->ut_line == ':')			/* idle unknown for xdm logins */
 	    printf(" ?xdm? ");
 	else
-	    print_time_ival7(idletime(tty), 0, stdout);
+	    print_time_ival7(idletime(tty, u->ut_time), 0, stdout);
     }
     fputs("  ", stdout);
     if (best) {
------------------------------------------------------------------------

  $B$=$l$+$i!">e$HK\<AE*$J:9$O$J$$$G$9$,!"(Bprocps$B$N:G?7$N(B3.2.3$B$X$N%Q%C%A$G$9!#(B

------------------------------------------------------------------------
diff -ru procps-3.2.3.orig/w.c procps-3.2.3/w.c
--- procps-3.2.3.orig/w.c	Sat Sep 20 15:42:26 2003
+++ procps-3.2.3/w.c	Tue Sep 14 01:47:01 2004
@@ -86,11 +86,11 @@
 }
 
 /**** stat the device file to get an idle time */
-static time_t idletime(const char *restrict const tty) {
+static time_t idletime(const char *restrict const tty, time_t logt) {
     struct stat sbuf;
     if (stat(tty, &sbuf) != 0)
 	return 0;
-    return time(NULL) - sbuf.st_atime;
+    return time(NULL) - (sbuf.st_atime < logt ? logt : sbuf.st_atime);
 }
 
 /***** 7 character formatted login time */
@@ -199,7 +199,7 @@
 	if (*u->ut_line == ':')			/* idle unknown for xdm logins */
 	    printf(" ?xdm? ");
 	else
-	    print_time_ival7(idletime(tty), 0, stdout);
+	    print_time_ival7(idletime(tty, u->ut_time), 0, stdout);
 	print_time_ival7(jcpu/Hertz, (jcpu%Hertz)*(100./Hertz), stdout);
 	if (best) {
 	    unsigned long long pcpu = best->utime + best->stime;
@@ -213,7 +213,7 @@
 	if (*u->ut_line == ':')			/* idle unknown for xdm logins */
 	    printf(" ?xdm? ");
 	else
-	    print_time_ival7(idletime(tty), 0, stdout);
+	    print_time_ival7(idletime(tty, u->ut_time), 0, stdout);
     }
     fputs(" ", stdout);
     if (likely(best)) {
------------------------------------------------------------------------

						nide@ics.nara-wu.ac.jp
