to add a return value indicating error results.
Change-Id: I557c3fe79168076aaa9516f0c36eafd471e19c56
Signed-off-by: taemin.yeom <taemin.yeom@samsung.com>
return ret;
}
-GVariant *dbus_handle_method_sync_with_reply_var(const char *dest,
+int dbus_handle_method_sync_with_reply_var(const char *dest,
const char *path,
const char *iface,
const char *method,
- GVariant *var)
+ GVariant *param,
+ GVariant **reply)
{
GError *err = NULL;
- GVariant * ret = NULL;
+ int ret = 0;
dbus_handle_s *dh = NULL;
if (!dest || !path || !iface || !method) {
_E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method);
- if (var)
- g_variant_unref(var);
- return NULL;
+ if (param)
+ g_variant_unref(param);
+ return -EINVAL;
}
dh = _dbus_handle_get_default_connection();
if (!dh) {
_E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type());
- if (var)
- g_variant_unref(var);
- return NULL;
+ if (param)
+ g_variant_unref(param);
+ return -ECOMM;
}
- ret = g_dbus_connection_call_sync(dh->conn,
+ *reply = g_dbus_connection_call_sync(dh->conn,
dest, path, iface, method,
- var, NULL,
+ param, NULL,
G_DBUS_CALL_FLAGS_NONE,
DBUS_REPLY_TIMEOUT,
NULL,
&err);
- if (!ret || err) {
+ if (!(*reply) || err) {
if (err) {
_E("failed to g_dbus_connection_call_sync:%s", err->message);
if (g_error_matches(err, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED))
- ret = g_variant_new("(i)", -EPERM);
+ ret = -EPERM;
else
- ret = NULL;
+ ret = -ECOMM;
g_error_free(err);
return ret;
} else {
_E("failed to g_dbus_connection_call_sync");
}
- return NULL;
+ return -ECOMM;
}
return ret;
}
-GVariant *dbus_handle_method_sync_with_reply_var_timeout(const char *dest, const char *path,
- const char *iface, const char *method, GVariant *var, int timeout)
+int dbus_handle_method_sync_with_reply_var_timeout(const char *dest, const char *path,
+ const char *iface, const char *method, GVariant *param, GVariant **reply, int timeout)
{
GError *err = NULL;
- GVariant * ret = NULL;
dbus_handle_s *dh = NULL;
if (!dest || !path || !iface || !method) {
_E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method);
- if (var)
- g_variant_unref(var);
- return NULL;
+ if (param)
+ g_variant_unref(param);
+ return -EINVAL;
}
dh = _dbus_handle_get_default_connection();
if (!dh) {
_E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type());
- if (var)
- g_variant_unref(var);
- return NULL;
+ if (param)
+ g_variant_unref(param);
+ return -ECOMM;
}
- ret = g_dbus_connection_call_sync(dh->conn,
+ *reply = g_dbus_connection_call_sync(dh->conn,
dest, path, iface, method,
- var, NULL,
+ param, NULL,
G_DBUS_CALL_FLAGS_NONE,
timeout,
NULL,
&err);
- if (!ret || err) {
+ if (!(*reply) || err) {
if (err) {
_E("failed to g_dbus_connection_call_sync:%s", err->message);
g_error_free(err);
} else {
_E("failed to g_dbus_connection_call_sync");
}
- return NULL;
+ return -ECOMM;
}
- return ret;
+ return 0;
}
gint* dbus_handle_get_unix_fd_list(GDBusMethodInvocation *invocation, int *size)
GVariant *param)
{
int result;
+ int ret = 0;
gboolean result_bool;
GVariant *reply = NULL;
return -1;
}
- reply = dbus_handle_method_sync_with_reply_var(dest, path, iface, method, param);
+ ret = dbus_handle_method_sync_with_reply_var(dest, path, iface, method, param, &reply);
+ if (ret < 0)
+ return ret;
+
if (!reply)
return -ECOMM;
_I("%s %s", "org.freedesktop.systemd1.Unit", "ActiveState");
- msg = dbus_handle_method_sync_with_reply_var("org.freedesktop.systemd1",
+ ret = dbus_handle_method_sync_with_reply_var("org.freedesktop.systemd1",
"/org/freedesktop/systemd1/unit/default_2etarget",
"org.freedesktop.DBus.Properties",
"Get",
- g_variant_new("(ss)", "org.freedesktop.systemd1.Unit", "ActiveState"));
+ g_variant_new("(ss)", "org.freedesktop.systemd1.Unit", "ActiveState"),
+ &msg);
+ if (ret < 0)
+ return ret;
if (!msg)
return -EBADMSG;
int timeout_msec,
void *data);
-GVariant *dbus_handle_method_sync_with_reply_var (const char *dest,
+int dbus_handle_method_sync_with_reply_var (const char *dest,
const char *path,
const char *iface,
const char *method,
- GVariant *var);
+ GVariant *param,
+ GVariant **reply);
-GVariant *dbus_handle_method_sync_with_reply_var_timeout (const char *dest,
+int dbus_handle_method_sync_with_reply_var_timeout (const char *dest,
const char *path,
const char *iface,
const char *method,
- GVariant *var,
+ GVariant *param,
+ GVariant **reply,
int timeout);
gint* dbus_handle_get_unix_fd_list (GDBusMethodInvocation *invocation,
goto finish;
}
- reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST,
+ ret = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST,
SYSTEMD_DBUS_PATH,
SYSTEMD_DBUS_MANAGER_IFACE,
method,
- g_variant_new("(ss)", name, "replace"));
+ g_variant_new("(ss)", name, "replace"),
+ &reply);
+ if (ret < 0)
+ goto finish;
+
if (!reply || !g_variant_get_safe(reply, "(o)", &objpath)) {
_E("fail (%s): no message", method);
ret = -EBADMSG;
_I("Starting: %s %s", method, name);
- reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST,
+ ret = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST,
SYSTEMD_DBUS_PATH,
SYSTEMD_DBUS_MANAGER_IFACE,
method,
- g_variant_new("(ss)", name, "replace"));
+ g_variant_new("(ss)", name, "replace"),
+ &reply);
+ if (ret < 0)
+ goto finish;
if (!reply || !g_variant_get_safe(reply, "(o)", &objpath)) {
_E("fail (%s): no message", method);
{
GVariant *reply = NULL;
GVariant *val = NULL;
+ int ret = 0;
if (!property)
return NULL;
- reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST,
+ ret = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST,
SYSTEMD_DBUS_PATH,
DBUS_IFACE_DBUS_PROPERTIES,
"Get",
- g_variant_new("(ss)", SYSTEMD_DBUS_MANAGER_IFACE, property));
- if (!reply || !g_variant_get_safe(reply, "(v)", &val))
+ g_variant_new("(ss)", SYSTEMD_DBUS_MANAGER_IFACE, property),
+ &reply);
+ if (!reply || !g_variant_get_safe(reply, "(v)", &val) || ret < 0)
_E("Failed to get variant");
if (reply)
g_variant_unref(reply);
char *escaped;
GVariant *reply = NULL;
GVariant *val = NULL;
+ int ret = 0;
if (!unit || !property)
return NULL;
escaped = systemd_get_unit_dbus_path(unit);
- reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST,
+ ret = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST,
escaped,
DBUS_IFACE_DBUS_PROPERTIES,
"Get",
- g_variant_new("(ss)", SYSTEMD_DBUS_UNIT_IFACE, property));
+ g_variant_new("(ss)", SYSTEMD_DBUS_UNIT_IFACE, property),
+ &reply);
- if (!reply || !g_variant_get_safe(reply, "(v)", &val))
+ if (!reply || !g_variant_get_safe(reply, "(v)", &val) || ret < 0)
_E("Failed to get variant");
if (reply)
g_variant_unref(reply);
char *escaped;
GVariant *reply = NULL;
GVariant *val = NULL;
+ int ret = 0;
if (!unit || !property)
return NULL;
escaped = systemd_get_unit_dbus_path(unit);
- reply = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST,
+ ret = dbus_handle_method_sync_with_reply_var(SYSTEMD_DBUS_DEST,
escaped,
DBUS_IFACE_DBUS_PROPERTIES,
"Get",
- g_variant_new("(ss)", SYSTEMD_DBUS_SERVICE_IFACE, property));
- if (!reply || !g_variant_get_safe(reply, "(v)", &val))
+ g_variant_new("(ss)", SYSTEMD_DBUS_SERVICE_IFACE, property),
+ &reply);
+ if (!reply || !g_variant_get_safe(reply, "(v)", &val) || ret < 0)
_E("Failed to get variant");
if (reply)
g_variant_unref(reply);