mothra: fix "bad ctl message" bug caused by fprint write buffer limit on long urls

front
cinap_lenrek 2012-06-07 02:12:04 +02:00
parent 049855460c
commit baea7ec1e2
1 changed files with 9 additions and 6 deletions

View File

@ -45,7 +45,7 @@ char *mtpt="/mnt/web";
static int
webclone(Url *url, char *buf, int nbuf)
{
int n, fd;
int n, conn, fd;
snprint(buf, nbuf, "%s/clone", mtpt);
if((fd = open(buf, ORDWR)) < 0)
@ -55,16 +55,19 @@ webclone(Url *url, char *buf, int nbuf)
return -1;
}
buf[n] = 0;
n = atoi(buf);
snprint(buf, nbuf, "%s/%d", mtpt, n);
conn = atoi(buf);
if(url && url->reltext[0]){
if(url->basename[0])
fprint(fd, "baseurl %s", url->basename);
if(fprint(fd, "url %s", url->reltext) < 0){
if(url->basename[0]){
n = snprint(buf, nbuf, "baseurl %s", url->basename);
write(fd, buf, n);
}
n = snprint(buf, nbuf, "url %s", url->reltext);
if(write(fd, buf, n) < 0){
close(fd);
return -1;
}
}
snprint(buf, nbuf, "%s/%d", mtpt, conn);
return fd;
}