/* unbind.c - dish shell unbind and squid commands */
static char *rcsid
= "$Header: /f/osi/others/quipu/uips/dish/RCS/unbind.c,v 7.2 91/02/22 09:30:31 mrose Interim $";
* $Header: /f/osi/others/quipu/uips/dish/RCS/unbind.c,v 7.2 91/02/22 09:30:31 mrose Interim $
* Revision 7.2 91/02/22 09:30:31 mrose
* Revision 7.1 90/03/15 11:20:40 mrose
* Revision 7.0 89/11/23 22:08:35 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
#ifdef SOCKETS /* USE INTERNET SOCKETS */
struct sockaddr_in sin_buf
;
struct sockaddr_in
* sin
= &sin_buf
;
if ((sd
= start_tcp_client ((struct sockaddr_in
*) 0, 0)) == NOTOK
) {
perror("start_tcp_client");
if (get_dish_sock (sin
, 0, 1) != 0)
if (join_tcp_server (sd
, sin
) == NOTOK
) {
(void) fprintf (stderr
,"No connection and no cache !!!\n");
(void) close_tcp_socket (sd
);
if ((ptr
= rindex (argv
[0], '/')) == NULLCP
)
(void) strcpy (buffer
,argv
[0]);
(void) strcpy (buffer
,++ptr
);
(void) strcat (buffer
, " \"");
(void) strcat (buffer
, *argv
++);
(void) strcat (buffer
, "\"");
(void) strcat (buffer
, "\n");
if (send(sd
, buffer
, strlen(buffer
), 0) == -1) {
(void) close_tcp_socket (sd
);
if ((res
= recv(sd
, buffer
, BUFSIZ
-1, 0)) == -1) {
(void) close_tcp_socket (sd
);
(void) write (2,&buffer
[1],--res
);
while ( (res
= recv(sd
, buffer
, BUFSIZ
, 0)) > 0)
(void) write (2,buffer
,res
);
} else if (*buffer
== '1') {
(void) write (1,&buffer
[1],--res
);
while ( (res
= recv(sd
, buffer
, BUFSIZ
, 0)) > 0)
(void) write (1,buffer
,res
);
(void) close_tcp_socket (sd
);
#else /* USE UNIX NAMED PIPES */
char sendfile
[LINESIZE
];
char * getenv(), *sprintf();
(void) sprintf (retfile
,"/tmp/dish%d",getpid());
if ( (ptr
= getenv ("DISHPROC")) == NULLCP
) {
(void) sprintf (sendfile
, "/tmp/dish-%d", getppid ());
(void) setenv ("DISHPROC", sendfile
);
(void) strcpy (sendfile
, ptr
);
if (mknod (retfile
,S_IFIFO
|0660,0) == -1) {
(void) fprintf (stderr
,"Can't create result file %s\n",retfile
);
(void) signal(i
,pipe_quit
);
if ((fd
= open (sendfile
,O_WRONLY
|O_NDELAY
)) == -1) {
(void) fprintf (stderr
,"No connection and no cache !!!\n");
if ((ptr
= rindex (argv
[0],'/')) == NULLCP
)
(void) sprintf (buffer
,"%s:%s",retfile
,argv
[0]);
(void) sprintf (buffer
,"%s:%s",retfile
,++ptr
);
(void) strcat (buffer
," ");
(void) strcat (buffer
,*argv
++);
if (( res
=write (fd
, buffer
,strlen (buffer
))) == -1) {
(void) fprintf (stderr
,"Write failed\n");
if (( fd
= open (retfile
,O_RDONLY
)) < 0) {
(void) fprintf (stderr
,"Can't read results\n");
if (( res
= read (fd
,buffer
,BUFSIZ
)) == -1) {
(void) fprintf (stderr
,"Read failed (%d)\n",errno
);
fputs (&buffer
[1], stderr
);
fputs (&buffer
[1], stdout
);
(void) fprintf (stderr
,"(signal %d) exiting...\n",sig
);