mirror of
https://github.com/samba-team/samba.git
synced 2024-12-25 23:21:54 +03:00
Merged in JohnR's ping messaging extension.
Jeremy.
This commit is contained in:
parent
1dd255b06d
commit
694372b2c4
@ -57,8 +57,9 @@ static struct dispatch_fns {
|
||||
} *dispatch_fns;
|
||||
|
||||
/****************************************************************************
|
||||
notifications come in as signals
|
||||
Notifications come in as signals.
|
||||
****************************************************************************/
|
||||
|
||||
static void sig_usr1(void)
|
||||
{
|
||||
received_signal = 1;
|
||||
@ -66,16 +67,20 @@ static void sig_usr1(void)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
a useful function for testing the message system
|
||||
A useful function for testing the message system.
|
||||
****************************************************************************/
|
||||
|
||||
void ping_message(int msg_type, pid_t src, void *buf, size_t len)
|
||||
{
|
||||
DEBUG(1,("INFO: Received PING message from PID %u\n",(unsigned int)src));
|
||||
char *msg = buf ? buf : "none";
|
||||
DEBUG(1,("INFO: Received PING message from PID %u [%s]\n",(unsigned int)src, msg));
|
||||
message_send_pid(src, MSG_PONG, buf, len, True);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
return current debug level
|
||||
Return current debug level.
|
||||
****************************************************************************/
|
||||
|
||||
void debuglevel_message(int msg_type, pid_t src, void *buf, size_t len)
|
||||
{
|
||||
DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %u\n",(unsigned int)src));
|
||||
@ -85,6 +90,7 @@ void debuglevel_message(int msg_type, pid_t src, void *buf, size_t len)
|
||||
/****************************************************************************
|
||||
Initialise the messaging functions.
|
||||
****************************************************************************/
|
||||
|
||||
BOOL message_init(void)
|
||||
{
|
||||
if (tdb) return True;
|
||||
@ -106,10 +112,10 @@ BOOL message_init(void)
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************
|
||||
form a static tdb key from a pid
|
||||
Form a static tdb key from a pid.
|
||||
******************************************************************/
|
||||
|
||||
static TDB_DATA message_key_pid(pid_t pid)
|
||||
{
|
||||
static char key[20];
|
||||
@ -122,11 +128,11 @@ static TDB_DATA message_key_pid(pid_t pid)
|
||||
return kbuf;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
notify a process that it has a message. If the process doesn't exist
|
||||
then delete its record in the database
|
||||
Notify a process that it has a message. If the process doesn't exist
|
||||
then delete its record in the database.
|
||||
****************************************************************************/
|
||||
|
||||
static BOOL message_notify(pid_t pid)
|
||||
{
|
||||
if (kill(pid, SIGUSR1) == -1) {
|
||||
@ -142,8 +148,9 @@ static BOOL message_notify(pid_t pid)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
send a message to a particular pid
|
||||
Send a message to a particular pid.
|
||||
****************************************************************************/
|
||||
|
||||
BOOL message_send_pid(pid_t pid, int msg_type, void *buf, size_t len, BOOL duplicates_allowed)
|
||||
{
|
||||
TDB_DATA kbuf;
|
||||
@ -228,11 +235,10 @@ BOOL message_send_pid(pid_t pid, int msg_type, void *buf, size_t len, BOOL dupli
|
||||
return False;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
retrieve the next message for the current process
|
||||
Retrieve the next message for the current process.
|
||||
****************************************************************************/
|
||||
|
||||
static BOOL message_recv(int *msg_type, pid_t *src, void **buf, size_t *len)
|
||||
{
|
||||
TDB_DATA kbuf;
|
||||
@ -284,12 +290,12 @@ static BOOL message_recv(int *msg_type, pid_t *src, void **buf, size_t *len)
|
||||
return False;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
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
|
||||
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)
|
||||
{
|
||||
int msg_type;
|
||||
@ -298,10 +304,10 @@ void message_dispatch(void)
|
||||
size_t len;
|
||||
struct dispatch_fns *dfn;
|
||||
|
||||
if (!received_signal)
|
||||
return;
|
||||
if (!received_signal) return;
|
||||
|
||||
DEBUG(10,("message_dispatch: received_signal = %d\n", received_signal));
|
||||
|
||||
received_signal = 0;
|
||||
|
||||
while (message_recv(&msg_type, &src, &buf, &len)) {
|
||||
@ -315,10 +321,10 @@ void message_dispatch(void)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
register a dispatch function for a particular message type
|
||||
Register a dispatch function for a particular message type.
|
||||
****************************************************************************/
|
||||
|
||||
void message_register(int msg_type,
|
||||
void (*fn)(int msg_type, pid_t pid, void *buf, size_t len))
|
||||
{
|
||||
@ -342,8 +348,9 @@ void message_register(int msg_type,
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
de-register the function for a particular message type
|
||||
De-register the function for a particular message type.
|
||||
****************************************************************************/
|
||||
|
||||
void message_deregister(int msg_type)
|
||||
{
|
||||
struct dispatch_fns *dfn, *next;
|
||||
@ -365,8 +372,9 @@ struct msg_all {
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
send one of the messages for the broadcast
|
||||
Send one of the messages for the broadcast.
|
||||
****************************************************************************/
|
||||
|
||||
static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
|
||||
{
|
||||
struct connections_data crec;
|
||||
@ -396,10 +404,11 @@ static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
this is a useful function for sending messages to all smbd processes.
|
||||
It isn't very efficient, but should be OK for the sorts of applications that
|
||||
use it. When we need efficient broadcast we can add it.
|
||||
This is a useful function for sending messages to all smbd processes.
|
||||
It isn't very efficient, but should be OK for the sorts of applications that
|
||||
use it. When we need efficient broadcast we can add it.
|
||||
****************************************************************************/
|
||||
|
||||
BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type, void *buf, size_t len, BOOL duplicates_allowed)
|
||||
{
|
||||
struct msg_all msg_all;
|
||||
|
@ -178,7 +178,7 @@ static int parse_type(char *mtype)
|
||||
/****************************************************************************
|
||||
do command
|
||||
****************************************************************************/
|
||||
static BOOL do_command(char *dest, char *msg_name, char **params)
|
||||
static BOOL do_command(char *dest, char *msg_name, int iparams, char **params)
|
||||
{
|
||||
int i, n, v;
|
||||
int mtype;
|
||||
@ -349,6 +349,9 @@ static BOOL do_command(char *dest, char *msg_name, char **params)
|
||||
n = atoi(params[0]);
|
||||
pong_count = 0;
|
||||
for (i=0;i<n;i++) {
|
||||
if (iparams > 1)
|
||||
retval = send_message(dest, MSG_PING, params[1], strlen(params[1]) + 1, True);
|
||||
else
|
||||
retval = send_message(dest, MSG_PING, NULL, 0, True);
|
||||
if (retval == False) break;
|
||||
}
|
||||
@ -404,17 +407,17 @@ static BOOL do_command(char *dest, char *msg_name, char **params)
|
||||
|
||||
if (!interactive) {
|
||||
if (argc < 2) usage(True);
|
||||
return (do_command(argv[0],argv[1],argc > 2 ? &argv[2] : 0));
|
||||
return (do_command(argv[0],argv[1], argc-2, argc > 2 ? &argv[2] : 0));
|
||||
}
|
||||
|
||||
while (True) {
|
||||
char *myargv[3];
|
||||
char *myargv[4];
|
||||
int myargc;
|
||||
|
||||
printf("smbcontrol> ");
|
||||
if (!fgets(temp, sizeof(temp)-1, stdin)) break;
|
||||
myargc = 0;
|
||||
while ((myargc < 3) &&
|
||||
while ((myargc < 4) &&
|
||||
(myargv[myargc] = strtok(myargc?NULL:temp," \t\n"))) {
|
||||
myargc++;
|
||||
}
|
||||
@ -422,7 +425,7 @@ static BOOL do_command(char *dest, char *msg_name, char **params)
|
||||
if (strequal(myargv[0],"q")) break;
|
||||
if (myargc < 2)
|
||||
usage(False);
|
||||
else if (!do_command(myargv[0],myargv[1],myargc > 2 ? &myargv[2] : 0))
|
||||
else if (!do_command(myargv[0],myargv[1],myargc-2,myargc > 2 ? &myargv[2] : 0))
|
||||
usage(False);
|
||||
}
|
||||
return(0);
|
||||
|
Loading…
Reference in New Issue
Block a user