All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Zaborowski <andrew.zaborowski@intel.com>
To: ell@lists.01.org
Subject: [PATCH 5/8] dbus: kdbus driver->name_acquire implementation
Date: Thu, 24 Mar 2016 03:07:06 +0100	[thread overview]
Message-ID: <1458785229-23266-5-git-send-email-andrew.zaborowski@intel.com> (raw)
In-Reply-To: <1458785229-23266-1-git-send-email-andrew.zaborowski@intel.com>

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

---
 ell/dbus-kernel.c  | 13 ++++++++++++-
 ell/dbus-private.h |  4 +++-
 ell/dbus.c         | 30 ++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/ell/dbus-kernel.c b/ell/dbus-kernel.c
index b47f973..9bc99d7 100644
--- a/ell/dbus-kernel.c
+++ b/ell/dbus-kernel.c
@@ -626,7 +626,8 @@ int _dbus_kernel_recv(int fd, void *kdbus_pool,
 	return r;
 }
 
-int _dbus_kernel_name_acquire(int fd, const char *name)
+int _dbus_kernel_name_acquire(int fd, const char *name, bool allow_replacement,
+				bool replace_existing, bool queue, bool *queued)
 {
 	struct {
 		struct kdbus_cmd head;
@@ -651,9 +652,19 @@ int _dbus_kernel_name_acquire(int fd, const char *name)
 	item->type = KDBUS_ITEM_NAME;
 	strcpy(item->str, name);
 
+	if (replace_existing)
+		cmd_name.head.flags |= KDBUS_NAME_REPLACE_EXISTING;
+	if (allow_replacement)
+		cmd_name.head.flags |= KDBUS_NAME_ALLOW_REPLACEMENT;
+	if (queue)
+		cmd_name.head.flags |= KDBUS_NAME_QUEUE;
+
 	if (ioctl(fd, KDBUS_CMD_NAME_ACQUIRE, &cmd_name) < 0)
 		return -errno;
 
+	if (queued)
+		*queued = !!(cmd_name.head.flags & KDBUS_NAME_IN_QUEUE);
+
 	return 0;
 }
 
diff --git a/ell/dbus-private.h b/ell/dbus-private.h
index b455df2..8309474 100644
--- a/ell/dbus-private.h
+++ b/ell/dbus-private.h
@@ -243,7 +243,9 @@ int _dbus_kernel_recv(int fd, void *kdbus_pool,
 			_dbus_name_owner_change_func_t name_owner_change_func,
 			void *user_data);
 
-int _dbus_kernel_name_acquire(int fd, const char *name);
+int _dbus_kernel_name_acquire(int fd, const char *name, bool allow_replacement,
+				bool replace_existing, bool queue,
+				bool *queued);
 int _dbus_kernel_add_match(int fd, uint64_t bloom_size, uint64_t bloom_n_hash,
 				const struct _dbus_filter_condition *rule,
 				int rule_len, unsigned int id);
diff --git a/ell/dbus.c b/ell/dbus.c
index 1570d33..e79e23d 100644
--- a/ell/dbus.c
+++ b/ell/dbus.c
@@ -33,6 +33,7 @@
 #include <string.h>
 #include <sys/socket.h>
 #include <sys/un.h>
+#include <errno.h>
 
 #include "util.h"
 #include "io.h"
@@ -1120,6 +1121,34 @@ static bool kdbus_get_name_owner(struct l_dbus *dbus, const char *name)
 	return true;
 }
 
+static uint32_t kdbus_name_acquire(struct l_dbus *dbus, const char *name,
+					bool allow_replacement,
+					bool replace_existing, bool queue,
+					l_dbus_name_acquire_func_t callback,
+					void *user_data)
+{
+	int fd = l_io_get_fd(dbus->io);
+	bool queued = false;
+	int r;
+
+	r = _dbus_kernel_name_acquire(fd, name, allow_replacement,
+					replace_existing, queue, &queued);
+	if (r < 0 && r != -EALREADY) {
+		l_util_debug(dbus->debug_handler,
+				dbus->debug_data, strerror(-r));
+
+		if (callback)
+			callback(dbus, false, false, user_data);
+
+		return 0;
+	}
+
+	if (callback)
+		callback(dbus, true, queued, user_data);
+
+	return 1;
+}
+
 static const struct l_dbus_ops kdbus_ops = {
 	.version  = 2,
 	.free = kdbus_free,
@@ -1130,6 +1159,7 @@ static const struct l_dbus_ops kdbus_ops = {
 		.remove_match = kdbus_remove_match,
 		.get_name_owner = kdbus_get_name_owner,
 	},
+	.name_acquire = kdbus_name_acquire,
 };
 
 static struct l_dbus *setup_kdbus(int fd)
-- 
2.5.0


  parent reply	other threads:[~2016-03-24  2:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-24  2:07 [PATCH 1/8] dbus: Rewrite service/disconnect watch APIs on top of filter API Andrew Zaborowski
2016-03-24  2:07 ` [PATCH 2/8] unit: Remove dbus watch tests using old API Andrew Zaborowski
2016-03-24  2:07 ` [PATCH 3/8] dbus: Remove now unused filter logic Andrew Zaborowski
2016-03-24  2:07 ` [PATCH 4/8] dbus: l_dbus_name_acquire public API and driver declarations Andrew Zaborowski
2016-03-25  3:03   ` Denis Kenzior
2016-03-26  0:15     ` Andrzej Zaborowski
2016-03-24  2:07 ` Andrew Zaborowski [this message]
2016-03-24  2:07 ` [PATCH 6/8] dbus: Classic driver->name_acquire implementation Andrew Zaborowski
2016-03-24  2:07 ` [PATCH 7/8] unit: Use l_dbus_name_acquire to acquire well-known name Andrew Zaborowski
2016-03-24  2:07 ` [PATCH 8/8] examples: " Andrew Zaborowski
2016-03-25  2:55 ` [PATCH 1/8] dbus: Rewrite service/disconnect watch APIs on top of filter API Denis Kenzior
2016-03-26  0:06   ` Andrzej Zaborowski
2016-03-26  3:01     ` Denis Kenzior
2016-03-26 15:50       ` Andrzej Zaborowski
2016-03-26 22:18         ` Denis Kenzior
2016-03-28 14:30           ` Andrzej Zaborowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1458785229-23266-5-git-send-email-andrew.zaborowski@intel.com \
    --to=andrew.zaborowski@intel.com \
    --cc=ell@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.