diff options
author | Karol Lewandowski <k.lewandowsk@samsung.com> | 2019-08-06 12:18:57 +0200 |
---|---|---|
committer | Karol Lewandowski <k.lewandowsk@samsung.com> | 2019-08-06 14:05:34 +0200 |
commit | fd6f395bf5fb2c7a4ec0e912f3f82a2f55df3226 (patch) | |
tree | 87253ad372b57cd176aa47306d552981fb4b4dbf | |
parent | 8c03d14c463fd1e7d22af8613afe0d7afa2fc707 (diff) | |
download | activationd-fd6f395bf5fb2c7a4ec0e912f3f82a2f55df3226.tar.gz activationd-fd6f395bf5fb2c7a4ec0e912f3f82a2f55df3226.tar.bz2 activationd-fd6f395bf5fb2c7a4ec0e912f3f82a2f55df3226.zip |
unit_control: Ensure API always returns valid error codesubmit/tizen/20190807.020938accepted/tizen/unified/20190807.111823
Additionally, introduce explicit return code for asynchronous
requests - UNIT_CONTROL_REQUEST_SENT, which does only mean
that request was posted, not completed.
Change-Id: Ia5a8f7141ede8d196c8af5e3c0ec65d2058f9f73
-rw-r--r-- | include/unit_control.h | 1 | ||||
-rw-r--r-- | src/libactd/unit_control.c | 45 |
2 files changed, 27 insertions, 19 deletions
diff --git a/include/unit_control.h b/include/unit_control.h index 6a03450..0ec916c 100644 --- a/include/unit_control.h +++ b/include/unit_control.h @@ -2,6 +2,7 @@ #define UNIT_CONTROL_H enum { + UNIT_CONTROL_REQUEST_SENT = 0, UNIT_CONTROL_OK, UNIT_CONTROL_ERROR, }; diff --git a/src/libactd/unit_control.c b/src/libactd/unit_control.c index e548d0f..fd83b80 100644 --- a/src/libactd/unit_control.c +++ b/src/libactd/unit_control.c @@ -19,6 +19,7 @@ #include <glib.h> #include <gio/gio.h> #include <errno.h> +#include <stdbool.h> #include "unit_control.h" @@ -104,14 +105,14 @@ const char *translate_to_systemd(const char *method) static int call_uc(GBusType bus_type, const char *method, const char *unit, int timeout_ms) { - int ret; GVariant *msg = NULL; - GDBusConnection *bus; - const char *result; + int ret = UNIT_CONTROL_ERROR; - bus = g_bus_get_sync(bus_type, NULL, NULL); + GDBusConnection *bus = g_bus_get_sync(bus_type, NULL, NULL); if (!bus) - return -1; + return ret; + + GError *err = NULL; if (bus_type == G_BUS_TYPE_SESSION) { msg = g_dbus_connection_call_sync(bus, @@ -124,13 +125,13 @@ static int call_uc(GBusType bus_type, const char *method, const char *unit, int G_DBUS_CALL_FLAGS_NONE, timeout2glib(timeout_ms), NULL, - NULL); + &err); if (!msg) - return -EBADMSG; - - ret = 0; + goto out; } else { /* we assume that activationd runs on system bus and can be used as a proxy */ + const char *result = NULL; + msg = g_dbus_connection_call_sync(bus, UNIT_CONTROL_NAME, UNIT_CONTROL_OBJ_PATH, @@ -141,19 +142,24 @@ static int call_uc(GBusType bus_type, const char *method, const char *unit, int G_DBUS_CALL_FLAGS_NONE, timeout2glib(timeout_ms), NULL, - NULL); + &err); if (!msg) - return -EBADMSG; + goto out; g_variant_get(msg, "(s)", &result); - if (g_strcmp0(result, "ok") == 0) - ret = 0; - else - ret = -1; - + bool is_ok = g_strcmp0(result, "ok") == 0; g_free(result); + + if (!is_ok) + goto out; } + ret = UNIT_CONTROL_OK; + +out: + if (err) + g_error_free(err); + return ret; } @@ -161,14 +167,15 @@ static int call_uc_async(GBusType bus_type, const char *method, const char *unit { GDBusConnection *bus; struct generic_user_data *data = user_data; + int ret = UNIT_CONTROL_ERROR; bus = g_bus_get_sync(bus_type, NULL, NULL); if (!bus) - return -1; + return ret; data = malloc(sizeof(*data)); if (!data) - return -ENOMEM; + return ret; data->user_data = user_data; data->cb = cb; @@ -203,7 +210,7 @@ static int call_uc_async(GBusType bus_type, const char *method, const char *unit data); } - return 0; + return UNIT_CONTROL_REQUEST_SENT; } int actd_start_unit(BusType bus_type, const char *unit, int timeout_ms) |