summaryrefslogtreecommitdiffstats
path: root/dbus
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-04-03 21:56:22 +0000
committerHavoc Pennington <hp@redhat.com>2003-04-03 21:56:22 +0000
commitf216e81432ddf04889202c33a6e68113f94d7611 (patch)
treebb8386366d183e43dc3471219ec627a21c65a639 /dbus
parentfe9f3b45cc7e2e84d180c433f1ab5f8fd0a0c619 (diff)
2003-04-03 Havoc Pennington <hp@redhat.com>
* bus/activation.c (load_directory): fix up memleaks (bus_activation_entry_free): free the entry * dbus/dbus-bus.c (dbus_bus_acquire_service): return an error if we get one from the message bus; fix memleaks. * dbus/dbus-message.c (dbus_set_error_from_message): new function
Diffstat (limited to 'dbus')
-rw-r--r--dbus/dbus-bus.c14
-rw-r--r--dbus/dbus-message.c39
-rw-r--r--dbus/dbus-message.h5
3 files changed, 56 insertions, 2 deletions
diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c
index dc1762eb..df883f51 100644
--- a/dbus/dbus-bus.c
+++ b/dbus/dbus-bus.c
@@ -534,7 +534,7 @@ dbus_bus_acquire_service (DBusConnection *connection,
DBusError *error)
{
DBusMessage *message, *reply;
- int service_result;
+ dbus_uint32_t service_result;
message = dbus_message_new (DBUS_SERVICE_DBUS,
DBUS_MESSAGE_ACQUIRE_SERVICE);
@@ -564,16 +564,26 @@ dbus_bus_acquire_service (DBusConnection *connection,
{
_DBUS_ASSERT_ERROR_IS_SET (error);
return -1;
- }
+ }
+ if (dbus_set_error_from_message (error, reply))
+ {
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ dbus_message_unref (reply);
+ return -1;
+ }
+
if (!dbus_message_get_args (reply, error,
DBUS_TYPE_UINT32, &service_result,
0))
{
_DBUS_ASSERT_ERROR_IS_SET (error);
+ dbus_message_unref (reply);
return -1;
}
+ dbus_message_unref (reply);
+
return service_result;
}
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index 39ed3942..46c4c406 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -2381,6 +2381,45 @@ dbus_message_sender_is (DBusMessage *message,
return FALSE;
}
+/**
+ * Sets a #DBusError based on the contents of the given
+ * message. The error is only set if the message
+ * is an error message, as in dbus_message_get_is_error().
+ * The name of the error is set to the name of the message,
+ * and the error message is set to the first argument
+ * if the argument exists and is a string.
+ *
+ * The return value indicates whether the error was set (the error is
+ * set if and only if the message is an error message).
+ * So you can check for an error reply and convert it to DBusError
+ * in one go.
+ *
+ * @param error the error to set
+ * @param message the message to set it from
+ * @returns #TRUE if dbus_message_get_is_error() returns #TRUE for the message
+ */
+dbus_bool_t
+dbus_set_error_from_message (DBusError *error,
+ DBusMessage *message)
+{
+ char *str;
+
+ if (!dbus_message_get_is_error (message))
+ return FALSE;
+
+ str = NULL;
+ dbus_message_get_args (message, NULL,
+ DBUS_TYPE_STRING, &str,
+ DBUS_TYPE_INVALID);
+
+ dbus_set_error (error, dbus_message_get_name (message),
+ str ? "%s" : NULL, str);
+
+ dbus_free (str);
+
+ return TRUE;
+}
+
/** @} */
/**
diff --git a/dbus/dbus-message.h b/dbus/dbus-message.h
index be752c94..47337863 100644
--- a/dbus/dbus-message.h
+++ b/dbus/dbus-message.h
@@ -148,6 +148,11 @@ dbus_bool_t dbus_message_iter_get_string_array (DBusMessageIter *iter,
dbus_bool_t dbus_message_iter_get_dict (DBusMessageIter *iter,
DBusDict **dict);
+
+
+dbus_bool_t dbus_set_error_from_message (DBusError *error,
+ DBusMessage *message);
+
DBUS_END_DECLS;
#endif /* DBUS_MESSAGE_H */