#include <glib.h>
#include <gio/gio.h>
#include <errno.h>
+#include <stdbool.h>
#include "unit_control.h"
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,
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,
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;
}
{
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;
data);
}
- return 0;
+ return UNIT_CONTROL_REQUEST_SENT;
}
int actd_start_unit(BusType bus_type, const char *unit, int timeout_ms)