[systemd-devel] [PATCH 3/7] domain: add kdbus_domain_user_new()

Djalal Harouni tixxdz at opendz.org
Wed Jul 23 14:19:07 PDT 2014


Add kdbus_domain_user_new() to allocate kdbus_domain_user objects.

Signed-off-by: Djalal Harouni <tixxdz at opendz.org>
---
 domain.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/domain.c b/domain.c
index 86fde55..18dc2a7 100644
--- a/domain.c
+++ b/domain.c
@@ -419,6 +419,33 @@ int kdbus_domain_make_user(struct kdbus_cmd_make *cmd, char **name)
 }
 
 /**
+ * kdbus_domain_user_new() - create a new kdbus_domain_user object
+ * @domain		The domain of the user
+ * @uid			The uid of the user; INVALID_UID for an
+ *			anonymous user like custom endpoint
+ *
+ * Return: a kdbus_domain_user freshly allocated. In case of memory
+ * allocation failure, NULL is returned.
+ */
+struct kdbus_domain_user *
+kdbus_domain_user_new(struct kdbus_domain *domain, kuid_t uid)
+{
+	struct kdbus_domain_user *u;
+
+	u = kzalloc(sizeof(*u), GFP_KERNEL);
+	if (!u)
+		return NULL;
+
+	kref_init(&u->kref);
+	u->domain = kdbus_domain_ref(domain);
+	u->uid = uid;
+	atomic_set(&u->buses, 0);
+	atomic_set(&u->connections, 0);
+
+	return u;
+}
+
+/**
  * __kdbus_domain_user_account() - account a kdbus_domain_user object
  *				   into the specified domain
  * @domain:		The domain of the user
-- 
1.9.3



More information about the systemd-devel mailing list