annotate src/process-unix.c @ 428:3ecd8885ac67 r21-2-22

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