1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

- 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 commit is contained in:
Andrew Tridgell 0001-01-01 00:00:00 +00:00
parent 2ebfdd21b3
commit f1c49ca7ce
8 changed files with 56 additions and 34 deletions

View File

@ -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

View File

@ -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 */

View File

@ -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));

View File

@ -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;

View File

@ -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 ) );

View File

@ -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;
}
}
}
}

View File

@ -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;
}

View File

@ -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);
}