PolicyKit: Branch 'wip/js-rule-files'

David Zeuthen david at kemper.freedesktop.org
Fri May 25 08:09:25 PDT 2012


 configure.ac                  |    1 
 src/Makefile.am               |    2 
 src/polkitbackend/Makefile.am |   25 +++++
 src/polkitbackend/polkitd.c   |  184 ++++++++++++++++++++++++++++++++++++++++++
 src/polkitd/Makefile.am       |   40 ---------
 src/polkitd/main.c            |  184 ------------------------------------------
 6 files changed, 210 insertions(+), 226 deletions(-)

New commits:
commit d973961df4aeaf7cf02ec60f9d4167fee2324bf8
Author: David Zeuthen <davidz at redhat.com>
Date:   Fri May 25 11:09:02 2012 -0400

    Move polkitd into src/polkitbackend
    
    Signed-off-by: David Zeuthen <davidz at redhat.com>

diff --git a/configure.ac b/configure.ac
index 930d8de..d9559cc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -458,7 +458,6 @@ src/Makefile
 src/polkit/Makefile
 src/polkitbackend/Makefile
 src/polkitagent/Makefile
-src/polkitd/Makefile
 src/programs/Makefile
 src/examples/Makefile
 docs/version.xml
diff --git a/src/Makefile.am b/src/Makefile.am
index 3380fb2..96c1e0c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,5 @@
 
-SUBDIRS = polkit polkitbackend polkitagent polkitd programs
+SUBDIRS = polkit polkitbackend polkitagent programs
 
 if BUILD_EXAMPLES
 SUBDIRS += examples
diff --git a/src/polkitbackend/Makefile.am b/src/polkitbackend/Makefile.am
index 1bafd94..3f6c043 100644
--- a/src/polkitbackend/Makefile.am
+++ b/src/polkitbackend/Makefile.am
@@ -65,6 +65,31 @@ libpolkit_backend_1_la_LIBADD =                               		\
 rulesdir = $(sysconfdir)/polkit-1/rules.d
 rules_DATA = 50-default.rules
 
+# ----------------------------------------------------------------------------------------------------
+
+libprivdir = $(prefix)/lib/polkit-1
+libpriv_PROGRAMS = polkitd
+
+polkitd_SOURCES = 							\
+					polkitd.c			\
+	$(NULL)
+
+polkitd_CFLAGS = 							\
+	-DPOLKIT_BACKEND_I_KNOW_API_IS_SUBJECT_TO_CHANGE		\
+	-DG_LOG_DOMAIN=\"polkitd-1\"					\
+	$(GLIB_CFLAGS)							\
+	$(NULL)
+
+polkitd_LDADD = 				        		\
+	$(DBUS_GLIB_LIBS)						\
+	$(GLIB_LIBS)							\
+	$(top_builddir)/src/polkit/libpolkit-gobject-1.la		\
+	$(top_builddir)/src/polkitbackend/libpolkit-backend-1.la	\
+	$(NULL)
+
+# ----------------------------------------------------------------------------------------------------
+
+
 CLEANFILES = $(BUILT_SOURCES)
 
 EXTRA_DIST =								\
