1 |
– |
/* Copyright (c) 1993 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Generate sections of a picture. |
6 |
|
*/ |
7 |
|
|
8 |
+ |
|
9 |
+ |
#include <stdio.h> |
10 |
+ |
#include <signal.h> |
11 |
+ |
#include <sys/types.h> |
12 |
+ |
#ifndef NON_POSIX /* XXX need abstraction for process management */ |
13 |
+ |
#include <sys/wait.h> |
14 |
+ |
#endif |
15 |
+ |
|
16 |
+ |
#include "platform.h" |
17 |
|
#include "standard.h" |
18 |
< |
#include <fcntl.h> |
18 |
> |
#include "color.h" |
19 |
> |
#include "view.h" |
20 |
> |
#include "rtprocess.h" |
21 |
|
|
22 |
|
#ifndef F_SETLKW |
23 |
|
|
24 |
< |
main(argc, argv) |
25 |
< |
int argc; |
26 |
< |
char *argv[]; |
24 |
> |
int |
25 |
> |
main( |
26 |
> |
int argc, |
27 |
> |
char *argv[] |
28 |
> |
) |
29 |
|
{ |
30 |
|
fprintf(stderr, "%s: no NFS lock manager on this machine\n", argv[0]); |
31 |
|
exit(1); |
33 |
|
|
34 |
|
#else |
35 |
|
|
26 |
– |
#include <signal.h> |
27 |
– |
#include "color.h" |
28 |
– |
#include "view.h" |
29 |
– |
#include "resolu.h" |
30 |
– |
|
36 |
|
#ifndef NFS |
37 |
|
#define NFS 1 |
38 |
|
#endif |
45 |
|
#endif |
46 |
|
#endif |
47 |
|
/* protection from SYSV signals(!) */ |
48 |
< |
#if defined(sgi) || defined(hpux) |
48 |
> |
#if defined(sgi) |
49 |
|
#define guard_io() sighold(SIGALRM) |
50 |
|
#define unguard() sigrelse(SIGALRM) |
51 |
|
#endif |
52 |
|
#ifndef guard_io |
53 |
< |
#define guard_io() 0 |
54 |
< |
#define unguard() 0 |
53 |
> |
#define guard_io() |
54 |
> |
#define unguard() |
55 |
|
#endif |
56 |
+ |
|
57 |
+ |
extern char *strerror(); |
58 |
+ |
|
59 |
|
/* rpict command */ |
60 |
|
char *rpargv[128] = {"rpict", "-S", "1"}; |
61 |
|
int rpargc = 3; |
54 |
– |
int rpd[3]; |
62 |
|
FILE *torp, *fromrp; |
63 |
|
COLR *pbuf; |
64 |
|
/* our view parameters */ |
69 |
|
char *outfile = NULL; |
70 |
|
int outfd; |
71 |
|
long scanorig; |
72 |
< |
int syncfd = -1; /* lock file descriptor */ |
72 |
> |
FILE *syncfp = NULL; /* synchronization file pointer */ |
73 |
> |
int synclst = F_UNLCK; /* synchronization file lock status */ |
74 |
|
int nforked = 0; |
75 |
|
|
76 |
+ |
#define sflock(t) if ((t)!=synclst) dolock(fileno(syncfp),synclst=t) |
77 |
+ |
|
78 |
|
char *progname; |
79 |
|
int verbose = 0; |
80 |
+ |
unsigned timelim = 0; |
81 |
+ |
int rvrlim = -1; |
82 |
|
|
71 |
– |
extern long lseek(), ftell(); |
72 |
– |
|
83 |
|
int gotalrm = 0; |
84 |
< |
int onalrm() { gotalrm++; } |
84 |
> |
void onalrm(int i) { gotalrm++; } |
85 |
|
|
86 |
+ |
static void dolock(int fd, int ltyp); |
87 |
+ |
static void init(int ac, char **av); |
88 |
+ |
static int nextpiece(int *xp, int *yp); |
89 |
+ |
static int rvrpiece(int *xp, int *yp); |
90 |
+ |
static int cleanup(int rstat); |
91 |
+ |
static void rpiece(void); |
92 |
+ |
static int putpiece(int xpos, int ypos); |
93 |
+ |
static void filerr(char *t); |
94 |
|
|
95 |
< |
main(argc, argv) |
96 |
< |
int argc; |
97 |
< |
char *argv[]; |
95 |
> |
|
96 |
> |
int |
97 |
> |
main( |
98 |
> |
int argc, |
99 |
> |
char *argv[] |
100 |
> |
) |
101 |
|
{ |
102 |
|
register int i, rval; |
103 |
|
|
104 |
|
progname = argv[0]; |
105 |
|
for (i = 1; i < argc; i++) { |
106 |
|
/* expand arguments */ |
107 |
< |
while (rval = expandarg(&argc, &argv, i)) |
108 |
< |
if (rval < 0) { |
109 |
< |
fprintf(stderr, "%s: cannot expand '%s'", |
110 |
< |
argv[0], argv[i]); |
111 |
< |
exit(1); |
112 |
< |
} |
107 |
> |
while ((rval = expandarg(&argc, &argv, i)) > 0) |
108 |
> |
; |
109 |
> |
if (rval < 0) { |
110 |
> |
fprintf(stderr, "%s: cannot expand '%s'", |
111 |
> |
argv[0], argv[i]); |
112 |
> |
exit(1); |
113 |
> |
} |
114 |
|
if (argv[i][0] == '-') |
115 |
|
switch (argv[i][1]) { |
116 |
|
case 'v': |
137 |
|
case 'p': /* pixel aspect ratio? */ |
138 |
|
if (argv[i][2] != 'a' || argv[i][3]) |
139 |
|
break; |
140 |
< |
pixaspect = atof(argv[i+1]); |
140 |
> |
pixaspect = atof(argv[++i]); |
141 |
|
continue; |
142 |
+ |
case 'T': /* time limit (hours) */ |
143 |
+ |
if (argv[i][2]) |
144 |
+ |
break; |
145 |
+ |
timelim = atof(argv[++i])*3600. + .5; |
146 |
+ |
break; |
147 |
|
case 'x': /* overall x resolution */ |
148 |
|
if (argv[i][2]) |
149 |
|
break; |
164 |
|
break; |
165 |
|
vmult = atoi(argv[++i]); |
166 |
|
continue; |
167 |
+ |
case 'R': /* recover */ |
168 |
+ |
if (argv[i][2]) |
169 |
+ |
break; |
170 |
+ |
rvrlim = 0; |
171 |
+ |
/* fall through */ |
172 |
|
case 'F': /* syncronization file */ |
173 |
|
if (argv[i][2]) |
174 |
|
break; |
175 |
< |
if ((syncfd = open(argv[++i], |
176 |
< |
O_RDWR|O_CREAT, 0666)) < 0) { |
175 |
> |
if ((syncfp = |
176 |
> |
fdopen(open(argv[++i],O_RDWR|O_CREAT,0666),"r+")) == NULL) { |
177 |
|
fprintf(stderr, "%s: cannot open\n", |
178 |
|
argv[i]); |
179 |
|
exit(1); |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
< |
init(ac, av) /* set up output file and start rpict */ |
210 |
< |
int ac; |
211 |
< |
char **av; |
209 |
> |
static void |
210 |
> |
dolock( /* lock or unlock a file */ |
211 |
> |
int fd, |
212 |
> |
int ltyp |
213 |
> |
) |
214 |
|
{ |
215 |
+ |
static struct flock fls; /* static so initialized to zeroes */ |
216 |
+ |
|
217 |
+ |
fls.l_type = ltyp; |
218 |
+ |
if (fcntl(fd, F_SETLKW, &fls) < 0) { |
219 |
+ |
fprintf(stderr, "%s: cannot lock/unlock file: %s\n", |
220 |
+ |
progname, strerror(errno)); |
221 |
+ |
exit(1); |
222 |
+ |
} |
223 |
+ |
} |
224 |
+ |
|
225 |
+ |
|
226 |
+ |
static void |
227 |
+ |
init( /* set up output file and start rpict */ |
228 |
+ |
int ac, |
229 |
+ |
char **av |
230 |
+ |
) |
231 |
+ |
{ |
232 |
|
static char hrbuf[16], vrbuf[16]; |
233 |
|
extern char VersionID[]; |
234 |
|
char *err; |
235 |
|
FILE *fp; |
236 |
|
int hr, vr; |
237 |
+ |
SUBPROC rpd; /* since we don't close_process(), this can be local */ |
238 |
|
/* set up view */ |
239 |
|
if ((err = setview(&ourview)) != NULL) { |
240 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
241 |
|
exit(1); |
242 |
|
} |
243 |
< |
if (syncfd != -1) { |
244 |
< |
char buf[32]; |
245 |
< |
buf[read(syncfd, buf, sizeof(buf)-1)] = '\0'; |
246 |
< |
sscanf(buf, "%d %d", &hmult, &vmult); |
243 |
> |
if (syncfp != NULL) { |
244 |
> |
sflock(F_RDLCK); |
245 |
> |
fscanf(syncfp, "%d %d", &hmult, &vmult); |
246 |
> |
sflock(F_UNLCK); |
247 |
|
} |
248 |
|
/* compute piece size */ |
249 |
|
hres /= hmult; |
250 |
|
vres /= vmult; |
251 |
+ |
if (hres <= 0 || vres <= 0) { |
252 |
+ |
fprintf(stderr, "%s: illegal resolution/subdivision\n", progname); |
253 |
+ |
exit(1); |
254 |
+ |
} |
255 |
|
normaspect(viewaspect(&ourview)*hmult/vmult, &pixaspect, &hres, &vres); |
256 |
|
sprintf(hrbuf, "%d", hres); |
257 |
|
rpargv[rpargc++] = "-x"; rpargv[rpargc++] = hrbuf; |
262 |
|
rpargv[rpargc] = NULL; |
263 |
|
/* open output file */ |
264 |
|
if ((outfd = open(outfile, O_WRONLY|O_CREAT|O_EXCL, 0666)) >= 0) { |
265 |
+ |
dolock(outfd, F_WRLCK); |
266 |
|
if ((fp = fdopen(dup(outfd), "w")) == NULL) |
267 |
|
goto filerr; |
268 |
< |
printargs(ac, av, fp); /* write header */ |
268 |
> |
newheader("RADIANCE", fp); /* create header */ |
269 |
> |
printargs(ac, av, fp); |
270 |
|
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
271 |
|
fputs(VIEWSTR, fp); |
272 |
|
fprintview(&ourview, fp); |
277 |
|
putc('\n', fp); |
278 |
|
fprtresolu(hres*hmult, vres*vmult, fp); |
279 |
|
} else if ((outfd = open(outfile, O_RDWR)) >= 0) { |
280 |
+ |
dolock(outfd, F_RDLCK); |
281 |
|
if ((fp = fdopen(dup(outfd), "r+")) == NULL) |
282 |
|
goto filerr; |
283 |
|
getheader(fp, NULL, NULL); /* skip header */ |
295 |
|
scanorig = ftell(fp); /* record position of first scanline */ |
296 |
|
if (fclose(fp) == -1) /* done with stream i/o */ |
297 |
|
goto filerr; |
298 |
< |
#if NFS |
240 |
< |
sync(); /* flush NFS buffers */ |
241 |
< |
#endif |
298 |
> |
dolock(outfd, F_UNLCK); |
299 |
|
/* start rpict process */ |
300 |
< |
if (open_process(rpd, rpargv) <= 0) { |
300 |
> |
if (open_process(&rpd, rpargv) <= 0) { |
301 |
|
fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]); |
302 |
|
exit(1); |
303 |
|
} |
304 |
< |
if ((fromrp = fdopen(rpd[0], "r")) == NULL || |
305 |
< |
(torp = fdopen(rpd[1], "w")) == NULL) { |
304 |
> |
if ((fromrp = fdopen(rpd.r, "r")) == NULL || |
305 |
> |
(torp = fdopen(rpd.w, "w")) == NULL) { |
306 |
|
fprintf(stderr, "%s: cannot open stream to %s\n", |
307 |
|
progname, rpargv[0]); |
308 |
|
exit(1); |
312 |
|
exit(1); |
313 |
|
} |
314 |
|
signal(SIGALRM, onalrm); |
315 |
+ |
if (timelim) |
316 |
+ |
alarm(timelim); |
317 |
|
return; |
318 |
|
filerr: |
319 |
|
fprintf(stderr, "%s: i/o error on file \"%s\"\n", progname, outfile); |
321 |
|
} |
322 |
|
|
323 |
|
|
324 |
< |
int |
325 |
< |
nextpiece(xp, yp) /* get next piece assignment */ |
326 |
< |
int *xp, *yp; |
324 |
> |
static int |
325 |
> |
nextpiece( /* get next piece assignment */ |
326 |
> |
int *xp, |
327 |
> |
int *yp |
328 |
> |
) |
329 |
|
{ |
269 |
– |
struct flock fls; |
270 |
– |
char buf[64]; |
271 |
– |
|
330 |
|
if (gotalrm) /* someone wants us to quit */ |
331 |
|
return(0); |
332 |
< |
if (syncfd != -1) { /* use sync file */ |
333 |
< |
fls.l_type = F_WRLCK; /* gain exclusive access */ |
334 |
< |
fls.l_whence = 0; |
335 |
< |
fls.l_start = 0L; |
336 |
< |
fls.l_len = 0L; |
337 |
< |
fcntl(syncfd, F_SETLKW, &fls); |
338 |
< |
lseek(syncfd, 0L, 0); |
339 |
< |
buf[read(syncfd, buf, sizeof(buf)-1)] = '\0'; |
340 |
< |
if (sscanf(buf, "%*d %*d %d %d", xp, yp) < 2) { |
332 |
> |
if (syncfp != NULL) { /* use sync file */ |
333 |
> |
/* |
334 |
> |
* So we don't necessarily have to lock and unlock the file |
335 |
> |
* multiple times (very slow), we establish an exclusive |
336 |
> |
* lock at the beginning on our synchronization file and |
337 |
> |
* maintain it in the subroutine rvrpiece(). |
338 |
> |
*/ |
339 |
> |
sflock(F_WRLCK); |
340 |
> |
fseek(syncfp, 0L, 0); /* read position */ |
341 |
> |
if (fscanf(syncfp, "%*d %*d %d %d", xp, yp) < 2) { |
342 |
|
*xp = hmult-1; |
343 |
|
*yp = vmult; |
344 |
|
} |
345 |
+ |
if (rvrlim == 0) /* initialize recovery limit */ |
346 |
+ |
rvrlim = *xp*vmult + *yp; |
347 |
+ |
if (rvrpiece(xp, yp)) { /* do stragglers first */ |
348 |
+ |
sflock(F_UNLCK); |
349 |
+ |
return(1); |
350 |
+ |
} |
351 |
|
if (--(*yp) < 0) { /* decrement position */ |
352 |
|
*yp = vmult-1; |
353 |
< |
if (--(*xp) < 0) { /* all done! */ |
354 |
< |
close(syncfd); |
353 |
> |
if (--(*xp) < 0) { /* all done */ |
354 |
> |
sflock(F_UNLCK); |
355 |
|
return(0); |
356 |
|
} |
357 |
|
} |
358 |
< |
sprintf(buf, "%4d %4d\n%4d %4d\n", hmult, vmult, *xp, *yp); |
359 |
< |
lseek(syncfd, 0L, 0); /* write new position */ |
360 |
< |
write(syncfd, buf, strlen(buf)); |
361 |
< |
fls.l_type = F_UNLCK; /* release sync file */ |
297 |
< |
fcntl(syncfd, F_SETLKW, &fls); |
358 |
> |
fseek(syncfp, 0L, 0); /* write new position */ |
359 |
> |
fprintf(syncfp, "%4d %4d\n%4d %4d\n\n", hmult, vmult, *xp, *yp); |
360 |
> |
fflush(syncfp); |
361 |
> |
sflock(F_UNLCK); /* release sync file */ |
362 |
|
return(1); |
363 |
|
} |
364 |
< |
if (fgets(buf, sizeof(buf), stdin) == NULL) /* use stdin */ |
301 |
< |
return(0); |
302 |
< |
if (sscanf(buf, "%d %d", xp, yp) == 2) |
303 |
< |
return(1); |
304 |
< |
fprintf(stderr, "%s: input format error\n", progname); |
305 |
< |
exit(cleanup(1)); |
364 |
> |
return(scanf("%d %d", xp, yp) == 2); /* use stdin */ |
365 |
|
} |
366 |
|
|
367 |
|
|
368 |
< |
int |
369 |
< |
cleanup(rstat) /* close rpict process and clean up */ |
370 |
< |
int rstat; |
368 |
> |
static int |
369 |
> |
rvrpiece( /* check for recoverable pieces */ |
370 |
> |
register int *xp, |
371 |
> |
register int *yp |
372 |
> |
) |
373 |
|
{ |
374 |
+ |
static char *pdone = NULL; /* which pieces are done */ |
375 |
+ |
static long readpos = -1; /* how far we've read */ |
376 |
+ |
register int i; |
377 |
+ |
/* |
378 |
+ |
* This routine is called by nextpiece() with an |
379 |
+ |
* exclusive lock on syncfp and the file pointer at the |
380 |
+ |
* appropriate position to read in the finished pieces. |
381 |
+ |
*/ |
382 |
+ |
if (rvrlim < 0) |
383 |
+ |
return(0); /* only check if asked */ |
384 |
+ |
if (pdone == NULL) /* first call */ |
385 |
+ |
pdone = calloc(hmult*vmult, sizeof(char)); |
386 |
+ |
if (pdone == NULL) { |
387 |
+ |
fprintf(stderr, "%s: out of memory\n", progname); |
388 |
+ |
exit(1); |
389 |
+ |
} |
390 |
+ |
if (readpos != -1) /* mark what's been done */ |
391 |
+ |
fseek(syncfp, readpos, 0); |
392 |
+ |
while (fscanf(syncfp, "%d %d", xp, yp) == 2) |
393 |
+ |
pdone[*xp*vmult+*yp] = 1; |
394 |
+ |
if (!feof(syncfp)) { |
395 |
+ |
fprintf(stderr, "%s: format error in sync file\n", progname); |
396 |
+ |
exit(1); |
397 |
+ |
} |
398 |
+ |
readpos = ftell(syncfp); |
399 |
+ |
i = hmult*vmult; /* find an unaccounted for piece */ |
400 |
+ |
while (i-- > rvrlim) |
401 |
+ |
if (!pdone[i]) { |
402 |
+ |
*xp = i / vmult; |
403 |
+ |
*yp = i % vmult; |
404 |
+ |
pdone[i] = 1; /* consider it done */ |
405 |
+ |
return(1); |
406 |
+ |
} |
407 |
+ |
rvrlim = -1; /* nothing left to recover */ |
408 |
+ |
free(pdone); |
409 |
+ |
pdone = NULL; |
410 |
+ |
return(0); |
411 |
+ |
} |
412 |
+ |
|
413 |
+ |
|
414 |
+ |
static int |
415 |
+ |
cleanup( /* close rpict process and clean up */ |
416 |
+ |
int rstat |
417 |
+ |
) |
418 |
+ |
{ |
419 |
|
int status; |
420 |
|
|
421 |
|
bfree((char *)pbuf, hres*vres*sizeof(COLR)); |
428 |
|
} |
429 |
|
|
430 |
|
|
431 |
< |
rpiece() /* render picture piece by piece */ |
431 |
> |
static void |
432 |
> |
rpiece(void) /* render picture piece by piece */ |
433 |
|
{ |
434 |
|
VIEW pview; |
435 |
|
int xorg, yorg; |
436 |
|
/* compute view parameters */ |
437 |
< |
copystruct(&pview, &ourview); |
437 |
> |
pview = ourview; |
438 |
|
switch (ourview.type) { |
439 |
|
case VT_PER: |
440 |
|
pview.horiz = 2.*180./PI*atan( |
447 |
|
pview.horiz = ourview.horiz / hmult; |
448 |
|
pview.vert = ourview.vert / vmult; |
449 |
|
break; |
450 |
+ |
case VT_CYL: |
451 |
+ |
pview.horiz = ourview.horiz / hmult; |
452 |
+ |
pview.vert = 2.*180./PI*atan( |
453 |
+ |
tan(PI/180./2.*ourview.vert)/vmult ); |
454 |
+ |
break; |
455 |
|
case VT_HEM: |
456 |
|
pview.horiz = 2.*180./PI*asin( |
457 |
|
sin(PI/180./2.*ourview.horiz)/hmult ); |
465 |
|
} |
466 |
|
/* render each piece */ |
467 |
|
while (nextpiece(&xorg, &yorg)) { |
468 |
< |
pview.hoff = ourview.hoff + xorg - 0.5*(hmult-1); |
469 |
< |
pview.voff = ourview.voff + yorg - 0.5*(vmult-1); |
468 |
> |
pview.hoff = ourview.hoff*hmult + xorg - 0.5*(hmult-1); |
469 |
> |
pview.voff = ourview.voff*vmult + yorg - 0.5*(vmult-1); |
470 |
|
fputs(VIEWSTR, torp); |
471 |
|
fprintview(&pview, torp); |
472 |
|
putc('\n', torp); |
476 |
|
} |
477 |
|
|
478 |
|
|
479 |
< |
int |
480 |
< |
putpiece(xpos, ypos) /* get next piece from rpict */ |
481 |
< |
int xpos, ypos; |
479 |
> |
static int |
480 |
> |
putpiece( /* get next piece from rpict */ |
481 |
> |
int xpos, |
482 |
> |
int ypos |
483 |
> |
) |
484 |
|
{ |
485 |
|
struct flock fls; |
486 |
|
int pid, status; |
487 |
|
int hr, vr; |
488 |
|
register int y; |
489 |
|
/* check bounds */ |
490 |
< |
if (xpos < 0 | ypos < 0 | xpos >= hmult | ypos >= vmult) { |
490 |
> |
if ((xpos < 0) | (ypos < 0) | (xpos >= hmult) | (ypos >= vmult)) { |
491 |
|
fprintf(stderr, "%s: requested piece (%d,%d) out of range\n", |
492 |
|
progname, xpos, ypos); |
493 |
|
exit(cleanup(1)); |
495 |
|
/* check header from rpict */ |
496 |
|
guard_io(); |
497 |
|
getheader(fromrp, NULL, NULL); |
498 |
< |
if (!fscnresolu(&hr, &vr, fromrp) || hr != hres | vr != vres) { |
498 |
> |
if (!fscnresolu(&hr, &vr, fromrp) || (hr != hres) | (vr != vres)) { |
499 |
|
fprintf(stderr, "%s: resolution mismatch from %s\n", |
500 |
|
progname, rpargv[0]); |
501 |
|
exit(cleanup(1)); |
536 |
|
/* lock file section so NFS doesn't mess up */ |
537 |
|
fls.l_whence = 0; |
538 |
|
fls.l_type = F_WRLCK; |
539 |
< |
fcntl(outfd, F_SETLKW, &fls); |
539 |
> |
if (fcntl(outfd, F_SETLKW, &fls) < 0) |
540 |
> |
filerr("lock"); |
541 |
|
#endif |
542 |
|
/* write new piece to file */ |
543 |
< |
if (lseek(outfd, fls.l_start, 0) == -1) |
544 |
< |
goto seekerr; |
543 |
> |
if (lseek(outfd, (off_t)fls.l_start, SEEK_SET) < 0) |
544 |
> |
filerr("seek"); |
545 |
|
if (hmult == 1) { |
546 |
|
if (writebuf(outfd, (char *)pbuf, |
547 |
|
vr*hr*sizeof(COLR)) != vr*hr*sizeof(COLR)) |
548 |
< |
goto writerr; |
548 |
> |
filerr("write"); |
549 |
|
} else |
550 |
|
for (y = 0; y < vr; y++) { |
551 |
|
if (writebuf(outfd, (char *)(pbuf+y*hr), |
552 |
|
hr*sizeof(COLR)) != hr*sizeof(COLR)) |
553 |
< |
goto writerr; |
553 |
> |
filerr("write"); |
554 |
|
if (y < vr-1 && lseek(outfd, |
555 |
< |
(long)(hmult-1)*hr*sizeof(COLR), |
556 |
< |
1) == -1) |
557 |
< |
goto seekerr; |
555 |
> |
(off_t)(hmult-1)*hr*sizeof(COLR), |
556 |
> |
SEEK_CUR) < 0) |
557 |
> |
filerr("seek"); |
558 |
|
} |
559 |
+ |
#if NFS |
560 |
+ |
fls.l_type = F_UNLCK; /* release lock */ |
561 |
+ |
if (fcntl(outfd, F_SETLKW, &fls) < 0) |
562 |
+ |
filerr("lock"); |
563 |
+ |
#endif |
564 |
|
if (verbose) { /* notify caller */ |
565 |
|
printf("%d %d done\n", xpos, ypos); |
566 |
|
fflush(stdout); |
567 |
|
} |
568 |
< |
if (pid == -1) { /* didn't fork or fork failed */ |
569 |
< |
#if NFS |
570 |
< |
fls.l_type = F_UNLCK; /* release lock */ |
571 |
< |
fcntl(outfd, F_SETLKW, &fls); |
572 |
< |
#endif |
573 |
< |
return(0); |
568 |
> |
if (syncfp != NULL) { /* record what's been done */ |
569 |
> |
sflock(F_WRLCK); |
570 |
> |
fseek(syncfp, 0L, 2); /* append index */ |
571 |
> |
fprintf(syncfp, "%4d %4d\n", xpos, ypos); |
572 |
> |
fflush(syncfp); |
573 |
> |
/*** Unlock not necessary, since |
574 |
> |
sflock(F_UNLCK); _exit() or nextpiece() is next ***/ |
575 |
|
} |
576 |
< |
_exit(0); /* else exit child process (releasing lock) */ |
577 |
< |
seekerr: |
578 |
< |
fprintf(stderr, "%s: seek error on file \"%s\"\n", progname, outfile); |
579 |
< |
_exit(1); |
580 |
< |
writerr: |
581 |
< |
fprintf(stderr, "%s: write error on file \"%s\"\n", progname, outfile); |
576 |
> |
if (pid == -1) /* didn't fork or fork failed */ |
577 |
> |
return(0); |
578 |
> |
_exit(0); /* else exit child process (releasing locks) */ |
579 |
> |
} |
580 |
> |
|
581 |
> |
|
582 |
> |
static void |
583 |
> |
filerr( /* report file error and exit */ |
584 |
> |
char *t |
585 |
> |
) |
586 |
> |
{ |
587 |
> |
fprintf(stderr, "%s: %s error on file \"%s\": %s\n", |
588 |
> |
progname, t, outfile, strerror(errno)); |
589 |
|
_exit(1); |
590 |
|
} |
591 |
|
|