From: Daniel Mack <daniel@zonque.org>
To: gregkh@linuxfoundation.org
Cc: dh.herrmann@gmail.com, tixxdz@opendz.org, teg@jklm.no,
linux-kernel@vger.kernel.org
Subject: [PATCH 3/4] kdbus: never return <0 from ioctls if we changed state
Date: Fri, 7 Aug 2015 16:36:35 +0200 [thread overview]
Message-ID: <1438958196-23036-4-git-send-email-daniel@zonque.org> (raw)
In-Reply-To: <1438958196-23036-1-git-send-email-daniel@zonque.org>
From: David Herrmann <dh.herrmann@gmail.com>
If an ioctl() returns <0, user-space should be safe to assume it had no
effect on the state of any object. This might not be always possible, but
in kdbus we adhered to this rule. But there's one exception, namely
KDBUS_CMD_NAME_ACQUIRE. This call used to fail with -EALREADY if we owned
a name and tried to acquire it again. However, regardless whether the
name was already owned, the name-flags are updated according to the newly
provided flags. Hence, we change the state of name-ownership, but might
still return an error.
This patch changes behavior and now returns 0 in those cases. User-space
still gets the same information (via return_flags), but will no longer be
told that the call failed. The tests reflect that and simply check for
KDBUS_NAME_ACQUIRED in 'return_flags'.
Reviewed-by: Daniel Mack <daniel@zonque.org>
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
---
ipc/kdbus/names.c | 3 ---
tools/testing/selftests/kdbus/test-chat.c | 6 ++++--
tools/testing/selftests/kdbus/test-names.c | 4 ----
3 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/ipc/kdbus/names.c b/ipc/kdbus/names.c
index a47ee54..bf44ca3 100644
--- a/ipc/kdbus/names.c
+++ b/ipc/kdbus/names.c
@@ -291,11 +291,9 @@ static int kdbus_name_update(struct kdbus_name_owner *owner, u64 flags,
/*
* Already the primary owner of the name, flags were already
* updated. Nothing to do.
- * For compatibility, we have to return -EALREADY.
*/
owner->flags |= KDBUS_NAME_PRIMARY;
- ret = -EALREADY;
} else if ((primary->flags & KDBUS_NAME_ALLOW_REPLACEMENT) &&
(flags & KDBUS_NAME_REPLACE_EXISTING)) {
@@ -344,7 +342,6 @@ static int kdbus_name_update(struct kdbus_name_owner *owner, u64 flags,
*/
list_del_init(&owner->name_entry);
- ret = -EEXIST;
} else {
/*
* Name is already claimed and queueing is not requested.
diff --git a/tools/testing/selftests/kdbus/test-chat.c b/tools/testing/selftests/kdbus/test-chat.c
index 71a92d8..41e5b53 100644
--- a/tools/testing/selftests/kdbus/test-chat.c
+++ b/tools/testing/selftests/kdbus/test-chat.c
@@ -41,8 +41,10 @@ int kdbus_test_chat(struct kdbus_test_env *env)
ret = kdbus_name_acquire(conn_a, "foo.bar.double", NULL);
ASSERT_RETURN(ret == 0);
- ret = kdbus_name_acquire(conn_a, "foo.bar.double", NULL);
- ASSERT_RETURN(ret == -EALREADY);
+ flags = 0;
+ ret = kdbus_name_acquire(conn_a, "foo.bar.double", &flags);
+ ASSERT_RETURN(ret == 0);
+ ASSERT_RETURN(!(flags & KDBUS_NAME_ACQUIRED));
ret = kdbus_name_release(conn_a, "foo.bar.double");
ASSERT_RETURN(ret == 0);
diff --git a/tools/testing/selftests/kdbus/test-names.c b/tools/testing/selftests/kdbus/test-names.c
index fd4ac5a..9217465 100644
--- a/tools/testing/selftests/kdbus/test-names.c
+++ b/tools/testing/selftests/kdbus/test-names.c
@@ -143,10 +143,6 @@ int kdbus_test_name_conflict(struct kdbus_test_env *env)
ret = conn_is_name_owner(env->conn, name);
ASSERT_RETURN(ret == 0);
- /* check that we can't acquire it again from the 1st connection */
- ret = kdbus_name_acquire(env->conn, name, NULL);
- ASSERT_RETURN(ret == -EALREADY);
-
/* check that we also can't acquire it again from the 2nd connection */
ret = kdbus_name_acquire(conn, name, NULL);
ASSERT_RETURN(ret == -EEXIST);
--
2.4.3
next prev parent reply other threads:[~2015-08-07 14:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-07 14:36 [PATCH 0/4] kdbus: name registry cleanup patches Daniel Mack
2015-08-07 14:36 ` [PATCH 1/4] kdbus: restructure name-registry to follow dbus-spec Daniel Mack
2015-08-07 14:36 ` [PATCH 2/4] kdbus: inform caller about exact updates on NAME_ACQUIRE Daniel Mack
2015-08-07 14:36 ` Daniel Mack [this message]
2015-08-07 14:36 ` [PATCH 4/4] kdbus: selftests: add more name registry tests Daniel Mack
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=1438958196-23036-4-git-send-email-daniel@zonque.org \
--to=daniel@zonque.org \
--cc=dh.herrmann@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=teg@jklm.no \
--cc=tixxdz@opendz.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®