static char *rcsid
= "$Header: /f/osi/quipu/dish/RCS/pipe.c,v 7.2 91/02/22 09:40:48 mrose Interim $";
* $Header: /f/osi/quipu/dish/RCS/pipe.c,v 7.2 91/02/22 09:40:48 mrose Interim $
* Revision 7.2 91/02/22 09:40:48 mrose
* Revision 7.1 90/07/09 14:47:21 mrose
* Revision 7.0 89/11/23 22:20:17 mrose
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
#define MIN(a,b) (( (b) < (a) ) ? (b) : (a) )
struct sockaddr_in sin_buf
;
struct sockaddr_in
*sin
= &sin_buf
;
if ((cp
= getenv ("DISHPARENT")) == NULLCP
) {
(void) sprintf (parent
, "%d", getppid ());
(void) setenv ("DISHPARENT", cp
= parent
);
if (sscanf (cp
, "%d", &parent_pid
) != 1) {
(void) fprintf (stderr
,"DISHPARENT malformed");
if (get_dish_sock (sin
) != 0)
if ((sd
= start_tcp_server (sin
, SOMAXCONN
, 0, 0)) == NOTOK
) {
perror ("start_tcp_server");
(void) ioctl (sd
, FIOCLEX
, NULLCP
);
if ((cp
= getenv ("DISHPROC")) == NULL
) {
(void) fprintf (stderr
, "no DISHPROC in environment\n");
(void) strcpy (retpipe
, cp
);
if ((fd
= open (retpipe
, O_RDONLY
)) < 0) {
(void) mknod (retpipe
, S_IFIFO
| 0600, 0);
if ((fd
= open (retpipe
, O_RDONLY
)) < 0) {
(void) fprintf (stderr
, "ropen failed\n");
if ((wfd
= open (retpipe
, O_WRONLY
)) < 0) {
(void) fprintf (stderr
, "wr open failed\n");
if ((xsd
= open ("/dev/tty", O_RDWR
)) != NOTOK
) {
(void) ioctl (xsd
, TIOCNOTTY
, NULLCP
);
(void) signal (SIGINT
, SIG_IGN
);
(void) signal (SIGQUIT
, SIG_IGN
);
(void) close_tcp_socket (sd
);
while ((sd_current
= join_tcp_client (sd
, &sock
)) == NOTOK
) {
perror("join_tcp_client");
(void) ioctl (sd_current
, FIOCLEX
, NULLCP
);
return (read_pipe_aux(buf
,len
));
ep
= (cp
= buf
) + len
- 1;
switch (res
= recv (sd_current
, cp
, ep
- cp
, 0)) {
(void) close (sd_current
);
if ((res
= read (fd
, buf
, len
)) <= 0) {
int read_pipe_aux2 (buf
, len
)
switch (res
= read_pipe_aux (buffer
, sizeof buffer
)) {
*buf
= buffer
, *len
= res
;
if (sscanf (buffer
+ 1, "%d", &cc
) != 1 || cc
< 0) {
(void) fprintf (stderr
, "protocol botch\n");
if ((cp
= malloc ((unsigned) cc
+ 1)) == NULL
) {
if (ep
= index (buffer
+ 1, '\n')) {
(void) strcpy (dp
, ++ep
);
for (; j
> 0; dp
+= i
, j
-= i
)
switch (i
= recv (sd_current
, dp
, j
, 0)) {
(void) close (sd_current
);
(void) fprintf (stderr
, "premature eof from peer\n");
send_pipe_aux2 (buf
, strlen (buf
));
if ((file
= open (inbuf
, O_WRONLY
)) <= 0) {
(void) fprintf (stderr
, "error %s on %s\n",sys_errname (errno
), inbuf
);
if ( (res
= send(sd_current
, buf
, i
, 0)) == -1) {
(void) close (sd_current
);
if ((res
= write (file
, buf
, MIN (BUFSIZ
,i
))) == -1 ) {
(void) fprintf (stderr
,"result write error (2)\n");
struct sockaddr_in
*isock
;
register struct hostent
*hp
;
if ((ptr
= getenv ("DISHPROC")) == NULLCP
) {
portno
= (getppid () & 0xffff) | 0x8000;
if ((hp
= gethostbystring (cp
= getlocalhost ())) == NULL
) {
(void) fprintf (stderr
,"%s: unknown host", cp
);
(void) sprintf (buffer
, "%s %d",
inet_ntoa (*(struct in_addr
*) hp
-> h_addr
),
(void) sprintf (buffer
, "127.0.0.1 %d", portno
);
(void) setenv ("DISHPROC", ptr
= buffer
);
if ((dp
= index (ptr
, ' ')) == NULLCP
|| sscanf (dp
+ 1, "%d", &portno
) != 1) {
(void) fprintf (stderr
,"DISHPROC malformed");
if ((hp
= gethostbystring (ptr
)) == NULL
) {
(void) fprintf (stderr
,"%s: unknown host in DISHPROC", ptr
);
bzero ((char *) isock
, sizeof *isock
);
isock
-> sin_family
= hp
-> h_addrtype
;
isock
-> sin_port
= htons ((u_short
) portno
);
if ((fd
= open (retpipe
, O_RDONLY
)) < 0) {
(void) fprintf (stderr
, "re-ropen failed\n");
if ((wfd
= open (retpipe
, O_WRONLY
)) < 0) {
(void) fprintf (stderr
, "re-wr open failed\n");