23#define BUF_COMMANDS 1024
24#define BUFSIZE_MINI 128
27extern int spawn(
int,
int,
const char *,
char *,
const int);
28extern void report(buffer *,
int,
char *,
int);
50 while ((
pid = wait_nohang(&
wstat)) > 0)
66 if (w != -1)
return w;
67 if (errno == EINTR)
return -1;
88 buffer_put(&
bo,&ch,1);
90 buffer_putflush(&
bo,
"",1);
102 if (
flagabort) {
err(
"Zqmail-spawn: Out of memory. (#4.3.0)\n");
return; }
103 if (
delnum < 0) {
err(
"Zqmail-spawn: Internal error: delnum negative. (#4.3.5)\n");
return; }
104 if (
delnum >=
auto_spawn) {
err(
"Zqmail-spawn: Internal error: delnum too big. (#4.3.5)\n");
return; }
105 if (
d[
delnum].used) {
err(
"Zqmail-spawn: Internal error: delnum in use. (#4.3.5)\n");
return; }
107 for (i = 0; i <
messid.len; ++i)
109 if (!i || (
messid.s[i] !=
'/'))
110 if ((
unsigned char) (
messid.s[i] -
'0') > 9)
111 {
err(
"Dqmail-spawn: Internal error: messid has nonnumerics. (#5.3.5)\n");
return; }
113 if (
messid.len > 100) {
err(
"Dqmail-spawn: Internal error: messid too long. (#5.3.5)\n");
return; }
114 if (!
messid.s[0]) {
err(
"Dqmail-spawn: Internal error: messid too short. (#5.3.5)\n");
return; }
117 {
err(
"Zqmail-spawn: Out of memory. (#4.3.0)\n");
return; }
120 if (
j >=
recip.len) {
err(
"DSorry, address must include host name. (#5.1.3)\n");
return; }
122 fdmess = open_read(
messid.s);
123 if (fdmess == -1) {
err(
"Zqmail-spawn: Unable to open message. (#4.3.0)\n");
return; }
125 if (fstat(fdmess,&st) == -1)
126 { close(fdmess);
err(
"Zqmail-spawn: Unable to fstat message. (#4.3.0)\n");
return; }
127 if ((st.st_mode & S_IFMT) != S_IFREG)
128 { close(fdmess);
err(
"ZSorry, message has wrong type. (#4.3.5)\n");
return; }
131 { close(fdmess);
err(
"ZSorry, message has wrong owner. (#4.3.5)\n");
return; }
133 if (pipe(pi) == -1) {
134 if (errno == EFAULT)
err(
"Zqmail-spawn: Unable to create pipe (wrong fildes). (#4.3.0)\n");
135 else if (errno == EMFILE)
err(
"Zqmail-spawn: Unable to create pipe (too many FDS). (#4.3.0)\n");
136 else if (errno == ENFILE)
err(
"Zqmail-spawn: Unable to create pipe (system file table full). (#4.3.0)\n");
137 else if (errno == ENOMEM)
err(
"Zqmail-spawn: Unable to create pipe (out of memory). (#4.3.0)\n");
138 else err(
"Zqmail-spawn: Unable to create pipe (unkown reason). (#4.3.0)\n");
149 { close(pi[0]); close(pi[1]);
err(
"Zqmail-spawn: Unable to fork. (#4.3.0)\n");
return; }
174 for (i = 0; i < r; ++i) {
178 delnum = (
unsigned int) (
unsigned char) ch;
199int main(
int argc,
char *
const *argv)
208 if (chdir(
"queue/mess") == -1)
_exit(110);
224 buffer_putflush(&
bo,&ch,1);
242 FD_SET(
d[i].
fdin,&rfds);
243 if (
d[i].
fdin >= nfds)
244 nfds =
d[i].
fdin + 1;
247 r = select(nfds,&rfds,(fd_set *) 0,(fd_set *) 0,(
struct timeval *) 0);
252 if (FD_ISSET(0,&rfds))
getcmd();
256 if (FD_ISSET(
d[i].
fdin,&rfds)) {
262 buffer_put(&
bo,&ch,1);
264 buffer_put(&
bo,
"",1);
269 while (!stralloc_readyplus(&
d[i].
output,r))
275 char *truncmess =
"\nError report too long, sorry.\n";
277 stralloc_cats(&
d[i].
output,truncmess);
int stralloc_copys(stralloc *, char const *)
void initialize(int, char **)
int spawn(int, int, const char *, char *, const int)
char outbuf[BUFSIZE_LINE]
ssize_t okwrite(int fd, char *buf, int n)
void report(buffer *, int, char *, int)
char cmdbuf[BUF_COMMANDS]