Add queue_size variable. Bug 1406
[users/jgh/exim.git] / src / src / queue.c
index d472b985134b0fc2168589d3f6ffe6b5e8d3daac..ac7aad1a022116d41716ba7c50ed2b58ed4e02a6 100644 (file)
@@ -767,26 +767,39 @@ if (!recurse)
 /* Called as a result of -bpc
 
 Arguments:  none
-Returns:    nothing
+Returns:    count
 */
 
-void
+unsigned
 queue_count(void)
 {
 int subcount;
-int count = 0;
+unsigned count = 0;
 uschar subdirs[64];
 
-for (queue_filename *f = queue_get_spool_list(
+for (queue_filename * f = queue_get_spool_list(
                                -1,             /* entire queue */
                                subdirs,        /* for holding sub list */
                                &subcount,      /* for subcount */
                                FALSE);         /* not random */
     f; f = f->next) count++;
-fprintf(stdout, "%d\n", count);
+return count;
 }
 
 
+#define QUEUE_SIZE_AGE 60      /* update rate for queue_size */
+
+unsigned
+queue_count_cached(void)
+{
+time_t now;
+if ((now = time(NULL)) >= queue_size_next)
+  {
+  queue_size = queue_count();
+  queue_size_next = now + (f.running_in_test_harness ? 3 : QUEUE_SIZE_AGE);
+  }
+return queue_size;
+}
 
 /************************************************
 *          List extra deliveries                *
@@ -1491,6 +1504,40 @@ if (s)
        }
 }
 
+
+
+/******************************************************************************/
+/******************************************************************************/
+
+#ifdef EXPERIMENTAL_QUEUE_RAMP
+void
+queue_notify_daemon(const uschar * msgid)
+{
+uschar buf[MESSAGE_ID_LENGTH + 2];
+int fd;
+
+DEBUG(D_queue_run) debug_printf("%s: %s\n", __FUNCTION__, msgid);
+
+buf[0] = NOTIFY_MSG_QRUN;
+memcpy(buf+1, msgid, MESSAGE_ID_LENGTH+1);
+
+if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) >= 0)
+  {
+  struct sockaddr_un sun = {.sun_family = AF_UNIX};
+  int len = offsetof(struct sockaddr_un, sun_path) + 1
+    + snprintf(sun.sun_path+1, sizeof(sun.sun_path)-1, "%s",
+       NOTIFIER_SOCKET_NAME);
+  sun.sun_path[0] = 0;
+
+  if (sendto(fd, buf, sizeof(buf), 0, &sun, len) < 0)
+    DEBUG(D_queue_run)
+      debug_printf("%s: sendto %s\n", __FUNCTION__, strerror(errno));
+  close(fd);
+  }
+else DEBUG(D_queue_run) debug_printf(" socket: %s\n", strerror(errno));
+}
+#endif
+
 #endif /*!COMPILE_UTILITY*/
 
 /* End of queue.c */