If the utmp login time is greater than the tty atime, use it to calculate
the idle time instead of the atime. This makes entries for people that have logged in but done nothing else show up correctly. Reviewed by: markk@knigma.org
This commit is contained in:
parent
d9f8912333
commit
3bebe99135
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=70242
@ -323,13 +323,19 @@ find_idle_and_ttywrite(w)
|
||||
{
|
||||
extern time_t now;
|
||||
struct stat sb;
|
||||
time_t touched;
|
||||
|
||||
(void)snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_DEV, w->tty);
|
||||
if (stat(tbuf, &sb) < 0) {
|
||||
warn("%s", tbuf);
|
||||
return;
|
||||
}
|
||||
w->idletime = now < sb.st_atime ? 0 : now - sb.st_atime;
|
||||
touched = sb.st_atime;
|
||||
if (touched < w->loginat) {
|
||||
/* tty untouched since before login */
|
||||
touched = w->loginat;
|
||||
}
|
||||
w->idletime = now < touched ? 0 : now - touched;
|
||||
|
||||
#define TALKABLE 0220 /* tty is writable if 220 mode */
|
||||
w->writable = ((sb.st_mode & TALKABLE) == TALKABLE);
|
||||
|
@ -134,6 +134,7 @@ main(argc, argv)
|
||||
struct stat *stp;
|
||||
FILE *ut;
|
||||
u_long l;
|
||||
time_t touched;
|
||||
int ch, i, nentries, nusers, wcmd, longidle, dropgid;
|
||||
char *memf, *nlistf, *p, *x;
|
||||
char buf[MAXHOSTNAMELEN], errbuf[256];
|
||||
@ -246,7 +247,12 @@ main(argc, argv)
|
||||
(void)sysctl(mib, 2, &ep->tdev, &size, NULL, 0);
|
||||
}
|
||||
#endif
|
||||
if ((ep->idle = now - stp->st_atime) < 0)
|
||||
touched = stp->st_atime;
|
||||
if (touched < ep->utmp.ut_time) {
|
||||
/* tty untouched since before login */
|
||||
touched = ep->utmp.ut_time;
|
||||
}
|
||||
if ((ep->idle = now - touched) < 0)
|
||||
ep->idle = 0;
|
||||
}
|
||||
(void)fclose(ut);
|
||||
|
Loading…
Reference in New Issue
Block a user