domain: add kdbus_domain_user_account()
authorDjalal Harouni <tixxdz@opendz.org>
Wed, 30 Jul 2014 20:11:54 +0000 (21:11 +0100)
committerKay Sievers <kay@vrfy.org>
Thu, 31 Jul 2014 14:29:54 +0000 (16:29 +0200)
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 <tixxdz@opendz.org>
domain.c
domain.h

index 11d7439b724d030b2352b85a7b1365e12dc7bf2f..1e2c3c975fab8c046f782f7fb706deca6b6a6bdf 100644 (file)
--- a/domain.c
+++ b/domain.c
@@ -521,6 +521,42 @@ exit_free:
        return ret;
 }
 
+/**
+ * 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
index fd2940ba860f8416c52cf9cd24d7e2b7ecfb91de..c81589ea87f1153ff713e3771a26225659c17168 100644 (file)
--- 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);