diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2009-01-22 22:49:30 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2009-01-22 22:49:30 +0100 |
commit | 1fcd85e8b9235301c7bc6c4c0878e73ddcbd4b16 (patch) | |
tree | 769f8e097b5225d8627bbb6698106000f226754e /source3/lib/messages_local.c | |
parent | ebb929779bf9f4aa0cb9695a3ee5ce5d550bcecc (diff) | |
parent | 8e2b48e1b7c7fd6b6080f2e56f654b682c6426a3 (diff) | |
download | samba-1fcd85e8b9235301c7bc6c4c0878e73ddcbd4b16.tar.gz samba-1fcd85e8b9235301c7bc6c4c0878e73ddcbd4b16.tar.bz2 samba-1fcd85e8b9235301c7bc6c4c0878e73ddcbd4b16.zip |
Merge branch 'master' of ssh://git.samba.org/data/git/samba
Diffstat (limited to 'source3/lib/messages_local.c')
-rw-r--r-- | source3/lib/messages_local.c | 105 |
1 files changed, 67 insertions, 38 deletions
diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c index 9f7f88f783..be848ac8ba 100644 --- a/source3/lib/messages_local.c +++ b/source3/lib/messages_local.c @@ -46,28 +46,33 @@ #include "librpc/gen_ndr/messaging.h" #include "librpc/gen_ndr/ndr_messaging.h" -static sig_atomic_t received_signal; +struct messaging_tdb_context { + struct messaging_context *msg_ctx; + struct tdb_wrap *tdb; + struct tevent_signal *se; + int received_messages; +}; 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); +static void message_dispatch(struct messaging_context *msg_ctx); -/**************************************************************************** - Notifications come in as signals. -****************************************************************************/ - -static void sig_usr1(void) +static void messaging_tdb_signal_handler(struct tevent_context *ev_ctx, + struct tevent_signal *se, + int signum, int count, + void *_info, void *private_data) { - received_signal = 1; - sys_select_signal(SIGUSR1); -} + struct messaging_tdb_context *ctx = talloc_get_type(private_data, + struct messaging_tdb_context); -static int messaging_tdb_destructor(struct messaging_backend *tdb_ctx) -{ - struct tdb_wrap *tdb = (struct tdb_wrap *)tdb_ctx->private_data; - TALLOC_FREE(tdb); - return 0; + ctx->received_messages++; + + DEBUG(10, ("messaging_tdb_signal_handler: sig[%d] count[%d] msgs[%d]\n", + signum, count, ctx->received_messages)); + + message_dispatch(ctx->msg_ctx); } /**************************************************************************** @@ -79,18 +84,29 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx, struct messaging_backend **presult) { struct messaging_backend *result; - struct tdb_wrap *tdb; + struct messaging_tdb_context *ctx; if (!(result = TALLOC_P(mem_ctx, struct messaging_backend))) { DEBUG(0, ("talloc failed\n")); return NT_STATUS_NO_MEMORY; } - tdb = tdb_wrap_open(result, lock_path("messages.tdb"), - 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, - O_RDWR|O_CREAT,0600); + ctx = TALLOC_ZERO_P(result, struct messaging_tdb_context); + if (!ctx) { + DEBUG(0, ("talloc failed\n")); + TALLOC_FREE(result); + return NT_STATUS_NO_MEMORY; + } + result->private_data = ctx; + result->send_fn = messaging_tdb_send; + + ctx->msg_ctx = msg_ctx; + + ctx->tdb = tdb_wrap_open(ctx, lock_path("messages.tdb"), + 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, + O_RDWR|O_CREAT,0600); - if (!tdb) { + if (!ctx->tdb) { NTSTATUS status = map_nt_error_from_unix(errno); DEBUG(0, ("ERROR: Failed to initialise messages database: " "%s\n", strerror(errno))); @@ -98,17 +114,23 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx, return status; } + ctx->se = tevent_add_signal(msg_ctx->event_ctx, + ctx, + SIGUSR1, 0, + messaging_tdb_signal_handler, + ctx); + if (!ctx->se) { + NTSTATUS status = map_nt_error_from_unix(errno); + DEBUG(0, ("ERROR: Failed to initialise messages signal handler: " + "%s\n", strerror(errno))); + TALLOC_FREE(result); + return status; + } + sec_init(); /* Activate the per-hashchain freelist */ - tdb_set_max_dead(tdb->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); + tdb_set_max_dead(ctx->tdb->tdb, 5); *presult = result; return NT_STATUS_OK; @@ -289,11 +311,13 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx, const DATA_BLOB *data, struct messaging_backend *backend) { + struct messaging_tdb_context *ctx = talloc_get_type(backend->private_data, + struct messaging_tdb_context); struct messaging_array *msg_array; struct messaging_rec *rec; NTSTATUS status; TDB_DATA key; - struct tdb_wrap *tdb = (struct tdb_wrap *)backend->private_data; + struct tdb_wrap *tdb = ctx->tdb; TALLOC_CTX *frame = talloc_stackframe(); /* NULL pointer means implicit length zero. */ @@ -406,26 +430,31 @@ static NTSTATUS retrieve_all_messages(TDB_CONTEXT *msg_tdb, messages on an *odd* byte boundary. ****************************************************************************/ -void message_dispatch(struct messaging_context *msg_ctx) +static void message_dispatch(struct messaging_context *msg_ctx) { + struct messaging_tdb_context *ctx = talloc_get_type(msg_ctx->local->private_data, + struct messaging_tdb_context); struct messaging_array *msg_array = NULL; - struct tdb_wrap *tdb = (struct tdb_wrap *) - (msg_ctx->local->private_data); + struct tdb_wrap *tdb = ctx->tdb; + NTSTATUS status; uint32 i; - if (!received_signal) + if (ctx->received_messages == 0) { return; + } - DEBUG(10, ("message_dispatch: received_signal = %d\n", - received_signal)); - - received_signal = 0; + DEBUG(10, ("message_dispatch: received_messages = %d\n", + ctx->received_messages)); - if (!NT_STATUS_IS_OK(retrieve_all_messages(tdb->tdb, NULL, - &msg_array))) { + status = retrieve_all_messages(tdb->tdb, NULL, &msg_array); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("message_dispatch: failed to retrieve messages: %s\n", + nt_errstr(status))); return; } + ctx->received_messages = 0; + for (i=0; i<msg_array->num_messages; i++) { messaging_dispatch_rec(msg_ctx, &msg_array->messages[i]); } |