|
|
1.1 root 1: /* unbind.c - dish shell unbind and squid commands */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/others/quipu/uips/dish/RCS/unbind.c,v 7.1 90/03/15 11:20:40 mrose Exp $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/others/quipu/uips/dish/RCS/unbind.c,v 7.1 90/03/15 11:20:40 mrose Exp $
9: *
10: *
11: * $Log: unbind.c,v $
12: * Revision 7.1 90/03/15 11:20:40 mrose
13: * quipu-sync
14: *
15: * Revision 7.0 89/11/23 22:08:35 mrose
16: * Release 6.0
17: *
18: */
19:
20: /*
21: * NOTICE
22: *
23: * Acquisition, use, and distribution of this module and related
24: * materials are subject to the restrictions of a license agreement.
25: * Consult the Preface in the User's Manual for the full terms of
26: * this agreement.
27: *
28: */
29:
30:
31: #include <stdio.h>
32: #include "quipu/util.h"
33: #include "tailor.h"
34: #include "general.h"
35:
36: extern int errno;
37:
38:
39: #ifdef SOCKETS /* USE INTERNET SOCKETS */
40:
41: #include "internet.h"
42:
43: main(argc,argv)
44: int argc;
45: char *argv[];
46: {
47: int sd,res,status;
48: struct sockaddr_in sin_buf;
49: struct sockaddr_in * sin = &sin_buf;
50: char buffer [BUFSIZ];
51: char * ptr;
52:
53: if ((sd = start_tcp_client ((struct sockaddr_in *) 0, 0)) == NOTOK) {
54: perror("start_tcp_client");
55: exit(-20);
56: }
57:
58: if (get_dish_sock (sin, 0) != 0)
59: exit (-21);
60:
61: if (join_tcp_server (sd, sin) == NOTOK) {
62: (void) fprintf (stderr,"No connection and no cache !!!\n");
63: (void) close_tcp_socket (sd);
64: exit (0);
65: }
66:
67: if ((ptr = rindex (argv[0], '/')) == NULLCP)
68: (void) strcpy (buffer,argv[0]);
69: else
70: (void) strcpy (buffer,++ptr);
71:
72: argc--,argv++;
73:
74: while (argc--) {
75: (void) strcat (buffer, " \"");
76: (void) strcat (buffer, *argv++);
77: (void) strcat (buffer, "\"");
78: }
79:
80: if (send(sd, buffer, strlen(buffer), 0) == -1) {
81: perror("send");
82: (void) close_tcp_socket (sd);
83: exit (-25);
84: }
85:
86: if ((res = recv(sd, buffer, BUFSIZ-1, 0)) == -1) {
87: perror ("recv");
88: (void) close_tcp_socket (sd);
89: exit (-26);
90: }
91: *(buffer + res) = 0;
92:
93: if (*buffer == '2') {
94: status = 1;
95: if (res > 1)
96: (void) write (2,&buffer[1],--res);
97: while ( (res = recv(sd, buffer, BUFSIZ, 0)) > 0)
98: (void) write (2,buffer,res);
99: } else if (*buffer == '1') {
100: status = 0;
101: if (res > 1)
102: (void) write (1,&buffer[1],--res);
103: while ( (res = recv(sd, buffer, BUFSIZ, 0)) > 0)
104: (void) write (1,buffer,res);
105: }
106:
107: (void) close_tcp_socket (sd);
108:
109: exit (status);
110: }
111:
112:
113: #else /* USE UNIX NAMED PIPES */
114:
115: #include <fcntl.h>
116: #include <sys/types.h>
117: #include <sys/stat.h>
118: #include <signal.h>
119:
120: char retfile [LINESIZE];
121: int fd;
122:
123: main (argc,argv)
124: int argc;
125: char ** argv;
126: {
127: int res;
128: char buffer [BUFSIZ];
129: char sendfile [LINESIZE];
130: int i;
131: char * ptr;
132: void pipe_quit ();
133: char * getenv(), *sprintf();
134:
135: (void) umask(0);
136: (void) sprintf (retfile,"/tmp/dish%d",getpid());
137: if ( (ptr = getenv ("DISHPROC")) == NULLCP ) {
138: (void) sprintf (sendfile, "/tmp/dish-%d", getppid ());
139: (void) setenv ("DISHPROC", sendfile);
140: }
141: else
142: (void) strcpy (sendfile, ptr);
143:
144: setbuf (stdout,NULLCP);
145: setbuf (stderr,NULLCP);
146:
147: if (mknod (retfile,S_IFIFO|0660,0) == -1) {
148: (void) fprintf (stderr,"Can't create result file %s\n",retfile);
149: exit (-5);
150: }
151:
152: for (i=1; i<=15; i++)
153: (void) signal(i,pipe_quit);
154:
155: if ((fd = open (sendfile,O_WRONLY|O_NDELAY)) == -1) {
156: (void) fprintf (stderr,"No connection and no cache !!!\n");
157: (void) unlink (retfile);
158: exit (0);
159: }
160:
161: argc--;
162: if ((ptr = rindex (argv[0],'/')) == NULLCP)
163: (void) sprintf (buffer,"%s:%s",retfile,argv[0]);
164: else
165: (void) sprintf (buffer,"%s:%s",retfile,++ptr);
166: *argv++;
167:
168: while (argc--) {
169: (void) strcat (buffer," ");
170: (void) strcat (buffer,*argv++);
171: }
172:
173: if (( res =write (fd, buffer,strlen (buffer))) == -1) {
174: (void) fprintf (stderr,"Write failed\n");
175: (void) close (fd);
176: (void) unlink (retfile);
177: exit (-2);
178: }
179: (void) close (fd);
180:
181:
182: /* get results */
183: if (( fd = open (retfile,O_RDONLY)) < 0) {
184: (void) fprintf (stderr,"Can't read results\n");
185: (void) unlink (retfile);
186: exit (-3);
187: }
188:
189: if (( res = read (fd,buffer,BUFSIZ)) == -1) {
190: (void) fprintf (stderr,"Read failed (%d)\n",errno);
191: (void) unlink (retfile);
192: (void) close (fd);
193: exit (-4);
194: }
195:
196: *(buffer+res) = 0;
197:
198: if (*buffer == '2')
199: fputs (&buffer[1], stderr);
200: else if (*buffer == '1')
201: fputs (&buffer[1], stdout);
202:
203: (void) close (fd);
204: (void) unlink (retfile);
205:
206: if (*buffer == '2')
207: exit (-1);
208: }
209:
210: void pipe_quit (sig)
211: int sig;
212: {
213: (void) unlink (retfile);
214: (void) fprintf (stderr,"(signal %d) exiting...\n",sig);
215: exit (0);
216: }
217:
218: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.