If stat() on the terminal specified in utmp fails due to ENOENT, don't
print a warning, and set the idletime variable for the entry to -1; then pick up the -1 later in sprint() and lprint() and ignore those idle times by printing just whitespace. When third party applications, such as kdm, insert utmp entries, they sometimes use strings like ":0", which can't be stat()'d and currently result in warnings that are not helpful to the user.
This commit is contained in:
parent
7d92e4785f
commit
021eeb2020
@ -189,7 +189,8 @@ lprint(PERSON *pn)
|
||||
* idle time. Follow with a comma if a remote login.
|
||||
*/
|
||||
delta = gmtime(&w->idletime);
|
||||
if (delta->tm_yday || delta->tm_hour || delta->tm_min) {
|
||||
if (w->idletime != -1 && (delta->tm_yday ||
|
||||
delta->tm_hour || delta->tm_min)) {
|
||||
cpr += printf("%-*s idle ",
|
||||
maxlen - (int)strlen(w->tty) + 1, ",");
|
||||
if (delta->tm_yday > 0) {
|
||||
|
@ -167,6 +167,11 @@ stimeprint(WHERE *w)
|
||||
{
|
||||
struct tm *delta;
|
||||
|
||||
if (w->idletime == -1) {
|
||||
(void)printf(" ");
|
||||
return;
|
||||
}
|
||||
|
||||
delta = gmtime(&w->idletime);
|
||||
if (!delta->tm_yday)
|
||||
if (!delta->tm_hour)
|
||||
|
@ -314,10 +314,23 @@ find_idle_and_ttywrite(WHERE *w)
|
||||
{
|
||||
struct stat sb;
|
||||
time_t touched;
|
||||
int error;
|
||||
|
||||
(void)snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_DEV, w->tty);
|
||||
if (stat(tbuf, &sb) < 0) {
|
||||
|
||||
error = stat(tbuf, &sb);
|
||||
if (error < 0 && errno == ENOENT) {
|
||||
/*
|
||||
* The terminal listed is not actually a terminal (i.e.,
|
||||
* ":0"). This is a failure, so we'll skip printing
|
||||
* out the idle time, which is non-ideal but better
|
||||
* than a bogus warning and idle time.
|
||||
*/
|
||||
w->idletime = -1;
|
||||
return;
|
||||
} else if (error < 0) {
|
||||
warn("%s", tbuf);
|
||||
w->idletime = -1;
|
||||
return;
|
||||
}
|
||||
touched = sb.st_atime;
|
||||
|
Loading…
Reference in New Issue
Block a user