summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/OS/Makefile-Base12
-rw-r--r--src/exim_monitor/em_globals.c2
-rw-r--r--src/exim_monitor/em_menu.c37
-rw-r--r--src/exim_monitor/em_queue.c15
-rw-r--r--src/src/acl.c22
-rw-r--r--src/src/child.c9
-rw-r--r--src/src/daemon.c86
-rw-r--r--src/src/dcc.c12
-rw-r--r--src/src/deliver.c243
-rw-r--r--src/src/exim.c106
-rw-r--r--src/src/expand.c1
-rw-r--r--src/src/functions.h2
-rw-r--r--src/src/globals.c3
-rw-r--r--src/src/globals.h3
-rw-r--r--src/src/queue.c199
-rw-r--r--src/src/readconf.c2
-rw-r--r--src/src/receive.c81
-rw-r--r--src/src/smtp_in.c6
-rw-r--r--src/src/spool_in.c32
-rw-r--r--src/src/spool_mbox.c10
-rw-r--r--src/src/spool_out.c74
-rw-r--r--src/src/transport.c23
22 files changed, 552 insertions, 428 deletions
diff --git a/src/OS/Makefile-Base b/src/OS/Makefile-Base
index 3995444cf..b9eaabaa6 100644
--- a/src/OS/Makefile-Base
+++ b/src/OS/Makefile-Base
@@ -448,7 +448,13 @@ MONBIN = em_StripChart.o $(EXIMON_TEXTPOP) em_globals.o em_init.o \
# The complete modules list also includes some specially compiled versions of
# code from the main Exim source tree.
-OBJ_MONBIN = util-spool_in.o util-store.o util-string.o tod.o tree.o $(MONBIN)
+OBJ_MONBIN = util-spool_in.o \
+ util-store.o \
+ util-string.o \
+ util-queue.o \
+ tod.o \
+ tree.o \
+ $(MONBIN)
eximon.bin: $(EXIMON_EDITME) eximon $(OBJ_MONBIN) \
../exim_monitor/em_version.c
@@ -568,6 +574,10 @@ util-string.o: $(HDRS) string.c
@echo "$(CC) -DCOMPILE_UTILITY string.c"
$(FE)$(CC) -c $(CFLAGS) $(INCLUDE) -DCOMPILE_UTILITY -o util-string.o string.c
+util-queue.o: $(HDRS) queue.c
+ @echo "$(CC) -DCOMPILE_UTILITY queue.c"
+ $(FE)$(CC) -c $(CFLAGS) $(INCLUDE) -DCOMPILE_UTILITY -o util-queue.o queue.c
+
util-os.o: $(HDRS) os.c
@echo "$(CC) -DCOMPILE_UTILITY os.c"
$(FE)$(CC) -c $(CFLAGS) $(INCLUDE) \
diff --git a/src/exim_monitor/em_globals.c b/src/exim_monitor/em_globals.c
index 6415e4238..9221ae2da 100644
--- a/src/exim_monitor/em_globals.c
+++ b/src/exim_monitor/em_globals.c
@@ -187,6 +187,8 @@ uid_t originator_uid;
uschar *primary_hostname = NULL;
+uschar *queue_name = US"";
+
int received_count = 0;
uschar *received_protocol = NULL;
int received_time = 0;
diff --git a/src/exim_monitor/em_menu.c b/src/exim_monitor/em_menu.c
index 51a952e99..dc24e3dfa 100644
--- a/src/exim_monitor/em_menu.c
+++ b/src/exim_monitor/em_menu.c
@@ -133,11 +133,12 @@ menu_is_up = FALSE;
* Display the message log *
*************************************************/
-static void msglogAction(Widget w, XtPointer client_data, XtPointer call_data)
+static void
+msglogAction(Widget w, XtPointer client_data, XtPointer call_data)
{
int i;
-uschar buffer[256];
Widget text = text_create((uschar *)client_data, text_depth);
+uschar * fname;
FILE *f = NULL;
w = w; /* Keep picky compilers happy */
@@ -147,18 +148,18 @@ call_data = call_data;
for (i = 0; i < (spool_is_split? 2:1); i++)
{
- message_subdir[0] = (i != 0)? ((uschar *)client_data)[5] : 0;
- sprintf(CS buffer, "%s/msglog/%s/%s", spool_directory, message_subdir,
- (uschar *)client_data);
- f = fopen(CS buffer, "r");
- if (f != NULL) break;
+ message_subdir[0] = i != 0 ? ((uschar *)client_data)[5] : 0;
+ fname = spool_fname(US"msglog", message_subdir, US client_data, US"");
+ if ((f = fopen(CS fname, "r")))
+ break;
}
if (f == NULL)
- text_showf(text, "%s: %s\n", buffer, strerror(errno));
+ text_showf(text, "%s: %s\n", fname, strerror(errno));
else
{
- while (Ufgets(buffer, 256, f) != NULL) text_show(text, buffer);
+ uschar buffer[256];
+ while (Ufgets(buffer, sizeof(buffer), f) != NULL) text_show(text, buffer);
fclose(f);
}
}
@@ -169,10 +170,10 @@ else
* Display the message body *
*************************************************/
-static void bodyAction(Widget w, XtPointer client_data, XtPointer call_data)
+static void
+bodyAction(Widget w, XtPointer client_data, XtPointer call_data)
{
int i;
-uschar buffer[256];
Widget text = text_create((uschar *)client_data, text_depth);
FILE *f = NULL;
@@ -181,19 +182,21 @@ call_data = call_data;
for (i = 0; i < (spool_is_split? 2:1); i++)
{
- message_subdir[0] = (i != 0)? ((uschar *)client_data)[5] : 0;
- sprintf(CS buffer, "%s/input/%s/%s-D", spool_directory, message_subdir,
- (uschar *)client_data);
- f = fopen(CS buffer, "r");
- if (f != NULL) break;
+ uschar * fname;
+ message_subdir[0] = i != 0 ? ((uschar *)client_data)[5] : 0;
+ fname = spool_fname(US"input", message_subdir, US client_data, US"-D");
+ if ((f = fopen(CS fname, "r")))
+ break;
}
if (f == NULL)
text_showf(text, "Failed to open file: %s\n", strerror(errno));
else
{
+ uschar buffer[256];
int count = 0;
- while (Ufgets(buffer, 256, f) != NULL)
+
+ while (Ufgets(buffer, sizeof(buffer), f) != NULL)
{
text_show(text, buffer);
count += Ustrlen(buffer);
diff --git a/src/exim_monitor/em_queue.c b/src/exim_monitor/em_queue.c
index c01a80fe0..893e43898 100644
--- a/src/exim_monitor/em_queue.c
+++ b/src/exim_monitor/em_queue.c
@@ -263,7 +263,8 @@ else
sender_address = NULL;
-sprintf(CS buffer, "%s/input/%s/%s-D", spool_directory, message_subdir, name);
+snprintf(CS buffer, sizeof(buffer), "%s/input/%s/%s/%s-D",
+ spool_directory, queue_name, message_subdir, name);
if (Ustat(buffer, &statdata) == 0)
q->size = message_size + statdata.st_size - SPOOL_DATA_START_OFFSET + 1;
@@ -271,7 +272,6 @@ if (Ustat(buffer, &statdata) == 0)
been delivered, and removing visible names. */
if (recipients_list != NULL)
- {
for (i = 0; i < recipients_count; i++)
{
uschar *r = recipients_list[i].address;
@@ -282,7 +282,6 @@ if (recipients_list != NULL)
(void)find_dest(q, r, dest_add, FALSE);
}
}
- }
/* Recover the dynamic store used by spool_read_header(). */
@@ -617,11 +616,13 @@ uschar buffer[1024];
message_subdir[0] = p->dir_char;
-sprintf(CS buffer, "%s/input/%s/%s-J", spool_directory, message_subdir, p->name);
-jread = fopen(CS buffer, "r");
-if (jread == NULL)
+snprintf(CS buffer, sizeof(buffer), "%s/input/%s/%s/%s-J",
+ spool_directory, queue_name, message_subdir, p->name);
+
+if (!(jread = fopen(CS buffer, "r")))
{
- sprintf(CS buffer, "%s/input/%s/%s-H", spool_directory, message_subdir, p->name);
+ snprintf(CS buffer, sizeof(buffer), "%s/input/%s/%s/%s-H",
+ spool_directory, queue_name, message_subdir, p->name);
if (Ustat(buffer, &statdata) < 0 || p->update_time == statdata.st_mtime)
return;
}
diff --git a/src/src/acl.c b/src/src/acl.c
index dd59b4952..381fdccf4 100644
--- a/src/src/acl.c
+++ b/src/src/acl.c
@@ -88,6 +88,7 @@ enum { ACLC_ACL,
#ifdef WITH_CONTENT_SCAN
ACLC_MIME_REGEX,
#endif
+ ACLC_QUEUE,
ACLC_RATELIMIT,
ACLC_RECIPIENTS,
#ifdef WITH_CONTENT_SCAN
@@ -108,7 +109,7 @@ enum { ACLC_ACL,
ACLC_VERIFY };
/* ACL conditions/modifiers: "delay", "control", "continue", "endpass",
-"message", "log_message", "log_reject_target", "logwrite", and "set" are
+"message", "log_message", "log_reject_target", "logwrite", "queue" and "set" are
modifiers that look like conditions but always return TRUE. They are used for
their side effects. */
@@ -152,13 +153,16 @@ static uschar *conditions[] = {
#ifdef WITH_CONTENT_SCAN
US"mime_regex",
#endif
+ US"queue",
US"ratelimit",
US"recipients",
#ifdef WITH_CONTENT_SCAN
US"regex",
#endif
US"remove_header",
- US"sender_domains", US"senders", US"set",
+ US"sender_domains",
+ US"senders",
+ US"set",
#ifdef WITH_CONTENT_SCAN
US"spam",
#endif
@@ -298,6 +302,7 @@ static uschar cond_expand_at_top[] = {
#ifdef WITH_CONTENT_SCAN
TRUE, /* mime_regex */
#endif
+ TRUE, /* queue */
TRUE, /* ratelimit */
FALSE, /* recipients */
#ifdef WITH_CONTENT_SCAN
@@ -360,6 +365,7 @@ static uschar cond_modifiers[] = {
#ifdef WITH_CONTENT_SCAN
FALSE, /* mime_regex */
#endif
+ TRUE, /* queue */
FALSE, /* ratelimit */
FALSE, /* recipients */
#ifdef WITH_CONTENT_SCAN
@@ -507,6 +513,12 @@ static unsigned int cond_forbids[] = {
~(1<<ACL_WHERE_MIME), /* mime_regex */
#endif
+ (1<<ACL_WHERE_NOTSMTP)| /* queue */
+ #ifndef DISABLE_PRDR
+ (1<<ACL_WHERE_PRDR)|
+ #endif
+ (1<<ACL_WHERE_DATA),
+
0, /* ratelimit */
(unsigned int)
@@ -3531,7 +3543,7 @@ for (; cb != NULL; cb = cb->next)
rc = match_isinlist(dkim_cur_signer,
&arg,0,NULL,NULL,MCL_STRING,TRUE,NULL);
else
- rc = FAIL;
+ rc = FAIL;
break;
case ACLC_DKIM_STATUS:
@@ -3690,6 +3702,10 @@ for (; cb != NULL; cb = cb->next)
break;
#endif
+ case ACLC_QUEUE:
+ queue_name = string_copy_malloc(arg);
+ break;
+
case ACLC_RATELIMIT:
rc = acl_ratelimit(arg, where, log_msgptr);
break;
diff --git a/src/src/child.c b/src/src/child.c
index 36d192e9a..7f5b90929 100644
--- a/src/src/child.c
+++ b/src/src/child.c
@@ -72,9 +72,9 @@ child_exec_exim(int exec_type, BOOL kill_v, int *pcount, BOOL minimal,
{
int first_special = -1;
int n = 0;
-int extra = (pcount != NULL)? *pcount : 0;
+int extra = pcount ? *pcount : 0;
uschar **argv =
- store_get((extra + acount + MAX_CLMACROS + 16) * sizeof(char *));
+ store_get((extra + acount + MAX_CLMACROS + 18) * sizeof(char *));
/* In all case, the list starts out with the path, any macros, and a changed
config file. */
@@ -113,6 +113,11 @@ if (!minimal)
if (synchronous_delivery) argv[n++] = US"-odi";
if (connection_max_messages >= 0)
argv[n++] = string_sprintf("-oB%d", connection_max_messages);
+ if (*queue_name)
+ {
+ argv[n++] = US"-MCG";
+ argv[n++] = queue_name;
+ }
}
/* Now add in any others that are in the call. Remember which they were,
diff --git a/src/src/daemon.c b/src/src/daemon.c
index 635b94055..779518f9f 100644
--- a/src/src/daemon.c
+++ b/src/src/daemon.c
@@ -651,8 +651,8 @@ if (pid == 0)
if (geteuid() != root_uid && !deliver_drop_privilege)
{
signal(SIGALRM, SIG_DFL);
- (void)child_exec_exim(CEE_EXEC_PANIC, FALSE, NULL, FALSE, 2, US"-Mc",
- message_id);
+ (void)child_exec_exim(CEE_EXEC_PANIC, FALSE, NULL, FALSE,
+ 2, US"-Mc", message_id);
/* Control does not return here. */
}
@@ -866,10 +866,10 @@ while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
/* If it wasn't an accepting process, see if it was a queue-runner
process that we are tracking. */
- if (queue_pid_slots != NULL)
+ if (queue_pid_slots)
{
- for (i = 0; i < queue_run_max; i++)
- {
+ int max = atoi(expand_string(queue_run_max));
+ for (i = 0; i < max; i++)
if (queue_pid_slots[i] == pid)
{
queue_pid_slots[i] = 0;
@@ -878,7 +878,6 @@ while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
queue_run_count, (queue_run_count == 1)? "" : "es");
break;
}
- }
}
}
}
@@ -916,6 +915,7 @@ int *listen_sockets = NULL;
int listen_socket_count = 0;
ip_address_item *addresses = NULL;
time_t last_connection_time = (time_t)0;
+int local_queue_run_max = atoi(expand_string(queue_run_max));
/* If any debugging options are set, turn on the D_pid bit so that all
debugging lines get the pid added. */
@@ -1572,11 +1572,11 @@ originator_login = ((pw = getpwuid(exim_uid)) != NULL)?
/* Get somewhere to keep the list of queue-runner pids if we are keeping track
of them (and also if we are doing queue runs). */
-if (queue_interval > 0 && queue_run_max > 0)
+if (queue_interval > 0 && local_queue_run_max > 0)
{
int i;
- queue_pid_slots = store_get(queue_run_max * sizeof(pid_t));
- for (i = 0; i < queue_run_max; i++) queue_pid_slots[i] = 0;
+ queue_pid_slots = store_get(local_queue_run_max * sizeof(pid_t));
+ for (i = 0; i < local_queue_run_max; i++) queue_pid_slots[i] = 0;
}
/* Set up the handler for termination of child processes. */
@@ -1615,12 +1615,11 @@ else if (daemon_listen)
int i, j;
int smtp_ports = 0;
int smtps_ports = 0;
- ip_address_item *ipa;
- uschar *p = big_buffer;
- uschar *qinfo = (queue_interval > 0)?
- string_sprintf("-q%s", readconf_printtime(queue_interval))
- :
- US"no queue runs";
+ ip_address_item * ipa;
+ uschar * p = big_buffer;
+ uschar * qinfo = queue_interval > 0
+ ? string_sprintf("-q%s", readconf_printtime(queue_interval))
+ : US"no queue runs";
/* Build a list of listening addresses in big_buffer, but limit it to 10
items. The style is for backwards compatibility.
@@ -1631,30 +1630,30 @@ else if (daemon_listen)
for (j = 0; j < 2; j++)
{
- for (i = 0, ipa = addresses; i < 10 && ipa != NULL; i++, ipa = ipa->next)
+ for (i = 0, ipa = addresses; i < 10 && ipa; i++, ipa = ipa->next)
{
/* First time round, look for SMTP ports; second time round, look for
SMTPS ports. For the first one of each, insert leading text. */
if (host_is_tls_on_connect_port(ipa->port) == (j > 0))
{
- if (j == 0)
- {
- if (smtp_ports++ == 0)
+ if (j == 0)
+ {
+ if (smtp_ports++ == 0)
{
memcpy(p, "SMTP on", 8);
p += 7;
}
- }
- else
- {
- if (smtps_ports++ == 0)
+ }
+ else
+ {
+ if (smtps_ports++ == 0)
{
(void)sprintf(CS p, "%sSMTPS on",
- (smtp_ports == 0)? "":" and for ");
- while (*p != 0) p++;
+ smtp_ports == 0 ? "" : " and for ");
+ while (*p) p++;
}
- }
+ }
/* Now the information about the port (and sometimes interface) */
@@ -1679,7 +1678,7 @@ else if (daemon_listen)
}
}
- if (ipa != NULL)
+ if (ipa)
{
memcpy(p, " ...", 5);
p += 4;
@@ -1689,17 +1688,19 @@ else if (daemon_listen)
log_write(0, LOG_MAIN,
"exim %s daemon started: pid=%d, %s, listening for %s",
version_string, getpid(), qinfo, big_buffer);
- set_process_info("daemon(%s): %s, listening for %s", version_string, qinfo, big_buffer);
+ set_process_info("daemon(%s): %s, listening for %s",
+ version_string, qinfo, big_buffer);
}
else
{
+ uschar * s = *queue_name
+ ? string_sprintf("-qG%s/%s", queue_name, readconf_printtime(queue_interval))
+ : string_sprintf("-q%s", readconf_printtime(queue_interval));
log_write(0, LOG_MAIN,
- "exim %s daemon started: pid=%d, -q%s, not listening for SMTP",
- version_string, getpid(), readconf_printtime(queue_interval));
- set_process_info("daemon(%s): -q%s, not listening",
- version_string,
- readconf_printtime(queue_interval));
+ "exim %s daemon started: pid=%d, %s, not listening for SMTP",
+ version_string, getpid(), s);
+ set_process_info("daemon(%s): %s, not listening", version_string, s);
}
/* Do any work it might be useful to amortize over our children
@@ -1791,7 +1792,7 @@ for (;;)
re-exec is required. */
if (queue_interval > 0 &&
- (queue_run_max <= 0 || queue_run_count < queue_run_max))
+ (local_queue_run_max <= 0 || queue_run_count < local_queue_run_max))
{
if ((pid = fork()) == 0)
{
@@ -1835,21 +1836,22 @@ for (;;)
if (deliver_force_thaw) *p++ = 'f';
if (queue_run_local) *p++ = 'l';
*p = 0;
- extra[0] = opt;
+ extra[0] = queue_name
+ ? string_sprintf("%sG%s", opt, queue_name) : opt;
/* If -R or -S were on the original command line, ensure they get
passed on. */
- if (deliver_selectstring != NULL)
+ if (deliver_selectstring)
{
- extra[extracount++] = deliver_selectstring_regex? US"-Rr" : US"-R";
+ extra[extracount++] = deliver_selectstring_regex ? US"-Rr" : US"-R";
extra[extracount++] = deliver_selectstring;
}
- if (deliver_selectstring_sender != NULL)
+ if (deliver_selectstring_sender)
{
- extra[extracount++] = deliver_selectstring_sender_regex?
- US"-Sr" : US"-S";
+ extra[extracount++] = deliver_selectstring_sender_regex
+ ? US"-Sr" : US"-S";
extra[extracount++] = deliver_selectstring_sender;
}
@@ -1876,15 +1878,13 @@ for (;;)
else
{
int i;
- for (i = 0; i < queue_run_max; ++i)
- {
+ for (i = 0; i < local_queue_run_max; ++i)
if (queue_pid_slots[i] <= 0)
{
queue_pid_slots[i] = pid;
queue_run_count++;
break;
}
- }
DEBUG(D_any) debug_printf("%d queue-runner process%s running\n",
queue_run_count, (queue_run_count == 1)? "" : "es");
}
diff --git a/src/src/dcc.c b/src/src/dcc.c
index c9d0db236..1841e733d 100644
--- a/src/src/dcc.c
+++ b/src/src/dcc.c
@@ -72,7 +72,6 @@ dcc_process(uschar **listptr)
uschar sendbuf[4096];
uschar recvbuf[4096];
uschar dcc_return_text[1024];
- uschar mbox_path[1024];
uschar message_subdir[2];
struct header_line *dcchdr;
uschar *dcc_acl_options;
@@ -102,14 +101,15 @@ dcc_process(uschar **listptr)
message_subdir[1] = '\0';
for (i = 0; i < 2; i++)
{
- message_subdir[0] = (split_spool_directory == (i == 0))? message_id[5] : 0;
- sprintf(CS mbox_path, "%s/input/%s/%s-D", spool_directory, message_subdir, message_id);
- data_file = Ufopen(mbox_path,"rb");
- if (data_file != NULL)
+ message_subdir[0] = split_spool_directory == (i == 0) ? message_id[5] : 0;
+
+ if ((data_file = Ufopen(
+ spool_fname(US"input", message_subdir, message_id, US"-D"),
+ "rb")))
break;
}
- if (data_file == NULL)
+ if (!data_file)
{
/* error while spooling */
log_write(0, LOG_MAIN|LOG_PANIC,
diff --git a/src/src/deliver.c b/src/src/deliver.c
index 1421852aa..b389c3731 100644
--- a/src/src/deliver.c
+++ b/src/src/deliver.c
@@ -76,8 +76,6 @@ static int return_count;
static uschar *frozen_info = US"";
static uschar *used_return_path = NULL;
-static uschar spoolname[PATH_MAX];
-
/*************************************************
@@ -285,10 +283,9 @@ int fd = Uopen(filename, O_WRONLY|O_APPEND|O_CREAT, mode);
if (fd < 0 && errno == ENOENT)
{
- uschar temp[16];
- sprintf(CS temp, "msglog/%s", message_subdir);
- if (message_subdir[0] == 0) temp[6] = 0;
- (void)directory_make(spool_directory, temp, MSGLOG_DIRECTORY_MODE, TRUE);
+ (void)directory_make(spool_directory,
+ spool_sname(US"msglog", message_subdir),
+ MSGLOG_DIRECTORY_MODE, TRUE);
fd = Uopen(filename, O_WRONLY|O_APPEND|O_CREAT, mode);
}
@@ -886,6 +883,9 @@ if (LOGGING(sender_on_delivery) || msg)
sender_address,
US">");
+if (*queue_name)
+ s = string_append(s, &size, &ptr, 2, US" Q=", queue_name);
+
#ifdef EXPERIMENTAL_SRS
if(addr->prop.srs_sender)
s = string_append(s, &size, &ptr, 3, US" SRS=<", addr->prop.srs_sender, US">");
@@ -1273,6 +1273,9 @@ else if (result == DEFER || result == PANIC)
s = string_cat(s, &size, &ptr, log_address);
+ if (*queue_name)
+ s = string_append(s, &size, &ptr, 2, US" Q=", queue_name);
+
/* Either driver_name contains something and driver_kind contains
" router" or " transport" (note the leading space), or driver_name is
a null string and driver_kind contains "routing" without the leading
@@ -1394,6 +1397,9 @@ else
if (LOGGING(sender_on_delivery))
s = string_append(s, &size, &ptr, 3, US" F=<", sender_address, US">");
+ if (*queue_name)
+ s = string_append(s, &size, &ptr, 2, US" Q=", queue_name);
+
/* Return path may not be set if no delivery actually happened */
if (used_return_path && LOGGING(return_path_on_delivery))
@@ -1950,12 +1956,13 @@ if ( !shadowing
|| tp->log_output || tp->log_fail_output || tp->log_defer_output
) )
{
- uschar *error;
+ uschar * error;
+
addr->return_filename =
- string_sprintf("%s/msglog/%s/%s-%d-%d", spool_directory, message_subdir,
- message_id, getpid(), return_count++);
- addr->return_file = open_msglog_file(addr->return_filename, 0400, &error);
- if (addr->return_file < 0)
+ spool_fname(US"msglog", message_subdir, message_id,
+ string_sprintf("-%d-%d", getpid(), return_count++));
+
+ if ((addr->return_file = open_msglog_file(addr->return_filename, 0400, &error)) < 0)
{
common_error(TRUE, addr, errno, US"Unable to %s file for %s transport "
"to return message: %s", error, tp->name, strerror(errno));
@@ -4378,13 +4385,13 @@ for (delivery_count = 0; addr_remote; delivery_count++)
a dup-with-new-file-pointer. */
(void)close(deliver_datafile);
- sprintf(CS spoolname, "%s/input/%s/%s-D", spool_directory, message_subdir,
- message_id);
- deliver_datafile = Uopen(spoolname, O_RDWR | O_APPEND, 0);
+ {
+ uschar * fname = spool_fname(US"input", message_subdir, message_id, US"-D");
- if (deliver_datafile < 0)
+ if ((deliver_datafile = Uopen(fname, O_RDWR | O_APPEND, 0)) < 0)
log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Failed to reopen %s for remote "
- "parallel delivery: %s", spoolname, strerror(errno));
+ "parallel delivery: %s", fname, strerror(errno));
+ }
/* Set the close-on-exec flag */
@@ -5231,53 +5238,51 @@ store, and also the list of recipients and the tree of non-recipients and
assorted flags. It updates message_size. If there is a reading or format error,
give up; if the message has been around for sufficiently long, remove it. */
-sprintf(CS spoolname, "%s-H", id);
-if ((rc = spool_read_header(spoolname, TRUE, TRUE)) != spool_read_OK)
{
- if (errno == ERRNO_SPOOLFORMAT)
+ uschar * spoolname = string_sprintf("%s-H", id);
+ if ((rc = spool_read_header(spoolname, TRUE, TRUE)) != spool_read_OK)
{
- struct stat statbuf;
- sprintf(CS big_buffer, "%s/input/%s/%s", spool_directory, message_subdir,
- spoolname);
- if (Ustat(big_buffer, &statbuf) == 0)
- log_write(0, LOG_MAIN, "Format error in spool file %s: "
- "size=" OFF_T_FMT, spoolname, statbuf.st_size);
- else log_write(0, LOG_MAIN, "Format error in spool file %s", spoolname);
- }
- else
- log_write(0, LOG_MAIN, "Error reading spool file %s: %s", spoolname,
- strerror(errno));
+ if (errno == ERRNO_SPOOLFORMAT)
+ {
+ struct stat statbuf;
+ if (Ustat(spool_fname(US"input", message_subdir, spoolname, US""),
+ &statbuf) == 0)
+ log_write(0, LOG_MAIN, "Format error in spool file %s: "
+ "size=" OFF_T_FMT, spoolname, statbuf.st_size);
+ else
+ log_write(0, LOG_MAIN, "Format error in spool file %s", spoolname);
+ }
+ else
+ log_write(0, LOG_MAIN, "Error reading spool file %s: %s", spoolname,
+ strerror(errno));
- /* If we managed to read the envelope data, received_time contains the
- time the message was received. Otherwise, we can calculate it from the
- message id. */
+ /* If we managed to read the envelope data, received_time contains the
+ time the message was received. Otherwise, we can calculate it from the
+ message id. */
- if (rc != spool_read_hdrerror)
- {
- received_time = 0;
- for (i = 0; i < 6; i++)
- received_time = received_time * BASE_62 + tab62[id[i] - '0'];
- }
+ if (rc != spool_read_hdrerror)
+ {
+ received_time = 0;
+ for (i = 0; i < 6; i++)
+ received_time = received_time * BASE_62 + tab62[id[i] - '0'];
+ }
- /* If we've had this malformed message too long, sling it. */
+ /* If we've had this malformed message too long, sling it. */
- if (now - received_time > keep_malformed)
- {
- sprintf(CS spoolname, "%s/msglog/%s/%s", spool_directory, message_subdir, id);
- Uunlink(spoolname);
- sprintf(CS spoolname, "%s/input/%s/%s-D", spool_directory, message_subdir, id);
- Uunlink(spoolname);
- sprintf(CS spoolname, "%s/input/%s/%s-H", spool_directory, message_subdir, id);
- Uunlink(spoolname);
- sprintf(CS spoolname, "%s/input/%s/%s-J", spool_directory, message_subdir, id);
- Uunlink(spoolname);
- log_write(0, LOG_MAIN, "Message removed because older than %s",
- readconf_printtime(keep_malformed));
- }
+ if (now - received_time > keep_malformed)
+ {
+ Uunlink(spool_fname(US"msglog", message_subdir, id, US""));
+ Uunlink(spool_fname(US"input", message_subdir, id, US"-D"));
+ Uunlink(spool_fname(US"input", message_subdir, id, US"-H"));
+ Uunlink(spool_fname(US"input", message_subdir, id, US"-J"));
+ log_write(0, LOG_MAIN, "Message removed because older than %s",
+ readconf_printtime(keep_malformed));
+ }
- (void)close(deliver_datafile);
- deliver_datafile = -1;
- return continue_closedown(); /* yields DELIVER_NOT_ATTEMPTED */
+ (void)close(deliver_datafile);
+ deliver_datafile = -1;
+ return continue_closedown(); /* yields DELIVER_NOT_ATTEMPTED */
+ }
}
/* The spool header file has been read. Look to see if there is an existing
@@ -5289,37 +5294,39 @@ existence, as it will get further successful deliveries added to it in this
run, and it will be deleted if this function gets to its end successfully.
Otherwise it might be needed again. */
-sprintf(CS spoolname, "%s/input/%s/%s-J", spool_directory, message_subdir, id);
-jread = Ufopen(spoolname, "rb");
-if (jread)
{
- while (Ufgets(big_buffer, big_buffer_size, jread))
+ uschar * fname = spool_fname(US"input", message_subdir, id, US"-J");
+
+ if ((jread = Ufopen(fname, "rb")))
{
- int n = Ustrlen(big_buffer);
- big_buffer[n-1] = 0;
- tree_add_nonrecipient(big_buffer);
- DEBUG(D_deliver) debug_printf("Previously delivered address %s taken from "
- "journal file\n", big_buffer);
+ while (Ufgets(big_buffer, big_buffer_size, jread))
+ {
+ int n = Ustrlen(big_buffer);
+ big_buffer[n-1] = 0;
+ tree_add_nonrecipient(big_buffer);
+ DEBUG(D_deliver) debug_printf("Previously delivered address %s taken from "
+ "journal file\n", big_buffer);
+ }
+ (void)fclose(jread);
+ /* Panic-dies on error */
+ (void)spool_write_header(message_id, SW_DELIVERING, NULL);
+ }
+ else if (errno != ENOENT)
+ {
+ log_write(0, LOG_MAIN|LOG_PANIC, "attempt to open journal for reading gave: "
+ "%s", strerror(errno));
+ return continue_closedown(); /* yields DELIVER_NOT_ATTEMPTED */
}
- (void)fclose(jread);
- /* Panic-dies on error */
- (void)spool_write_header(message_id, SW_DELIVERING, NULL);
- }
-else if (errno != ENOENT)
- {
- log_write(0, LOG_MAIN|LOG_PANIC, "attempt to open journal for reading gave: "
- "%s", strerror(errno));
- return continue_closedown(); /* yields DELIVER_NOT_ATTEMPTED */
- }
-/* A null recipients list indicates some kind of disaster. */
+ /* A null recipients list indicates some kind of disaster. */
-if (!recipients_list)
- {
- (void)close(deliver_datafile);
- deliver_datafile = -1;
- log_write(0, LOG_MAIN, "Spool error: no recipients for %s", spoolname);
- return continue_closedown(); /* yields DELIVER_NOT_ATTEMPTED */
+ if (!recipients_list)
+ {
+ (void)close(deliver_datafile);
+ deliver_datafile = -1;
+ log_write(0, LOG_MAIN, "Spool error: no recipients for %s", fname);
+ return continue_closedown(); /* yields DELIVER_NOT_ATTEMPTED */
+ }
}
@@ -5407,16 +5414,14 @@ done by rewriting the header spool file. */
if (message_logs)
{
- uschar *error;
+ uschar * fname = spool_fname(US"msglog", message_subdir, id, US"");
+ uschar * error;
int fd;
- sprintf(CS spoolname, "%s/msglog/%s/%s", spool_directory, message_subdir, id);
- fd = open_msglog_file(spoolname, SPOOL_MODE, &error);
-
- if (fd < 0)
+ if ((fd = open_msglog_file(fname, SPOOL_MODE, &error)) < 0)
{
log_write(0, LOG_MAIN|LOG_PANIC, "Couldn't %s message log %s: %s", error,
- spoolname, strerror(errno));
+ fname, strerror(errno));
return continue_closedown(); /* yields DELIVER_NOT_ATTEMPTED */
}
@@ -5425,7 +5430,7 @@ if (message_logs)
if (!(message_log = fdopen(fd, "a")))
{
log_write(0, LOG_MAIN|LOG_PANIC, "Couldn't fdopen message log %s: %s",
- spoolname, strerror(errno));
+ fname, strerror(errno));
return continue_closedown(); /* yields DELIVER_NOT_ATTEMPTED */
}
}
@@ -6644,13 +6649,12 @@ therein are added to the non-recipients. */
if (addr_local || addr_remote)
{
- sprintf(CS spoolname, "%s/input/%s/%s-J", spool_directory, message_subdir, id);
- journal_fd = Uopen(spoolname, O_WRONLY|O_APPEND|O_CREAT, SPOOL_MODE);
-
- if (journal_fd < 0)
+ uschar * fname = spool_fname(US"input", message_subdir, id, US"-J");
+
+ if ((journal_fd = Uopen(fname, O_WRONLY|O_APPEND|O_CREAT, SPOOL_MODE)) <0)
{
log_write(0, LOG_MAIN|LOG_PANIC, "Couldn't open journal file %s: %s",
- spoolname, strerror(errno));
+ fname, strerror(errno));
return DELIVER_NOT_ATTEMPTED;
}
@@ -6663,12 +6667,12 @@ if (addr_local || addr_remote)
|| fchmod(journal_fd, SPOOL_MODE)
)
{
- int ret = Uunlink(spoolname);
+ int ret = Uunlink(fname);
log_write(0, LOG_MAIN|LOG_PANIC, "Couldn't set perms on journal file %s: %s",
- spoolname, strerror(errno));
+ fname, strerror(errno));
if(ret && errno != ENOENT)
log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to unlink %s: %s",
- spoolname, strerror(errno));
+ fname, strerror(errno));
return DELIVER_NOT_ATTEMPTED;
}
}
@@ -7509,40 +7513,43 @@ Then delete the message itself. */
if (!addr_defer)
{
+ uschar * fname;
+
if (message_logs)
{
- sprintf(CS spoolname, "%s/msglog/%s/%s", spool_directory, message_subdir,
- id);
+ fname = spool_fname(US"msglog", message_subdir, id, US"");
if (preserve_message_logs)
{
int rc;
- sprintf(CS big_buffer, "%s/msglog.OLD/%s", spool_directory, id);
- if ((rc = Urename(spoolname, big_buffer)) < 0)
+ uschar * moname = spool_fname(US"msglog.OLD", US"", id, US"");
+
+ if ((rc = Urename(fname, moname)) < 0)
{
- (void)directory_make(spool_directory, US"msglog.OLD",
- MSGLOG_DIRECTORY_MODE, TRUE);
- rc = Urename(spoolname, big_buffer);
+ (void)directory_make(spool_directory,
+ spool_sname(US"msglog.OLD", US""),
+ MSGLOG_DIRECTORY_MODE, TRUE);
+ rc = Urename(fname, moname);
}
if (rc < 0)
log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to move %s to the "
- "msglog.OLD directory", spoolname);
+ "msglog.OLD directory", fname);
}
else
- if (Uunlink(spoolname) < 0)
+ if (Uunlink(fname) < 0)
log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to unlink %s: %s",
- spoolname, strerror(errno));
+ fname, strerror(errno));
}
/* Remove the two message files. */
- sprintf(CS spoolname, "%s/input/%s/%s-D", spool_directory, message_subdir, id);
- if (Uunlink(spoolname) < 0)
+ fname = spool_fname(US"input", message_subdir, id, US"-D");
+ if (Uunlink(fname) < 0)
log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to unlink %s: %s",
- spoolname, strerror(errno));
- sprintf(CS spoolname, "%s/input/%s/%s-H", spool_directory, message_subdir, id);
- if (Uunlink(spoolname) < 0)
+ fname, strerror(errno));
+ fname = spool_fname(US"input", message_subdir, id, US"-H");
+ if (Uunlink(fname) < 0)
log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to unlink %s: %s",
- spoolname, strerror(errno));
+ fname, strerror(errno));
/* Log the end of this message, with queue time if requested. */
@@ -8009,9 +8016,10 @@ if (journal_fd >= 0) (void)close(journal_fd);
if (remove_journal)
{
- sprintf(CS spoolname, "%s/input/%s/%s-J", spool_directory, message_subdir, id);
- if (Uunlink(spoolname) < 0 && errno != ENOENT)
- log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to unlink %s: %s", spoolname,
+ uschar * fname = spool_fname(US"input", message_subdir, id, US"-J");
+
+ if (Uunlink(fname) < 0 && errno != ENOENT)
+ log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to unlink %s: %s", fname,
strerror(errno));
/* Move the message off the spool if reqested */
@@ -8086,6 +8094,7 @@ int rc;
uschar * new_sender_address,
* save_sender_address;
BOOL save_qr = queue_running;
+uschar * spoolname;
/* make spool_open_datafile non-noisy on fail */
@@ -8104,7 +8113,7 @@ spool_read_header() may change all of them. But OTOH, when this
deliver_get_sender_address() gets called, the current message is done
already and nobody needs the globals anymore. (HS12, 2015-08-21) */
-sprintf(CS spoolname, "%s-H", id);
+spoolname = string_sprintf("%s-H", id);
save_sender_address = sender_address;
rc = spool_read_header(spoolname, TRUE, TRUE);
diff --git a/src/src/exim.c b/src/src/exim.c
index 474851c21..08ceab7e1 100644
--- a/src/src/exim.c
+++ b/src/src/exim.c
@@ -2729,12 +2729,22 @@ for (i = 1; i < argc; i++)
/* -MCD: set the smtp_use_dsn flag; this indicates that the host
that exim is connected to supports the esmtp extension DSN */
+
else if (Ustrcmp(argrest, "CD") == 0)
{
smtp_use_dsn = TRUE;
break;
}
+ /* -MCG: set the queue name, to a non-default value */
+
+ else if (Ustrcmp(argrest, "CG") == 0)
+ {
+ if (++i < argc) queue_name = string_copy(argv[i]);
+ else badarg = TRUE;
+ break;
+ }
+
/* -MCP: set the smtp_use_pipelining flag; this is useful only when
it preceded -MC (see above) */
@@ -2750,9 +2760,9 @@ for (i = 1; i < argc; i++)
else if (Ustrcmp(argrest, "CQ") == 0)
{
- if(++i < argc) passed_qr_pid = (pid_t)(Uatol(argv[i]));
+ if (++i < argc) passed_qr_pid = (pid_t)(Uatol(argv[i]));
else badarg = TRUE;
- if(++i < argc) passed_qr_pipe = (int)(Uatol(argv[i]));
+ if (++i < argc) passed_qr_pipe = (int)(Uatol(argv[i]));
else badarg = TRUE;
break;
}
@@ -3227,7 +3237,7 @@ for (i = 1; i < argc; i++)
if (*argrest == 'f')
{
queue_run_force = TRUE;
- if (*(++argrest) == 'f')
+ if (*++argrest == 'f')
{
deliver_force_thaw = TRUE;
argrest++;
@@ -3242,8 +3252,19 @@ for (i = 1; i < argc; i++)
argrest++;
}
- /* -q[f][f][l]: Run the queue, optionally forced, optionally local only,
- optionally starting from a given message id. */
+ /* -q[f][f][l][G<name>]... Work on the named queue */
+
+ if (*argrest == 'G')
+ {
+ int i;
+ for (argrest++, i = 0; argrest[i] && argrest[i] != '/'; ) i++;
+ queue_name = string_copyn(argrest, i);
+ argrest += i;
+ if (*argrest == '/') argrest++;
+ }
+
+ /* -q[f][f][l][G<name>]: Run the queue, optionally forced, optionally local
+ only, optionally named, optionally starting from a given message id. */
if (*argrest == 0 &&
(i + 1 >= argc || argv[i+1][0] == '-' || mac_ismsgid(argv[i+1])))
@@ -3255,20 +3276,14 @@ for (i = 1; i < argc; i++)
stop_queue_run_id = argv[++i];
}
- /* -q[f][f][l]<n>: Run the queue at regular intervals, optionally forced,
- optionally local only. */
+ /* -q[f][f][l][G<name>/]<n>: Run the queue at regular intervals, optionally
+ forced, optionally local only, optionally named. */
- else
+ else if ((queue_interval = readconf_readtime(*argrest ? argrest : argv[++i],
+ 0, FALSE)) <= 0)
{
- if (*argrest != 0)
- queue_interval = readconf_readtime(argrest, 0, FALSE);
- else
- queue_interval = readconf_readtime(argv[++i], 0, FALSE);
- if (queue_interval <= 0)
- {
- fprintf(stderr, "exim: bad time value %s: abandoned\n", argv[i]);
- exit(EXIT_FAILURE);
- }
+ fprintf(stderr, "exim: bad time value %s: abandoned\n", argv[i]);
+ exit(EXIT_FAILURE);
}
break;
@@ -3288,8 +3303,7 @@ for (i = 1; i < argc; i++)
if (*argrest != 0)
{
int i;
- for (i = 0; i < sizeof(rsopts)/sizeof(uschar *); i++)
- {
+ for (i = 0; i < nelem(rsopts); i++)
if (Ustrcmp(argrest, rsopts[i]) == 0)
{
if (i != 2) queue_run_force = TRUE;
@@ -3297,21 +3311,20 @@ for (i = 1; i < argc; i++)
if (i == 1 || i == 4) deliver_force_thaw = TRUE;
argrest += Ustrlen(rsopts[i]);
}
- }
}
/* -R: Set string to match in addresses for forced queue run to
pick out particular messages. */
- if (*argrest == 0)
+ if (*argrest)
+ deliver_selectstring = argrest;
+ else if (i+1 < argc)
+ deliver_selectstring = argv[++i];
+ else
{
- if (i+1 < argc) deliver_selectstring = argv[++i]; else
- {
- fprintf(stderr, "exim: string expected after -R\n");
- exit(EXIT_FAILURE);
- }
+ fprintf(stderr, "exim: string expected after -R\n");
+ exit(EXIT_FAILURE);
}
- else deliver_selectstring = argrest;
break;
@@ -3332,11 +3345,10 @@ for (i = 1; i < argc; i++)
in all cases provided there are no further characters in this
argument. */
- if (*argrest != 0)
+ if (*argrest)
{
int i;
- for (i = 0; i < sizeof(rsopts)/sizeof(uschar *); i++)
- {
+ for (i = 0; i < nelem(rsopts); i++)
if (Ustrcmp(argrest, rsopts[i]) == 0)
{
if (i != 2) queue_run_force = TRUE;
@@ -3344,21 +3356,20 @@ for (i = 1; i < argc; i++)
if (i == 1 || i == 4) deliver_force_thaw = TRUE;
argrest += Ustrlen(rsopts[i]);
}
- }
}
/* -S: Set string to match in addresses for forced queue run to
pick out particular messages. */
- if (*argrest == 0)
+ if (*argrest)
+ deliver_selectstring_sender = argrest;
+ else if (i+1 < argc)
+ deliver_selectstring_sender = argv[++i];
+ else
{
- if (i+1 < argc) deliver_selectstring_sender = argv[++i]; else
- {
- fprintf(stderr, "exim: string expected after -S\n");
- exit(EXIT_FAILURE);
- }
+ fprintf(stderr, "exim: string expected after -S\n");
+ exit(EXIT_FAILURE);
}
- else deliver_selectstring_sender = argrest;
break;
/* -Tqt is an option that is exclusively for use by the testing suite.
@@ -3472,8 +3483,9 @@ for (i = 1; i < argc; i++)
/* If -R or -S have been specified without -q, assume a single queue run. */
-if ((deliver_selectstring != NULL || deliver_selectstring_sender != NULL) &&
- queue_interval < 0) queue_interval = 0;
+if ( (deliver_selectstring || deliver_selectstring_sender)
+ && queue_interval < 0)
+ queue_interval = 0;
END_ARG:
@@ -3489,12 +3501,12 @@ if ((
) ||
(
msg_action_arg > 0 &&
- (daemon_listen || queue_interval >= 0 || list_options ||
+ (daemon_listen || queue_interval > 0 || list_options ||
(checking && msg_action != MSG_LOAD) ||
bi_option || test_retry_arg >= 0 || test_rewrite_arg >= 0)
) ||
(
- (daemon_listen || queue_interval >= 0) &&
+ (daemon_listen || queue_interval > 0) &&
(sender_address != NULL || list_options || list_queue || checking ||
bi_option)
) ||
@@ -4670,7 +4682,11 @@ if (queue_interval == 0 && !daemon_listen)
(start_queue_run_id == NULL)? US"" : start_queue_run_id,
(stop_queue_run_id == NULL)? US"" : US" stopping at ",
(stop_queue_run_id == NULL)? US"" : stop_queue_run_id);
- set_process_info("running the queue (single queue run)");
+ if (*queue_name)
+ set_process_info(CS string_sprintf(
+ "running the '%s' queue (single queue run)", queue_name));
+ else
+ set_process_info("running the queue (single queue run)");
queue_run(start_queue_run_id, stop_queue_run_id, FALSE);
exim_exit(EXIT_SUCCESS);
}
@@ -5714,8 +5730,8 @@ while (more)
if (geteuid() != root_uid && !deliver_drop_privilege && !unprivileged)
{
- (void)child_exec_exim(CEE_EXEC_EXIT, FALSE, NULL, FALSE, 2, US"-Mc",
- message_id);
+ (void)child_exec_exim(CEE_EXEC_EXIT, FALSE, NULL, FALSE,
+ 2, US"-Mc", message_id);
/* Control does not return here. */
}
diff --git a/src/src/expand.c b/src/src/expand.c
index 1484a3027..a0b36f7e2 100644
--- a/src/src/expand.c
+++ b/src/src/expand.c
@@ -627,6 +627,7 @@ static var_entry var_table[] = {
{ "prvscheck_result", vtype_stringptr, &prvscheck_result },
{ "qualify_domain", vtype_stringptr, &qualify_domain_sender },
{ "qualify_recipient", vtype_stringptr, &qualify_domain_recipient },
+ { "queue_name", vtype_stringptr, &queue_name },
{ "rcpt_count", vtype_int, &rcpt_count },
{ "rcpt_defer_count", vtype_int, &rcpt_defer_count },
{ "rcpt_fail_count", vtype_int, &rcpt_fail_count },
diff --git a/src/src/functions.h b/src/src/functions.h
index cc4cb7ea6..ebbdc55e2 100644
--- a/src/src/functions.h
+++ b/src/src/functions.h
@@ -407,6 +407,8 @@ extern int spam(const uschar **);
extern FILE *spool_mbox(unsigned long *, const uschar *);
#endif
extern BOOL spool_move_message(uschar *, uschar *, uschar *, uschar *);
+extern uschar *spool_fname(const uschar *, uschar *, uschar *, uschar *);
+extern uschar *spool_sname(const uschar *, uschar *);
extern int spool_open_datafile(uschar *);
extern int spool_open_temp(uschar *);
extern int spool_read_header(uschar *, BOOL, BOOL);
diff --git a/src/src/globals.c b/src/src/globals.c
index e7a54c4b8..4f5a922b4 100644
--- a/src/src/globals.c
+++ b/src/src/globals.c
@@ -1018,6 +1018,7 @@ BOOL queue_2stage = FALSE;
uschar *queue_domains = NULL;
int queue_interval = -1;
BOOL queue_list_requires_admin = TRUE;
+uschar *queue_name = US"";
BOOL queue_only = FALSE;
uschar *queue_only_file = NULL;
int queue_only_load = -1;
@@ -1028,7 +1029,7 @@ BOOL queue_run_first_delivery = FALSE;
BOOL queue_run_force = FALSE;
BOOL queue_run_in_order = FALSE;
BOOL queue_run_local = FALSE;
-int queue_run_max = 5;
+uschar *queue_run_max = US"5";
pid_t queue_run_pid = (pid_t)0;
int queue_run_pipe = -1;
BOOL queue_running = FALSE;
diff --git a/src/src/globals.h b/src/src/globals.h
index 1caf8e8a9..6e42bc3d7 100644
--- a/src/src/globals.h
+++ b/src/src/globals.h
@@ -666,6 +666,7 @@ extern BOOL queue_running; /* TRUE for queue running process and */
extern pid_t queue_run_pid; /* PID of the queue running process or 0 */
extern int queue_run_pipe; /* Pipe for synchronizing */
extern int queue_interval; /* Queue running interval */
+extern uschar *queue_name; /* Name of queue, if nondefault spooling */
extern BOOL queue_only; /* TRUE to disable immediate delivery */
extern int queue_only_load; /* Max load before auto-queue */
extern BOOL queue_only_load_latch; /* Latch queue_only_load TRUE */
@@ -673,7 +674,7 @@ extern uschar *queue_only_file; /* Queue if file exists/not-exists */
extern BOOL queue_only_override; /* Allow override from command line */
extern BOOL queue_only_policy; /* ACL or local_scan wants queue_only */
extern BOOL queue_run_in_order; /* As opposed to random */
-extern int queue_run_max; /* Max queue runners */
+extern uschar *queue_run_max; /* Max queue runners */
extern BOOL queue_smtp; /* Disable all immediate STMP (-odqs)*/
extern uschar *queue_smtp_domains; /* Ditto, for these domains */
diff --git a/src/src/queue.c b/src/src/queue.c
index cc8d36b23..f53759c43 100644
--- a/src/src/queue.c
+++ b/src/src/queue.c
@@ -12,6 +12,42 @@
+/* Routines with knowlege of spool layout */
+
+static void
+spool_pname_buf(uschar * buf, int len)
+{
+snprintf(CS buf, len, "%s/%s/input", spool_directory, queue_name);
+}
+
+static uschar *
+spool_dname(const uschar * purpose, uschar * subdir)
+{
+return string_sprintf("%s/%s/%s/%s",
+ spool_directory, queue_name, purpose, subdir);
+}
+
+uschar *
+spool_sname(const uschar * purpose, uschar * subdir)
+{
+return string_sprintf("%s%s%s%s%s",
+ queue_name, *queue_name ? "/" : "",
+ purpose,
+ *subdir ? "/" : "", subdir);
+}
+
+uschar *
+spool_fname(const uschar * purpose, uschar * subdir, uschar * fname, uschar * suffix)
+{
+return string_sprintf("%s/%s/%s/%s/%s%s",
+ spool_directory, queue_name, purpose, subdir, fname, suffix);
+}
+
+
+
+
+#ifndef COMPILE_UTILITY
+
/* The number of nodes to use for the bottom-up merge sort when a list of queue
items is to be ordered. The code for this sort was contributed as a patch by
Michael Haardt. */
@@ -142,7 +178,8 @@ else i = subdiroffset;
/* Set up prototype for the directory name. */
-sprintf(CS buffer, "%s/input", spool_directory);
+spool_pname_buf(buffer, sizeof(buffer));
+buffer[sizeof(buffer) - 3] = 0;
subptr = Ustrlen(buffer);
buffer[subptr+2] = 0; /* terminator for lengthened name */
@@ -161,8 +198,9 @@ for (; i <= *subcount; i++)
buffer[subptr+1] = subdirchar;
}
- dd = opendir(CS buffer);
- if (dd == NULL) continue;
+ DEBUG(D_queue_run) debug_printf("looking in %s\n", buffer);
+ if (!(dd = opendir(CS buffer)))
+ continue;
/* Now scan the directory. */
@@ -264,9 +302,11 @@ for (; i <= *subcount; i++)
{
if (!split_spool_directory && count <= 2)
{
+ uschar subdir[2];
+
rmdir(CS buffer);
- sprintf(CS big_buffer, "%s/msglog/%c", spool_directory, subdirchar);
- rmdir(CS big_buffer);
+ subdir[0] = subdirchar; subdir[1] = 0;
+ rmdir(CS spool_dname(US"msglog", subdir));
}
if (subdiroffset > 0) break; /* Single sub-directory */
}
@@ -389,7 +429,11 @@ if (!recurse)
}
log_detail = string_copy(big_buffer);
- log_write(L_queue_run, LOG_MAIN, "Start queue run: %s", log_detail);
+ if (*queue_name)
+ log_write(L_queue_run, LOG_MAIN, "Start '%s' queue run: %s",
+ queue_name, log_detail);
+ else
+ log_write(L_queue_run, LOG_MAIN, "Start queue run: %s", log_detail);
}
/* If deliver_selectstring is a regex, compile it. */
@@ -476,9 +520,8 @@ for (i = (queue_run_in_order? -1 : 0);
/* Check that the message still exists */
message_subdir[0] = f->dir_uschar;
- sprintf(CS buffer, "%s/input/%s/%s", spool_directory, message_subdir,
- f->text);
- if (Ustat(buffer, &statbuf) < 0) continue;
+ if (Ustat(spool_fname(US"input", message_subdir, f->text, US""), &statbuf) < 0)
+ continue;
/* There are some tests that require the reading of the header file. Ensure
the store used is scavenged afterwards so that this process doesn't keep
@@ -698,7 +741,12 @@ if (queue_2stage)
/* At top level, log the end of the run. */
-if (!recurse) log_write(L_queue_run, LOG_MAIN, "End queue run: %s", log_detail);
+if (!recurse)
+ if (*queue_name)
+ log_write(L_queue_run, LOG_MAIN, "End '%s' queue run: %s",
+ queue_name, log_detail);
+ else
+ log_write(L_queue_run, LOG_MAIN, "End queue run: %s", log_detail);
}
@@ -841,17 +889,16 @@ for (; f != NULL; f = f->next)
int ptr;
FILE *jread;
struct stat statbuf;
+ uschar * fname = spool_fname(US"input", message_subdir, f->text, US"");
- sprintf(CS big_buffer, "%s/input/%s/%s", spool_directory, message_subdir,
- f->text);
- ptr = Ustrlen(big_buffer)-1;
- big_buffer[ptr] = 'D';
+ ptr = Ustrlen(fname)-1;
+ fname[ptr] = 'D';
/* Add the data size to the header size; don't count the file name
at the start of the data file, but add one for the notional blank line
that precedes the data. */
- if (Ustat(big_buffer, &statbuf) == 0)
+ if (Ustat(fname, &statbuf) == 0)
size = message_size + statbuf.st_size - SPOOL_DATA_START_OFFSET + 1;
i = (now - received_time)/60; /* minutes on queue */
if (i > 90)
@@ -863,8 +910,8 @@ for (; f != NULL; f = f->next)
/* Collect delivered addresses from any J file */
- big_buffer[ptr] = 'J';
- jread = Ufopen(big_buffer, "rb");
+ fname[ptr] = 'J';
+ jread = Ufopen(fname, "rb");
if (jread != NULL)
{
while (Ufgets(big_buffer, big_buffer_size, jread) != NULL)
@@ -892,9 +939,9 @@ for (; f != NULL; f = f->next)
if (save_errno == ERRNO_SPOOLFORMAT)
{
struct stat statbuf;
- sprintf(CS big_buffer, "%s/input/%s/%s", spool_directory, message_subdir,
- f->text);
- if (Ustat(big_buffer, &statbuf) == 0)
+ uschar * fname = spool_fname(US"input", message_subdir, f->text, US"");
+
+ if (Ustat(fname, &statbuf) == 0)
printf("*** spool format error: size=" OFF_T_FMT " ***",
statbuf.st_size);
else printf("*** spool format error ***");
@@ -959,7 +1006,7 @@ struct passwd *pw;
uschar *doing = NULL;
uschar *username;
uschar *errmsg;
-uschar spoolname[256];
+uschar spoolname[32];
/* Set the global message_id variable, used when re-writing spool files. This
also causes message ids to be added to log messages. */
@@ -1004,12 +1051,13 @@ if (action >= MSG_SHOW_BODY)
for (i = 0; i < 2; i++)
{
- message_subdir[0] = (split_spool_directory == (i == 0))? id[5] : 0;
- sprintf(CS spoolname, "%s/%s/%s/%s%s", spool_directory, subdirectory,
- message_subdir, id, suffix);
- fd = Uopen(spoolname, O_RDONLY, 0);
- if (fd >= 0) break;
- if (i == 0) continue;
+ message_subdir[0] = split_spool_directory == (i == 0) ? id[5] : 0;
+ if ((fd = Uopen(spool_fname(subdirectory, message_subdir, id, suffix),
+ O_RDONLY, 0)) >= 0)
+ break;
+ if (i == 0)
+ continue;
+
printf("Failed to open %s file for %s%s: %s\n", subdirectory, id, suffix,
strerror(errno));
if (action == MSG_SHOW_LOG && !message_logs)
@@ -1031,7 +1079,6 @@ only if the action is remove and the user is an admin user, to allow for
tidying up broken states. */
if ((deliver_datafile = spool_open_datafile(id)) < 0)
- {
if (errno == ENOENT)
{
yield = FALSE;
@@ -1046,7 +1093,6 @@ if ((deliver_datafile = spool_open_datafile(id)) < 0)
strerror(errno));
return FALSE;
}
- }
/* Read the spool header file for the message. Again, continue after an
error only in the case of deleting by an administrator. Setting the third
@@ -1159,49 +1205,70 @@ switch(action)
operation, just run everything twice. */
case MSG_REMOVE:
- message_subdir[0] = id[5];
- for (j = 0; j < 2; message_subdir[0] = 0, j++)
{
- sprintf(CS spoolname, "%s/msglog/%s/%s", spool_directory, message_subdir, id);
- if (Uunlink(spoolname) < 0)
- {
- if (errno != ENOENT)
- {
- yield = FALSE;
- printf("Error while removing %s: %s\n", spoolname,
- strerror(errno));
- }
- }
- else removed = TRUE;
+ uschar suffix[3];
- for (i = 0; i < 3; i++)
+ suffix[0] = '-';
+ suffix[2] = 0;
+ message_subdir[0] = id[5];
+
+ for (j = 0; j < 2; message_subdir[0] = 0, j++)
{
- sprintf(CS spoolname, "%s/input/%s/%s-%c", spool_directory, message_subdir,
- id, "DHJ"[i]);
- if (Uunlink(spoolname) < 0)
- {
- if (errno != ENOENT)
- {
- yield = FALSE;
- printf("Error while removing %s: %s\n", spoolname,
- strerror(errno));
- }
- }
- else removed = TRUE;
+ uschar * fname = spool_fname(US"msglog", message_subdir, id, US"");
+
+ DEBUG(D_any) debug_printf(" removing %s", fname);
+ if (Uunlink(fname) < 0)
+ {
+ if (errno != ENOENT)
+ {
+ yield = FALSE;
+ printf("Error while removing %s: %s\n", fname, strerror(errno));
+ }
+ else DEBUG(D_any) debug_printf(" (no file)\n");
+ }
+ else
+ {
+ removed = TRUE;
+ DEBUG(D_any) debug_printf(" (ok)\n");
+ }
+
+ for (i = 0; i < 3; i++)
+ {
+ uschar * fname;
+
+ suffix[1] = (US"DHJ")[i];
+ fname = spool_fname(US"input", message_subdir, id, suffix);
+
+ DEBUG(D_any) debug_printf(" removing %s", fname);
+ if (Uunlink(fname) < 0)
+ {
+ if (errno != ENOENT)
+ {
+ yield = FALSE;
+ printf("Error while removing %s: %s\n", fname, strerror(errno));
+ }
+ else DEBUG(D_any) debug_printf(" (no file)\n");
+ }
+ else
+ {
+ removed = TRUE;
+ DEBUG(D_any) debug_printf(" (done)\n");
+ }
+ }
}
- }
- /* In the common case, the datafile is open (and locked), so give the
- obvious message. Otherwise be more specific. */
+ /* In the common case, the datafile is open (and locked), so give the
+ obvious message. Otherwise be more specific. */
- if (deliver_datafile >= 0) printf("has been removed\n");
- else printf("has been removed or did not exist\n");
- if (removed)
- {
- log_write(0, LOG_MAIN, "removed by %s", username);
- log_write(0, LOG_MAIN, "Completed");
+ if (deliver_datafile >= 0) printf("has been removed\n");
+ else printf("has been removed or did not exist\n");
+ if (removed)
+ {
+ log_write(0, LOG_MAIN, "removed by %s", username);
+ log_write(0, LOG_MAIN, "Completed");
+ }
+ break;
}
- break;
case MSG_MARK_ALL_DELIVERED:
@@ -1380,4 +1447,6 @@ while ((ss = string_nextinlist(&s, &sep, buffer, sizeof(buffer))) != NULL)
}
}
+#endif /*!COMPILE_UTILITY*/
+
/* End of queue.c */
diff --git a/src/src/readconf.c b/src/src/readconf.c
index f4a9b2d23..25ff58eb9 100644
--- a/src/src/readconf.c
+++ b/src/src/readconf.c
@@ -369,7 +369,7 @@ static optionlist optionlist_config[] = {
{ "queue_only_load_latch", opt_bool, &queue_only_load_latch },
{ "queue_only_override", opt_bool, &queue_only_override },
{ "queue_run_in_order", opt_bool, &queue_run_in_order },
- { "queue_run_max", opt_int, &queue_run_max },
+ { "queue_run_max", opt_stringptr, &queue_run_max },
{ "queue_smtp_domains", opt_stringptr, &queue_smtp_domains },
{ "receive_timeout", opt_time, &receive_timeout },
{ "received_header_text", opt_stringptr, &received_header_text },
diff --git a/src/src/receive.c b/src/src/receive.c
index 92ec2cd87..52e041c90 100644
--- a/src/src/receive.c
+++ b/src/src/receive.c
@@ -23,7 +23,7 @@ extern int dcc_ok;
static FILE *data_file = NULL;
static int data_fd = -1;
-static uschar spool_name[256];
+static uschar *spool_name = US"";
@@ -1543,7 +1543,7 @@ yet, initialize the size and warning count, and deal with no size limit. */
message_id[0] = 0;
data_file = NULL;
data_fd = -1;
-spool_name[0] = 0;
+spool_name = US"";
message_size = 0;
warning_count = 0;
received_count = 1; /* For the one we will add */
@@ -2472,7 +2472,7 @@ it will fit. */
to be the least significant base-62 digit of the time of arrival. Otherwise
ensure that it is an empty string. */
-message_subdir[0] = split_spool_directory? message_id[5] : 0;
+message_subdir[0] = split_spool_directory ? message_id[5] : 0;
/* Now that we have the message-id, if there is no message-id: header, generate
one, but only for local (without suppress_local_fixups) or submission mode
@@ -2861,20 +2861,18 @@ if (cutthrough.fd >= 0)
/* Open a new spool file for the data portion of the message. We need
to access it both via a file descriptor and a stream. Try to make the
-directory if it isn't there. Note re use of sprintf: spool_directory
-is checked on input to be < 200 characters long. */
+directory if it isn't there. */
-sprintf(CS spool_name, "%s/input/%s/%s-D", spool_directory, message_subdir,
- message_id);
-data_fd = Uopen(spool_name, O_RDWR|O_CREAT|O_EXCL, SPOOL_MODE);
-if (data_fd < 0)
+spool_name = spool_fname(US"input", message_subdir, message_id, US"-D");
+DEBUG(D_receive) debug_printf("Data file name: %s\n", spool_name);
+
+if ((data_fd = Uopen(spool_name, O_RDWR|O_CREAT|O_EXCL, SPOOL_MODE)) < 0)
{
if (errno == ENOENT)
{
- uschar temp[16];
- sprintf(CS temp, "input/%s", message_subdir);
- if (message_subdir[0] == 0) temp[5] = 0;
- (void)directory_make(spool_directory, temp, INPUT_DIRECTORY_MODE, TRUE);
+ (void) directory_make(spool_directory,
+ spool_sname(US"input", message_subdir),
+ INPUT_DIRECTORY_MODE, TRUE);
data_fd = Uopen(spool_name, O_RDWR|O_CREAT|O_EXCL, SPOOL_MODE);
}
if (data_fd < 0)
@@ -3650,11 +3648,11 @@ signal(SIGINT, SIG_IGN);
deliver_firsttime = TRUE;
#ifdef EXPERIMENTAL_BRIGHTMAIL
-if (bmi_run == 1) {
- /* rewind data file */
+if (bmi_run == 1)
+ { /* rewind data file */
lseek(data_fd, (long int)SPOOL_DATA_START_OFFSET, SEEK_SET);
bmi_verdicts = bmi_process_message(header_list, data_fd);
-};
+ }
#endif
/* Update the timstamp in our Received: header to account for any time taken by
@@ -3692,7 +3690,6 @@ if (host_checking || blackholed_by != NULL)
/* Write the -H file */
else
- {
if ((msg_size = spool_write_header(message_id, SW_RECEIVING, &errmsg)) < 0)
{
log_write(0, LOG_MAIN, "Message abandoned: %s", errmsg);
@@ -3712,7 +3709,6 @@ else
/* Does not return */
}
}
- }
/* The message has now been successfully received. */
@@ -3806,6 +3802,9 @@ if (LOGGING(8bitmime))
s = string_append(s, &size, &sptr, 2, US" M8S=", big_buffer);
}
+if (*queue_name)
+ s = string_append(s, &size, &sptr, 2, US" Q=", queue_name);
+
/* If an addr-spec in a message-id contains a quoted string, it can contain
any characters except " \ and CR and so in particular it can contain NL!
Therefore, make sure we use a printing-characters only version for the log.
@@ -3860,16 +3859,15 @@ if (message_logs && blackholed_by == NULL)
{
int fd;
- sprintf(CS spool_name, "%s/msglog/%s/%s", spool_directory, message_subdir,
- message_id);
- fd = Uopen(spool_name, O_WRONLY|O_APPEND|O_CREAT, SPOOL_MODE);
-
- if (fd < 0 && errno == ENOENT)
+ spool_name = spool_fname(US"msglog", message_subdir, message_id, US"");
+
+ if ( (fd = Uopen(spool_name, O_WRONLY|O_APPEND|O_CREAT, SPOOL_MODE)) < 0
+ && errno == ENOENT
+ )
{
- uschar temp[16];
- sprintf(CS temp, "msglog/%s", message_subdir);
- if (message_subdir[0] == 0) temp[6] = 0;
- (void)directory_make(spool_directory, temp, MSGLOG_DIRECTORY_MODE, TRUE);
+ (void)directory_make(spool_directory,
+ spool_sname(US"msglog", message_subdir),
+ MSGLOG_DIRECTORY_MODE, TRUE);
fd = Uopen(spool_name, O_WRONLY|O_APPEND|O_CREAT, SPOOL_MODE);
}
@@ -3954,17 +3952,9 @@ if (smtp_input && sender_host_address != NULL && !sender_host_notsocket &&
/* Delete the files for this aborted message. */
- sprintf(CS spool_name, "%s/input/%s/%s-D", spool_directory,
- message_subdir, message_id);
- Uunlink(spool_name);
-
- sprintf(CS spool_name, "%s/input/%s/%s-H", spool_directory,
- message_subdir, message_id);
- Uunlink(spool_name);
-
- sprintf(CS spool_name, "%s/msglog/%s/%s", spool_directory,
- message_subdir, message_id);
- Uunlink(spool_name);
+ Uunlink(spool_fname(US"input", message_subdir, message_id, US"-D"));
+ Uunlink(spool_fname(US"input", message_subdir, message_id, US"-H"));
+ Uunlink(spool_fname(US"msglog", message_subdir, message_id, US""));
goto TIDYUP;
}
@@ -4118,16 +4108,11 @@ if (smtp_input)
switch (cutthrough_done)
{
case ACCEPTED: log_write(0, LOG_MAIN, "Completed");/* Delivery was done */
- case PERM_REJ: { /* Delete spool files */
- sprintf(CS spool_name, "%s/input/%s/%s-D", spool_directory,
- message_subdir, message_id);
- Uunlink(spool_name);
- sprintf(CS spool_name, "%s/input/%s/%s-H", spool_directory,
- message_subdir, message_id);
- Uunlink(spool_name);
- sprintf(CS spool_name, "%s/msglog/%s/%s", spool_directory,
- message_subdir, message_id);
- Uunlink(spool_name);
+ case PERM_REJ:
+ { /* Delete spool files */
+ Uunlink(spool_fname(US"input", message_subdir, message_id, US"-D"));
+ Uunlink(spool_fname(US"input", message_subdir, message_id, US"-H"));
+ Uunlink(spool_fname(US"msglog", message_subdir, message_id, US""));
}
case TMP_REJ: message_id[0] = 0; /* Prevent a delivery from starting */
default:break;
diff --git a/src/src/smtp_in.c b/src/src/smtp_in.c
index df66ed02f..53387011c 100644
--- a/src/src/smtp_in.c
+++ b/src/src/smtp_in.c
@@ -4963,8 +4963,10 @@ while (done <= 0)
break;
}
etrn_command = US"exim -R";
- argv = CUSS child_exec_exim(CEE_RETURN_ARGV, TRUE, NULL, TRUE, 2, US"-R",
- smtp_cmd_data);
+ argv = CUSS child_exec_exim(CEE_RETURN_ARGV, TRUE, NULL, TRUE,
+ *queue_name ? 4 : 2,
+ US"-R", smtp_cmd_data,
+ US"-MCG", queue_name);
}
/* If we are host-testing, don't actually do anything. */
diff --git a/src/src/spool_in.c b/src/src/spool_in.c
index cafca603d..7eb42907c 100644
--- a/src/src/spool_in.c
+++ b/src/src/spool_in.c
@@ -37,7 +37,6 @@ spool_open_datafile(uschar *id)
int i;
struct stat statbuf;
flock_t lock_data;
-uschar spoolname[256];
int fd;
/* If split_spool_directory is set, first look for the file in the appropriate
@@ -49,20 +48,27 @@ splitting state. */
for (i = 0; i < 2; i++)
{
+ uschar * fname;
int save_errno;
- message_subdir[0] = (split_spool_directory == (i == 0))? id[5] : 0;
- sprintf(CS spoolname, "%s/input/%s/%s-D", spool_directory, message_subdir, id);
- if ((fd = Uopen(spoolname, O_RDWR | O_APPEND, 0)) >= 0)
+
+ message_subdir[0] = split_spool_directory == i == 0 ? id[5] : 0;
+ fname = spool_fname(US"input", message_subdir, id, US"-D");
+ DEBUG(D_deliver) debug_printf("Trying spool file %s\n", fname);
+
+ if ((fd = Uopen(fname, O_RDWR | O_APPEND, 0)) >= 0)
break;
save_errno = errno;
if (errno == ENOENT)
{
if (i == 0) continue;
if (!queue_running)
- log_write(0, LOG_MAIN, "Spool file %s-D not found", id);
+ log_write(0, LOG_MAIN, "Spool%s%s file %s-D not found",
+ *queue_name ? " Q=" : "",
+ *queue_name ? queue_name : "",
+ id);
}
- else log_write(0, LOG_MAIN, "Spool error for %s: %s", spoolname,
- strerror(errno));
+ else
+ log_write(0, LOG_MAIN, "Spool error for %s: %s", fname, strerror(errno));
errno = save_errno;
return -1;
}
@@ -318,12 +324,12 @@ and unsplit directories, as for the data file above. */
for (n = 0; n < 2; n++)
{
if (!subdir_set)
- message_subdir[0] = (split_spool_directory == (n == 0))? name[5] : 0;
- sprintf(CS big_buffer, "%s/input/%s/%s", spool_directory, message_subdir,
- name);
- f = Ufopen(big_buffer, "rb");
- if (f != NULL) break;
- if (n != 0 || subdir_set || errno != ENOENT) return spool_read_notopen;
+ message_subdir[0] = split_spool_directory == (n == 0) ? name[5] : 0;
+
+ if ((f = Ufopen(spool_fname(US"input", message_subdir, name, US""), "rb")))
+ break;
+ if (n != 0 || subdir_set || errno != ENOENT)
+ return spool_read_notopen;
}
errno = 0;
diff --git a/src/src/spool_mbox.c b/src/src/spool_mbox.c
index ada3f3693..b7ab06127 100644
--- a/src/src/spool_mbox.c
+++ b/src/src/spool_mbox.c
@@ -113,17 +113,15 @@ if (!spool_mbox_ok)
message_subdir[1] = '\0';
for (i = 0; i < 2; i++)
{
- message_subdir[0] = (split_spool_directory == (i == 0))? message_id[5] : 0;
- temp_string = string_sprintf("%s/input/%s/%s-D", spool_directory,
- message_subdir, message_id);
- data_file = Ufopen(temp_string, "rb");
- if (data_file != NULL) break;
+ message_subdir[0] = split_spool_directory == (i == 0) ? message_id[5] : 0;
+ temp_string = spool_fname(US"input", message_subdir, message_id, US"-D");
+ if ((data_file = Ufopen(temp_string, "rb"))) break;
}
}
else
data_file = Ufopen(source_file_override, "rb");
- if (data_file == NULL)
+ if (!data_file)
{
log_write(0, LOG_MAIN|LOG_PANIC, "Could not open datafile for message %s",
message_id);
diff --git a/src/src/spool_out.c b/src/src/spool_out.c
index e960907db..82b606871 100644
--- a/src/src/spool_out.c
+++ b/src/src/spool_out.c
@@ -134,15 +134,16 @@ int size_correction;
FILE *f;
header_line *h;
struct stat statbuf;
-uschar name[256];
-uschar temp_name[256];
+uschar * tname;
+uschar * fname;
-sprintf(CS temp_name, "%s/input/%s/hdr.%d", spool_directory, message_subdir,
- (int)getpid());
-fd = spool_open_temp(temp_name);
-if (fd < 0) return spool_write_error(where, errmsg, US"open", NULL, NULL);
+tname = spool_fname(US"input", message_subdir,
+ string_sprintf("hdr.%d", (int)getpid()), US"");
+
+if ((fd = spool_open_temp(tname)) < 0)
+ return spool_write_error(where, errmsg, US"open", NULL, NULL);
f = fdopen(fd, "wb");
-DEBUG(D_receive|D_deliver) debug_printf("Writing spool header file\n");
+DEBUG(D_receive|D_deliver) debug_printf("Writing spool header file: %s\n", tname);
/* We now have an open file to which the header data is to be written. Start
with the file's leaf name, to make the file self-identifying. Continue with the
@@ -302,7 +303,7 @@ to get the actual size of the headers. */
fflush(f);
if (fstat(fd, &statbuf))
- return spool_write_error(where, errmsg, US"fstat", temp_name, f);
+ return spool_write_error(where, errmsg, US"fstat", tname, f);
size_correction = statbuf.st_size;
/* Finally, write out the message's headers. To make it easier to read them
@@ -323,29 +324,30 @@ for (h = header_list; h != NULL; h = h->next)
/* Flush and check for any errors while writing */
if (fflush(f) != 0 || ferror(f))
- return spool_write_error(where, errmsg, US"write", temp_name, f);
+ return spool_write_error(where, errmsg, US"write", tname, f);
/* Force the file's contents to be written to disk. Note that fflush()
just pushes it out of C, and fclose() doesn't guarantee to do the write
either. That's just the way Unix works... */
if (EXIMfsync(fileno(f)) < 0)
- return spool_write_error(where, errmsg, US"sync", temp_name, f);
+ return spool_write_error(where, errmsg, US"sync", tname, f);
/* Get the size of the file, and close it. */
if (fstat(fd, &statbuf) != 0)
- return spool_write_error(where, errmsg, US"fstat", temp_name, NULL);
+ return spool_write_error(where, errmsg, US"fstat", tname, NULL);
if (fclose(f) != 0)
- return spool_write_error(where, errmsg, US"close", temp_name, NULL);
+ return spool_write_error(where, errmsg, US"close", tname, NULL);
/* Rename the file to its correct name, thereby replacing any previous
incarnation. */
-sprintf(CS name, "%s/input/%s/%s-H", spool_directory, message_subdir, id);
+fname = spool_fname(US"input", message_subdir, id, US"-H");
+DEBUG(D_receive|D_deliver) debug_printf("Renaming spool header file: %s\n", fname);
-if (Urename(temp_name, name) < 0)
- return spool_write_error(where, errmsg, US"rename", temp_name, NULL);
+if (Urename(tname, fname) < 0)
+ return spool_write_error(where, errmsg, US"rename", tname, NULL);
/* Linux (and maybe other OS?) does not automatically sync a directory after
an operation like rename. We therefore have to do it forcibly ourselves in
@@ -359,20 +361,20 @@ these cases. One hack on top of another... but that's life. */
#ifdef NEED_SYNC_DIRECTORY
-sprintf(CS temp_name, "%s/input/%s/.", spool_directory, message_subdir);
+tname = spool_fname(US"input", message_subdir, US".", US"");
-#ifndef O_DIRECTORY
-#define O_DIRECTORY 0
-#endif
+# ifndef O_DIRECTORY
+# define O_DIRECTORY 0
+# endif
-if ((fd = Uopen(temp_name, O_RDONLY|O_DIRECTORY, 0)) < 0)
- return spool_write_error(where, errmsg, US"directory open", name, NULL);
+if ((fd = Uopen(tname, O_RDONLY|O_DIRECTORY, 0)) < 0)
+ return spool_write_error(where, errmsg, US"directory open", fname, NULL);
if (EXIMfsync(fd) < 0 && errno != EINVAL)
- return spool_write_error(where, errmsg, US"directory sync", name, NULL);
+ return spool_write_error(where, errmsg, US"directory sync", fname, NULL);
if (close(fd) < 0)
- return spool_write_error(where, errmsg, US"directory close", name, NULL);
+ return spool_write_error(where, errmsg, US"directory close", fname, NULL);
#endif /* NEED_SYNC_DIRECTORY */
@@ -413,13 +415,12 @@ static BOOL
make_link(uschar *dir, uschar *subdir, uschar *id, uschar *suffix, uschar *from,
uschar *to, BOOL noentok)
{
-uschar f[256], t[256];
-sprintf(CS f, "%s/%s%s/%s/%s%s", spool_directory, from, dir, subdir, id, suffix);
-sprintf(CS t, "%s/%s%s/%s/%s%s", spool_directory, to, dir, subdir, id, suffix);
-if (Ulink(f, t) < 0 && (!noentok || errno != ENOENT))
+uschar * fname = spool_fname(string_sprintf("%s%s", from, dir), subdir, id, suffix);
+uschar * tname = spool_fname(string_sprintf("%s%s", to, dir), subdir, id, suffix);
+if (Ulink(fname, tname) < 0 && (!noentok || errno != ENOENT))
{
log_write(0, LOG_MAIN|LOG_PANIC, "link(\"%s\", \"%s\") failed while moving "
- "message: %s", f, t, strerror(errno));
+ "message: %s", fname, tname, strerror(errno));
return FALSE;
}
return TRUE;
@@ -451,12 +452,11 @@ static BOOL
break_link(uschar *dir, uschar *subdir, uschar *id, uschar *suffix, uschar *from,
BOOL noentok)
{
-uschar f[256];
-sprintf(CS f, "%s/%s%s/%s/%s%s", spool_directory, from, dir, subdir, id, suffix);
-if (Uunlink(f) < 0 && (!noentok || errno != ENOENT))
+uschar * fname = spool_fname(string_sprintf("%s%s", from, dir), subdir, id, suffix);
+if (Uunlink(fname) < 0 && (!noentok || errno != ENOENT))
{
log_write(0, LOG_MAIN|LOG_PANIC, "unlink(\"%s\") failed while moving "
- "message: %s", f, strerror(errno));
+ "message: %s", fname, strerror(errno));
return FALSE;
}
return TRUE;
@@ -488,10 +488,12 @@ spool_move_message(uschar *id, uschar *subdir, uschar *from, uschar *to)
{
/* Create any output directories that do not exist. */
-sprintf(CS big_buffer, "%sinput/%s", to, subdir);
-(void)directory_make(spool_directory, big_buffer, INPUT_DIRECTORY_MODE, TRUE);
-sprintf(CS big_buffer, "%smsglog/%s", to, subdir);
-(void)directory_make(spool_directory, big_buffer, INPUT_DIRECTORY_MODE, TRUE);
+(void) directory_make(spool_directory,
+ spool_sname(string_sprintf("%sinput", to), subdir),
+ INPUT_DIRECTORY_MODE, TRUE);
+(void) directory_make(spool_directory,
+ spool_sname(string_sprintf("%smsglog", to), subdir),
+ INPUT_DIRECTORY_MODE, TRUE);
/* Move the message by first creating new hard links for all the files, and
then removing the old links. When moving messages onto the main spool, the -H
diff --git a/src/src/transport.c b/src/src/transport.c
index 86350ba9d..e1e6dcebf 100644
--- a/src/src/transport.c
+++ b/src/src/transport.c
@@ -1013,7 +1013,7 @@ dkim_transport_write_message(address_item *addr, int fd, int options,
int dkim_fd;
int save_errno = 0;
BOOL rc;
-uschar dkim_spool_name[256];
+uschar * dkim_spool_name;
char sbuf[2048];
int sread = 0;
int wwritten = 0;
@@ -1027,8 +1027,8 @@ if (!(dkim_private_key && dkim_domain && dkim_selector))
check_string, escape_string, rewrite_rules,
rewrite_existflags);
-(void)string_format(dkim_spool_name, 256, "%s/input/%s/%s-%d-K",
- spool_directory, message_subdir, message_id, (int)getpid());
+dkim_spool_name = spool_fname(US"input", message_subdir, message_id,
+ string_sprintf("-%d-K", (int)getpid()));
if ((dkim_fd = Uopen(dkim_spool_name, O_RDWR|O_CREAT|O_TRUNC, SPOOL_MODE)) < 0)
{
@@ -1655,8 +1655,6 @@ open_db *dbm_file;
uschar buffer[256];
int i;
-uschar spool_dir [PATH_MAX];
-uschar spool_file [PATH_MAX];
struct stat statbuf;
*more = FALSE;
@@ -1714,8 +1712,6 @@ emptied, delete it and continue with any continuation records that may exist.
but the 1 off will remain without it. This code now allows me to SKIP over
a message I do not want to send out on this run. */
-sprintf(CS spool_dir, "%s/input/", spool_directory);
-
host_length = host_record->count * MESSAGE_ID_LENGTH;
while (1)
@@ -1754,13 +1750,13 @@ while (1)
for (i = msgq_count - 1; i >= 0; --i) if (msgq[i].bKeep)
{
- if (split_spool_directory)
- sprintf(CS spool_file, "%s%c/%s-D",
- spool_dir, msgq[i].message_id[5], msgq[i].message_id);
- else
- sprintf(CS spool_file, "%s%s-D", spool_dir, msgq[i].message_id);
+ uschar subdir[2];
+
+ subdir[0] = split_spool_directory ? msgq[i].message_id[5] : 0;
+ subdir[1] = 0;
- if (Ustat(spool_file, &statbuf) != 0)
+ if (Ustat(spool_fname(US"input", subdir, msgq[i].message_id, US"-D"),
+ &statbuf) != 0)
msgq[i].bKeep = FALSE;
else if (!oicf_func || oicf_func(msgq[i].message_id, oicf_data))
{
@@ -1927,7 +1923,6 @@ if ((pid = fork()) == 0)
argv = CUSS child_exec_exim(CEE_RETURN_ARGV, TRUE, &i, FALSE, 0);
- /* Call with the dsn flag */
if (smtp_use_dsn) argv[i++] = US"-MCD";
if (smtp_authenticated) argv[i++] = US"-MCA";