[gnome-shell] automount: port from CK to systemd-logind



commit e8498adaf19e281c88f2116eb398a6135712fed5
Author: Lennart Poettering <lennart poettering net>
Date:   Sat Feb 11 04:51:42 2012 +0100

    automount: port from CK to systemd-logind
    
    ConsoleKit is being obsoleted by systemd. Accordingly port the CK logic
    in the gnome-shell automount manager to systemd-logind APIs.
    
    This makes use of systemd-logind's native C APIs which are much easier
    to use than the D-Bus APIs in this case, and much faster too (since they
    are synchronous and directly query the kernel for the information we
    need). The dependency is compile time optional, and in order to be nice
    to the Debian folks g-s compiled with this enabled fill automatically
    fall back to CK support on systems lacking systemd.

 configure.ac              |   27 +++++++++++++++++++++++++++
 js/ui/automountManager.js |   32 +++++++++++++++++++++++++-------
 src/Makefile.am           |    2 ++
 src/shell-util.c          |   28 ++++++++++++++++++++++++++++
 src/shell-util.h          |    2 ++
 5 files changed, 84 insertions(+), 7 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4da64d2..272dbf2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -141,6 +141,33 @@ PKG_CHECK_MODULES(CALENDAR_SERVER, libecal-1.2 >= $LIBECAL_MIN_VERSION libedatas
 AC_SUBST(CALENDAR_SERVER_CFLAGS)
 AC_SUBST(CALENDAR_SERVER_LIBS)
 
+AC_ARG_WITH(systemd,
+            AS_HELP_STRING([--with-systemd],
+                           [Add systemd support]),
+            [with_systemd=$withval], [with_systemd=auto])
+
+PKG_CHECK_MODULES(SYSTEMD,
+                  [libsystemd-login libsystemd-daemon],
+                  [have_systemd=yes], [have_systemd=no])
+
+if test "x$with_systemd" = "xauto" ; then
+        if test x$have_systemd = xno ; then
+                use_systemd=no
+        else
+                use_systemd=yes
+        fi
+else
+        use_systemd=$with_systemd
+fi
+
+if test "x$use_systemd" = "xyes"; then
+        if test "x$have_systemd" = "xno"; then
+                AC_MSG_ERROR([Systemd support explicitly required, but systemd not found])
+        fi
+
+        AC_DEFINE(WITH_SYSTEMD, 1, [systemd support])
+fi
+
 MUTTER_GIR_DIR=`$PKG_CONFIG --variable=girdir libmutter`
 MUTTER_TYPELIB_DIR=`$PKG_CONFIG --variable=typelibdir libmutter`
 AC_SUBST(MUTTER_GIR_DIR)
diff --git a/js/ui/automountManager.js b/js/ui/automountManager.js
index 9686020..e25276d 100644
--- a/js/ui/automountManager.js
+++ b/js/ui/automountManager.js
@@ -2,9 +2,11 @@
 
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
+const GLib = imports.gi.GLib;
 const Gio = imports.gi.Gio;
 const Params = imports.misc.params;
 
+const Shell = imports.gi.Shell;
 const Main = imports.ui.main;
 const ShellMountOperation = imports.ui.shellMountOperation;
 const ScreenSaver = imports.misc.screenSaver;
@@ -67,6 +69,10 @@ function ConsoleKitManager() {
     return self;
 }
 
+function haveSystemd() {
+    return GLib.access("/sys/fs/cgroup/systemd", 0) >= 0;
+}
+
 const AutomountManager = new Lang.Class({
     Name: 'AutomountManager',
 
@@ -74,7 +80,8 @@ const AutomountManager = new Lang.Class({
         this._settings = new Gio.Settings({ schema: SETTINGS_SCHEMA });
         this._volumeQueue = [];
 
-        this.ckListener = new ConsoleKitManager();
+        if (!haveSystemd())
+            this.ckListener = new ConsoleKitManager();
 
         this._ssProxy = new ScreenSaver.ScreenSaverProxy();
         this._ssProxy.connectSignal('ActiveChanged',
@@ -122,11 +129,22 @@ const AutomountManager = new Lang.Class({
         return false;
     },
 
+    _sessionActive: function() {
+        // Return whether the current session is active, using the
+        // right mechanism: either systemd if available or ConsoleKit
+        // as fallback.
+
+        if (haveSystemd())
+            return Shell.session_is_active_for_systemd();
+
+        return this.ckListener.sessionActive;
+    },
+
     _onDriveConnected: function() {
         // if we're not in the current ConsoleKit session,
         // or screensaver is active, don't play sounds
-        if (!this.ckListener.sessionActive)
-            return;        
+        if (!this._sessionActive())
+            return;
 
         if (this._ssProxy.screenSaverActive)
             return;
@@ -137,8 +155,8 @@ const AutomountManager = new Lang.Class({
     _onDriveDisconnected: function() {
         // if we're not in the current ConsoleKit session,
         // or screensaver is active, don't play sounds
-        if (!this.ckListener.sessionActive)
-            return;        
+        if (!this._sessionActive())
+            return;
 
         if (this._ssProxy.screenSaverActive)
             return;
@@ -149,7 +167,7 @@ const AutomountManager = new Lang.Class({
     _onDriveEjectButton: function(monitor, drive) {
         // TODO: this code path is not tested, as the GVfs volume monitor
         // doesn't emit this signal just yet.
-        if (!this.ckListener.sessionActive)
+        if (!this._sessionActive())
             return;
 
         // we force stop/eject in this case, so we don't have to pass a
@@ -188,7 +206,7 @@ const AutomountManager = new Lang.Class({
         if (params.checkSession) {
             // if we're not in the current ConsoleKit session,
             // don't attempt automount
-            if (!this.ckListener.sessionActive)
+            if (!this._sessionActive())
                 return;
 
             if (this._ssProxy.screenSaverActive) {
diff --git a/src/Makefile.am b/src/Makefile.am
index 464831a..835ce5f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -81,6 +81,7 @@ include Makefile-hotplug-sniffer.am
 
 gnome_shell_cflags =				\
 	$(GNOME_SHELL_CFLAGS)			\
+	$(SYSTEMD_CFLAGS)                       \
 	-I$(srcdir)/tray			\
 	-DVERSION=\"$(VERSION)\"		\
 	-DLOCALEDIR=\"$(datadir)/locale\" 	\
@@ -279,6 +280,7 @@ libgnome_shell_la_LDFLAGS = -avoid-version
 libgnome_shell_la_LIBADD =		\
 	-lm			\
 	$(GNOME_SHELL_LIBS)	\
+	$(SYSTEMD_LIBS)         \
 	$(BLUETOOTH_LIBS)	\
 	libst-1.0.la       	\
 	libtray.la		\
diff --git a/src/shell-util.c b/src/shell-util.c
index 27b2217..c389425 100644
--- a/src/shell-util.c
+++ b/src/shell-util.c
@@ -14,6 +14,11 @@
 #include <libxml/tree.h>
 #include <libxml/xmlmemory.h>
 
+#ifdef WITH_SYSTEMD
+#include <systemd/sd-daemon.h>
+#include <systemd/sd-login.h>
+#endif
+
 /* Some code in this file adapted under the GPLv2+ from:
  *
  * GNOME panel utils: gnome-panel/gnome-panel/panel-util.c
@@ -833,3 +838,26 @@ shell_shader_effect_set_double_uniform (ClutterShaderEffect *effect,
                                            name,
                                            &gvalue);
 }
+
+/**
+ * shell_session_is_active_for_systemd:
+ *
+ * Checks whether the session we are running in is currently active,
+ * i.e. in the foreground and ready for user input.
+ *
+ * Returns: TRUE if session is active
+ */
+gboolean
+shell_session_is_active_for_systemd (void)
+{
+  /* If this isn't systemd, let's assume the session is active. */
+
+#ifdef WITH_SYSTEMD
+  if (sd_booted () <= 0)
+    return TRUE;
+
+  return sd_session_is_active (NULL) != 0;
+#else
+  return TRUE;
+#endif
+}
diff --git a/src/shell-util.h b/src/shell-util.h
index 8a8e5b9..5de9473 100644
--- a/src/shell-util.h
+++ b/src/shell-util.h
@@ -50,6 +50,8 @@ void shell_shader_effect_set_double_uniform (ClutterShaderEffect *effect,
                                              const gchar         *name,
                                              gdouble             value);
 
+gboolean shell_session_is_active_for_systemd (void);
+
 G_END_DECLS
 
 #endif /* __SHELL_UTIL_H__ */



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