[gnome-online-accounts] identity: Separate identity service off into its own process



commit ac7047d82d45747cf692a1385efab021c5d08202
Author: Ray Strode <rstrode redhat com>
Date:   Tue Oct 28 17:10:49 2014 -0400

    identity: Separate identity service off into its own process
    
    This commit segregates the kerberos specific functionality off
    into its own helper process.
    
    This has a couple of benefits:
    
    1) It is actually a better fit for how the code was initially designed,
    which was first staged in gnome-settings-daemon with g-o-a talking to
    it. Right now we have gnome-online-accounts talking to itself,
    in-process, through d-bus, which is suboptimal.
    
    2) It keeps any leaks or crashes in the kerberos code from bringing
    down the whole online accounts daemon.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=739593

 data/Makefile.am                     |    8 ++++-
 data/org.gnome.Identity.service.in   |    3 ++
 src/daemon/Makefile.am               |    8 ----
 src/daemon/goadaemon.c               |   43 ++++++++++++------------
 src/goaidentity/Makefile.am          |   10 +++--
 src/goaidentity/goaidentityservice.c |    2 +-
 src/goaidentity/main.c               |   59 ++++++++++++++++++++++++++++++++++
 7 files changed, 97 insertions(+), 36 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index d5513ef..a080424 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -11,9 +11,14 @@ gsettings_SCHEMAS = $(gsettings_in_files:.xml.in=.xml)
 
 servicedir       = $(datadir)/dbus-1/services
 service_in_files = org.gnome.OnlineAccounts.service.in
+
+if BUILD_KERBEROS
+service_in_files += org.gnome.Identity.service.in
+endif
+
 service_DATA     = $(service_in_files:.service.in=.service)
 
-$(service_DATA): $(service_in_files) Makefile
+%.service: %.service.in Makefile
        @sed -e "s|\ libexecdir\@|$(libexecdir)|" $< > $@
 
 EXTRA_DIST =                                           \
@@ -25,6 +30,7 @@ EXTRA_DIST =                                          \
 DISTCLEANFILES =                                       \
        $(gsettings_SCHEMAS)                            \
        org.gnome.OnlineAccounts.service                \
+       org.gnome.Identity.service                      \
        $(NULL)
 
 clean-local :
diff --git a/data/org.gnome.Identity.service.in b/data/org.gnome.Identity.service.in
new file mode 100644
index 0000000..bd3b032
--- /dev/null
+++ b/data/org.gnome.Identity.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gnome.Identity
+Exec= libexecdir@/goa-identity-service
diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am
index 9fdb115..8f5352f 100644
--- a/src/daemon/Makefile.am
+++ b/src/daemon/Makefile.am
@@ -48,14 +48,6 @@ goa_daemon_LDADD =                                           \
        $(TP_LIBS)                                              \
        $(NULL)
 
-if BUILD_KERBEROS
-goa_daemon_LDADD +=                                            \
-       $(top_builddir)/src/goaidentity/libgoaidentity.la       \
-       $(KRB5_LIBS)                                            \
-       $(GCR_LIBS)                                             \
-       $(NULL)
-endif
-
 clean-local :
        rm -f *~
 
diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c
index 6c048a5..68d4803 100644
--- a/src/daemon/goadaemon.c
+++ b/src/daemon/goadaemon.c
@@ -25,9 +25,6 @@
 #include "goadaemon.h"
 #include "goabackend/goabackend.h"
 #include "goabackend/goautils.h"
-#ifdef GOA_KERBEROS_ENABLED
-#include "goaidentity/goaidentityservice.h"
-#endif
 
 struct _GoaDaemon
 {
@@ -43,10 +40,6 @@ struct _GoaDaemon
 
   GoaManager *manager;
 
-#ifdef GOA_KERBEROS_ENABLED
-  GoaIdentityService *identity_service;
-#endif
-
   guint config_timeout_id;
 };
 
@@ -112,10 +105,6 @@ goa_daemon_finalize (GObject *object)
   g_object_unref (daemon->object_manager);
   g_object_unref (daemon->connection);
 
-#ifdef GOA_KERBEROS_ENABLED
-  g_clear_object (&daemon->identity_service);
-#endif
-
   G_OBJECT_CLASS (goa_daemon_parent_class)->finalize (object);
 }
 
@@ -173,15 +162,32 @@ on_file_monitor_changed (GFileMonitor      *monitor,
     }
 }
 
