46#define BUF_CHANNELS 1024
58 sendlog1(
"status: qmail-todo stop processing asap\n");
67 sendlog1(
"alert: qmail-todo lost connection to qmail-clean ... exiting\n");
99 static stralloc
addr = {0};
107 if (!stralloc_cats(&
addr,
"@"))
return 0;
112 j = byte_rchr(
addr.s,i,
'%');
119 at = byte_rchr(
addr.s,
addr.len,
'@');
123 if (!stralloc_0(&
rwline))
return 0;
127 for (i = 0; i <=
addr.len; ++i)
128 if (!i || (i == at + 1) || (i ==
addr.len) || ((i > at) && (
addr.s[i] ==
'.')))
131 if (!stralloc_cats(&
rwline,x))
return 0;
132 if (!stralloc_cats(&
rwline,
"-"))
return 0;
134 if (!stralloc_0(&
rwline))
return 0;
139 if (!stralloc_0(&
rwline))
return 0;
159 if (!stralloc_cats(&
comm_buf,
"L"))
goto FAIL;
160 if (!stralloc_cats(&
comm_buf,x))
goto FAIL;
161 if (!stralloc_0(&
comm_buf))
goto FAIL;
174 if (!stralloc_cats(&
comm_buf,
"L"))
goto FAIL;
175 if (!stralloc_cats(&
comm_buf,x))
goto FAIL;
176 if (!stralloc_cats(&
comm_buf,y))
goto FAIL;
177 if (!stralloc_cats(&
comm_buf,
z))
goto FAIL;
178 if (!stralloc_0(&
comm_buf))
goto FAIL;
193 if (ndelay_on(
fdout) == -1)
215 else if (
local) s=
"L";
221 if (!stralloc_cats(&
comm_buf,
"D"))
goto FAIL;
222 if (!stralloc_cats(&
comm_buf,s))
goto FAIL;
224 if (!stralloc_0(&
comm_buf))
goto FAIL;
232void comm_info(
unsigned long id,
unsigned long size,
char* from,
unsigned long pid,
unsigned long uid)
238 if (!stralloc_cats(&
comm_buf,
"Linfo msg "))
goto FAIL;
241 if (!stralloc_cats(&
comm_buf,
": bytes "))
goto FAIL;
244 if (!stralloc_cats(&
comm_buf,
" from <"))
goto FAIL;
246 if (!stralloc_cats(&
comm_buf,from))
goto FAIL;
255 if (!stralloc_cats(&
comm_buf,
"> qp "))
goto FAIL;
258 if (!stralloc_cats(&
comm_buf,
" uid "))
goto FAIL;
261 if (!stralloc_cats(&
comm_buf,
"\n"))
goto FAIL;
262 if (!stralloc_0(&
comm_buf))
goto FAIL;
298 if (FD_ISSET(
fdout,wfds)) {
304 if ((w == -1) && (errno == EPIPE))
315 if (FD_ISSET(
fdin,rfds)) {
319 r = read(
fdin, &
c, 1);
321 if ((r == -1) && (errno != EINTR))
332 sendlog1(
"warning: qmail-todo: qmail-send speaks an obscure dialect\n");
406 fd = open_read(
fn.s);
408 {
sendlog3(
"warning: qmail-todo is unable to open ",
fn.s,
"\n");
return; }
412 if (stat(
fn.s,&st) == -1)
413 {
sendlog3(
"warning: qmail-todo is unable to stat ",
fn.s,
" for mess\n");
goto FAIL; }
417 if (unlink(
fn.s) == -1)
if (errno != ENOENT)
418 {
sendlog3(
"warning: qmail-todo is unable to unlink ",
fn.s,
" for mess\n");
goto FAIL; }
422 if (unlink(
fn.s) == -1)
if (errno != ENOENT)
423 {
sendlog3(
"warning: qmail-todo is unable to unlink ",
fn.s,
" for info\n");
goto FAIL; }
425 fdnumber = open_excl(
fn.s);
427 {
sendlog3(
"warning: qmail-todo unable to create ",
fn.s,
" for info\n");
goto FAIL; }
445 sendlog3(
"warning: qmail-todo has trouble reading ",
fn.s,
"\n");
goto FAIL;
453 scan_ulong(
todoline.s + 1,&pid);
break;
457 sendlog3(
"warning: qmail-todo has trouble writing to ",
fn.s,
" for todo\n");
goto FAIL;
463 case 0:
nomem();
goto FAIL;
464 case 2:
c = 1;
break;
465 default:
c = 0;
break;
467 if (fdchan[
c] == -1) {
469 fdchan[
c] = open_excl(
fn.s);
471 {
sendlog3(
"warning: qmail-todo is unable to create ",
fn.s,
" for delivery\n");
goto FAIL; }
477 sendlog3(
"warning: qmail-todo has trouble writing to ",
fn.s,
" for delivery\n");
goto FAIL;
482 sendlog3(
"warning: qmail-todo recognizes unknown record type in ",
fn.s,
"\n");
goto FAIL;
489 if (buffer_flush(&
bo) == -1)
490 {
sendlog3(
"warning: qmail-todo has trouble writing to ",
fn.s,
" for info\n");
goto FAIL; }
491 if (fsync(fdnumber) == -1)
492 {
sendlog3(
"warning: qmail-todo has trouble fsyncing ",
fn.s,
" for info\n");
goto FAIL; }
493 close(fdnumber); fdnumber = -1;
496 if (fdchan[
c] != -1) {
498 if (buffer_flush(&bchan[
c]) == -1)
499 {
sendlog3(
"warning: qmail-todo has trouble writing to ",
fn.s,
" in channel\n");
goto FAIL; }
500 if (fsync(fdchan[
c]) == -1)
501 {
sendlog3(
"warning: qmail-todo has trouble fsyncing ",
fn.s,
" in channel\n");
goto FAIL; }
502 close(fdchan[
c]); fdchan[
c] = -1;
510 sendlog3(
"warning: qmail-clean unable to clean up ",
fn.s,
"\n");
518 if (
fd != -1) close(
fd);
519 if (fdnumber != -1) close(fdnumber);
521 if (fdchan[
c] != -1) close(fdchan[
c]);
553 {
sendlog1(
"alert: qmail-todo is unable to reread control/locals\n");
return; }
557 {
sendlog1(
"alert: qmail-todo is unable to reread control/virtualdomains\n");
return; }
576 sendlog1(
"alert: qmail-todo is unable to reread controls: unable to switch to home directory\n");
583 sendlog1(
"alert: qmail-todo is unable to switch back to queue directory; HELP! sleeping...\n");
603 {
sendlog1(
"alert: qmail-todo cannot start and switch to home directory\n");
_exit(110); }
605 {
sendlog1(
"alert: qmail-todo cannot start and read controls\n");
_exit(112); }
607 {
sendlog1(
"alert: qmail-todo cannot start and switch to queue directory\n");
_exit(110); }
616 r = read(
fdin, &
c, 1);
617 if ((r == -1) && (errno != EINTR))
639 if (wakeup <=
recent) tv.tv_sec = 0;
643 if (select(nfds,&rfds,&wfds,(fd_set *) 0,&tv) == -1)
647 sendlog1(
"warning: qmail-todo has trouble in select\n");
void constmap_free(struct constmap *cm)
int constmap_init(struct constmap *cm, char *s, int len, int flagcolon)
int control_rldef(stralloc *sa, char *fn, int flagme, char *def)
int control_readfile(stralloc *sa, char *fn, int flagme)
int stralloc_copys(stralloc *, char const *)
unsigned int fmtqfn(char *s, char *dirslash, unsigned long id, int flagsplit)
void z(char *, char *, int, int, int, int)
void c(char *, char *, char *, int, int, int)
char todobufinfo[BUFSIZE_OUT]
char todobufchan[CHANNELS][BUF_CHANNELS]
void fnmake_todo(unsigned long id)
void fnmake_info(unsigned long id)
char * chanaddr[CHANNELS]
char todobuf[BUFSIZE_MESS]
void comm_write(unsigned long id, int local, int remote)
char toqcbuf[BUFSIZE_LINE]
char fromqcbuf[BUFSIZE_LINE]
struct constmap mappercenthack
void fnmake_mess(unsigned long id)
void todo_do(fd_set *rfds)
void comm_do(fd_set *wfds, fd_set *rfds)
void todo_selprep(int *nfds, fd_set *rfds, datetime_sec *wakeup)
void comm_info(unsigned long id, unsigned long size, char *from, unsigned long pid, unsigned long uid)
struct constmap maplocals
void fnmake_chanaddr(unsigned long id, int c)
void comm_selprep(int *nfds, fd_set *wfds, fd_set *rfds)
void sendlog3(char *x, char *y, char *z)
void readsubdir_init(readsubdir *, char *, void(*)())
int readsubdir_next(readsubdir *, unsigned long *)
void trigger_selprep(int *, fd_set *)
int trigger_pulled(fd_set *)