annotate lib-src/gnuslib.c @ 4885:6772ce4d982b

Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums lisp/ChangeLog addition: 2010-01-24 Aidan Kehoe <kehoea@parhasard.net> Correct the semantics of #'member*, #'eql, #'assoc* in the presence of bignums; change the integerp byte code to fixnump semantics. * bytecomp.el (fixnump, integerp, byte-compile-integerp): Change the integerp byte code to fixnump; add a byte-compile method to integerp using fixnump and numberp and avoiding a funcall most of the time, since in the non-core contexts where integerp is used, it's mostly distinguishing between fixnums and things that are not numbers at all. * byte-optimize.el (side-effect-free-fns, byte-after-unbind-ops) (byte-compile-side-effect-and-error-free-ops): Replace the integerp bytecode with fixnump; add fixnump to the side-effect-free-fns. Add the other extended number type predicates to the list in passing. * obsolete.el (floatp-safe): Mark this as obsolete. * cl.el (eql): Go into more detail in the docstring here. Don't bother checking whether both arguments are numbers; one is enough, #'equal will fail correctly if they have distinct types. (subst): Replace a call to #'integerp (deciding whether to use #'memq or not) with one to #'fixnump. Delete most-positive-fixnum, most-negative-fixnum from this file; they're now always in C, so they can't be modified from Lisp. * cl-seq.el (member*, assoc*, rassoc*): Correct these functions in the presence of bignums. * cl-macs.el (cl-make-type-test): The type test for a fixnum is now fixnump. Ditch floatp-safe, use floatp instead. (eql): Correct this compiler macro in the presence of bignums. (assoc*): Correct this compiler macro in the presence of bignums. * simple.el (undo): Change #'integerp to #'fixnump here, since we use #'delq with the same value as ELT a few lines down. src/ChangeLog addition: 2010-01-24 Aidan Kehoe <kehoea@parhasard.net> Fix problems with #'eql, extended number types, and the hash table implementation; change the Bintegerp bytecode to fixnump semantics even on bignum builds, since #'integerp can have a fast implementation in terms of #'fixnump for most of its extant uses, but not vice-versa. * lisp.h: Always #include number.h; we want the macros provided in it, even if the various number types are not available. * number.h (NON_FIXNUM_NUMBER_P): New macro, giving 1 when its argument is of non-immediate number type. Equivalent to FLOATP if WITH_NUMBER_TYPES is not defined. * elhash.c (lisp_object_eql_equal, lisp_object_eql_hash): Use NON_FIXNUM_NUMBER_P in these functions, instead of FLOATP, giving more correct behaviour in the presence of the extended number types. * bytecode.c (Bfixnump, execute_optimized_program): Rename Bintegerp to Bfixnump; change its semantics to reflect the new name on builds with bignum support. * data.c (Ffixnump, Fintegerp, syms_of_data, vars_of_data): Always make #'fixnump available, even on non-BIGNUM builds; always implement #'integerp in this file, even on BIGNUM builds. Move most-positive-fixnum, most-negative-fixnum here from number.c, so they are Lisp constants even on builds without number types, and attempts to change or bind them error. Use the NUMBERP and INTEGERP macros even on builds without extended number types. * data.c (fixnum_char_or_marker_to_int): Rename this function from integer_char_or_marker_to_int, to better reflect the arguments it accepts. * number.c (Fevenp, Foddp, syms_of_number): Never provide #'integerp in this file. Remove #'oddp, #'evenp; their implementations are overridden by those in cl.el. * number.c (vars_of_number): most-positive-fixnum, most-negative-fixnum are no longer here. man/ChangeLog addition: 2010-01-23 Aidan Kehoe <kehoea@parhasard.net> Generally: be careful to say fixnum, not integer, when talking about fixed-precision integral types. I'm sure I've missed instances, both here and in the docstrings, but this is a decent start. * lispref/text.texi (Columns): Document where only fixnums, not integers generally, are accepted. (Registers): Remove some ancient char-int confoundance here. * lispref/strings.texi (Creating Strings, Creating Strings): Be more exact in describing where fixnums but not integers in general are accepted. (Creating Strings): Use a more contemporary example to illustrate how concat deals with lists including integers about #xFF. Delete some obsolete documentation on same. (Char Table Types): Document that only fixnums are accepted as values in syntax tables. * lispref/searching.texi (String Search, Search and Replace): Be exact in describing where fixnums but not integers in general are accepted. * lispref/range-tables.texi (Range Tables): Be exact in describing them; only fixnums are accepted to describe ranges. * lispref/os.texi (Killing XEmacs, User Identification) (Time of Day, Time Conversion): Be more exact about using fixnum where only fixed-precision integers are accepted. * lispref/objects.texi (Integer Type): Be more exact (and up-to-date) about the possible values for integers. Cross-reference to documentation of the bignum extension. (Equality Predicates): (Range Table Type): (Array Type): Use fixnum, not integer, to describe a fixed-precision integer. (Syntax Table Type): Correct some English syntax here. * lispref/numbers.texi (Numbers): Change the phrasing here to use fixnum to mean the fixed-precision integers normal in emacs. Document that our terminology deviates from that of Common Lisp, and that we're working on it. (Compatibility Issues): Reiterate the Common Lisp versus Emacs Lisp compatibility issues. (Comparison of Numbers, Arithmetic Operations): * lispref/commands.texi (Command Loop Info, Working With Events): * lispref/buffers.texi (Modification Time): Be more exact in describing where fixnums but not integers in general are accepted.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 24 Jan 2010 15:21:27 +0000
parents 2161ac78b41e
children e6508b64ee08 061f4f90f874
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* -*-C-*-
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 458
diff changeset
2 Common library code for the XEmacs server and client.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 458
diff changeset
4 This file is part of XEmacs.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 Copying is permitted under those conditions described by the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 General Public License.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 Copyright (C) 1989 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 Author: Andy Norman (ange@hplb.hpl.hp.com), based on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 'etc/server.c' and 'etc/emacsclient.c' from the 18.52 GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 Emacs distribution.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 Please mail bugs and suggestions to the author at the above address.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 /* HISTORY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 * 11-Nov-1990 bristor@simba
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 * Added EOT stuff.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 * This file incorporates new features added by Bob Weiner <weiner@mot.com>,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 * Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 * Please see the note at the end of the README file for details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 * (If gnuserv came bundled with your emacs, the README file is probably
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 * ../etc/gnuserv.README relative to the directory containing this file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 static char rcsid [] = "!Header: gnuslib.c,v 2.4 95/02/16 11:57:37 arup alpha !";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 #include "gnuserv.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 #include <errno.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 #ifdef SYSV_IPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 static int connect_to_ipc_server (void);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 #ifdef UNIX_DOMAIN_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 static int connect_to_unix_server (void);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 #ifdef INTERNET_DOMAIN_SOCKETS
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
46 static int connect_to_internet_server (char *serverhost, unsigned short port);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 /* On some systems, e.g. DGUX, inet_addr returns a 'struct in_addr'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 #ifdef HAVE_BROKEN_INET_ADDR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 # define IN_ADDR struct in_addr
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 # define NUMERIC_ADDR_ERROR (numeric_addr.s_addr == -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 # if (LONGBITS > 32)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 # define IN_ADDR unsigned int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 # else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 # define IN_ADDR unsigned long
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 # endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 # define NUMERIC_ADDR_ERROR (numeric_addr == (IN_ADDR) -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 #include <stdlib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 #include <sys/types.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 #include <sys/stat.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 #ifdef HAVE_UNISTD_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 #include <unistd.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 #endif /* HAVE_UNISTD_H */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 #ifdef HAVE_STRING_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 #include <string.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 #endif /* HAVE_STRING_H */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 #include <arpa/inet.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 char *tmpdir = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 char *progname = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
79 int
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
80 make_connection (char *hostarg, int portarg, int *s)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 #ifdef INTERNET_DOMAIN_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 char *ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 if (hostarg == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 hostarg = getenv("GNU_HOST");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 if (portarg == 0 && (ptr=getenv("GNU_PORT")) != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 portarg = atoi(ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 if (hostarg != NULL) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 /* hostname was given explicitly, via cmd line arg or GNU_HOST,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 * so obey it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 #ifdef UNIX_DOMAIN_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 if (!strcmp(hostarg, "unix")) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 *s = connect_to_unix_server();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 return (int) CONN_UNIX;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 #endif /* UNIX_DOMAIN_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 #ifdef INTERNET_DOMAIN_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 *s = connect_to_internet_server(hostarg, portarg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 return (int) CONN_INTERNET;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 #ifdef SYSV_IPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 return -1; /* hostarg should always be NULL for SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 } else {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 /* no hostname given. Use unix-domain/sysv-ipc, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 * internet-domain connection to local host if they're not available. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 #if defined(UNIX_DOMAIN_SOCKETS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 *s = connect_to_unix_server();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 return (int) CONN_UNIX;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 #elif defined(SYSV_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 *s = connect_to_ipc_server();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 return (int) CONN_IPC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 #elif defined(INTERNET_DOMAIN_SOCKETS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 char localhost[HOSTNAMSZ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 gethostname(localhost,HOSTNAMSZ); /* use this host by default */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 *s = connect_to_internet_server(localhost, portarg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 return (int) CONN_INTERNET;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 #endif /* IPC type */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 #ifdef SYSV_IPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 connect_to_ipc_server -- establish connection with server process via SYSV IPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 Returns msqid for server if successful.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
131 static int
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
132 connect_to_ipc_server (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 int s; /* connected msqid */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 key_t key; /* message key */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 char buf[GSERV_BUFSZ+1]; /* buffer for filename */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 sprintf(buf,"%s/gsrv%d",tmpdir,(int)geteuid());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 creat(buf,0600);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 if ((key = ftok(buf,1)) == -1) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 perror(progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 fprintf(stderr, "%s: unable to get ipc key from %s\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 progname, buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 exit(1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 if ((s = msgget(key,0600)) == -1) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 perror(progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 fprintf(stderr,"%s: unable to access msg queue\n",progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 exit(1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 }; /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 return(s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 } /* connect_to_ipc_server */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 disconnect_from_ipc_server -- inform the server that sending has finished,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 and wait for its reply.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
162 void
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
163 disconnect_from_ipc_server (int s, struct msgbuf *msgp, int echo)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 int len; /* length of received message */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 send_string(s,EOT_STR); /* EOT terminates this message */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 msgp->mtype = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 if(msgsnd(s,msgp,strlen(msgp->mtext)+1,0) < 0) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 perror(progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 fprintf(stderr,"%s: unable to send message to server\n",progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 exit(1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 }; /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 if((len = msgrcv(s,msgp,GSERV_BUFSZ,getpid(),0)) < 0) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 perror(progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 fprintf(stderr,"%s: unable to receive message from server\n",progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 exit(1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 }; /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 if (echo) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 msgp->mtext[len] = '\0'; /* string terminate message */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 fputs(msgp->mtext, stdout);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 if (msgp->mtext[len-1] != '\n') putchar ('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 }; /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 } /* disconnect_from_ipc_server */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 #endif /* SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 #if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 send_string -- send string to socket.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
196 void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
197 send_string (int s, const char *msg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 if (send(s,msg,strlen(msg),0) < 0) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 perror(progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 fprintf(stderr,"%s: unable to send\n",progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 exit(1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 }; /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 int len, left=strlen(msg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 while (left > 0) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 if ((len=write(s,msg,min2(left,GSERV_BUFSZ))) < 0) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 /* XEmacs addition: robertl@arnet.com */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 if (errno == EPIPE) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 return ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 perror(progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 fprintf(stderr,"%s: unable to send\n",progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 exit(1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 }; /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 left -= len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 msg += len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 }; /* while */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 } /* send_string */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 read_line -- read a \n terminated line from a socket
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
226 int
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
227 read_line (int s, char *dest)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 int length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 int offset=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 char buffer[GSERV_BUFSZ+1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 while ((length=read(s,buffer+offset,1)>0) && buffer[offset]!='\n'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 && buffer[offset] != EOT_CHR) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 offset += length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 if (offset >= GSERV_BUFSZ)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 buffer[offset] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 strcpy(dest,buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 } /* read_line */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 #endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 #ifdef UNIX_DOMAIN_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 connect_to_unix_server -- establish connection with server process via a unix-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 domain socket. Returns socket descriptor for server
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 if successful.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
252 static int
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
253 connect_to_unix_server (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 int s; /* connected socket descriptor */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 struct sockaddr_un server; /* for unix connections */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 if ((s = socket(AF_UNIX,SOCK_STREAM,0)) < 0) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 perror(progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 fprintf(stderr,"%s: unable to create socket\n",progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 exit(1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 }; /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 server.sun_family = AF_UNIX;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 #ifdef HIDE_UNIX_SOCKET
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 sprintf(server.sun_path,"%s/gsrvdir%d/gsrv",tmpdir,(int)geteuid());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 #else /* HIDE_UNIX_SOCKET */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 sprintf(server.sun_path,"%s/gsrv%d",tmpdir,(int)geteuid());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 #endif /* HIDE_UNIX_SOCKET */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 if (connect(s,(struct sockaddr *)&server,strlen(server.sun_path)+2) < 0) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 perror(progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 fprintf(stderr,"%s: unable to connect to local\n",progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 exit(1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 }; /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 return(s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 } /* connect_to_unix_server */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 #endif /* UNIX_DOMAIN_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 #ifdef INTERNET_DOMAIN_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 internet_addr -- return the internet addr of the hostname or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 internet address passed. Return -1 on error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
287 int
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
288 internet_addr (char *host)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 struct hostent *hp; /* pointer to host info for remote host */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 IN_ADDR numeric_addr; /* host address */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 numeric_addr = inet_addr(host);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 if (!NUMERIC_ADDR_ERROR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 return numeric_addr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 else if ((hp = gethostbyname(host)) != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 return ((struct in_addr *)(hp->h_addr))->s_addr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 } /* internet_addr */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 #ifdef AUTH_MAGIC_COOKIE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 # include <X11/X.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 # include <X11/Xauth.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 static Xauth *server_xauth = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 connect_to_internet_server -- establish connection with server process via
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 an internet domain socket. Returns socket
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 descriptor for server if successful.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
315 static int
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
316 connect_to_internet_server (char *serverhost, unsigned short port)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 int s; /* connected socket descriptor */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 struct servent *sp; /* pointer to service information */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 struct sockaddr_in peeraddr_in; /* for peer socket address */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 char buf[512]; /* temporary buffer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 /* clear out address structures */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 memset((char *)&peeraddr_in,0,sizeof(struct sockaddr_in));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 /* Set up the peer address to which we will connect. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 peeraddr_in.sin_family = AF_INET;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 /* look up the server host's internet address */
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
330 if ((peeraddr_in.sin_addr.s_addr = internet_addr (serverhost)) ==
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
331 (unsigned int) -1)
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
332 {
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
333 fprintf (stderr, "%s: unable to find %s in /etc/hosts or from YP\n",
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
334 progname, serverhost);
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
335 exit(1);
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
336 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 if (port == 0) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 if ((sp = getservbyname ("gnuserv","tcp")) == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 peeraddr_in.sin_port = htons(DEFAULT_PORT+getuid());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 peeraddr_in.sin_port = sp->s_port;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 } /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 peeraddr_in.sin_port = htons(port);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 /* Create the socket. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 if ((s = socket (AF_INET,SOCK_STREAM, 0))== -1) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 perror(progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 fprintf(stderr,"%s: unable to create socket\n",progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 exit(1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 }; /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 /* Try to connect to the remote server at the address
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 * which was just built into peeraddr.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 if (connect(s, (struct sockaddr *)&peeraddr_in,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 sizeof(struct sockaddr_in)) == -1) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 perror(progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 fprintf(stderr, "%s: unable to connect to remote\n",progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 exit(1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 }; /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 #ifdef AUTH_MAGIC_COOKIE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 /* send credentials using MIT-MAGIC-COOKIE-1 protocol */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 server_xauth =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 XauGetAuthByAddr(FamilyInternet,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 sizeof(peeraddr_in.sin_addr.s_addr),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 (char *) &peeraddr_in.sin_addr.s_addr,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 strlen(MCOOKIE_SCREEN), MCOOKIE_SCREEN,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 strlen(MCOOKIE_X_NAME), MCOOKIE_X_NAME);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 if (server_xauth && server_xauth->data) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 sprintf(buf, "%s\n%d\n", MCOOKIE_NAME, server_xauth->data_length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 write (s, buf, strlen(buf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 write (s, server_xauth->data, server_xauth->data_length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 return (s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 #endif /* AUTH_MAGIC_COOKIE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 sprintf (buf, "%s\n", DEFAUTH_NAME);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 write (s, buf, strlen(buf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 return(s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 } /* connect_to_internet_server */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 #endif /* INTERNET_DOMAIN_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 #if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 disconnect_from_server -- inform the server that sending has finished, and wait for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 its reply.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
399 void
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
400 disconnect_from_server (int s, int echo)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 char buffer[REPLYSIZ+1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 char buffer[GSERV_BUFSZ+1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 int add_newline = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 int length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 send_string(s,EOT_STR); /* make sure server gets string */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 647
diff changeset
412 #ifndef _SCO_DS
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 /*
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 647
diff changeset
414 * There used to be a comment here complaining about ancient Linux
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 647
diff changeset
415 * versions. It is no longer relevant. I don't know why _SCO_DS is
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 647
diff changeset
416 * verboten here, as the original comment did not say.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 if (shutdown(s,1) == -1) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 perror(progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 fprintf(stderr, "%s: unable to shutdown socket\n",progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 exit(1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 }; /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 while((length = recv(s,buffer,REPLYSIZ,0)) > 0) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 buffer[length] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 if (echo) fputs(buffer,stdout);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 add_newline = (buffer[length-1] != '\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 }; /* while */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 while ((length = read(s,buffer,GSERV_BUFSZ)) > 0 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 (length == -1 && errno == EINTR)) {
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 647
diff changeset
435 if (length > 0) {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 buffer[length] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 if (echo) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 fputs(buffer,stdout);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 add_newline = (buffer[length-1] != '\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 }; /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 }; /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 }; /* while */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 if (echo && add_newline) putchar('\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 if(length < 0) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 perror(progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 fprintf(stderr,"%s: unable to read the reply from the server\n",progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 exit(1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 }; /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 } /* disconnect_from_server */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 #endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */