| 106 |
|
if (mknod(mktemp(strcpy(outpname,TEMPLATE)), S_IFIFO|0600) < 0) |
| 107 |
|
goto createrr; |
| 108 |
|
sprintf(buf, "%d\n%s\n%s\n", getpid(), inpname, outpname); |
| 109 |
< |
if (lseek(persistfd, 0L, 0) < 0) |
| 110 |
< |
error(SYSTEM, "seek error on persist file in pfhold"); |
| 109 |
> |
if (lseek(persistfd, 0L, 0) < 0 || ftruncate(persistfd, 0L) < 0) |
| 110 |
> |
error(SYSTEM, "seek/truncate error on persist file"); |
| 111 |
|
n = strlen(buf); |
| 112 |
|
if (write(persistfd, buf, n) < n) |
| 113 |
< |
error(SYSTEM, "error writing persist file in pfhold"); |
| 113 |
> |
error(SYSTEM, "error writing persist file"); |
| 114 |
|
/* wait TIMELIM for someone to signal us */ |
| 115 |
|
signal(SIGIO, sig_noop); |
| 116 |
|
alarm(TIMELIM); |
| 180 |
|
error(SYSTEM, "cannot open output pipe in io_process"); |
| 181 |
|
} |
| 182 |
|
/* pass input to output */ |
| 183 |
< |
cp = buf; n = sizeof(buf); |
| 184 |
< |
/* do as much as we can each way */ |
| 185 |
< |
while ((nr = read(0, cp, n)) > 0) { |
| 186 |
< |
nr += cp-buf; |
| 187 |
< |
if ((n = write(1, buf, nr)) <= 0) |
| 188 |
< |
goto writerr; |
| 189 |
< |
cp = buf; |
| 190 |
< |
while (n < nr) |
| 191 |
< |
*cp++ = buf[n++]; |
| 192 |
< |
n = sizeof(buf) - (cp-buf); |
| 193 |
< |
} |
| 183 |
> |
/* read as much as we can, write all of it */ |
| 184 |
> |
while ((nr = read(0, cp=buf, sizeof(buf))) > 0) |
| 185 |
> |
do { |
| 186 |
> |
if ((n = write(1, cp, nr)) <= 0) |
| 187 |
> |
goto writerr; |
| 188 |
> |
cp += n; |
| 189 |
> |
} while ((nr -= n) > 0); |
| 190 |
|
if (nr < 0) |
| 191 |
|
error(SYSTEM, "read error in io_process"); |
| 192 |
|
close(0); /* close input */ |
| 197 |
– |
nr = cp-buf; /* write remainder */ |
| 198 |
– |
cp = buf; |
| 199 |
– |
while (nr > 0) { |
| 200 |
– |
if ((n = write(1, cp, nr)) <= 0) |
| 201 |
– |
goto writerr; |
| 202 |
– |
cp += n; |
| 203 |
– |
nr -= n; |
| 204 |
– |
} |
| 193 |
|
close(1); /* close output */ |
| 194 |
|
if (pid) /* parent waits for child */ |
| 195 |
|
wait(0); |
| 199 |
|
writerr: |
| 200 |
|
error(SYSTEM, "write error in io_process"); |
| 201 |
|
} |
| 202 |
+ |
|
| 203 |
+ |
#else |
| 204 |
+ |
|
| 205 |
+ |
pfclean() {} |
| 206 |
|
|
| 207 |
|
#endif |