annotate src/process-unix.c @ 406:b8cc9ab3f761 r21-2-33

Import from CVS: tag r21-2-33
author cvs
date Mon, 13 Aug 2007 11:17:09 +0200
parents 2f8bb876ab1d
children de805c49cfc1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1 /* Asynchronous subprocess implementation for UNIX
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 1995
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
3 Free Software Foundation, Inc.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
4 Copyright (C) 1995 Sun Microsystems, Inc.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
5 Copyright (C) 1995, 1996 Ben Wing.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
6
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
7 This file is part of XEmacs.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
8
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
9 XEmacs is free software; you can redistribute it and/or modify it
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
11 Free Software Foundation; either version 2, or (at your option) any
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
12 later version.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
13
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
17 for more details.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
18
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
20 along with XEmacs; see the file COPYING. If not, write to
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
22 Boston, MA 02111-1307, USA. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
23
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
24 /* This file has been Mule-ized except for `start-process-internal',
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
25 `open-network-stream-internal' and `open-multicast-group-internal'. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
26
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
27 /* This file has been split into process.c and process-unix.c by
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
28 Kirill M. Katsnelson <kkm@kis.ru>, so please bash him and not
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
29 the original author(s) */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
30
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
31 /* The IPv6 support is derived from the code for GNU Emacs-20.3
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
32 written by Wolfgang S. Rupprecht */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
33
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
34 #include <config.h>
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
35
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
36 #if !defined (NO_SUBPROCESSES)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
37
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
38 /* The entire file is within this conditional */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
39
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
40 #include "lisp.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
41
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
42 #include "buffer.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
43 #include "events.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
44 #include "frame.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
45 #include "hash.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
46 #include "lstream.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
47 #include "opaque.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
48 #include "process.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
49 #include "procimpl.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
50 #include "sysdep.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
51 #include "window.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
52 #ifdef FILE_CODING
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
53 #include "file-coding.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
54 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
55
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
56 #include <setjmp.h>
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
57 #include "sysfile.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
58 #include "sysproc.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
59 #include "systime.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
60 #include "syssignal.h" /* Always include before systty.h */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
61 #include "systty.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
62 #include "syswait.h"
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
63
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
64
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
65 /*
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
66 * Implementation-specific data. Pointed to by Lisp_Process->process_data
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
67 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
68
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
69 struct unix_process_data
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
70 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
71 /* Non-0 if this is really a ToolTalk channel. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
72 int connected_via_filedesc_p;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
73 /* Descriptor by which we read from this process. -1 for dead process */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
74 int infd;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
75 /* Descriptor for the tty which this process is using.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
76 -1 if we didn't record it (on some systems, there's no need). */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
77 int subtty;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
78 /* Name of subprocess terminal. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
79 Lisp_Object tty_name;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
80 /* Non-false if communicating through a pty. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
81 char pty_flag;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
82 };
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
83
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
84 #define UNIX_DATA(p) ((struct unix_process_data*)((p)->process_data))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
85
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
86 #ifdef HAVE_PTYS
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
87 /* The file name of the pty opened by allocate_pty. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
88
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
89 static char pty_name[24];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
90 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
91
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
92
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
93
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
94 /**********************************************************************/
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
95 /* Static helper routines */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
96 /**********************************************************************/
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
97
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
98 static SIGTYPE
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
99 close_safely_handler (int signo)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
100 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
101 EMACS_REESTABLISH_SIGNAL (signo, close_safely_handler);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
102 SIGRETURN;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
103 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
104
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
105 static void
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
106 close_safely (int fd)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
107 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
108 stop_interrupts ();
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
109 signal (SIGALRM, close_safely_handler);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
110 alarm (1);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
111 close (fd);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
112 alarm (0);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
113 start_interrupts ();
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
114 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
115
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
116 static void
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
117 close_descriptor_pair (int in, int out)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
118 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
119 if (in >= 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
120 close (in);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
121 if (out != in && out >= 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
122 close (out);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
123 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
124
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
125 /* Close all descriptors currently in use for communication
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
126 with subprocess. This is used in a newly-forked subprocess
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
127 to get rid of irrelevant descriptors. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
128
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
129 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
130 close_process_descs_mapfun (const void* key, void* contents, void* arg)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
131 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
132 Lisp_Object proc;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
133 CVOID_TO_LISP (proc, contents);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
134 event_stream_delete_stream_pair (XPROCESS(proc)->pipe_instream,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
135 XPROCESS(proc)->pipe_outstream);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
136 return 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
137 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
138
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
139 /* #### This function is currently called from child_setup
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
140 in callproc.c. It should become static though - kkm */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
141 void
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
142 close_process_descs (void)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
143 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
144 maphash (close_process_descs_mapfun, usid_to_process, 0);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
145 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
146
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
147 /* connect to an existing file descriptor. This is very similar to
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
148 open-network-stream except that it assumes that the connection has
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
149 already been initialized. It is currently used for ToolTalk
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
150 communication. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
151
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
152 /* This function used to be visible on the Lisp level, but there is no
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
153 real point in doing that. Here is the doc string:
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
154
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
155 "Connect to an existing file descriptor.\n\
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
156 Returns a subprocess-object to represent the connection.\n\
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
157 Input and output work as for subprocesses; `delete-process' closes it.\n\
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
158 Args are NAME BUFFER INFD OUTFD.\n\
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
159 NAME is name for process. It is modified if necessary to make it unique.\n\
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
160 BUFFER is the buffer (or buffer-name) to associate with the process.\n\
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
161 Process output goes at end of that buffer, unless you specify\n\
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
162 an output stream or filter function to handle the output.\n\
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
163 BUFFER may be also nil, meaning that this process is not associated\n\
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
164 with any buffer\n\
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
165 INFD and OUTFD specify the file descriptors to use for input and\n\
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
166 output, respectively."
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
167 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
168
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
169 Lisp_Object
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
170 connect_to_file_descriptor (Lisp_Object name, Lisp_Object buffer,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
171 Lisp_Object infd, Lisp_Object outfd)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
172 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
173 /* This function can GC */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
174 Lisp_Object proc;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
175 int inch;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
176
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
177 CHECK_STRING (name);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
178 CHECK_INT (infd);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
179 CHECK_INT (outfd);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
180
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
181 inch = XINT (infd);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
182 if (get_process_from_usid (FD_TO_USID(inch)))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
183 error ("There is already a process connected to fd %d", inch);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
184 if (!NILP (buffer))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
185 buffer = Fget_buffer_create (buffer);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
186 proc = make_process_internal (name);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
187
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
188 XPROCESS (proc)->pid = Fcons (infd, name);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
189 XPROCESS (proc)->buffer = buffer;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
190 init_process_io_handles (XPROCESS (proc), (void*)inch, (void*)XINT (outfd), 0);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
191 UNIX_DATA (XPROCESS (proc))->connected_via_filedesc_p = 1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
192
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
193 event_stream_select_process (XPROCESS (proc));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
194
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
195 return proc;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
196 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
197
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
198 #ifdef HAVE_PTYS
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
199
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
200 /* Open an available pty, returning a file descriptor.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
201 Return -1 on failure.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
202 The file name of the terminal corresponding to the pty
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
203 is left in the variable pty_name. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
204
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
205 static int
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
206 allocate_pty (void)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
207 {
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
208 #ifndef PTY_OPEN
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
209 struct stat stb;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
210
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
211 /* Some systems name their pseudoterminals so that there are gaps in
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
212 the usual sequence - for example, on HP9000/S700 systems, there
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
213 are no pseudoterminals with names ending in 'f'. So we wait for
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
214 three failures in a row before deciding that we've reached the
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
215 end of the ptys. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
216 int failed_count = 0;
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
217 #endif
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
218 int fd;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
219 #ifndef HAVE_GETPT
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
220 int i;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
221 int c;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
222 #endif
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
223
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
224 #ifdef PTY_ITERATION
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
225 PTY_ITERATION
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
226 #else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
227 for (c = FIRST_PTY_LETTER; c <= 'z'; c++)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
228 for (i = 0; i < 16; i++)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
229 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
230 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
231 #ifdef PTY_NAME_SPRINTF
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
232 PTY_NAME_SPRINTF
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
233 #else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
234 sprintf (pty_name, "/dev/pty%c%x", c, i);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
235 #endif /* no PTY_NAME_SPRINTF */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
236
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
237 #ifdef PTY_OPEN
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
238 PTY_OPEN;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
239 #else /* no PTY_OPEN */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
240 #ifdef IRIS
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
241 /* Unusual IRIS code */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
242 *ptyv = open ("/dev/ptc", O_RDWR | O_NONBLOCK | OPEN_BINARY, 0);
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
243 if (fd < 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
244 return -1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
245 if (fstat (fd, &stb) < 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
246 return -1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
247 #else /* not IRIS */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
248 if (stat (pty_name, &stb) < 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
249 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
250 failed_count++;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
251 if (failed_count >= 3)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
252 return -1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
253 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
254 else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
255 failed_count = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
256 fd = open (pty_name, O_RDWR | O_NONBLOCK | OPEN_BINARY, 0);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
257 #endif /* not IRIS */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
258 #endif /* no PTY_OPEN */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
259
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
260 if (fd >= 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
261 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
262 /* check to make certain that both sides are available
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
263 this avoids a nasty yet stupid bug in rlogins */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
264 #ifdef PTY_TTY_NAME_SPRINTF
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
265 PTY_TTY_NAME_SPRINTF
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
266 #else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
267 sprintf (pty_name, "/dev/tty%c%x", c, i);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
268 #endif /* no PTY_TTY_NAME_SPRINTF */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
269 #if !defined(UNIPLUS) && !defined(HAVE_GETPT)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
270 if (access (pty_name, 6) != 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
271 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
272 close (fd);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
273 #if !defined(IRIS) && !defined(__sgi)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
274 continue;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
275 #else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
276 return -1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
277 #endif /* IRIS */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
278 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
279 #endif /* not UNIPLUS */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
280 setup_pty (fd);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
281 return fd;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
282 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
283 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
284 return -1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
285 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
286 #endif /* HAVE_PTYS */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
287
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
288 static int
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
289 create_bidirectional_pipe (int *inchannel, int *outchannel,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
290 volatile int *forkin, volatile int *forkout)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
291 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
292 int sv[2];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
293
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
294 #ifdef SKTPAIR
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
295 if (socketpair (AF_UNIX, SOCK_STREAM, 0, sv) < 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
296 return -1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
297 *outchannel = *inchannel = sv[0];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
298 *forkout = *forkin = sv[1];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
299 #else /* not SKTPAIR */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
300 int temp;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
301 temp = pipe (sv);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
302 if (temp < 0) return -1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
303 *inchannel = sv[0];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
304 *forkout = sv[1];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
305 temp = pipe (sv);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
306 if (temp < 0) return -1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
307 *outchannel = sv[1];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
308 *forkin = sv[0];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
309 #endif /* not SKTPAIR */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
310 return 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
311 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
312
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
313
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
314 #ifdef HAVE_SOCKETS
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
315
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
316 #if !(defined(HAVE_GETADDRINFO) && defined(HAVE_GETNAMEINFO))
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
317 static int
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
318 get_internet_address (Lisp_Object host, struct sockaddr_in *address,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
319 Error_behavior errb)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
320 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
321 struct hostent *host_info_ptr = NULL;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
322 #ifdef TRY_AGAIN
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
323 int count = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
324 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
325
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
326 xzero (*address);
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
327
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
328 while (1)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
329 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
330 #ifdef TRY_AGAIN
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
331 if (count++ > 10) break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
332 #ifndef BROKEN_CYGWIN
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
333 h_errno = 0;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
334 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
335 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
336 /* Some systems can't handle SIGIO/SIGALARM in gethostbyname. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
337 slow_down_interrupts ();
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
338 host_info_ptr = gethostbyname ((char *) XSTRING_DATA (host));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
339 speed_up_interrupts ();
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
340 #ifdef TRY_AGAIN
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
341 if (! (host_info_ptr == 0 && h_errno == TRY_AGAIN))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
342 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
343 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
344 Fsleep_for (make_int (1));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
345 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
346 if (host_info_ptr)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
347 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
348 address->sin_family = host_info_ptr->h_addrtype;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
349 memcpy (&address->sin_addr, host_info_ptr->h_addr, host_info_ptr->h_length);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
350 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
351 else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
352 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
353 IN_ADDR numeric_addr;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
354 /* Attempt to interpret host as numeric inet address */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
355 numeric_addr = inet_addr ((char *) XSTRING_DATA (host));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
356 if (NUMERIC_ADDR_ERROR)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
357 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
358 maybe_error (Qprocess, errb,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
359 "Unknown host \"%s\"", XSTRING_DATA (host));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
360 return 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
361 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
362
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
363 /* There was some broken code here that called strlen() here
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
364 on (char *) &numeric_addr and even sometimes accessed
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
365 uninitialized data. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
366 address->sin_family = AF_INET;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
367 * (IN_ADDR *) &address->sin_addr = numeric_addr;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
368 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
369
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
370 return 1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
371 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
372 #endif /* !(HAVE_GETADDRINFO && HAVE_GETNAMEINFO) */
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
373
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
374 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
375 set_socket_nonblocking_maybe (int fd, int port, const char* proto)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
376 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
377 #ifdef PROCESS_IO_BLOCKING
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
378 Lisp_Object tail;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
379
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
380 for (tail = network_stream_blocking_port_list; CONSP (tail); tail = XCDR (tail))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
381 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
382 Lisp_Object tail_port = XCAR (tail);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
383
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
384 if (STRINGP (tail_port))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
385 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
386 struct servent *svc_info;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
387 CHECK_STRING (tail_port);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
388 svc_info = getservbyname ((char *) XSTRING_DATA (tail_port), proto);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
389 if ((svc_info != 0) && (svc_info->s_port == port))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
390 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
391 else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
392 continue;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
393 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
394 else if (INTP (tail_port) && (htons ((unsigned short) XINT (tail_port)) == port))
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
395 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
396 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
397
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
398 if (!CONSP (tail))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
399 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
400 set_descriptor_non_blocking (fd);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
401 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
402 #else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
403 set_descriptor_non_blocking (fd);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
404 #endif /* PROCESS_IO_BLOCKING */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
405 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
406
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
407 #endif /* HAVE_SOCKETS */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
408
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
409 /* Compute the Lisp form of the process status from
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
410 the numeric status that was returned by `wait'. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
411
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
412 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
413 update_status_from_wait_code (Lisp_Process *p, int *w_fmh)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
414 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
415 /* C compiler lossage when attempting to pass w directly */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
416 int w = *w_fmh;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
417
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
418 if (WIFSTOPPED (w))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
419 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
420 p->status_symbol = Qstop;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
421 p->exit_code = WSTOPSIG (w);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
422 p->core_dumped = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
423 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
424 else if (WIFEXITED (w))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
425 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
426 p->status_symbol = Qexit;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
427 p->exit_code = WEXITSTATUS (w);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
428 p->core_dumped = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
429 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
430 else if (WIFSIGNALED (w))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
431 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
432 p->status_symbol = Qsignal;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
433 p->exit_code = WTERMSIG (w);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
434 p->core_dumped = WCOREDUMP (w);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
435 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
436 else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
437 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
438 p->status_symbol = Qrun;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
439 p->exit_code = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
440 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
441 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
442
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
443 #ifdef SIGCHLD
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
444
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
445 #define MAX_EXITED_PROCESSES 1000
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
446 static volatile pid_t exited_processes[MAX_EXITED_PROCESSES];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
447 static volatile int exited_processes_status[MAX_EXITED_PROCESSES];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
448 static volatile int exited_processes_index;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
449
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
450 static volatile int sigchld_happened;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
451
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
452 /* On receipt of a signal that a child status has changed,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
453 loop asking about children with changed statuses until
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
454 the system says there are no more. All we do is record
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
455 the processes and wait status.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
456
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
457 This function could be called from within the SIGCHLD
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
458 handler, so it must be completely reentrant. When
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
459 not called from a SIGCHLD handler, BLOCK_SIGCHLD should
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
460 be non-zero so that SIGCHLD is blocked while this
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
461 function is running. (This is necessary so avoid
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
462 race conditions with the SIGCHLD_HAPPENED flag). */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
463
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
464 static void
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
465 record_exited_processes (int block_sigchld)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
466 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
467 if (!sigchld_happened)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
468 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
469 return;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
470 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
471
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
472 #ifdef EMACS_BLOCK_SIGNAL
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
473 if (block_sigchld)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
474 EMACS_BLOCK_SIGNAL (SIGCHLD);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
475 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
476
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
477 while (sigchld_happened)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
478 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
479 int pid;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
480 int w;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
481
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
482 /* Keep trying to get a status until we get a definitive result. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
483 do
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
484 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
485 errno = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
486 #ifdef WNOHANG
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
487 # ifndef WUNTRACED
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
488 # define WUNTRACED 0
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
489 # endif /* not WUNTRACED */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
490 # ifdef HAVE_WAITPID
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
491 pid = waitpid ((pid_t) -1, &w, WNOHANG | WUNTRACED);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
492 # else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
493 pid = wait3 (&w, WNOHANG | WUNTRACED, 0);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
494 # endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
495 #else /* not WNOHANG */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
496 pid = wait (&w);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
497 #endif /* not WNOHANG */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
498 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
499 while (pid <= 0 && errno == EINTR);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
500
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
501 if (pid <= 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
502 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
503
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
504 if (exited_processes_index < MAX_EXITED_PROCESSES)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
505 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
506 exited_processes[exited_processes_index] = pid;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
507 exited_processes_status[exited_processes_index] = w;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
508 exited_processes_index++;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
509 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
510
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
511 /* On systems with WNOHANG, we just ignore the number
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
512 of times that SIGCHLD was signalled, and keep looping
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
513 until there are no more processes to wait on. If we
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
514 don't have WNOHANG, we have to rely on the count in
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
515 SIGCHLD_HAPPENED. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
516 #ifndef WNOHANG
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
517 sigchld_happened--;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
518 #endif /* not WNOHANG */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
519 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
520
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
521 sigchld_happened = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
522
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
523 if (block_sigchld)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
524 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
525 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
526
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
527 /* For any processes that have changed status and are recorded
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
528 and such, update the corresponding Lisp_Process.
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
529 We separate this from record_exited_processes() so that
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
530 we never have to call this function from within a signal
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
531 handler. We block SIGCHLD in case record_exited_processes()
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
532 is called from a signal handler. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
533
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
534 /** USG WARNING: Although it is not obvious from the documentation
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
535 in signal(2), on a USG system the SIGCLD handler MUST NOT call
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
536 signal() before executing at least one wait(), otherwise the handler
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
537 will be called again, resulting in an infinite loop. The relevant
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
538 portion of the documentation reads "SIGCLD signals will be queued
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
539 and the signal-catching function will be continually reentered until
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
540 the queue is empty". Invoking signal() causes the kernel to reexamine
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
541 the SIGCLD queue. Fred Fish, UniSoft Systems Inc.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
542
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
543 (Note that now this only applies in SYS V Release 2 and before.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
544 On SYS V Release 3, we use sigset() to set the signal handler for
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
545 the first time, and so we don't have to reestablish the signal handler
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
546 in the handler below. On SYS V Release 4, we don't get this weirdo
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
547 behavior when we use sigaction(), which we do use.) */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
548
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
549 static SIGTYPE
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
550 sigchld_handler (int signo)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
551 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
552 #ifdef OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
553 int old_errno = errno;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
554
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
555 sigchld_happened++;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
556 record_exited_processes (0);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
557 errno = old_errno;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
558 #else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
559 sigchld_happened++;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
560 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
561 #ifdef HAVE_UNIXOID_EVENT_LOOP
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
562 signal_fake_event ();
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
563 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
564 /* WARNING - must come after wait3() for USG systems */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
565 EMACS_REESTABLISH_SIGNAL (signo, sigchld_handler);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
566 SIGRETURN;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
567 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
568
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
569 #endif /* SIGCHLD */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
570
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
571 #ifdef SIGNALS_VIA_CHARACTERS
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
572 /* Get signal character to send to process if SIGNALS_VIA_CHARACTERS */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
573
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
574 static int
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
575 process_signal_char (int tty_fd, int signo)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
576 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
577 /* If it's not a tty, pray that these default values work */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
578 if (!isatty(tty_fd)) {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
579 #define CNTL(ch) (037 & (ch))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
580 switch (signo)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
581 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
582 case SIGINT: return CNTL('C');
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
583 case SIGQUIT: return CNTL('\\');
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
584 #ifdef SIGTSTP
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
585 case SIGTSTP: return CNTL('Z');
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
586 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
587 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
588 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
589
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
590 #ifdef HAVE_TERMIOS
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
591 /* TERMIOS is the latest and bestest, and seems most likely to work.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
592 If the system has it, use it. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
593 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
594 struct termios t;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
595 tcgetattr (tty_fd, &t);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
596 switch (signo)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
597 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
598 case SIGINT: return t.c_cc[VINTR];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
599 case SIGQUIT: return t.c_cc[VQUIT];
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
600 #if defined(SIGTSTP) && defined(VSUSP)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
601 case SIGTSTP: return t.c_cc[VSUSP];
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
602 #endif
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
603 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
604 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
605
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
606 # elif defined (TIOCGLTC) && defined (TIOCGETC) /* not HAVE_TERMIOS */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
607 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
608 /* On Berkeley descendants, the following IOCTL's retrieve the
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
609 current control characters. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
610 struct tchars c;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
611 struct ltchars lc;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
612 switch (signo)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
613 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
614 case SIGINT: ioctl (tty_fd, TIOCGETC, &c); return c.t_intrc;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
615 case SIGQUIT: ioctl (tty_fd, TIOCGETC, &c); return c.t_quitc;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
616 # ifdef SIGTSTP
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
617 case SIGTSTP: ioctl (tty_fd, TIOCGLTC, &lc); return lc.t_suspc;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
618 # endif /* SIGTSTP */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
619 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
620 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
621
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
622 # elif defined (TCGETA) /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
623 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
624 /* On SYSV descendants, the TCGETA ioctl retrieves the current
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
625 control characters. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
626 struct termio t;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
627 ioctl (tty_fd, TCGETA, &t);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
628 switch (signo) {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
629 case SIGINT: return t.c_cc[VINTR];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
630 case SIGQUIT: return t.c_cc[VQUIT];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
631 # ifdef SIGTSTP
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
632 case SIGTSTP: return t.c_cc[VSWTCH];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
633 # endif /* SIGTSTP */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
634 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
635 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
636 # else /* ! defined (TCGETA) */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
637 #error ERROR! Using SIGNALS_VIA_CHARACTERS, but not HAVE_TERMIOS || (TIOCGLTC && TIOCGETC) || TCGETA
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
638 /* If your system configuration files define SIGNALS_VIA_CHARACTERS,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
639 you'd better be using one of the alternatives above! */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
640 # endif /* ! defined (TCGETA) */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
641 return '\0';
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
642 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
643 #endif /* SIGNALS_VIA_CHARACTERS */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
644
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
645
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
646
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
647
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
648 /**********************************************************************/
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
649 /* Process implementation methods */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
650 /**********************************************************************/
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
651
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
652 /*
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
653 * Allocate and initialize Lisp_Process->process_data
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
654 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
655
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
656 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
657 unix_alloc_process_data (Lisp_Process *p)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
658 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
659 p->process_data = xnew (struct unix_process_data);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
660
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
661 UNIX_DATA(p)->connected_via_filedesc_p = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
662 UNIX_DATA(p)->infd = -1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
663 UNIX_DATA(p)->subtty = -1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
664 UNIX_DATA(p)->tty_name = Qnil;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
665 UNIX_DATA(p)->pty_flag = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
666 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
667
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
668 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
669 * Mark any Lisp objects in Lisp_Process->process_data
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
670 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
671
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
672 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
673 unix_mark_process_data (Lisp_Process *proc)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
674 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
675 mark_object (UNIX_DATA(proc)->tty_name);
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
676 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
677
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
678 /*
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
679 * Initialize XEmacs process implementation once
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
680 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
681
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
682 #ifdef SIGCHLD
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
683 static void
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
684 unix_init_process (void)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
685 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
686 #ifndef CANNOT_DUMP
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
687 if (! noninteractive || initialized)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
688 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
689 signal (SIGCHLD, sigchld_handler);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
690 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
691 #endif /* SIGCHLD */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
692
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
693 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
694 * Initialize any process local data. This is called when newly
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
695 * created process is connected to real OS file handles. The
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
696 * handles are generally represented by void* type, but are
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
697 * of type int (file descriptors) for UNIX
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
698 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
699
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
700 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
701 unix_init_process_io_handles (Lisp_Process *p, void* in, void* out, int flags)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
702 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
703 UNIX_DATA(p)->infd = (int)in;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
704 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
705
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
706 /*
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
707 * Fork off a subprocess. P is a pointer to a newly created subprocess
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
708 * object. If this function signals, the caller is responsible for
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
709 * deleting (and finalizing) the process object.
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
710 *
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
711 * The method must return PID of the new process, a (positive??? ####) number
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
712 * which fits into Lisp_Int. No return value indicates an error, the method
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
713 * must signal an error instead.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
714 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
715
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
716 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
717 unix_create_process (Lisp_Process *p,
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
718 Lisp_Object *argv, int nargv,
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
719 Lisp_Object program, Lisp_Object cur_dir)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
720 {
298
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 288
diff changeset
721 /* This function rewritten by ben@xemacs.org. */
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
722
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
723 int pid;
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
724 int inchannel = -1;
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
725 int outchannel = -1;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
726 /* Use volatile to protect variables from being clobbered by longjmp. */
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
727 volatile int forkin = -1;
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
728 volatile int forkout = -1;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
729 volatile int pty_flag = 0;
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
730
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
731 #ifdef HAVE_PTYS
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
732 if (!NILP (Vprocess_connection_type))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
733 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
734 /* find a new pty, open the master side, return the opened
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
735 file handle, and store the name of the corresponding slave
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
736 side in global variable pty_name. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
737 outchannel = inchannel = allocate_pty ();
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
738 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
739
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
740 if (inchannel >= 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
741 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
742 /* You're "supposed" to now open the slave in the child.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
743 On some systems, we can open it here; this allows for
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
744 better error checking. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
745 #if !defined(USG)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
746 /* On USG systems it does not work to open the pty's tty here
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
747 and then close and reopen it in the child. */
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
748 #ifdef O_NOCTTY
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
749 /* Don't let this terminal become our controlling terminal
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
750 (in case we don't have one). */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
751 forkout = forkin = open (pty_name, O_RDWR | O_NOCTTY | OPEN_BINARY, 0);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
752 #else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
753 forkout = forkin = open (pty_name, O_RDWR | OPEN_BINARY, 0);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
754 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
755 if (forkin < 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
756 goto io_failure;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
757 #endif /* not USG */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
758 UNIX_DATA(p)->pty_flag = pty_flag = 1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
759 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
760 else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
761 #endif /* HAVE_PTYS */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
762 if (create_bidirectional_pipe (&inchannel, &outchannel,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
763 &forkin, &forkout) < 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
764 goto io_failure;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
765
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
766 #if 0
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
767 /* Replaced by close_process_descs */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
768 set_exclusive_use (inchannel);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
769 set_exclusive_use (outchannel);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
770 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
771
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
772 set_descriptor_non_blocking (inchannel);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
773
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
774 /* Record this as an active process, with its channels.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
775 As a result, child_setup will close Emacs's side of the pipes. */
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 278
diff changeset
776 init_process_io_handles (p, (void*)inchannel, (void*)outchannel,
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 278
diff changeset
777 pty_flag ? STREAM_PTY_FLUSHING : 0);
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
778 /* Record the tty descriptor used in the subprocess. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
779 UNIX_DATA(p)->subtty = forkin;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
780
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
781 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
782 #if !defined(__CYGWIN32__)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
783 /* child_setup must clobber environ on systems with true vfork.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
784 Protect it from permanent change. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
785 char **save_environ = environ;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
786 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
787
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
788 pid = fork ();
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
789 if (pid == 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
790 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
791 /**** Now we're in the child process ****/
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
792 int xforkin = forkin;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
793 int xforkout = forkout;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
794
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
795 if (!pty_flag)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
796 EMACS_SEPARATE_PROCESS_GROUP ();
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
797 #ifdef HAVE_PTYS
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
798 else
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
799 {
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
800 /* Disconnect the current controlling terminal, pursuant to
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
801 making the pty be the controlling terminal of the process.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
802 Also put us in our own process group. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
803
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
804 disconnect_controlling_terminal ();
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
805
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
806 /* Open the pty connection and make the pty's terminal
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
807 our controlling terminal.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
808
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
809 On systems with TIOCSCTTY, we just use it to set
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
810 the controlling terminal. On other systems, the
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
811 first TTY we open becomes the controlling terminal.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
812 So, we end up with four possibilities:
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
813
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
814 (1) on USG and TIOCSCTTY systems, we open the pty
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
815 and use TIOCSCTTY.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
816 (2) on other USG systems, we just open the pty.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
817 (3) on non-USG systems with TIOCSCTTY, we
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
818 just use TIOCSCTTY. (On non-USG systems, we
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
819 already opened the pty in the parent process.)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
820 (4) on non-USG systems without TIOCSCTTY, we
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
821 close the pty and reopen it.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
822
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
823 This would be cleaner if we didn't open the pty
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
824 in the parent process, but doing it that way
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
825 makes it possible to trap error conditions.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
826 It's harder to convey an error from the child
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
827 process, and I don't feel like messing with
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
828 this now. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
829
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
830 /* There was some weirdo, probably wrong,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
831 conditionalization on RTU and UNIPLUS here.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
832 I deleted it. So sue me. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
833
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
834 /* SunOS has TIOCSCTTY but the close/open method
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
835 also works. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
836
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
837 # if defined (USG) || !defined (TIOCSCTTY)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
838 /* Now close the pty (if we had it open) and reopen it.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
839 This makes the pty the controlling terminal of the
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
840 subprocess. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
841 /* I wonder if close (open (pty_name, ...)) would work? */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
842 if (xforkin >= 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
843 close (xforkin);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
844 xforkout = xforkin = open (pty_name, O_RDWR | OPEN_BINARY, 0);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
845 if (xforkin < 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
846 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
847 write (1, "Couldn't open the pty terminal ", 31);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
848 write (1, pty_name, strlen (pty_name));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
849 write (1, "\n", 1);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
850 _exit (1);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
851 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
852 # endif /* USG or not TIOCSCTTY */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
853
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
854 /* Miscellaneous setup required for some systems.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
855 Must be done before using tc* functions on xforkin.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
856 This guarantees that isatty(xforkin) is true. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
857
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
858 # ifdef SETUP_SLAVE_PTY
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
859 SETUP_SLAVE_PTY;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
860 # endif /* SETUP_SLAVE_PTY */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
861
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
862 # ifdef TIOCSCTTY
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
863 /* We ignore the return value
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
864 because faith@cs.unc.edu says that is necessary on Linux. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
865 assert (isatty (xforkin));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
866 ioctl (xforkin, TIOCSCTTY, 0);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
867 # endif /* TIOCSCTTY */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
868
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
869 /* Change the line discipline. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
870
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
871 # if defined (HAVE_TERMIOS) && defined (LDISC1)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
872 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
873 struct termios t;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
874 assert (isatty (xforkin));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
875 tcgetattr (xforkin, &t);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
876 t.c_lflag = LDISC1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
877 if (tcsetattr (xforkin, TCSANOW, &t) < 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
878 perror ("create_process/tcsetattr LDISC1 failed\n");
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
879 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
880 # elif defined (NTTYDISC) && defined (TIOCSETD)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
881 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
882 /* Use new line discipline. TIOCSETD is accepted and
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
883 ignored on Sys5.4 systems with ttcompat. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
884 int ldisc = NTTYDISC;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
885 assert (isatty (xforkin));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
886 ioctl (xforkin, TIOCSETD, &ldisc);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
887 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
888 # endif /* TIOCSETD & NTTYDISC */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
889
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
890 /* Make our process group be the foreground group
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
891 of our new controlling terminal. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
892
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
893 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
894 int piddly = EMACS_GET_PROCESS_GROUP ();
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
895 EMACS_SET_TTY_PROCESS_GROUP (xforkin, &piddly);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
896 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
897
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
898 /* On AIX, we've disabled SIGHUP above once we start a
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
899 child on a pty. Now reenable it in the child, so it
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
900 will die when we want it to.
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
901 JV: This needs to be done ALWAYS as we might have inherited
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
902 a SIG_IGN handling from our parent (nohup) and we are in new
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
903 process group.
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
904 */
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
905 signal (SIGHUP, SIG_DFL);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
906 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
907
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
908 if (pty_flag)
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
909 /* Set up the terminal characteristics of the pty. */
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
910 child_setup_tty (xforkout);
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
911
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
912 #endif /* HAVE_PTYS */
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
913
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
914 signal (SIGINT, SIG_DFL);
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
915 signal (SIGQUIT, SIG_DFL);
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
916
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
917 {
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
918 char *current_dir;
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
919 char **new_argv = alloca_array (char *, nargv + 2);
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
920 int i;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
921
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
922 /* Nothing below here GCs so our string pointers shouldn't move. */
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
923 new_argv[0] = (char *) XSTRING_DATA (program);
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
924 for (i = 0; i < nargv; i++)
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
925 {
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
926 CHECK_STRING (argv[i]);
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
927 new_argv[i + 1] = (char *) XSTRING_DATA (argv[i]);
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
928 }
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
929 new_argv[i + 1] = 0;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
930
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
931 TO_EXTERNAL_FORMAT (LISP_STRING, cur_dir,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
932 C_STRING_ALLOCA, current_dir,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
933 Qfile_name);
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
934
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
935 child_setup (xforkin, xforkout, xforkout, new_argv, current_dir);
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
936 }
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
937
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
938 } /**** End of child code ****/
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
939
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
940 /**** Back in parent process ****/
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
941 #if !defined(__CYGWIN32__)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
942 environ = save_environ;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
943 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
944 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
945
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
946 if (pid < 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
947 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
948 close_descriptor_pair (forkin, forkout);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
949 report_file_error ("Doing fork", Qnil);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
950 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
951
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
952 /* #### dmoore - why is this commented out, otherwise we leave
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
953 subtty = forkin, but then we close forkin just below. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
954 /* UNIX_DATA(p)->subtty = -1; */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
955
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
956 /* If the subfork execv fails, and it exits,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
957 this close hangs. I don't know why.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
958 So have an interrupt jar it loose. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
959 if (forkin >= 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
960 close_safely (forkin);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
961 if (forkin != forkout && forkout >= 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
962 close (forkout);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
963
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
964 #ifdef HAVE_PTYS
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
965 if (pty_flag)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
966 UNIX_DATA (p)->tty_name = build_string (pty_name);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
967 else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
968 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
969 UNIX_DATA (p)->tty_name = Qnil;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
970
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
971 /* Notice that SIGCHLD was not blocked. (This is not possible on
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
972 some systems.) No biggie if SIGCHLD occurs right around the
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
973 time that this call happens, because SIGCHLD() does not actually
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
974 deselect the process (that doesn't occur until the next time
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
975 we're waiting for an event, when status_notify() is called). */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
976 return pid;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
977
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
978 io_failure:
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
979 {
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
980 int save_errno = errno;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
981 close_descriptor_pair (forkin, forkout);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
982 close_descriptor_pair (inchannel, outchannel);
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
983 errno = save_errno;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
984 report_file_error ("Opening pty or pipe", Qnil);
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 380
diff changeset
985 return 0; /* not reached */
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
986 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
987 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
988
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
989 /* Return nonzero if this process is a ToolTalk connection. */
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
990
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
991 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
992 unix_tooltalk_connection_p (Lisp_Process *p)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
993 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
994 return UNIX_DATA(p)->connected_via_filedesc_p;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
995 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
996
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
997 /* This is called to set process' virtual terminal size */
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
998
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
999 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1000 unix_set_window_size (Lisp_Process* p, int cols, int rows)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1001 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1002 return set_window_size (UNIX_DATA(p)->infd, cols, rows);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1003 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1004
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1005 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1006 * This method is called to update status fields of the process
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1007 * structure. If the process has not existed, this method is
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1008 * expected to do nothing.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1009 *
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1010 * The method is called only for real child processes.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1011 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1012
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1013 #ifdef HAVE_WAITPID
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1014 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1015 unix_update_status_if_terminated (Lisp_Process* p)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1016 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1017 int w;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1018 #ifdef SIGCHLD
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1019 EMACS_BLOCK_SIGNAL (SIGCHLD);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1020 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1021 if (waitpid (XINT (p->pid), &w, WNOHANG) == XINT (p->pid))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1022 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1023 p->tick++;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1024 update_status_from_wait_code (p, &w);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1025 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1026 #ifdef SIGCHLD
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1027 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1028 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1029 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1030 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1031
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1032 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1033 * Update status of all exited processes. Called when SIGCLD has signaled.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1034 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1035
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1036 #ifdef SIGCHLD
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1037 static void
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1038 unix_reap_exited_processes (void)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1039 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1040 int i;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1041 Lisp_Process *p;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1042
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1043 #ifndef OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1044 record_exited_processes (1);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1045 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1046
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1047 if (exited_processes_index <= 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1048 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1049 return;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1050 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1051
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1052 #ifdef EMACS_BLOCK_SIGNAL
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1053 EMACS_BLOCK_SIGNAL (SIGCHLD);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1054 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1055 for (i = 0; i < exited_processes_index; i++)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1056 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1057 int pid = exited_processes[i];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1058 int w = exited_processes_status[i];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1059
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1060 /* Find the process that signaled us, and record its status. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1061
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1062 p = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1063 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1064 Lisp_Object tail;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1065 LIST_LOOP (tail, Vprocess_list)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1066 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1067 Lisp_Object proc = XCAR (tail);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1068 p = XPROCESS (proc);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1069 if (INTP (p->pid) && XINT (p->pid) == pid)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1070 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1071 p = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1072 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1073 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1074
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1075 if (p)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1076 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1077 /* Change the status of the process that was found. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1078 p->tick++;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1079 process_tick++;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1080 update_status_from_wait_code (p, &w);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1081
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1082 /* If process has terminated, stop waiting for its output. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1083 if (WIFSIGNALED (w) || WIFEXITED (w))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1084 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1085 if (!NILP(p->pipe_instream))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1086 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1087 /* We can't just call event_stream->unselect_process_cb (p)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1088 here, because that calls XtRemoveInput, which is not
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1089 necessarily reentrant, so we can't call this at interrupt
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1090 level.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1091 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1092 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1093 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1094 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1095 else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1096 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1097 /* There was no asynchronous process found for that id. Check
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1098 if we have a synchronous process. Only set sync process status
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1099 if there is one, so we work OK with the waitpid() call in
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1100 wait_for_termination(). */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1101 if (synch_process_alive != 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1102 { /* Set the global sync process status variables. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1103 synch_process_alive = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1104
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1105 /* Report the status of the synchronous process. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1106 if (WIFEXITED (w))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1107 synch_process_retcode = WEXITSTATUS (w);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1108 else if (WIFSIGNALED (w))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1109 synch_process_death = signal_name (WTERMSIG (w));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1110 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1111 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1112 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1113
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1114 exited_processes_index = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1115
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1116 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1117 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1118 #endif /* SIGCHLD */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1119
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1120 /*
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1121 * Stuff the entire contents of LSTREAM to the process output pipe
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1122 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1123
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1124 static JMP_BUF send_process_frame;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1125
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1126 static SIGTYPE
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1127 send_process_trap (int signum)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1128 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1129 EMACS_REESTABLISH_SIGNAL (signum, send_process_trap);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1130 EMACS_UNBLOCK_SIGNAL (signum);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1131 LONGJMP (send_process_frame, 1);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1132 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1133
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1134 static void
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1135 unix_send_process (Lisp_Object proc, struct lstream* lstream)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1136 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1137 /* Use volatile to protect variables from being clobbered by longjmp. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1138 SIGTYPE (*volatile old_sigpipe) (int) = 0;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1139 volatile Lisp_Object vol_proc = proc;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1140 Lisp_Process *volatile p = XPROCESS (proc);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1141
406
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1142 /* #### JV: layering violation?
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1143
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1144 This function knows too much about the relation between the encodingstream
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1145 (DATA_OUTSTREAM) and te actual output stream p->output_stream.
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1146
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1147 If encoding streams properly forwarded all calls, we could simply
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1148 use DATA_OUTSTREAM everywhere. */
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1149
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1150 if (!SETJMP (send_process_frame))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1151 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1152 /* use a reasonable-sized buffer (somewhere around the size of the
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1153 stream buffer) so as to avoid inundating the stream with blocked
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1154 data. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1155 Bufbyte chunkbuf[512];
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1156 Bytecount chunklen;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1157
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1158 while (1)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1159 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1160 ssize_t writeret;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1161
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1162 chunklen = Lstream_read (lstream, chunkbuf, 512);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1163 if (chunklen <= 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1164 break; /* perhaps should abort() if < 0?
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1165 This should never happen. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1166 old_sigpipe =
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1167 (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1168 /* Lstream_write() will never successfully write less than
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1169 the amount sent in. In the worst case, it just buffers
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1170 the unwritten data. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1171 writeret = Lstream_write (XLSTREAM (DATA_OUTSTREAM(p)), chunkbuf,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1172 chunklen);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1173 signal (SIGPIPE, old_sigpipe);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1174 if (writeret < 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1175 /* This is a real error. Blocking errors are handled
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1176 specially inside of the filedesc stream. */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1177 report_file_error ("writing to process", list1 (proc));
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1178 while (Lstream_was_blocked_p (XLSTREAM (p->pipe_outstream)))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1179 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1180 /* Buffer is full. Wait, accepting input;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1181 that may allow the program
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1182 to finish doing output and read more. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1183 Faccept_process_output (Qnil, make_int (1), Qnil);
406
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1184 /* It could have *really* finished, deleting the process */
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1185 if (NILP(p->pipe_outstream))
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
1186 return;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1187 old_sigpipe =
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1188 (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1189 Lstream_flush (XLSTREAM (p->pipe_outstream));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1190 signal (SIGPIPE, old_sigpipe);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1191 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1192 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1193 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1194 else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1195 { /* We got here from a longjmp() from the SIGPIPE handler */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1196 signal (SIGPIPE, old_sigpipe);
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 373
diff changeset
1197 /* Close the file lstream so we don't attempt to write to it further */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 373
diff changeset
1198 /* #### There is controversy over whether this might cause fd leakage */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 373
diff changeset
1199 /* my tests say no. -slb */
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 373
diff changeset
1200 XLSTREAM (p->pipe_outstream)->flags &= ~LSTREAM_FL_IS_OPEN;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1201 p->status_symbol = Qexit;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1202 p->exit_code = 256; /* #### SIGPIPE ??? */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1203 p->core_dumped = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1204 p->tick++;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1205 process_tick++;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1206 deactivate_process (*((Lisp_Object *) (&vol_proc)));
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1207 error ("SIGPIPE raised on process %s; closed it",
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1208 XSTRING_DATA (p->name));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1209 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1210
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1211 old_sigpipe = (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1212 Lstream_flush (XLSTREAM (DATA_OUTSTREAM(p)));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1213 signal (SIGPIPE, old_sigpipe);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1214 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1215
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1216 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1217 * Send EOF to the process. The default implementation simply
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1218 * closes the output stream. The method must return 0 to call
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1219 * the default implementation, or 1 if it has taken all care about
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1220 * sending EOF to the process.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1221 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1222
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1223 static int
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1224 unix_process_send_eof (Lisp_Object proc)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1225 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1226 if (!UNIX_DATA (XPROCESS (proc))->pty_flag)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1227 return 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1228
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1229 /* #### get_eof_char simply doesn't return the correct character
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1230 here. Maybe it is needed to determine the right eof
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1231 character in init_process_io_handles but here it simply screws
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1232 things up. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1233 #if 0
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1234 Bufbyte eof_char = get_eof_char (XPROCESS (proc));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1235 send_process (proc, Qnil, &eof_char, 0, 1);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1236 #else
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1237 send_process (proc, Qnil, (const Bufbyte *) "\004", 0, 1);
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1238 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1239 return 1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1240 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1241
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1242 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1243 * Called before the process is deactivated. The process object
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1244 * is not immediately finalized, just undergoes a transition to
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1245 * inactive state.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1246 *
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1247 * The return value is a unique stream ID, as returned by
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1248 * event_stream_delete_stream_pair
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1249 *
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1250 * In the lack of this method, only event_stream_delete_stream_pair
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1251 * is called on both I/O streams of the process.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1252 *
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1253 * The UNIX version guards this by ignoring possible SIGPIPE.
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1254 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1255
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1256 static USID
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1257 unix_deactivate_process (Lisp_Process *p)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1258 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1259 SIGTYPE (*old_sigpipe) (int) = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1260 USID usid;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1261
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1262 if (UNIX_DATA(p)->infd >= 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1263 flush_pending_output (UNIX_DATA(p)->infd);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1264
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1265 /* closing the outstream could result in SIGPIPE, so ignore it. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1266 old_sigpipe = (SIGTYPE (*) (int)) signal (SIGPIPE, SIG_IGN);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1267 usid = event_stream_delete_stream_pair (p->pipe_instream, p->pipe_outstream);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1268 signal (SIGPIPE, old_sigpipe);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1269
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1270 UNIX_DATA(p)->infd = -1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1271
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1272 return usid;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1273 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1274
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1275 /* send a signal number SIGNO to PROCESS.
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1276 CURRENT_GROUP means send to the process group that currently owns
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1277 the terminal being used to communicate with PROCESS.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1278 This is used for various commands in shell mode.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1279 If NOMSG is zero, insert signal-announcements into process's buffers
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1280 right away.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1281
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1282 If we can, we try to signal PROCESS by sending control characters
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1283 down the pty. This allows us to signal inferiors who have changed
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1284 their uid, for which killpg would return an EPERM error.
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1285
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1286 The method signals an error if the given SIGNO is not valid
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1287 */
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1288
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1289 static void
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1290 unix_kill_child_process (Lisp_Object proc, int signo,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1291 int current_group, int nomsg)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1292 {
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1293 int gid;
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1294 int no_pgrp = 0;
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1295 int kill_retval;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1296 Lisp_Process *p = XPROCESS (proc);
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1297
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1298 if (!UNIX_DATA(p)->pty_flag)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1299 current_group = 0;
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1300
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1301 /* If we are using pgrps, get a pgrp number and make it negative. */
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1302 if (current_group)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1303 {
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1304 #ifdef SIGNALS_VIA_CHARACTERS
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1305 /* If possible, send signals to the entire pgrp
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1306 by sending an input character to it. */
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1307 {
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1308 char sigchar = process_signal_char(UNIX_DATA(p)->subtty, signo);
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1309 if (sigchar) {
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1310 send_process (proc, Qnil, (Bufbyte *) &sigchar, 0, 1);
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1311 return;
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1312 }
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1313 }
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1314 #endif /* ! defined (SIGNALS_VIA_CHARACTERS) */
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1315
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1316 #ifdef TIOCGPGRP
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1317 /* Get the pgrp using the tty itself, if we have that.
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1318 Otherwise, use the pty to get the pgrp.
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1319 On pfa systems, saka@pfu.fujitsu.co.JP writes:
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1320 "TIOCGPGRP symbol defined in sys/ioctl.h at E50.
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1321 But, TIOCGPGRP does not work on E50 ;-P works fine on E60"
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1322 His patch indicates that if TIOCGPGRP returns an error, then
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1323 we should just assume that p->pid is also the process group id. */
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1324 {
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1325 int err;
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1326
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1327 err = ioctl ( (UNIX_DATA(p)->subtty != -1
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1328 ? UNIX_DATA(p)->subtty
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1329 : UNIX_DATA(p)->infd), TIOCGPGRP, &gid);
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1330
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1331 #ifdef pfa
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1332 if (err == -1)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1333 gid = - XINT (p->pid);
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1334 #endif /* ! defined (pfa) */
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1335 }
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1336 if (gid == -1)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1337 no_pgrp = 1;
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1338 else
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1339 gid = - gid;
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1340 #else /* ! defined (TIOCGPGRP ) */
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1341 /* Can't select pgrps on this system, so we know that
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1342 the child itself heads the pgrp. */
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1343 gid = - XINT (p->pid);
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1344 #endif /* ! defined (TIOCGPGRP ) */
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1345 }
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1346 else
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1347 gid = - XINT (p->pid);
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1348
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1349 switch (signo)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1350 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1351 #ifdef SIGCONT
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1352 case SIGCONT:
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1353 p->status_symbol = Qrun;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1354 p->exit_code = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1355 p->tick++;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1356 process_tick++;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1357 if (!nomsg)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1358 status_notify ();
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1359 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1360 #endif /* ! defined (SIGCONT) */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1361 case SIGINT:
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1362 case SIGQUIT:
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1363 case SIGKILL:
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1364 flush_pending_output (UNIX_DATA(p)->infd);
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1365 break;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1366 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1367
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1368 /* If we don't have process groups, send the signal to the immediate
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1369 subprocess. That isn't really right, but it's better than any
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1370 obvious alternative. */
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1371 if (no_pgrp)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1372 {
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1373 kill_retval = kill (XINT (p->pid), signo) ? errno : 0;
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1374 }
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1375 else
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1376 {
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1377 /* gid may be a pid, or minus a pgrp's number */
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1378 #if defined (TIOCSIGNAL) || defined (TIOCSIGSEND)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1379 if (current_group)
369
1d62742628b6 Import from CVS: tag r21-1-14
cvs
parents: 365
diff changeset
1380 {
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1381 #ifdef TIOCSIGNAL
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1382 kill_retval = ioctl (UNIX_DATA(p)->infd, TIOCSIGNAL, signo);
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1383 #else /* ! defined (TIOCSIGNAL) */
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1384 kill_retval = ioctl (UNIX_DATA(p)->infd, TIOCSIGSEND, signo);
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1385 #endif /* ! defined (TIOCSIGNAL) */
369
1d62742628b6 Import from CVS: tag r21-1-14
cvs
parents: 365
diff changeset
1386 }
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1387 else
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1388 kill_retval = kill (- XINT (p->pid), signo) ? errno : 0;
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1389 #else /* ! (defined (TIOCSIGNAL) || defined (TIOCSIGSEND)) */
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1390 kill_retval = EMACS_KILLPG (-gid, signo) ? errno : 0;
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1391 #endif /* ! (defined (TIOCSIGNAL) || defined (TIOCSIGSEND)) */
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1392 }
369
1d62742628b6 Import from CVS: tag r21-1-14
cvs
parents: 365
diff changeset
1393
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1394 if (kill_retval < 0 && errno == EINVAL)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 369
diff changeset
1395 error ("Signal number %d is invalid for this system", signo);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1396 }
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1397
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1398 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1399 * Kill any process in the system given its PID.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1400 *
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1401 * Returns zero if a signal successfully sent, or
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1402 * negative number upon failure
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1403 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1404
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1405 static int
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1406 unix_kill_process_by_pid (int pid, int sigcode)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1407 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1408 return kill (pid, sigcode);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1409 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1410
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1411 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1412 * Return TTY name used to communicate with subprocess
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1413 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1414
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1415 static Lisp_Object
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1416 unix_get_tty_name (Lisp_Process *p)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1417 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1418 return UNIX_DATA (p)->tty_name;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1419 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1420
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1421 /*
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1422 * Canonicalize host name HOST, and return its canonical form
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1423 *
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1424 * The default implementation just takes HOST for a canonical name.
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1425 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1426
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1427 #ifdef HAVE_SOCKETS
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1428 static Lisp_Object
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1429 unix_canonicalize_host_name (Lisp_Object host)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1430 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1431 #if defined(HAVE_GETADDRINFO) && defined(HAVE_GETNAMEINFO)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1432 struct addrinfo hints, *res;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1433 static char addrbuf[NI_MAXHOST];
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1434 Lisp_Object canonname;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1435 int retval;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1436 char *ext_host;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1437
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1438 xzero (hints);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1439 hints.ai_flags = AI_CANONNAME;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1440 hints.ai_family = AF_UNSPEC;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1441 hints.ai_socktype = SOCK_STREAM;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1442 hints.ai_protocol = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1443 TO_EXTERNAL_FORMAT (LISP_STRING, host, C_STRING_ALLOCA, ext_host, Qnative);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1444 retval = getaddrinfo (ext_host, NULL, &hints, &res);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1445 if (retval != 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1446 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1447 char *gai_error;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1448
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1449 TO_INTERNAL_FORMAT (C_STRING, gai_strerror (retval),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1450 C_STRING_ALLOCA, gai_error,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1451 Qnative);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1452 maybe_error (Qprocess, ERROR_ME_NOT,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1453 "%s \"%s\"", gai_error, XSTRING_DATA (host));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1454 canonname = host;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1455 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1456 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1457 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1458 int gni = getnameinfo (res->ai_addr, res->ai_addrlen,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1459 addrbuf, sizeof(addrbuf),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1460 NULL, 0, NI_NUMERICHOST);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1461 canonname = gni ? host : build_ext_string (addrbuf, Qnative);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1462
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1463 freeaddrinfo (res);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1464 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1465
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1466 return canonname;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1467 #else /* ! HAVE_GETADDRINFO */
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1468 struct sockaddr_in address;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1469
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1470 if (!get_internet_address (host, &address, ERROR_ME_NOT))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1471 return host;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1472
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1473 if (address.sin_family == AF_INET)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1474 return build_string (inet_ntoa (address.sin_addr));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1475 else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1476 /* #### any clue what to do here? */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1477 return host;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1478 #endif /* ! HAVE_GETADDRINFO */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1479 }
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1480
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1481 /* open a TCP network connection to a given HOST/SERVICE. Treated
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1482 exactly like a normal process when reading and writing. Only
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1483 differences are in status display and process deletion. A network
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1484 connection has no PID; you cannot signal it. All you can do is
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1485 deactivate and close it via delete-process */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1486
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1487 static void
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1488 unix_open_network_stream (Lisp_Object name, Lisp_Object host, Lisp_Object service,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1489 Lisp_Object protocol, void** vinfd, void** voutfd)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1490 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1491 int inch;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1492 int outch;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1493 volatile int s;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1494 volatile int port;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1495 volatile int retry = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1496 int retval;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1497
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1498 CHECK_STRING (host);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1499
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1500 if (!EQ (protocol, Qtcp) && !EQ (protocol, Qudp))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1501 error ("Unsupported protocol \"%s\"",
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1502 string_data (symbol_name (XSYMBOL (protocol))));
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1503
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1504 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1505 #if defined(HAVE_GETADDRINFO) && defined(HAVE_GETNAMEINFO)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1506 struct addrinfo hints, *res;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1507 struct addrinfo * volatile lres;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1508 char *portstring;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1509 volatile int xerrno = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1510 volatile int failed_connect = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1511 char *ext_host;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1512 /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1513 * Caution: service can either be a string or int.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1514 * Convert to a C string for later use by getaddrinfo.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1515 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1516 if (INTP (service))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1517 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1518 char portbuf[128];
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1519 snprintf (portbuf, sizeof (portbuf), "%ld", (long) XINT (service));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1520 portstring = portbuf;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1521 port = htons ((unsigned short) XINT (service));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1522 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1523 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1524 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1525 CHECK_STRING (service);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1526 TO_EXTERNAL_FORMAT (LISP_STRING, service,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1527 C_STRING_ALLOCA, portstring,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1528 Qnative);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1529 port = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1530 }
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1531
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1532 xzero (hints);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1533 hints.ai_flags = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1534 hints.ai_family = AF_UNSPEC;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1535 if (EQ (protocol, Qtcp))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1536 hints.ai_socktype = SOCK_STREAM;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1537 else /* EQ (protocol, Qudp) */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1538 hints.ai_socktype = SOCK_DGRAM;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1539 hints.ai_protocol = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1540 TO_EXTERNAL_FORMAT (LISP_STRING, host, C_STRING_ALLOCA, ext_host, Qnative);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1541 retval = getaddrinfo (ext_host, portstring, &hints, &res);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1542 if (retval != 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1543 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1544 char *gai_error;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1545
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1546 TO_INTERNAL_FORMAT (C_STRING, gai_strerror (retval),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1547 C_STRING_ALLOCA, gai_error,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1548 Qnative);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1549 error ("%s/%s %s", XSTRING_DATA (host), portstring, gai_error);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1550 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1551
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1552 /* address loop */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1553 for (lres = res; lres ; lres = lres->ai_next)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1554 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1555 if (EQ (protocol, Qtcp))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1556 s = socket (lres->ai_family, SOCK_STREAM, 0);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1557 else /* EQ (protocol, Qudp) */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1558 s = socket (lres->ai_family, SOCK_DGRAM, 0);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1559
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1560 if (s < 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1561 continue;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1562
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1563 /* Turn off interrupts here -- see comments below. There used to
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1564 be code which called bind_polling_period() to slow the polling
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1565 period down rather than turn it off, but that seems rather
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1566 bogus to me. Best thing here is to use a non-blocking connect
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1567 or something, to check for QUIT. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1568
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1569 /* Comments that are not quite valid: */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1570
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1571 /* Kernel bugs (on Ultrix at least) cause lossage (not just EINTR)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1572 when connect is interrupted. So let's not let it get interrupted.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1573 Note we do not turn off polling, because polling is only used
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1574 when not interrupt_input, and thus not normally used on the systems
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1575 which have this bug. On systems which use polling, there's no way
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1576 to quit if polling is turned off. */
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1577
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1578 /* Slow down polling. Some kernels have a bug which causes retrying
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1579 connect to fail after a connect. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1580
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1581 slow_down_interrupts ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1582
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1583 loop:
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1584
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1585 /* A system call interrupted with a SIGALRM or SIGIO comes back
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1586 here, with can_break_system_calls reset to 0. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1587 SETJMP (break_system_call_jump);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1588 if (QUITP)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1589 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1590 speed_up_interrupts ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1591 REALLY_QUIT;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1592 /* In case something really weird happens ... */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1593 slow_down_interrupts ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1594 }
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1595
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1596 /* Break out of connect with a signal (it isn't otherwise possible).
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1597 Thus you don't get screwed with a hung network. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1598 can_break_system_calls = 1;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1599 retval = connect (s, lres->ai_addr, lres->ai_addrlen);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1600 can_break_system_calls = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1601 if (retval == -1)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1602 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1603 xerrno = errno;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1604 if (errno != EISCONN)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1605 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1606 if (errno == EINTR)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1607 goto loop;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1608 if (errno == EADDRINUSE && retry < 20)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1609 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1610 /* A delay here is needed on some FreeBSD systems,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1611 and it is harmless, since this retrying takes time anyway
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1612 and should be infrequent.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1613 `sleep-for' allowed for quitting this loop with interrupts
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1614 slowed down so it can't be used here. Async timers should
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1615 already be disabled at this point so we can use `sleep'. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1616 sleep (1);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1617 retry++;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1618 goto loop;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1619 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1620 }
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1621
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1622 failed_connect = 1;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1623 close (s);
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1624
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1625 speed_up_interrupts ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1626
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1627 continue;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1628 }
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1629
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1630 if (port == 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1631 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1632 int gni;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1633 char servbuf[NI_MAXSERV];
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1634
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1635 if (EQ (protocol, Qtcp))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1636 gni = getnameinfo (lres->ai_addr, lres->ai_addrlen,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1637 NULL, 0, servbuf, sizeof(servbuf),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1638 NI_NUMERICSERV);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1639 else /* EQ (protocol, Qudp) */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1640 gni = getnameinfo (lres->ai_addr, lres->ai_addrlen,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1641 NULL, 0, servbuf, sizeof(servbuf),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1642 NI_NUMERICSERV | NI_DGRAM);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1643
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1644 if (gni == 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1645 port = strtol (servbuf, NULL, 10);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1646 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1647
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1648 break;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1649 } /* address loop */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1650
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1651 speed_up_interrupts ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1652
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1653 freeaddrinfo (res);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1654 if (s < 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1655 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1656 errno = xerrno;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1657
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1658 if (failed_connect)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1659 report_file_error ("connection failed", list2 (host, name));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1660 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1661 report_file_error ("error creating socket", list1 (name));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1662 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1663 #else /* ! HAVE_GETADDRINFO */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1664 struct sockaddr_in address;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1665
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1666 if (INTP (service))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1667 port = htons ((unsigned short) XINT (service));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1668 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1669 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1670 struct servent *svc_info;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1671 CHECK_STRING (service);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1672
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1673 if (EQ (protocol, Qtcp))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1674 svc_info = getservbyname ((char *) XSTRING_DATA (service), "tcp");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1675 else /* EQ (protocol, Qudp) */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1676 svc_info = getservbyname ((char *) XSTRING_DATA (service), "udp");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1677
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1678 if (svc_info == 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1679 error ("Unknown service \"%s\"", XSTRING_DATA (service));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1680 port = svc_info->s_port;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1681 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1682
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1683 get_internet_address (host, &address, ERROR_ME);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1684 address.sin_port = port;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1685
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1686 if (EQ (protocol, Qtcp))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1687 s = socket (address.sin_family, SOCK_STREAM, 0);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1688 else /* EQ (protocol, Qudp) */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1689 s = socket (address.sin_family, SOCK_DGRAM, 0);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1690
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1691 if (s < 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1692 report_file_error ("error creating socket", list1 (name));
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1693
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1694 /* Turn off interrupts here -- see comments below. There used to
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1695 be code which called bind_polling_period() to slow the polling
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1696 period down rather than turn it off, but that seems rather
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1697 bogus to me. Best thing here is to use a non-blocking connect
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1698 or something, to check for QUIT. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1699
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1700 /* Comments that are not quite valid: */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1701
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1702 /* Kernel bugs (on Ultrix at least) cause lossage (not just EINTR)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1703 when connect is interrupted. So let's not let it get interrupted.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1704 Note we do not turn off polling, because polling is only used
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1705 when not interrupt_input, and thus not normally used on the systems
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1706 which have this bug. On systems which use polling, there's no way
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1707 to quit if polling is turned off. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1708
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1709 /* Slow down polling. Some kernels have a bug which causes retrying
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1710 connect to fail after a connect. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1711
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1712 slow_down_interrupts ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1713
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1714 loop:
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1715
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1716 /* A system call interrupted with a SIGALRM or SIGIO comes back
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1717 here, with can_break_system_calls reset to 0. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1718 SETJMP (break_system_call_jump);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1719 if (QUITP)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1720 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1721 speed_up_interrupts ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1722 REALLY_QUIT;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1723 /* In case something really weird happens ... */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1724 slow_down_interrupts ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1725 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1726
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1727 /* Break out of connect with a signal (it isn't otherwise possible).
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1728 Thus you don't get screwed with a hung network. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1729 can_break_system_calls = 1;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1730 retval = connect (s, (struct sockaddr *) &address, sizeof (address));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1731 can_break_system_calls = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1732 if (retval == -1 && errno != EISCONN)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1733 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1734 int xerrno = errno;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1735 if (errno == EINTR)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1736 goto loop;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1737 if (errno == EADDRINUSE && retry < 20)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1738 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1739 /* A delay here is needed on some FreeBSD systems,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1740 and it is harmless, since this retrying takes time anyway
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1741 and should be infrequent.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1742 `sleep-for' allowed for quitting this loop with interrupts
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1743 slowed down so it can't be used here. Async timers should
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1744 already be disabled at this point so we can use `sleep'. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1745 sleep (1);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1746 retry++;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1747 goto loop;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1748 }
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1749
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1750 close (s);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1751
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1752 speed_up_interrupts ();
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1753
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1754 errno = xerrno;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1755 report_file_error ("connection failed", list2 (host, name));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1756 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1757
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1758 speed_up_interrupts ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1759 #endif /* ! HAVE_GETADDRINFO */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
1760 }
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1761
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1762 inch = s;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1763 outch = dup (s);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1764 if (outch < 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1765 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1766 close (s); /* this used to be leaked; from Kyle Jones */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1767 report_file_error ("error duplicating socket", list1 (name));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1768 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1769
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1770 set_socket_nonblocking_maybe (inch, port, "tcp");
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1771
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1772 *vinfd = (void*)inch;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1773 *voutfd = (void*)outch;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1774 }
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1775
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1776
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1777 #ifdef HAVE_MULTICAST
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1778
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1779 /* Didier Verna <didier@xemacs.org> Nov. 28 1997.
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1780
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1781 This function is similar to open-network-stream-internal, but provides a
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1782 mean to open an UDP multicast connection instead of a TCP one. Like in the
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1783 TCP case, the multicast connection will be seen as a sub-process,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1784
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1785 Some notes:
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1786 - Normally, we should use sendto and recvfrom with non connected
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1787 sockets. The current code doesn't allow us to do this. In the future, it
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1788 would be a good idea to extend the process data structure in order to deal
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1789 properly with the different types network connections.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1790 - For the same reason, when leaving a multicast group, it is better to make
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1791 a setsockopt - IP_DROP_MEMBERSHIP before closing the descriptors.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1792 Unfortunately, this can't be done here because delete_process doesn't know
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1793 about the kind of connection we have. However, this is not such an
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1794 important issue.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1795 */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1796
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1797 static void
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1798 unix_open_multicast_group (Lisp_Object name, Lisp_Object dest, Lisp_Object port,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1799 Lisp_Object ttl, void** vinfd, void** voutfd)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1800 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1801 struct ip_mreq imr;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1802 struct sockaddr_in sa;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1803 struct protoent *udp;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1804 int ws, rs;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1805 int theport;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1806 unsigned char thettl;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1807 int one = 1; /* For REUSEADDR */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1808 int ret;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1809 volatile int retry = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1810
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1811 CHECK_STRING (dest);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1812
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1813 CHECK_NATNUM (port);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1814 theport = htons ((unsigned short) XINT (port));
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1815
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1816 CHECK_NATNUM (ttl);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1817 thettl = (unsigned char) XINT (ttl);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1818
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1819 if ((udp = getprotobyname ("udp")) == NULL)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1820 error ("No info available for UDP protocol");
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1821
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1822 /* Init the sockets. Yes, I need 2 sockets. I couldn't duplicate one. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1823 if ((rs = socket (PF_INET, SOCK_DGRAM, udp->p_proto)) < 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1824 report_file_error ("error creating socket", list1(name));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1825 if ((ws = socket (PF_INET, SOCK_DGRAM, udp->p_proto)) < 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1826 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1827 close (rs);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1828 report_file_error ("error creating socket", list1(name));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1829 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1830
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1831 /* This will be used for both sockets */
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 278
diff changeset
1832 memset (&sa, 0, sizeof(sa));
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1833 sa.sin_family = AF_INET;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1834 sa.sin_port = theport;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1835 sa.sin_addr.s_addr = htonl (inet_addr ((char *) XSTRING_DATA (dest)));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1836
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1837 /* Socket configuration for reading ------------------------ */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1838
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1839 /* Multiple connections from the same machine. This must be done before
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1840 bind. If it fails, it shouldn't be fatal. The only consequence is that
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1841 people won't be able to connect twice from the same machine. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1842 if (setsockopt (rs, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof (one))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1843 < 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1844 warn_when_safe (Qmulticast, Qwarning, "Cannot reuse socket address");
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1845
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1846 /* bind socket name */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1847 if (bind (rs, (struct sockaddr *)&sa, sizeof(sa)))
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1848 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1849 close (rs);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1850 close (ws);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1851 report_file_error ("error binding socket", list2(name, port));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1852 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1853
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1854 /* join multicast group */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1855 imr.imr_multiaddr.s_addr = htonl (inet_addr ((char *) XSTRING_DATA (dest)));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1856 imr.imr_interface.s_addr = htonl (INADDR_ANY);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1857 if (setsockopt (rs, IPPROTO_IP, IP_ADD_MEMBERSHIP,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1858 (char *) &imr, sizeof (struct ip_mreq)) < 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1859 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1860 close (ws);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1861 close (rs);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1862 report_file_error ("error adding membership", list2(name, dest));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1863 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1864
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1865 /* Socket configuration for writing ----------------------- */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1866
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
1867 /* Normally, there's no 'connect' in multicast, since we prefer to use
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1868 'sendto' and 'recvfrom'. However, in order to handle this connection in
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1869 the process-like way it is done for TCP, we must be able to use 'write'
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1870 instead of 'sendto'. Consequently, we 'connect' this socket. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1871
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1872 /* See open-network-stream-internal for comments on this part of the code */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1873 slow_down_interrupts ();
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1874
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1875 loop:
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1876
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1877 /* A system call interrupted with a SIGALRM or SIGIO comes back
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1878 here, with can_break_system_calls reset to 0. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1879 SETJMP (break_system_call_jump);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1880 if (QUITP)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1881 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1882 speed_up_interrupts ();
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1883 REALLY_QUIT;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1884 /* In case something really weird happens ... */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1885 slow_down_interrupts ();
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1886 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1887
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1888 /* Break out of connect with a signal (it isn't otherwise possible).
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1889 Thus you don't get screwed with a hung network. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1890 can_break_system_calls = 1;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1891 ret = connect (ws, (struct sockaddr *) &sa, sizeof (sa));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1892 can_break_system_calls = 0;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1893 if (ret == -1 && errno != EISCONN)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1894 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1895 int xerrno = errno;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1896
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1897 if (errno == EINTR)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1898 goto loop;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1899 if (errno == EADDRINUSE && retry < 20)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1900 {
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1901 /* A delay here is needed on some FreeBSD systems,
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1902 and it is harmless, since this retrying takes time anyway
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1903 and should be infrequent.
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1904 `sleep-for' allowed for quitting this loop with interrupts
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1905 slowed down so it can't be used here. Async timers should
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1906 already be disabled at this point so we can use `sleep'. */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1907 sleep (1);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1908 retry++;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1909 goto loop;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1910 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1911
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1912 close (rs);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1913 close (ws);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1914 speed_up_interrupts ();
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1915
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1916 errno = xerrno;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1917 report_file_error ("error connecting socket", list2(name, port));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1918 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1919
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1920 speed_up_interrupts ();
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1921
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1922 /* scope */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1923 if (setsockopt (ws, IPPROTO_IP, IP_MULTICAST_TTL,
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1924 (char *) &thettl, sizeof (thettl)) < 0)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1925 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1926 close (rs);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1927 close (ws);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1928 report_file_error ("error setting ttl", list2(name, ttl));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1929 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
1930
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1931 set_socket_nonblocking_maybe (rs, theport, "udp");
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1932
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1933 *vinfd = (void*)rs;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1934 *voutfd = (void*)ws;
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1935 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1936
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1937 #endif /* HAVE_MULTICAST */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1938
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1939 #endif /* HAVE_SOCKETS */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1940
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1941
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1942 /**********************************************************************/
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1943 /* Initialization */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1944 /**********************************************************************/
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1945
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1946 void
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1947 process_type_create_unix (void)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1948 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1949 PROCESS_HAS_METHOD (unix, alloc_process_data);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1950 PROCESS_HAS_METHOD (unix, mark_process_data);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1951 #ifdef SIGCHLD
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1952 PROCESS_HAS_METHOD (unix, init_process);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1953 PROCESS_HAS_METHOD (unix, reap_exited_processes);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1954 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1955 PROCESS_HAS_METHOD (unix, init_process_io_handles);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1956 PROCESS_HAS_METHOD (unix, create_process);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1957 PROCESS_HAS_METHOD (unix, tooltalk_connection_p);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1958 PROCESS_HAS_METHOD (unix, set_window_size);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1959 #ifdef HAVE_WAITPID
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1960 PROCESS_HAS_METHOD (unix, update_status_if_terminated);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1961 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1962 PROCESS_HAS_METHOD (unix, send_process);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1963 PROCESS_HAS_METHOD (unix, process_send_eof);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1964 PROCESS_HAS_METHOD (unix, deactivate_process);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1965 PROCESS_HAS_METHOD (unix, kill_child_process);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1966 PROCESS_HAS_METHOD (unix, kill_process_by_pid);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1967 PROCESS_HAS_METHOD (unix, get_tty_name);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1968 #ifdef HAVE_SOCKETS
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1969 PROCESS_HAS_METHOD (unix, canonicalize_host_name);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1970 PROCESS_HAS_METHOD (unix, open_network_stream);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1971 #ifdef HAVE_MULTICAST
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1972 PROCESS_HAS_METHOD (unix, open_multicast_group);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1973 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1974 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1975 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1976
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1977 void
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1978 vars_of_process_unix (void)
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1979 {
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1980 Fprovide (intern ("unix-processes"));
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1981 }
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1982
727739f917cb Import from CVS: tag r20-5b30
cvs
parents:
diff changeset
1983 #endif /* !defined (NO_SUBPROCESSES) */