diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-08-08 18:44:15 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-08-08 18:44:15 +0200 |
commit | 9ed63f16131637fc0e76bd40b5452cfc45bccfc7 (patch) | |
tree | c60b6216b04de3bf0e88b996180e4a8220853603 /src/shared/dbus-common.c | |
parent | fd4d89b2c0b31da01d134301e30916931ae3c7d9 (diff) | |
parent | b9c26b413497a0014ac2058a0ec04849a83df1ea (diff) |
Merge remote-tracking branch 'simonpe/cleanup'
Diffstat (limited to 'src/shared/dbus-common.c')
-rw-r--r-- | src/shared/dbus-common.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/shared/dbus-common.c b/src/shared/dbus-common.c index 5d64568c34..7f0dce5ad3 100644 --- a/src/shared/dbus-common.c +++ b/src/shared/dbus-common.c @@ -1237,3 +1237,76 @@ finish: return (pid_t) pid; } + +bool bus_error_is_no_service(const DBusError *error) { + assert(error); + + if (!dbus_error_is_set(error)) + return false; + + if (dbus_error_has_name(error, DBUS_ERROR_NAME_HAS_NO_OWNER)) + return true; + + if (dbus_error_has_name(error, DBUS_ERROR_SERVICE_UNKNOWN)) + return true; + + return startswith(error->name, "org.freedesktop.DBus.Error.Spawn."); +} + +int bus_method_call_with_reply(DBusConnection *bus, + const char *destination, + const char *path, + const char *interface, + const char *method, + DBusMessage **return_reply, + DBusError *return_error, + int first_arg_type, ...) { + DBusError error; + DBusMessage *m, *reply; + va_list ap; + int r = 0; + + dbus_error_init(&error); + assert(bus); + + m = dbus_message_new_method_call(destination, path, interface, method); + if (!m) { + r = log_oom(); + goto finish; + } + + va_start(ap, first_arg_type); + if (!dbus_message_append_args_valist(m, first_arg_type, ap)) { + va_end(ap); + dbus_message_unref(m); + r = log_oom(); + goto finish; + } + va_end(ap); + + reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error); + dbus_message_unref(m); + if (!reply) { + log_error("Failed to issue method call: %s", bus_error_message(&error)); + if (bus_error_is_no_service(&error)) + r = -ENOENT; + else if (dbus_error_has_name(&error, DBUS_ERROR_ACCESS_DENIED)) + r = -EACCES; + else if (dbus_error_has_name(&error, DBUS_ERROR_NO_REPLY)) + r = -ETIMEDOUT; + else + r = -EIO; + goto finish; + } + if (return_reply) + *return_reply = reply; + else + dbus_message_unref(reply); +finish: + if(return_error) + *return_error=error; + else + dbus_error_free(&error); + + return r; +} |