--- ray/src/util/rpiece.c 1992/08/07 11:05:30 2.5 +++ ray/src/util/rpiece.c 1992/08/08 18:47:39 2.7 @@ -10,6 +10,7 @@ static char SCCSid[] = "$SunId$ LBL"; #include "standard.h" #include +#include #include "color.h" #include "view.h" #include "resolu.h" @@ -35,7 +36,10 @@ int verbose = 0; extern long lseek(), ftell(); +int gotalrm = 0; +int onalrm() { gotalrm++; } + main(argc, argv) int argc; char *argv[]; @@ -168,7 +172,6 @@ char **av; scanorig = ftell(fp); /* record position of first scanline */ if (fclose(fp) == -1) /* done with stream i/o */ goto filerr; - sync(); /* avoid NFS buffering */ /* start rpict process */ if (open_process(rpd, rpargv) <= 0) { fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]); @@ -184,6 +187,7 @@ char **av; fprintf(stderr, "%s: out of memory\n", progname); exit(1); } + signal(SIGALRM, onalrm); return; filerr: fprintf(stderr, "%s: file i/o error\n", outfile); @@ -199,7 +203,9 @@ int *xp, *yp; struct flock fls; char buf[64]; - if (syncfd != -1) { /* using sync file */ + if (gotalrm) /* someone wants us to quit */ + return(0); + if (syncfd != -1) { /* use sync file */ fls.l_type = F_WRLCK; /* gain exclusive access */ fls.l_whence = 0; fls.l_start = 0L; @@ -225,7 +231,7 @@ int *xp, *yp; fcntl(syncfd, F_SETLKW, &fls); return(1); } - if (fgets(buf, sizeof(buf), stdin) == NULL) /* using stdin */ + if (fgets(buf, sizeof(buf), stdin) == NULL) /* use stdin */ return(0); if (sscanf(buf, "%d %d", xp, yp) == 2) return(1); @@ -297,6 +303,7 @@ rpiece() /* render picture piece by piece */ putpiece(xpos, ypos) /* get next piece from rpict */ int xpos, ypos; { + struct flock fls; int hr, vr; int y; @@ -312,6 +319,9 @@ int xpos, ypos; progname, rpargv[0]); exit(1); } + fls.l_whence = 1; + fls.l_start = 0L; + fls.l_len = hr*sizeof(COLR); for (y = 0; y < vr; y++) { /* transfer scanlines */ if (freadcolrs(scanline, hr, fromrp) < 0) { fprintf(stderr, "%s: read error from %s\n", @@ -324,10 +334,14 @@ scanorig+((long)((vmult-1-ypos)*vres+y)*hmult*hres+xpo fprintf(stderr, "%s: seek error\n", outfile); exit(1); } + fls.l_type = F_WRLCK; + fcntl(outfd, F_SETLKW, &fls); if (writebuf(outfd, (char *)scanline, hr*sizeof(COLR)) != hr*sizeof(COLR)) { fprintf(stderr, "%s: write error\n", outfile); exit(1); } + fls.l_type = F_UNLCK; + fcntl(outfd, F_SETLKW, &fls); } }