summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2003-04-23 00:19:30 +0000
committerJeremy Allison <jra@samba.org>2003-04-23 00:19:30 +0000
commit30418a47c609fdff286bcab4e29e3fe0b244632e (patch)
tree686c03e79accb58f88d118db61b9f6f147b8a04d
parent9c6e58869f45dd2be0904b9ecf9e757b2b3841d6 (diff)
downloadsamba-30418a47c609fdff286bcab4e29e3fe0b244632e.tar.gz
samba-30418a47c609fdff286bcab4e29e3fe0b244632e.tar.bz2
samba-30418a47c609fdff286bcab4e29e3fe0b244632e.zip
Limit the number of outstanding print notify messages for a process to
1000. Jeremy. (This used to be commit 2e5e4c10d2377493913554e7dab79d97a4d16d87)
-rw-r--r--source3/lib/messages.c31
-rw-r--r--source3/printing/notify.c9
2 files changed, 39 insertions, 1 deletions
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index 0615cc1883..8706ede706 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -304,6 +304,37 @@ BOOL message_send_pid_with_timeout(pid_t pid, int msg_type, const void *buf, siz
}
/****************************************************************************
+ Count the messages pending for a particular pid. Expensive....
+****************************************************************************/
+
+unsigned int messages_pending_for_pid(pid_t pid)
+{
+ TDB_DATA kbuf;
+ TDB_DATA dbuf;
+ char *buf;
+ unsigned int message_count = 0;
+
+ kbuf = message_key_pid(sys_getpid());
+
+ 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.
****************************************************************************/
diff --git a/source3/printing/notify.c b/source3/printing/notify.c
index 428eb54ce4..ee973da211 100644
--- a/source3/printing/notify.c
+++ b/source3/printing/notify.c
@@ -174,8 +174,15 @@ static void print_notify_send_messages_to_printer(const char *printer, unsigned
if (!print_notify_pid_list(printer, send_ctx, &num_pids, &pid_list))
return;
- for (i = 0; i < num_pids; i++)
+ for (i = 0; i < num_pids; i++) {
+ unsigned int q_len = messages_pending_for_pid(pid_list[i]);
+ if (q_len > 1000) {
+ DEBUG(5, ("print_notify_send_messages_to_printer: discarding notify to printer %s as queue length = %u\n",
+ printer, q_len ));
+ continue;
+ }
message_send_pid_with_timeout(pid_list[i], MSG_PRINTER_NOTIFY2, buf, offset, True, timeout);
+ }
}
/*******************************************************************