summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/src/daemon.c36
-rw-r--r--src/src/exim.c2
-rw-r--r--src/src/expand.c61
-rw-r--r--src/src/functions.h3
-rw-r--r--src/src/globals.c2
-rw-r--r--src/src/globals.h2
-rw-r--r--src/src/macros.h3
-rw-r--r--src/src/queue.c32
8 files changed, 124 insertions, 17 deletions
diff --git a/src/src/daemon.c b/src/src/daemon.c
index b6c27ffe5..a6980e95e 100644
--- a/src/src/daemon.c
+++ b/src/src/daemon.c
@@ -983,6 +983,7 @@ daemon_notifier_socket(void)
int fd;
const uschar * where;
struct sockaddr_un sun = {.sun_family = AF_UNIX};
+int len;
DEBUG(D_any) debug_printf("creating notifier socket\n");
@@ -996,10 +997,12 @@ if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0))) < 0)
(void)fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
#endif
-snprintf(sun.sun_path, sizeof(sun.sun_path), "%s/%s",
- spool_directory, NOTIFIER_SOCKET_NAME);
+sun.sun_path[0] = 0; /* Abstract local socket addr - Linux-specific? */
+len = offsetof(struct sockaddr_un, sun_path) + 1
+ + snprintf(sun.sun_path+1, sizeof(sun.sun_path)-1, "%s", NOTIFIER_SOCKET_NAME);
+
where = US"bind";
-if (bind(fd, (const struct sockaddr *)&sun, sizeof(sun)) < 0)
+if (bind(fd, (const struct sockaddr *)&sun, len) < 0)
goto bad;
where = US"SO_PASSCRED";
@@ -1023,9 +1026,10 @@ static BOOL
daemon_notification(void)
{
uschar buf[256], cbuf[256];
+struct sockaddr_un sun;
struct iovec iov = {.iov_base = buf, .iov_len = sizeof(buf)-1};
-struct msghdr msg = { .msg_name = NULL,
- .msg_namelen = 0,
+struct msghdr msg = { .msg_name = &sun,
+ .msg_namelen = sizeof(sun),
.msg_iov = &iov,
.msg_iovlen = 1,
.msg_control = cbuf,
@@ -1038,6 +1042,14 @@ buf[sizeof(buf)-1] = 0;
if ((sz = recvmsg(daemon_notifier_fd, &msg, 0)) <= 0) return FALSE;
if (sz >= sizeof(buf)) return FALSE;
+#ifdef notdef
+debug_printf("addrlen %d\n", msg.msg_namelen);
+#endif
+DEBUG(D_queue_run) debug_printf("%s from addr%s '%s'\n", __FUNCTION__,
+ *sun.sun_path ? "" : " abstract", sun.sun_path+ (*sun.sun_path ? 0 : 1));
+
+/* Refuse to handle the item unless the peer has good credentials */
+
for (struct cmsghdr * cp = CMSG_FIRSTHDR(&msg);
cp;
cp = CMSG_NXTHDR(&msg, cp))
@@ -1064,6 +1076,20 @@ switch (buf[0])
memcpy(queuerun_msgid, buf+1, MESSAGE_ID_LENGTH+1);
return TRUE;
#endif /*EXPERIMENTAL_QUEUE_RAMP*/
+
+ case NOTIFY_QUEUE_SIZE_REQ:
+ {
+ uschar buf[16];
+ int len = snprintf(CS buf, sizeof(buf), "%u", queue_count_cached());
+
+ DEBUG(D_queue_run)
+ debug_printf("%s: queue size request: %s\n", __FUNCTION__, buf);
+
+ if (sendto(daemon_notifier_fd, buf, len, 0, &sun, msg.msg_namelen) < 0)
+ log_write(0, LOG_MAIN|LOG_PANIC,
+ "%s: sendto: %s\n", __FUNCTION__, strerror(errno));
+ return FALSE;
+ }
}
return FALSE;
}
diff --git a/src/src/exim.c b/src/src/exim.c
index a8f3c2248..dfd6df76c 100644
--- a/src/src/exim.c
+++ b/src/src/exim.c
@@ -4363,7 +4363,7 @@ if (list_queue)
if (count_queue)
{
set_process_info("counting the queue");
- queue_count();
+ fprintf(stdout, "%u\n", queue_count());
exit(EXIT_SUCCESS);
}
diff --git a/src/src/expand.c b/src/src/expand.c
index 7986bbd14..cd4522afb 100644
--- a/src/src/expand.c
+++ b/src/src/expand.c
@@ -466,6 +466,7 @@ typedef struct {
static uschar * fn_recipients(void);
typedef uschar * stringptr_fn_t(void);
+static uschar * fn_queue_size(void);
/* This table must be kept in alphabetical order. */
@@ -669,6 +670,7 @@ static var_entry var_table[] = {
{ "qualify_domain", vtype_stringptr, &qualify_domain_sender },
{ "qualify_recipient", vtype_stringptr, &qualify_domain_recipient },
{ "queue_name", vtype_stringptr, &queue_name },
+ { "queue_size", vtype_string_func, &fn_queue_size },
{ "rcpt_count", vtype_int, &rcpt_count },
{ "rcpt_defer_count", vtype_int, &rcpt_defer_count },
{ "rcpt_fail_count", vtype_int, &rcpt_fail_count },
@@ -1741,6 +1743,65 @@ return g ? g->s : NULL;
/*************************************************
+* Return size of queue *
+*************************************************/
+/* Ask the daemon for the queue size */
+
+static uschar *
+fn_queue_size(void)
+{
+struct sockaddr_un sun = {.sun_family = AF_UNIX};
+uschar buf[16];
+int fd;
+ssize_t len;
+const uschar * where;
+
+if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0)
+ {
+ DEBUG(D_expand) debug_printf(" socket: %s\n", strerror(errno));
+ return NULL;
+ }
+
+#define ABSTRACT_CLIENT
+#ifdef ABSTRACT_CLIENT
+sun.sun_path[0] = 0; /* Abstract local socket addr - Linux-specific? */
+len = offsetof(struct sockaddr_un, sun_path) + 1
+ + snprintf(sun.sun_path+1, sizeof(sun.sun_path)-1, "exim_%d", getpid());
+#else
+len = offsetof(struct sockaddr_un, sun_path)
+ + snprintf(sun.sun_path, sizeof(sun.sun_path), "%s/p_%d",
+ spool_directory, getpid());
+#endif
+
+if (bind(fd, &sun, len) < 0) { where = US"bind"; goto bad; }
+
+#ifdef notdef
+debug_printf("local%s '%s'\n", *sun.sun_path ? "" : " abstract",
+ sun.sun_path+ (*sun.sun_path ? 0 : 1));
+#endif
+
+sun.sun_path[0] = 0; /* Abstract local socket addr - Linux-specific? */
+len = offsetof(struct sockaddr_un, sun_path) + 1
+ + snprintf(sun.sun_path+1, sizeof(sun.sun_path)-1, "%s", NOTIFIER_SOCKET_NAME);
+
+if (connect(fd, &sun, len) < 0) { where = US"connect"; goto bad; }
+
+buf[0] = NOTIFY_QUEUE_SIZE_REQ;
+if (send(fd, buf, 1, 0) < 0) { where = US"send"; goto bad; }
+
+if ((len = recv(fd, buf, sizeof(buf), 0)) < 0) { where = US"recv"; goto bad; }
+
+close(fd);
+return string_copyn(buf, len);
+
+bad:
+ close(fd);
+ DEBUG(D_expand) debug_printf(" %s: %s\n", where, strerror(errno));
+ return NULL;
+}
+
+
+/*************************************************
* Find value of a variable *
*************************************************/
diff --git a/src/src/functions.h b/src/src/functions.h
index 9716a02b4..be929a710 100644
--- a/src/src/functions.h
+++ b/src/src/functions.h
@@ -363,7 +363,8 @@ extern int vaguely_random_number_fallback(int);
extern BOOL queue_action(uschar *, int, uschar **, int, int);
extern void queue_check_only(void);
-extern void queue_count(void);
+extern unsigned queue_count(void);
+extern unsigned queue_count_cached(void);
extern void queue_list(int, uschar **, int);
#ifdef EXPERIMENTAL_QUEUE_RAMP
extern void queue_notify_daemon(const uschar * hostname);
diff --git a/src/src/globals.c b/src/src/globals.c
index a06aa5c1f..a5711c73b 100644
--- a/src/src/globals.c
+++ b/src/src/globals.c
@@ -1208,6 +1208,8 @@ int queue_only_load = -1;
uschar *queue_run_max = US"5";
pid_t queue_run_pid = (pid_t)0;
int queue_run_pipe = -1;
+unsigned queue_size = 0;
+time_t queue_size_next = 0;
uschar *queue_smtp_domains = NULL;
uint32_t random_seed = 0;
diff --git a/src/src/globals.h b/src/src/globals.h
index 760863ac3..b570078c3 100644
--- a/src/src/globals.h
+++ b/src/src/globals.h
@@ -805,6 +805,8 @@ extern uschar *queue_only_file; /* Queue if file exists/not-exists */
extern BOOL queue_only_override; /* Allow override from command line */
extern BOOL queue_run_in_order; /* As opposed to random */
extern uschar *queue_run_max; /* Max queue runners */
+extern unsigned queue_size; /* items in queue */
+extern time_t queue_size_next; /* next time to evaluate queue_size */
extern uschar *queue_smtp_domains; /* Ditto, for these domains */
extern unsigned int random_seed; /* Seed for random numbers */
diff --git a/src/src/macros.h b/src/src/macros.h
index 7f50dbb89..93756d8a1 100644
--- a/src/src/macros.h
+++ b/src/src/macros.h
@@ -1101,6 +1101,7 @@ should not be one active. */
#define NOTIFIER_SOCKET_NAME "exim_daemon_notify"
-#define NOTIFY_MSG_QRUN 1 /* Notify message types */
+#define NOTIFY_MSG_QRUN 1 /* Notify message types */
+#define NOTIFY_QUEUE_SIZE_REQ 2
/* End of macros.h */
diff --git a/src/src/queue.c b/src/src/queue.c
index 5f75470e0..ac7aad1a0 100644
--- a/src/src/queue.c
+++ b/src/src/queue.c
@@ -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 *
@@ -1511,11 +1524,12 @@ 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;
- snprintf(sun.sun_path, sizeof(sun.sun_path), "%s/%s",
- spool_directory, NOTIFIER_SOCKET_NAME);
-
- if (sendto(fd, buf, sizeof(buf), 0, &sun, sizeof(sun)) < 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);