diff --git a/client/hostinfo_unix.C b/client/hostinfo_unix.C
index 61f0e17..0bd674a 100644
a
|
b
|
inline bool user_idle(time_t t, struct utmp* u) { |
1036 | 1036 | |
1037 | 1037 | #else // ! __APPLE__ |
1038 | 1038 | |
| 1039 | // |
| 1040 | // |
| 1041 | bool interrupts_idle(time_t t) { |
| 1042 | static FILE *ifp = NULL; |
| 1043 | static long irq_count[256]; |
| 1044 | static time_t last_irq = time(NULL); |
| 1045 | |
| 1046 | char line[256]; |
| 1047 | int i = 0; |
| 1048 | long ccount = 0; |
| 1049 | |
| 1050 | if (ifp == NULL) { |
| 1051 | if ((ifp = fopen("/proc/interrupts", "r")) == NULL) { |
| 1052 | return true; |
| 1053 | } |
| 1054 | } |
| 1055 | rewind(ifp); |
| 1056 | while (fgets(line, sizeof(line), ifp)) { |
| 1057 | // Check for mouse, keyboard and PS/2 devices. |
| 1058 | if (strcasestr(line, "mouse") != NULL || |
| 1059 | strcasestr(line, "keyboard") != NULL || |
| 1060 | strcasestr(line, "i8042") != NULL) { |
| 1061 | // If any IRQ count changed, update last_irq. |
| 1062 | if (sscanf(line, "%d: %ld", &i, &ccount) == 2 && |
| 1063 | irq_count[i] != ccount) { |
| 1064 | last_irq = time(NULL); |
| 1065 | irq_count[i] = ccount; |
| 1066 | } |
| 1067 | } |
| 1068 | } |
| 1069 | return last_irq < t; |
| 1070 | } |
| 1071 | |
1039 | 1072 | bool HOST_INFO::users_idle(bool check_all_logins, double idle_time_to_run) { |
1040 | 1073 | time_t idle_time = time(0) - (long) (60 * idle_time_to_run); |
1041 | 1074 | |
… |
… |
bool HOST_INFO::users_idle(bool check_all_logins, double idle_time_to_run) { |
1054 | 1087 | if (!device_idle(idle_time, "/dev/input/mice")) return false; |
1055 | 1088 | if (!device_idle(idle_time, "/dev/kbd")) return false; |
1056 | 1089 | // solaris |
| 1090 | |
| 1091 | // Check /proc/interrupts to detect keyboard or mouse activity. |
| 1092 | if (!interrupts_idle(idle_time)) return false; |
1057 | 1093 | return true; |
1058 | 1094 | } |
1059 | 1095 | |