diff options
Diffstat (limited to 'src/qmail-todo.c')
-rw-r--r-- | src/qmail-todo.c | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/src/qmail-todo.c b/src/qmail-todo.c index 0abb10e..09a5006 100644 --- a/src/qmail-todo.c +++ b/src/qmail-todo.c @@ -3,6 +3,7 @@ #include <unistd.h> #include "alloc.h" #include "auto_qmail.h" +#include "auto_queue.h" #include "byte.h" #include "constmap.h" #include "control.h" @@ -27,6 +28,8 @@ #include "sendtodo.h" #include "qmail.h" +stralloc queuedir = {0}; + stralloc percenthack = {0}; struct constmap mappercenthack; stralloc locals = {0}; @@ -202,7 +205,7 @@ int comm_canwrite(void) return 0; } -void comm_write(unsigned long id, int local, int remote) +void comm_write(unsigned long id,int local,int remote) { int pos; char *s; @@ -225,7 +228,7 @@ void comm_write(unsigned long id, int local, int remote) comm_buf.len = pos; } -void comm_info(unsigned long id, unsigned long size, char* from, unsigned long pid, unsigned long uid) +void comm_info(unsigned long id,unsigned long size,char* from,unsigned long pid,unsigned long uid) { int pos; int i; @@ -400,26 +403,26 @@ void todo_do(fd_set *rfds) fnmake_todo(id); fd = open_read(fn.s); - if (fd == -1) { sendlog3("warning: qmail-todo: unable to open ",fn.s,"\n"); return; } + if (fd == -1) { sendlog3("warning: qmail-todo is unable to open ",fn.s,"\n"); return; } fnmake_mess(id); /* just for the statistics */ if (stat(fn.s,&st) == -1) - { sendlog3("warning: qmail-todo: unable to stat ",fn.s," for mess\n"); goto FAIL; } + { sendlog3("warning: qmail-todo is unable to stat ",fn.s," for mess\n"); goto FAIL; } for (c = 0; c < CHANNELS; ++c) { fnmake_chanaddr(id,c); if (unlink(fn.s) == -1) if (errno != ENOENT) - { sendlog3("warning: qmail-todo: unable to unlink ",fn.s," for mess\n"); goto FAIL; } + { sendlog3("warning: qmail-todo is unable to unlink ",fn.s," for mess\n"); goto FAIL; } } fnmake_info(id); if (unlink(fn.s) == -1) if (errno != ENOENT) - { sendlog3("warning: qmail-todo: unable to unlink ",fn.s," for info\n"); goto FAIL; } + { sendlog3("warning: qmail-todo is unable to unlink ",fn.s," for info\n"); goto FAIL; } fdnumber = open_excl(fn.s); if (fdnumber == -1) - { sendlog3("warning: qmail-todo: unable to create ",fn.s," for info\n"); goto FAIL; } + { sendlog3("warning: qmail-todo unable to create ",fn.s," for info\n"); goto FAIL; } strnum[fmt_ulong(strnum,id)] = 0; sendlog3("new msg ",strnum,"\n"); @@ -437,7 +440,7 @@ void todo_do(fd_set *rfds) if (getln(&bi,&todoline,&match,'\0') == -1) { /* perhaps we're out of memory, perhaps an I/O error */ fnmake_todo(id); - sendlog3("warning: qmail-todo: trouble reading ",fn.s,"\n"); goto FAIL; + sendlog3("warning: qmail-todo has trouble reading ",fn.s,"\n"); goto FAIL; } if (!match) break; @@ -449,7 +452,7 @@ void todo_do(fd_set *rfds) case 'F': if (buffer_putflush(&bo,todoline.s,todoline.len) == -1) { fnmake_info(id); - sendlog3("warning: qmail-todo: trouble writing to ",fn.s," for todo\n"); goto FAIL; + sendlog3("warning: qmail-todo has trouble writing to ",fn.s," for todo\n"); goto FAIL; } comm_info(id,(unsigned long) st.st_size,todoline.s + 1,pid,uid); break; @@ -463,18 +466,18 @@ void todo_do(fd_set *rfds) fnmake_chanaddr(id,c); fdchan[c] = open_excl(fn.s); if (fdchan[c] == -1) - { sendlog3("warning: qmail-todo: unable to create ",fn.s," for delivery\n"); goto FAIL; } + { sendlog3("warning: qmail-todo is unable to create ",fn.s," for delivery\n"); goto FAIL; } buffer_init(&bchan[c],write,fdchan[c],todobufchan[c],sizeof(todobufchan[c])); flagchan[c] = 1; } if (buffer_put(&bchan[c],rwline.s,rwline.len) == -1) { fnmake_chanaddr(id,c); - sendlog3("warning: qmail-todo: trouble writing to ",fn.s," for delivery\n"); goto FAIL; + sendlog3("warning: qmail-todo has trouble writing to ",fn.s," for delivery\n"); goto FAIL; } break; default: fnmake_todo(id); - sendlog3("warning: qmail-todo: unknown record type in ",fn.s,"\n"); goto FAIL; + sendlog3("warning: qmail-todo recognizes unknown record type in ",fn.s,"\n"); goto FAIL; } } @@ -482,16 +485,16 @@ void todo_do(fd_set *rfds) fnmake_info(id); if (buffer_flush(&bo) == -1) - { sendlog3("warning: qmail-todo: trouble writing to ",fn.s," for info\n"); goto FAIL; } + { sendlog3("warning: qmail-todo has trouble writing to ",fn.s," for info\n"); goto FAIL; } if (fsync(fdnumber) == -1) - { sendlog3("warning: qmail-todo: trouble fsyncing ",fn.s," for info\n"); goto FAIL; } + { sendlog3("warning: qmail-todo has trouble fsyncing ",fn.s," for info\n"); goto FAIL; } close(fdnumber); fdnumber = -1; for (c = 0; c < CHANNELS; ++c) if (fdchan[c] != -1) { fnmake_chanaddr(id,c); - if (buffer_flush(&bchan[c]) == -1) { sendlog3("warning: qmail-todo: trouble writing to ",fn.s," in channel\n"); goto FAIL; } - if (fsync(fdchan[c]) == -1) { sendlog3("warning: qmail-todo: trouble fsyncing ",fn.s," in channel\n"); goto FAIL; } + if (buffer_flush(&bchan[c]) == -1) { sendlog3("warning: qmail-todo has trouble writing to ",fn.s," in channel\n"); goto FAIL; } + if (fsync(fdchan[c]) == -1) { sendlog3("warning: qmail-todo has trouble fsyncing ",fn.s," in channel\n"); goto FAIL; } close(fdchan[c]); fdchan[c] = -1; } @@ -543,10 +546,10 @@ void regetcontrols(void) int r; if (control_readfile(&newlocals,"control/locals",1) != 1) - { sendlog1("alert: qmail-todo: unable to reread control/locals\n"); return; } + { sendlog1("alert: qmail-todo is unable to reread control/locals\n"); return; } r = control_readfile(&newvdoms,"control/virtualdomains",0); if (r == -1) - { sendlog1("alert: qmail-todo: unable to reread control/virtualdomains\n"); return; } + { sendlog1("alert: qmail-todo is unable to reread control/virtualdomains\n"); return; } constmap_free(&maplocals); constmap_free(&mapvdoms); @@ -565,13 +568,14 @@ void regetcontrols(void) void reread(void) { if (chdir(auto_qmail) == -1) { - sendlog1("alert: qmail-todo: unable to reread controls: unable to switch to home directory\n"); + sendlog1("alert: qmail-todo is unable to reread controls: unable to switch to home directory\n"); return; } regetcontrols(); - while (chdir("queue") == -1) { - sendlog1("alert: qmail-todo: unable to switch back to queue directory; HELP! sleeping...\n"); + + while (chdir(queuedir.s) == -1) { + sendlog1("alert: qmail-todo is unable to switch back to queue directory; HELP! sleeping...\n"); sleep(10); } } @@ -586,12 +590,16 @@ int main() int r; char c; + 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) - { sendlog1("alert: qmail-todo: cannot start: unable to switch to home directory\n"); _exit(110); } + { sendlog1("alert: qmail-todo cannot start and switch to home directory\n"); _exit(110); } if (!getcontrols()) - { sendlog1("alert: qmail-todo: cannot start: unable to read controls\n"); _exit(112); } - if (chdir("queue") == -1) - { sendlog1("alert: qmail-todo: cannot start: unable to switch to queue directory\n"); _exit(110); } + { sendlog1("alert: qmail-todo cannot start and read controls\n"); _exit(112); } + if (chdir(queuedir.s) == -1) + { sendlog1("alert: qmail-todo cannot start and switch to queue directory\n"); _exit(110); } sig_pipeignore(); umask(077); @@ -631,7 +639,7 @@ int main() if (errno == EINTR) ; else - sendlog1("warning: qmail-todo: trouble in select\n"); + sendlog1("warning: qmail-todo has trouble in select\n"); else { recent = now(); |