diff --git a/src/polkitbackend/polkitd.c b/src/polkitbackend/polkitd.c
new file mode 100644
index 0000000..0bb3f32
--- /dev/null
+++ b/src/polkitbackend/polkitd.c
@@ -0,0 +1,184 @@
+/*
+ * Copyright (C) 2008-2010 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: David Zeuthen <davidz at redhat.com>
+ */
+
+#include "config.h"
+
+#include <signal.h>
+
+#include <glib-unix.h>
+
+#include <polkit/polkit.h>
+#include <polkitbackend/polkitbackend.h>
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static PolkitBackendAuthority *authority = NULL;
+static gpointer                registration_id = NULL;
+static GMainLoop              *loop = NULL;
+static gboolean                opt_replace = FALSE;
+static gboolean                opt_no_debug = FALSE;
+static GOptionEntry            opt_entries[] = {
+  {"replace", 'r', 0, G_OPTION_ARG_NONE, &opt_replace, "Replace existing daemon", NULL},
+  {"no-debug", 'n', 0, G_OPTION_ARG_NONE, &opt_no_debug, "Don't print debug information", NULL},
+  {NULL }
+};
+
+static void
+on_bus_acquired (GDBusConnection *connection,
+                 const gchar     *name,
+                 gpointer         user_data)
+{
+  GError *error;
+
+  g_print ("Connected to the system bus\n");
+
+  g_assert (authority == NULL);
+  g_assert (registration_id == NULL);
+
+  authority = polkit_backend_authority_get ();
+  g_print ("Using authority class %s\n", g_type_name (G_TYPE_FROM_INSTANCE (authority)));
+
+  error = NULL;
+  registration_id = polkit_backend_authority_register (authority,
+                                                       connection,
+                                                       "/org/freedesktop/PolicyKit1/Authority",
+                                                       &error);
+  if (registration_id == NULL)
+    {
+      g_printerr ("Error registering authority: %s\n", error->message);
+      g_error_free (error);
+      g_main_loop_quit (loop); /* exit */
+    }
+}
+
+static void
+on_name_lost (GDBusConnection *connection,
+              const gchar     *name,
+              gpointer         user_data)
+{
+  g_print ("Lost the name org.freedesktop.PolicyKit1 - exiting\n");
+  g_main_loop_quit (loop);
+}
+
+static void
+on_name_acquired (GDBusConnection *connection,
+                  const gchar     *name,
+                  gpointer         user_data)
+{
+  g_print ("Acquired the name org.freedesktop.PolicyKit1\n");
+}
+
+static gboolean
+on_sigint (gpointer user_data)
+{
+  g_print ("Handling SIGINT\n");
+  g_main_loop_quit (loop);
+  return FALSE;
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+  GError *error;
+  GOptionContext *opt_context;
+  gint ret;
+  guint name_owner_id;
+  guint sigint_id;
+
+  ret = 1;
+  loop = NULL;
+  opt_context = NULL;
+  name_owner_id = 0;
+  sigint_id = 0;
+  registration_id = NULL;
+
+  g_type_init ();
+
+  opt_context = g_option_context_new ("polkit system daemon");
+  g_option_context_add_main_entries (opt_context, opt_entries, NULL);
+  error = NULL;
+  if (!g_option_context_parse (opt_context, &argc, &argv, &error))
+    {
+      g_printerr ("Error parsing options: %s", error->message);
+      g_error_free (error);
+      goto out;
+    }
+
+  /* If --no-debug is requested don't clutter stdout/stderr etc.
+   */
+  if (opt_no_debug)
+    {
+      gint dev_null_fd;
+      dev_null_fd = open ("/dev/null", O_RDWR);
+      if (dev_null_fd >= 0)
+        {
+          dup2 (dev_null_fd, STDIN_FILENO);
+          dup2 (dev_null_fd, STDOUT_FILENO);
+          dup2 (dev_null_fd, STDERR_FILENO);
+          close (dev_null_fd);
+        }
+      else
+        {
+          g_warning ("Error opening /dev/null: %m");
+        }
+    }
+
+
+  loop = g_main_loop_new (NULL, FALSE);
+
+  sigint_id = g_unix_signal_add (SIGINT,
+                                 on_sigint,
+                                 NULL);
+
+  name_owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
+                                  "org.freedesktop.PolicyKit1",
+                                  G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
+                                    (opt_replace ? G_BUS_NAME_OWNER_FLAGS_REPLACE : 0),
+                                  on_bus_acquired,
+                                  on_name_acquired,
+                                  on_name_lost,
+                                  NULL,
+                                  NULL);
+
+  g_print ("Entering main event loop\n");
+  g_main_loop_run (loop);
+
+  ret = 0;
+
+  g_print ("Shutting down\n");
+ out:
+  if (sigint_id > 0)
+    g_source_remove (sigint_id);
+  if (name_owner_id != 0)
+    g_bus_unown_name (name_owner_id);
+  if (registration_id != NULL)
+    polkit_backend_authority_unregister (registration_id);
+  if (authority != NULL)
+    g_object_unref (authority);
+  if (loop != NULL)
+    g_main_loop_unref (loop);
+  if (opt_context != NULL)
+    g_option_context_free (opt_context);
+
+  g_print ("Exiting with code %d\n", ret);
+  return ret;
+}
diff --git a/src/polkitd/Makefile.am b/src/polkitd/Makefile.am
deleted file mode 100644
index 8132fa7..0000000
--- a/src/polkitd/Makefile.am
+++ /dev/null
@@ -1,40 +0,0 @@
-NULL =
-
-INCLUDES =                                              		\
-	-I$(top_builddir)/src                           		\
-	-I$(top_srcdir)/src                             		\
-	-DPACKAGE_LIBEXEC_DIR=\""$(libexecdir)"\"       		\
-	-DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\"       		\
-	-DPACKAGE_DATA_DIR=\""$(datadir)"\"             		\
-	-DPACKAGE_BIN_DIR=\""$(bindir)"\"               		\
-	-DPACKAGE_LOCALSTATE_DIR=\""$(localstatedir)"\" 		\
-	-DPACKAGE_LOCALE_DIR=\""$(localedir)"\"         		\
-	-DPACKAGE_LIB_DIR=\""$(libdir)"\"               		\
-	-D_POSIX_PTHREAD_SEMANTICS                      		\
-	-D_REENTRANT	                                		\
-	$(NULL)
-
-libprivdir = $(prefix)/lib/polkit-1
-libpriv_PROGRAMS = polkitd
-
-polkitd_SOURCES = 							\
-					main.c				\
-	$(NULL)
-
-polkitd_CFLAGS = 							\
-	-DPOLKIT_BACKEND_I_KNOW_API_IS_SUBJECT_TO_CHANGE		\
-	-DG_LOG_DOMAIN=\"polkitd-1\"					\
-	$(GLIB_CFLAGS)							\
-	$(NULL)
-
-polkitd_LDADD = 				        		\
-	$(DBUS_GLIB_LIBS)						\
-	$(GLIB_LIBS)							\
-	$(top_builddir)/src/polkit/libpolkit-gobject-1.la		\
-	$(top_builddir)/src/polkitbackend/libpolkit-backend-1.la	\
-	$(NULL)
-
-CLEANFILES = $(BUILT_SOURCES)
-
-clean-local :
-	rm -f *~
diff --git a/src/polkitd/main.c b/src/polkitd/main.c
deleted file mode 100644
index f77a12f..0000000
--- a/src/polkitd/main.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Copyright (C) 2008-2010 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, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * Author: David Zeuthen <davidz at redhat.com>
- */
-
-#include "config.h"
-
-#include <signal.h>
-
-#include <glib-unix.h>
-
-#include <polkit/polkit.h>
-#include <polkitbackend/polkitbackend.h>
-
-/* ---------------------------------------------------------------------------------------------------- */
-
-static PolkitBackendAuthority *authority = NULL;
-static gpointer                registration_id = NULL;
-static GMainLoop              *loop = NULL;
-static gboolean                opt_replace = FALSE;
-static gboolean                opt_no_debug = FALSE;
-static GOptionEntry            opt_entries[] = {
-  {"replace", 'r', 0, G_OPTION_ARG_NONE, &opt_replace, "Replace existing daemon", NULL},
-  {"no-debug", 'n', 0, G_OPTION_ARG_NONE, &opt_no_debug, "Don't print debug information", NULL},
-  {NULL }
-};
-
-static void
-on_bus_acquired (GDBusConnection *connection,
-                 const gchar     *name,
-                 gpointer         user_data)
-{
-  GError *error;
-
-  g_print ("Connected to the system bus\n");
-
-  g_assert (authority == NULL);
-  g_assert (registration_id == NULL);
-
-  authority = polkit_backend_authority_get ();
-  g_print ("Using authority class %s\n", g_type_name (G_TYPE_FROM_INSTANCE (authority)));
-
-  error = NULL;
-  registration_id = polkit_backend_authority_register (authority,
-                                                       connection,
-                                                       "/org/freedesktop/PolicyKit1/Authority",
-                                                       &error);
-  if (registration_id == NULL)
-    {
-      g_printerr ("Error registering authority: %s\n", error->message);
-      g_error_free (error);
-      g_main_loop_quit (loop); /* exit */
-    }
-}
-
-static void
-on_name_lost (GDBusConnection *connection,
-              const gchar     *name,
-              gpointer         user_data)
-{
-  g_print ("Lost the name org.freedesktop.PolicyKit1 - exiting\n");
-  g_main_loop_quit (loop);
-}
-
-static void
-on_name_acquired (GDBusConnection *connection,
-                  const gchar     *name,
-                  gpointer         user_data)
-{
-  g_print ("Acquired the name org.freedesktop.PolicyKit1\n");
-}
-
-static gboolean
-on_sigint (gpointer user_data)
-{
-  g_print ("Handling SIGINT\n");
-  g_main_loop_quit (loop);
-  return FALSE;
-}
-
-int
-main (int    argc,
-      char **argv)
-{
-  GError *error;
-  GOptionContext *opt_context;
-  gint ret;
-  guint name_owner_id;
-  guint sigint_id;
-
-  ret = 1;
-  loop = NULL;
-  opt_context = NULL;
-  name_owner_id = 0;
-  sigint_id = 0;
-  registration_id = NULL;
-
-  g_type_init ();
-
-  opt_context = g_option_context_new ("polkit authority");
-  g_option_context_add_main_entries (opt_context, opt_entries, NULL);
-  error = NULL;
-  if (!g_option_context_parse (opt_context, &argc, &argv, &error))
-    {
-      g_printerr ("Error parsing options: %s", error->message);
-      g_error_free (error);
-      goto out;
-    }
-
-  /* If --no-debug is requested don't clutter stdout/stderr etc.
-   */
-  if (opt_no_debug)
-    {
-      gint dev_null_fd;
-      dev_null_fd = open ("/dev/null", O_RDWR);
-      if (dev_null_fd >= 0)
-        {
-          dup2 (dev_null_fd, STDIN_FILENO);
-          dup2 (dev_null_fd, STDOUT_FILENO);
-          dup2 (dev_null_fd, STDERR_FILENO);
-          close (dev_null_fd);
-        }
-      else
-        {
-          g_warning ("Error opening /dev/null: %m");
-        }
-    }
-
-
-  loop = g_main_loop_new (NULL, FALSE);
-
-  sigint_id = g_unix_signal_add (SIGINT,
-                                 on_sigint,
-                                 NULL);
-
-  name_owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
-                                  "org.freedesktop.PolicyKit1",
-                                  G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
-                                    (opt_replace ? G_BUS_NAME_OWNER_FLAGS_REPLACE : 0),
-                                  on_bus_acquired,
-                                  on_name_acquired,
-                                  on_name_lost,
-                                  NULL,
-                                  NULL);
-
-  g_print ("Entering main event loop\n");
-  g_main_loop_run (loop);
-
-  ret = 0;
-
-  g_print ("Shutting down\n");
- out:
-  if (sigint_id > 0)
-    g_source_remove (sigint_id);
-  if (name_owner_id != 0)
-    g_bus_unown_name (name_owner_id);
-  if (registration_id != NULL)
-    polkit_backend_authority_unregister (registration_id);
-  if (authority != NULL)
-    g_object_unref (authority);
-  if (loop != NULL)
-    g_main_loop_unref (loop);
-  if (opt_context != NULL)
-    g_option_context_free (opt_context);
-
-  g_print ("Exiting with code %d\n", ret);
-  return ret;
-}


More information about the hal-commit mailing list