* try via XDG_RUNTIME_DIR first, then
* fallback to normal bus access */
- e = getenv("XDG_RUNTIME_DIR");
+ e = __secure_getenv("XDG_RUNTIME_DIR");
if (e) {
char *p;
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, ...) {
+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;
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 (!return_error)
+ 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 = -EIO;
goto finish;
}
+
if (return_reply)
*return_reply = reply;
else
dbus_message_unref(reply);
+
finish:
- if(return_error)
- *return_error=error;
+ if (m)
+ dbus_message_unref(m);
+
+ if (return_error)
+ *return_error = error;
else
dbus_error_free(&error);