Control: tags -1 + patch pending

I've implemented what I believe is a fix for this.  It currently
detect an unused KDM session, and assume the machine is busy if it
fail to detect the kdm login screen.  It should be extended to detect
a unused lightdm and gdm session.

Here is the patch, already commited in my local git repositry but not
pushed to alioth as alioth is still down because of disk failure.

Please test it.  Also, let me know what the xlsclients output from
lightdm and gdm is, to extend it to those environments too.

A similar fix should be added to the killer package too, but it
probably would have to use the xprintidle function instead of
xlsclients.

diff --git a/debian/changelog b/debian/changelog
index b653c23..d3572b5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,5 +1,6 @@
 shutdown-at-night (0.13) UNRELEASED; urgency=low
 
+  [ Mike Gabriel ]
   * Package becomes team-maintained: Debian Edu Packaging Team.
   * debian/control:
     + Package migrated to Git. Update Vcs-*: fields and point to
@@ -9,6 +10,12 @@ shutdown-at-night (0.13) UNRELEASED; urgency=low
   * debian/source/format:
     + Add file. Use format 1.0 to match capabilities of Debian Edu's dak.
 
+  [ Petter Reinholdtsen ]
+  * Rewrite logic checking if a host is unused to look for the KDM login
+    screen to confirm the X sessions are unused (Closes: #729553).
+  * Add depend on x11-utils for the xlsclients tool used to check unused
+    X sessions.
+
  -- Mike Gabriel <[email protected]>  Wed, 23 Oct 2013 11:39:21 +0200
 
 shutdown-at-night (0.12) unstable; urgency=low
diff --git a/debian/control b/debian/control
index eabf899..8fd4532 100644
--- a/debian/control
+++ b/debian/control
@@ -13,7 +13,7 @@ Vcs-Browser: 
http://anonscm.debian.org/gitweb/?p=debian-edu/pkg-team/shutdown-at
 Package: shutdown-at-night
 Architecture: all
 Depends: ${misc:Depends}, ${perl:Depends},  cron | fcron,
- wakeonlan, ng-utils, fping, ethtool
+ wakeonlan, ng-utils, fping, ethtool, x11-utils
 Recommends: nvram-wakeup
 Suggests: sitesummary (>= 0.0.41)
 Description: System to shut down clients at night, and wake them in the morning
diff --git a/shutdown-at-night b/shutdown-at-night
index 652564d..d1208c8 100755
--- a/shutdown-at-night
+++ b/shutdown-at-night
@@ -96,9 +96,43 @@ prepare_wakeonlan() {
     ethtool -s $interface wol g
 }
 
+# Return true if local user is logged in, false otherwise
+is_local_user() {
+    if [ "$(who)" ] ; then
+       return 0
+    else
+       return 1
+    fi
+}
+
+# Return true if ldm login is active
+is_active_ldm_session() {
+    if ps -efwww | egrep -q ' ssh .*LTSP_CLIEN[T]' ; then
+       return 0
+    else
+       return 1
+    fi
+}
+
+# Return false if X session is confirmed unused (ie login screen is
+# shown).  If not sure, claim it is used to be safe.
+is_xsession_used() {
+    for s in \
+       /var/run/gdm3/auth-for-Debian-gdm-*/database \
+       /var/run/xauth/* \
+       /run/xauth/*; do
+       if [ -e "$s" ] ; then
+           if XAUTHORITY="$s" DISPLAY=:0 xlsclients | egrep -q 'kdmgreet' ; 
then
+               return 1
+           fi
+       fi
+    done
+    return 0
+}
+
 is_host_unused() {
     # Logged in users, or ldm connection to a remote server
-    if [ "$(who)" ] ||  ps -efwww | egrep -q ' ssh .*LTSP_CLIEN[T]' ; then
+    if is_xsession_used || is_local_user || is_active_ldm_session; then
        return 1
     fi
     # Uptime is less than one hour
@@ -137,4 +171,3 @@ if enabled_for_host ; then
 else
     logger -t shutdown-at-night "shutdown-at-night is not enabled for client 
$hostname."
 fi
-

-- 
Happy hacking
Petter Reinholdtsen


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to