ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rpiece.c
(Generate patch)

Comparing ray/src/util/rpiece.c (file contents):
Revision 2.2 by greg, Thu Aug 6 17:16:29 1992 UTC vs.
Revision 2.36 by gwlarson, Thu Jun 18 09:23:49 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 Regents of the University of California */
1 > /* Copyright (c) 1995 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 9 | Line 9 | static char SCCSid[] = "$SunId$ LBL";
9   */
10  
11   #include "standard.h"
12 < #include <fcntl.h>
12 >
13 > #ifndef F_SETLKW
14 >
15 > main(argc, argv)
16 > int argc;
17 > char *argv[];
18 > {
19 >        fprintf(stderr, "%s: no NFS lock manager on this machine\n", argv[0]);
20 >        exit(1);
21 > }
22 >
23 > #else
24 >
25 > #include <signal.h>
26   #include "color.h"
27   #include "view.h"
28   #include "resolu.h"
29  
30 + #ifndef NFS
31 + #define  NFS                    1
32 + #endif
33 +                                /* set the following to 0 to forgo forking */
34 + #ifndef MAXFORK
35 + #if NFS
36 + #define  MAXFORK                3       /* allotment of duped processes */
37 + #else
38 + #define  MAXFORK                0
39 + #endif
40 + #endif
41 +                                        /* protection from SYSV signals(!) */
42 + #if defined(sgi)
43 + #define guard_io()      sighold(SIGALRM)
44 + #define unguard()       sigrelse(SIGALRM)
45 + #endif
46 + #ifndef guard_io
47 + #define guard_io()      0
48 + #define unguard()       0
49 + #endif
50 +
51 + #ifndef linux
52 + extern char  *sys_errlist[];
53 + #endif
54 +
55                                  /* rpict command */
56 < char  *rpargv[128] = {"rpict", "-S", "1", "-x", "512", "-y", "512", };
57 < int  rpargc = 7;
56 > char  *rpargv[128] = {"rpict", "-S", "1"};
57 > int  rpargc = 3;
58   int  rpd[3];
59   FILE  *torp, *fromrp;
60 < COLR  *scanline;
60 > COLR  *pbuf;
61                                  /* our view parameters */
62   VIEW  ourview = STDVIEW;
63 < double  pixaspect = 0.0;
64 < int  hres = 512, vres = 512, hmult = 2, vmult = 2;
63 > double  pixaspect = 1.0;
64 > int  hres = 1024, vres = 1024, hmult = 4, vmult = 4;
65                                  /* output file */
66   char  *outfile = NULL;
67   int  outfd;
68   long  scanorig;
69 + FILE  *syncfp = NULL;           /* synchronization file pointer */
70 + int  synclst = F_UNLCK;         /* synchronization file lock status */
71 + int  nforked = 0;
72  
73 + #define  sflock(t)      if ((t)!=synclst) dolock(fileno(syncfp),synclst=t)
74 +
75   char  *progname;
76   int  verbose = 0;
77 + unsigned  timelim = 0;
78 + int  rvrlim = -1;
79  
80 < extern long  lseek(), ftell();
80 > int  gotalrm = 0;
81 > int  onalrm() { gotalrm++; }
82  
83  
84   main(argc, argv)
# Line 43 | Line 89 | char  *argv[];
89          
90          progname = argv[0];
91          for (i = 1; i < argc; i++) {
92 +                                                /* expand arguments */
93 +                while (rval = expandarg(&argc, &argv, i))
94 +                        if (rval < 0) {
95 +                                fprintf(stderr, "%s: cannot expand '%s'",
96 +                                                argv[0], argv[i]);
97 +                                exit(1);
98 +                        }
99                  if (argv[i][0] == '-')
100                          switch (argv[i][1]) {
101                          case 'v':
# Line 67 | Line 120 | char  *argv[];
120                                  }
121                                  break;
122                          case 'p':               /* pixel aspect ratio? */
123 <                                if (argv[i][2] == 'a' && !argv[i][3])
124 <                                        pixaspect = atof(argv[i+1]);
123 >                                if (argv[i][2] != 'a' || argv[i][3])
124 >                                        break;
125 >                                pixaspect = atof(argv[++i]);
126 >                                continue;
127 >                        case 'T':               /* time limit (hours) */
128 >                                if (argv[i][2])
129 >                                        break;
130 >                                timelim = atof(argv[++i])*3600. + .5;
131                                  break;
132 <                        case 'x':               /* piece x resolution */
133 <                                if (!argv[i][2])
134 <                                        hres = atoi(argv[i+1]);
135 <                                break;
136 <                        case 'y':               /* piece y resolution */
137 <                                if (!argv[i][2])
138 <                                        vres = atoi(argv[i+1]);
139 <                                break;
132 >                        case 'x':               /* overall x resolution */
133 >                                if (argv[i][2])
134 >                                        break;
135 >                                hres = atoi(argv[++i]);
136 >                                continue;
137 >                        case 'y':               /* overall y resolution */
138 >                                if (argv[i][2])
139 >                                        break;
140 >                                vres = atoi(argv[++i]);
141 >                                continue;
142                          case 'X':               /* horizontal multiplier */
143                                  if (argv[i][2])
144                                          break;
# Line 88 | Line 149 | char  *argv[];
149                                          break;
150                                  vmult = atoi(argv[++i]);
151                                  continue;
152 +                        case 'R':               /* recover */
153 +                                if (argv[i][2])
154 +                                        break;
155 +                                rvrlim = 0;
156 +                        /* fall through */
157 +                        case 'F':               /* syncronization file */
158 +                                if (argv[i][2])
159 +                                        break;
160 +                                if ((syncfp =
161 +                fdopen(open(argv[++i],O_RDWR|O_CREAT,0666),"r+")) == NULL) {
162 +                                        fprintf(stderr, "%s: cannot open\n",
163 +                                                        argv[i]);
164 +                                        exit(1);
165 +                                }
166 +                                continue;
167 +                        case 'z':               /* z-file ist verbotten */
168 +                                fprintf(stderr, "%s: -z option not allowed\n",
169 +                                                argv[0]);
170 +                                exit(1);
171                          case 'o':               /* output file */
172                                  if (argv[i][2])
173                                          break;
174                                  outfile = argv[++i];
175                                  continue;
176 <                        }
176 >                        } else if (i >= argc-1)
177 >                                break;
178                  rpargv[rpargc++] = argv[i];
179          }
180 <        rpargv[rpargc] = NULL;
180 >        if (i >= argc) {
181 >                fprintf(stderr, "%s: missing octree argument\n", argv[0]);
182 >                exit(1);
183 >        }
184          if (outfile == NULL) {
185                  fprintf(stderr, "%s: missing output file\n", argv[0]);
186                  exit(1);
187          }
188          init(argc, argv);
189          rpiece();
190 <        rval = cleanup();
107 <        exit(rval);
190 >        exit(cleanup(0));
191   }
192  
193  
194 + dolock(fd, ltyp)                /* lock or unlock a file */
195 + int  fd;
196 + int  ltyp;
197 + {
198 +        static struct flock  fls;       /* static so initialized to zeroes */
199 +
200 +        fls.l_type = ltyp;
201 +        if (fcntl(fd, F_SETLKW, &fls) < 0) {
202 +                fprintf(stderr, "%s: cannot lock/unlock file: %s\n",
203 +                                progname, sys_errlist[errno]);
204 +                exit(1);
205 +        }
206 + }
207 +
208 +
209   init(ac, av)                    /* set up output file and start rpict */
210   int  ac;
211   char  **av;
212   {
213 +        static char  hrbuf[16], vrbuf[16];
214          extern char  VersionID[];
215          char  *err;
216          FILE  *fp;
# Line 121 | Line 220 | char  **av;
220                  fprintf(stderr, "%s: %s\n", progname, err);
221                  exit(1);
222          }
223 +        if (syncfp != NULL) {
224 +                sflock(F_RDLCK);
225 +                fscanf(syncfp, "%d %d", &hmult, &vmult);
226 +                sflock(F_UNLCK);
227 +        }
228 +                                        /* compute piece size */
229 +        hres /= hmult;
230 +        vres /= vmult;
231          normaspect(viewaspect(&ourview)*hmult/vmult, &pixaspect, &hres, &vres);
232 +        sprintf(hrbuf, "%d", hres);
233 +        rpargv[rpargc++] = "-x"; rpargv[rpargc++] = hrbuf;
234 +        sprintf(vrbuf, "%d", vres);
235 +        rpargv[rpargc++] = "-y"; rpargv[rpargc++] = vrbuf;
236 +        rpargv[rpargc++] = "-pa"; rpargv[rpargc++] = "0";
237 +        rpargv[rpargc++] = av[ac-1];
238 +        rpargv[rpargc] = NULL;
239                                          /* open output file */
240          if ((outfd = open(outfile, O_WRONLY|O_CREAT|O_EXCL, 0666)) >= 0) {
241 +                dolock(outfd, F_WRLCK);
242                  if ((fp = fdopen(dup(outfd), "w")) == NULL)
243                          goto filerr;
244 <                printargs(ac, av, fp);          /* write header */
244 >                newheader("RADIANCE", fp);      /* create header */
245 >                printargs(ac, av, fp);
246                  fprintf(fp, "SOFTWARE= %s\n", VersionID);
247                  fputs(VIEWSTR, fp);
248                  fprintview(&ourview, fp);
# Line 137 | Line 253 | char  **av;
253                  putc('\n', fp);
254                  fprtresolu(hres*hmult, vres*vmult, fp);
255          } else if ((outfd = open(outfile, O_RDWR)) >= 0) {
256 <                sleep(30);                      /* wait for header */
256 >                dolock(outfd, F_RDLCK);
257                  if ((fp = fdopen(dup(outfd), "r+")) == NULL)
258                          goto filerr;
259 <                getheader(fp, NULL);            /* skip header */
260 <                if (fscnresolu(&hr, &vr, fp) < 0 ||     /* check resolution */
259 >                getheader(fp, NULL, NULL);      /* skip header */
260 >                if (!fscnresolu(&hr, &vr, fp) ||        /* check resolution */
261                                  hr != hres*hmult || vr != vres*vmult) {
262 <                        fprintf(stderr, "%s: picture resolution mismatch\n",
263 <                                        outfile);
262 >                        fprintf(stderr, "%s: resolution mismatch on file \"%s\"\n",
263 >                                        progname, outfile);
264                          exit(1);
265                  }
266          } else {
267 <                fprintf(stderr, "%s: cannot open\n", outfile);
267 >                fprintf(stderr, "%s: cannot open file \"%s\"\n",
268 >                                progname, outfile);
269                  exit(1);
270          }
271          scanorig = ftell(fp);           /* record position of first scanline */
272          if (fclose(fp) == -1)           /* done with stream i/o */
273                  goto filerr;
274 +        dolock(outfd, F_UNLCK);
275                                          /* start rpict process */
276          if (open_process(rpd, rpargv) <= 0) {
277 <                fprintf(stderr, "%s: cannot start\n", rpargv[0]);
277 >                fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]);
278                  exit(1);
279          }
280          if ((fromrp = fdopen(rpd[0], "r")) == NULL ||
# Line 165 | Line 283 | char  **av;
283                                  progname, rpargv[0]);
284                  exit(1);
285          }
286 <        if ((scanline = (COLR *)malloc(hres*sizeof(COLR))) == NULL) {
286 >        if ((pbuf = (COLR *)bmalloc(hres*vres*sizeof(COLR))) == NULL) {
287                  fprintf(stderr, "%s: out of memory\n", progname);
288                  exit(1);
289          }
290 +        signal(SIGALRM, onalrm);
291 +        if (timelim)
292 +                alarm(timelim);
293          return;
294   filerr:
295 <        fprintf(stderr, "%s: file i/o error\n", outfile);
295 >        fprintf(stderr, "%s: i/o error on file \"%s\"\n", progname, outfile);
296          exit(1);
297   }
298  
299  
300   int
301 < cleanup()                       /* close rpict process and clean up */
301 > nextpiece(xp, yp)               /* get next piece assignment */
302 > int  *xp, *yp;
303   {
304 <        register int  rpstat;
304 >        if (gotalrm)                    /* someone wants us to quit */
305 >                return(0);
306 >        if (syncfp != NULL) {           /* use sync file */
307 >                /*
308 >                 * So we don't necessarily have to lock and unlock the file
309 >                 * multiple times (very slow), we establish an exclusive
310 >                 * lock at the beginning on our synchronization file and
311 >                 * maintain it in the subroutine rvrpiece().
312 >                 */
313 >                sflock(F_WRLCK);
314 >                fseek(syncfp, 0L, 0);           /* read position */
315 >                if (fscanf(syncfp, "%*d %*d %d %d", xp, yp) < 2) {
316 >                        *xp = hmult-1;
317 >                        *yp = vmult;
318 >                }
319 >                if (rvrlim == 0)                /* initialize recovery limit */
320 >                        rvrlim = *xp*vmult + *yp;
321 >                if (rvrpiece(xp, yp)) {         /* do stragglers first */
322 >                        sflock(F_UNLCK);
323 >                        return(1);
324 >                }
325 >                if (--(*yp) < 0) {              /* decrement position */
326 >                        *yp = vmult-1;
327 >                        if (--(*xp) < 0) {      /* all done */
328 >                                sflock(F_UNLCK);
329 >                                return(0);
330 >                        }
331 >                }
332 >                fseek(syncfp, 0L, 0);           /* write new position */
333 >                fprintf(syncfp, "%4d %4d\n%4d %4d\n\n", hmult, vmult, *xp, *yp);
334 >                fflush(syncfp);
335 >                sflock(F_UNLCK);                /* release sync file */
336 >                return(1);
337 >        }
338 >        return(scanf("%d %d", xp, yp) == 2);    /* use stdin */
339 > }
340  
341 <        free((char *)scanline);
341 >
342 > int
343 > rvrpiece(xp, yp)                /* check for recoverable pieces */
344 > register int  *xp, *yp;
345 > {
346 >        static char  *pdone = NULL;     /* which pieces are done */
347 >        static long  readpos = -1;      /* how far we've read */
348 >        register int  i;
349 >        /*
350 >         * This routine is called by nextpiece() with an
351 >         * exclusive lock on syncfp and the file pointer at the
352 >         * appropriate position to read in the finished pieces.
353 >         */
354 >        if (rvrlim < 0)
355 >                return(0);              /* only check if asked */
356 >        if (pdone == NULL)              /* first call */
357 >                pdone = calloc(hmult*vmult, sizeof(char));
358 >        if (pdone == NULL) {
359 >                fprintf(stderr, "%s: out of memory\n", progname);
360 >                exit(1);
361 >        }
362 >        if (readpos != -1)              /* mark what's been done */
363 >                fseek(syncfp, readpos, 0);
364 >        while (fscanf(syncfp, "%d %d", xp, yp) == 2)
365 >                pdone[*xp*vmult+*yp] = 1;
366 >        if (!feof(syncfp)) {
367 >                fprintf(stderr, "%s: format error in sync file\n", progname);
368 >                exit(1);
369 >        }
370 >        readpos = ftell(syncfp);
371 >        i = hmult*vmult;                /* find an unaccounted for piece */
372 >        while (i-- > rvrlim)
373 >                if (!pdone[i]) {
374 >                        *xp = i / vmult;
375 >                        *yp = i % vmult;
376 >                        pdone[i] = 1;   /* consider it done */
377 >                        return(1);
378 >                }
379 >        rvrlim = -1;                    /* nothing left to recover */
380 >        free(pdone);
381 >        pdone = NULL;
382 >        return(0);
383 > }
384 >
385 >
386 > int
387 > cleanup(rstat)                  /* close rpict process and clean up */
388 > int  rstat;
389 > {
390 >        int  status;
391 >
392 >        bfree((char *)pbuf, hres*vres*sizeof(COLR));
393          fclose(torp);
394          fclose(fromrp);
395 <        rpstat = close_process(rpd);
396 <        if (rpstat == -1)
397 <                rpstat = 0;
398 <        return(rpstat);
395 >        while (wait(&status) != -1)
396 >                if (rstat == 0)
397 >                        rstat = status>>8 & 0xff;
398 >        return(rstat);
399   }
400  
401  
402   rpiece()                        /* render picture piece by piece */
403   {
196        extern char  *gets(), *strcat();
404          VIEW  pview;
198        char  buf[48];
405          int  xorg, yorg;
406 <        
407 <        while (gets(buf) != NULL) {
408 <                if (sscanf(buf, "%d %d", &xorg, &yorg) != 2) {
409 <                        fprintf(stderr, "%s: input format error\n", progname);
410 <                        exit(1);
411 <                }
412 <                copystruct(&pview, &ourview);   /* compute view for piece */
413 <                switch (ourview.type) {
414 <                case VT_PER:
415 <                        pview.horiz = 2.*180./PI*atan(
416 <                                        tan(PI/180./2.*ourview.horiz)/hmult );
417 <                        pview.vert = 2.*180./PI*atan(
418 <                                        tan(PI/180./2.*ourview.vert)/vmult );
419 <                        break;
420 <                case VT_PAR:
421 <                case VT_ANG:
422 <                        pview.horiz = ourview.horiz / hmult;
423 <                        pview.vert = ourview.vert / vmult;
424 <                        break;
425 <                case VT_HEM:
426 <                default:
427 <                        fprintf(stderr, "%s: unknown view type '-vt%c'\n",
428 <                                        progname, ourview.type);
429 <                        exit(1);
430 <                }
431 <                pview.hoff += xorg - 0.5*(hmult-1);
432 <                pview.voff += yorg - 0.5*(vmult-1);
406 >                                        /* compute view parameters */
407 >        copystruct(&pview, &ourview);
408 >        switch (ourview.type) {
409 >        case VT_PER:
410 >                pview.horiz = 2.*180./PI*atan(
411 >                                tan(PI/180./2.*ourview.horiz)/hmult );
412 >                pview.vert = 2.*180./PI*atan(
413 >                                tan(PI/180./2.*ourview.vert)/vmult );
414 >                break;
415 >        case VT_PAR:
416 >        case VT_ANG:
417 >                pview.horiz = ourview.horiz / hmult;
418 >                pview.vert = ourview.vert / vmult;
419 >                break;
420 >        case VT_CYL:
421 >                pview.horiz = ourview.horiz / hmult;
422 >                pview.vert = 2.*180./PI*atan(
423 >                                tan(PI/180./2.*ourview.vert)/vmult );
424 >                break;
425 >        case VT_HEM:
426 >                pview.horiz = 2.*180./PI*asin(
427 >                                sin(PI/180./2.*ourview.horiz)/hmult );
428 >                pview.vert = 2.*180./PI*asin(
429 >                                sin(PI/180./2.*ourview.vert)/vmult );
430 >                break;
431 >        default:
432 >                fprintf(stderr, "%s: unknown view type '-vt%c'\n",
433 >                                progname, ourview.type);
434 >                exit(cleanup(1));
435 >        }
436 >                                        /* render each piece */
437 >        while (nextpiece(&xorg, &yorg)) {
438 >                pview.hoff = ourview.hoff*hmult + xorg - 0.5*(hmult-1);
439 >                pview.voff = ourview.voff*vmult + yorg - 0.5*(vmult-1);
440                  fputs(VIEWSTR, torp);
441                  fprintview(&pview, torp);
442                  putc('\n', torp);
443 <                fflush(torp);                   /* assign piece to rpict */
443 >                fflush(torp);                   /* assigns piece to rpict */
444                  putpiece(xorg, yorg);           /* place piece in output */
232                if (verbose) {                  /* notify caller */
233                        strcat(buf, " done\n");
234                        writebuf(fileno(stdout), buf, strlen(buf));
235                }
445          }
446   }
447  
448  
449 + int
450   putpiece(xpos, ypos)            /* get next piece from rpict */
451   int  xpos, ypos;
452   {
453 +        struct flock  fls;
454 +        int  pid, status;
455          int  hr, vr;
456 <        int  y;
457 <
458 <        getheader(fromrp, NULL);        /* discard header info. */
459 <        if (fscnresolu(&hr, &vr, fromrp) < 0 || /* check resolution */
460 <                        hr != hres || vr != vres) {
461 <                fprintf(stderr, "%s: resolution mismatch from rpict\n",
250 <                                progname);
251 <                exit(1);
456 >        register int  y;
457 >                                /* check bounds */
458 >        if (xpos < 0 | ypos < 0 | xpos >= hmult | ypos >= vmult) {
459 >                fprintf(stderr, "%s: requested piece (%d,%d) out of range\n",
460 >                                progname, xpos, ypos);
461 >                exit(cleanup(1));
462          }
463 <        for (y = 0; y < vr; y++) {      /* transfer scanlines */
464 <                if (freadcolrs(scanline, hr, fromrp) < 0) {
465 <                        fprintf(stderr, "%s: read error from rpict\n",
466 <                                        progname);
467 <                        exit(1);
463 >                                /* check header from rpict */
464 >        guard_io();
465 >        getheader(fromrp, NULL, NULL);
466 >        if (!fscnresolu(&hr, &vr, fromrp) || hr != hres | vr != vres) {
467 >                fprintf(stderr, "%s: resolution mismatch from %s\n",
468 >                                progname, rpargv[0]);
469 >                exit(cleanup(1));
470 >        }
471 >        if (verbose) {                          /* notify caller */
472 >                printf("%d %d begun\n", xpos, ypos);
473 >                fflush(stdout);
474 >        }
475 >        unguard();
476 >                                /* load new piece into buffer */
477 >        for (y = 0; y < vr; y++) {
478 >                guard_io();
479 >                if (freadcolrs(pbuf+y*hr, hr, fromrp) < 0) {
480 >                        fprintf(stderr, "%s: read error from %s\n",
481 >                                        progname, rpargv[0]);
482 >                        exit(cleanup(1));
483                  }
484 <                if ((y == 0 || hmult != 1) && lseek(outfd,
485 < scanorig+((long)((vmult-1-ypos)*vres+y)*hmult*hres+xpos*hres)*sizeof(COLR),
486 <                                0) == -1) {
487 <                        fprintf(stderr, "%s: seek error\n", outfile);
488 <                        exit(1);
484 >                unguard();
485 >        }
486 > #if MAXFORK
487 >                                /* fork so we don't slow rpict down */
488 >        if ((pid = fork()) > 0) {
489 >                if (++nforked >= MAXFORK) {
490 >                        wait(&status);          /* reap a child */
491 >                        if (status)
492 >                                exit(cleanup(status>>8 & 0xff));
493 >                        nforked--;
494                  }
495 <                if (writebuf(outfd, (char *)scanline, hr*sizeof(COLR)) !=
496 <                                hr*sizeof(COLR)) {
497 <                        fprintf(stderr, "%s: write error\n", outfile);
498 <                        exit(1);
495 >                return(pid);
496 >        }
497 > #else
498 >        pid = -1;               /* no forking */
499 > #endif
500 >        fls.l_start = scanorig +
501 >                ((long)(vmult-1-ypos)*vres*hmult+xpos)*hres*sizeof(COLR);
502 > #if NFS
503 >        fls.l_len = ((long)(vres-1)*hmult+1)*hres*sizeof(COLR);
504 >                                /* lock file section so NFS doesn't mess up */
505 >        fls.l_whence = 0;
506 >        fls.l_type = F_WRLCK;
507 >        if (fcntl(outfd, F_SETLKW, &fls) < 0)
508 >                filerr("lock");
509 > #endif
510 >                                /* write new piece to file */
511 >        if (lseek(outfd, fls.l_start, 0) < 0)
512 >                filerr("seek");
513 >        if (hmult == 1) {
514 >                if (writebuf(outfd, (char *)pbuf,
515 >                                vr*hr*sizeof(COLR)) != vr*hr*sizeof(COLR))
516 >                        filerr("write");
517 >        } else
518 >                for (y = 0; y < vr; y++) {
519 >                        if (writebuf(outfd, (char *)(pbuf+y*hr),
520 >                                        hr*sizeof(COLR)) != hr*sizeof(COLR))
521 >                                filerr("write");
522 >                        if (y < vr-1 && lseek(outfd,
523 >                                        (long)(hmult-1)*hr*sizeof(COLR),
524 >                                        1) < 0)
525 >                                filerr("seek");
526                  }
527 + #if NFS
528 +        fls.l_type = F_UNLCK;           /* release lock */
529 +        if (fcntl(outfd, F_SETLKW, &fls) < 0)
530 +                filerr("lock");
531 + #endif
532 +        if (verbose) {                          /* notify caller */
533 +                printf("%d %d done\n", xpos, ypos);
534 +                fflush(stdout);
535          }
536 +        if (syncfp != NULL) {                   /* record what's been done */
537 +                sflock(F_WRLCK);
538 +                fseek(syncfp, 0L, 2);           /* append index */
539 +                fprintf(syncfp, "%4d %4d\n", xpos, ypos);
540 +                fflush(syncfp);
541 +                                /*** Unlock not necessary, since
542 +                sflock(F_UNLCK);        _exit() or nextpiece() is next ***/
543 +        }
544 +        if (pid == -1)          /* didn't fork or fork failed */
545 +                return(0);
546 +        _exit(0);               /* else exit child process (releasing locks) */
547   }
548 +
549 +
550 + filerr(t)                       /* report file error and exit */
551 + char  *t;
552 + {
553 +        fprintf(stderr, "%s: %s error on file \"%s\": %s\n",
554 +                        progname, t, outfile, sys_errlist[errno]);
555 +        _exit(1);
556 + }
557 +
558 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines