From 473f084c56f6d94d094cdf46852f5371c5063a99 Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Fri, 6 Dec 2013 19:03:17 -0200 Subject: [PATCH] lightmediascannerctl: start daemon if not running. While the service would be activated if we did call some method we are checking for the current nameowner to do some operations (status, etc) and it would exit if there was no server at that time. Now we launch the service and make sure it's there. --- src/bin/lightmediascannerctl.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/bin/lightmediascannerctl.c b/src/bin/lightmediascannerctl.c index 8931f33..5764bc0 100644 --- a/src/bin/lightmediascannerctl.c +++ b/src/bin/lightmediascannerctl.c @@ -4,6 +4,47 @@ #include #include +static gboolean +start_service_by_name(void) +{ + GError *error = NULL; + GVariant *var; + GDBusConnection *conn; + + conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); + if (error) { + fprintf(stderr, "Could not get session bus connection: %s\n", + error->message); + g_error_free(error); + return FALSE; + } + + var = g_dbus_connection_call_sync(conn, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + "StartServiceByName", + g_variant_new("(su)", + "org.lightmediascanner", 0), + G_VARIANT_TYPE("(u)"), + G_DBUS_CALL_FLAGS_NONE, + 10000, + NULL, + &error); + g_object_unref(conn); + if (var) + g_variant_unref(var); + + if (error) { + fprintf(stderr, "Could not start org.lightmediascanner: %s\n", + error->message); + g_error_free(error); + return FALSE; + } + + return TRUE; +} + struct app { int ret; int argc; @@ -480,6 +521,9 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } + if (!start_service_by_name()) + return EXIT_FAILURE; + app.timer = NULL; app.loop = g_main_loop_new(NULL, FALSE); app.proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, -- 2.7.4