]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3-lib Add a way to allocate the task_id value in server_id
authorAndrew Bartlett <abartlet@samba.org>
Thu, 21 Jul 2011 06:29:38 +0000 (16:29 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 30 Apr 2012 07:55:12 +0000 (17:55 +1000)
This safely allocates the task_id so that when we have multiple event
contexts, they can each have their own messaging context, particularly
for the imessaging subsystem under source4.

Andrew Bartlett

source3/Makefile.in
source3/include/proto.h
source3/lib/util.c

index e5aba232737d076101ca2a7c9187f830ba428700..37419de5e506952203725574439ecd0a363ded54 100644 (file)
@@ -484,7 +484,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) $(LIBTSOCKET_OBJ) \
          lib/file_id.o lib/idmap_cache.o \
          ../libcli/security/dom_sid.o ../libcli/security/security_descriptor.o \
          ../libcli/security/security_token.o ../libcli/security/util_sid.o \
-         ../libcli/smb/util.o
+         ../libcli/smb/util.o ../lib/util/idtree.o
 
 LIB_DUMMY_OBJ = lib/smbd_shim.o lib/dummyparam.o
 LIB_NONSMBD_OBJ = $(LIB_OBJ) $(LIB_DUMMY_OBJ)
@@ -593,7 +593,6 @@ LIBTSOCKET_OBJ = ../lib/tsocket/tsocket.o \
 
 CLDAP_OBJ = libads/cldap.o \
        ../libcli/cldap/cldap.o \
-       ../lib/util/idtree.o \
        $(LIBCLI_LDAP_MESSAGE_OBJ) $(LIBCLI_LDAP_NDR_OBJ)
 
 TLDAP_OBJ = lib/tldap.o lib/tldap_util.o lib/util_tsock.o
index 8392b68797293fb61547aa5f374cc997e726c8a0..c2c74fae81c12c113f71cd5560bb82d0bc588971 100644 (file)
@@ -517,6 +517,7 @@ uint32 get_my_vnn(void);
 void set_my_unique_id(uint64_t unique_id);
 struct server_id pid_to_procid(pid_t pid);
 struct server_id procid_self(void);
+struct server_id *new_server_id_task(TALLOC_CTX *mem_ctx);
 bool procid_equal(const struct server_id *p1, const struct server_id *p2);
 bool cluster_id_equal(const struct server_id *id1,
                      const struct server_id *id2);
index e43cfbbcb88137213ccf19d0c459ded41559ba8e..7913ce9ee7815d6f0a32dd6fd436c5d55b6bfe85 100644 (file)
@@ -2016,6 +2016,48 @@ struct server_id procid_self(void)
        return pid_to_procid(getpid());
 }
 
+static struct idr_context *task_id_tree;
+
+static int free_task_id(struct server_id *server_id)
+{
+       idr_remove(task_id_tree, server_id->task_id);
+       return 0;
+}
+
+/* Return a server_id with a unique task_id element.  Free the
+ * returned pointer to de-allocate the task_id via a talloc destructor
+ * (ie, use talloc_free()) */
+struct server_id *new_server_id_task(TALLOC_CTX *mem_ctx)
+{
+       struct server_id *server_id;
+       int task_id;
+       if (!task_id_tree) {
+               task_id_tree = idr_init(NULL);
+               if (!task_id_tree) {
+                       return NULL;
+               }
+       }
+
+       server_id = talloc(mem_ctx, struct server_id);
+
+       if (!server_id) {
+               return NULL;
+       }
+       *server_id = procid_self();
+
+       /* 0 is the default server_id, so we need to start with 1 */
+       task_id = idr_get_new_above(task_id_tree, server_id, 1, INT32_MAX);
+
+       if (task_id == -1) {
+               talloc_free(server_id);
+               return NULL;
+       }
+
+       talloc_set_destructor(server_id, free_task_id);
+       server_id->task_id = task_id;
+       return server_id;
+}
+
 bool procid_equal(const struct server_id *p1, const struct server_id *p2)
 {
        if (p1->pid != p2->pid)