From f0ce4f7ae3b58f45b70598e3a44539e3e12291ce Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 12 Sep 2000 06:13:25 +0000 Subject: - changed the msg_type to be an int instead of an enum so that it is easier to add new message types to messages.h without breaking old binaries - added a MSG_FORCE_ELECTION message to force nmbd to hold an election (This used to be commit f1c49ca7ce56bc39259041a71479e84ebf53eeca) --- source3/include/messages.h | 7 ++++++- source3/include/proto.h | 9 +++++---- source3/lib/debug.c | 2 +- source3/lib/messages.c | 31 ++++++++++++++++++------------- source3/nmbd/nmbd.c | 7 ++++--- source3/nmbd/nmbd_elections.c | 21 +++++++++++++++++++++ source3/nmbd/nmbd_packets.c | 11 ----------- source3/utils/msgtest.c | 2 +- 8 files changed, 56 insertions(+), 34 deletions(-) (limited to 'source3') diff --git a/source3/include/messages.h b/source3/include/messages.h index 4bc4014ca0..6ab21e7433 100644 --- a/source3/include/messages.h +++ b/source3/include/messages.h @@ -22,6 +22,11 @@ #ifndef _MESSAGES_H_ #define _MESSAGES_H_ -enum message_type {MSG_DEBUG}; +/* general messages */ +#define MSG_DEBUG 1 +#define MSG_PING 2 + +/* nmbd messages */ +#define MSG_FORCE_ELECTION 1001 #endif diff --git a/source3/include/proto.h b/source3/include/proto.h index f12f7e1570..4fc539ef6e 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -59,7 +59,7 @@ uint32 crc32_calc_buffer( char *buffer, uint32 count); /*The following definitions come from lib/debug.c */ -void debug_message(enum message_type msg_type, pid_t src, void *buf, size_t len); +void debug_message(int 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 reopen_logs( void ); @@ -153,10 +153,10 @@ void mdfour(unsigned char *out, unsigned char *in, int n); /*The following definitions come from lib/messages.c */ BOOL message_init(void); -BOOL message_send_pid(pid_t pid, enum message_type msg_type, void *buf, size_t len); +BOOL message_send_pid(pid_t pid, int 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)); +void message_register(int msg_type, + void (*fn)(int msg_type, pid_t pid, void *buf, size_t len)); /*The following definitions come from lib/ms_fnmatch.c */ @@ -997,6 +997,7 @@ void check_master_browser_exists(time_t t); void run_elections(time_t t); void process_election(struct subnet_record *subrec, struct packet_struct *p, char *buf); BOOL check_elections(void); +void nmbd_message_election(int msg_type, pid_t src, void *buf, size_t len); /*The following definitions come from nmbd/nmbd_incomingdgrams.c */ diff --git a/source3/lib/debug.c b/source3/lib/debug.c index e67aea7fd3..1a53f4c2a8 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(enum message_type msg_type, pid_t src, void *buf, size_t len) +void debug_message(int msg_type, pid_t src, void *buf, size_t len) { int level; memcpy(&level, buf, sizeof(int)); diff --git a/source3/lib/messages.c b/source3/lib/messages.c index bbda5d71ed..927cb095dd 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -43,7 +43,7 @@ static int received_signal; struct message_rec { int msg_version; - enum message_type msg_type; + int msg_type; pid_t dest; pid_t src; size_t len; @@ -52,8 +52,8 @@ struct message_rec { /* 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); + int msg_type; + void (*fn)(int msg_type, pid_t pid, void *buf, size_t len); } *dispatch_fns; /**************************************************************************** @@ -124,7 +124,7 @@ static BOOL message_notify(pid_t pid) /**************************************************************************** send a message to a particular pid ****************************************************************************/ -BOOL message_send_pid(pid_t pid, enum message_type msg_type, void *buf, size_t len) +BOOL message_send_pid(pid_t pid, int msg_type, void *buf, size_t len) { TDB_DATA kbuf; TDB_DATA dbuf; @@ -150,7 +150,7 @@ BOOL message_send_pid(pid_t pid, enum message_type msg_type, void *buf, size_t l if (!p) goto failed; memcpy(p, &rec, sizeof(rec)); - memcpy(p+sizeof(rec), buf, len); + if (len > 0) memcpy(p+sizeof(rec), buf, len); dbuf.dptr = p; dbuf.dsize = len + sizeof(rec); @@ -165,7 +165,7 @@ BOOL message_send_pid(pid_t pid, enum message_type msg_type, void *buf, size_t l memcpy(p, dbuf.dptr, dbuf.dsize); memcpy(p+dbuf.dsize, &rec, sizeof(rec)); - memcpy(p+dbuf.dsize+sizeof(rec), buf, len); + if (len > 0) memcpy(p+dbuf.dsize+sizeof(rec), buf, len); dbuf.dptr = p; dbuf.dsize += len + sizeof(rec); @@ -187,7 +187,7 @@ BOOL message_send_pid(pid_t pid, enum message_type msg_type, void *buf, size_t l /**************************************************************************** retrieve the next message for the current process ****************************************************************************/ -static BOOL message_recv(enum message_type *msg_type, pid_t *src, void **buf, size_t *len) +static BOOL message_recv(int *msg_type, pid_t *src, void **buf, size_t *len) { TDB_DATA kbuf; TDB_DATA dbuf; @@ -207,10 +207,15 @@ static BOOL message_recv(enum message_type *msg_type, pid_t *src, void **buf, si goto failed; } - (*buf) = (void *)malloc(rec.len); - if (!(*buf)) goto failed; + if (rec.len > 0) { + (*buf) = (void *)malloc(rec.len); + if (!(*buf)) goto failed; + + memcpy(*buf, dbuf.dptr+sizeof(rec), rec.len); + } else { + *buf = NULL; + } - memcpy(*buf, dbuf.dptr+sizeof(rec), rec.len); *len = rec.len; *msg_type = rec.msg_type; *src = rec.src; @@ -236,7 +241,7 @@ so you can register multiple handlers for a message ****************************************************************************/ void message_dispatch(void) { - enum message_type msg_type; + int msg_type; pid_t src; void *buf; size_t len; @@ -258,8 +263,8 @@ void message_dispatch(void) /**************************************************************************** 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)) +void message_register(int msg_type, + void (*fn)(int msg_type, pid_t pid, void *buf, size_t len)) { struct dispatch_fns *dfn; diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 2da879fc94..914f288001 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -312,6 +312,9 @@ static void process(void) { time_t t = time(NULL); + /* check for internal messages */ + message_dispatch(); + /* * Check all broadcast subnets to see if * we need to run an election on any of them. @@ -490,9 +493,6 @@ static void process(void) /* free up temp memory */ lp_talloc_free(); - - /* check for internal messages */ - message_init(); } } /* process */ @@ -795,6 +795,7 @@ static void usage(char *pname) pidfile_create("nmbd"); message_init(); + message_register(MSG_FORCE_ELECTION, nmbd_message_election); DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index be38b572f6..522e268ae7 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -381,3 +381,24 @@ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name )); } return run_any_election; } + + + +/**************************************************************************** +process a internal Samba message forcing an election +***************************************************************************/ +void nmbd_message_election(int msg_type, pid_t src, void *buf, size_t len) +{ + struct subnet_record *subrec; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + struct work_record *work; + for (work = subrec->workgrouplist; work; work = work->next) { + if (strequal(work->work_group, global_myworkgroup)) { + work->needelection = True; + work->ElectionCount=0; + work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; + } + } + } +} diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index d1f77fe2d2..50193d5339 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1758,14 +1758,6 @@ only use %d.\n", (count*2) + 2, FD_SETSIZE)); return False; } -/**************************************************************************** -do any signal triggered processing -***************************************************************************/ -static void nmbd_async_processing(void) -{ - message_dispatch(); -} - /**************************************************************************** Listens for NMB or DGRAM packets, and queues them. return True if the socket is dead @@ -1826,9 +1818,6 @@ BOOL listen_for_packets(BOOL run_election) BlockSignals(True, SIGTERM); if(selrtn == -1) { - if (errno == EINTR) { - nmbd_async_processing(); - } return False; } diff --git a/source3/utils/msgtest.c b/source3/utils/msgtest.c index c0ced262d7..22d7a9a331 100644 --- a/source3/utils/msgtest.c +++ b/source3/utils/msgtest.c @@ -56,7 +56,7 @@ pid = atoi(argv[1]); level = atoi(argv[2]); - debug_message_send(pid, level); + message_send_pid(pid, MSG_FORCE_ELECTION, NULL, 0); return (0); } -- cgit