Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hostinfo_unix: Ignore tty(S|ACM) devices in TTY idle time calculation #4126

Merged
merged 1 commit into from
Feb 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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