+#ifdef GOA_KERBEROS_ENABLED
+static void
+activate_identity_service (GoaDaemon *daemon)
+{
+  GoaProvider *provider;
+
+  /* We activate the identity service implicitly by using the kerberos
+   * backend.  This way if the kerberos backend isn't enabled, we don't
+   * end up starting the identity service needlessly
+   */
+  provider = goa_provider_get_for_provider_type (GOA_KERBEROS_NAME);
+
+  if (provider != NULL)
+    {
+      g_debug ("activated kerberos provider");
+      g_object_unref (provider);
+    }
+}
+#endif
+
 static void
 goa_daemon_init (GoaDaemon *daemon)
 {
   static volatile GQuark goa_error_domain = 0;
   GoaObjectSkeleton *object;
   gchar *path;
-#ifdef GOA_KERBEROS_ENABLED
-  GError *error = NULL;
-#endif
 
   /* this will force associating errors in the GOA_ERROR error domain
    * with org.freedesktop.Goa.Error.* errors via g_dbus_error_register_error_domain().
@@ -228,14 +234,7 @@ goa_daemon_init (GoaDaemon *daemon)
   g_dbus_object_manager_server_set_connection (daemon->object_manager, daemon->connection);
 
 #ifdef GOA_KERBEROS_ENABLED
-  daemon->identity_service = goa_identity_service_new ();
-  if (!goa_identity_service_activate (daemon->identity_service,
-                                      &error))
-    {
-      g_warning ("Error activating identity service: %s", error->message);
-      g_error_free (error);
-      g_clear_object (&daemon->identity_service);
-    }
+  activate_identity_service (daemon);
 #endif
 }
 
diff --git a/src/goaidentity/Makefile.am b/src/goaidentity/Makefile.am
index 8e11f6d..537287a 100644
--- a/src/goaidentity/Makefile.am
+++ b/src/goaidentity/Makefile.am
@@ -47,6 +47,7 @@ identity_sources =                                            \
        goakerberosidentity.c                                   \
        goakerberosidentityinquiry.c                            \
        goakerberosidentitymanager.c                            \
+       main.c                                                  \
        $(NULL)
 
 identity_dbus_built_sources =                                  \
@@ -95,23 +96,24 @@ BUILT_SOURCES += $(realmd_dbus_built_sources)
 EXTRA_DIST += org.freedesktop.realmd.xml
 
 if BUILD_KERBEROS
-noinst_LTLIBRARIES = libgoaidentity.la
+libexec_PROGRAMS = goa-identity-service
 
-libgoaidentity_la_SOURCES =                                    \
+goa_identity_service_SOURCES =                                         \
        goaidentityenumtypes.h          goaidentityenumtypes.c  \
        $(identity_dbus_built_sources)                          \
        $(realmd_dbus_built_sources)                            \
        $(identity_sources)                                     \
        $(NULL)
 
-libgoaidentity_la_CFLAGS =                                     \
+goa_identity_service_CFLAGS =                                  \
        $(GLIB_CFLAGS)                                          \
        $(GTK_CFLAGS)                                           \
        $(KRB5_CFLAGS)                                          \
        $(GCR_CFLAGS)                                           \
        $(NULL)
 
-libgoaidentity_la_LIBADD =                                     \
+goa_identity_service_LDADD =                                   \
+       $(top_builddir)/src/goa/libgoa-1.0.la                   \
        $(GLIB_LIBS)                                            \
        $(GTK_LIBS)                                             \
        $(KRB5_LIBS)                                            \
diff --git a/src/goaidentity/goaidentityservice.c b/src/goaidentity/goaidentityservice.c
index 38bbde6..6b6225a 100644
--- a/src/goaidentity/goaidentityservice.c
+++ b/src/goaidentity/goaidentityservice.c
@@ -1757,7 +1757,7 @@ on_name_lost (GDBusConnection    *connection,
               GoaIdentityService *self)
 {
   if (g_strcmp0 (name, "org.gnome.Identity") == 0)
-    g_debug ("GoaIdentityService: Lost name org.gnome.Identity");
+    raise (SIGTERM);
 }
 
 gboolean
diff --git a/src/goaidentity/main.c b/src/goaidentity/main.c
new file mode 100644
index 0000000..2de35ac
--- /dev/null
+++ b/src/goaidentity/main.c
@@ -0,0 +1,59 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <glib-unix.h>
+
+#include <gio/gio.h>
+
+#include "goaidentityservice.h"
+
+int
+main (int    argc,
+      char **argv)
+{
+  GMainLoop *loop;
+  GoaIdentityService *service;
+  GError *error;
+  int ret = 1;
+
+  loop = g_main_loop_new (NULL, FALSE);
+  service = goa_identity_service_new ();
+
+  error = NULL;
+  goa_identity_service_activate (service, &error);
+
+  if (error != NULL) {
+      g_warning ("couldn't activate identity service: %s", error->message);
+      g_error_free (error);
+      goto out;
+  }
+
+  g_main_loop_run (loop);
+
+  goa_identity_service_deactivate (service);
+
+  ret = 0;
+out:
+  g_object_unref (service);
+  g_main_loop_unref (loop);
+
+  return ret;
+}


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