Skip to content

Commit

Permalink
Suse's big concurrency patch.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Dec 12, 2009
1 parent 3fb0ea9 commit f2028f9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
4 changes: 2 additions & 2 deletions chkspawn.c
Expand Up @@ -22,8 +22,8 @@ void main()
_exit(1);
}

if (auto_spawn > 255) {
substdio_puts(subfderr,"Oops. You have set conf-spawn higher than 255.\n");
if (auto_spawn > 65000) {
substdio_puts(subfderr,"Oops. You have set conf-spawn higher than 65000.\n");
substdio_flush(subfderr);
_exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion conf-spawn
@@ -1,4 +1,4 @@
120
1000

This is a silent concurrency limit. You can't set it above 255. On some
systems you can't set it above 125. qmail will refuse to compile if the
Expand Down
27 changes: 18 additions & 9 deletions qmail-send.c
Expand Up @@ -262,6 +262,8 @@ char *recip;
while (!stralloc_copys(&comm_buf[c],"")) nomem();
ch = delnum;
while (!stralloc_append(&comm_buf[c],&ch)) nomem();
ch = delnum >> 8;
while (!stralloc_append(&comm_buf[c],&ch)) nomem();
fnmake_split(id);
while (!stralloc_cats(&comm_buf[c],fn.s)) nomem();
while (!stralloc_0(&comm_buf[c])) nomem();
Expand Down Expand Up @@ -906,41 +908,42 @@ int c;
dline[c].len = REPORTMAX;
/* qmail-lspawn and qmail-rspawn are responsible for keeping it short */
/* but from a security point of view, we don't trust rspawn */
if (!ch && (dline[c].len > 1))
if (!ch && (dline[c].len > 2))
{
delnum = (unsigned int) (unsigned char) dline[c].s[0];
delnum += (unsigned int) ((unsigned int) dline[c].s[1]) << 8;
if ((delnum < 0) || (delnum >= concurrency[c]) || !d[c][delnum].used)
log1("warning: internal error: delivery report out of range\n");
else
{
strnum3[fmt_ulong(strnum3,d[c][delnum].delid)] = 0;
if (dline[c].s[1] == 'Z')
if (dline[c].s[2] == 'Z')
if (jo[d[c][delnum].j].flagdying)
{
dline[c].s[1] = 'D';
dline[c].s[2] = 'D';
--dline[c].len;
while (!stralloc_cats(&dline[c],"I'm not going to try again; this message has been in the queue too long.\n")) nomem();
while (!stralloc_0(&dline[c])) nomem();
}
switch(dline[c].s[1])
switch(dline[c].s[2])
{
case 'K':
log3("delivery ",strnum3,": success: ");
logsafe(dline[c].s + 2);
logsafe(dline[c].s + 3);
log1("\n");
markdone(c,jo[d[c][delnum].j].id,d[c][delnum].mpos);
--jo[d[c][delnum].j].numtodo;
break;
case 'Z':
log3("delivery ",strnum3,": deferral: ");
logsafe(dline[c].s + 2);
logsafe(dline[c].s + 3);
log1("\n");
break;
case 'D':
log3("delivery ",strnum3,": failure: ");
logsafe(dline[c].s + 2);
logsafe(dline[c].s + 3);
log1("\n");
addbounce(jo[d[c][delnum].j].id,d[c][delnum].recip.s,dline[c].s + 2);
addbounce(jo[d[c][delnum].j].id,d[c][delnum].recip.s,dline[c].s + 3);
markdone(c,jo[d[c][delnum].j].id,d[c][delnum].mpos);
--jo[d[c][delnum].j].numtodo;
break;
Expand Down Expand Up @@ -1538,15 +1541,21 @@ void main()
numjobs = 0;
for (c = 0;c < CHANNELS;++c)
{
char ch;
char ch, ch1;
int u;
int r;
do
r = read(chanfdin[c],&ch,1);
while ((r == -1) && (errno == error_intr));
if (r < 1)
{ log1("alert: cannot start: hath the daemon spawn no fire?\n"); _exit(111); }
do
r = read(chanfdin[c],&ch1,1);
while ((r == -1) && (errno == error_intr));
if (r < 1)
{ log1("alert: cannot start: hath the daemon spawn no fire?\n"); _exit(111); }
u = (unsigned int) (unsigned char) ch;
u += (unsigned int) ((unsigned char) ch1) << 8;
if (concurrency[c] > u) concurrency[c] = u;
numjobs += concurrency[c];
}
Expand Down
22 changes: 14 additions & 8 deletions spawn.c
Expand Up @@ -64,7 +64,7 @@ int okwrite(fd,buf,n) int fd; char *buf; int n;
int flagreading = 1;
char outbuf[1024]; substdio ssout;

int stage = 0; /* reading 0:delnum 1:messid 2:sender 3:recip */
int stage = 0; /* reading 0:delnum 1:delnum2 2:messid 3:sender 4:recip */
int flagabort = 0; /* if 1, everything except delnum is garbage */
int delnum;
stralloc messid = {0};
Expand All @@ -74,6 +74,7 @@ stralloc recip = {0};
void err(s) char *s;
{
char ch; ch = delnum; substdio_put(&ssout,&ch,1);
ch = delnum >> 8; substdio_put(&ssout,&ch,1);
substdio_puts(&ssout,s); substdio_putflush(&ssout,"",1);
}

Expand Down Expand Up @@ -156,16 +157,19 @@ void getcmd()
{
case 0:
delnum = (unsigned int) (unsigned char) ch;
messid.len = 0; stage = 1; break;
stage = 1; break;
case 1:
delnum += (unsigned int) ((unsigned int) ch) << 8;
messid.len = 0; stage = 2; break;
case 2:
if (!stralloc_append(&messid,&ch)) flagabort = 1;
if (ch) break;
sender.len = 0; stage = 2; break;
case 2:
sender.len = 0; stage = 3; break;
case 3:
if (!stralloc_append(&sender,&ch)) flagabort = 1;
if (ch) break;
recip.len = 0; stage = 3; break;
case 3:
recip.len = 0; stage = 4; break;
case 4:
if (!stralloc_append(&recip,&ch)) flagabort = 1;
if (ch) break;
docmd();
Expand Down Expand Up @@ -202,7 +206,8 @@ char **argv;

initialize(argc,argv);

ch = auto_spawn; substdio_putflush(&ssout,&ch,1);
ch = auto_spawn; substdio_put(&ssout,&ch,1);
ch = auto_spawn >> 8; substdio_putflush(&ssout,&ch,1);

for (i = 0;i < auto_spawn;++i) { d[i].used = 0; d[i].output.s = 0; }

Expand Down Expand Up @@ -237,7 +242,8 @@ char **argv;
continue; /* read error on a readable pipe? be serious */
if (r == 0)
{
ch = i; substdio_put(&ssout,&ch,1);
char ch; ch = i; substdio_put(&ssout,&ch,1);
ch = i >> 8; substdio_put(&ssout,&ch,1);
report(&ssout,d[i].wstat,d[i].output.s,d[i].output.len);
substdio_put(&ssout,"",1);
substdio_flush(&ssout);
Expand Down

0 comments on commit f2028f9

Please sign in to comment.