15 |
|
#include "view.h" |
16 |
|
#include "resolu.h" |
17 |
|
|
18 |
+ |
#ifndef NFS |
19 |
+ |
#define NFS 1 |
20 |
+ |
#endif |
21 |
|
/* set the following to 0 to forgo forking */ |
22 |
|
#ifndef MAXFORK |
23 |
+ |
#if NFS |
24 |
|
#define MAXFORK 3 /* allotment of duped processes */ |
25 |
+ |
#else |
26 |
+ |
#define MAXFORK 0 |
27 |
|
#endif |
28 |
+ |
#endif |
29 |
|
|
30 |
|
/* rpict command */ |
31 |
|
char *rpargv[128] = {"rpict", "-S", "1", "-x", "512", "-y", "512", "-pa", "1"}; |
109 |
|
case 'F': /* syncronization file */ |
110 |
|
if (argv[i][2]) |
111 |
|
break; |
112 |
< |
if ((syncfd = open(argv[++i], O_RDWR)) < 0) { |
112 |
> |
if ((syncfd = open(argv[++i], |
113 |
> |
O_RDWR|O_CREAT, 0666)) < 0) { |
114 |
|
fprintf(stderr, "%s: cannot open\n", |
115 |
|
argv[i]); |
116 |
|
exit(1); |
172 |
|
} else if ((outfd = open(outfile, O_RDWR)) >= 0) { |
173 |
|
if ((fp = fdopen(dup(outfd), "r+")) == NULL) |
174 |
|
goto filerr; |
175 |
< |
getheader(fp, NULL); /* skip header */ |
175 |
> |
getheader(fp, NULL, NULL); /* skip header */ |
176 |
|
if (fscnresolu(&hr, &vr, fp) < 0 || /* check resolution */ |
177 |
|
hr != hres*hmult || vr != vres*vmult) { |
178 |
|
fprintf(stderr, "%s: resolution mismatch on file \"%s\"\n", |
187 |
|
scanorig = ftell(fp); /* record position of first scanline */ |
188 |
|
if (fclose(fp) == -1) /* done with stream i/o */ |
189 |
|
goto filerr; |
190 |
+ |
#if NFS |
191 |
|
sync(); /* flush NFS buffers */ |
192 |
+ |
#endif |
193 |
|
/* start rpict process */ |
194 |
|
if (open_process(rpd, rpargv) <= 0) { |
195 |
|
fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]); |
335 |
|
exit(cleanup(1)); |
336 |
|
} |
337 |
|
/* check header from rpict */ |
338 |
< |
getheader(fromrp, NULL); |
338 |
> |
getheader(fromrp, NULL, NULL); |
339 |
|
if (fscnresolu(&hr, &vr, fromrp) < 0 || hr != hres | vr != vres) { |
340 |
|
fprintf(stderr, "%s: resolution mismatch from %s\n", |
341 |
|
progname, rpargv[0]); |
362 |
|
#else |
363 |
|
pid = -1; /* no forking */ |
364 |
|
#endif |
365 |
+ |
#if NFS |
366 |
|
/* lock file section so NFS doesn't mess up */ |
367 |
|
fls.l_whence = 0; |
368 |
|
fls.l_len = (long)vres*hmult*hres*sizeof(COLR); |
369 |
|
fls.l_start = scanorig + (vmult-1-ypos)*fls.l_len; |
370 |
|
fls.l_type = F_WRLCK; |
371 |
|
fcntl(outfd, F_SETLKW, &fls); |
372 |
+ |
#endif |
373 |
|
/* write new piece to file */ |
374 |
|
if (lseek(outfd, fls.l_start+(long)xpos*hres*sizeof(COLR), 0) == -1) |
375 |
|
goto seekerr; |
388 |
|
goto seekerr; |
389 |
|
} |
390 |
|
if (pid == -1) { /* fork failed */ |
391 |
+ |
#if NFS |
392 |
|
fls.l_type = F_UNLCK; /* release lock */ |
393 |
|
fcntl(outfd, F_SETLKW, &fls); |
394 |
+ |
#endif |
395 |
|
return(0); |
396 |
|
} |
397 |
|
_exit(0); /* else exit child process (releasing lock) */ |