Switch from libsystemd to glib 60/214360/4 accepted/tizen_5.5_unified_mobile_hotfix accepted/tizen_5.5_unified_wearable_hotfix tizen_5.5_mobile_hotfix tizen_5.5_tv tizen_5.5_wearable_hotfix accepted/tizen/5.5/unified/20191031.022213 accepted/tizen/5.5/unified/mobile/hotfix/20201027.090057 accepted/tizen/5.5/unified/wearable/hotfix/20201027.112750 accepted/tizen/unified/20191009.231758 submit/tizen/20191009.095955 submit/tizen_5.5/20191031.000004 submit/tizen_5.5_mobile_hotfix/20201026.185104 submit/tizen_5.5_wearable_hotfix/20201026.184304 tizen_5.5.m2_release
authorMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Mon, 2 Sep 2019 08:58:46 +0000 (10:58 +0200)
committerMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Tue, 8 Oct 2019 14:26:59 +0000 (16:26 +0200)
Change-Id: Ibe5d385ff53996126f0eb39443ae0a57dc7061c2
Signed-off-by: Maciej Slodczyk <m.slodczyk2@partner.samsung.com>
Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
12 files changed:
Makefile.am
include/systemd_dbus.h
packaging/activationd.spec
src/core/service.c
src/epc.c
src/listeners/unit_control_api.c
src/util/systemd_dbus.c
tests/activationd_acceptance_checker.c
tests/activationd_acceptance_tests.c
tests/activationd_acceptance_tests.h
tests/activationd_acceptance_tests_dbus_signal.c
tests/activationd_acceptance_tests_unit_control.c

index 03010a003b371f70d423b418c13f56f8ca42c9aa..2b351431b032e3d40ebccb026caf4814099be272 100644 (file)
@@ -228,7 +228,7 @@ activationd_acceptance_checker_SOURCES = \
        tests/activationd_acceptance_checker.c
 
 activationd_acceptance_checker_CFLAGS = $(AM_CFLAGS)
-activationd_acceptance_checker_LDFLAGS = $(VCONF_LIBS) $(LIBSYSTEMD_LIBS)
+activationd_acceptance_checker_LDFLAGS = $(VCONF_LIBS) $(LIBSYSTEMD_LIBS) $(GLIB_LIBS) $(GIO_LIBS)
 
 bin_PROGRAMS += activationd_acceptance_service
 
