1 |
< |
/* Copyright (c) 1993 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"; |
25 |
|
|
26 |
|
extern int headismine; /* boolean true if header belongs to me */ |
27 |
|
|
28 |
+ |
extern char *progname; /* global program name */ |
29 |
+ |
|
30 |
|
static char *persistfname = NULL; /* persist file name */ |
31 |
|
static int persistfd = -1; /* persist file descriptor */ |
32 |
|
|
97 |
|
|
98 |
|
pfhold() /* holding pattern for idle rendering process */ |
99 |
|
{ |
100 |
< |
char buf[128]; |
100 |
> |
char buf[512]; |
101 |
|
register int n; |
102 |
|
/* close input and output descriptors */ |
103 |
|
close(fileno(stdin)); |
104 |
|
close(fileno(stdout)); |
105 |
|
/* create named pipes for input and output */ |
106 |
< |
if (mknod(mktemp(strcpy(inpname,TEMPLATE)), S_IFIFO|0600) < 0) |
106 |
> |
if (mknod(mktemp(strcpy(inpname,TEMPLATE)), S_IFIFO|0600, 0) < 0) |
107 |
|
goto createrr; |
108 |
< |
if (mknod(mktemp(strcpy(outpname,TEMPLATE)), S_IFIFO|0600) < 0) |
108 |
> |
if (mknod(mktemp(strcpy(outpname,TEMPLATE)), S_IFIFO|0600, 0) < 0) |
109 |
|
goto createrr; |
110 |
< |
sprintf(buf, "%d\n%s\n%s\n", getpid(), inpname, outpname); |
111 |
< |
if (lseek(persistfd, 0L, 0) < 0) |
112 |
< |
error(SYSTEM, "seek error on persist file in pfhold"); |
110 |
> |
sprintf(buf, "%s %d\n%s\n%s\n", progname, getpid(), inpname, outpname); |
111 |
> |
if (lseek(persistfd, 0L, 0) < 0 || ftruncate(persistfd, 0L) < 0) |
112 |
> |
error(SYSTEM, "seek/truncate error on persist file"); |
113 |
|
n = strlen(buf); |
114 |
|
if (write(persistfd, buf, n) < n) |
115 |
< |
error(SYSTEM, "error writing persist file in pfhold"); |
115 |
> |
error(SYSTEM, "error writing persist file"); |
116 |
|
/* wait TIMELIM for someone to signal us */ |
117 |
|
signal(SIGIO, sig_noop); |
118 |
|
alarm(TIMELIM); |
142 |
|
{ |
143 |
|
register char *cp; |
144 |
|
register int nr, n; |
145 |
< |
char buf[4096], *pfin, *pfout; |
145 |
> |
char buf[512], *pfin, *pfout; |
146 |
|
int pid; |
147 |
|
/* load and close persist file */ |
148 |
< |
nr = read(persistfd, buf, sizeof(buf)); |
148 |
> |
nr = read(persistfd, buf, sizeof(buf)-1); |
149 |
|
pfdetach(); |
150 |
|
if (nr < 0) |
151 |
|
error(SYSTEM, "cannot read persist file"); |
152 |
|
buf[nr] = '\0'; |
153 |
< |
if ((cp = index(buf, '\n')) == NULL) |
153 |
> |
if ((cp = index(buf, ' ')) == NULL) |
154 |
|
goto formerr; |
155 |
|
*cp++ = '\0'; |
156 |
< |
if ((pid = atoi(buf)) <= 0) |
156 |
> |
if ((pid = atoi(cp)) <= 0) |
157 |
|
goto formerr; |
156 |
– |
pfin = cp; |
158 |
|
if ((cp = index(cp, '\n')) == NULL) |
159 |
|
goto formerr; |
160 |
+ |
pfin = ++cp; |
161 |
+ |
if ((cp = index(cp, '\n')) == NULL) |
162 |
+ |
goto formerr; |
163 |
|
*cp++ = '\0'; |
164 |
|
pfout = cp; |
165 |
|
if ((cp = index(cp, '\n')) == NULL) |
167 |
|
*cp++ = '\0'; |
168 |
|
if (cp-buf != nr) |
169 |
|
goto formerr; |
170 |
+ |
if (strcmp(buf, progname)) { |
171 |
+ |
sprintf(errmsg, "persist file for %s, not %s", buf, progname); |
172 |
+ |
error(USER, errmsg); |
173 |
+ |
} |
174 |
|
/* wake up rendering process */ |
175 |
|
if (kill(pid, SIGIO) < 0) |
176 |
|
error(SYSTEM, "cannot signal rendering process in io_process"); |
188 |
|
error(SYSTEM, "cannot open output pipe in io_process"); |
189 |
|
} |
190 |
|
/* pass input to output */ |
191 |
< |
cp = buf; n = sizeof(buf); |
192 |
< |
/* do as much as we can each way */ |
193 |
< |
while ((nr = read(0, cp, n)) > 0) { |
194 |
< |
nr += cp-buf; |
195 |
< |
if ((n = write(1, buf, nr)) <= 0) |
196 |
< |
goto writerr; |
197 |
< |
cp = buf; |
190 |
< |
while (n < nr) |
191 |
< |
*cp++ = buf[n++]; |
192 |
< |
n = sizeof(buf) - (cp-buf); |
193 |
< |
} |
191 |
> |
/* read as much as we can, write all of it */ |
192 |
> |
while ((nr = read(0, cp=buf, sizeof(buf))) > 0) |
193 |
> |
do { |
194 |
> |
if ((n = write(1, cp, nr)) <= 0) |
195 |
> |
goto writerr; |
196 |
> |
cp += n; |
197 |
> |
} while ((nr -= n) > 0); |
198 |
|
if (nr < 0) |
199 |
|
error(SYSTEM, "read error in io_process"); |
200 |
|
close(0); /* close input */ |
197 |
– |
nr = cp-buf; /* write remainder */ |
198 |
– |
cp = buf; |
199 |
– |
while (nr > 0) { |
200 |
– |
if ((n = write(1, cp, nr)) <= 0) |
201 |
– |
goto writerr; |
202 |
– |
cp += n; |
203 |
– |
nr -= n; |
204 |
– |
} |
201 |
|
close(1); /* close output */ |
202 |
|
if (pid) /* parent waits for child */ |
203 |
|
wait(0); |