All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dbus: Don't send replies to messages with no reply flag
@ 2016-11-09 10:22 Andrew Zaborowski
  2016-11-09 20:16 ` Denis Kenzior
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Zaborowski @ 2016-11-09 10:22 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 2332 bytes --]

Kdbus doesn't store the cookies for messages that have the no reply flag
and throws error when a reply is sent with reply_cookie that it doesn't
know.  It's not fatal, but we save some cycles by not sending the message
with both dbus versions.

We mark those replies with reply_serial == 0, rather than setting a
"discard" flag on the message, because the method call's serial is
effectively an invalid reply_serial value.
---
 ell/dbus-message.c | 10 +++++++---
 ell/dbus.c         | 10 ++++++++++
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/ell/dbus-message.c b/ell/dbus-message.c
index 072a902..3b44fb8 100644
--- a/ell/dbus-message.c
+++ b/ell/dbus-message.c
@@ -326,7 +326,8 @@ LIB_EXPORT struct l_dbus_message *l_dbus_message_new_method_return(
 					DBUS_MESSAGE_FLAG_NO_REPLY_EXPECTED,
 					hdr->version);
 
-	message->reply_serial = _dbus_message_get_serial(method_call);
+	if (!l_dbus_message_get_no_reply(method_call))
+		message->reply_serial = _dbus_message_get_serial(method_call);
 
 	sender = l_dbus_message_get_sender(method_call);
 	if (sender)
@@ -369,11 +370,14 @@ LIB_EXPORT struct l_dbus_message *l_dbus_message_new_error_valist(
 {
 	char str[1024];
 	struct dbus_header *hdr = method_call->header;
+	uint32_t reply_serial = 0;
 
 	vsnprintf(str, sizeof(str), format, args);
 
-	return _dbus_message_new_error(hdr->version,
-					_dbus_message_get_serial(method_call),
+	if (!l_dbus_message_get_no_reply(method_call))
+		reply_serial = _dbus_message_get_serial(method_call);
+
+	return _dbus_message_new_error(hdr->version, reply_serial,
 					l_dbus_message_get_sender(method_call),
 					name, str);
 }
diff --git a/ell/dbus.c b/ell/dbus.c
index 236c35a..2c04ec9 100644
--- a/ell/dbus.c
+++ b/ell/dbus.c
@@ -313,6 +313,16 @@ static uint32_t send_message(struct l_dbus *dbus, bool priority,
 				void *user_data, l_dbus_destroy_func_t destroy)
 {
 	struct message_callback *callback;
+	enum dbus_message_type type;
+
+	type = _dbus_message_get_type(message);
+
+	if ((type == DBUS_MESSAGE_TYPE_METHOD_RETURN ||
+				type == DBUS_MESSAGE_TYPE_ERROR) &&
+			_dbus_message_get_reply_serial(message) == 0) {
+		l_dbus_message_unref(message);
+		return 0;
+	}
 
 	callback = l_new(struct message_callback, 1);
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread
* [PATCH 1/2] dbus: Add private _dbus_message_new_error
@ 2016-04-18 14:31 Andrew Zaborowski
  2016-04-18 14:31 ` [PATCH] dbus: Don't send replies to messages with no reply flag Andrew Zaborowski
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Zaborowski @ 2016-04-18 14:31 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 3112 bytes --]

---
 ell/dbus-message.c | 47 +++++++++++++++++++++++++++++++----------------
 ell/dbus-private.h |  5 +++++
 2 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/ell/dbus-message.c b/ell/dbus-message.c
index a409e53..86cec96 100644
--- a/ell/dbus-message.c
+++ b/ell/dbus-message.c
@@ -328,33 +328,32 @@ LIB_EXPORT struct l_dbus_message *l_dbus_message_new_method_return(
 	return message;
 }
 
-LIB_EXPORT struct l_dbus_message *l_dbus_message_new_error_valist(
-					struct l_dbus_message *method_call,
-					const char *name,
-					const char *format, va_list args)
+struct l_dbus_message *_dbus_message_new_error(uint8_t version,
+						uint32_t reply_serial,
+						const char *destination,
+						const char *name,
+						const char *error)
 {
-	char str[1024];
 	struct l_dbus_message *reply;
-	struct dbus_header *hdr = method_call->header;
-	const char *sender;
+	bool r;
 
 	if (!_dbus_valid_interface(name))
 		return NULL;
 
-	vsnprintf(str, sizeof(str), format, args);
 	reply = message_new_common(DBUS_MESSAGE_TYPE_ERROR,
 					DBUS_MESSAGE_FLAG_NO_REPLY_EXPECTED,
-					hdr->version);
-
-	reply->reply_serial = _dbus_message_get_serial(method_call);
-
-	sender = l_dbus_message_get_sender(method_call);
-	if (sender)
-		reply->destination = l_strdup(sender);
+					version);
 
 	reply->error_name = l_strdup(name);
+	reply->destination = l_strdup(destination);
+	reply->reply_serial = reply_serial;
 
-	if (!l_dbus_message_set_arguments(reply, "s", str)) {
+	if (error)
+		r = l_dbus_message_set_arguments(reply, "s", error);
+	else
+		r = l_dbus_message_set_arguments(reply, "");
+
+	if (!r) {
 		l_dbus_message_unref(reply);
 		return NULL;
 	}
@@ -362,6 +361,22 @@ LIB_EXPORT struct l_dbus_message *l_dbus_message_new_error_valist(
 	return reply;
 }
 
+LIB_EXPORT struct l_dbus_message *l_dbus_message_new_error_valist(
+					struct l_dbus_message *method_call,
+					const char *name,
+					const char *format, va_list args)
+{
+	char str[1024];
+	struct dbus_header *hdr = method_call->header;
+
+	vsnprintf(str, sizeof(str), format, args);
+
+	return _dbus_message_new_error(hdr->version,
+					_dbus_message_get_serial(method_call),
+					l_dbus_message_get_sender(method_call),
+					name, str);
+}
+
 LIB_EXPORT struct l_dbus_message *l_dbus_message_new_error(
 					struct l_dbus_message *method_call,
 					const char *name,
diff --git a/ell/dbus-private.h b/ell/dbus-private.h
index 63c239b..030ce0b 100644
--- a/ell/dbus-private.h
+++ b/ell/dbus-private.h
@@ -141,6 +141,11 @@ struct l_dbus_message *_dbus_message_new_signal(uint8_t version,
 						const char *path,
 						const char *interface,
 						const char *name);
+struct l_dbus_message *_dbus_message_new_error(uint8_t version,
+						uint32_t reply_serial,
+						const char *destination,
+						const char *name,
+						const char *error);
 
 struct l_dbus_message *dbus_message_from_blob(const void *data, size_t size);
 struct l_dbus_message *dbus_message_build(void *header, size_t header_size,
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-11-09 20:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-09 10:22 [PATCH] dbus: Don't send replies to messages with no reply flag Andrew Zaborowski
2016-11-09 20:16 ` Denis Kenzior
  -- strict thread matches above, loose matches on Subject: below --
2016-04-18 14:31 [PATCH 1/2] dbus: Add private _dbus_message_new_error Andrew Zaborowski
2016-04-18 14:31 ` [PATCH] dbus: Don't send replies to messages with no reply flag Andrew Zaborowski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.