annotate lib-src/gnuslib.c @ 149:538048ae2ab8 r20-3b1

Import from CVS: tag r20-3b1
author cvs
date Mon, 13 Aug 2007 09:36:16 +0200
parents 360340f9fd5f
children 43dd3413c7c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* -*-C-*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Common library code for the GNU Emacs server and client.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 Copying is permitted under those conditions described by the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 General Public License.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Copyright (C) 1989 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 Author: Andy Norman (ange@hplb.hpl.hp.com), based on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 'etc/server.c' and 'etc/emacsclient.c' from the 18.52 GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 Emacs distribution.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 Please mail bugs and suggestions to the author at the above address.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 /* HISTORY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 * 11-Nov-1990 bristor@simba
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 * Added EOT stuff.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 * This file incorporates new features added by Bob Weiner <weiner@mot.com>,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 * Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 * Please see the note at the end of the README file for details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 * (If gnuserv came bundled with your emacs, the README file is probably
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 * ../etc/gnuserv.README relative to the directory containing this file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 static char rcsid [] = "!Header: gnuslib.c,v 2.4 95/02/16 11:57:37 arup alpha !";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
36 #include <errno.h>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 #include "gnuserv.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 static int connect_to_ipc_server (void);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #ifdef UNIX_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 static int connect_to_unix_server (void);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 static int connect_to_internet_server (char *serverhost, u_short port);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 /* On some systems, e.g. DGUX, inet_addr returns a 'struct in_addr'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #ifdef HAVE_BROKEN_INET_ADDR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 # define IN_ADDR struct in_addr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 # define NUMERIC_ADDR_ERROR (numeric_addr.s_addr == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 # if (LONGBITS > 32)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 # define IN_ADDR unsigned int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 # define IN_ADDR unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 # define NUMERIC_ADDR_ERROR (numeric_addr == (IN_ADDR) -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 #include <stdlib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 #include <sys/stat.h>
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 108
diff changeset
66 #ifdef HAVE_UNISTD_H
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 #include <unistd.h>
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 108
diff changeset
68 #endif /* HAVE_UNISTD_H */
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 108
diff changeset
69 #ifdef HAVE_STRING_H
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 #include <string.h>
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 108
diff changeset
71 #endif /* HAVE_STRING_H */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 #include <arpa/inet.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 char *progname = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 int make_connection(hostarg, portarg, s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 char *hostarg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 int portarg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 int *s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 char localhost[HOSTNAMSZ];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 char *ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 if (hostarg == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 hostarg = getenv("GNU_HOST");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 if (portarg == 0 && (ptr=getenv("GNU_PORT")) != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 portarg = atoi(ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 if (hostarg != NULL) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 /* hostname was given explicitly, via cmd line arg or GNU_HOST,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 * so obey it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 #ifdef UNIX_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 if (!strcmp(hostarg, "unix")) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 *s = connect_to_unix_server();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 return (int) CONN_UNIX;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 #endif /* UNIX_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 *s = connect_to_internet_server(hostarg, portarg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 return (int) CONN_INTERNET;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 return -1; /* hostarg should always be NULL for SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 } else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 /* no hostname given. Use unix-domain/sysv-ipc, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 * internet-domain connection to local host if they're not available. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 #ifdef UNIX_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 *s = connect_to_unix_server();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 return (int) CONN_UNIX;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 *s = connect_to_ipc_server();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 return (int) CONN_IPC;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 gethostname(localhost,HOSTNAMSZ); /* use this host by default */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 *s = connect_to_internet_server(localhost, portarg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 return (int) CONN_INTERNET;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 connect_to_ipc_server -- establish connection with server process via SYSV IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 Returns msqid for server if successful.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 static int connect_to_ipc_server (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 int s; /* connected msqid */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 key_t key; /* message key */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 char buf[GSERV_BUFSZ+1]; /* buffer for filename */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 sprintf(buf,"/tmp/gsrv%d",(int)geteuid());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 creat(buf,0600);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 if ((key = ftok(buf,1)) == -1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 fprintf(stderr, "%s: unable to get ipc key from %s\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 progname, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 if ((s = msgget(key,0600)) == -1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 fprintf(stderr,"%s: unable to access msg queue\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 }; /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 return(s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 } /* connect_to_ipc_server */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 disconnect_from_ipc_server -- inform the server that sending has finished,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 and wait for its reply.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 void disconnect_from_ipc_server(s,msgp,echo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 int s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 struct msgbuf *msgp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 int echo;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 int len; /* length of received message */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 send_string(s,EOT_STR); /* EOT terminates this message */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 msgp->mtype = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 if(msgsnd(s,msgp,strlen(msgp->mtext)+1,0) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 fprintf(stderr,"%s: unable to send message to server\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 }; /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 if((len = msgrcv(s,msgp,GSERV_BUFSZ,getpid(),0)) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 fprintf(stderr,"%s: unable to receive message from server\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 }; /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 if (echo) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 msgp->mtext[len] = '\0'; /* string terminate message */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 fputs(msgp->mtext, stdout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 if (msgp->mtext[len-1] != '\n') putchar ('\n');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 }; /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 } /* disconnect_from_ipc_server */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 #endif /* SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 #if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 send_string -- send string to socket.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 void send_string(s,msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 int s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 CONST char *msg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 if (send(s,msg,strlen(msg),0) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 fprintf(stderr,"%s: unable to send\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 }; /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 int len, left=strlen(msg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 while (left > 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 if ((len=write(s,msg,min2(left,GSERV_BUFSZ))) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 /* XEmacs addition: robertl@arnet.com */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 if (errno == EPIPE) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 return ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 fprintf(stderr,"%s: unable to send\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 }; /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 left -= len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 msg += len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 }; /* while */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 } /* send_string */
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
224
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
225 /*
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
226 read_line -- read a \n terminated line from a socket
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
227 */
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
228 int read_line(s,dest)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
229 int s;
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
230 char *dest;
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
231 {
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
232 char *index = NULL;
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
233 int length;
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
234 int offset=0;
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
235 char buffer[GSERV_BUFSZ+1];
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
236
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
237 while ((length=read(s,buffer+offset,1)>0) && buffer[offset]!='\n'
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
238 && buffer[offset] != EOT_CHR) {
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
239 offset += length;
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
240 if (offset >= GSERV_BUFSZ)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
241 break;
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
242 }
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
243 buffer[offset] = '\0';
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
244 strcpy(dest,buffer);
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
245 return 1;
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
246 } /* read_line */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 #endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 #ifdef UNIX_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 connect_to_unix_server -- establish connection with server process via a unix-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 domain socket. Returns socket descriptor for server
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 if successful.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 static int connect_to_unix_server (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 int s; /* connected socket descriptor */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 struct sockaddr_un server; /* for unix connections */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 if ((s = socket(AF_UNIX,SOCK_STREAM,0)) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 fprintf(stderr,"%s: unable to create socket\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 }; /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 server.sun_family = AF_UNIX;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 #ifdef HIDE_UNIX_SOCKET
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 sprintf(server.sun_path,"/tmp/gsrvdir%d/gsrv",(int)geteuid());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 #else /* HIDE_UNIX_SOCKET */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 sprintf(server.sun_path,"/tmp/gsrv%d",(int)geteuid());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 #endif /* HIDE_UNIX_SOCKET */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 if (connect(s,(struct sockaddr *)&server,strlen(server.sun_path)+2) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 fprintf(stderr,"%s: unable to connect to local\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 }; /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 return(s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 } /* connect_to_unix_server */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 #endif /* UNIX_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 internet_addr -- return the internet addr of the hostname or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 internet address passed. Return -1 on error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 int internet_addr(host)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 char *host;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 struct hostent *hp; /* pointer to host info for remote host */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 IN_ADDR numeric_addr; /* host address */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 numeric_addr = inet_addr(host);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 if (!NUMERIC_ADDR_ERROR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 return numeric_addr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 else if ((hp = gethostbyname(host)) != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 return ((struct in_addr *)(hp->h_addr))->s_addr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 } /* internet_addr */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 #ifdef AUTH_MAGIC_COOKIE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 # include <X11/X.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 # include <X11/Xauth.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 static Xauth *server_xauth = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 connect_to_internet_server -- establish connection with server process via
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 an internet domain socket. Returns socket
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 descriptor for server if successful.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 static int connect_to_internet_server (char *serverhost, u_short port)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 int s; /* connected socket descriptor */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 struct servent *sp; /* pointer to service information */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 struct sockaddr_in peeraddr_in; /* for peer socket address */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 char buf[512]; /* temporary buffer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 /* clear out address structures */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 memset((char *)&peeraddr_in,0,sizeof(struct sockaddr_in));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 /* Set up the peer address to which we will connect. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 peeraddr_in.sin_family = AF_INET;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 /* look up the server host's internet address */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 if ((peeraddr_in.sin_addr.s_addr = internet_addr(serverhost)) == -1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 fprintf(stderr,"%s: unable to find %s in /etc/hosts or from YP\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 progname,serverhost);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 }; /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 if (port == 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 if ((sp = getservbyname ("gnuserv","tcp")) == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 peeraddr_in.sin_port = htons(DEFAULT_PORT+getuid());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 peeraddr_in.sin_port = sp->s_port;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 peeraddr_in.sin_port = htons(port);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 /* Create the socket. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 if ((s = socket (AF_INET,SOCK_STREAM, 0))== -1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 fprintf(stderr,"%s: unable to create socket\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 }; /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 /* Try to connect to the remote server at the address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 * which was just built into peeraddr.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 if (connect(s, (struct sockaddr *)&peeraddr_in,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 sizeof(struct sockaddr_in)) == -1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 fprintf(stderr, "%s: unable to connect to remote\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 }; /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 #ifdef AUTH_MAGIC_COOKIE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 /* send credentials using MIT-MAGIC-COOKIE-1 protocol */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 server_xauth =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 XauGetAuthByAddr(FamilyInternet,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 sizeof(peeraddr_in.sin_addr.s_addr),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (char *) &peeraddr_in.sin_addr.s_addr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 strlen(MCOOKIE_SCREEN), MCOOKIE_SCREEN,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 strlen(MCOOKIE_X_NAME), MCOOKIE_X_NAME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 if (server_xauth && server_xauth->data) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 sprintf(buf, "%s\n%d\n", MCOOKIE_NAME, server_xauth->data_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 write (s, buf, strlen(buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 write (s, server_xauth->data, server_xauth->data_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 return (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 #endif /* AUTH_MAGIC_COOKIE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 sprintf (buf, "%s\n", DEFAUTH_NAME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 write (s, buf, strlen(buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 return(s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 } /* connect_to_internet_server */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 #endif /* INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 #if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 disconnect_from_server -- inform the server that sending has finished, and wait for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 its reply.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 void disconnect_from_server(s,echo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 int s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 int echo;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 char buffer[REPLYSIZ+1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 char buffer[GSERV_BUFSZ+1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 int add_newline = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 int length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 send_string(s,EOT_STR); /* make sure server gets string */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 #if !defined (linux) && !defined (_SCO_DS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 * shutdown is completely hozed under linux. If s is a unix domain socket,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 * you'll get EOPNOTSUPP back from it. If s is an internet socket, you get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 * a broken pipe when you try to read a bit later. The latter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 * problem is fixed for linux versions >= 1.1.46, but the problem
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 * with unix sockets persists. Sigh.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 if (shutdown(s,1) == -1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 fprintf(stderr, "%s: unable to shutdown socket\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 }; /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 while((length = recv(s,buffer,REPLYSIZ,0)) > 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 buffer[length] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 if (echo) fputs(buffer,stdout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 add_newline = (buffer[length-1] != '\n');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 }; /* while */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 #else
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
436 while ((length = read(s,buffer,GSERV_BUFSZ)) > 0 ||
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
437 (length == -1 && errno == EINTR)) {
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
438 if (length) {
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
439 buffer[length] = '\0';
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
440 if (echo) {
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
441 fputs(buffer,stdout);
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
442 add_newline = (buffer[length-1] != '\n');
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
443 }; /* if */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 }; /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 }; /* while */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 if (echo && add_newline) putchar('\n');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 if(length < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 fprintf(stderr,"%s: unable to read the reply from the server\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 }; /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 } /* disconnect_from_server */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 #endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */