summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/include/proto.h6
-rw-r--r--source3/lib/debug.c35
-rw-r--r--source3/lib/messages.c53
3 files changed, 66 insertions, 28 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 754c51ee9d..f12f7e1570 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -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 */
diff --git a/source3/lib/debug.c b/source3/lib/debug.c
index 5279dda2e3..e67aea7fd3 100644
--- a/source3/lib/debug.c
+++ b/source3/lib/debug.c
@@ -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,28 +143,27 @@ void debug_message_send(pid_t pid, int level)
* get ready for syslog stuff
* ************************************************************************** **
*/
-void setup_logging( char *pname, BOOL interactive )
- {
- if( interactive )
- {
- stdout_logging = True;
- dbf = stdout;
- }
-#ifdef WITH_SYSLOG
- else
- {
- char *p = strrchr( pname,'/' );
+void setup_logging(char *pname, BOOL interactive)
+{
+ message_register(MSG_DEBUG, debug_message);
- if( p )
- pname = p + 1;
+ if (interactive) {
+ stdout_logging = True;
+ dbf = stdout;
+ }
+#ifdef WITH_SYSLOG
+ else {
+ char *p = strrchr( pname,'/' );
+ if (p)
+ pname = p + 1;
#ifdef LOG_DAEMON
- openlog( pname, LOG_PID, SYSLOG_FACILITY );
+ openlog( pname, LOG_PID, SYSLOG_FACILITY );
#else /* for old systems that have no facility codes. */
- openlog( pname, LOG_PID );
+ openlog( pname, LOG_PID );
#endif
- }
+ }
#endif
- } /* setup_logging */
+} /* setup_logging */
/* ************************************************************************** **
* reopen the log files
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index 30eef40ec9..bbda5d71ed 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -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);
+}