Add kdbus_domain_user_account() to account and link users into a
domain.

This function will take the domain lock, and it will be used as a
replacement for kdbus_domain_user_find_or_new().

Signed-off-by: Djalal Harouni <tix...@opendz.org>
---
 domain.c | 36 ++++++++++++++++++++++++++++++++++++
 domain.h |  4 ++++
 2 files changed, 40 insertions(+)

diff --git a/domain.c b/domain.c
index 11d7439..1e2c3c9 100644
--- a/domain.c
+++ b/domain.c
@@ -522,6 +522,42 @@ exit_free:
 }
 
 /**
+ * kdbus_domain_user_account() - account a kdbus_domain_user object
+ *                              into the specified domain
+ * @domain:            The domain of the user
+ * @uid:               The uid of the user; INVALID_UID for an
+ *                     anonymous user like a custom endpoint
+ * @user               Pointer to a reference where the accounted
+ *                     domain user will be stored.
+ *
+ * Return: 0 on success, negative errno on failure.
+ *
+ * On success: if there is a uid matching, then use the already
+ * accounted kdbus_domain_user, increment its reference counter and
+ * return it in the 'user' argument. Otherwise, allocate a new one,
+ * link it into the domain, then return it.
+ *
+ * On failure: the 'user' argument is not updated.
+ *
+ * This function will first check if the domain was not disconnected.
+ */
+int kdbus_domain_user_account(struct kdbus_domain *domain,
+                             kuid_t uid,
+                             struct kdbus_domain_user **user)
+{
+       int ret = -ESHUTDOWN;
+
+       mutex_lock(&domain->lock);
+
+       if (!domain->disconnected)
+               ret = __kdbus_domain_user_account(domain, uid, user);
+
+       mutex_unlock(&domain->lock);
+
+       return ret;
+}
+
+/**
  * kdbus_domain_user_find_or_new() - get a kdbus_domain_user object in a domain
  * @domain:            The domain
  * @uid:               The uid of the user; INVALID_UID for an anonymous
diff --git a/domain.h b/domain.h
index fd2940b..c81589e 100644
--- a/domain.h
+++ b/domain.h
@@ -103,6 +103,10 @@ int __kdbus_domain_user_account(struct kdbus_domain 
*domain,
                                kuid_t uid,
                                struct kdbus_domain_user **user);
 
+int kdbus_domain_user_account(struct kdbus_domain *domain,
+                             kuid_t uid,
+                             struct kdbus_domain_user **user);
+
 struct kdbus_domain_user
 *kdbus_domain_user_find_or_new(struct kdbus_domain *domain, kuid_t uid);
 struct kdbus_domain_user *kdbus_domain_user_ref(struct kdbus_domain_user *u);
-- 
1.9.3

_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to