]> git.pld-linux.org Git - packages/NetworkManager.git/blobdiff - systemd-fallback.patch
- updated to 1.8.0
[packages/NetworkManager.git] / systemd-fallback.patch
index 7ad09edaad270c56c409b7dd198e263d5be5fe9e..b27bacb76d3675a50aec3dd30001e72b26576561 100644 (file)
---- NetworkManager-0.9.8.0/configure.ac~       2013-02-21 14:04:19.582661393 +0100
-+++ NetworkManager-0.9.8.0/configure.ac        2013-02-21 14:23:32.286416661 +0100
-@@ -283,7 +283,7 @@
- AM_CONDITIONAL(SESSION_TRACKING_CK, test "$with_session_tracking" = "consolekit")
- AM_CONDITIONAL(SESSION_TRACKING_SYSTEMD, test "xwith_session_tracking" = "systemd")
- if test "$with_session_tracking" = "systemd"; then
--      PKG_CHECK_MODULES(SYSTEMD_LOGIN, [libsystemd-login])
-+      PKG_CHECK_MODULES(SYSTEMD_LOGIN, [libsystemd-daemon libsystemd-login])
-       AC_SUBST(SYSTEMD_LOGIN_CFLAGS)
-       AC_SUBST(SYSTEMD_LOGIN_LIBS)
+--- NetworkManager-1.8.0/configure.ac.orig     2017-05-27 22:30:22.001467624 +0200
++++ NetworkManager-1.8.0/configure.ac  2017-05-27 22:57:15.061449204 +0200
+@@ -447,7 +447,7 @@
+ # output
+ session_tracking=
+ if test "$use_systemd_logind" = "yes" -o "$use_systemd_logind" = "auto"; then
+-    PKG_CHECK_MODULES(SYSTEMD_LOGIN, [libsystemd], [have_systemd_logind=yes], [PKG_CHECK_MODULES(SYSTEMD_LOGIN, [libsystemd-login], [have_systemd_logind=yes], [have_systemd_logind=no])])
++    PKG_CHECK_MODULES(SYSTEMD_LOGIN, [libsystemd], [have_systemd_logind=yes], [PKG_CHECK_MODULES(SYSTEMD_LOGIN, [libsystemd-daemon libsystemd-login], [have_systemd_logind=yes], [have_systemd_logind=no])])
+ else
+     have_systemd_logind=no
  fi
---- NetworkManager-0.9.10.0/src/nm-session-monitor-systemd.c.orig      2014-07-04 02:44:13.000000000 +0200
-+++ NetworkManager-0.9.10.0/src/nm-session-monitor-systemd.c   2014-07-05 09:46:03.260229549 +0200
-@@ -28,6 +28,10 @@
- #include <glib/gstdio.h>
- #include <systemd/sd-login.h>
- #include <stdlib.h>
-+#include <systemd/sd-daemon.h>
-+#include <sys/stat.h>
-+#include <gio/gio.h>
-+#include "nm-logging.h"
+@@ -477,11 +477,12 @@
  
- #include "nm-session-utils.h"
- #include "nm-session-monitor.h"
-@@ -108,10 +112,20 @@ sd_source_new (void)
-       return source;
- }
+ if test "$use_consolekit" = "yes"; then
+       AC_DEFINE([SESSION_TRACKING_CONSOLEKIT], 1, [Define to 1 if ConsoleKit is available])
+-      AC_DEFINE([CKDB_PATH], "/var/run/ConsoleKit/database", [Path to ConsoleKit database])
+       session_tracking="$session_tracking, consolekit"
+ fi
+ session_tracking="$(printf '%s' "${session_tracking}" | sed 's/^, //')"
  
-+/********************************************************************/
++AC_DEFINE([CKDB_PATH], "/var/run/ConsoleKit/database", [Path to ConsoleKit database])
 +
