Ticket #463: interrupts_idle.patch

File interrupts_idle.patch, 1.7 KB (added by fthomas, 16 years ago)

Patch to integrate interrupts_idle() into client/hostinfo_unix.C.

  • client/hostinfo_unix.C

    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) { 
    10361036
    10371037#else  // ! __APPLE__
    10381038
     1039//
     1040//
     1041bool 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
    10391072bool HOST_INFO::users_idle(bool check_all_logins, double idle_time_to_run) {
    10401073    time_t idle_time = time(0) - (long) (60 * idle_time_to_run);
    10411074
    bool HOST_INFO::users_idle(bool check_all_logins, double idle_time_to_run) { 
    10541087    if (!device_idle(idle_time, "/dev/input/mice")) return false;
    10551088    if (!device_idle(idle_time, "/dev/kbd")) return false;
    10561089        // solaris
     1090
     1091    // Check /proc/interrupts to detect keyboard or mouse activity.
     1092    if (!interrupts_idle(idle_time)) return false;
    10571093    return true;
    10581094}
    10591095