From 7f5fefb7bb65ef35916769988abbec8209889225 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 14 Dec 2006 01:00:16 +0000 Subject: r20165: Change messaging subsystem to only allow one message per type - this is all we use right now and makes re-entrancy problems with deleting handlers with a message dispatch loop go away. Jeremy. (This used to be commit 2e9b6faeae1474d65a5c12f5a19b0ae045d47c2e) --- source3/lib/messages.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'source3') diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 10fc5af24d..66bbebac27 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -458,8 +458,7 @@ static BOOL message_recv(char *msgs_buf, size_t total_len, int *msg_type, /**************************************************************************** Receive and dispatch any messages pending for this process. - Notice that all dispatch handlers for a particular msg_type get called, - so you can register multiple handlers for a message. + 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. ****************************************************************************/ @@ -509,7 +508,8 @@ void message_dispatch(void) } /**************************************************************************** - Register a dispatch function for a particular message type. + Register/replace a dispatch function for a particular message type. + 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. ****************************************************************************/ @@ -520,6 +520,13 @@ void message_register(int msg_type, { struct dispatch_fns *dfn; + for (dfn = dispatch_fns; dfn; dfn = dfn->next) { + if (dfn->msg_type == msg_type) { + dfn->fn = fn; + return; + } + } + dfn = SMB_MALLOC_P(struct dispatch_fns); if (dfn != NULL) { @@ -550,6 +557,7 @@ void message_deregister(int msg_type) if (dfn->msg_type == msg_type) { DLIST_REMOVE(dispatch_fns, dfn); SAFE_FREE(dfn); + return; } } } -- cgit