-+#define CKDB_PATH "/var/run/ConsoleKit/database"
-+
- struct _NMSessionMonitor {
-       GObject parent_instance;
+ AC_ARG_WITH(suspend-resume, AS_HELP_STRING([--with-suspend-resume=upower|systemd|elogind|consolekit], [Build NetworkManager with specific suspend/resume support]))
+ if test "z$with_suspend_resume" = "z"; then
+     PKG_CHECK_EXISTS([libsystemd >= 209], [have_systemd_inhibit=yes],
+--- NetworkManager-1.8.0/src/nm-session-monitor.c.orig 2017-05-10 10:59:08.000000000 +0200
++++ NetworkManager-1.8.0/src/nm-session-monitor.c      2017-05-27 23:07:26.988108884 +0200
+@@ -33,6 +33,7 @@
+ #endif
  
-       GSource *sd_source;
-+
-+      GKeyFile *database;
-+      GFileMonitor *database_monitor;
-+      time_t database_mtime;
-+      GHashTable *sessions_by_uid;
-+      GHashTable *sessions_by_user;
+ #ifdef SESSION_TRACKING_SYSTEMD
++#include <systemd/sd-daemon.h>
+ #include <systemd/sd-login.h>
+ #define LOGIND_NAME "systemd-logind"
+ #endif
+@@ -65,13 +66,11 @@ struct _NMSessionMonitor {
+       } sd;
+ #endif
+-#ifdef SESSION_TRACKING_CONSOLEKIT
+       struct {
+               GFileMonitor *monitor;
+               GHashTable *cache;
+               time_t timestamp;
+       } ck;
+-#endif
  };
  
  struct _NMSessionMonitorClass {
-@@ -131,6 +145,215 @@ G_DEFINE_TYPE (NMSessionMonitor, nm_sess
+@@ -144,7 +143,6 @@ st_sd_finalize (NMSessionMonitor *monito
  
- /* ---------------------------------------------------------------------------------------------------- */
+ /*****************************************************************************/
  
-+typedef struct {
-+      char *user;
-+      uid_t uid;
-+      gboolean local;
-+      gboolean active;
-+} Session;
-+
-+static void
-+session_free (Session *s)
-+{
-+      g_free (s->user);
-+      memset (s, 0, sizeof (Session));
-+      g_free (s);
-+}
-+
-+static gboolean
-+check_key (GKeyFile *keyfile, const char *group, const char *key, GError **error)
-+{
-+      if (g_key_file_has_key (keyfile, group, key, error))
-+              return TRUE;
-+
-+      if (!error) {
-+              g_set_error (error,
-+                               NM_SESSION_MONITOR_ERROR,
-+                               NM_SESSION_MONITOR_ERROR_MALFORMED_DATABASE,
-+                               "ConsoleKit database " CKDB_PATH " group '%s' had no '%s' key",
-+                               group, key);
-+      }
-+      return FALSE;
-+}
-+
-+static Session *
-+session_new (GKeyFile *keyfile, const char *group, GError **error)
-+{
-+      GError *local = NULL;
-+      Session *s;
-+      const char *uname = NULL;
-+
-+      s = g_new0 (Session, 1);
-+      g_assert (s);
-+
-+      s->uid = G_MAXUINT; /* paranoia */
-+      if (!check_key (keyfile, group, "uid", &local))
-+              goto error;
-+      s->uid = (uid_t) g_key_file_get_integer (keyfile, group, "uid", &local);
-+      if (local)
-+              goto error;
-+
-+      if (!check_key (keyfile, group, "is_active", &local))
-+              goto error;
-+      s->active = g_key_file_get_boolean (keyfile, group, "is_active", &local);
-+      if (local)
-+              goto error;
-+
-+      if (!check_key (keyfile, group, "is_local", &local))
-+              goto error;
-+      s->local = g_key_file_get_boolean (keyfile, group, "is_local", &local);
-+      if (local)
-+              goto error;
-+
-+      if (!nm_session_uid_to_user (s->uid, &uname, error))
-+              return FALSE;
-+      s->user = g_strdup (uname);
-+
-+      return s;
-+
-+error:
-+      session_free (s);
-+      g_propagate_error (error, local);
-+      return NULL;
-+}
-+
-+static void
-+session_merge (Session *src, Session *dest)
-+{
-+      g_return_if_fail (src != NULL);
-+      g_return_if_fail (dest != NULL);
-+
-+      g_warn_if_fail (g_strcmp0 (src->user, dest->user) == 0);
-+      g_warn_if_fail (src->uid == dest->uid);
-+
-+      dest->local = (dest->local || src->local);
-+      dest->active = (dest->active || src->active);
-+}
-+
-+/********************************************************************/
-+
-+static void
-+free_database (NMSessionMonitor *self)
-+{
-+      if (self->database != NULL) {
-+              g_key_file_free (self->database);
-+              self->database = NULL;
-+      }
-+
-+      g_hash_table_remove_all (self->sessions_by_uid);
-+      g_hash_table_remove_all (self->sessions_by_user);
-+}
-+
-+static gboolean
-+reload_database (NMSessionMonitor *self, GError **error)
-+{
-+      struct stat statbuf;
-+      char **groups = NULL;
-+      gsize len = 0, i;
-+      Session *s;
-+
-+      free_database (self);
-+
-+      errno = 0;
-+      if (stat (CKDB_PATH, &statbuf) != 0) {
-+              g_set_error (error,
-+                           NM_SESSION_MONITOR_ERROR,
-+                           errno == ENOENT ? NM_SESSION_MONITOR_ERROR_NO_DATABASE : NM_SESSION_MONITOR_ERROR_IO_ERROR,
-+                           "Error statting file " CKDB_PATH ": %s",
-+                           strerror (errno));
-+              goto error;
-+      }
-+      self->database_mtime = statbuf.st_mtime;
-+
-+      self->database = g_key_file_new ();
-+      if (!g_key_file_load_from_file (self->database, CKDB_PATH, G_KEY_FILE_NONE, error))
-+              goto error;
-+
-+      groups = g_key_file_get_groups (self->database, &len);
-+      if (!groups) {
-+              g_set_error_literal (error,
-+                                   NM_SESSION_MONITOR_ERROR,
-+                                   NM_SESSION_MONITOR_ERROR_IO_ERROR,
-+                                   "Could not load groups from " CKDB_PATH "");
-+              goto error;
-+      }
-+
-+      for (i = 0; i < len; i++) {
-+              Session *found;
-+
-+              if (!g_str_has_prefix (groups[i], "Session "))
-+                      continue;
-+
-+              s = session_new (self->database, groups[i], error);
-+              if (!s)
-+                      goto error;
-+
-+              found = g_hash_table_lookup (self->sessions_by_user, (gpointer) s->user);
-+              if (found) {
-+                      session_merge (s, found);
-+                      session_free (s);
-+              } else {
-+                      /* Entirely new user */
-+                      g_hash_table_insert (self->sessions_by_user, (gpointer) s->user, s);
-+                      g_hash_table_insert (self->sessions_by_uid, GUINT_TO_POINTER (s->uid), s);
-+              }
-+      }
-+
-+      g_strfreev (groups);
-+      return TRUE;
-+
-+error:
-+      if (groups)
-+              g_strfreev (groups);
-+      free_database (self);
-+      return FALSE;
-+}
-+
-+static gboolean
-+ensure_database (NMSessionMonitor *self, GError **error)
-+{
-+      gboolean ret = FALSE;
-+
-+      if (self->database != NULL) {
-+              struct stat statbuf;
-+
-+              errno = 0;
-+              if (stat (CKDB_PATH, &statbuf) != 0) {
-+                      g_set_error (error,
-+                                   NM_SESSION_MONITOR_ERROR,
-+                                   errno == ENOENT ? NM_SESSION_MONITOR_ERROR_NO_DATABASE : NM_SESSION_MONITOR_ERROR_IO_ERROR,
-+                                   "Error statting file " CKDB_PATH " to check timestamp: %s",
-+                                   strerror (errno));
-+                      goto out;
-+              }
-+
-+              if (statbuf.st_mtime == self->database_mtime) {
-+                      ret = TRUE;
-+                      goto out;
-+              }
-+      }
-+
-+      ret = reload_database (self, error);
-+
-+out:
-+      return ret;
-+}
-+
-+static void
-+on_file_monitor_changed (GFileMonitor *    file_monitor,
-+                         GFile *           file,
-+                         GFile *           other_file,
-+                         GFileMonitorEvent event_type,
-+                         gpointer          user_data)
-+{
-+      NMSessionMonitor *self = NM_SESSION_MONITOR (user_data);
-+
-+      /* throw away cache */
-+      free_database (self);
-+
-+      g_signal_emit (self, signals[CHANGED_SIGNAL], 0);
-+}
-+
- static gboolean
- sessions_changed (gpointer user_data)
- {
-@@ -144,9 +367,50 @@ sessions_changed (gpointer user_data)
- static void
- nm_session_monitor_init (NMSessionMonitor *monitor)
- {
--      monitor->sd_source = sd_source_new ();
--      g_source_set_callback (monitor->sd_source, sessions_changed, monitor, NULL);
--      g_source_attach (monitor->sd_source, NULL);
-+      if (sd_booted () > 0) {
-+              monitor->sd_source = sd_source_new ();
-+              g_source_set_callback (monitor->sd_source, sessions_changed, monitor, NULL);
-+              g_source_attach (monitor->sd_source, NULL);
-+
-+              monitor->database_monitor = NULL;
-+              monitor->database = NULL;
-+      } else {
-+              monitor->sd_source = NULL;
-+
-+              GError *error = NULL;
-+              GFile *file;
-+
-+              /* Sessions-by-user is responsible for destroying the Session objects */
-+              monitor->sessions_by_user = g_hash_table_new_full (g_str_hash, g_str_equal,
-+                                                              NULL, (GDestroyNotify) session_free);
-+              monitor->sessions_by_uid = g_hash_table_new (g_direct_hash, g_direct_equal);
-+
-+
-+              error = NULL;
-+              if (!ensure_database (monitor, &error)) {
-+                      /* Ignore the first error if the CK database isn't found yet */
-+                      if (g_error_matches (error,
-+                                           NM_SESSION_MONITOR_ERROR,
-+                                           NM_SESSION_MONITOR_ERROR_NO_DATABASE) == FALSE) {
-+                              nm_log_err (LOGD_CORE, "Error loading " CKDB_PATH ": %s", error->message);
-+                      }
-+                      g_error_free (error);
-+              }
-+
-+              error = NULL;
-+              file = g_file_new_for_path (CKDB_PATH);
-+              monitor->database_monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &error);
-+              g_object_unref (file);
-+              if (monitor->database_monitor == NULL) {
-+                      nm_log_err (LOGD_CORE, "Error monitoring " CKDB_PATH ": %s", error->message);
-+                      g_error_free (error);
-+              } else {
-+                      g_signal_connect (monitor->database_monitor,
-+                                        "changed",
-+                                        G_CALLBACK (on_file_monitor_changed),
-+                                        monitor);
-+              }
-+      }
+-#ifdef SESSION_TRACKING_CONSOLEKIT
+ typedef struct {
+       gboolean active;
+ } CkSession;
+@@ -278,7 +276,6 @@ ck_finalize (NMSessionMonitor *monitor)
+       g_clear_pointer (&monitor->ck.cache, g_hash_table_unref);
+       g_clear_object (&monitor->ck.monitor);
  }
+-#endif /* SESSION_TRACKING_CONSOLEKIT */
  
- static void
-@@ -159,6 +423,12 @@ nm_session_monitor_finalize (GObject *ob
-               g_source_unref (monitor->sd_source);
-       }
+ /*****************************************************************************/
  
-+      if (monitor->database_monitor != NULL)
-+              g_object_unref (monitor->database_monitor);
-+
-+      if (monitor->database != NULL)
-+              free_database (monitor);
-+
-       if (G_OBJECT_CLASS (nm_session_monitor_parent_class)->finalize != NULL)
-               G_OBJECT_CLASS (nm_session_monitor_parent_class)->finalize (object);
- }
-@@ -204,15 +474,36 @@ nm_session_monitor_user_has_session (NMS
-                                      uid_t *out_uid,
-                                      GError **error)
- {
--      uid_t uid;
-+      if (monitor->sd_source != NULL) {
-+              uid_t uid;
+@@ -350,13 +347,16 @@ nm_session_monitor_session_exists (NMSes
+       g_return_val_if_fail (NM_IS_SESSION_MONITOR (self), FALSE);
  
--      if (!nm_session_user_to_uid (username, &uid, error))
--              return FALSE;
-+              if (!nm_session_user_to_uid (username, &uid, error))
-+                      return FALSE;
--      if (out_uid)
--              *out_uid = uid;
-+              if (out_uid)
-+                      *out_uid = uid;
--      return nm_session_monitor_uid_has_session (monitor, uid, NULL, error);
-+              return nm_session_monitor_uid_has_session (monitor, uid, NULL, error);
+ #ifdef SESSION_TRACKING_SYSTEMD
+-      if (st_sd_session_exists (self, uid, active))
+-              return TRUE;
++      if (sd_booted () > 0) {
++              if (st_sd_session_exists (self, uid, active))
++                      return TRUE;
 +      } else {
-+              Session *s;
+ #endif
+-
+-#ifdef SESSION_TRACKING_CONSOLEKIT
+       if (ck_session_exists (self, uid, active))
+               return TRUE;
 +
-+              if (!ensure_database (monitor, error))
-+                      return FALSE;
-+
-+              s = g_hash_table_lookup (monitor->sessions_by_user, (gpointer) username);
-+              if (!s) {
-+                      g_set_error (error,
-+                                   NM_SESSION_MONITOR_ERROR,
-+                                   NM_SESSION_MONITOR_ERROR_UNKNOWN_USER,
-+                                   "No session found for user '%s'",
-+                                   username);
-+                      return FALSE;
-+              }
-+
-+              if (out_uid)
-+                      *out_uid = s->uid;
-+              return TRUE;
++#ifdef SESSION_TRACKING_SYSTEMD
 +      }
- }
+ #endif
  
- gboolean
-@@ -220,12 +511,31 @@ nm_session_monitor_user_active (NMSessio
-                                 const char *username,
-                                 GError **error)
+       return FALSE;
+@@ -368,26 +368,28 @@ static void
+ nm_session_monitor_init (NMSessionMonitor *monitor)
  {
--      uid_t uid;
-+      if (monitor->sd_source != NULL) {
-+              uid_t uid;
--      if (!nm_session_user_to_uid (username, &uid, error))
--              return FALSE;
-+              if (!nm_session_user_to_uid (username, &uid, error))
-+                      return FALSE;
--      return nm_session_monitor_uid_active (monitor, uid, error);
-+              return nm_session_monitor_uid_active (monitor, uid, error);
-+      } else {
-+              Session *s;
-+
-+              if (!ensure_database (monitor, error))
-+                      return FALSE;
-+
-+              s = g_hash_table_lookup (monitor->sessions_by_user, (gpointer) username);
-+              if (!s) {
-+                      g_set_error (error,
-+                                   NM_SESSION_MONITOR_ERROR,
-+                                   NM_SESSION_MONITOR_ERROR_UNKNOWN_USER,
-+                                   "No session found for user '%s'",
-+                                   username);
-+                      return FALSE;
-+              }
-+
-+              return s->active;
+ #ifdef SESSION_TRACKING_SYSTEMD
++      if (sd_booted () > 0) {
+       st_sd_init (monitor);
+       _LOGD ("using "LOGIND_NAME" session tracking");
++      } else
+ #endif
+-#ifdef SESSION_TRACKING_CONSOLEKIT
++      {
+       ck_init (monitor);
+       _LOGD ("using ConsoleKit session tracking");
+-#endif
 +      }
  }
  
- gboolean
-@@ -234,19 +544,40 @@ nm_session_monitor_uid_has_session (NMSe
-                                     const char **out_user,
-                                     GError **error)
+ static void
+ finalize (GObject *object)
  {
--      int num_sessions;
-+      if (monitor->sd_source != NULL) {
-+              int num_sessions;
+ #ifdef SESSION_TRACKING_SYSTEMD
++      if (sd_booted () > 0)
+       st_sd_finalize (NM_SESSION_MONITOR (object));
++      else
+ #endif
  
--      if (!nm_session_uid_to_user (uid, out_user, error))
--              return FALSE;
-+              if (!nm_session_uid_to_user (uid, out_user, error))
-+                      return FALSE;
+-#ifdef SESSION_TRACKING_CONSOLEKIT
+       ck_finalize (NM_SESSION_MONITOR (object));
+-#endif
  
--      /* Get all sessions (including inactive ones) for the user */
--      num_sessions = sd_uid_get_sessions (uid, 0, NULL);
--      if (num_sessions < 0) {
--              nm_log_warn (LOGD_CORE, "Failed to get systemd sessions for uid %d: %d",
--                           uid, num_sessions);
--              return FALSE;
-+              /* Get all sessions (including inactive ones) for the user */
-+              num_sessions = sd_uid_get_sessions (uid, 0, NULL);
-+              if (num_sessions < 0) {
-+                      nm_log_warn (LOGD_CORE, "Failed to get systemd sessions for uid %d: %d",
-+                                   uid, num_sessions);
-+                      return FALSE;
-+              }
-+              return num_sessions > 0;
-+      } else {
-+              Session *s;
-+
-+              if (!ensure_database (monitor, error))
-+                      return FALSE;
-+
-+              s = g_hash_table_lookup (monitor->sessions_by_uid, GUINT_TO_POINTER (uid));
-+              if (!s) {
-+                      g_set_error (error,
-+                                   NM_SESSION_MONITOR_ERROR,
-+                                   NM_SESSION_MONITOR_ERROR_UNKNOWN_USER,
-+                                   "No session found for uid %d",
-+                                   uid);
-+                      return FALSE;
-+              }
-+
-+              if (out_user)
-+                      *out_user = s->user;
-+              return TRUE;
-       }
--      return num_sessions > 0;
- }
- gboolean
-@@ -254,14 +585,33 @@ nm_session_monitor_uid_active (NMSession
-                                uid_t uid,
-                                GError **error)
- {
--      int num_sessions;
-+      if (monitor->sd_source != NULL) {
-+              int num_sessions;
--      /* Get active sessions for the user */
--      num_sessions = sd_uid_get_sessions (uid, 1, NULL);
--      if (num_sessions < 0) {
--              nm_log_warn (LOGD_CORE, "Failed to get active systemd sessions for uid %d: %d",
--                           uid, num_sessions);
--              return FALSE;
-+              /* Get active sessions for the user */
-+              num_sessions = sd_uid_get_sessions (uid, 1, NULL);
-+              if (num_sessions < 0) {
-+                      nm_log_warn (LOGD_CORE, "Failed to get active systemd sessions for uid %d: %d",
-+                                   uid, num_sessions);
-+                      return FALSE;
-+              }
-+              return num_sessions > 0;
-+      } else {
-+              Session *s;
-+
-+              if (!ensure_database (monitor, error))
-+                      return FALSE;
-+
-+              s = g_hash_table_lookup (monitor->sessions_by_uid, GUINT_TO_POINTER (uid));
-+              if (!s) {
-+                      g_set_error (error,
-+                                   NM_SESSION_MONITOR_ERROR,
-+                                   NM_SESSION_MONITOR_ERROR_UNKNOWN_USER,
-+                                   "No session found for uid '%d'",
-+                                   uid);
-+                      return FALSE;
-+              }
-+
-+              return s->active;
-       }
--      return num_sessions > 0;
+       G_OBJECT_CLASS (nm_session_monitor_parent_class)->finalize (object);
  }
---- NetworkManager-0.9.10.0/src/nm-sleep-monitor-systemd.c.orig        2014-07-04 02:44:13.000000000 +0200
-+++ NetworkManager-0.9.10.0/src/nm-sleep-monitor-systemd.c     2014-07-05 09:49:32.623554089 +0200
-@@ -26,6 +26,7 @@
- #include <glib/gi18n.h>
- #include <gio/gio.h>
+--- NetworkManager-1.8.0/src/nm-sleep-monitor.c.orig   2017-05-10 10:59:08.000000000 +0200
++++ NetworkManager-1.8.0/src/nm-sleep-monitor.c        2017-05-27 23:22:47.011431711 +0200
+@@ -26,6 +26,10 @@
+ #include <sys/stat.h>
  #include <gio/gunixfdlist.h>
-+#include <systemd/sd-daemon.h>
  
- #include "nm-logging.h"
- #include "nm-dbus-manager.h"
-@@ -36,12 +37,15 @@
- #define SD_PATH              "/org/freedesktop/login1"
- #define SD_INTERFACE         "org.freedesktop.login1.Manager"
-+#define UPOWER_DBUS_SERVICE "org.freedesktop.UPower"
++#ifdef SUSPEND_RESUME_SYSTEMD
++# include <systemd/sd-daemon.h>
++#endif
++
+ #include "nm-core-internal.h"
+ #include "NetworkManagerUtils.h"
  
- struct _NMSleepMonitor {
-       GObject parent_instance;
+@@ -40,9 +44,9 @@
  
-       GDBusProxy *sd_proxy;
-       gint inhibit_fd;
-+      
-+      DBusGProxy *upower_proxy;
- };
+ #elif defined (SUSPEND_RESUME_SYSTEMD) || defined (SUSPEND_RESUME_ELOGIND)
  
- struct _NMSleepMonitorClass {
-@@ -63,6 +67,20 @@ G_DEFINE_TYPE (NMSleepMonitor, nm_sleep_
+-#define SUSPEND_DBUS_NAME               "org.freedesktop.login1"
+-#define SUSPEND_DBUS_PATH               "/org/freedesktop/login1"
+-#define SUSPEND_DBUS_INTERFACE          "org.freedesktop.login1.Manager"
++#define SD_SUSPEND_DBUS_NAME               "org.freedesktop.login1"
++#define SD_SUSPEND_DBUS_PATH               "/org/freedesktop/login1"
++#define SD_SUSPEND_DBUS_INTERFACE          "org.freedesktop.login1.Manager"
+ #define USE_UPOWER                      0
+ #if defined (SUSPEND_RESUME_SYSTEMD)
+ #define _NMLOG_PREFIX_NAME              "sleep-monitor-sd"
+@@ -52,6 +56,17 @@
  
- /********************************************************************/
+ #elif defined(SUSPEND_RESUME_CONSOLEKIT)
  
-+static void
-+upower_sleeping_cb (DBusGProxy *proxy, gpointer user_data)
-+{
-+        nm_log_dbg (LOGD_SUSPEND, "Received UPower sleeping signal");
-+        g_signal_emit (user_data, signals[SLEEPING], 0);
-+}
++#define USE_UPOWER                      0
++#define _NMLOG_PREFIX_NAME              "sleep-monitor-ck"
 +
-+static void
-+upower_resuming_cb (DBusGProxy *proxy, gpointer user_data)
-+{
-+        nm_log_dbg (LOGD_SUSPEND, "Received UPower resuming signal");
-+        g_signal_emit (user_data, signals[RESUMING], 0);
-+}
++#else
 +
- static gboolean
- drop_inhibitor (NMSleepMonitor *self)
- {
-@@ -164,9 +182,34 @@ sleep_setup (NMSleepMonitor *self)
- static void
- nm_sleep_monitor_init (NMSleepMonitor *self)
- {
--      self->inhibit_fd = -1;
--      sleep_setup (self);
--      take_inhibitor (self);
-+      if (sd_booted () > 0) {
-+              self->inhibit_fd = -1;
-+              sleep_setup (self);
-+              take_inhibitor (self);
-+      } else {
-+              NMDBusManager *dbus_mgr;
-+              DBusGConnection *bus;
++#error define one of SUSPEND_RESUME_SYSTEMD, SUSPEND_RESUME_ELOGIND, SUSPEND_RESUME_CONSOLEKIT, or SUSPEND_RESUME_UPOWER
 +
-+              dbus_mgr = nm_dbus_manager_get ();
-+        bus = nm_dbus_manager_get_connection (dbus_mgr);
-+        self->upower_proxy = dbus_g_proxy_new_for_name (bus,
-+                                                        UPOWER_DBUS_SERVICE,
-+                                                        "/org/freedesktop/UPower",
-+                                                        "org.freedesktop.UPower");
-+        if (self->upower_proxy) {
-+                      dbus_g_proxy_add_signal (self->upower_proxy, "Sleeping", G_TYPE_INVALID);
-+                      dbus_g_proxy_connect_signal (self->upower_proxy, "Sleeping",
-+                                                                               G_CALLBACK (upower_sleeping_cb),
-+                                                                               self, NULL);
++#endif
 +
-+                      dbus_g_proxy_add_signal (self->upower_proxy, "Resuming", G_TYPE_INVALID);
-+                      dbus_g_proxy_connect_signal (self->upower_proxy, "Resuming",
-+                                                                               G_CALLBACK (upower_resuming_cb),
-+                                                                               self, NULL);
-+        } else
-+                              nm_log_warn (LOGD_SUSPEND, "could not initialize UPower D-Bus proxy");
-+        g_object_unref (dbus_mgr);
-+      }
- }
++#if defined (SUSPEND_RESUME_SYSTEMD) || defined(SUSPEND_RESUME_CONSOLEKIT)
++ 
+ /* ConsoleKit2 has added the same suspend/resume DBUS API that Systemd
+  * uses. http://consolekit2.github.io/ConsoleKit2/#Manager.Inhibit
+  */
+@@ -59,12 +74,6 @@
+ #define SUSPEND_DBUS_NAME               "org.freedesktop.ConsoleKit"
+ #define SUSPEND_DBUS_PATH               "/org/freedesktop/ConsoleKit/Manager"
+ #define SUSPEND_DBUS_INTERFACE          "org.freedesktop.ConsoleKit.Manager"
+-#define USE_UPOWER                      0
+-#define _NMLOG_PREFIX_NAME              "sleep-monitor-ck"
+-
+-#else
+-
+-#error define one of SUSPEND_RESUME_SYSTEMD, SUSPEND_RESUME_ELOGIND, SUSPEND_RESUME_CONSOLEKIT, or SUSPEND_RESUME_UPOWER
  
- static void
-@@ -174,9 +217,14 @@ finalize (GObject *object)
- {
-       NMSleepMonitor *self = NM_SLEEP_MONITOR (object);
+ #endif
  
--      drop_inhibitor (self);
--      if (self->sd_proxy)
--              g_object_unref (self->sd_proxy);
-+      if (sd_booted () > 0) {
-+              drop_inhibitor (self);
-+              if (self->sd_proxy)
-+                      g_object_unref (self->sd_proxy);
-+      } else {
-+              if (self->upower_proxy)
-+                      g_object_unref (self->upower_proxy);
-+      }
-       if (G_OBJECT_CLASS (nm_sleep_monitor_parent_class)->finalize != NULL)
-               G_OBJECT_CLASS (nm_sleep_monitor_parent_class)->finalize (object);
+@@ -347,6 +356,17 @@ nm_sleep_monitor_init (NMSleepMonitor *s
+ {
+       self->inhibit_fd = -1;
+       self->cancellable = g_cancellable_new ();
++#ifdef SUSPEND_RESUME_SYSTEMD
++      if (sd_booted () > 0)
++              g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
++                                            G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START |
++                                            G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
++                                            NULL,
++                                            SD_SUSPEND_DBUS_NAME, SD_SUSPEND_DBUS_PATH, SD_SUSPEND_DBUS_INTERFACE,
++                                            self->cancellable,
++                                            (GAsyncReadyCallback) on_proxy_acquired, self);
++      else
++#endif
+       g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
+                                 G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START |
+                                 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
This page took 0.059493 seconds and 4 git commands to generate.