From f260b45d646ae69602f63c1f6a002384b4828a1c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 24 May 2007 14:47:24 +0000 Subject: r23117: Factor out local messaging. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This removes message_block / message_unblock. I've talked to Jeremy and Günther, giving them my reasons why I believe they have no effect. Neither could come up with a counter-argument, so they go :-) (This used to be commit a925e0991ffbaea4a533bab3a5d61e5d367d46c8) --- source3/lib/messages_local.c | 431 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 431 insertions(+) create mode 100644 source3/lib/messages_local.c (limited to 'source3/lib/messages_local.c') diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c new file mode 100644 index 0000000000..b459ce0238 --- /dev/null +++ b/source3/lib/messages_local.c @@ -0,0 +1,431 @@ +/* + Unix SMB/CIFS implementation. + Samba internal messaging functions + Copyright (C) 2007 by Volker Lendecke + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/** + @defgroup messages Internal messaging framework + @{ + @file messages.c + + @brief Module for internal messaging between Samba daemons. + + The idea is that if a part of Samba wants to do communication with + another Samba process then it will do a message_register() of a + dispatch function, and use message_send_pid() to send messages to + that process. + + The dispatch function is given the pid of the sender, and it can + use that to reply by message_send_pid(). See ping_message() for a + simple example. + + @caution Dispatch functions must be able to cope with incoming + messages on an *odd* byte boundary. + + This system doesn't have any inherent size limitations but is not + very efficient for large messages or when messages are sent in very + quick succession. + +*/ + +#include "includes.h" +#include "librpc/gen_ndr/messaging.h" +#include "librpc/gen_ndr/ndr_messaging.h" + +/* the locking database handle */ +static int received_signal; + +static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, + struct server_id pid, int msg_type, + const DATA_BLOB *data, + struct messaging_backend *backend); + +/**************************************************************************** + Notifications come in as signals. +****************************************************************************/ + +static void sig_usr1(void) +{ + received_signal = 1; + sys_select_signal(SIGUSR1); +} + +static int messaging_tdb_destructor(struct messaging_backend *tdb_ctx) +{ + TDB_CONTEXT *tdb = (TDB_CONTEXT *)tdb_ctx->private_data; + tdb_close(tdb); + return 0; +} + +/**************************************************************************** + Initialise the messaging functions. +****************************************************************************/ + +NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx, + TALLOC_CTX *mem_ctx, + struct messaging_backend **presult) +{ + struct messaging_backend *result; + TDB_CONTEXT *tdb; + + if (!(result = TALLOC_P(mem_ctx, struct messaging_backend))) { + DEBUG(0, ("talloc failed\n")); + return NT_STATUS_NO_MEMORY; + } + + tdb = tdb_open_log(lock_path("messages.tdb"), + 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, + O_RDWR|O_CREAT,0600); + + if (!tdb) { + DEBUG(0,("ERROR: Failed to initialise messages database\n")); + TALLOC_FREE(result); + return NT_STATUS_INTERNAL_DB_CORRUPTION; + } + + sec_init(); + + /* Activate the per-hashchain freelist */ + tdb_set_max_dead(tdb, 5); + + CatchSignal(SIGUSR1, SIGNAL_CAST sig_usr1); + + result->private_data = (void *)tdb; + result->send_fn = messaging_tdb_send; + + talloc_set_destructor(result, messaging_tdb_destructor); + + *presult = result; + return NT_STATUS_OK; +} + +/******************************************************************* + Form a static tdb key from a pid. +******************************************************************/ + +static TDB_DATA message_key_pid(struct server_id pid) +{ + static char key[20]; + TDB_DATA kbuf; + + slprintf(key, sizeof(key)-1, "PID/%s", procid_str_static(&pid)); + + kbuf.dptr = (uint8 *)key; + kbuf.dsize = strlen(key)+1; + return kbuf; +} + +/* + Fetch the messaging array for a process + */ + +static NTSTATUS messaging_tdb_fetch(TDB_CONTEXT *msg_tdb, + TDB_DATA key, + TALLOC_CTX *mem_ctx, + struct messaging_array **presult) +{ + struct messaging_array *result; + TDB_DATA data; + DATA_BLOB blob; + NTSTATUS status; + + if (!(result = TALLOC_ZERO_P(mem_ctx, struct messaging_array))) { + return NT_STATUS_NO_MEMORY; + } + + data = tdb_fetch(msg_tdb, key); + + if (data.dptr == NULL) { + *presult = result; + return NT_STATUS_OK; + } + + blob = data_blob_const(data.dptr, data.dsize); + + status = ndr_pull_struct_blob( + &blob, result, result, + (ndr_pull_flags_fn_t)ndr_pull_messaging_array); + + SAFE_FREE(data.dptr); + + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(result); + return status; + } + + if (DEBUGLEVEL >= 10) { + DEBUG(10, ("messaging_tdb_fetch:\n")); + NDR_PRINT_DEBUG(messaging_array, result); + } + + *presult = result; + return NT_STATUS_OK; +} + +/* + Store a messaging array for a pid +*/ + +static NTSTATUS messaging_tdb_store(TDB_CONTEXT *msg_tdb, + TDB_DATA key, + struct messaging_array *array) +{ + TDB_DATA data; + DATA_BLOB blob; + NTSTATUS status; + TALLOC_CTX *mem_ctx; + int ret; + + if (array->num_messages == 0) { + tdb_delete(msg_tdb, key); + return NT_STATUS_OK; + } + + if (!(mem_ctx = talloc_new(array))) { + return NT_STATUS_NO_MEMORY; + } + + status = ndr_push_struct_blob( + &blob, mem_ctx, array, + (ndr_push_flags_fn_t)ndr_push_messaging_array); + + if (!NT_STATUS_IS_OK(status)) { + talloc_free(mem_ctx); + return status; + } + + if (DEBUGLEVEL >= 10) { + DEBUG(10, ("messaging_tdb_store:\n")); + NDR_PRINT_DEBUG(messaging_array, array); + } + + data.dptr = blob.data; + data.dsize = blob.length; + + ret = tdb_store(msg_tdb, key, data, TDB_REPLACE); + TALLOC_FREE(mem_ctx); + + return (ret == 0) ? NT_STATUS_OK : NT_STATUS_INTERNAL_DB_CORRUPTION; +} + +/**************************************************************************** + Notify a process that it has a message. If the process doesn't exist + then delete its record in the database. +****************************************************************************/ + +static NTSTATUS message_notify(struct server_id procid) +{ + pid_t pid = procid.pid; + int ret; + uid_t euid = geteuid(); + + /* + * Doing kill with a non-positive pid causes messages to be + * sent to places we don't want. + */ + + SMB_ASSERT(pid > 0); + + if (euid != 0) { + /* If we're not root become so to send the message. */ + save_re_uid(); + set_effective_uid(0); + } + + ret = kill(pid, SIGUSR1); + + if (euid != 0) { + /* Go back to who we were. */ + int saved_errno = errno; + restore_re_uid_fromroot(); + errno = saved_errno; + } + + if (ret == 0) { + return NT_STATUS_OK; + } + + /* + * Something has gone wrong + */ + + DEBUG(2,("message to process %d failed - %s\n", (int)pid, + strerror(errno))); + + /* + * No call to map_nt_error_from_unix -- don't want to link in + * errormap.o into lots of utils. + */ + + if (errno == ESRCH) return NT_STATUS_INVALID_HANDLE; + if (errno == EINVAL) return NT_STATUS_INVALID_PARAMETER; + if (errno == EPERM) return NT_STATUS_ACCESS_DENIED; + return NT_STATUS_UNSUCCESSFUL; +} + +/**************************************************************************** + Send a message to a particular pid. +****************************************************************************/ + +static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, + struct server_id pid, int msg_type, + const DATA_BLOB *data, + struct messaging_backend *backend) +{ + struct messaging_array *msg_array; + struct messaging_rec *rec; + TALLOC_CTX *mem_ctx; + NTSTATUS status; + TDB_DATA key = message_key_pid(pid); + TDB_CONTEXT *tdb = (TDB_CONTEXT *)backend->private_data; + + /* NULL pointer means implicit length zero. */ + if (!data->data) { + SMB_ASSERT(data->length == 0); + } + + /* + * Doing kill with a non-positive pid causes messages to be + * sent to places we don't want. + */ + + SMB_ASSERT(procid_to_pid(&pid) > 0); + + if (!(mem_ctx = talloc_init("message_send_pid"))) { + return NT_STATUS_NO_MEMORY; + } + + if (tdb_chainlock(tdb, key) == -1) { + TALLOC_FREE(mem_ctx); + return NT_STATUS_LOCK_NOT_GRANTED; + } + + status = messaging_tdb_fetch(tdb, key, mem_ctx, &msg_array); + + if (!NT_STATUS_IS_OK(status)) { + goto done; + } + + if ((msg_type & MSG_FLAG_LOWPRIORITY) + && (msg_array->num_messages > 1000)) { + DEBUG(5, ("Dropping message for PID %s\n", + procid_str_static(&pid))); + status = NT_STATUS_INSUFFICIENT_RESOURCES; + goto done; + } + + if (!(rec = TALLOC_REALLOC_ARRAY(mem_ctx, msg_array->messages, + struct messaging_rec, + msg_array->num_messages+1))) { + status = NT_STATUS_NO_MEMORY; + goto done; + } + + rec[msg_array->num_messages].msg_version = MESSAGE_VERSION; + rec[msg_array->num_messages].msg_type = msg_type & MSG_TYPE_MASK; + rec[msg_array->num_messages].dest = pid; + rec[msg_array->num_messages].src = procid_self(); + rec[msg_array->num_messages].buf = *data; + + msg_array->messages = rec; + msg_array->num_messages += 1; + + status = messaging_tdb_store(tdb, key, msg_array); + + if (!NT_STATUS_IS_OK(status)) { + goto done; + } + + status = message_notify(pid); + + if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) { + DEBUG(2, ("pid %s doesn't exist - deleting messages record\n", + procid_str_static(&pid))); + tdb_delete(tdb, message_key_pid(pid)); + } + + done: + tdb_chainunlock(tdb, key); + TALLOC_FREE(mem_ctx); + return status; +} + +/**************************************************************************** + Retrieve all messages for the current process. +****************************************************************************/ + +static NTSTATUS retrieve_all_messages(TDB_CONTEXT *msg_tdb, + TALLOC_CTX *mem_ctx, + struct messaging_array **presult) +{ + struct messaging_array *result; + TDB_DATA key = message_key_pid(procid_self()); + NTSTATUS status; + + if (tdb_chainlock(msg_tdb, key) == -1) { + return NT_STATUS_LOCK_NOT_GRANTED; + } + + status = messaging_tdb_fetch(msg_tdb, key, mem_ctx, &result); + + /* + * We delete the record here, tdb_set_max_dead keeps it around + */ + tdb_delete(msg_tdb, key); + tdb_chainunlock(msg_tdb, key); + + if (NT_STATUS_IS_OK(status)) { + *presult = result; + } + + return status; +} + +/**************************************************************************** + Receive and dispatch any messages pending for this process. + JRA changed Dec 13 2006. Only one message handler now permitted per type. + *NOTE*: Dispatch functions must be able to cope with incoming + messages on an *odd* byte boundary. +****************************************************************************/ + +void message_dispatch(struct messaging_context *msg_ctx) +{ + struct messaging_array *msg_array = NULL; + TDB_CONTEXT *tdb = (TDB_CONTEXT *)(msg_ctx->local->private_data); + uint32 i; + + if (!received_signal) + return; + + DEBUG(10, ("message_dispatch: received_signal = %d\n", + received_signal)); + + received_signal = 0; + + if (!NT_STATUS_IS_OK(retrieve_all_messages(tdb, NULL, &msg_array))) { + return; + } + + for (i=0; inum_messages; i++) { + messaging_dispatch_rec(msg_ctx, &msg_array->messages[i]); + } + + TALLOC_FREE(msg_array); +} + +/** @} **/ -- cgit From 3f0f678154039f1906d207e5246d955394b17967 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 4 Jun 2007 19:50:30 +0000 Subject: r23344: Better error message (This used to be commit 4042d2cdd2797e2f675ddeb0d288327ca55d9f5b) --- source3/lib/messages_local.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/lib/messages_local.c') diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c index b459ce0238..f210bff695 100644 --- a/source3/lib/messages_local.c +++ b/source3/lib/messages_local.c @@ -93,9 +93,11 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx, O_RDWR|O_CREAT,0600); if (!tdb) { - DEBUG(0,("ERROR: Failed to initialise messages database\n")); + NTSTATUS status = map_nt_error_from_unix(errno); + DEBUG(0, ("ERROR: Failed to initialise messages database: " + "%s\n", strerror(errno))); TALLOC_FREE(result); - return NT_STATUS_INTERNAL_DB_CORRUPTION; + return status; } sec_init(); -- cgit From b05c7b97830f6029c264fc44831c2f5eae4f0c83 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 10 Jun 2007 10:18:03 +0000 Subject: r23408: Remove a bogus comment (This used to be commit 0442e680eeacb56852e200fdf6f78e4972ecad68) --- source3/lib/messages_local.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/lib/messages_local.c') diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c index f210bff695..1f50e5bb6f 100644 --- a/source3/lib/messages_local.c +++ b/source3/lib/messages_local.c @@ -47,7 +47,6 @@ #include "librpc/gen_ndr/messaging.h" #include "librpc/gen_ndr/ndr_messaging.h" -/* the locking database handle */ static int received_signal; static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/lib/messages_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/messages_local.c') diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c index 1f50e5bb6f..efd6d23ecd 100644 --- a/source3/lib/messages_local.c +++ b/source3/lib/messages_local.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/lib/messages_local.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/messages_local.c') diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c index efd6d23ecd..db098f2744 100644 --- a/source3/lib/messages_local.c +++ b/source3/lib/messages_local.c @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ /** -- cgit From f9578af966c1c1b5b5df4acac9977472d2896bea Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 9 Nov 2007 14:39:45 +0100 Subject: ndr: change NTSTAUS into enum ndr_err_code (samba3 callers) lib/messages_local.c rpc_client/ndr.c smbd/notify_internal.c utils/net_rpc_registry.c metze (This used to be commit c2645d2164c05976a98bafed980b6029baf89977) --- source3/lib/messages_local.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/lib/messages_local.c') diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c index db098f2744..5f7c46f61e 100644 --- a/source3/lib/messages_local.c +++ b/source3/lib/messages_local.c @@ -142,7 +142,7 @@ static NTSTATUS messaging_tdb_fetch(TDB_CONTEXT *msg_tdb, struct messaging_array *result; TDB_DATA data; DATA_BLOB blob; - NTSTATUS status; + enum ndr_err_code ndr_err; if (!(result = TALLOC_ZERO_P(mem_ctx, struct messaging_array))) { return NT_STATUS_NO_MEMORY; @@ -157,15 +157,15 @@ static NTSTATUS messaging_tdb_fetch(TDB_CONTEXT *msg_tdb, blob = data_blob_const(data.dptr, data.dsize); - status = ndr_pull_struct_blob( + ndr_err = ndr_pull_struct_blob( &blob, result, result, (ndr_pull_flags_fn_t)ndr_pull_messaging_array); SAFE_FREE(data.dptr); - if (!NT_STATUS_IS_OK(status)) { + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { TALLOC_FREE(result); - return status; + return ndr_map_error2ntstatus(ndr_err); } if (DEBUGLEVEL >= 10) { @@ -187,7 +187,7 @@ static NTSTATUS messaging_tdb_store(TDB_CONTEXT *msg_tdb, { TDB_DATA data; DATA_BLOB blob; - NTSTATUS status; + enum ndr_err_code ndr_err; TALLOC_CTX *mem_ctx; int ret; @@ -200,13 +200,13 @@ static NTSTATUS messaging_tdb_store(TDB_CONTEXT *msg_tdb, return NT_STATUS_NO_MEMORY; } - status = ndr_push_struct_blob( + ndr_err = ndr_push_struct_blob( &blob, mem_ctx, array, (ndr_push_flags_fn_t)ndr_push_messaging_array); - if (!NT_STATUS_IS_OK(status)) { + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { talloc_free(mem_ctx); - return status; + return ndr_map_error2ntstatus(ndr_err); } if (DEBUGLEVEL >= 10) { -- cgit From 2b17840a0efdc7de3d9abfa262a64f73ada3f301 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 25 Nov 2007 09:33:29 +0100 Subject: Remove a static, and "signal_received" needs to be sig_atomic_t (This used to be commit 8acd4a202f6b4518c2ce9cdd30f5dfb14b86c07c) --- source3/lib/messages_local.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'source3/lib/messages_local.c') diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c index 5f7c46f61e..0cd482647a 100644 --- a/source3/lib/messages_local.c +++ b/source3/lib/messages_local.c @@ -46,7 +46,7 @@ #include "librpc/gen_ndr/messaging.h" #include "librpc/gen_ndr/ndr_messaging.h" -static int received_signal; +static sig_atomic_t received_signal; static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, struct server_id pid, int msg_type, @@ -118,12 +118,14 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx, Form a static tdb key from a pid. ******************************************************************/ -static TDB_DATA message_key_pid(struct server_id pid) +static TDB_DATA message_key_pid(TALLOC_CTX *mem_ctx, struct server_id pid) { - static char key[20]; + char *key; TDB_DATA kbuf; - slprintf(key, sizeof(key)-1, "PID/%s", procid_str_static(&pid)); + key = talloc_asprintf(talloc_tos(), "PID/%s", procid_str_static(&pid)); + + SMB_ASSERT(key != NULL); kbuf.dptr = (uint8 *)key; kbuf.dsize = strlen(key)+1; @@ -289,10 +291,10 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, { struct messaging_array *msg_array; struct messaging_rec *rec; - TALLOC_CTX *mem_ctx; NTSTATUS status; - TDB_DATA key = message_key_pid(pid); + TDB_DATA key; TDB_CONTEXT *tdb = (TDB_CONTEXT *)backend->private_data; + TALLOC_CTX *frame = talloc_stackframe(); /* NULL pointer means implicit length zero. */ if (!data->data) { @@ -306,16 +308,14 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, SMB_ASSERT(procid_to_pid(&pid) > 0); - if (!(mem_ctx = talloc_init("message_send_pid"))) { - return NT_STATUS_NO_MEMORY; - } + key = message_key_pid(frame, pid); if (tdb_chainlock(tdb, key) == -1) { - TALLOC_FREE(mem_ctx); + TALLOC_FREE(frame); return NT_STATUS_LOCK_NOT_GRANTED; } - status = messaging_tdb_fetch(tdb, key, mem_ctx, &msg_array); + status = messaging_tdb_fetch(tdb, key, talloc_tos(), &msg_array); if (!NT_STATUS_IS_OK(status)) { goto done; @@ -329,7 +329,7 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, goto done; } - if (!(rec = TALLOC_REALLOC_ARRAY(mem_ctx, msg_array->messages, + if (!(rec = TALLOC_REALLOC_ARRAY(talloc_tos(), msg_array->messages, struct messaging_rec, msg_array->num_messages+1))) { status = NT_STATUS_NO_MEMORY; @@ -356,12 +356,12 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) { DEBUG(2, ("pid %s doesn't exist - deleting messages record\n", procid_str_static(&pid))); - tdb_delete(tdb, message_key_pid(pid)); + tdb_delete(tdb, message_key_pid(talloc_tos(), pid)); } done: tdb_chainunlock(tdb, key); - TALLOC_FREE(mem_ctx); + TALLOC_FREE(frame); return status; } @@ -374,10 +374,11 @@ static NTSTATUS retrieve_all_messages(TDB_CONTEXT *msg_tdb, struct messaging_array **presult) { struct messaging_array *result; - TDB_DATA key = message_key_pid(procid_self()); + TDB_DATA key = message_key_pid(mem_ctx, procid_self()); NTSTATUS status; if (tdb_chainlock(msg_tdb, key) == -1) { + TALLOC_FREE(key.dptr); return NT_STATUS_LOCK_NOT_GRANTED; } @@ -393,6 +394,8 @@ static NTSTATUS retrieve_all_messages(TDB_CONTEXT *msg_tdb, *presult = result; } + TALLOC_FREE(key.dptr); + return status; } -- cgit From 3a0437623e2e1043ced3db5b300a17a85bf69324 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 18 May 2008 14:30:33 +0200 Subject: Convert messages_local.c to use "struct tdb_wrap" This works around a problem with smbcontrol opening messaging.tdb twice. Very likely this is not the right fix. Michael, please check. Volker (This used to be commit 9d52cf3f9394eb78465173bad53ea8dc86512213) --- source3/lib/messages_local.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'source3/lib/messages_local.c') diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c index 0cd482647a..f436afc2ff 100644 --- a/source3/lib/messages_local.c +++ b/source3/lib/messages_local.c @@ -65,8 +65,8 @@ static void sig_usr1(void) static int messaging_tdb_destructor(struct messaging_backend *tdb_ctx) { - TDB_CONTEXT *tdb = (TDB_CONTEXT *)tdb_ctx->private_data; - tdb_close(tdb); + struct tdb_wrap *tdb = (struct tdb_wrap *)tdb_ctx->private_data; + TALLOC_FREE(tdb); return 0; } @@ -79,16 +79,16 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx, struct messaging_backend **presult) { struct messaging_backend *result; - TDB_CONTEXT *tdb; + struct tdb_wrap *tdb; if (!(result = TALLOC_P(mem_ctx, struct messaging_backend))) { DEBUG(0, ("talloc failed\n")); return NT_STATUS_NO_MEMORY; } - tdb = tdb_open_log(lock_path("messages.tdb"), - 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, - O_RDWR|O_CREAT,0600); + tdb = tdb_wrap_open(result, lock_path("messages.tdb"), + 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, + O_RDWR|O_CREAT,0600); if (!tdb) { NTSTATUS status = map_nt_error_from_unix(errno); @@ -101,7 +101,7 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx, sec_init(); /* Activate the per-hashchain freelist */ - tdb_set_max_dead(tdb, 5); + tdb_set_max_dead(tdb->tdb, 5); CatchSignal(SIGUSR1, SIGNAL_CAST sig_usr1); @@ -293,7 +293,7 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, struct messaging_rec *rec; NTSTATUS status; TDB_DATA key; - TDB_CONTEXT *tdb = (TDB_CONTEXT *)backend->private_data; + struct tdb_wrap *tdb = (struct tdb_wrap *)backend->private_data; TALLOC_CTX *frame = talloc_stackframe(); /* NULL pointer means implicit length zero. */ @@ -310,12 +310,12 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, key = message_key_pid(frame, pid); - if (tdb_chainlock(tdb, key) == -1) { + if (tdb_chainlock(tdb->tdb, key) == -1) { TALLOC_FREE(frame); return NT_STATUS_LOCK_NOT_GRANTED; } - status = messaging_tdb_fetch(tdb, key, talloc_tos(), &msg_array); + status = messaging_tdb_fetch(tdb->tdb, key, talloc_tos(), &msg_array); if (!NT_STATUS_IS_OK(status)) { goto done; @@ -345,7 +345,7 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, msg_array->messages = rec; msg_array->num_messages += 1; - status = messaging_tdb_store(tdb, key, msg_array); + status = messaging_tdb_store(tdb->tdb, key, msg_array); if (!NT_STATUS_IS_OK(status)) { goto done; @@ -356,11 +356,11 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) { DEBUG(2, ("pid %s doesn't exist - deleting messages record\n", procid_str_static(&pid))); - tdb_delete(tdb, message_key_pid(talloc_tos(), pid)); + tdb_delete(tdb->tdb, message_key_pid(talloc_tos(), pid)); } done: - tdb_chainunlock(tdb, key); + tdb_chainunlock(tdb->tdb, key); TALLOC_FREE(frame); return status; } @@ -409,7 +409,8 @@ static NTSTATUS retrieve_all_messages(TDB_CONTEXT *msg_tdb, void message_dispatch(struct messaging_context *msg_ctx) { struct messaging_array *msg_array = NULL; - TDB_CONTEXT *tdb = (TDB_CONTEXT *)(msg_ctx->local->private_data); + struct tdb_wrap *tdb = (struct tdb_wrap *) + (msg_ctx->local->private_data); uint32 i; if (!received_signal) @@ -420,7 +421,8 @@ void message_dispatch(struct messaging_context *msg_ctx) received_signal = 0; - if (!NT_STATUS_IS_OK(retrieve_all_messages(tdb, NULL, &msg_array))) { + if (!NT_STATUS_IS_OK(retrieve_all_messages(tdb->tdb, NULL, + &msg_array))) { return; } -- cgit