From: Sam Hartman Date: Tue, 19 Mar 2013 13:30:09 +0000 (-0400) Subject: libmoonshot: spawn moonshot-dbus-launch X-Git-Tag: 0.7.1~105 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=moonshot-ui.git;a=commitdiff_plain;h=1156eacaa3d16adacf2326af61d9260340aa9132 libmoonshot: spawn moonshot-dbus-launch Call the moonshot-dbus-launch script to attempt to set up a session bus. Connect to address written on stdout. --- diff --git a/Makefile.am b/Makefile.am index 20e3434..697676f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,11 +9,12 @@ bin_PROGRAMS = \ src/moonshot \ src/moonshot-webp -AM_CFLAGS = -g -O0 +AM_CFLAGS = -g -O0 -Wall -AM_CPPFLAGS = -g -O0 \ +AM_CPPFLAGS = \ -include config.h \ -DLOCALEDIR=\""$(localedir)"\" \ + -DMOONSHOT_LAUNCH_SCRIPT='"$(pkglibexecdir)/moonshot-dbus-launch"' \ -I$(top_srcdir)/libmoonshot \ -I$(top_builddir)/libmoonshot diff --git a/libmoonshot/libmoonshot-dbus.c b/libmoonshot/libmoonshot-dbus.c index 0121cb7..7287291 100644 --- a/libmoonshot/libmoonshot-dbus.c +++ b/libmoonshot/libmoonshot-dbus.c @@ -33,6 +33,8 @@ */ #include +#include +#include #include #include #include @@ -63,12 +65,44 @@ void moonshot_free (void *data) { g_free (data); } +static char *moonshot_launch_argv[] = { + MOONSHOT_LAUNCH_SCRIPT, NULL +}; static DBusConnection *dbus_launch_moonshot() { - return NULL; + DBusConnection *connection = NULL; + DBusError dbus_error; + GPid child_pid; + gint fd_stdin = -1, fd_stdout = -1; + ssize_t addresslen; + char dbus_address[1024]; + + if (g_spawn_async_with_pipes( NULL /*cwd*/, + moonshot_launch_argv, NULL /*environ*/, + 0 /*flags*/, NULL /*setup*/, NULL, + &child_pid, &fd_stdin, &fd_stdout, + NULL /*stderr*/, NULL /*error*/) == 0 ) { + return NULL; + } + addresslen = read( fd_stdout, dbus_address, sizeof dbus_address); + /* we require at least 2 octets of address because we trim the newline*/ + if (addresslen <= 1) { + fail: close(fd_stdin); + close(fd_stdout); + g_spawn_close_pid(child_pid); + return NULL; + } + dbus_error_init(&dbus_error); + dbus_address[addresslen-1] = '\0'; + connection = dbus_connection_open(dbus_address, &dbus_error); + if (dbus_error_is_set(&dbus_error)) { + dbus_error_free(&dbus_error); + goto fail; + } else return connection; } + static DBusGProxy *dbus_connect (MoonshotError **error) { DBusConnection *connection;