| 1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* Holodeck display process communication |
| 6 |
|
*/ |
| 10 |
|
#include <sys/uio.h> |
| 11 |
|
|
| 12 |
|
#ifndef HDSUF |
| 13 |
< |
#define HDSUF ".hdi" |
| 13 |
> |
#define HDSUF ".hdi" |
| 14 |
|
#endif |
| 15 |
+ |
#ifndef SLAVENAME |
| 16 |
+ |
#define SLAVENAME "slave" |
| 17 |
+ |
#endif |
| 18 |
|
|
| 19 |
|
#ifndef FNONBLK |
| 20 |
|
#define FNONBLK O_NONBLOCK |
| 28 |
|
disp_open(dname) /* open the named display driver */ |
| 29 |
|
char *dname; |
| 30 |
|
{ |
| 31 |
< |
char buf[128], fd0[8], fd1[8], *cmd[5], *sfn; |
| 31 |
> |
char buf[sizeof(HDGRID)+512], fd0[8], fd1[8], *cmd[5], *sfn; |
| 32 |
|
int i, n, len; |
| 33 |
< |
/* get full display program name */ |
| 33 |
> |
|
| 34 |
> |
if (!strcmp(dname, SLAVENAME)) { |
| 35 |
> |
dpd[0] = 0; /* read from stdin */ |
| 36 |
> |
dpout = stdout; /* write to stdout */ |
| 37 |
> |
dpd[2] = -1; /* we're the slave process */ |
| 38 |
> |
} else { |
| 39 |
> |
/* get full display program name */ |
| 40 |
|
#ifdef DEVPATH |
| 41 |
< |
sprintf(buf, "%s/%s%s", DEVPATH, dname, HDSUF); |
| 41 |
> |
sprintf(buf, "%s/%s%s", DEVPATH, dname, HDSUF); |
| 42 |
|
#else |
| 43 |
< |
sprintf(buf, "dev/%s%s", dname, HDSUF); |
| 43 |
> |
sprintf(buf, "dev/%s%s", dname, HDSUF); |
| 44 |
|
#endif |
| 45 |
< |
/* dup stdin and stdout */ |
| 46 |
< |
if (readinp) |
| 47 |
< |
sprintf(fd0, "%d", dup(0)); |
| 48 |
< |
else |
| 49 |
< |
strcpy(fd0, "-1"); |
| 50 |
< |
sprintf(fd1, "%d", dup(1)); |
| 51 |
< |
/* start the display process */ |
| 52 |
< |
cmd[0] = buf; |
| 53 |
< |
cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0; |
| 54 |
< |
cmd[4] = NULL; |
| 55 |
< |
i = open_process(dpd, cmd); |
| 56 |
< |
if (i <= 0) |
| 57 |
< |
error(USER, "cannot start display process"); |
| 58 |
< |
if ((dpout = fdopen(dpd[1], "w")) == NULL) |
| 59 |
< |
error(SYSTEM, "cannot associate FILE with display pipe"); |
| 45 |
> |
/* dup stdin and stdout */ |
| 46 |
> |
if (readinp) |
| 47 |
> |
sprintf(fd0, "%d", dup(0)); |
| 48 |
> |
else |
| 49 |
> |
strcpy(fd0, "-1"); |
| 50 |
> |
sprintf(fd1, "%d", dup(1)); |
| 51 |
> |
/* start the display process */ |
| 52 |
> |
cmd[0] = buf; |
| 53 |
> |
cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0; |
| 54 |
> |
cmd[4] = NULL; |
| 55 |
> |
i = open_process(dpd, cmd); |
| 56 |
> |
if (i <= 0) |
| 57 |
> |
error(USER, "cannot start display process"); |
| 58 |
> |
if ((dpout = fdopen(dpd[1], "w")) == NULL) |
| 59 |
> |
error(SYSTEM, "problem opening display pipe"); |
| 60 |
> |
/* close dup'ed stdin and stdout */ |
| 61 |
> |
if (readinp) |
| 62 |
> |
close(atoi(fd0)); |
| 63 |
> |
close(atoi(fd1)); |
| 64 |
> |
} |
| 65 |
|
dpd[1] = -1; /* causes ignored error in close_process() */ |
| 66 |
|
inp_flags = 0; |
| 56 |
– |
/* close dup'ed stdin and stdout */ |
| 57 |
– |
if (readinp) |
| 58 |
– |
close(atoi(fd0)); |
| 59 |
– |
close(atoi(fd1)); |
| 67 |
|
/* check if outside */ |
| 68 |
|
if (vdef(OBSTRUCTIONS) && vbool(OBSTRUCTIONS)) |
| 69 |
|
disp_result(DS_OUTSECT, 0, NULL); |
| 213 |
|
case DR_CLOBBER: /* clobber holodeck */ |
| 214 |
|
if (msg.nbytes) |
| 215 |
|
error(INTERNAL, "bad DR_CLOBBER from display process"); |
| 216 |
< |
if (!force || !ncprocs) |
| 216 |
> |
if (force <= 0 | ncprocs <= 0) |
| 217 |
|
error(WARNING, "request to clobber holodeck denied"); |
| 218 |
|
else { |
| 219 |
|
error(WARNING, "clobbering holodeck contents"); |
| 250 |
|
disp_result(DS_SHUTDOWN, 0, NULL); |
| 251 |
|
fclose(dpout); |
| 252 |
|
dpout = NULL; |
| 253 |
< |
return(close_process(dpd)); |
| 253 |
> |
return(dpd[2]<0 ? 0 : close_process(dpd)); |
| 254 |
|
} |
| 255 |
|
|
| 256 |
|
|