summaryrefslogtreecommitdiffstats
path: root/source/lib/messages.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/lib/messages.c')
-rw-r--r--source/lib/messages.c117
1 files changed, 82 insertions, 35 deletions
diff --git a/source/lib/messages.c b/source/lib/messages.c
index d9886a54daf..9d2d46e4114 100644
--- a/source/lib/messages.c
+++ b/source/lib/messages.c
@@ -79,7 +79,7 @@ static void sig_usr1(void)
A useful function for testing the message system.
****************************************************************************/
-static void ping_message(int msg_type, pid_t src, void *buf, size_t len)
+void ping_message(int msg_type, pid_t src, void *buf, size_t len)
{
char *msg = buf ? buf : "none";
DEBUG(1,("INFO: Received PING message from PID %u [%s]\n",(unsigned int)src, msg));
@@ -87,6 +87,16 @@ static void ping_message(int msg_type, pid_t src, void *buf, size_t len)
}
/****************************************************************************
+ 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));
+ message_send_pid(src, MSG_DEBUGLEVEL, DEBUGLEVEL_CLASS, sizeof(DEBUGLEVEL_CLASS), True);
+}
+
+/****************************************************************************
Initialise the messaging functions.
****************************************************************************/
@@ -106,6 +116,7 @@ BOOL message_init(void)
CatchSignal(SIGUSR1, SIGNAL_CAST sig_usr1);
message_register(MSG_PING, ping_message);
+ message_register(MSG_REQ_DEBUGLEVEL, debuglevel_message);
return True;
}
@@ -133,9 +144,6 @@ static TDB_DATA message_key_pid(pid_t pid)
static BOOL message_notify(pid_t pid)
{
- /* Doing kill with a non-positive pid causes messages to be
- * sent to places we don't want. */
- SMB_ASSERT(pid > 0);
if (kill(pid, SIGUSR1) == -1) {
if (errno == ESRCH) {
DEBUG(2,("pid %d doesn't exist - deleting messages record\n", (int)pid));
@@ -166,10 +174,6 @@ BOOL message_send_pid(pid_t pid, int msg_type, const void *buf, size_t len,
rec.src = sys_getpid();
rec.len = len;
- /* Doing kill with a non-positive pid causes messages to be
- * sent to places we don't want. */
- SMB_ASSERT(pid > 0);
-
kbuf = message_key_pid(pid);
/* lock the record for the destination */
@@ -318,8 +322,8 @@ void message_dispatch(void)
received_signal = 0;
while (message_recv(&msg_type, &src, &buf, &len)) {
- DEBUG(10,("message_dispatch: received msg_type=%d src_pid=%d\n",
- msg_type, (int) src));
+ DEBUG(10,("message_dispatch: received msg_type=%d src_pid=%u\n",
+ msg_type, (unsigned int) src));
n_handled = 0;
for (dfn = dispatch_fns; dfn; dfn = dfn->next) {
if (dfn->msg_type == msg_type) {
@@ -329,9 +333,9 @@ void message_dispatch(void)
}
}
if (!n_handled) {
- DEBUG(5,("message_dispatch: warning: no handlers registered for "
- "msg_type %d in pid %d\n",
- msg_type, sys_getpid()));
+ DEBUG(5,("message_dispatch: warning: no handlers registed for "
+ "msg_type %d in pid%u\n",
+ msg_type, (unsigned int)getpid()));
}
SAFE_FREE(buf);
}
@@ -382,11 +386,10 @@ void message_deregister(int msg_type)
struct msg_all {
int msg_type;
- uint32 msg_flag;
const void *buf;
size_t len;
BOOL duplicates;
- int n_sent;
+ int n_sent;
};
/****************************************************************************
@@ -406,20 +409,13 @@ static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void
if (crec.cnum != -1)
return 0;
- /* Don't send if the receiver hasn't registered an interest. */
-
- if(!(crec.bcast_msg_flags & msg_all->msg_flag))
- return 0;
-
- /* If the msg send fails because the pid was not found (i.e. smbd died),
+ /* if the msg send fails because the pid was not found (i.e. smbd died),
* the msg has already been deleted from the messages.tdb.*/
-
if (!message_send_pid(crec.pid, msg_all->msg_type,
msg_all->buf, msg_all->len,
msg_all->duplicates)) {
- /* If the pid was not found delete the entry from connections.tdb */
-
+ /* if the pid was not found delete the entry from connections.tdb */
if (errno == ESRCH) {
DEBUG(2,("pid %u doesn't exist - deleting connections %d [%s]\n",
(unsigned int)crec.pid, crec.cnum, crec.name));
@@ -450,17 +446,6 @@ BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type,
struct msg_all msg_all;
msg_all.msg_type = msg_type;
- if (msg_type < 1000)
- msg_all.msg_flag = FLAG_MSG_GENERAL;
- else if (msg_type > 1000 && msg_type < 2000)
- msg_all.msg_flag = FLAG_MSG_NMBD;
- else if (msg_type > 2000 && msg_type < 3000)
- msg_all.msg_flag = FLAG_MSG_PRINTING;
- else if (msg_type > 3000 && msg_type < 4000)
- msg_all.msg_flag = FLAG_MSG_SMBD;
- else
- return False;
-
msg_all.buf = buf;
msg_all.len = len;
msg_all.duplicates = duplicates_allowed;
@@ -471,4 +456,66 @@ BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type,
*n_sent = msg_all.n_sent;
return True;
}
+
/** @} **/
+
+static SIG_ATOMIC_T gotalarm;
+
+/***************************************************************
+ Signal function to tell us we timed out.
+****************************************************************/
+
+static void gotalarm_sig(void)
+{
+ gotalarm = 1;
+}
+
+/*
+ lock the messaging tdb based on a string - this is used as a primitive form of mutex
+ between smbd instances.
+*/
+BOOL message_named_mutex(const char *name, unsigned int timeout)
+{
+ TDB_DATA key;
+ int ret;
+
+ if (!message_init())
+ return False;
+
+ key.dptr = (char *)name;
+ key.dsize = strlen(name)+1;
+
+ if (timeout) {
+ gotalarm = 0;
+ CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
+ alarm(timeout);
+ }
+
+ ret = tdb_chainlock(tdb, key);
+
+ if (timeout) {
+ alarm(0);
+ CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
+ if (gotalarm)
+ return False;
+ }
+
+ if (ret == 0)
+ DEBUG(10,("message_named_mutex: got mutex for %s\n", name ));
+
+ return (ret == 0);
+}
+
+/*
+ unlock a named mutex
+*/
+void message_named_mutex_release(char *name)
+{
+ TDB_DATA key;
+
+ key.dptr = name;
+ key.dsize = strlen(name)+1;
+
+ tdb_chainunlock(tdb, key);
+ DEBUG(10,("message_named_mutex: released mutex for %s\n", name ));
+}