1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
13 |
|
#include <sys/uio.h> |
14 |
|
|
15 |
|
#ifndef HDSUF |
16 |
< |
#define HDSUF ".hdisp" |
16 |
> |
#define HDSUF ".hdi" |
17 |
|
#endif |
18 |
|
|
19 |
|
static int inp_flags; |
20 |
|
static int dpd[3]; |
21 |
< |
static int pipesiz; |
21 |
> |
static FILE *dpout; |
22 |
|
|
23 |
|
|
24 |
|
disp_open(dname) /* open the named display driver */ |
25 |
|
char *dname; |
26 |
|
{ |
27 |
< |
char dpath[128], *com[2]; |
27 |
> |
char dpath[128], fd0[8], fd1[8], *cmd[5]; |
28 |
|
int i; |
29 |
< |
|
29 |
> |
/* get full display program name */ |
30 |
|
#ifdef DEVPATH |
31 |
|
sprintf(dpath, "%s/%s%s", DEVPATH, dname, HDSUF); |
32 |
|
#else |
33 |
|
sprintf(dpath, "dev/%s%s", dname, HDSUF); |
34 |
|
#endif |
35 |
< |
com[0] = dpath; com[1] = NULL; |
36 |
< |
pipesiz = open_process(dpd, com); |
37 |
< |
if (pipesiz <= 0) |
35 |
> |
/* dup stdin and stdout */ |
36 |
> |
if (readinp) |
37 |
> |
sprintf(fd0, "%d", dup(0)); |
38 |
> |
else |
39 |
> |
strcpy(fd0, "-1"); |
40 |
> |
sprintf(fd1, "%d", dup(1)); |
41 |
> |
/* start the display process */ |
42 |
> |
cmd[0] = dpath; |
43 |
> |
cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0; |
44 |
> |
cmd[4] = NULL; |
45 |
> |
i = open_process(dpd, cmd); |
46 |
> |
if (i <= 0) |
47 |
|
error(USER, "cannot start display process"); |
48 |
+ |
if ((dpout = fdopen(dpd[1], "w")) == NULL) |
49 |
+ |
error(SYSTEM, "cannot associate FILE with display pipe"); |
50 |
+ |
dpd[1] = -1; /* causes ignored error in close_process() */ |
51 |
|
inp_flags = 0; |
52 |
+ |
/* close dup'ed stdin and stdout */ |
53 |
+ |
if (readinp) |
54 |
+ |
close(atoi(fd0)); |
55 |
+ |
close(atoi(fd1)); |
56 |
+ |
/* check if outside */ |
57 |
+ |
if (vdef(OBSTRUCTIONS) && vbool(OBSTRUCTIONS)) |
58 |
+ |
disp_result(DS_OUTSECT, 0, NULL); |
59 |
+ |
/* send eye separation if specified */ |
60 |
+ |
if (vdef(EYESEP)) { |
61 |
+ |
char fbuf[32]; |
62 |
+ |
sprintf(fbuf, "%.9e", vflt(EYESEP)); |
63 |
+ |
disp_result(DS_EYESEP, strlen(fbuf)+1, fbuf); |
64 |
+ |
} |
65 |
|
/* write out hologram grids */ |
66 |
|
for (i = 0; hdlist[i] != NULL; i++) |
67 |
|
disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]); |
68 |
+ |
disp_flush(); |
69 |
|
} |
70 |
|
|
71 |
|
|
83 |
|
int n; |
84 |
|
char *buf = NULL; |
85 |
|
|
86 |
< |
if (pipesiz <= 0) |
86 |
> |
if (dpout == NULL) |
87 |
|
return(-1); |
88 |
+ |
/* flush display output */ |
89 |
+ |
disp_flush(); |
90 |
|
/* check read blocking */ |
91 |
|
if (block != (inp_flags == 0)) { |
92 |
|
inp_flags = block ? 0 : FNONBLK; |
96 |
|
/* read message header */ |
97 |
|
n = read(dpd[0], (char *)&msg, sizeof(MSGHEAD)); |
98 |
|
if (n != sizeof(MSGHEAD)) { |
99 |
< |
if (n >= 0) |
99 |
> |
if (n >= 0) { |
100 |
> |
dpout = NULL; |
101 |
|
error(USER, "display process died"); |
102 |
+ |
} |
103 |
|
if (errno != EAGAIN & errno != EINTR) |
104 |
|
goto readerr; |
105 |
|
return(2); /* acceptable failure */ |
108 |
|
buf = (char *)malloc(msg.nbytes); |
109 |
|
if (buf == NULL) |
110 |
|
error(SYSTEM, "out of memory in disp_check"); |
111 |
< |
if (fcntl(dpd[0], F_SETFL, inp_flags=0) < 0) |
111 |
> |
if (inp_flags != 0 && fcntl(dpd[0], F_SETFL, inp_flags=0) < 0) |
112 |
|
goto fcntlerr; |
113 |
|
if (readbuf(dpd[0], buf, msg.nbytes) != msg.nbytes) |
114 |
|
goto readerr; |
115 |
|
} |
116 |
|
switch (msg.type) { /* take appropriate action */ |
117 |
< |
case DR_BUNDLE: |
117 |
> |
case DR_BUNDLE: /* new bundle to calculate */ |
118 |
|
if (msg.nbytes != sizeof(PACKHEAD)) |
119 |
|
error(INTERNAL, "bad DR_BUNDLE from display process"); |
120 |
|
bundle_set(BS_ADD, (PACKHEAD *)buf, 1); |
121 |
|
break; |
122 |
< |
case DR_NEWSET: |
122 |
> |
case DR_NEWSET: /* new calculation set */ |
123 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
124 |
|
error(INTERNAL, "bad DR_NEWSET from display process"); |
125 |
< |
disp_result(DS_STARTIMM, 0, NULL); |
125 |
> |
if (msg.nbytes) |
126 |
> |
disp_result(DS_STARTIMM, 0, NULL); |
127 |
|
bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
128 |
< |
disp_result(DS_ENDIMM, 0, NULL); |
128 |
> |
if (msg.nbytes) { |
129 |
> |
disp_result(DS_ENDIMM, 0, NULL); |
130 |
> |
disp_flush(); |
131 |
> |
} |
132 |
|
break; |
133 |
< |
case DR_ADDSET: |
133 |
> |
case DR_ADDSET: /* add to calculation set */ |
134 |
> |
if (!msg.nbytes) |
135 |
> |
break; |
136 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
137 |
|
error(INTERNAL, "bad DR_ADDSET from display process"); |
138 |
|
disp_result(DS_STARTIMM, 0, NULL); |
139 |
|
bundle_set(BS_ADD, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
140 |
|
disp_result(DS_ENDIMM, 0, NULL); |
141 |
+ |
disp_flush(); |
142 |
|
break; |
143 |
< |
case DR_DELSET: |
143 |
> |
case DR_ADJSET: /* adjust calculation set members */ |
144 |
> |
if (!msg.nbytes) |
145 |
> |
break; |
146 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
147 |
+ |
error(INTERNAL, "bad DR_ADJSET from display process"); |
148 |
+ |
disp_result(DS_STARTIMM, 0, NULL); |
149 |
+ |
bundle_set(BS_ADJ, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
150 |
+ |
disp_result(DS_ENDIMM, 0, NULL); |
151 |
+ |
disp_flush(); |
152 |
+ |
break; |
153 |
+ |
case DR_DELSET: /* delete from calculation set */ |
154 |
+ |
if (!msg.nbytes) |
155 |
+ |
break; |
156 |
+ |
if (msg.nbytes % sizeof(PACKHEAD)) |
157 |
|
error(INTERNAL, "bad DR_DELSET from display process"); |
158 |
|
bundle_set(BS_DEL, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
159 |
|
break; |
160 |
< |
case DR_ATTEN: |
160 |
> |
case DR_ATTEN: /* block for priority request */ |
161 |
|
if (msg.nbytes) |
162 |
|
error(INTERNAL, "bad DR_ATTEN from display process"); |
163 |
|
/* send acknowledgement */ |
164 |
|
disp_result(DS_ACKNOW, 0, NULL); |
165 |
|
return(disp_check(1)); /* block on following request */ |
166 |
< |
case DR_SHUTDOWN: |
166 |
> |
case DR_KILL: /* kill computation process(es) */ |
167 |
|
if (msg.nbytes) |
168 |
+ |
error(INTERNAL, "bad DR_KILL from display process"); |
169 |
+ |
if (nprocs > 0) |
170 |
+ |
done_rtrace(); |
171 |
+ |
else |
172 |
+ |
error(WARNING, "no rtrace process to kill"); |
173 |
+ |
break; |
174 |
+ |
case DR_RESTART: /* restart computation process(es) */ |
175 |
+ |
if (msg.nbytes) |
176 |
+ |
error(INTERNAL, "bad DR_RESTART from display process"); |
177 |
+ |
if (ncprocs > nprocs) |
178 |
+ |
new_rtrace(); |
179 |
+ |
else if (nprocs > 0) |
180 |
+ |
error(WARNING, "rtrace already runnning"); |
181 |
+ |
else |
182 |
+ |
error(WARNING, "holodeck not open for writing"); |
183 |
+ |
break; |
184 |
+ |
case DR_CLOBBER: /* clobber holodeck */ |
185 |
+ |
if (msg.nbytes) |
186 |
+ |
error(INTERNAL, "bad DR_CLOBBER from display process"); |
187 |
+ |
if (!force || !ncprocs) |
188 |
+ |
error(WARNING, "request to clobber holodeck denied"); |
189 |
+ |
else { |
190 |
+ |
error(WARNING, "clobbering holodeck contents"); |
191 |
+ |
hdclobber(NULL); |
192 |
+ |
} |
193 |
+ |
break; |
194 |
+ |
case DR_SHUTDOWN: /* shut down program */ |
195 |
+ |
if (msg.nbytes) |
196 |
|
error(INTERNAL, "bad DR_SHUTDOWN from display process"); |
197 |
|
return(0); /* zero return signals shutdown */ |
198 |
+ |
case DR_NOOP: /* do nothing */ |
199 |
+ |
break; |
200 |
|
default: |
201 |
|
error(INTERNAL, "unrecognized request from display process"); |
202 |
|
} |
215 |
|
{ |
216 |
|
int rval; |
217 |
|
|
218 |
< |
if (pipesiz <= 0) |
218 |
> |
if (dpout == NULL) |
219 |
|
return(-1); |
220 |
|
disp_result(DS_SHUTDOWN, 0, NULL); |
221 |
< |
pipesiz = 0; |
221 |
> |
fclose(dpout); |
222 |
> |
dpout = NULL; |
223 |
|
return(close_process(dpd)); |
224 |
|
} |
225 |
|
|
226 |
|
|
227 |
< |
disp_result(type, nbytes, p) /* send result message to display process */ |
227 |
> |
disp_result(type, nbytes, p) /* queue result message to display process */ |
228 |
|
int type, nbytes; |
229 |
|
char *p; |
230 |
|
{ |
151 |
– |
struct iovec iov[2]; |
231 |
|
MSGHEAD msg; |
153 |
– |
int n; |
232 |
|
|
233 |
< |
if (pipesiz <= 0) |
233 |
> |
if (dpout == NULL) |
234 |
|
return; |
235 |
|
msg.type = type; |
236 |
|
msg.nbytes = nbytes; |
237 |
< |
if (nbytes == 0 || sizeof(MSGHEAD)+nbytes > pipesiz) { |
238 |
< |
do |
239 |
< |
n = write(dpd[1], (char *)&msg, sizeof(MSGHEAD)); |
240 |
< |
while (n < 0 && errno == EINTR); |
241 |
< |
if (n != sizeof(MSGHEAD)) |
242 |
< |
goto writerr; |
243 |
< |
if (nbytes > 0 && writebuf(dpd[1], p, nbytes) != nbytes) |
244 |
< |
goto writerr; |
245 |
< |
return; |
246 |
< |
} |
169 |
< |
iov[0].iov_base = (char *)&msg; |
170 |
< |
iov[0].iov_len = sizeof(MSGHEAD); |
171 |
< |
iov[1].iov_base = p; |
172 |
< |
iov[1].iov_len = nbytes; |
173 |
< |
do |
174 |
< |
n = writev(dpd[1], iov, 2); |
175 |
< |
while (n < 0 && errno == EINTR); |
176 |
< |
if (n == sizeof(MSGHEAD)+nbytes) |
177 |
< |
return; |
178 |
< |
writerr: |
179 |
< |
error(SYSTEM, "write error in disp_result"); |
237 |
> |
fwrite((char *)&msg, sizeof(MSGHEAD), 1, dpout); |
238 |
> |
if (nbytes > 0) |
239 |
> |
fwrite(p, 1, nbytes, dpout); |
240 |
> |
} |
241 |
> |
|
242 |
> |
|
243 |
> |
disp_flush() /* flush output to display */ |
244 |
> |
{ |
245 |
> |
if (fflush(dpout) < 0) |
246 |
> |
error(SYSTEM, "error writing to the display process"); |
247 |
|
} |