From ed70369c091923addf5a8d64bed92c0417e91e07 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 12 Dec 2020 17:25:06 +0100 Subject: [PATCH] hostinfo_unix: Ignore tty(S|ACM) devices in TTY idle time calculation 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. --- client/hostinfo_unix.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/client/hostinfo_unix.cpp b/client/hostinfo_unix.cpp index 2cf9af3a18c..9b51574d98f 100644 --- a/client/hostinfo_unix.cpp +++ b/client/hostinfo_unix.cpp @@ -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 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 @@ -1596,6 +1606,11 @@ vector 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);