[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#714477: killer: Is no longer able to figure out when X users last were active



Control: tags -1 + patch

Here is a fairly untested patch to solve this issue.  I lack the test
bench to test it right now.  It should use xprintidle as reported by the
user when running from the users home directory to detect X usage, and
use the resulting value in calculating which processes to kill.

diff --git a/debian/control b/debian/control
index b8d4997..e644488 100644
--- a/debian/control
+++ b/debian/control
@@ -13,7 +13,11 @@ Vcs-Browser:
http://anonscm.debian.org/gitweb/?p=debian-edu/pkg-team/killer.git
 
 Package: killer
 Architecture: all
-Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends}, exim4 |
 mail-transport-agent
+Depends: ${shlibs:Depends}
+ , ${misc:Depends}
+ , ${perl:Depends}
+ , exim4 | mail-transport-agent
+ , xprintidle
 Description: Background job killer
  killer is a perl script that gets rid of background jobs. Background
  jobs are defined as processes that belong to users who are not
 currently
diff --git a/killer b/killer
index 1f95f2e..f915974 100755
--- a/killer
+++ b/killer
@@ -927,6 +927,24 @@ sub initializeTty($@) {
 
 }
 
+=head2 getX11IdleTime
+
+Figure out how long a user has been idle in X11.  Return the seconds
+of idle time.
+
+=cut
+
+sub getX11IdleTime($) {
+    my $self = shift;
+    my ( $user ) = @_;
+    $idletime_ms = `su $user -c 'DISPLAY=:0 xprintidle' 2>/dev/null`;
+    if ($idletime_ms ~= m/\d+/) {
+        return $idletime_ms / 1000;
+    } else {
+        return undef;
+    }
+}
+
 =head2 getIdleTime user
 
 Figure out how long a user has been idle.  This is accomplished by
@@ -971,6 +989,10 @@ sub getIdleTime($) {
                 $idletime = (time - $statparts[8]);
             }
         }
+        my $xIdleTime = $self->getX11IdleTime($user);
+        if (defined $xIdleTime && $idleTime > $xIdleTime) {
+            $idletime = $xIdleTime;
+        }
     }
     return $idletime;
 }

-- 
Happy hacking
Petter Reinholdtsen


Reply to: