struct message_rec {
int msg_version;
int msg_type;
- pid_t dest;
- pid_t src;
+ struct process_id dest;
+ struct process_id src;
size_t len;
};
static struct dispatch_fns {
struct dispatch_fns *next, *prev;
int msg_type;
- void (*fn)(int msg_type, pid_t pid, void *buf, size_t len);
+ void (*fn)(int msg_type, struct process_id pid, void *buf, size_t len);
} *dispatch_fns;
/****************************************************************************
static void sig_usr1(void)
{
received_signal = 1;
- sys_select_signal();
+ sys_select_signal(SIGUSR1);
}
/****************************************************************************
A useful function for testing the message system.
****************************************************************************/
-static void ping_message(int msg_type, pid_t src, void *buf, size_t len)
+static void ping_message(int msg_type, struct process_id src,
+ void *buf, size_t len)
{
const char *msg = buf ? buf : "none";
- DEBUG(1,("INFO: Received PING message from PID %u [%s]\n",(unsigned int)src, msg));
+ DEBUG(1,("INFO: Received PING message from PID %s [%s]\n",
+ procid_str_static(&src), msg));
message_send_pid(src, MSG_PONG, buf, len, True);
}
message_register(MSG_PING, ping_message);
+ /* Register some debugging related messages */
+
+ register_msg_pool_usage();
+ register_dmalloc_msgs();
+
return True;
}
Form a static tdb key from a pid.
******************************************************************/
-static TDB_DATA message_key_pid(pid_t pid)
+static TDB_DATA message_key_pid(struct process_id pid)
{
static char key[20];
TDB_DATA kbuf;
- slprintf(key, sizeof(key)-1, "PID/%d", (int)pid);
+ slprintf(key, sizeof(key)-1, "PID/%s", procid_str_static(&pid));
kbuf.dptr = (char *)key;
kbuf.dsize = strlen(key)+1;
then delete its record in the database.
****************************************************************************/
-static BOOL message_notify(pid_t pid)
+static BOOL message_notify(struct process_id procid)
{
+ pid_t pid = procid.pid;
/*
* Doing kill with a non-positive pid causes messages to be
* sent to places we don't want.
if (kill(pid, SIGUSR1) == -1) {
if (errno == ESRCH) {
DEBUG(2,("pid %d doesn't exist - deleting messages record\n", (int)pid));
- tdb_delete(tdb, message_key_pid(pid));
+ tdb_delete(tdb, message_key_pid(procid));
} else {
DEBUG(2,("message to process %d failed - %s\n", (int)pid, strerror(errno)));
}
Send a message to a particular pid.
****************************************************************************/
-static BOOL message_send_pid_internal(pid_t pid, int msg_type, const void *buf, size_t len,
- BOOL duplicates_allowed, unsigned int timeout)
+static BOOL message_send_pid_internal(struct process_id pid, int msg_type,
+ const void *buf, size_t len,
+ BOOL duplicates_allowed,
+ unsigned int timeout)
{
TDB_DATA kbuf;
TDB_DATA dbuf;
* sent to places we don't want.
*/
- SMB_ASSERT(pid > 0);
+ SMB_ASSERT(procid_to_pid(&pid) > 0);
rec.msg_version = MESSAGE_VERSION;
rec.msg_type = msg_type;
rec.dest = pid;
- rec.src = sys_getpid();
+ rec.src = procid_self();
rec.len = len;
kbuf = message_key_pid(pid);
- dbuf.dptr = (void *)malloc(len + sizeof(rec));
+ dbuf.dptr = (void *)SMB_MALLOC(len + sizeof(rec));
if (!dbuf.dptr)
return False;
Send a message to a particular pid - no timeout.
****************************************************************************/
-BOOL message_send_pid(pid_t pid, int msg_type, const void *buf, size_t len, BOOL duplicates_allowed)
+BOOL message_send_pid(struct process_id pid, int msg_type, const void *buf, size_t len, BOOL duplicates_allowed)
{
return message_send_pid_internal(pid, msg_type, buf, len, duplicates_allowed, 0);
}
Send a message to a particular pid, with timeout in seconds.
****************************************************************************/
-BOOL message_send_pid_with_timeout(pid_t pid, int msg_type, const void *buf, size_t len,
+BOOL message_send_pid_with_timeout(struct process_id pid, int msg_type, const void *buf, size_t len,
BOOL duplicates_allowed, unsigned int timeout)
{
return message_send_pid_internal(pid, msg_type, buf, len, duplicates_allowed, timeout);
}
+/****************************************************************************
+ Count the messages pending for a particular pid. Expensive....
+****************************************************************************/
+
+unsigned int messages_pending_for_pid(struct process_id pid)
+{
+ TDB_DATA kbuf;
+ TDB_DATA dbuf;
+ char *buf;
+ unsigned int message_count = 0;
+
+ kbuf = message_key_pid(pid);
+
+ dbuf = tdb_fetch(tdb, kbuf);
+ if (dbuf.dptr == NULL || dbuf.dsize == 0) {
+ SAFE_FREE(dbuf.dptr);
+ return 0;
+ }
+
+ for (buf = dbuf.dptr; dbuf.dsize > sizeof(struct message_rec);) {
+ struct message_rec rec;
+ memcpy(&rec, buf, sizeof(rec));
+ buf += (sizeof(rec) + rec.len);
+ dbuf.dsize -= (sizeof(rec) + rec.len);
+ message_count++;
+ }
+
+ SAFE_FREE(dbuf.dptr);
+ return message_count;
+}
+
/****************************************************************************
Retrieve all messages for the current process.
****************************************************************************/
*msgs_buf = NULL;
*total_len = 0;
- kbuf = message_key_pid(sys_getpid());
+ kbuf = message_key_pid(pid_to_procid(sys_getpid()));
if (tdb_chainlock(tdb, kbuf) == -1)
return False;
Parse out the next message for the current process.
****************************************************************************/
-static BOOL message_recv(char *msgs_buf, size_t total_len, int *msg_type, pid_t *src, char **buf, size_t *len)
+static BOOL message_recv(char *msgs_buf, size_t total_len, int *msg_type,
+ struct process_id *src, char **buf, size_t *len)
{
struct message_rec rec;
char *ret_buf = *buf;
void message_dispatch(void)
{
int msg_type;
- pid_t src;
+ struct process_id src;
char *buf;
char *msgs_buf;
size_t len, total_len;
return;
for (buf = msgs_buf; message_recv(msgs_buf, total_len, &msg_type, &src, &buf, &len); buf += len) {
- DEBUG(10,("message_dispatch: received msg_type=%d src_pid=%u\n",
- msg_type, (unsigned int) src));
+ DEBUG(10,("message_dispatch: received msg_type=%d "
+ "src_pid=%u\n", msg_type,
+ (unsigned int) procid_to_pid(&src)));
n_handled = 0;
for (dfn = dispatch_fns; dfn; dfn = dfn->next) {
if (dfn->msg_type == msg_type) {
****************************************************************************/
void message_register(int msg_type,
- void (*fn)(int msg_type, pid_t pid, void *buf, size_t len))
+ void (*fn)(int msg_type, struct process_id pid,
+ void *buf, size_t len))
{
struct dispatch_fns *dfn;
- dfn = (struct dispatch_fns *)malloc(sizeof(*dfn));
+ dfn = SMB_MALLOC_P(struct dispatch_fns);
if (dfn != NULL) {
/* 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));
+ DEBUG(2,("pid %s doesn't exist - deleting connections %d [%s]\n",
+ procid_str_static(&crec.pid),
+ crec.cnum, crec.name));
tdb_delete(the_tdb, kbuf);
}
}
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 > 2000 && msg_type < 2100)
+ msg_all.msg_flag = FLAG_MSG_PRINT_NOTIFY;
+ else if (msg_type > 2100 && msg_type < 3000)
+ msg_all.msg_flag = FLAG_MSG_PRINT_GENERAL;
else if (msg_type > 3000 && msg_type < 4000)
msg_all.msg_flag = FLAG_MSG_SMBD;
else