summaryrefslogtreecommitdiff
path: root/src/qmail-send.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-18 15:15:18 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-18 15:15:18 +0200
commit7b4d3ab22988d021d5f12b81aec746f7e486fa52 (patch)
tree651e78e316411a39baadadb1cfaca450e1351c7f /src/qmail-send.c
parent25f74781424d5e13f0211c08cce8c2a1d60b9aec (diff)
update to 4.3.09
Diffstat (limited to 'src/qmail-send.c')
-rw-r--r--src/qmail-send.c101
1 files changed, 54 insertions, 47 deletions
diff --git a/src/qmail-send.c b/src/qmail-send.c
index 026161f..e8b9de6 100644
--- a/src/qmail-send.c
+++ b/src/qmail-send.c
@@ -26,6 +26,7 @@
#include "scan.h"
#include "case.h"
#include "auto_qmail.h"
+#include "auto_queue.h"
#include "trigger.h"
#include "newfield.h"
#include "quote.h"
@@ -40,6 +41,8 @@
int lifetime = 604800;
int bouncemaxbytes = 0;
+stralloc queuedir = {0};
+
stralloc percenthack = {0};
struct constmap mappercenthack;
stralloc locals = {0};
@@ -69,7 +72,7 @@ int flagreadasap = 0; void sighup() { flagreadasap = 1; }
void cleandied()
{
- log1s("alert: lost connection to qmail-clean ... exiting\n");
+ log1s("alert: qmail-send lost connection to qmail-clean ... exiting\n");
flagexitasap = 1;
}
@@ -77,7 +80,7 @@ int flagspawnalive[CHANNELS];
void spawndied(int c)
{
- log1s("alert: oh no! lost spawn connection! dying...\n");
+ log1s("alert: oh no! qmail-send lost spawn connection! dying...\n");
flagspawnalive[c] = 0;
flagexitasap = 1;
}
@@ -302,7 +305,7 @@ void cleanup_do()
if (buffer_putflush(&toqc,fn.s,fn.len) == -1) { cleandied(); return; }
if (buffer_get(&fromqc,&ch,1) != 1) { cleandied(); return; }
if (ch != '+')
- log3s("warning: qmail-clean unable to clean up ",fn.s,"\n");
+ log3s("warning: qmail-clean is unable to clean up ",fn.s,"\n");
}
@@ -355,7 +358,7 @@ void pqadd(unsigned long id)
return;
FAIL:
- log3s("warning: unable to stat ",fn.s,"; will try again later\n");
+ log3s("warning: qmail-send send is unable to stat ",fn.s,"; will try again later\n");
pe.id = id; pe.dt = now() + SLEEP_SYSFAIL;
while (!prioq_insert(&pqfail,&pe)) nomem();
}
@@ -384,7 +387,7 @@ void pqfinish()
fnmake_chanaddr(pe.id,c);
ut[0] = ut[1] = pe.dt;
if (utime(fn.s,ut) == -1)
- log3s("warning: unable to utime ",fn.s,"; message will be retried too soon\n");
+ log3s("warning: qmail-send is unable to utime ",fn.s,"; message will be retried too soon\n");
}
}
@@ -467,16 +470,16 @@ void job_close(int j)
if (jo[j].flaghiteof && !jo[j].numtodo) {
fnmake_chanaddr(jo[j].id,jo[j].channel);
if (unlink(fn.s) == -1) {
- log3s("warning: unable to unlink ",fn.s,"; will try again later\n");
+ log3s("warning: qmail-send is unable to unlink ",fn.s,"; will try again later\n");
pe.dt = now() + SLEEP_SYSFAIL;
} else {
for (c = 0; c < CHANNELS; ++c) if (c != jo[j].channel) {
fnmake_chanaddr(jo[j].id,c);
if (stat(fn.s,&st) == 0) return; /* more channels going */
if (errno != ENOENT) {
- log3s("warning: unable to stat ",fn.s,"\n");
- break; /* this is the only reason for HOPEFULLY */
- }
+ log3s("warning: qmail-send is unable to stat ",fn.s,"\n");
+ break; /* this is the only reason for HOPEFULLY */
+ }
}
pe.dt = now();
while (!prioq_insert(&pqdone,&pe)) nomem();
@@ -548,7 +551,7 @@ void addbounce(unsigned long id,char *recip,char *report)
for (;;) {
fd = open_append(fn2.s);
if (fd != -1) break;
- log1s("alert: unable to append to bounce message; HELP! sleeping...\n");
+ log1s("alert: qmail-send is unable to append to bounce message; HELP! sleeping...\n");
sleep(10);
}
@@ -557,7 +560,7 @@ void addbounce(unsigned long id,char *recip,char *report)
while (pos < bouncetext.len) {
w = write(fd,bouncetext.s + pos,bouncetext.len - pos);
if (w <= 0) {
- log1s("alert: unable to append to bounce message; HELP! sleeping...\n");
+ log1s("alert: qmail-send is unable to append to bounce message; HELP! sleeping...\n");
sleep(10);
}
else
@@ -598,7 +601,7 @@ int injectbounce(unsigned long id)
if (stat(fn2.s,&st) == -1) {
if (errno == ENOENT) return 1;
- log3s("warning: unable to stat ",fn2.s,"\n");
+ log3s("warning: qmail-send is unable to stat ",fn2.s,"\n");
return 0;
}
@@ -608,7 +611,7 @@ int injectbounce(unsigned long id)
log3s("double bounce: discarding ",fn2.s,"\n");
else {
if (qmail_open(&qqt) == -1)
- { log1s("warning: unable to start qmail-queue, will try later\n"); return 0; }
+ { log1s("warning: qmail-send is unable to start qmail-queue, will try later\n"); return 0; }
qp = qmail_qp(&qqt);
if (*sender.s) { bouncesender = ""; bouncerecip = sender.s; }
@@ -673,21 +676,21 @@ I tried to deliver a bounce message to this address, but the bounce bounced!\n\
}
if (r > 0)
qmail_puts(&qqt,"\n\n--- Rest of message truncated.\n");
- } else { /* preserve default behavior */
+ } else { /* preserve default behavior */
buffer_init(&bi,read,fd,inbuf,sizeof(inbuf));
while ((r = buffer_get(&bi,buf,sizeof(buf))) > 0)
qmail_put(&qqt,buf,r);
- }
- close(fd);
- if (r == -1) qmail_fail(&qqt);
+ }
+ close(fd);
+ if (r == -1) qmail_fail(&qqt);
}
qmail_from(&qqt,bouncesender);
qmail_to(&qqt,bouncerecip);
if (*qmail_close(&qqt)) {
- log1s("warning: trouble injecting bounce message, will try later\n");
+ log1s("warning: qmail-send has trouble injecting bounce message, will try later\n");
return 0;
}
@@ -698,7 +701,7 @@ I tried to deliver a bounce message to this address, but the bounce bounced!\n\
}
if (unlink(fn2.s) != 0) {
- log3s("warning: unable to unlink ",fn2.s,"\n");
+ log3s("warning: qmail-send is unable to unlink ",fn2.s,"\n");
return 0;
}
@@ -819,7 +822,7 @@ void markdone(int c,unsigned long id,seek_pos pos)
close(fd);
return;
}
- log3s("warning: trouble marking ",fn.s,"; message will be delivered twice!\n");
+ log3s("warning: qmail-send has trouble marking ",fn.s,"; message will be delivered twice!\n");
}
void del_dochan(int c)
@@ -845,7 +848,7 @@ void del_dochan(int c)
if (!ch && (dline[c].len > 1)) {
delnum = (unsigned int) (unsigned char) dline[c].s[0];
if ((delnum < 0) || (delnum >= concurrency[c]) || !d[c][delnum].used)
- log1s("warning: internal error: delivery report out of range\n");
+ log1s("warning: qmail-send's internal error: delivery report out of range\n");
else {
strnum3[fmt_ulong(strnum3,d[c][delnum].delid)] = 0;
if (dline[c].s[1] == 'Z')
@@ -1017,7 +1020,7 @@ void pass_dochan(int c)
if (getln(&pass[c].b,&line,&match,'\0') == -1) {
fnmake_chanaddr(pass[c].id,c);
- log3s("warning: trouble reading ",fn.s,"; will try again later\n");
+ log3s("warning: qmail-send has trouble reading ",fn.s,"; will try again later\n");
close(pass[c].fd);
job_close(pass[c].j);
pass[c].id = 0;
@@ -1041,7 +1044,7 @@ void pass_dochan(int c)
break;
default:
fnmake_chanaddr(pass[c].id,c);
- log3s("warning: unknown record type in ",fn.s,"!\n");
+ log3s("warning: qmail-send recognizes unknown record type in ",fn.s,"!\n");
close(pass[c].fd);
job_close(pass[c].j);
pass[c].id = 0;
@@ -1052,7 +1055,7 @@ void pass_dochan(int c)
return;
trouble:
- log3s("warning: trouble opening ",fn.s,"; will try again later\n");
+ log3s("warning: qmail-send has trouble opening ",fn.s,"; will try again later\n");
pe.dt = recent + SLEEP_SYSFAIL;
while (!prioq_insert(&pqchan[c],&pe)) nomem();
}
@@ -1068,7 +1071,7 @@ void messdone(unsigned long id)
fnmake_chanaddr(id,c);
if (stat(fn.s,&st) == 0) return; /* false alarm; consequence of HOPEFULLY */
if (errno != ENOENT) {
- log3s("warning: unable to stat ",fn.s,"; will try again later\n");
+ log3s("warning: qmail-send is unable to stat ",fn.s,"; will try again later\n");
goto FAIL;
}
}
@@ -1076,14 +1079,14 @@ void messdone(unsigned long id)
fnmake_todo(id);
if (stat(fn.s,&st) == 0) return;
if (errno != ENOENT) {
- log3s("warning: unable to stat ",fn.s,"; will try again later\n");
+ log3s("warning: qmail-send is unable to stat ",fn.s,"; will try again later\n");
goto FAIL;
}
fnmake_info(id);
if (stat(fn.s,&st) == -1) {
if (errno == ENOENT) return;
- log3s("warning: unable to stat ",fn.s,"; will try again later\n");
+ log3s("warning: qmail-send is unable to stat ",fn.s,"; will try again later\n");
goto FAIL;
}
@@ -1097,7 +1100,7 @@ void messdone(unsigned long id)
/* -todo +info -local -remote -bounce */
fnmake_info(id);
if (unlink(fn.s) == -1) {
- log3s("warning: unable to unlink ",fn.s,"; will try again later\n");
+ log3s("warning: qmail-send is unable to unlink ",fn.s,"; will try again later\n");
goto FAIL;
}
@@ -1145,7 +1148,7 @@ int todofdout;
int flagtodoalive;
void tododied() {
- log1s("alert: lost connection to qmail-todo ... exiting\n");
+ log1s("alert: qmail-send lost connection to qmail-todo ... exiting\n");
flagexitasap = 1;
flagtodoalive = 0;
}
@@ -1200,13 +1203,13 @@ void todo_del(char* s)
case 'X':
break;
default:
- log1s("warning: qmail-send unable to understand qmail-todo\n");
+ log1s("warning: qmail-send is unable to understand qmail-todo\n");
return;
}
len = scan_ulong(s,&id);
if (!len || s[len]) {
- log1s("warning: qmail-send unable to understand qmail-todo\n");
+ log1s("warning: qmail-send is unable to understand qmail-todo\n");
return;
}
@@ -1265,7 +1268,7 @@ void todo_do(fd_set *rfds)
tododied();
break;
default:
- log1s("warning: qmail-send unable to understand qmail-todo: report mangled\n");
+ log1s("warning: qmail-send is unable to understand qmail-todo: report mangled\n");
break;
}
todoline.len = 0;
@@ -1312,13 +1315,13 @@ void regetcontrols()
{
int r;
- if (control_readfile(&newlocals,"control/locals",1) != 1) { log1s("alert: unable to reread control/locals\n"); return; }
- if (control_readint(&concurrency[0],"control/concurrencylocal") == -1) { log1s("alert: unable to reread control/concurrencylocal\n"); return; }
- if (control_readint(&concurrency[1],"control/concurrencyremote") == -1) { log1s("alert: unable to reread control/concurrencyremote\n"); return; }
- if (control_readint(&lifetime,"control/queuelifetime") == -1) { log1s("alert: unable to reread control/queuelifetime\n"); return; }
+ if (control_readfile(&newlocals,"control/locals",1) != 1) { log1s("alert: qmail-send is unable to reread control/locals\n"); return; }
+ if (control_readint(&concurrency[0],"control/concurrencylocal") == -1) { log1s("alert: qmail-send is unable to reread control/concurrencylocal\n"); return; }
+ if (control_readint(&concurrency[1],"control/concurrencyremote") == -1) { log1s("alert: qmail-send is unable to reread control/concurrencyremote\n"); return; }
+ if (control_readint(&lifetime,"control/queuelifetime") == -1) { log1s("alert: qmail-send is unable to reread control/queuelifetime\n"); return; }
r = control_readfile(&newvdoms,"control/virtualdomains",0);
- if (r == -1) { log1s("alert: unable to reread control/virtualdomains\n"); return; }
+ if (r == -1) { log1s("alert: qmail-send is unable to reread control/virtualdomains\n"); return; }
constmap_free(&maplocals);
constmap_free(&mapvdoms);
@@ -1336,14 +1339,14 @@ void regetcontrols()
void reread()
{
if (chdir(auto_qmail) == -1) {
- log1s("alert: unable to reread controls: unable to switch to home directory\n");
+ log1s("alert: qmail-send is unable to reread controls: unable to switch to home directory\n");
return;
}
write(todofdout,"H",1);
regetcontrols();
- while (chdir("queue") == -1) {
- log1s("alert: unable to switch back to queue directory; HELP! sleeping...\n");
+ while (chdir(queuedir.s) == -1) {
+ log1s("alert: qmail-send is unable to switch back to queue directory; HELP! sleeping...\n");
sleep(10);
}
}
@@ -1360,10 +1363,14 @@ int main()
int u;
int r;
char ch;
+
+ if (!stralloc_copys(&queuedir,auto_queue)) _exit(110);
+ if (!stralloc_cats(&queuedir,"/queue")) _exit(110);
+ if (!stralloc_0(&queuedir)) _exit(110);
- if (chdir(auto_qmail) == -1) { log1s("alert: cannot start: unable to switch to home directory\n"); _exit(110); }
- if (!getcontrols()) { log1s("alert: cannot start: unable to read controls\n"); _exit(111); }
- if (chdir("queue") == -1) { log1s("alert: cannot start: unable to switch to queue directory\n"); _exit(110); }
+ if (chdir(auto_qmail) == -1) { log3s("alert: qmail-send is unable to switch to home directory ",auto_qmail,"\n"); _exit(110); }
+ if (!getcontrols()) { log1s("alert: qmail-send is unable to read controls\n"); _exit(111); }
+ if (chdir(queuedir.s) == -1) { log3s("alert: qmail-send cannot start and is unable to switch to queue directory ",queuedir.s,"\n"); _exit(110); }
sig_pipeignore();
sig_termcatch(sigterm);
sig_alarmcatch(sigalrm);
@@ -1372,8 +1379,8 @@ int main()
umask(077);
fd = open_write("lock/sendmutex");
- if (fd == -1) { log1s("alert: cannot start: unable to open mutex\n"); _exit(111); }
- if (lock_exnb(fd) == -1) { log1s("alert: cannot start: qmail-send is already running\n"); _exit(111); }
+ if (fd == -1) { log1s("alert: qmail-send is unable to open mutex\n"); _exit(111); }
+ if (lock_exnb(fd) == -1) { log1s("alert: qmail-send is already running\n"); _exit(111); }
numjobs = 0;
for (c = 0;c < CHANNELS;++c) {
@@ -1424,7 +1431,7 @@ int main()
if (errno == EINTR)
;
else
- log1s("warning: trouble in select\n");
+ log1s("warning: qmail-send has trouble in select\n");
else {
recent = now();
@@ -1437,6 +1444,6 @@ int main()
}
pqfinish();
- log1s("status: exiting\n");
+ log1s("status: qmail-send exiting\n");
_exit(0);
}