index c9101cbaa605c8c7aa0f89d113e2099761bffba7..e387f3504ee95fa93328332f0ed7737eddff18ce 100644 (file)
@@ -55,7 +55,4 @@ int epc_dbus_call_async(char *service, char *obj, char *interface, char *method,
        epc_dbus_call_simple_async(SYSTEMD_SERVICE, OBJ, INTF, METHOD, CB, DATA,          \
                                                        ARGS, ##__VA_ARGS__)
 
-int epc_acquire_systemd_bus(sd_bus **bus);
-void epc_set_systemd_private(bool);
-
 #endif /* EPC_SYSTEMD_DBUS_H */
index cba5ec615cd11dd1f2dff7031b59a29129330f7b..2aec0bb3c8506d3664e6a795b13697e2d55d2be5 100644 (file)
@@ -74,6 +74,7 @@ This package provides a decision maker for activating systemd units based on var
 Summary:    activationd test services
 Group:      System/Monitoring
 BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(glib-2.0)
 Requires:   event-processing-core
 
 %description -n activationd-test-services
index 285fea704ce59e5e6dd8d4e49c0fc322333de3dc..574c6e1ecd5b4c604d2f1f7e9bca9995cf4de89e 100644 (file)
@@ -26,6 +26,7 @@
 #include <systemd/sd-bus.h>
 #include <json-c/json.h>
 #include <unistd.h>
+#include <libsyscommon/dbus-system.h>
 
 #include "log.h"
 #include "service.h"
@@ -50,33 +51,21 @@ int systemd_service_init_by_pid(pid_t pid, struct systemd_service *s)
 
 static int get_service_name(const char *dbus_path, char **service_name)
 {
-       _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
-       _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
-       _cleanup_free_ char *name = NULL;
-       int ret;
+       GVariant *reply = dbus_handle_method_sync_with_reply_var("org.freedesktop.systemd1",
+                                                       dbus_path,
+                                                       "org.freedesktop.DBus.Properties",
+                                                       "Get",
+                                                       g_variant_new("ss", "org.freedesktop.systemd1.Unit", "Id"));
 
-       ret = epc_acquire_systemd_bus(&bus);
-       if (ret < 0) {
-               log_error_errno(ret, "Failed to acquire the default system bus connection: %m.");
-               return ret;
-       }
 
-       ret = sd_bus_get_property_string(bus,
-                                                                        "org.freedesktop.systemd1",
-                                                                        dbus_path,
-                                                                        "org.freedesktop.systemd1.Unit",
-                                                                        "Id",
-                                                                        &error,
-                                                                        &name);
-       if (ret < 0) {
-               log_error("Failed to get \"Id\" property of %s: %s",
-                                 dbus_path, error.message);
-               return ret;
+       if (!reply) {
+               log_error("Failed to get \"Id\" property of %s", dbus_path);
+               return -ENOMEM;
        }
 
-       log_debug("Service Id: %s", name);
+       g_variant_get(reply, "(s)", service_name);
+       g_variant_unref(reply);
 
-       *service_name = strdup(name);
        if (*service_name == NULL) {
                log_error("Unable to allocate string");
                return -ENOMEM;
@@ -140,41 +129,28 @@ void systemd_service_cleanup(struct systemd_service *s)
 
 int systemd_get_unit_by_pid(pid_t pid, const char **name)
 {
-       _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
-       _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
-       _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
-       const char *unit;
-       int rc;
+       GVariant *reply;
 
        assert(name);
 
-       rc = epc_acquire_systemd_bus(&bus);
-       if (rc < 0) {
-               log_error_errno(rc, "Failed to acquire the defult system bus connection: %m.");
-               return rc;
-       }
-
-       rc = sd_bus_call_method(bus,
-                                                       SYSTEMD_SERVICE,
+       reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_SERVICE,
                                                        SYSTEMD_OBJ,
                                                        SYSTEMD_MANAGER_INTERFACE,
-                                                       "GetUnitByPID",                     /* method */
-                                                       &error,                             /* place to store error */
-                                                       &m,                                 /* place to store answer */
-                                                       "u",                                /* input signature */
-                                                       pid);                               /* input argument */
-       if (rc < 0) {
-               log_error("Failed to issue \"GetUnitByPID\" method call: %s.", error.message);
-               return rc;
-       }
+                                                       "GetUnitByPID",
+                                                       g_variant_new("u", pid));
 
-       rc = sd_bus_message_read(m, "o", &unit);
-       if (rc < 0) {
-               log_error_errno(rc, "Failed to parse response message: %m.");
-               return rc;
+       if (!reply) {
+               log_error("Failed to issue \"GetUnitByPID\" method call.");
+               return -1;
        }
 
-       *name = strdup(unit);
+       g_variant_get(reply, "(o)", name);
+       g_variant_unref(reply);
+
+       if (*name == NULL) {
+               log_error("Unable to allocate string");
+               return -ENOMEM;
+       }
 
        return 0;
 }
index 3e1f88dae4cbdc6f201a0c27470c764ad573aa09..98e5e131d18b5dc856dbef7c7c5c800d60e03167 100644 (file)
--- a/src/epc.c
+++ b/src/epc.c
 #include <json-c/json.h>
 #include <stdio.h>
 #include <poll.h>
-#include <systemd/sd-bus.h>
 #include <systemd/sd-event.h>
 #include <signal.h>
 #include <syslog.h>
 #include <unistd.h>
+#include <libsyscommon/dbus-system.h>
 
 #include "log.h"
 #include "module.h"
@@ -70,7 +70,6 @@ static void print_help(const char *name)
        switch (running_mode) {
        case EPC_MODE_NORMAL:
                printf("  -d, --disable-module <module>  Disable <module>\n"
-                          "  --systemd-private              Use private connection to systemd\n"
                           "  --no-action                    Do not execute any action\n");
                break;
 
@@ -95,13 +94,11 @@ static int parse_argv(int ac, char *av[])
        enum {
                ARG_LOG_LEVEL = 0x100,
                ARG_NO_ACTION,
-               ARG_PRIVATE,
        };
 
        static const struct option options[] = {
                {"log-level", required_argument, NULL, ARG_LOG_LEVEL},
                {"disable-module", required_argument, NULL, 'd'},
-               {"systemd-private", no_argument, NULL, ARG_PRIVATE},
                {"no-action", no_argument, NULL, ARG_NO_ACTION},
                {"config-file", required_argument, NULL, 'c'},
                {"help", no_argument, NULL, 'h'},
@@ -156,9 +153,6 @@ static int parse_argv(int ac, char *av[])
                        epc_disable_module_category(EPC_MODULE_TYPE_ACTION);
                        break;
 
-               case ARG_PRIVATE:
-                       epc_set_systemd_private(true);
-                       break;
 
                default:
                        print_help(av[0]);
@@ -173,7 +167,6 @@ static int parse_argv(int ac, char *av[])
 int main(int ac, char *av[])
 {
        int rc;
-       sd_bus *bus = NULL;
        sd_event *loop;
        sigset_t ss;
        struct epc_config *modules_config = NULL;
@@ -192,12 +185,6 @@ int main(int ac, char *av[])
                return -1;
        }
 
-       rc = epc_acquire_systemd_bus(&bus);
-       if (rc < 0) {
-               log_error_errno(rc, "Failed to acquire the default system bus connection: %m");
-               return -1;
-       }
-
        rc = sd_event_new(&loop);
        if (rc < 0) {
                log_error_errno(rc, "Failed to allocate the event loop.");
@@ -205,7 +192,6 @@ int main(int ac, char *av[])
        }
 
        /* If there is way to register a catch-all handler */
-       /* sd_bus_attach_event(bus, loop, SD_EVENT_PRIORITY_NORMAL); */
        sigemptyset(&ss);
        sigaddset(&ss, SIGINT);
        sigaddset(&ss, SIGTERM);
@@ -290,8 +276,6 @@ int main(int ac, char *av[])
        epc_modules_cleanup();
        epc_config_cleanup_global();
 
-       sd_bus_close(bus);
-
        rc = epc_call_at_exit();
 
        epc_modules_unload();
index cb6e944d3df93a3c65d5d7112420e044727a7a43..1ffbc807b8d99068c2627fa8384fba10f77da3d9 100644 (file)
@@ -48,7 +48,9 @@ static GVariant *method_generic_callback(GVariant *param, GDBusMethodInvocation
 
        if (!g_variant_is_of_type(param, STRING_VARIANT)) {
                log_error("Invalid parameter type passed to %s method.  "
-                         "Expected: (s), got: %s\n", method, g_variant_get_type_string(param));
+                         "Expected: (s), got: %s - %s\n", method,
+                         g_variant_get_type_string(param),
+                         g_variant_print(param, TRUE));
                r = -EINVAL;
                goto fail;
        }
index 5bf992aac8bcd5c44ba56d6467fafd04c84e10de..2379f0a89abc2de19fb7ddc8e7557b8c01fb25ea 100644 (file)
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <errno.h>
-#include <libsyscommon/dbus-system.h>
 
 #include "common.h"
 #include "systemd_dbus.h"
 #include "log.h"
 
-static sd_bus *systemd_bus = NULL;
-static bool epc_systemd_private = false;
 
 int epc_dbus_call_async(char *service, char *obj, char *interface, char *method,
                                         epc_dbus_handler_t cb,
@@ -73,58 +70,3 @@ int epc_dbus_call(char *service, char *obj, char *interface, char *method,
 
        return dbus_handle_method_sync_var(service, obj, interface, method, var);
 }
-
-static int get_bus_by_address(const char *addr, sd_bus **bus)
-{
-       _cleanup_(sd_bus_unrefp) sd_bus *rbus = NULL;
-       int ret;
-
-       ret = sd_bus_new(&rbus);
-       if (ret < 0)
-               return ret;
-
-       ret = sd_bus_set_address(rbus, addr);
-       if (ret < 0)
-               return ret;
-
-       ret = sd_bus_start(rbus);
-       if (ret < 0)
-               return ret;
-
-       *bus = rbus;
-       rbus = NULL;
-       return 0;
-}
-
-int epc_acquire_systemd_bus(sd_bus **bus)
-{
-       int ret;
-
-       if (systemd_bus) {
-               *bus = systemd_bus;
-               sd_bus_ref(systemd_bus);
-               return 0;
-       }
-
-       if (!epc_systemd_private) {
-               ret = sd_bus_open_system(bus);
-               if (ret < 0)
-                       return ret;
-       } else {
-               ret = get_bus_by_address(SYSTEMD_KERNEL_BUS, bus);
-               if (ret < 0) {
-                       ret = get_bus_by_address(SYSTEMD_PRIVATE_BUS, bus);
-                       if (ret < 0)
-                               return ret;
-               }
-       }
-
-       systemd_bus = *bus;
-
-       return 0;
-}
-
-void epc_set_systemd_private(bool priv)
-{
-       epc_systemd_private = priv;
-}
index 3d109f35c45adcc64e58a0fa881d4d45d569265f..91c2bc79897de5dd38d407fb958887578194da13 100644 (file)
@@ -21,6 +21,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/timerfd.h>
+#include <glib.h>
+#include <glib-unix.h>
 
 #include "common.h"
 #include "systemd_dbus.h"
@@ -465,95 +467,114 @@ static const char *test_result(int r)
 
 static void cleanup(struct test_data *data)
 {
-       for (int i = 0; i < data->tests_count; i++)
+       GError *err = NULL;
+
+       for (int i = 0; i < data->tests_count; i++) {
+               if (data->tests[i].subscription_id > 0)
+                       g_dbus_connection_signal_unsubscribe(data->bus, data->tests[i].subscription_id);
                free(data->tests[i].path);
+       }
+
+       for (int i = 0; i < 4; ++i) {
+               if (data->event_sources[i] > 0)
+                       g_source_remove(data->event_sources[i]);
+       }
+
        if (!data->bus)
                return;
-       sd_bus_flush(data->bus);
-       sd_bus_unref(data->bus);
+
+       g_dbus_connection_close_sync(data->bus, NULL, &err);
+       if (err) {
+               fprintf(stderr, "error closing connection: %s\n", err->message);
+               g_error_free(err);
+       }
+       g_object_unref(data->bus); /* TODO: really necessary?? */
 }
 
-static int signal_handler(sd_event_source *s,
-               const struct signalfd_siginfo *si,
-               void *userdata)
+
+static gboolean signal_handler (gpointer userdata)
 {
-       sd_event *loop = userdata;
-       sd_event_exit(loop, EXIT_FAILURE);
-       return 0;
+       struct test_data *data = (struct test_data*)userdata;
+       g_main_loop_quit(data->loop);
+       return G_SOURCE_CONTINUE;
 }
 
-static int start(sd_event_source *s, uint64_t usec, void *userdata)
+static gboolean start(gpointer userdata)
 {
        struct test_data *data = (struct test_data*)userdata;
-       return start_test(data);
+       start_test(data);
+       data->event_sources[2] = 0; /* reset event source as we won't use it anymore */
+       return FALSE;
 }
 
-static int timeout_handler(sd_event_source *s, uint64_t usec, void *userdata)
+static gboolean timeout_handler(gpointer userdata)
 {
        struct test_data *data = (struct test_data*)userdata;
        fprintf(stderr, "test timed out\n");
-       sd_event_exit(data->loop, EXIT_FAILURE);
-       return 0;
+       g_main_loop_quit(data->loop);
+       return G_SOURCE_CONTINUE;
 }
 
 static int call_subscribe(struct test_data *data)
 {
-       __attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL;
-       __attribute__((cleanup(sd_bus_error_free))) sd_bus_error error = SD_BUS_ERROR_NULL;
-       int ret;
+       GVariant *msg = NULL;
+       GError *error = NULL;
 
-       ret = sd_bus_call_method(data->bus,
+       /* load unit/get path */
+       msg = g_dbus_connection_call_sync(data->bus,
                        SYSTEMD_SERVICE,
                        SYSTEMD_OBJ,
                        SYSTEMD_MANAGER_INTERFACE,
                        "Subscribe",
-                       &error,
-                       &reply,
-                       "");
-
-       if (ret < 0) {
-               fprintf(stderr, "Failed to issue Subscribe() call: %s\n", error.message);
-               return -1;
+                       NULL,
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       10000,
+                       NULL,
+                       &error);
+       if (error) {
+               fprintf(stderr, "Subscribe method call error: %s\n", error->message);
+               g_error_free(error);
+               return -EINVAL;
        }
+       g_variant_unref(msg);
        return 0;
 }
 
 static int call_load_unit(struct test_data *data)
 {
-       __attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL;
-       __attribute__((cleanup(sd_bus_error_free))) sd_bus_error error = SD_BUS_ERROR_NULL;
-       int ret;
-       const char *path = NULL;
-       char err[512];
+       GVariant *msg = NULL;
+       GError *error = NULL;
+       gchar *path = NULL;
 
+       /*load unit/get path */
        for (int i = 0; i < data->tests_count; i++) {
-               ret = sd_bus_call_method(data->bus,
+               msg = g_dbus_connection_call_sync(data->bus,
                                SYSTEMD_SERVICE,
                                SYSTEMD_OBJ,
                                SYSTEMD_MANAGER_INTERFACE,
                                "LoadUnit",
-                               &error,
-                               &reply,
-                               "s",
-                               data->tests[i].unit);
-
-               if (ret < 0) {
-                       fprintf(stderr, "Failed to issue LoadUnit() call: %s\n", error.message);
-                       return -1;
-               }
-
-               ret = sd_bus_message_read(reply, "o", &path);
-               if (ret < 0) {
-                       if (strerror_r(-ret, err, sizeof err))
-                               fprintf(stderr, "Failed to read reply: %s\n", err);
-                       return -1;
+                               g_variant_new("(s)", data->tests[i].unit),
+                               NULL,
+                               G_DBUS_CALL_FLAGS_NONE,
+                               10000,
+                               NULL,
+                               &error);
+               if (error) {
+                       fprintf(stderr, "Failed to issue LoadUnit() call: %s\n", error->message);
+                       g_error_free(error);
+                       return -EINVAL;
                }
 
+               g_variant_get(msg, "(o)", &path);
                if (!path) {
-                       fprintf(stderr, "could not get object path\n");
-                       return -1;
+                       fprintf(stderr, "Failed to read LoadUnit() reply\n");
+                       return -EINVAL;
                }
                data->tests[i].path = strdup(path);
+
+               g_free(path);
+               g_variant_unref(msg);
        }
        return 0;
 }
@@ -611,17 +632,17 @@ int main(int argc, char *argv[])
        struct test_data data = {
                .bus = NULL,
                .loop = NULL,
-               .step_timer = NULL,
+               .step_timer = 0,
+               .event_sources = {0, 0, 0, 0},
                .state = UNKNOWN,
                .prev_state = UNKNOWN,
                .current_test = 0
        };
 
+       GError *g_err;
        int test_type;
        int r;
-       uint64_t now;
        sigset_t ss;
-       char buf[512];
        char err[512];
 
        r = parse_cmdline(argc, argv, &test_type);
@@ -644,10 +665,11 @@ int main(int argc, char *argv[])
                goto fail;
        }
 
-       r = sd_bus_open_system(&data.bus);
-       if (r < 0) {
-               if (strerror_r(-r, err, sizeof err))
-                       fprintf(stderr, "Failed to read reply: %s\n", err);
+       g_err = NULL;
+       data.bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &g_err);
+       if (g_err) {
+               fprintf(stderr, "Failed to open bus: %s\n", g_err->message);
+               g_error_free(g_err);
                goto fail;
        }
 
@@ -660,25 +682,28 @@ int main(int argc, char *argv[])
                goto fail;
 
        for (int i = 0; i < data.tests_count; i++) {
-               r = snprintf(buf, sizeof buf, "type='signal',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged', path='%s'", data.tests[i].path);
-               if (r < 0) {
-                       if (strerror_r(-r, err, sizeof err))
-                               fprintf(stderr, "Failed to create match rule: %s\n", err);
-                       goto fail;
-               }
-
-               r = sd_bus_add_match(data.bus, NULL, buf, on_properties_changed, &data);
-               if (r < 0) {
-                       if (strerror_r(-r, err, sizeof err))
-                               fprintf(stderr, "Failed to add PropertiesChanged match: %s\n", err);
+               data.tests[i].subscription_id = g_dbus_connection_signal_subscribe(
+                                       data.bus,
+                                       NULL,
+                                       "org.freedesktop.DBus.Properties",
+                                       "PropertiesChanged",
+                                       data.tests[i].path,
+                                       NULL,
+                                       G_DBUS_SIGNAL_FLAGS_NONE,
+                                       on_properties_changed,
+                                       &data,
+                                       NULL
+                               );
+
+               if (data.tests[i].subscription_id == 0) {
+                       fprintf(stderr, "Failed to add PropertiesChanged match\n");
                        goto fail;
                }
        }
 
-       r = sd_event_new(&data.loop);
-       if (r < 0) {
-               if (strerror_r(-r, err, sizeof err))
-                       fprintf(stderr, "Failed to create main loop: %s\n", err);
+       data.loop = g_main_loop_new (NULL, FALSE);
+       if (!data.loop) {
+               fprintf(stderr, "Failed to create main loop\n");
                goto fail;
        }
 
@@ -692,50 +717,32 @@ int main(int argc, char *argv[])
                goto fail;
        }
 
-       r = sd_event_add_signal(data.loop, NULL, SIGINT, signal_handler, data.loop);
-       if (r < 0) {
-               if (strerror_r(-r, err, sizeof err))
-                       fprintf(stderr, "Failed to register SIGINT handler: %s\n", err);
+       data.event_sources[0] = g_unix_signal_add(SIGINT, signal_handler, &data);
+       if (data.event_sources[0] == 0) {
+               fprintf(stderr, "Failed to register SIGINT handler\n");
                goto fail;
        }
 
-       r = sd_event_add_signal(data.loop, NULL, SIGTERM, signal_handler, data.loop);
-       if (r < 0) {
-               if (strerror_r(-r, err, sizeof err))
-                       fprintf(stderr, "Failed to register SIGTERM handler: %s\n", err);
+       data.event_sources[1] = g_unix_signal_add(SIGTERM, signal_handler, &data);
+       if (data.event_sources[1] == 0) {
+               fprintf(stderr, "Failed to register SIGTERM handler\n");
                goto fail;
        }
 
-       r = sd_bus_attach_event(data.bus, data.loop, 0);
-       if (r < 0) {
-               if (strerror_r(-r, err, sizeof err))
-                       fprintf(stderr, "Failed to attach bus to event loop: %s\n", err);
-               goto fail;
-       }
-
-       r = sd_event_add_time(data.loop, NULL, CLOCK_REALTIME, 0, 0, start, &data);
-       if (r < 0) {
-               if (strerror_r(-r, err, sizeof err))
-                       fprintf(stderr, "Failed to attach timer to event loop: %s\n", err);
+       data.event_sources[2] = g_timeout_add_seconds(1, start, &data);
+       if (data.event_sources[2] == 0) {
+               fprintf(stderr, "Failed to attach timer to event loop\n");
                goto fail;
        }
 
        /* time out all tests after 30sec */
-       sd_event_now(data.loop, CLOCK_REALTIME, &now);
-
-       r = sd_event_add_time(data.loop, NULL, CLOCK_REALTIME, now+30000000, 0, timeout_handler, &data);
-       if (r < 0) {
-               if (strerror_r(-r, err, sizeof err))
-                       fprintf(stderr, "Failed to attach timer to event loop: %s\n", err);
+       data.event_sources[3] = g_timeout_add_seconds(30, timeout_handler, &data);
+       if (data.event_sources[3] == 0) {
+               fprintf(stderr, "Failed to attach timer to event loop\n");
                goto fail;
        }
 
-       r = sd_event_loop(data.loop);
-       if (r < 0) {
-               if (strerror_r(-r, err, sizeof err))
-                       fprintf(stderr, "Failed to run main loop: %s\n", err);
-               goto fail;
-       }
+       g_main_loop_run(data.loop);
 
        r = print_results(&data);
        cleanup(&data);
index 2cc7e1510205773c98f7d2dd30c036282f9c8331..a3f5279a7ff6117de688891d0aeef189c5ab1433 100644 (file)
@@ -56,18 +56,16 @@ static void next_test(struct test_data *data)
 
 static void stop_test_step_timeout(struct test_data *data)
 {
-       int enabled;
-       sd_event_source_get_enabled(data->step_timer, &enabled);
-
-       if (enabled != SD_EVENT_OFF)
-               sd_event_source_set_enabled(data->step_timer, SD_EVENT_OFF);
+       if (data->step_timer != 0) {
+               g_source_remove(data->step_timer);
+               data->step_timer = 0;
+       }
 }
 
-static int on_test_step_timeout(sd_event_source *s, uint64_t usec, void *userdata)
+static gboolean on_test_step_timeout(gpointer userdata)
 {
        struct test_data *data = (struct test_data *)userdata;
        struct test_sequence *test = &data->tests[data->current_test];
-
        test->result = TEST_FAIL;
        next_test(data);
        return 0;
@@ -75,19 +73,12 @@ static int on_test_step_timeout(sd_event_source *s, uint64_t usec, void *userdat
 
 static int start_test_step_timeout(struct test_data *data)
 {
-       int r;
-       uint64_t now;
-       char err[512];
-
-       sd_event_now(data->loop, CLOCK_REALTIME, &now);
-       r = sd_event_add_time(data->loop, &data->step_timer, CLOCK_REALTIME, now+2000000, 0, on_test_step_timeout, data);
-       if (r < 0) {
-               if (strerror_r(-r, err, sizeof err))
-                       fprintf(stderr, "Failed to attach timer to event loop: %s\n", err);
-               return r;
+       data->step_timer = g_timeout_add_seconds(2, on_test_step_timeout, data);
+       if (data->step_timer == 0) {
+               fprintf(stderr, "Failed to init step timer\n");
+               return -EINVAL;
        }
-
-       return 0;
+       return FALSE;
 }
 
 static int check_test_result(struct test_data *data)
@@ -96,7 +87,6 @@ static int check_test_result(struct test_data *data)
        struct action *a = &test->actions[test->current_action];
        enum unit_state exp_state = a->expected_states[a->current_state];
 
-
        if (data->state != exp_state) {
                fprintf(stderr, "test failed (%s instead of %s at step %d of action %d of test %d)\n",
                                from_unit_state(data->state),
@@ -138,7 +128,7 @@ int test_step(struct test_data *data)
 
        /* last test */
        if (data->current_test == data->tests_count) {
-               sd_event_exit(data->loop, EXIT_SUCCESS);
+               g_main_loop_quit(data->loop);
                return 0;
        }
        test = &data->tests[data->current_test];
@@ -149,8 +139,6 @@ int test_step(struct test_data *data)
                return 0;
        }
 
-       //if (set_vconf_key(test->key, test->actions[test->current_action].action))
-       //      return -1;
        if (!test->step || test->step(data) != 0)
                return -1;
 
@@ -163,66 +151,46 @@ int start_test(struct test_data *data)
        return test_step(data);
 }
 
-
-int on_properties_changed(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
+void on_properties_changed(GDBusConnection *connection,
+               const gchar *sender_name,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *signal_name,
+               GVariant *parameters,
+               gpointer user_data)
 {
-       int r;
-       struct test_data *data = (struct test_data*)userdata;
-       const char *iface;
-       const char *member;
-       const char *value = NULL;
-       const char *contents;
-
-       r = sd_bus_message_read(m, "s", &iface);
-       if (r < 0) {
-               fprintf(stderr, "Failed to parse PropertiesChanged\n");
-               return r;
-       }
-
-       r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}");
-       if (r < 0)
-               return r;
-
-       while ((r = sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, "sv")) > 0) {
-               char type;
-
-               r = sd_bus_message_read(m, "s", &member);
-               if (r < 0)
-                       return r;
-
-               r = sd_bus_message_peek_type(m, &type, &contents);
-               if (r < 0)
-                       return r;
-
-               r = sd_bus_message_enter_container(m, SD_BUS_TYPE_VARIANT, contents);
-               if (r < 0)
-                       return r;
-
-               if (strcmp(member, "ActiveState") == 0) {
-                       r = sd_bus_message_read(m, "s", &value);
-                       if (r < 0)
-                               return r;
-               } else {
-                       r = sd_bus_message_skip(m, contents);
-                       if (r < 0)
-                               return r;
+       GVariantIter iter, iter1;
+       char *value = NULL;
+       GVariant *variant;
+       GVariant *child;
+       gchar *key;
+       struct test_data *data = (struct test_data*)user_data;
+
+       g_variant_iter_init (&iter, parameters);
+
+       /* skip 's' - interface name */
+       child = g_variant_iter_next_value (&iter);
+       g_variant_unref(child);
+
+       /* next is 'a{sv}' where ActiveState is */
+       child = g_variant_iter_next_value (&iter);
+
+       g_variant_iter_init (&iter1, child);
+       while (g_variant_iter_loop (&iter1, "{sv}", &key, &variant)) {
+               if (!g_strcmp0(key, "ActiveState")) {
+                       if (g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) {
+                               value = strdup(g_variant_get_string(variant, NULL));
+                               break;
+                       }
                }
-
-               r = sd_bus_message_exit_container(m);
-               if (r < 0)
-                       return r;
-
-               r = sd_bus_message_exit_container(m);
-               if (r < 0)
-                       return r;
        }
 
-       r = sd_bus_message_exit_container(m);
-       if (r < 0)
-               return r;
+       g_variant_unref(child);
 
-       if (value)
+       if (value) {
                check_unit_state(data, value);
-       return 0;
+               free(value);
+       }
+
 }
 
index 4eb8307a20413134dc9e482ce5c65f7e4d76ddd3..a7666ab96244184022a612e3bfb6102bc39fd94e 100644 (file)
@@ -19,7 +19,8 @@
 #ifndef ACTIVATIOND_ACCEPTANCE_TESTS_H
 #define ACTIVATIOND_ACCEPTANCE_TESTS_H
 
-#include <systemd/sd-bus.h>
+#include <gio/gio.h>
+
 #include "vconf_key_changed_event.h"
 
 struct vkc_value;
@@ -54,14 +55,16 @@ struct test_sequence {
        int result;
        char *unit;
        char *path;
+       guint subscription_id;
        int (*step)(struct test_data *test);
 };
 
 
 struct test_data {
-       sd_bus *bus;
-       sd_event *loop;
-       sd_event_source *step_timer;
+       GDBusConnection *bus;
+       GMainLoop *loop;
+       guint event_sources[4];
+       guint step_timer;
        struct test_sequence *tests;
        int tests_count;
        int current_test;
@@ -70,6 +73,13 @@ struct test_data {
 };
 
 int start_test(struct test_data *data);
-int on_properties_changed(sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
+
+void on_properties_changed(GDBusConnection *connection,
+               const gchar *sender_name,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *signal_name,
+               GVariant *parameters,
+               gpointer user_data);
 
 #endif /* ACTIVATIOND_ACCEPTANCE_TESTS_H */
index a0414347fd01b26b757a4b3c12d90766eb921335..23cb6cd029150a3257fa15a8b51e81a47a75e097 100644 (file)
 #define DBUS_TEST_INTERFACE "org.freedesktop.ActivationdTestInterface"
 #define DBUS_TEST_PATH "/org/freedesktop/activationd/test/object"
 
-static int send_dbus_signal(sd_bus *bus, const char *method, int param_cnt, const struct vkc_value *params)
+static int send_dbus_signal(GDBusConnection *bus, const char *method, int param_cnt, const struct vkc_value *params)
 {
-       _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
-       int ret;
+       GVariant *p;
+       GError *err = NULL;
+       GVariantBuilder builder;
 
-       ret = sd_bus_message_new_signal(bus, &m, DBUS_TEST_PATH, DBUS_TEST_INTERFACE, method);
-       if (ret < 0)
-               goto fail;
+       g_variant_builder_init(&builder, G_VARIANT_TYPE_TUPLE);
 
        for (int i = 0; i < param_cnt; i++) {
                switch(params[i].type) {
                case VKC_STRING:
-                       ret = sd_bus_message_append(m, "s", params[i].value.s);
-                       if (ret < 0)
-                               goto fail;
+                       g_variant_builder_add(&builder, "s", params[i].value.s);
                        break;
                case VKC_DOUBLE:
-                       ret = sd_bus_message_append(m, "d", params[i].value.d);
-                       if (ret < 0)
-                               goto fail;
+                       g_variant_builder_add(&builder, "d", params[i].value.d);
                        break;
                case VKC_INT:
-                       ret = sd_bus_message_append(m, "i", params[i].value.i);
-                       if (ret < 0)
-                               goto fail;
+                       g_variant_builder_add(&builder, "i", params[i].value.i);
                        break;
                case VKC_BOOL:
-                       ret = sd_bus_message_append(m, "b", params[i].value.b);
-                       if (ret < 0)
-                               goto fail;
+                       g_variant_builder_add(&builder, "b", params[i].value.b);
                        break;
                }
        }
-       sd_bus_send(bus, m, NULL);
-       /* return value of sd_bus_send is useless because it will always fail on negative tests,
-        * always return 0 instead */
+       p = g_variant_builder_end(&builder);
+
+       g_dbus_connection_emit_signal(bus,
+                       NULL,
+                       DBUS_TEST_PATH,
+                       DBUS_TEST_INTERFACE,
+                       method,
+                       p,
+                       &err);
+
+       if (err) {
+               fprintf(stderr, "Could not emit signal %s: %s\n", method, err->message);
+               g_error_free(err);
+               return -EINVAL;
+       }
        return 0;
-fail:
-       return ret;
 }
 
 int dbus_signal_step(struct test_data *data)
index 330b6e7f15ec4d73401b1983550330d7b1555050..59a17884d915dab818ee47c6bbdafabc766a8567 100644 (file)
@@ -15,6 +15,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <glib.h>
 
 #include "activationd_acceptance_tests.h"
 #include "activationd_acceptance_tests_unit_control.h"
 #define ACTD_DBUS_API_SERVICE_NAME "org.tizen.activationd"
 #define ACTD_DBUS_API_OBJECT_PATH "/org/tizen/activationd"
 
-static int unit_control_call(sd_bus *bus, const char *unit, int param_cnt, const struct vkc_value *params)
+static int unit_control_call(GDBusConnection *bus, const char *unit, int param_cnt, const struct vkc_value *params)
 {
        assert(bus);
        assert(unit);
        assert(params);
 
-       _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
        int ret;
-       char err[512];
+       GVariant *msg = NULL;
+       GError *error = NULL;
 
        if (param_cnt != 1) {
                fprintf(stderr, "invalid param count (%d)\n", param_cnt);
@@ -46,30 +47,23 @@ static int unit_control_call(sd_bus *bus, const char *unit, int param_cnt, const
                goto fail;
        }
 
-       ret = sd_bus_message_new_method_call(
-                       bus,
-                       &m,
+       msg = g_dbus_connection_call_sync(bus,
                        ACTD_DBUS_API_SERVICE_NAME,
                        ACTD_DBUS_API_OBJECT_PATH,
                        ACTD_DBUS_API_INTERFACE_NAME,
-                       params[0].value.s);
-
-       if (ret < 0) {
-               if (strerror_r(-ret, err, sizeof err))
-                       fprintf(stderr, "failed to issue dbus api method call: %s", err);
-               goto fail;
+                       params[0].value.s,
+                       g_variant_new("(s)", unit),
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       10000,
+                       NULL,
+                       &error);
+       if (error) {
+               fprintf(stderr, "Subscribe method call error: %s\n", error->message);
+               g_error_free(error);
+               return -EINVAL;
        }
-
-       ret = sd_bus_message_append(m, "s", unit);
-       if (ret < 0) {
-               fprintf(stderr, "failed to create dbus api call\n");
-               goto fail;
-       }
-
-
-       sd_bus_call(bus, m, 0, NULL, NULL);
-       /* return value of sd_bus_call is useless because it will always fail on negative tests,
-        * always return 0 instead */
+       g_variant_unref(msg);
        return 0;
 fail:
        return ret;