Skip to content

Commit

Permalink
hostinfo_unix: Ignore tty(S|ACM) devices in TTY idle time calculation
Browse files Browse the repository at this point in the history
The atime (access time) of device nodes whose name starts with
/dev/ttyS (serial port) or /dev/ttyACM (serial USB) should not be used
for TTY idle time calculation. It is perfectly possible that they are
used without any user being active.
  • Loading branch information
Flowdalic committed Jan 15, 2021
1 parent 57fa9d5 commit ed70369
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion client/hostinfo_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1567,9 +1567,19 @@ inline long device_idle_time(const char *device) {
static const struct dir_tty_dev {
const char *dir;
const char *dev;
const vector<string> ignore_list;

bool should_ignore(const string &devname) const {
for (const string &ignore : ignore_list) {
if (devname.rfind(ignore, 0) == 0) return true;
}
return false;
}
} tty_patterns[] = {
#ifdef unix
{ "/dev", "tty" },
{ "/dev", "tty",
{"ttyS", "ttyACM"},
},
{ "/dev", "pty" },
{ "/dev/pts", NULL },
#endif
Expand All @@ -1596,6 +1606,11 @@ vector<string> get_tty_list() {
//
if (tty_patterns[i].dev) {
if ((strstr(devname, tty_patterns[i].dev) != devname)) continue;

// Ignore some devices. This could be, for example,
// ttyS* (serial port) or devACM* (serial USB) devices
// which may be used even without a user being active.
if (tty_patterns[i].should_ignore(devname)) continue;
}

sprintf(fullname, "%s/%s", tty_patterns[i].dir, devname);
Expand Down

0 comments on commit ed70369

Please sign in to comment.