[jhbuild/wip/rootowned: 1/2] helpr bits
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [jhbuild/wip/rootowned: 1/2] helpr bits
- Date: Fri, 7 Oct 2011 15:09:50 +0000 (UTC)
commit f31838b37a434a72fd95eef87916818cc9fed85b
Author: Colin Walters <walters verbum org>
Date: Wed Oct 5 18:00:44 2011 -0400
helpr bits
configure.ac | 11 ++
jhbuild/Makefile.am | 5 +
jhbuild/jhbuild-install-helper.c | 216 ++++++++++++++++++++++++++++++++++++++
3 files changed, 232 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 357a7b1..39a097a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,6 +21,17 @@ AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE], "$GETTEXT_PACKAGE", [Gettext package])
AC_PROG_CC
PKG_PROG_PKG_CONFIG
+AC_ARG_ENABLE(
+ os-building,
+ AS_HELP_STRING([--enable-os-building=@<:@no/yes@:>@], [If specified, provide support for root-owned builds]),
+ [enable_os_building=$enableval],
+ [enable_os_building=no])
+
+if test x$enable_os_building = xyes; then
+ PKG_CHECK_MODULES(GIO_UNIX, [gio-unix-2.0])
+fi
+AM_CONDITIONAL(OS_BUILDING, test x$enable_os_building=xyes)
+
# Documentation
AC_ARG_ENABLE(
doc_installation,
diff --git a/jhbuild/Makefile.am b/jhbuild/Makefile.am
index cd5fde4..7c327fe 100644
--- a/jhbuild/Makefile.am
+++ b/jhbuild/Makefile.am
@@ -11,3 +11,8 @@ app_PYTHON = \
moduleset.py \
monkeypatch.py
+libexec_PROGRAMS = jhbuild-install-helper
+
+jhbuild_install_helper_SOURCES = jhbuild-install-helper.c
+jhbuild_install_helper_CFLAGS = $(GIO_UNIX_CFLAGS)
+jhbuild_install_helper_LIBS = $(GIO_UNIX_LIBS)
diff --git a/jhbuild/jhbuild-install-helper.c b/jhbuild/jhbuild-install-helper.c
new file mode 100644
index 0000000..b2598e1
--- /dev/null
+++ b/jhbuild/jhbuild-install-helper.c
@@ -0,0 +1,216 @@
+#include <glib.h>
+
+#ifdef G_OS_UNIX
+#include <gio/gunixfdlist.h>
+/* For STDOUT_FILENO */
+#include <unistd.h>
+#endif
+
+#ifndef JHBUILD_ROOT
+#error JHBUILD_ROOT must be specified
+#endif
+
+typedef struct {
+ GDBusConnection *system_bus;
+
+ char *root;
+} JhbuildInstallHelper;
+
+static GDBusNodeInfo *introspection_data = NULL;
+
+static const gchar introspection_xml[] =
+ "<node>"
+ " <interface name='org.gnome.JhbuildInstallHelper'>"
+ " <method name='RootRebase'>"
+ " <annotation name='org.gtk.GDBus.Annotation' value='OnMethod'/>"
+ " <arg type='s' name='rootid' direction='in'/>"
+ " </method>"
+ " <method name='RootUpdateWithArtifact'>"
+ " <annotation name='org.gtk.GDBus.Annotation' value='OnMethod'/>"
+ " <arg type='s' name='rootid' direction='in'/>"
+ " <arg type='h' name='tardata' direction='in'/>"
+ " </method>"
+ " </interface>"
+ "</node>";
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+handle_method_call (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ if (g_strcmp0 (method_name, "HelloWorld") == 0)
+ {
+ const gchar *greeting;
+
+ g_variant_get (parameters, "(&s)", &greeting);
+
+ if (g_strcmp0 (greeting, "Return Unregistered") == 0)
+ {
+ g_dbus_method_invocation_return_error (invocation,
+ G_IO_ERROR,
+ G_IO_ERROR_FAILED_HANDLED,
+ "As requested, here's a GError not registered (G_IO_ERROR_FAILED_HANDLED)");
+ }
+ else if (g_strcmp0 (greeting, "Return Registered") == 0)
+ {
+ g_dbus_method_invocation_return_error (invocation,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_MATCH_RULE_NOT_FOUND,
+ "As requested, here's a GError that is registered (G_DBUS_ERROR_MATCH_RULE_NOT_FOUND)");
+ }
+ else if (g_strcmp0 (greeting, "Return Raw") == 0)
+ {
+ g_dbus_method_invocation_return_dbus_error (invocation,
+ "org.gtk.GDBus.SomeErrorName",
+ "As requested, here's a raw D-Bus error");
+ }
+ else
+ {
+ gchar *response;
+ response = g_strdup_printf ("You greeted me with '%s'. Thanks!", greeting);
+ g_dbus_method_invocation_return_value (invocation,
+ g_variant_new ("(s)", response));
+ g_free (response);
+ }
+ }
+ else if (g_strcmp0 (method_name, "EmitSignal") == 0)
+ {
+ GError *local_error;
+ gdouble speed_in_mph;
+ gchar *speed_as_string;
+
+ g_variant_get (parameters, "(d)", &speed_in_mph);
+ speed_as_string = g_strdup_printf ("%g mph!", speed_in_mph);
+
+ local_error = NULL;
+ g_dbus_connection_emit_signal (connection,
+ NULL,
+ object_path,
+ interface_name,
+ "VelocityChanged",
+ g_variant_new ("(ds)",
+ speed_in_mph,
+ speed_as_string),
+ &local_error);
+ g_assert_no_error (local_error);
+ g_free (speed_as_string);
+
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ }
+ else if (g_strcmp0 (method_name, "GimmeStdout") == 0)
+ {
+#ifdef G_OS_UNIX
+ if (g_dbus_connection_get_capabilities (connection) & G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING)
+ {
+ GDBusMessage *reply;
+ GUnixFDList *fd_list;
+ GError *error;
+
+ fd_list = g_unix_fd_list_new ();
+ error = NULL;
+ g_unix_fd_list_append (fd_list, STDOUT_FILENO, &error);
+ g_assert_no_error (error);
+
+ reply = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation));
+ g_dbus_message_set_unix_fd_list (reply, fd_list);
+
+ error = NULL;
+ g_dbus_connection_send_message (connection,
+ reply,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+ NULL, /* out_serial */
+ &error);
+ g_assert_no_error (error);
+
+ g_object_unref (invocation);
+ g_object_unref (fd_list);
+ g_object_unref (reply);
+ }
+ else
+ {
+ g_dbus_method_invocation_return_dbus_error (invocation,
+ "org.gtk.GDBus.Failed",
+ "Your message bus daemon does not support file descriptor passing (need D-Bus >= 1.3.0)");
+ }
+#else
+ g_dbus_method_invocation_return_dbus_error (invocation,
+ "org.gtk.GDBus.NotOnUnix",
+ "Your OS does not support file descriptor passing");
+#endif
+ }
+}
+
+static void
+on_bus_acquired (GDBusConnection *connection,
+ const char *name,
+ gpointer user_data)
+{
+ JhbuildInstallHelper *helper = user_data;
+
+ helper->system_bus = g_object_ref (connection);
+}
+
+static void
+on_name_acquired (GDBusConnection *connection,
+ const char *name,
+ gpointer user_data)
+{
+ JhbuildInstallHelper *helper = user_data;
+
+
+}
+
+static void
+on_name_lost (GDBusConnection *connection,
+ const char *name,
+ gpointer user_data)
+{
+ JhbuildInstallHelper *helper = user_data;
+
+
+}
+
+static void
+install_helper_run (JhbuildInstallHelper *helper)
+{
+ GError *error = NULL;
+
+ helper->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (!helper->system_bus)
+ g_error ("%s", error->message);
+
+ g_bus_own_name (G_BUS_TYPE_SYSTEM,
+ "org.gnome.JhbuildInstallHelper",
+ G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
+ on_bus_acquired,
+ on_name_acquired,
+ on_name_lost,
+ helper,
+ NULL);
+}
+
+int
+main (int argc,
+ char **argv,
+ char **envp)
+{
+ GMainLoop *loop;
+ JhbuildInstallHelper helper;
+
+ g_type_init ();
+
+ loop = g_main_loop_new (NULL, TRUE);
+
+ install_helper_run (&helper);
+
+ g_main_loop_run (loop);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]