1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-04 08:22:08 +03:00

much nicer message interface. We now register dispatch functions,

allowing new bits of code or vfs modules to register functions without
impacting on the messaging code itself.

Also note that multiple registrations for the same message type are
possible allowing the same message to be delivered to multiple parts
of the code (possibly useful for reload messages).
This commit is contained in:
Andrew Tridgell
-
parent e08b521559
commit c3350c77f5
3 changed files with 66 additions and 28 deletions

View File

@ -59,9 +59,9 @@ uint32 crc32_calc_buffer( char *buffer, uint32 count);
/*The following definitions come from lib/debug.c */
void debug_message(pid_t src, void *buf, int len);
void debug_message(enum message_type msg_type, pid_t src, void *buf, size_t len);
void debug_message_send(pid_t pid, int level);
void setup_logging( char *pname, BOOL interactive );
void setup_logging(char *pname, BOOL interactive);
void reopen_logs( void );
void force_check_log_size( void );
BOOL need_to_check_log_size( void );
@ -155,6 +155,8 @@ void mdfour(unsigned char *out, unsigned char *in, int n);
BOOL message_init(void);
BOOL message_send_pid(pid_t pid, enum message_type msg_type, void *buf, size_t len);
void message_dispatch(void);
void message_register(enum message_type msg_type,
void (*fn)(enum message_type msg_type, pid_t pid, void *buf, size_t len));
/*The following definitions come from lib/ms_fnmatch.c */

View File

@ -122,7 +122,7 @@ static size_t format_pos = 0;
/****************************************************************************
receive a "set debug level" message
****************************************************************************/
void debug_message(pid_t src, void *buf, int len)
void debug_message(enum message_type msg_type, pid_t src, void *buf, size_t len)
{
int level;
memcpy(&level, buf, sizeof(int));
@ -143,19 +143,18 @@ void debug_message_send(pid_t pid, int level)
* get ready for syslog stuff
* ************************************************************************** **
*/
void setup_logging( char *pname, BOOL interactive )
{
if( interactive )
{
void setup_logging(char *pname, BOOL interactive)
{
message_register(MSG_DEBUG, debug_message);
if (interactive) {
stdout_logging = True;
dbf = stdout;
}
#ifdef WITH_SYSLOG
else
{
else {
char *p = strrchr( pname,'/' );
if( p )
if (p)
pname = p + 1;
#ifdef LOG_DAEMON
openlog( pname, LOG_PID, SYSLOG_FACILITY );
@ -164,7 +163,7 @@ void setup_logging( char *pname, BOOL interactive )
#endif
}
#endif
} /* setup_logging */
} /* setup_logging */
/* ************************************************************************** **
* reopen the log files

View File

@ -19,7 +19,18 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* this module is used for internal messaging between Samba daemons. */
/* this module is used 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.
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"
@ -38,6 +49,13 @@ struct message_rec {
size_t len;
};
/* we have a linked list of dispatch handlers */
static struct dispatch_fns {
struct dispatch_fns *next, *prev;
enum message_type msg_type;
void (*fn)(enum message_type msg_type, pid_t pid, void *buf, size_t len);
} *dispatch_fns;
/****************************************************************************
notifications come in as signals
****************************************************************************/
@ -213,6 +231,8 @@ static BOOL message_recv(enum message_type *msg_type, pid_t *src, void **buf, si
/****************************************************************************
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
****************************************************************************/
void message_dispatch(void)
{
@ -220,18 +240,35 @@ void message_dispatch(void)
pid_t src;
void *buf;
size_t len;
struct dispatch_fns *dfn;
if (!received_signal) return;
received_signal = 0;
while (message_recv(&msg_type, &src, &buf, &len)) {
switch (msg_type) {
case MSG_DEBUG:
debug_message(src, buf, len);
break;
default:
DEBUG(0,("Unknown message type %d from %d\n", msg_type, (int)src));
break;
for (dfn = dispatch_fns; dfn; dfn = dfn->next) {
if (dfn->msg_type == msg_type) {
dfn->fn(msg_type, src, buf, len);
}
}
}
}
/****************************************************************************
register a dispatch function for a particular message type
****************************************************************************/
void message_register(enum message_type msg_type,
void (*fn)(enum message_type msg_type, pid_t pid, void *buf, size_t len))
{
struct dispatch_fns *dfn;
dfn = (struct dispatch_fns *)malloc(sizeof(*dfn));
ZERO_STRUCTP(dfn);
dfn->msg_type = msg_type;
dfn->fn = fn;
DLIST_ADD(dispatch_fns, dfn);
}