Limit the number of outstanding print notify messages for a process to
authorJeremy Allison <jra@samba.org>
Wed, 23 Apr 2003 00:19:16 +0000 (00:19 +0000)
committerJeremy Allison <jra@samba.org>
Wed, 23 Apr 2003 00:19:16 +0000 (00:19 +0000)
1000.
Jeremy.
(This used to be commit aabaac05c6adbb510ed27f87115de3e83e27158c)

source3/lib/messages.c
source3/printing/notify.c

index 0615cc188377e2a47875c4031fcea124e05c518d..8706ede70653cf6540ace0602f3ccda94988f29d 100644 (file)
@@ -303,6 +303,37 @@ BOOL message_send_pid_with_timeout(pid_t pid, int msg_type, const void *buf, siz
        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(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.
 ****************************************************************************/
index 428eb54ce4989ac97079e4fdad89cc70b219d100..ee973da211c5c41e6db6e66b7f9d5907fe0bad29 100644 (file)
@@ -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);
+       }
 }
 
 /*******************************************************************