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); |
117 |
|
} |
118 |
|
continue; |
119 |
+ |
case 'z': /* z-file ist verbotten */ |
120 |
+ |
fprintf(stderr, "%s: -z option not allowed\n", |
121 |
+ |
argv[0]); |
122 |
+ |
exit(1); |
123 |
|
case 'o': /* output file */ |
124 |
|
if (argv[i][2]) |
125 |
|
break; |
135 |
|
} |
136 |
|
init(argc, argv); |
137 |
|
rpiece(); |
138 |
< |
rval = cleanup(0); |
127 |
< |
exit(rval); |
138 |
> |
exit(cleanup(0)); |
139 |
|
} |
140 |
|
|
141 |
|
|
175 |
|
} else if ((outfd = open(outfile, O_RDWR)) >= 0) { |
176 |
|
if ((fp = fdopen(dup(outfd), "r+")) == NULL) |
177 |
|
goto filerr; |
178 |
< |
getheader(fp, NULL); /* skip header */ |
179 |
< |
if (fscnresolu(&hr, &vr, fp) < 0 || /* check resolution */ |
178 |
> |
getheader(fp, NULL, NULL); /* skip header */ |
179 |
> |
if (!fscnresolu(&hr, &vr, fp) || /* check resolution */ |
180 |
|
hr != hres*hmult || vr != vres*vmult) { |
181 |
|
fprintf(stderr, "%s: resolution mismatch on file \"%s\"\n", |
182 |
|
progname, outfile); |
190 |
|
scanorig = ftell(fp); /* record position of first scanline */ |
191 |
|
if (fclose(fp) == -1) /* done with stream i/o */ |
192 |
|
goto filerr; |
193 |
+ |
#if NFS |
194 |
|
sync(); /* flush NFS buffers */ |
195 |
+ |
#endif |
196 |
|
/* start rpict process */ |
197 |
|
if (open_process(rpd, rpargv) <= 0) { |
198 |
|
fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]); |
338 |
|
exit(cleanup(1)); |
339 |
|
} |
340 |
|
/* check header from rpict */ |
341 |
< |
getheader(fromrp, NULL); |
342 |
< |
if (fscnresolu(&hr, &vr, fromrp) < 0 || hr != hres | vr != vres) { |
341 |
> |
getheader(fromrp, NULL, NULL); |
342 |
> |
if (!fscnresolu(&hr, &vr, fromrp) || hr != hres | vr != vres) { |
343 |
|
fprintf(stderr, "%s: resolution mismatch from %s\n", |
344 |
|
progname, rpargv[0]); |
345 |
|
exit(cleanup(1)); |
365 |
|
#else |
366 |
|
pid = -1; /* no forking */ |
367 |
|
#endif |
355 |
– |
/* lock file section so NFS doesn't mess up */ |
356 |
– |
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 |
+ |
#if NFS |
371 |
+ |
/* lock file section so NFS doesn't mess up */ |
372 |
+ |
fls.l_whence = 0; |
373 |
|
fls.l_type = F_WRLCK; |
374 |
|
fcntl(outfd, F_SETLKW, &fls); |
375 |
+ |
#endif |
376 |
|
/* write new piece to file */ |
377 |
|
if (lseek(outfd, fls.l_start+(long)xpos*hres*sizeof(COLR), 0) == -1) |
378 |
|
goto seekerr; |
391 |
|
goto seekerr; |
392 |
|
} |
393 |
|
if (pid == -1) { /* fork failed */ |
394 |
+ |
#if NFS |
395 |
|
fls.l_type = F_UNLCK; /* release lock */ |
396 |
|
fcntl(outfd, F_SETLKW, &fls); |
397 |
+ |
#endif |
398 |
|
return(0); |
399 |
|
} |
400 |
|
_exit(0); /* else exit child process (releasing lock) */ |