diff options
author | Andrew Bartlett <abartlet@samba.org> | 2011-07-21 16:29:38 +1000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2012-04-30 17:55:12 +1000 |
commit | 442a81e7b282eef85d3c7d978846a531b55cbd5f (patch) | |
tree | b5b82c36137e530f3496186e76bf05c04645e92e | |
parent | f10c63810077a6759a9df4e9c653066f9f355d96 (diff) | |
download | samba-442a81e7b282eef85d3c7d978846a531b55cbd5f.tar.gz samba-442a81e7b282eef85d3c7d978846a531b55cbd5f.tar.bz2 samba-442a81e7b282eef85d3c7d978846a531b55cbd5f.zip |
s3-lib Add a way to allocate the task_id value in server_id
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
-rw-r--r-- | source3/Makefile.in | 3 | ||||
-rw-r--r-- | source3/include/proto.h | 1 | ||||
-rw-r--r-- | source3/lib/util.c | 42 |
3 files changed, 44 insertions, 2 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in index e5aba23273..37419de5e5 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -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 diff --git a/source3/include/proto.h b/source3/include/proto.h index 8392b68797..c2c74fae81 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -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); diff --git a/source3/lib/util.c b/source3/lib/util.c index e43cfbbcb8..7913ce9ee7 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -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) |