ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rpiece.c
Revision: 2.67
Committed: Tue Jun 3 21:31:51 2025 UTC (2 days, 20 hours ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 2.66: +2 -3 lines
Log Message:
refactor: More consistent use of global char * progname and fixargv0()

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 greg 2.67 static const char RCSid[] = "$Id: rpiece.c,v 2.66 2024/09/12 23:14:32 greg Exp $";
3 greg 2.1 #endif
4     /*
5     * Generate sections of a picture.
6     */
7    
8 schorsch 2.43
9     #include <stdio.h>
10     #include <signal.h>
11     #include <sys/types.h>
12 schorsch 2.49
13     #include "platform.h"
14 schorsch 2.45 #ifndef NON_POSIX /* XXX need abstraction for process management */
15     #include <sys/wait.h>
16     #endif
17 schorsch 2.43
18 greg 2.44 #include "standard.h"
19 schorsch 2.43 #include "color.h"
20     #include "view.h"
21     #include "rtprocess.h"
22 greg 2.16
23     #ifndef F_SETLKW
24    
25 schorsch 2.43 int
26     main(
27     int argc,
28     char *argv[]
29     )
30 greg 2.16 {
31     fprintf(stderr, "%s: no NFS lock manager on this machine\n", argv[0]);
32     exit(1);
33     }
34    
35     #else
36    
37 greg 2.12 #ifndef NFS
38     #define NFS 1
39     #endif
40 greg 2.55
41     #ifndef RHAS_FORK_EXEC
42     #undef MAXFORK
43     #define MAXFORK 0
44     #endif
45 greg 2.9 #ifndef MAXFORK
46 greg 2.12 #if NFS
47 greg 2.10 #define MAXFORK 3 /* allotment of duped processes */
48 greg 2.12 #else
49     #define MAXFORK 0
50 greg 2.9 #endif
51 greg 2.12 #endif
52 greg 2.18 /* protection from SYSV signals(!) */
53 greg 2.27 #if defined(sgi)
54 greg 2.18 #define guard_io() sighold(SIGALRM)
55     #define unguard() sigrelse(SIGALRM)
56     #endif
57     #ifndef guard_io
58 schorsch 2.43 #define guard_io()
59     #define unguard()
60 greg 2.18 #endif
61 gregl 2.34
62 greg 2.1 /* rpict command */
63 greg 2.23 char *rpargv[128] = {"rpict", "-S", "1"};
64     int rpargc = 3;
65 greg 2.1 FILE *torp, *fromrp;
66 greg 2.8 COLR *pbuf;
67 greg 2.1 /* our view parameters */
68     VIEW ourview = STDVIEW;
69 greg 2.4 double pixaspect = 1.0;
70 greg 2.23 int hres = 1024, vres = 1024, hmult = 4, vmult = 4;
71 greg 2.1 /* output file */
72     char *outfile = NULL;
73     int outfd;
74     long scanorig;
75 greg 2.25 FILE *syncfp = NULL; /* synchronization file pointer */
76     int synclst = F_UNLCK; /* synchronization file lock status */
77 greg 2.9 int nforked = 0;
78 greg 2.1
79 greg 2.25 #define sflock(t) if ((t)!=synclst) dolock(fileno(syncfp),synclst=t)
80    
81 greg 2.1 int verbose = 0;
82 greg 2.53 int nowarn = 0;
83 greg 2.31 unsigned timelim = 0;
84 greg 2.25 int rvrlim = -1;
85 greg 2.1
86 greg 2.6 int gotalrm = 0;
87 schorsch 2.38 void onalrm(int i) { gotalrm++; }
88 greg 2.1
89 schorsch 2.43 static void dolock(int fd, int ltyp);
90     static void init(int ac, char **av);
91     static int nextpiece(int *xp, int *yp);
92     static int rvrpiece(int *xp, int *yp);
93     static int cleanup(int rstat);
94     static void rpiece(void);
95     static int putpiece(int xpos, int ypos);
96     static void filerr(char *t);
97 greg 2.6
98 schorsch 2.43
99     int
100     main(
101     int argc,
102     char *argv[]
103     )
104 greg 2.1 {
105 greg 2.55 int i, rval;
106 greg 2.1
107 greg 2.67 fixargv0(argv[0]); /* assigns global progname */
108 greg 2.1 for (i = 1; i < argc; i++) {
109 greg 2.22 /* expand arguments */
110 greg 2.37 while ((rval = expandarg(&argc, &argv, i)) > 0)
111     ;
112     if (rval < 0) {
113 greg 2.50 fprintf(stderr, "%s: cannot expand '%s'\n",
114 greg 2.37 argv[0], argv[i]);
115     exit(1);
116     }
117 greg 2.1 if (argv[i][0] == '-')
118     switch (argv[i][1]) {
119 greg 2.53 case 'w':
120     if (!argv[i][2])
121     nowarn = !nowarn;
122     else if (argv[i][2] == '+')
123     nowarn = 0;
124     else if (argv[i][2] == '-')
125     nowarn = 1;
126     break;
127 greg 2.1 case 'v':
128     switch (argv[i][2]) {
129     case '\0': /* verbose option */
130     verbose = !verbose;
131     continue;
132     case 'f': /* view file */
133     if (viewfile(argv[++i], &ourview, NULL) <= 0) {
134     fprintf(stderr,
135     "%s: not a view file\n", argv[i]);
136     exit(1);
137     }
138     continue;
139     default: /* view option? */
140     rval = getviewopt(&ourview, argc-i, argv+i);
141     if (rval >= 0) {
142     i += rval;
143     continue;
144     }
145     break;
146     }
147     break;
148     case 'p': /* pixel aspect ratio? */
149 greg 2.51 if (argv[i][2] == 'm') {
150     fprintf(stderr, "%s: -pm unsupported\n",
151     argv[0]);
152     ++i;
153     continue;
154     }
155 greg 2.61 if (argv[i][2] == 'X') {
156     fprintf(stderr, "%s: -pXYZ unsupported\n",
157     argv[0]);
158     ++i;
159     continue;
160     }
161     if (argv[i][2] == 'c') {
162     fprintf(stderr, "%s: -pc unsupported\n",
163     argv[0]);
164     i += 9;
165     continue;
166     }
167 greg 2.23 if (argv[i][2] != 'a' || argv[i][3])
168     break;
169 gregl 2.35 pixaspect = atof(argv[++i]);
170 greg 2.23 continue;
171 greg 2.64 case 'S':
172     fprintf(stderr, "%s: -S unsupported\n", argv[0]);
173     i++;
174     continue;
175 greg 2.31 case 'T': /* time limit (hours) */
176     if (argv[i][2])
177     break;
178     timelim = atof(argv[++i])*3600. + .5;
179 greg 2.51 continue;
180 greg 2.23 case 'x': /* overall x resolution */
181     if (argv[i][2])
182     break;
183     hres = atoi(argv[++i]);
184     continue;
185     case 'y': /* overall y resolution */
186     if (argv[i][2])
187     break;
188     vres = atoi(argv[++i]);
189     continue;
190 greg 2.1 case 'X': /* horizontal multiplier */
191     if (argv[i][2])
192     break;
193     hmult = atoi(argv[++i]);
194     continue;
195     case 'Y': /* vertical multiplier */
196     if (argv[i][2])
197     break;
198     vmult = atoi(argv[++i]);
199     continue;
200 greg 2.25 case 'R': /* recover */
201     if (argv[i][2])
202     break;
203     rvrlim = 0;
204     /* fall through */
205 greg 2.5 case 'F': /* syncronization file */
206     if (argv[i][2])
207     break;
208 greg 2.28 if ((syncfp =
209     fdopen(open(argv[++i],O_RDWR|O_CREAT,0666),"r+")) == NULL) {
210 greg 2.5 fprintf(stderr, "%s: cannot open\n",
211     argv[i]);
212     exit(1);
213     }
214     continue;
215 greg 2.15 case 'z': /* z-file ist verbotten */
216     fprintf(stderr, "%s: -z option not allowed\n",
217     argv[0]);
218     exit(1);
219 greg 2.1 case 'o': /* output file */
220     if (argv[i][2])
221     break;
222     outfile = argv[++i];
223     continue;
224 greg 2.53 }
225     else if (i >= argc-1)
226     break;
227 greg 2.1 rpargv[rpargc++] = argv[i];
228     }
229 greg 2.23 if (i >= argc) {
230     fprintf(stderr, "%s: missing octree argument\n", argv[0]);
231     exit(1);
232     }
233 greg 2.1 if (outfile == NULL) {
234     fprintf(stderr, "%s: missing output file\n", argv[0]);
235     exit(1);
236     }
237     init(argc, argv);
238     rpiece();
239 greg 2.15 exit(cleanup(0));
240 greg 2.1 }
241    
242    
243 schorsch 2.43 static void
244     dolock( /* lock or unlock a file */
245     int fd,
246     int ltyp
247     )
248 greg 2.25 {
249     static struct flock fls; /* static so initialized to zeroes */
250    
251     fls.l_type = ltyp;
252     if (fcntl(fd, F_SETLKW, &fls) < 0) {
253 greg 2.28 fprintf(stderr, "%s: cannot lock/unlock file: %s\n",
254 greg 2.37 progname, strerror(errno));
255 greg 2.54 _exit(1);
256 greg 2.25 }
257     }
258    
259    
260 schorsch 2.43 static void
261     init( /* set up output file and start rpict */
262     int ac,
263     char **av
264     )
265 greg 2.1 {
266 greg 2.23 static char hrbuf[16], vrbuf[16];
267 greg 2.2 extern char VersionID[];
268 greg 2.1 char *err;
269     FILE *fp;
270     int hr, vr;
271 schorsch 2.39 SUBPROC rpd; /* since we don't close_process(), this can be local */
272 greg 2.1 /* set up view */
273     if ((err = setview(&ourview)) != NULL) {
274     fprintf(stderr, "%s: %s\n", progname, err);
275     exit(1);
276     }
277 greg 2.25 if (syncfp != NULL) {
278     sflock(F_RDLCK);
279     fscanf(syncfp, "%d %d", &hmult, &vmult);
280     sflock(F_UNLCK);
281 greg 2.5 }
282 greg 2.23 /* compute piece size */
283 greg 2.53 hr = hres; vr = vres;
284     if (pixaspect > FTINY)
285     normaspect(viewaspect(&ourview), &pixaspect, &hr, &vr);
286 greg 2.23 hres /= hmult;
287     vres /= vmult;
288 greg 2.46 if (hres <= 0 || vres <= 0) {
289 greg 2.47 fprintf(stderr, "%s: illegal resolution/subdivision\n", progname);
290 greg 2.46 exit(1);
291     }
292 greg 2.1 normaspect(viewaspect(&ourview)*hmult/vmult, &pixaspect, &hres, &vres);
293 greg 2.53 if (!nowarn && (hr != hres*hmult) | (vr != vres*vmult))
294     fprintf(stderr,
295 greg 2.57 "%s: warning - changed resolution from %dx%d to %dx%d\n",
296 greg 2.53 progname, hr, vr, hres*hmult, vres*vmult);
297 greg 2.23 sprintf(hrbuf, "%d", hres);
298     rpargv[rpargc++] = "-x"; rpargv[rpargc++] = hrbuf;
299     sprintf(vrbuf, "%d", vres);
300     rpargv[rpargc++] = "-y"; rpargv[rpargc++] = vrbuf;
301     rpargv[rpargc++] = "-pa"; rpargv[rpargc++] = "0";
302 greg 2.63 rpargv[rpargc++] = "-pm"; rpargv[rpargc++] = "0";
303 greg 2.23 rpargv[rpargc++] = av[ac-1];
304     rpargv[rpargc] = NULL;
305 greg 2.1 /* open output file */
306     if ((outfd = open(outfile, O_WRONLY|O_CREAT|O_EXCL, 0666)) >= 0) {
307 greg 2.25 dolock(outfd, F_WRLCK);
308 greg 2.1 if ((fp = fdopen(dup(outfd), "w")) == NULL)
309     goto filerr;
310 greg 2.29 newheader("RADIANCE", fp); /* create header */
311     printargs(ac, av, fp);
312 greg 2.2 fprintf(fp, "SOFTWARE= %s\n", VersionID);
313 greg 2.66 fprintf(fp, "TILED= %d %d\n", hmult, vmult);
314 greg 2.1 fputs(VIEWSTR, fp);
315     fprintview(&ourview, fp);
316 greg 2.59 fputc('\n', fp);
317 greg 2.52 fputnow(fp);
318 greg 2.1 if (pixaspect < .99 || pixaspect > 1.01)
319     fputaspect(pixaspect, fp);
320 greg 2.60 fputprims(stdprims, fp);
321 greg 2.1 fputformat(COLRFMT, fp);
322 greg 2.59 fputc('\n', fp);
323 greg 2.1 fprtresolu(hres*hmult, vres*vmult, fp);
324     } else if ((outfd = open(outfile, O_RDWR)) >= 0) {
325 greg 2.25 dolock(outfd, F_RDLCK);
326 greg 2.1 if ((fp = fdopen(dup(outfd), "r+")) == NULL)
327     goto filerr;
328 greg 2.13 getheader(fp, NULL, NULL); /* skip header */
329 greg 2.15 if (!fscnresolu(&hr, &vr, fp) || /* check resolution */
330 greg 2.1 hr != hres*hmult || vr != vres*vmult) {
331 greg 2.8 fprintf(stderr, "%s: resolution mismatch on file \"%s\"\n",
332     progname, outfile);
333 greg 2.1 exit(1);
334     }
335     } else {
336 greg 2.8 fprintf(stderr, "%s: cannot open file \"%s\"\n",
337     progname, outfile);
338 greg 2.1 exit(1);
339     }
340     scanorig = ftell(fp); /* record position of first scanline */
341     if (fclose(fp) == -1) /* done with stream i/o */
342     goto filerr;
343 greg 2.25 dolock(outfd, F_UNLCK);
344 greg 2.1 /* start rpict process */
345 greg 2.58 rpd = sp_inactive;
346 schorsch 2.39 if (open_process(&rpd, rpargv) <= 0) {
347 greg 2.3 fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]);
348 greg 2.1 exit(1);
349     }
350 schorsch 2.39 if ((fromrp = fdopen(rpd.r, "r")) == NULL ||
351     (torp = fdopen(rpd.w, "w")) == NULL) {
352 greg 2.1 fprintf(stderr, "%s: cannot open stream to %s\n",
353     progname, rpargv[0]);
354     exit(1);
355     }
356 greg 2.23 if ((pbuf = (COLR *)bmalloc(hres*vres*sizeof(COLR))) == NULL) {
357 greg 2.1 fprintf(stderr, "%s: out of memory\n", progname);
358     exit(1);
359     }
360 greg 2.6 signal(SIGALRM, onalrm);
361 greg 2.31 if (timelim)
362     alarm(timelim);
363 greg 2.1 return;
364     filerr:
365 greg 2.8 fprintf(stderr, "%s: i/o error on file \"%s\"\n", progname, outfile);
366 greg 2.1 exit(1);
367     }
368    
369    
370 schorsch 2.43 static int
371     nextpiece( /* get next piece assignment */
372     int *xp,
373     int *yp
374     )
375 greg 2.5 {
376 greg 2.6 if (gotalrm) /* someone wants us to quit */
377     return(0);
378 greg 2.25 if (syncfp != NULL) { /* use sync file */
379     /*
380     * So we don't necessarily have to lock and unlock the file
381     * multiple times (very slow), we establish an exclusive
382     * lock at the beginning on our synchronization file and
383     * maintain it in the subroutine rvrpiece().
384     */
385     sflock(F_WRLCK);
386     fseek(syncfp, 0L, 0); /* read position */
387     if (fscanf(syncfp, "%*d %*d %d %d", xp, yp) < 2) {
388 greg 2.8 *xp = hmult-1;
389     *yp = vmult;
390     }
391 greg 2.25 if (rvrlim == 0) /* initialize recovery limit */
392     rvrlim = *xp*vmult + *yp;
393     if (rvrpiece(xp, yp)) { /* do stragglers first */
394     sflock(F_UNLCK);
395     return(1);
396     }
397 greg 2.8 if (--(*yp) < 0) { /* decrement position */
398 greg 2.5 *yp = vmult-1;
399 greg 2.25 if (--(*xp) < 0) { /* all done */
400     sflock(F_UNLCK);
401 greg 2.5 return(0);
402     }
403     }
404 greg 2.25 fseek(syncfp, 0L, 0); /* write new position */
405     fprintf(syncfp, "%4d %4d\n%4d %4d\n\n", hmult, vmult, *xp, *yp);
406     fflush(syncfp);
407     sflock(F_UNLCK); /* release sync file */
408 greg 2.5 return(1);
409     }
410 greg 2.26 return(scanf("%d %d", xp, yp) == 2); /* use stdin */
411 greg 2.5 }
412    
413    
414 schorsch 2.43 static int
415     rvrpiece( /* check for recoverable pieces */
416 greg 2.55 int *xp,
417     int *yp
418 schorsch 2.43 )
419 greg 2.25 {
420     static char *pdone = NULL; /* which pieces are done */
421     static long readpos = -1; /* how far we've read */
422 greg 2.56 int px, py, i;
423 greg 2.25 /*
424     * This routine is called by nextpiece() with an
425     * exclusive lock on syncfp and the file pointer at the
426     * appropriate position to read in the finished pieces.
427     */
428     if (rvrlim < 0)
429     return(0); /* only check if asked */
430     if (pdone == NULL) /* first call */
431 greg 2.56 pdone = (char *)calloc(hmult*vmult, sizeof(char));
432 greg 2.30 if (pdone == NULL) {
433     fprintf(stderr, "%s: out of memory\n", progname);
434     exit(1);
435     }
436 greg 2.25 if (readpos != -1) /* mark what's been done */
437     fseek(syncfp, readpos, 0);
438 greg 2.56 while (fscanf(syncfp, "%d %d", &px, &py) == 2)
439     pdone[px*vmult+py] = 1;
440 greg 2.25 if (!feof(syncfp)) {
441     fprintf(stderr, "%s: format error in sync file\n", progname);
442     exit(1);
443     }
444     readpos = ftell(syncfp);
445     i = hmult*vmult; /* find an unaccounted for piece */
446     while (i-- > rvrlim)
447     if (!pdone[i]) {
448     *xp = i / vmult;
449     *yp = i % vmult;
450     pdone[i] = 1; /* consider it done */
451     return(1);
452     }
453     rvrlim = -1; /* nothing left to recover */
454     free(pdone);
455     pdone = NULL;
456     return(0);
457     }
458    
459    
460 schorsch 2.43 static int
461     cleanup( /* close rpict process and clean up */
462     int rstat
463     )
464 greg 2.1 {
465 greg 2.10 int status;
466 greg 2.1
467 greg 2.23 bfree((char *)pbuf, hres*vres*sizeof(COLR));
468 greg 2.1 fclose(torp);
469     fclose(fromrp);
470 greg 2.10 while (wait(&status) != -1)
471 greg 2.9 if (rstat == 0)
472     rstat = status>>8 & 0xff;
473     return(rstat);
474 greg 2.1 }
475    
476    
477 schorsch 2.43 static void
478     rpiece(void) /* render picture piece by piece */
479 greg 2.1 {
480 greg 2.59 char *err;
481 greg 2.1 VIEW pview;
482     int xorg, yorg;
483 greg 2.11 /* render each piece */
484 greg 2.5 while (nextpiece(&xorg, &yorg)) {
485 greg 2.59 pview = ourview;
486     err = cropview(&pview, (double)xorg/hmult, (double)yorg/vmult,
487     (xorg+1.)/hmult, (yorg+1.)/vmult);
488     if (err != NULL) {
489     fprintf(stderr, "%s: %s\n", progname, err);
490     exit(cleanup(1));
491     }
492 greg 2.1 fputs(VIEWSTR, torp);
493     fprintview(&pview, torp);
494 greg 2.59 fputc('\n', torp);
495 greg 2.11 fflush(torp); /* assigns piece to rpict */
496 greg 2.1 putpiece(xorg, yorg); /* place piece in output */
497     }
498     }
499    
500    
501 schorsch 2.43 static int
502     putpiece( /* get next piece from rpict */
503     int xpos,
504     int ypos
505     )
506 greg 2.1 {
507 greg 2.7 struct flock fls;
508 greg 2.9 int pid, status;
509 greg 2.1 int hr, vr;
510 greg 2.55 int y;
511 greg 2.8 /* check bounds */
512 schorsch 2.41 if ((xpos < 0) | (ypos < 0) | (xpos >= hmult) | (ypos >= vmult)) {
513 greg 2.5 fprintf(stderr, "%s: requested piece (%d,%d) out of range\n",
514     progname, xpos, ypos);
515 greg 2.10 exit(cleanup(1));
516 greg 2.5 }
517 greg 2.8 /* check header from rpict */
518 greg 2.18 guard_io();
519 greg 2.13 getheader(fromrp, NULL, NULL);
520 schorsch 2.41 if (!fscnresolu(&hr, &vr, fromrp) || (hr != hres) | (vr != vres)) {
521 greg 2.3 fprintf(stderr, "%s: resolution mismatch from %s\n",
522     progname, rpargv[0]);
523 greg 2.10 exit(cleanup(1));
524 greg 2.1 }
525 greg 2.24 if (verbose) { /* notify caller */
526     printf("%d %d begun\n", xpos, ypos);
527     fflush(stdout);
528     }
529 greg 2.18 unguard();
530 greg 2.8 /* load new piece into buffer */
531 greg 2.18 for (y = 0; y < vr; y++) {
532     guard_io();
533 greg 2.8 if (freadcolrs(pbuf+y*hr, hr, fromrp) < 0) {
534 greg 2.3 fprintf(stderr, "%s: read error from %s\n",
535     progname, rpargv[0]);
536 greg 2.10 exit(cleanup(1));
537 greg 2.1 }
538 greg 2.18 unguard();
539     }
540 greg 2.9 #if MAXFORK
541     /* fork so we don't slow rpict down */
542     if ((pid = fork()) > 0) {
543 greg 2.10 if (++nforked >= MAXFORK) {
544 greg 2.9 wait(&status); /* reap a child */
545     if (status)
546 greg 2.10 exit(cleanup(status>>8 & 0xff));
547 greg 2.9 nforked--;
548     }
549     return(pid);
550     }
551     #else
552     pid = -1; /* no forking */
553     #endif
554 greg 2.19 fls.l_start = scanorig +
555     ((long)(vmult-1-ypos)*vres*hmult+xpos)*hres*sizeof(COLR);
556 greg 2.12 #if NFS
557 greg 2.19 fls.l_len = ((long)(vres-1)*hmult+1)*hres*sizeof(COLR);
558 greg 2.8 /* lock file section so NFS doesn't mess up */
559     fls.l_whence = 0;
560     fls.l_type = F_WRLCK;
561 greg 2.54 #if 0
562 greg 2.26 if (fcntl(outfd, F_SETLKW, &fls) < 0)
563     filerr("lock");
564 greg 2.54 #else
565     dolock(outfd, F_WRLCK);
566     #endif
567 greg 2.12 #endif
568 greg 2.8 /* write new piece to file */
569 greg 2.42 if (lseek(outfd, (off_t)fls.l_start, SEEK_SET) < 0)
570 greg 2.26 filerr("seek");
571 greg 2.9 if (hmult == 1) {
572 greg 2.62 if (writebuf(outfd, pbuf,
573 greg 2.9 vr*hr*sizeof(COLR)) != vr*hr*sizeof(COLR))
574 greg 2.26 filerr("write");
575 greg 2.9 } else
576     for (y = 0; y < vr; y++) {
577 greg 2.62 if (writebuf(outfd, pbuf+y*hr,
578 greg 2.9 hr*sizeof(COLR)) != hr*sizeof(COLR))
579 greg 2.26 filerr("write");
580 greg 2.9 if (y < vr-1 && lseek(outfd,
581 greg 2.37 (off_t)(hmult-1)*hr*sizeof(COLR),
582 greg 2.42 SEEK_CUR) < 0)
583 greg 2.26 filerr("seek");
584 greg 2.1 }
585 greg 2.25 #if NFS
586     fls.l_type = F_UNLCK; /* release lock */
587 greg 2.54 #if 0
588 greg 2.26 if (fcntl(outfd, F_SETLKW, &fls) < 0)
589     filerr("lock");
590 greg 2.54 #else
591     dolock(outfd, F_UNLCK);
592     #endif
593 greg 2.25 #endif
594 greg 2.32 if (verbose) { /* notify caller */
595     printf("%d %d done\n", xpos, ypos);
596     fflush(stdout);
597     }
598 greg 2.25 if (syncfp != NULL) { /* record what's been done */
599     sflock(F_WRLCK);
600     fseek(syncfp, 0L, 2); /* append index */
601     fprintf(syncfp, "%4d %4d\n", xpos, ypos);
602     fflush(syncfp);
603     /*** Unlock not necessary, since
604     sflock(F_UNLCK); _exit() or nextpiece() is next ***/
605 greg 2.20 }
606 greg 2.25 if (pid == -1) /* didn't fork or fork failed */
607 greg 2.9 return(0);
608 greg 2.25 _exit(0); /* else exit child process (releasing locks) */
609 greg 2.26 }
610    
611    
612 schorsch 2.43 static void
613     filerr( /* report file error and exit */
614     char *t
615     )
616 greg 2.26 {
617     fprintf(stderr, "%s: %s error on file \"%s\": %s\n",
618 greg 2.37 progname, t, outfile, strerror(errno));
619 greg 2.9 _exit(1);
620 greg 2.1 }
621 greg 2.16
622     #endif