annotate src/process.c @ 237:89ec2bb86eea r20-5b17

Import from CVS: tag r20-5b17
author cvs
date Mon, 13 Aug 2007 10:15:03 +0200
parents 52952cbfc5b5
children 677f6a0ee643
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Asynchronous subprocess control for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 1995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 Copyright (C) 1995 Sun Microsystems, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 Copyright (C) 1995, 1996 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /* Synched up with: Mule 2.0, FSF 19.30. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 /* This file has been Mule-ized except for `start-process-internal'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 and `open-network-stream-internal'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #if !defined (NO_SUBPROCESSES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 /* The entire file is within this conditional */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #include "commands.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #include "events.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #include "frame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #include "insdel.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #include "lstream.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #include "opaque.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #include "process.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #include "sysdep.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #include "window.h"
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
47 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
48 #include "mule-coding.h"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
49 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #include <setjmp.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 #include "sysfile.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #include "sysproc.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 #include "systime.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 #include "syssignal.h" /* Always include before systty.h */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 #include "systty.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 #include "syswait.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 /* a process object is a network connection when its pid field a cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (name of name of port we are connected to . foreign host name) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 /* Valid values of process->status_symbol */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 Lisp_Object Qrun, Qstop; /* Qexit from eval.c, Qsignal from data.c. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 /* Qrun => Qopen, Qexit => Qclosed for "network connection" processes */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 Lisp_Object Qopen, Qclosed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 /* t means use pty, nil means use a pipe,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 maybe other values to come. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 static Lisp_Object Vprocess_connection_type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
72 #ifdef PROCESS_IO_BLOCKING
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
73 /* List of port numbers or port names to set a blocking I/O mode.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
74 Nil means set a non-blocking I/O mode [default]. */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
75 static Lisp_Object network_stream_blocking_port_list;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
76 #endif /* PROCESS_IO_BLOCKING */
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
77
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 /* FSFmacs says:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 These next two vars are non-static since sysdep.c uses them in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 emulation of `select'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 /* Number of events of change of status of a process. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 static volatile int process_tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 /* Number of events for which the user or sentinel has been notified. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 static int update_tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 /* Nonzero means delete a process right away if it exits. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 int delete_exited_processes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 /* Indexed by descriptor, gives the process (if any) for that descriptor */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 Lisp_Object descriptor_to_process[MAXDESC];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 /* List of process objects. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 Lisp_Object Vprocess_list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 Lisp_Object Qprocessp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 /* Buffered-ahead input char from process, indexed by channel.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 -1 means empty (no char is buffered).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 Used on sys V where the only way to tell if there is any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 output from the process is to read at least one char.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 Always -1 on systems that support FIONREAD. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 /* FSFmacs says:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 Don't make static; need to access externally. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 static int proc_buffered_char[MAXDESC];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 #ifdef HAVE_PTYS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 /* The file name of the pty opened by allocate_pty. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 static char pty_name[24];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 /* the process Lisp object */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 * Structure records pertinent information about open channels.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 * There is one channel associated with each process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 struct Lisp_Process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 struct lcrecord_header header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 /* Name of this process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 Lisp_Object name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 /* List of command arguments that this process was run with */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 Lisp_Object command;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 /* (funcall FILTER PROC STRING) (if FILTER is non-nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 to dispose of a bunch of chars from the process all at once */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 Lisp_Object filter;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 /* (funcall SENTINEL PROCESS) when process state changes */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 Lisp_Object sentinel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 /* Buffer that output is going to */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 Lisp_Object buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 /* Marker set to end of last buffer-inserted output from this process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 Lisp_Object mark;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 /* Lisp_Int of subprocess' PID, or a cons of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 service/host if this is really a network connection */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 Lisp_Object pid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 /* Non-0 if this is really a ToolTalk channel. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 int connected_via_filedesc_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 #if 0 /* FSFmacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 /* Perhaps it's cleaner this way, but FSFmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 provides no way of retrieving this value, so I'll
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 leave this info with PID. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 /* Non-nil if this is really a child process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 Lisp_Object childp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 /* Symbol indicating status of process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 This may be a symbol: run, stop, exit, signal */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 Lisp_Object status_symbol;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 /* Exit code if process has terminated,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 signal which stopped/interrupted process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 or 0 if process is running */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 int exit_code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 /* Number of this process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 /* Non-false if process has exited and "dumped core" on its way down */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 char core_dumped;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 /* Descriptor by which we read from this process. -1 for dead process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 int infd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 /* Descriptor by which we write to this process. -1 for dead process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 int outfd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 /* Descriptor for the tty which this process is using.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 -1 if we didn't record it (on some systems, there's no need). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 int subtty;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 /* Name of subprocess terminal. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 Lisp_Object tty_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 /* Non-false if communicating through a pty. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 char pty_flag;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 /* This next field is only actually used #ifdef ENERGIZE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 /* if this flag is not NIL, then filter will do the read on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 channel, rather than having a call to make_string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 This only works if the filter is a subr. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 char filter_does_read;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 /* Non-nil means kill silently if Emacs is exited. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 char kill_without_query;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 char selected;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 /* Event-count of last event in which this process changed status. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 volatile int tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 /* Event-count of last such event reported. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 int update_tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 /* streams used in input and output */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 Lisp_Object instream;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 Lisp_Object outstream;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 /* The actual filedesc stream used for output; may be different
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 than OUTSTREAM under Mule */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 Lisp_Object filedesc_stream;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 static Lisp_Object mark_process (Lisp_Object, void (*) (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 static void print_process (Lisp_Object, Lisp_Object, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 static void finalize_process (void *, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 DEFINE_LRECORD_IMPLEMENTATION ("process", process,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 mark_process, print_process, finalize_process,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 0, 0, struct Lisp_Process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 mark_process (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 struct Lisp_Process *proc = XPROCESS (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ((markobj) (proc->name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ((markobj) (proc->command));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 ((markobj) (proc->filter));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ((markobj) (proc->sentinel));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ((markobj) (proc->buffer));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ((markobj) (proc->mark));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ((markobj) (proc->pid));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ((markobj) (proc->tty_name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ((markobj) (proc->instream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ((markobj) (proc->outstream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ((markobj) (proc->filedesc_stream));
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
219 return proc->status_symbol;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 print_process (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 struct Lisp_Process *proc = XPROCESS (obj);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
226
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 if (print_readably)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 error ("printing unreadable object #<process %s>",
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
229 XSTRING_DATA (proc->name));
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
230
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 if (!escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 print_internal (proc->name, printcharfun, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 int netp = network_connection_p (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 write_c_string (((netp) ? GETTEXT ("#<network connection ") :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 GETTEXT ("#<process ")), printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 print_internal (proc->name, printcharfun, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 write_c_string (((netp) ? " " : " pid "), printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 print_internal (proc->pid, printcharfun, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 write_c_string (" state:", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 print_internal (proc->status_symbol, printcharfun, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 write_c_string (">", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 #ifdef HAVE_WINDOW_SYSTEM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 extern void debug_process_finalization (struct Lisp_Process *p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 #endif /* HAVE_WINDOW_SYSTEM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 finalize_process (void *header, int for_disksave)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 if (for_disksave) return; /* hmm, what would this do anyway? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 /* #### this probably needs to be tied into the tty event loop */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 /* #### when there is one */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 #ifdef HAVE_WINDOW_SYSTEM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 struct Lisp_Process *p = (struct Lisp_Process *) header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 debug_process_finalization (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 #endif /* HAVE_WINDOW_SYSTEM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 /* basic process accessors */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 static SIGTYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 close_safely_handler (int signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 EMACS_REESTABLISH_SIGNAL (signo, close_safely_handler);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 SIGRETURN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 close_safely (int fd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 stop_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 signal (SIGALRM, close_safely_handler);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 alarm (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 alarm (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 start_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 close_descriptor_pair (int in, int out)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 if (in >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 close (in);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 if (out != in && out >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 close (out);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 /* Close all descriptors currently in use for communication
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 with subprocess. This is used in a newly-forked subprocess
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 to get rid of irrelevant descriptors. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 close_process_descs (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 #ifndef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 for (i = 0; i < MAXDESC; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 Lisp_Object process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 process = descriptor_to_process[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 if (!NILP (process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 close_descriptor_pair (XPROCESS (process)->infd,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 XPROCESS (process)->outfd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 get_process_file_descriptors (struct Lisp_Process *p, int *infd,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 int *outfd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 if (! p) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 /* the cast of MAXDESC is needed for some versions of Linux */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 assert (p->infd >= -1 && p->infd < ((int) (MAXDESC)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 assert (p->outfd >= -1 && p->outfd < ((int) (MAXDESC)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 *infd = p->infd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 *outfd = p->outfd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 struct Lisp_Process *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 get_process_from_input_descriptor (int infd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 if ((infd < 0) || (infd >= ((int) (MAXDESC)))) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 proc = descriptor_to_process[infd];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 if (NILP (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 return XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 get_process_selected_p (struct Lisp_Process *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 return p->selected;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 set_process_selected_p (struct Lisp_Process *p, int selected_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 p->selected = !!selected_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 #ifdef HAVE_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 network_connection_p (Lisp_Object process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
362 return GC_CONSP (XPROCESS (process)->pid);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 connected_via_filedesc_p (struct Lisp_Process *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 return p->connected_via_filedesc_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
372 DEFUN ("processp", Fprocessp, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 Return t if OBJECT is a process.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
374 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
375 (obj))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
377 return PROCESSP (obj) ? Qt : Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
380 DEFUN ("process-list", Fprocess_list, 0, 0, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 Return a list of all processes.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
382 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
383 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 return Fcopy_sequence (Vprocess_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
388 DEFUN ("get-process", Fget_process, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 Return the process named NAME, or nil if there is none.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
390 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
391 (name))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 Lisp_Object tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 if (GC_PROCESSP (name))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
396 return name;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 if (!gc_in_progress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 /* this only gets called during GC when emacs is going away as a result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 of a signal or crash. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 CHECK_STRING (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 for (tail = Vprocess_list; GC_CONSP (tail); tail = XCDR (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 Lisp_Object proc = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 QUIT;
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 185
diff changeset
407 if (internal_equal (name, XPROCESS (proc)->name, 0))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
408 return XCAR (tail);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
413 DEFUN ("get-buffer-process", Fget_buffer_process, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 Return the (or, a) process associated with BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 BUFFER may be a buffer or the name of one.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
416 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
417 (name))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 Lisp_Object buf, tail, proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 if (GC_NILP (name)) return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 buf = Fget_buffer (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 if (GC_NILP (buf)) return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 for (tail = Vprocess_list; GC_CONSP (tail); tail = XCDR (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 /* jwz: do not quit here - it isn't necessary, as there is no way for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 Vprocess_list to get circular or overwhelmingly long, and this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 function is called from layout_mode_element under redisplay. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 /* QUIT; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 proc = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 if (GC_PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 return proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 /* This is how commands for the user decode process arguments. It
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 accepts a process, a process name, a buffer, a buffer name, or nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 Buffers denote the first process in the buffer, and nil denotes the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 current buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 get_process (Lisp_Object name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 {
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
446 Lisp_Object proc, obj;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 /* #### Look more closely into translating process names. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 /* This may be called during a GC from process_send_signal() from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 kill_buffer_processes() if emacs decides to abort(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 if (GC_PROCESSP (name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 return name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
457 if (GC_STRINGP (name))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
458 {
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
459 obj = Fget_process (name);
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
460 if (GC_NILP (obj))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
461 obj = Fget_buffer (name);
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
462 if (GC_NILP (obj))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
463 error ("Process %s does not exist", XSTRING_DATA (name));
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
464 }
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
465 else if (GC_NILP (name))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
466 obj = Fcurrent_buffer ();
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
467 else
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
468 obj = name;
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
469
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
470 /* Now obj should be either a buffer object or a process object.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
471 */
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
472 if (GC_BUFFERP (obj))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
473 {
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
474 proc = Fget_buffer_process (obj);
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
475 if (GC_NILP (proc))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
476 error ("Buffer %s has no process", XSTRING_DATA (XBUFFER(obj)->name));
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
477 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 {
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
480 /* fsf: CHECK_PROCESS (obj, 0); */
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
481 proc = obj;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 }
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 120
diff changeset
483 return proc;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
486 DEFUN ("process-id", Fprocess_id, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 Return the process id of PROCESS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 This is the pid of the Unix process which PROCESS uses or talks to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 For a network connection, this value is a cons of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (foreign-network-port . foreign-host-name).
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
491 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
492 (proc))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 Lisp_Object pid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 pid = XPROCESS (proc)->pid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 if (network_connection_p (proc))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
499 /* return Qnil; */
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
500 return Fcons (Fcar (pid), Fcdr (pid));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 else
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
502 return pid;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
505 DEFUN ("process-name", Fprocess_name, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 Return the name of PROCESS, as a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 This is the name of the program invoked in PROCESS,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 possibly modified to make it unique among process names.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
509 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
510 (proc))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 return XPROCESS (proc)->name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
516 DEFUN ("process-command", Fprocess_command, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 Return the command that was executed to start PROCESS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 This is a list of strings, the first string being the program executed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 and the rest of the strings being the arguments given to it.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
520 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
521 (proc))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 return XPROCESS (proc)->command;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 /* creating a process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 make_process_internal (Lisp_Object name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 Lisp_Object val, name1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 int i;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
537 struct Lisp_Process *p =
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
538 alloc_lcrecord_type (struct Lisp_Process, lrecord_process);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 /* If name is already in use, modify it until it is unused. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 name1 = name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 for (i = 1; ; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 char suffix[10];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 Lisp_Object tem = Fget_process (name1);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
546 if (NILP (tem))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 sprintf (suffix, "<%d>", i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 name1 = concat2 (name, build_string (suffix));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 name = name1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 p->name = name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 p->command = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 p->filter = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 p->sentinel = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 p->buffer = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 p->mark = Fmake_marker ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 p->pid = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 p->status_symbol = Qrun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 p->connected_via_filedesc_p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 p->exit_code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 p->core_dumped = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 p->infd = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 p->outfd = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 p->subtty = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 p->tty_name = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 p->pty_flag = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 p->filter_does_read = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 p->kill_without_query = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 p->selected = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 p->tick = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 p->update_tick = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 p->instream = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 p->outstream = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 XSETPROCESS (val, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 Vprocess_list = Fcons (val, Vprocess_list);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
580 return val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 #ifdef HAVE_PTYS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 /* Open an available pty, returning a file descriptor.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 Return -1 on failure.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 The file name of the terminal corresponding to the pty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 is left in the variable pty_name. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 allocate_pty (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 struct stat stb;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 int c, i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 int fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 /* Some systems name their pseudoterminals so that there are gaps in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 the usual sequence - for example, on HP9000/S700 systems, there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 are no pseudoterminals with names ending in 'f'. So we wait for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 three failures in a row before deciding that we've reached the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 end of the ptys. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 int failed_count = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 #ifdef PTY_ITERATION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 PTY_ITERATION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 for (c = FIRST_PTY_LETTER; c <= 'z'; c++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 for (i = 0; i < 16; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 #ifdef PTY_NAME_SPRINTF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 PTY_NAME_SPRINTF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 sprintf (pty_name, "/dev/pty%c%x", c, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 #endif /* no PTY_NAME_SPRINTF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 #ifdef PTY_OPEN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 PTY_OPEN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 #else /* no PTY_OPEN */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 #ifdef IRIS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 /* Unusual IRIS code */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 *ptyv = open ("/dev/ptc", O_RDWR | O_NDELAY, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 if (fd < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 if (fstat (fd, &stb) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 #else /* not IRIS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 if (stat (pty_name, &stb) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 failed_count++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 if (failed_count >= 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 failed_count = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 #ifdef O_NONBLOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 fd = open (pty_name, O_RDWR | O_NONBLOCK, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 fd = open (pty_name, O_RDWR | O_NDELAY, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 #endif /* not IRIS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 #endif /* no PTY_OPEN */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 if (fd >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 /* check to make certain that both sides are available
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 this avoids a nasty yet stupid bug in rlogins */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 #ifdef PTY_TTY_NAME_SPRINTF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 PTY_TTY_NAME_SPRINTF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 sprintf (pty_name, "/dev/tty%c%x", c, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 #endif /* no PTY_TTY_NAME_SPRINTF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 #ifndef UNIPLUS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 if (access (pty_name, 6) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 #if !defined(IRIS) && !defined(__sgi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 #endif /* IRIS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 #endif /* not UNIPLUS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 setup_pty (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 return fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 #endif /* HAVE_PTYS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 create_bidirectional_pipe (int *inchannel, int *outchannel,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 volatile int *forkin, volatile int *forkout)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 int sv[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 #ifdef SKTPAIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 if (socketpair (AF_UNIX, SOCK_STREAM, 0, sv) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 *outchannel = *inchannel = sv[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 *forkout = *forkin = sv[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 #else /* not SKTPAIR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 int temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 temp = pipe (sv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 if (temp < 0) return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 *inchannel = sv[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 *forkout = sv[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 temp = pipe (sv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 if (temp < 0) return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 *outchannel = sv[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 *forkin = sv[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 #endif /* not SKTPAIR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 static Bufbyte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 get_eof_char (struct Lisp_Process *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 /* Figure out the eof character for the outfd of the given process.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
702 * The following code is similar to that in process_send_signal, and
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 * should probably be merged with that code somehow. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
705 CONST Bufbyte ctrl_d = (Bufbyte) '\004';
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
706
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
707 if (!isatty (p->outfd))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
708 return ctrl_d;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 #ifdef HAVE_TERMIOS
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
710 {
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
711 struct termios t;
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
712 tcgetattr (p->outfd, &t);
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
713 #if 0
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
714 /* What is the following line designed to do??? -mrb */
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
715 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VEOF + 1))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
716 return ctrl_d;
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
717 else
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
718 return (Bufbyte) t.c_cc[VEOF];
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
719 #endif
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
720 return t.c_cc[VEOF] == CDISABLE ? ctrl_d : (Bufbyte) t.c_cc[VEOF];
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
721 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 #else /* ! HAVE_TERMIOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 /* On Berkeley descendants, the following IOCTL's retrieve the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 current control characters. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 #if defined (TIOCGETC)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
726 {
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
727 struct tchars c;
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
728 ioctl (p->outfd, TIOCGETC, &c);
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
729 return (Bufbyte) c.t_eofc;
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
730 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 #else /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 /* On SYSV descendants, the TCGETA ioctl retrieves the current control
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 characters. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 #ifdef TCGETA
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
735 {
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
736 struct termio t;
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
737 ioctl (p->outfd, TCGETA, &t);
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
738 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VINTR + 1))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
739 return ctrl_d;
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
740 else
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
741 return (Bufbyte) t.c_cc[VINTR];
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
742 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 #else /* ! defined (TCGETA) */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
744 /* Rather than complain, we'll just guess ^D, which is what
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 * earlier emacsen always used. */
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
746 return ctrl_d;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 #endif /* ! defined (TCGETA) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 #endif /* ! defined (TIOCGETC) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 #endif /* ! defined (HAVE_TERMIOS) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 get_pty_max_bytes (struct Lisp_Process *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 int pty_max_bytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 pty_max_bytes = fpathconf (p->outfd, _PC_MAX_CANON);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 if (pty_max_bytes < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 pty_max_bytes = 250;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 pty_max_bytes = 250;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 /* Deduct one, to leave space for the eof. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 pty_max_bytes--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 return pty_max_bytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 init_process_fds (struct Lisp_Process *p, int in, int out)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 p->infd = in;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 p->outfd = out;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 p->instream = make_filedesc_input_stream (in, 0, -1, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 p->outstream = make_filedesc_output_stream (out, 0, -1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 LSTR_BLOCKED_OK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 | (p->pty_flag ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 LSTR_PTY_FLUSHING : 0));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 p->filedesc_stream = p->outstream;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 if (p->pty_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 Bufbyte eof_char = get_eof_char (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 int pty_max_bytes = get_pty_max_bytes (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 filedesc_stream_set_pty_flushing (XLSTREAM (p->outstream),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 pty_max_bytes, eof_char);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 }
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
788 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
789 p->instream = make_decoding_input_stream
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
790 (XLSTREAM (p->instream),
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
791 Fget_coding_system (Vcoding_system_for_read));
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
792 Lstream_set_character_mode (XLSTREAM (p->instream));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
793 p->outstream = make_encoding_output_stream
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
794 (XLSTREAM (p->outstream),
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
795 Fget_coding_system (Vcoding_system_for_write));
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
796 /* CODE_CNTL (&out_state[outchannel]) |= CC_END; !!####
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
797 What's going on here? */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
798 #endif /* MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 static void
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
802 create_process (Lisp_Object process,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 char **new_argv, CONST char *current_dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 /* This function rewritten by wing@666.com. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 int pid, inchannel, outchannel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 /* Use volatile to protect variables from being clobbered by longjmp. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 volatile int forkin, forkout;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 volatile int pty_flag = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 char **env;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 struct Lisp_Process *p = XPROCESS (process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 env = environ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 inchannel = outchannel = forkin = forkout = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 #ifdef HAVE_PTYS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 if (!NILP (Vprocess_connection_type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 /* find a new pty, open the master side, return the opened
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 file handle, and store the name of the corresponding slave
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 side in global variable pty_name. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 outchannel = inchannel = allocate_pty ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 if (inchannel >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 /* You're "supposed" to now open the slave in the child.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 On some systems, we can open it here; this allows for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 better error checking. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 #ifndef USG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 /* On USG systems it does not work to open the pty's tty here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 and then close and reopen it in the child. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 #ifdef O_NOCTTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 /* Don't let this terminal become our controlling terminal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (in case we don't have one). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 forkout = forkin = open (pty_name, O_RDWR | O_NOCTTY, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 forkout = forkin = open (pty_name, O_RDWR, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 if (forkin < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 goto io_failure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 #endif /* not USG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 p->pty_flag = pty_flag = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 #endif /* HAVE_PTYS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 if (create_bidirectional_pipe (&inchannel, &outchannel,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 &forkin, &forkout) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 goto io_failure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 /* Replaced by close_process_descs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 set_exclusive_use (inchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 set_exclusive_use (outchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 set_descriptor_non_blocking (inchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 /* Record this as an active process, with its channels.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 As a result, child_setup will close Emacs's side of the pipes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 descriptor_to_process[inchannel] = process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 init_process_fds (p, inchannel, outchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 /* Record the tty descriptor used in the subprocess. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 p->subtty = forkin;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 p->status_symbol = Qrun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 p->exit_code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 /* child_setup must clobber environ on systems with true vfork.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 Protect it from permanent change. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 char **save_environ = environ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 #ifdef EMACS_BTL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 /* when performance monitoring is on, turn it off before the vfork(),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 as the child has no handler for the signal -- when back in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 parent process, turn it back on if it was really on when you "turned
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 it off" */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 int logging_on = cadillac_stop_logging (); /* #### rename me */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 #ifndef WINDOWSNT
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 161
diff changeset
884 pid = fork ();
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 if (pid == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 #endif /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 /**** Now we're in the child process ****/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 int xforkin = forkin;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 int xforkout = forkout;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 if (!pty_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 EMACS_SEPARATE_PROCESS_GROUP ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 #ifdef HAVE_PTYS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 /* Disconnect the current controlling terminal, pursuant to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 making the pty be the controlling terminal of the process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 Also put us in our own process group. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 disconnect_controlling_terminal ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 /* Open the pty connection and make the pty's terminal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 our controlling terminal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 On systems with TIOCSCTTY, we just use it to set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 the controlling terminal. On other systems, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 first TTY we open becomes the controlling terminal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 So, we end up with four possibilities:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (1) on USG and TIOCSCTTY systems, we open the pty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 and use TIOCSCTTY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (2) on other USG systems, we just open the pty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (3) on non-USG systems with TIOCSCTTY, we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 just use TIOCSCTTY. (On non-USG systems, we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 already opened the pty in the parent process.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (4) on non-USG systems without TIOCSCTTY, we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 close the pty and reopen it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 This would be cleaner if we didn't open the pty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 in the parent process, but doing it that way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 makes it possible to trap error conditions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 It's harder to convey an error from the child
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 process, and I don't feel like messing with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 this now. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 /* There was some weirdo, probably wrong,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 conditionalization on RTU and UNIPLUS here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 I deleted it. So sue me. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 /* SunOS has TIOCSCTTY but the close/open method
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 also works. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 # if defined (USG) || !defined (TIOCSCTTY)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 /* Now close the pty (if we had it open) and reopen it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 This makes the pty the controlling terminal of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 subprocess. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 /* I wonder if close (open (pty_name, ...)) would work? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 if (xforkin >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 close (xforkin);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 xforkout = xforkin = open (pty_name, O_RDWR, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 if (xforkin < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 write (1, "Couldn't open the pty terminal ", 31);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 write (1, pty_name, strlen (pty_name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 write (1, "\n", 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 _exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 # endif /* USG or not TIOCSCTTY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 /* Miscellaneous setup required for some systems.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 Must be done before using tc* functions on xforkin.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 This guarantees that isatty(xforkin) is true. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
954
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 # ifdef SETUP_SLAVE_PTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 SETUP_SLAVE_PTY;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 # endif /* SETUP_SLAVE_PTY */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
958
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 # ifdef TIOCSCTTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 /* We ignore the return value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 because faith@cs.unc.edu says that is necessary on Linux. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 assert (isatty (xforkin));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 ioctl (xforkin, TIOCSCTTY, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 # endif /* TIOCSCTTY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 /* Change the line discipline. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 # if defined (HAVE_TERMIOS) && defined (LDISC1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 struct termios t;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 assert (isatty (xforkin));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 tcgetattr (xforkin, &t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 t.c_lflag = LDISC1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 if (tcsetattr (xforkin, TCSANOW, &t) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 perror ("create_process/tcsetattr LDISC1 failed\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 # elif defined (NTTYDISC) && defined (TIOCSETD)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 /* Use new line discipline. TIOCSETD is accepted and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 ignored on Sys5.4 systems with ttcompat. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 int ldisc = NTTYDISC;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 assert (isatty (xforkin));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 ioctl (xforkin, TIOCSETD, &ldisc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 # endif /* TIOCSETD & NTTYDISC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 /* Make our process group be the foreground group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 of our new controlling terminal. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 int piddly = EMACS_GET_PROCESS_GROUP ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 EMACS_SET_TTY_PROCESS_GROUP (xforkin, &piddly);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 # ifdef AIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 /* On AIX, we've disabled SIGHUP above once we start a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 child on a pty. Now reenable it in the child, so it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 will die when we want it to. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 signal (SIGHUP, SIG_DFL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 # endif /* AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 #endif /* HAVE_PTYS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 signal (SIGINT, SIG_DFL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 signal (SIGQUIT, SIG_DFL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
1007 #if !defined(MSDOS) && !defined(WINDOWSNT)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 if (pty_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 /* Set up the terminal characteristics of the pty. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 child_setup_tty (xforkout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 pid = child_setup (xforkin, xforkout, xforkout,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 new_argv, current_dir);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
1017 #else /* not WINDOWSNT */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 child_setup (xforkin, xforkout, xforkout, new_argv, current_dir);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 #endif /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 #endif /* not MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 #ifdef EMACS_BTL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 else if (logging_on)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 cadillac_start_logging (); /* #### rename me */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 environ = save_environ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 if (pid < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 close_descriptor_pair (forkin, forkout);
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 161
diff changeset
1033 report_file_error ("Doing fork", Qnil);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 p->pid = make_int (pid);
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1037 /* #### dmoore - why is this commented out, otherwise we leave
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1038 subtty = forkin, but then we close forkin just below. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 /* p->subtty = -1; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 register_child (pid, inchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 #endif /* WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 /* If the subfork execv fails, and it exits,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 this close hangs. I don't know why.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 So have an interrupt jar it loose. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 if (forkin >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 close_safely (forkin);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 if (forkin != forkout && forkout >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 close (forkout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 #ifdef HAVE_PTYS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 if (pty_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 XPROCESS (process)->tty_name = build_string (pty_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 XPROCESS (process)->tty_name = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 /* Notice that SIGCHLD was not blocked. (This is not possible on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 some systems.) No biggie if SIGCHLD occurs right around the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 time that this call happens, because SIGCHLD() does not actually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 deselect the process (that doesn't occur until the next time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 we're waiting for an event, when status_notify() is called). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 event_stream_select_process (XPROCESS (process));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 io_failure:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 int temp = errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 close_descriptor_pair (forkin, forkout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 close_descriptor_pair (inchannel, outchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 errno = temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 report_file_error ("Opening pty or pipe", Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 /* This function is the unwind_protect form for Fstart_process_internal. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 PROC doesn't have its pid set, then we know someone has signalled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 an error and the process wasn't started successfully, so we should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 remove it from the process list. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 static void remove_process (Lisp_Object proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 start_process_unwind (Lisp_Object proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 /* Was PROC started successfully? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 if (EQ (XPROCESS (proc)->pid, Qnil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 remove_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1093 DEFUN ("start-process-internal", Fstart_process_internal, 3, MANY, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 Start a program in a subprocess. Return the process object for it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 NAME is name for process. It is modified if necessary to make it unique.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 BUFFER is the buffer or (buffer-name) to associate with the process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 Process output goes at end of that buffer, unless you specify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 an output stream or filter function to handle the output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 BUFFER may be also nil, meaning that this process is not associated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 with any buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 Third arg is program file name. It is searched for as in the shell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 Remaining arguments are strings to give program as arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 INCODE and OUTCODE specify the coding-system objects used in input/output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 from/to the process.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1106 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1107 (int nargs, Lisp_Object *args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 {
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1109 /* This function can call lisp */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 /* !!#### This function has not been Mule-ized */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 Lisp_Object buffer, name, program, proc, current_dir;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 int speccount = specpdl_depth ();
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1114 struct gcpro gcpro1, gcpro2, gcpro3;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 char **new_argv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1118 name = args[0];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 buffer = args[1];
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1120 program = args[2];
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1121 current_dir = Qnil;
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1122
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1123 /* Protect against various file handlers doing GCs below. */
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1124 GCPRO3 (buffer, program, current_dir);
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1125
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 if (!NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 buffer = Fget_buffer_create (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1129 CHECK_STRING (name);
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1130 CHECK_STRING (program);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 /* Make sure that the child will be able to chdir to the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 buffer's current directory, or its unhandled equivalent. We
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 can't just have the child check for an error when it does the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 chdir, since it's in a vfork.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1137 Note: these assignments and calls are like this in order to insure
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1138 "caller protects args" GC semantics. */
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1139 current_dir = current_buffer->directory;
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1140 current_dir = Funhandled_file_name_directory (current_dir);
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1141 current_dir = expand_and_dir_to_file (current_dir, Qnil);
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1142
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 #if 0 /* This loser breaks ange-ftp */
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1144 /* dmoore - if you re-enable this code, you have to gcprotect
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1145 current_buffer through the above calls. */
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1146 if (NILP (Ffile_accessible_directory_p (current_dir)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1147 report_file_error ("Setting current directory",
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1148 list1 (current_buffer->directory));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 /* If program file name is not absolute, search our path for it */
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
1152 if (!IS_DIRECTORY_SEP (XSTRING_BYTE (program, 0))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
1153 && !(XSTRING_LENGTH (program) > 1
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
1154 && IS_DEVICE_SEP (XSTRING_BYTE (program, 1))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 {
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1156 struct gcpro ngcpro1;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1157
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 tem = Qnil;
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1159 NGCPRO1 (tem);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 locate_file (Vexec_path, program, EXEC_SUFFIXES, &tem,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 X_OK);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 if (NILP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 report_file_error ("Searching for program", list1 (program));
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1164 program = Fexpand_file_name (tem, Qnil);
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1165 NUNGCPRO;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 if (!NILP (Ffile_directory_p (program)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 error ("Specified program for new process is a directory");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1173 /* Nothing below here GCs so our string pointers shouldn't move. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
1174 new_argv = alloca_array (char *, nargs - 1);
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1175 new_argv[0] = (char *) XSTRING_DATA (program);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 for (i = 3; i < nargs; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 tem = args[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 CHECK_STRING (tem);
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
1180 new_argv[i - 2] = (char *) XSTRING_DATA (tem);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 new_argv[i - 2] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 proc = make_process_internal (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 XPROCESS (proc)->buffer = buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 XPROCESS (proc)->command = Flist (nargs - 2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 args + 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 /* Make the process marker point into the process buffer (if any). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 if (!NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 Fset_marker (XPROCESS (proc)->mark,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 make_int (BUF_ZV (XBUFFER (buffer))), buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 /* If an error occurs and we can't start the process, we want to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 remove it from the process list. This means that each error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 check in create_process doesn't need to call remove_process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 itself; it's all taken care of here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 record_unwind_protect (start_process_unwind, proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
1201 create_process (proc, new_argv, (char *) XSTRING_DATA (current_dir));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1203 UNGCPRO;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 return unbind_to (speccount, proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 /* connect to an existing file descriptor. This is very similar to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 open-network-stream except that it assumes that the connection has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 already been initialized. It is currently used for ToolTalk
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 communication. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 /* This function used to be visible on the Lisp level, but there is no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 real point in doing that. Here is the doc string:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 "Connect to an existing file descriptor.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 Returns a subprocess-object to represent the connection.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 Input and output work as for subprocesses; `delete-process' closes it.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 Args are NAME BUFFER INFD OUTFD.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 NAME is name for process. It is modified if necessary to make it unique.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 BUFFER is the buffer (or buffer-name) to associate with the process.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 Process output goes at end of that buffer, unless you specify\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 an output stream or filter function to handle the output.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 BUFFER may be also nil, meaning that this process is not associated\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 with any buffer\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 INFD and OUTFD specify the file descriptors to use for input and\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 output, respectively."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 connect_to_file_descriptor (Lisp_Object name, Lisp_Object buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 Lisp_Object infd, Lisp_Object outfd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 int inch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 CHECK_STRING (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 CHECK_INT (infd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 CHECK_INT (outfd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 inch = XINT (infd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 if (!NILP (descriptor_to_process[inch]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 error ("There is already a process connected to fd %d", inch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 if (!NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 buffer = Fget_buffer_create (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 proc = make_process_internal (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 descriptor_to_process[inch] = proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 XPROCESS (proc)->pid = Fcons (infd, name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 XPROCESS (proc)->buffer = buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 init_process_fds (XPROCESS (proc), inch, XINT (outfd));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 XPROCESS (proc)->connected_via_filedesc_p = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 event_stream_select_process (XPROCESS (proc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 return proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 #ifdef HAVE_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 get_internet_address (Lisp_Object host, struct sockaddr_in *address,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
1268 struct hostent *host_info_ptr = NULL;
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 104
diff changeset
1269 #ifdef TRY_AGAIN
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 104
diff changeset
1270 int count = 0;
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 104
diff changeset
1271 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 #ifndef HAVE_TERM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 memset (address, 0, sizeof (*address));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 #ifdef TRY_AGAIN
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 104
diff changeset
1279 if (count++ > 10) break;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 h_errno = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 /* Some systems can't handle SIGIO/SIGALARM in gethostbyname. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 slow_down_interrupts ();
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
1284 host_info_ptr = gethostbyname ((char *) XSTRING_DATA (host));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 speed_up_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 #ifdef TRY_AGAIN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 if (! (host_info_ptr == 0 && h_errno == TRY_AGAIN))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 Fsleep_for (make_int (1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 if (host_info_ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 address->sin_family = host_info_ptr->h_addrtype;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 memcpy (&address->sin_addr, host_info_ptr->h_addr, host_info_ptr->h_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 IN_ADDR numeric_addr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 /* Attempt to interpret host as numeric inet address */
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
1301 numeric_addr = inet_addr ((char *) XSTRING_DATA (host));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 if (NUMERIC_ADDR_ERROR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 maybe_error (Qprocess, errb,
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
1305 "Unknown host \"%s\"", XSTRING_DATA (host));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 /* There was some broken code here that called strlen() here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 on (char *) &numeric_addr and even sometimes accessed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 uninitialized data. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 address->sin_family = AF_INET;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 * (IN_ADDR *) &address->sin_addr = numeric_addr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 /* open a TCP network connection to a given HOST/SERVICE. Treated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 exactly like a normal process when reading and writing. Only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 differences are in status display and process deletion. A network
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 connection has no PID; you cannot signal it. All you can do is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 deactivate and close it via delete-process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1325 DEFUN ("open-network-stream-internal", Fopen_network_stream_internal, 4, 4, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 Open a TCP connection for a service to a host.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 Returns a subprocess-object to represent the connection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 Input and output work as for subprocesses; `delete-process' closes it.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1329
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 NAME is name for process. It is modified if necessary to make it unique.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 BUFFER is the buffer (or buffer-name) to associate with the process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 Process output goes at end of that buffer, unless you specify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 an output stream or filter function to handle the output.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1334 BUFFER may also be nil, meaning that this process is not associated
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1335 with any buffer.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 Third arg is name of the host to connect to, or its IP address.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 Fourth arg SERVICE is name of the service desired, or an integer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 specifying a port number to connect to.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1339 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1340 (name, buffer, host, service))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 /* !!#### This function has not been Mule-ized */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 struct sockaddr_in address;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 int s, outch, inch;
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
1347 volatile int port;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
1349 volatile int retry = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 int retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 GCPRO4 (name, buffer, host, service);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 CHECK_STRING (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 CHECK_STRING (host);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 if (INTP (service))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 port = htons ((unsigned short) XINT (service));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 struct servent *svc_info;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 CHECK_STRING (service);
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
1361 svc_info = getservbyname ((char *) XSTRING_DATA (service), "tcp");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 if (svc_info == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 #ifdef WIN32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 error ("Unknown service \"%s\" (%d)",
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
1365 XSTRING_DATA (service), WSAGetLastError ());
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 #else
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
1367 error ("Unknown service \"%s\"", XSTRING_DATA (service));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 port = svc_info->s_port;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 get_internet_address (host, &address, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 address.sin_port = port;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 s = socket (address.sin_family, SOCK_STREAM, 0);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
1376 if (s < 0)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 report_file_error ("error creating socket", list1 (name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 /* Turn off interrupts here -- see comments below. There used to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 be code which called bind_polling_period() to slow the polling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 period down rather than turn it off, but that seems rather
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 bogus to me. Best thing here is to use a non-blocking connect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 or something, to check for QUIT. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 /* Comments that are not quite valid: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 /* Kernel bugs (on Ultrix at least) cause lossage (not just EINTR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 when connect is interrupted. So let's not let it get interrupted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 Note we do not turn off polling, because polling is only used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 when not interrupt_input, and thus not normally used on the systems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 which have this bug. On systems which use polling, there's no way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 to quit if polling is turned off. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 /* Slow down polling. Some kernels have a bug which causes retrying
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 connect to fail after a connect. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 slow_down_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 loop:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 /* A system call interrupted with a SIGALRM or SIGIO comes back
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 here, with can_break_system_calls reset to 0. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 SETJMP (break_system_call_jump);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 if (QUITP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 speed_up_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 REALLY_QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 /* In case something really weird happens ... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 slow_down_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 /* Break out of connect with a signal (it isn't otherwise possible).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 Thus you don't get screwed with a hung network. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 can_break_system_calls = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 retval = connect (s, (struct sockaddr *) &address, sizeof (address));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 can_break_system_calls = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 if (retval == -1 && errno != EISCONN)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 int xerrno = errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 if (errno == EINTR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 goto loop;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 if (errno == EADDRINUSE && retry < 20)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 /* A delay here is needed on some FreeBSD systems,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 and it is harmless, since this retrying takes time anyway
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
1426 and should be infrequent.
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
1427 `sleep-for' allowed for quitting this loop with interrupts
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
1428 slowed down so it can't be used here. Async timers should
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
1429 already be disabled at this point so we can use `sleep'. */
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
1430 sleep (1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 retry++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 goto loop;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 close (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 speed_up_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 errno = xerrno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 report_file_error ("connection failed", list2 (host, name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 speed_up_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 #else /* HAVE_TERM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 s = connect_server (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 if (s < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 report_file_error ("error creating socket", Fcons (name, Qnil));
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
1449 send_command (s, C_PORT, 0, "%s:%d", XSTRING_DATA (host), ntohs (port));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 send_command (s, C_DUMB, 1, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 #endif /* HAVE_TERM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 inch = s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 outch = dup (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 if (outch < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 close (s); /* this used to be leaked; from Kyle Jones */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 report_file_error ("error duplicating socket", list1 (name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 if (!NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 buffer = Fget_buffer_create (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 proc = make_process_internal (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 descriptor_to_process[inch] = proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1467 #ifdef PROCESS_IO_BLOCKING
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1468 {
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1469 Lisp_Object tail;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1470
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1471 for (tail = network_stream_blocking_port_list; CONSP (tail); tail = XCDR (tail))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1472 {
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1473 Lisp_Object tail_port = XCAR (tail);
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1474
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1475 if (STRINGP (tail_port))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1476 {
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1477 struct servent *svc_info;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1478 CHECK_STRING (tail_port);
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1479 svc_info = getservbyname ((char *) XSTRING_DATA (tail_port), "tcp");
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1480 if ((svc_info != 0) && (svc_info->s_port == port))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1481 break;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1482 else
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1483 continue;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1484 }
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1485 else if ((INTP (tail_port)) && (htons ((unsigned short) XINT (tail_port)) == port))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1486 break;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1487 }
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1488
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1489 if (!CONSP (tail))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1490 {
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1491 #endif /* PROCESS_IO_BLOCKING */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 set_descriptor_non_blocking (inch);
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1493 #ifdef PROCESS_IO_BLOCKING
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1494 }
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1495 }
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
1496 #endif /* PROCESS_IO_BLOCKING */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 XPROCESS (proc)->pid = Fcons (service, host);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 XPROCESS (proc)->buffer = buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 init_process_fds (XPROCESS (proc), inch, outch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 XPROCESS (proc)->connected_via_filedesc_p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 event_stream_select_process (XPROCESS (proc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 return proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 #endif /* HAVE_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 canonicalize_host_name (Lisp_Object host)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 #ifdef HAVE_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 /* #### for HAVE_TERM, you probably have to do something else. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 struct sockaddr_in address;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 if (!get_internet_address (host, &address, ERROR_ME_NOT))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 return host;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 if (address.sin_family == AF_INET)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 return build_string (inet_ntoa (address.sin_addr));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 /* #### any clue what to do here? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 return host;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 return host;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1532 DEFUN ("set-process-window-size", Fset_process_window_size, 3, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 Tell PROCESS that it has logical window size HEIGHT and WIDTH.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1534 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1535 (proc, height, width))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 CHECK_NATNUM (height);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 CHECK_NATNUM (width);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 if (set_window_size (XPROCESS (proc)->infd, XINT (height), XINT (width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 return Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 /* Process I/O */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 /* (Faccept_process_output is now in event-stream.c) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 /* Some FSFmacs error handlers here. We handle this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 in call2_trapping_errors(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 /* Read pending output from the process channel,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 starting with our buffered-ahead character if we have one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 Yield number of characters read.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 This function reads at most 1024 bytes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 If you want to read all available subprocess output,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 you must call it repeatedly until it returns zero. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 read_process_output (Lisp_Object proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 Bytecount nbytes, nchars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 Bufbyte chars[1024];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 Lisp_Object outstream;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 struct Lisp_Process *p = XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 /* If there is a lot of output from the subprocess, the loop in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 execute_internal_event() might call read_process_output() more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 than once. If the filter that was executed from one of these
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 calls set the filter to t, we have to stop now. Return -1 rather
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 than 0 so execute_internal_event() doesn't close the process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 Really, the loop in execute_internal_event() should check itself
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 for a process-filter change, like in status_notify(); but the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 struct Lisp_Process is not exported outside of this file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 if (p->infd < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 return -1; /* already closed */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 if (!NILP (p->filter) && (p->filter_does_read))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 Lisp_Object filter_result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 /* Some weird FSFmacs crap here with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 Vdeactivate_mark and current_buffer->keymap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 running_asynch_code = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 filter_result = call2_trapping_errors ("Error in process filter",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 p->filter, proc, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 running_asynch_code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 restore_match_data ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 CHECK_INT (filter_result);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 return XINT (filter_result);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 #if 0 /* FSFmacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 /* #### equivalent code from FSFmacs. Would need some porting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 for Windows NT. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 if (proc_buffered_char[channel] < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 nchars = read_child_output (channel, chars, sizeof (chars));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 nchars = read (channel, chars, sizeof chars);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 chars[0] = proc_buffered_char[channel];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 proc_buffered_char[channel] = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 nchars = read_child_output (channel, chars + 1, sizeof (chars) - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 nchars = read (channel, chars + 1, sizeof chars - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 if (nchars < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 nchars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 nchars = nchars + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 #endif /* FSFmacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 nbytes = Lstream_read (XLSTREAM (p->instream), chars, sizeof (chars));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 if (nbytes <= 0) return nbytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 nchars = bytecount_to_charcount (chars, nbytes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 outstream = p->filter;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 if (!NILP (outstream))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 /* We used to bind inhibit-quit to t here, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 call2_trapping_errors() does that for us. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 running_asynch_code = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 call2_trapping_errors ("Error in process filter",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 outstream, proc, make_string (chars, nbytes));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 running_asynch_code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 restore_match_data ();
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
1639 return nchars;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 /* If no filter, write into buffer if it isn't dead. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 Lisp_Object old_read_only = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 Bufpos old_point;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 Bufpos old_begv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 Bufpos old_zv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 int old_zmacs_region_stays = zmacs_region_stays;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 struct gcpro gcpro1, gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 struct buffer *buf = XBUFFER (p->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 GCPRO2 (proc, old_read_only);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 old_point = BUF_PT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 old_begv = BUF_BEGV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 old_zv = BUF_ZV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 old_read_only = buf->read_only;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 buf->read_only = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 /* Insert new output into buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 at the current end-of-output marker,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 thus preserving logical ordering of input and output. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 if (XMARKER (p->mark)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 BUF_SET_PT (buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 bufpos_clip_to_bounds (old_begv, marker_position (p->mark),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 old_zv));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 BUF_SET_PT (buf, old_zv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 /* If the output marker is outside of the visible region, save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 the restriction and widen. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 if (! (BUF_BEGV (buf) <= BUF_PT (buf) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 BUF_PT (buf) <= BUF_ZV (buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 Fwiden (p->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 /* Make sure opoint floats ahead of any new text, just as point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 would. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 if (BUF_PT (buf) <= old_point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 old_point += nchars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 /* Insert after old_begv, but before old_zv. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 if (BUF_PT (buf) < old_begv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 old_begv += nchars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 if (BUF_PT (buf) <= old_zv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 old_zv += nchars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 /* This screws up intial display of the window. jla */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 /* Insert before markers in case we are inserting where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 the buffer's mark is, and the user's next command is Meta-y. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 buffer_insert_raw_string_1 (buf, -1, chars,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 nbytes, INSDEL_BEFORE_MARKERS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 buffer_insert_raw_string (buf, chars, nbytes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 Fset_marker (p->mark, make_int (BUF_PT (buf)), p->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 MARK_MODELINE_CHANGED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 /* If the restriction isn't what it should be, set it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 if (old_begv != BUF_BEGV (buf) || old_zv != BUF_ZV (buf))
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1705 {
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1706 Fwiden(p->buffer);
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1707 old_begv = bufpos_clip_to_bounds (BUF_BEG (buf),
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1708 old_begv,
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1709 BUF_Z (buf));
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1710 old_zv = bufpos_clip_to_bounds (BUF_BEG (buf),
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1711 old_zv,
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1712 BUF_Z (buf));
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1713 Fnarrow_to_region (make_int (old_begv), make_int (old_zv),
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1714 p->buffer);
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1715 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 /* Handling the process output should not deactivate the mark. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 zmacs_region_stays = old_zmacs_region_stays;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 buf->read_only = old_read_only;
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1720 old_point = bufpos_clip_to_bounds (BUF_BEGV (buf),
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1721 old_point,
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
1722 BUF_ZV (buf));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 BUF_SET_PT (buf, old_point);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 }
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
1727 return nchars;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 /* Sending data to subprocess */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 static JMP_BUF send_process_frame;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 static SIGTYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 send_process_trap (int signum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 EMACS_REESTABLISH_SIGNAL (signum, send_process_trap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 EMACS_UNBLOCK_SIGNAL (signum);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 LONGJMP (send_process_frame, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 /* send some data to process PROC. If NONRELOCATABLE is non-NULL, it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 specifies the address of the data. Otherwise, the data comes from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 object RELOCATABLE (either a string or a buffer). START and LEN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 specify the offset and length of the data to send.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 Note that START and LEN are in Bufpos's if RELOCATABLE is a buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 and in Bytecounts otherwise. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 send_process (volatile Lisp_Object proc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 Lisp_Object relocatable, CONST Bufbyte *nonrelocatable,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 int start, int len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 /* Use volatile to protect variables from being clobbered by longjmp. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 struct gcpro gcpro1, gcpro2;
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
1758 SIGTYPE (*volatile old_sigpipe) (int) = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 Lisp_Object lstream = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 volatile struct Lisp_Process *p = XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 #if defined (NO_UNION_TYPE) /* || !defined (__GNUC__) GCC bug only??? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 /* #### ugh! There must be a better solution. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 Lisp_Object defeat_volatile_kludge = (Lisp_Object) proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 Lisp_Object defeat_volatile_kludge = proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 GCPRO2 (defeat_volatile_kludge, lstream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 if (p->outfd < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 signal_simple_error ("Process not open for writing", proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 if (nonrelocatable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 lstream =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 make_fixed_buffer_input_stream (nonrelocatable + start, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 else if (GC_BUFFERP (relocatable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 lstream = make_lisp_buffer_input_stream (XBUFFER (relocatable),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 start, start + len, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 lstream = make_lisp_string_input_stream (relocatable, start, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 if (!SETJMP (send_process_frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 /* use a reasonable-sized buffer (somewhere around the size of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 stream buffer) so as to avoid inundating the stream with blocked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 data. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 Bufbyte chunkbuf[512];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 Bytecount chunklen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 int writeret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 chunklen = Lstream_read (XLSTREAM (lstream), chunkbuf, 512);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 if (chunklen <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 break; /* perhaps should abort() if < 0?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 This should never happen. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 old_sigpipe =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 /* Lstream_write() will never successfully write less than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 the amount sent in. In the worst case, it just buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 the unwritten data. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 writeret = Lstream_write (XLSTREAM (p->outstream), chunkbuf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 chunklen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 if (writeret < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 /* This is a real error. Blocking errors are handled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 specially inside of the filedesc stream. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 report_file_error ("writing to process",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 list1 (proc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 while (filedesc_stream_was_blocked (XLSTREAM (p->filedesc_stream)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
1813 /* Buffer is full. Wait, accepting input;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 that may allow the program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 to finish doing output and read more. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 Faccept_process_output (Qnil, make_int (1), Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 old_sigpipe =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 Lstream_flush (XLSTREAM (p->filedesc_stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 { /* We got here from a longjmp() from the SIGPIPE handler */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 p->status_symbol = Qexit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 p->exit_code = 256; /* #### SIGPIPE ??? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 p->core_dumped = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 p->tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 process_tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 deactivate_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 error ("SIGPIPE raised on process %s; closed it",
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1834 XSTRING_DATA (p->name));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 }
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1836 old_sigpipe = (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 Lstream_flush (XLSTREAM (p->outstream));
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1838 signal (SIGPIPE, old_sigpipe);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 UNGCPRO;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
1840 Lstream_delete (XLSTREAM (lstream));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1843 DEFUN ("process-tty-name", Fprocess_tty_name, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 Return the name of the terminal PROCESS uses, or nil if none.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 This is the terminal that the process itself reads and writes on,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 not the name of the pty that Emacs uses to talk with that terminal.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1847 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1848 (proc))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 return XPROCESS (proc)->tty_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1854 DEFUN ("set-process-buffer", Fset_process_buffer, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 Set buffer associated with PROCESS to BUFFER (a buffer, or nil).
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1856 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1857 (proc, buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 if (!NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 CHECK_BUFFER (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 XPROCESS (proc)->buffer = buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 return buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1866 DEFUN ("process-buffer", Fprocess_buffer, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 Return the buffer PROCESS is associated with.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 Output from PROCESS is inserted in this buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 unless PROCESS has a filter.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1870 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1871 (proc))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 return XPROCESS (proc)->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1877 DEFUN ("process-mark", Fprocess_mark, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 Return the marker for the end of the last output from PROCESS.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1879 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1880 (proc))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 return XPROCESS (proc)->mark;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 set_process_filter (Lisp_Object proc, Lisp_Object filter, int filter_does_read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 CHECK_PROCESS (proc);
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 223
diff changeset
1890 if (PROCESS_LIVE_P (proc)) {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 if (EQ (filter, Qt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 event_stream_unselect_process (XPROCESS (proc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 event_stream_select_process (XPROCESS (proc));
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 223
diff changeset
1895 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 XPROCESS (proc)->filter = filter;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 XPROCESS (proc)->filter_does_read = filter_does_read;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1901 DEFUN ("set-process-filter", Fset_process_filter, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 Give PROCESS the filter function FILTER; nil means no filter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 t means stop accepting output from the process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 When a process has a filter, each time it does output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 the entire string of output is passed to the filter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 The filter gets two arguments: the process and the string of output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 If the process has a filter, its buffer is not used for output.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1908 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1909 (proc, filter))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 set_process_filter (proc, filter, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 return filter;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1915 DEFUN ("process-filter", Fprocess_filter, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 Return the filter function of PROCESS; nil if none.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 See `set-process-filter' for more info on filter functions.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1918 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1919 (proc))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 return XPROCESS (proc)->filter;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1925 DEFUN ("process-send-region", Fprocess_send_region, 3, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 Send current contents of region as input to PROCESS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 PROCESS may be a process name or an actual process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 Called from program, takes three arguments, PROCESS, START and END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 If the region is more than 500 or so characters long,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 it is sent in several bunches. This may happen even for shorter regions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 Output from processes can arrive in between bunches.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1932 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1933 (process, start, end))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 Lisp_Object proc = get_process (process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 Bufpos st, en;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 get_buffer_range_char (current_buffer, start, end, &st, &en, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 send_process (proc, Fcurrent_buffer (), 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 st, en - st);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
1943 return Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1946 DEFUN ("process-send-string", Fprocess_send_string, 2, 4, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 Send PROCESS the contents of STRING as input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 PROCESS may be a process name or an actual process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 Optional arguments FROM and TO specify part of STRING, see `substring'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 If STRING is more than 500 or so characters long,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 it is sent in several bunches. This may happen even for shorter strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 Output from processes can arrive in between bunches.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1953 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1954 (process, string, from, to))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 Bytecount len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 Bytecount bfr, bto;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 proc = get_process (process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 CHECK_STRING (string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 get_string_range_byte (string, from, to, &bfr, &bto,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 GB_HISTORICAL_STRING_BEHAVIOR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 len = bto - bfr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 send_process (proc, string, 0, bfr, len);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
1968 return Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1971 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1972
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1973 DEFUN ("process-input-coding-system", Fprocess_input_coding_system, 1, 1, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1974 Return PROCESS's input coding system.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1975 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1976 (process))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1977 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1978 process = get_process (process);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1979 return decoding_stream_coding_system (XLSTREAM ( XPROCESS (process)->instream) );
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1980 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1981
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1982 DEFUN ("process-output-coding-system", Fprocess_output_coding_system, 1, 1, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1983 Return PROCESS's output coding system.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1984 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1985 (process))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1986 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1987 process = get_process (process);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1988 return encoding_stream_coding_system (XLSTREAM (XPROCESS (process)->outstream));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1989 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
1990
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1991 DEFUN ("process-coding-system", Fprocess_coding_system, 1, 1, 0, /*
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1992 Return a pair of coding-system for decoding and encoding of PROCESS.
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1993 */
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1994 (process))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1995 {
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
1996 process = get_process (process);
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
1997 return Fcons (decoding_stream_coding_system
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
1998 (XLSTREAM (XPROCESS (process)->instream)),
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
1999 encoding_stream_coding_system
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2000 (XLSTREAM (XPROCESS (process)->outstream)));
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2001 }
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2002
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2003 DEFUN ("set-process-input-coding-system",
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2004 Fset_process_input_coding_system, 2, 2, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2005 Set PROCESS's input coding system to CODESYS.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2006 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2007 (process, codesys))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2008 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2009 codesys = Fget_coding_system (codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2010 process = get_process (process);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2011 set_decoding_stream_coding_system ( XLSTREAM ( XPROCESS (process)->instream ), codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2012 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2013 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2014
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2015 DEFUN ("set-process-output-coding-system",
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2016 Fset_process_output_coding_system, 2, 2, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2017 Set PROCESS's output coding system to CODESYS.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2018 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2019 (process, codesys))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2020 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2021 codesys = Fget_coding_system (codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2022 process = get_process (process);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2023 set_encoding_stream_coding_system
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2024 ( XLSTREAM ( XPROCESS (process)->outstream), codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2025 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2026 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2027
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2028 DEFUN ("set-process-coding-system",
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2029 Fset_process_coding_system, 1, 3, 0, /*
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2030 Set coding-systems of PROCESS to DECODING and ENCODING.
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2031 */
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2032 (process, decoding, encoding))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2033 {
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2034 if(!NILP(decoding)){
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2035 Fset_process_input_coding_system(process, decoding);
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2036 }
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2037 if(!NILP(encoding)){
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2038 Fset_process_output_coding_system(process, encoding);
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2039 }
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2040 return Qnil;
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2041 }
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
2042
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2043 #endif /* MULE */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2044
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 /* process status */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 /* Some FSFmacs error handlers here. We handle this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 in call2_trapping_errors(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 exec_sentinel_unwind (Lisp_Object datum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 struct Lisp_Cons *d = XCONS (datum);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 XPROCESS (d->car)->sentinel = d->cdr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 free_cons (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 exec_sentinel (Lisp_Object proc, Lisp_Object reason)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 /* This function can GC */
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2066 int speccount = specpdl_depth ();
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 struct Lisp_Process *p = XPROCESS (proc);
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2068 Lisp_Object sentinel = p->sentinel;
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2069
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 if (NILP (sentinel))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 /* Some weird FSFmacs crap here with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 Vdeactivate_mark and current_buffer->keymap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 /* Zilch the sentinel while it's running, to avoid recursive invocations;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 assure that it gets restored no matter how the sentinel exits. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 p->sentinel = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 record_unwind_protect (exec_sentinel_unwind, noseeum_cons (proc, sentinel));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 /* We used to bind inhibit-quit to t here, but call2_trapping_errors()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 does that for us. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 running_asynch_code = 1;
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2083 call2_trapping_errors ("Error in process sentinel", sentinel, proc, reason);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 running_asynch_code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 restore_match_data ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2089 DEFUN ("set-process-sentinel", Fset_process_sentinel, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 Give PROCESS the sentinel SENTINEL; nil for none.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 The sentinel is called as a function when the process changes state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 It gets two arguments: the process, and a string describing the change.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2093 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2094 (proc, sentinel))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 XPROCESS (proc)->sentinel = sentinel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 return sentinel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2101 DEFUN ("process-sentinel", Fprocess_sentinel, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 Return the sentinel of PROCESS; nil if none.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 See `set-process-sentinel' for more info on sentinels.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2104 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2105 (proc))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 return XPROCESS (proc)->sentinel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 CONST char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 signal_name (int signum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 if (signum >= 0 && signum < NSIG)
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
2116 return (CONST char *) sys_siglist[signum];
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
2117
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
2118 return (CONST char *) GETTEXT ("unknown signal");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 /* Compute the Lisp form of the process status from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 the numeric status that was returned by `wait'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 static void
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2125 update_status_from_wait_code (struct Lisp_Process *p, int *w_fmh)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 /* C compiler lossage when attempting to pass w directly */
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2128 int w = *w_fmh;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 if (WIFSTOPPED (w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 p->status_symbol = Qstop;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 p->exit_code = WSTOPSIG (w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 p->core_dumped = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 else if (WIFEXITED (w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 p->status_symbol = Qexit;
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2139 p->exit_code = WEXITSTATUS (w);
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2140 p->core_dumped = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 else if (WIFSIGNALED (w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 p->status_symbol = Qsignal;
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2145 p->exit_code = WTERMSIG (w);
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2146 p->core_dumped = WCOREDUMP (w);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 p->status_symbol = Qrun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 p->exit_code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 update_process_status (Lisp_Object p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 Lisp_Object status_symbol,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 int exit_code,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 int core_dumped)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 XPROCESS (p)->tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 process_tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 XPROCESS (p)->status_symbol = status_symbol;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 XPROCESS (p)->exit_code = exit_code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 XPROCESS (p)->core_dumped = core_dumped;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 #ifdef SIGCHLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 #define MAX_EXITED_PROCESSES 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 static volatile pid_t exited_processes[MAX_EXITED_PROCESSES];
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2172 static volatile int exited_processes_status[MAX_EXITED_PROCESSES];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 static volatile int exited_processes_index;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 static volatile int sigchld_happened;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 /* For any processes that have changed status and are recorded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 and such, update the corresponding struct Lisp_Process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 We separate this from record_exited_processes() so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 we never have to call this function from within a signal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 handler. We block SIGCHLD in case record_exited_processes()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 is called from a signal handler. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 reap_exited_processes (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 struct Lisp_Process *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
2190 if (exited_processes_index <= 0)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
2191 {
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
2192 return;
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
2193 }
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
2194
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
2195 #ifdef EMACS_BLOCK_SIGNAL
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 EMACS_BLOCK_SIGNAL (SIGCHLD);
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
2197 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 for (i = 0; i < exited_processes_index; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 int pid = exited_processes[i];
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2201 int w = exited_processes_status[i];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 /* Find the process that signaled us, and record its status. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 Lisp_Object tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 LIST_LOOP (tail, Vprocess_list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 Lisp_Object proc = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 p = XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 if (INTP (p->pid) && XINT (p->pid) == pid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 if (p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 /* Change the status of the process that was found. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 p->tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 process_tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 update_status_from_wait_code (p, &w);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
2224
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 /* If process has terminated, stop waiting for its output. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 if (WIFSIGNALED (w) || WIFEXITED (w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 if (p->infd >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 /* We can't just call event_stream->unselect_process_cb (p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 here, because that calls XtRemoveInput, which is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 necessarily reentrant, so we can't call this at interrupt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 /* There was no asynchronous process found for that id. Check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 if we have a synchronous process. Only set sync process status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 if there is one, so we work OK with the waitpid() call in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 wait_for_termination(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 if (synch_process_alive != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 { /* Set the global sync process status variables. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 synch_process_alive = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 /* Report the status of the synchronous process. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 if (WIFEXITED (w))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2250 synch_process_retcode = WEXITSTATUS (w);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 else if (WIFSIGNALED (w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 synch_process_death = signal_name (WTERMSIG (w));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 exited_processes_index = 0;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
2258
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 /* On receipt of a signal that a child status has changed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 loop asking about children with changed statuses until
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 the system says there are no more. All we do is record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 the processes and wait status.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 This function could be called from within the SIGCHLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 handler, so it must be completely reentrant. When
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 not called from a SIGCHLD handler, BLOCK_SIGCHLD should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 be non-zero so that SIGCHLD is blocked while this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 function is running. (This is necessary so avoid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 race conditions with the SIGCHLD_HAPPENED flag). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 record_exited_processes (int block_sigchld)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 {
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
2277 if (!sigchld_happened)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
2278 {
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
2279 return;
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
2280 }
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
2281
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
2282 #ifdef EMACS_BLOCK_SIGNAL
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 if (block_sigchld)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 EMACS_BLOCK_SIGNAL (SIGCHLD);
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
2285 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 while (sigchld_happened)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 int pid;
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2290 int w;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
2291
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 /* Keep trying to get a status until we get a definitive result. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
2293 do
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 errno = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 #ifdef WNOHANG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 # ifndef WUNTRACED
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 # define WUNTRACED 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 # endif /* not WUNTRACED */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 # ifdef HAVE_WAITPID
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 pid = waitpid ((pid_t) -1, &w, WNOHANG | WUNTRACED);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 pid = wait3 (&w, WNOHANG | WUNTRACED, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 #else /* not WNOHANG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 pid = wait (&w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 #endif /* not WNOHANG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 while (pid <= 0 && errno == EINTR);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
2310
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 if (pid <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 break;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
2313
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 if (exited_processes_index < MAX_EXITED_PROCESSES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 exited_processes[exited_processes_index] = pid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 exited_processes_status[exited_processes_index] = w;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 exited_processes_index++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
2320
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 /* On systems with WNOHANG, we just ignore the number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 of times that SIGCHLD was signalled, and keep looping
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 until there are no more processes to wait on. If we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 don't have WNOHANG, we have to rely on the count in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 SIGCHLD_HAPPENED. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 #ifndef WNOHANG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 sigchld_happened--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 #endif /* not WNOHANG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 sigchld_happened = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 if (block_sigchld)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 /** USG WARNING: Although it is not obvious from the documentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 in signal(2), on a USG system the SIGCLD handler MUST NOT call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 signal() before executing at least one wait(), otherwise the handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 will be called again, resulting in an infinite loop. The relevant
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 portion of the documentation reads "SIGCLD signals will be queued
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 and the signal-catching function will be continually reentered until
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 the queue is empty". Invoking signal() causes the kernel to reexamine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 the SIGCLD queue. Fred Fish, UniSoft Systems Inc.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
2345
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 (Note that now this only applies in SYS V Release 2 and before.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 On SYS V Release 3, we use sigset() to set the signal handler for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 the first time, and so we don't have to reestablish the signal handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 in the handler below. On SYS V Release 4, we don't get this weirdo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 behavior when we use sigaction(), which we do use.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 static SIGTYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 sigchld_handler (int signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 #ifdef OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 int old_errno = errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 sigchld_happened++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 record_exited_processes (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 errno = old_errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 sigchld_happened++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 #endif
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 217
diff changeset
2364 #ifdef HAVE_UNIXOID_EVENT_LOOP
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 signal_fake_event ();
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 217
diff changeset
2366 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 /* WARNING - must come after wait3() for USG systems */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 EMACS_REESTABLISH_SIGNAL (signo, sigchld_handler);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 SIGRETURN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 #endif /* SIGCHLD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 /* Return a string describing a process status list. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
2376 static Lisp_Object
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 status_message (struct Lisp_Process *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 Lisp_Object symbol = p->status_symbol;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 int code = p->exit_code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 int coredump = p->core_dumped;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 Lisp_Object string, string2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 string = build_string (signal_name (code));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 if (coredump)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 string2 = build_translated_string (" (core dumped)\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 string2 = build_string ("\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 set_string_char (XSTRING (string), 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 DOWNCASE (current_buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 string_char (XSTRING (string), 0)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 return concat2 (string, string2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 else if (EQ (symbol, Qexit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 if (code == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 return build_translated_string ("finished\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 string = Fnumber_to_string (make_int (code));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 if (coredump)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 string2 = build_translated_string (" (core dumped)\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 string2 = build_string ("\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 return concat2 (build_translated_string ("exited abnormally with code "),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 concat2 (string, string2));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 return Fcopy_sequence (Fsymbol_name (symbol));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 /* Tell status_notify() to check for terminated processes. We do this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 because on some systems we sometimes miss SIGCHLD calls. (Not sure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 why.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 kick_status_notify (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 process_tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 /* Report all recent events of a change in process status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 (either run the sentinel or output a message).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 This is done while Emacs is waiting for keyboard input. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 status_notify (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 Lisp_Object tail = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 Lisp_Object symbol = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 Lisp_Object msg = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 struct gcpro gcpro1, gcpro2, gcpro3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 /* process_tick is volatile, so we have to remember it now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 Otherwise, we get a race condition is SIGCHLD happens during
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 this function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 (Actually, this is not the case anymore. The code to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 update the process structures has been moved out of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 SIGCHLD handler. But for the moment I'm leaving this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 stuff in -- it can't hurt.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 int temp_process_tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 #ifdef SIGCHLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 #ifndef OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 record_exited_processes (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 reap_exited_processes ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 temp_process_tick = process_tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 if (update_tick == temp_process_tick)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 /* We need to gcpro tail; if read_process_output calls a filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 which deletes a process and removes the cons to which tail points
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 from Vprocess_alist, and then causes a GC, tail is an unprotected
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 reference. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 GCPRO3 (tail, symbol, msg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 Lisp_Object proc = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 struct Lisp_Process *p = XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 /* p->tick is also volatile. Same thing as above applies. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 int this_process_tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 #ifdef HAVE_WAITPID
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 /* #### extra check for terminated processes, in case a SIGCHLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 got missed (this seems to happen sometimes, I'm not sure why).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 {
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2474 int w;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 #ifdef SIGCHLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 EMACS_BLOCK_SIGNAL (SIGCHLD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 if (INTP (p->pid) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 waitpid (XINT (p->pid), &w, WNOHANG) == XINT (p->pid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 p->tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 update_status_from_wait_code (p, &w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 #ifdef SIGCHLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489 this_process_tick = p->tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 if (this_process_tick != p->update_tick)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 p->update_tick = this_process_tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 /* If process is still active, read any output that remains. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 while (!EQ (p->filter, Qt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 && read_process_output (proc) > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 /* Get the text to use for the message. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 msg = status_message (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 /* If process is terminated, deactivate it or delete it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 symbol = p->status_symbol;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
2505 if (EQ (symbol, Qsignal)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 || EQ (symbol, Qexit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 if (delete_exited_processes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 remove_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 deactivate_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 /* Now output the message suitably. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515 if (!NILP (p->sentinel))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516 exec_sentinel (proc, msg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 /* Don't bother with a message in the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 when a process becomes runnable. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 else if (!EQ (symbol, Qrun) && !NILP (p->buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 {
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2521 Lisp_Object old_read_only = Qnil;
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2522 Lisp_Object old = Fcurrent_buffer ();
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2523 Bufpos opoint;
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2524 struct gcpro ngcpro1, ngcpro2;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 /* Avoid error if buffer is deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 (probably that's why the process is dead, too) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 if (!BUFFER_LIVE_P (XBUFFER (p->buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2531 NGCPRO2 (old, old_read_only);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532 Fset_buffer (p->buffer);
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2533 opoint = BUF_PT (current_buffer);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 /* Insert new output into buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 at the current end-of-output marker,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536 thus preserving logical ordering of input and output. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 if (XMARKER (p->mark)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 BUF_SET_PT (current_buffer, marker_position (p->mark));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 BUF_SET_PT (current_buffer, BUF_ZV (current_buffer));
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2541 if (BUF_PT (current_buffer) <= opoint)
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2542 opoint += (string_char_length (XSTRING (msg))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2543 + string_char_length (XSTRING (p->name))
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2544 + 10);
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2545
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2546 old_read_only = current_buffer->read_only;
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2547 current_buffer->read_only = Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 buffer_insert_c_string (current_buffer, "\nProcess ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 Finsert (1, &p->name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 buffer_insert_c_string (current_buffer, " ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 Finsert (1, &msg);
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2552 current_buffer->read_only = old_read_only;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 Fset_marker (p->mark, make_int (BUF_PT (current_buffer)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 p->buffer);
161
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2555
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2556 opoint = bufpos_clip_to_bounds(BUF_BEGV (XBUFFER (p->buffer)),
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2557 opoint,
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2558 BUF_ZV (XBUFFER (p->buffer)));
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2559 BUF_SET_PT (current_buffer, opoint);
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2560 Fset_buffer (old);
28f395d8dc7a Import from CVS: tag r20-3b7
cvs
parents: 159
diff changeset
2561 NUNGCPRO;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 } /* end for */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 /* in case buffers use %s in modeline-format */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 MARK_MODELINE_CHANGED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 redisplay ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 update_tick = temp_process_tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2575 DEFUN ("process-status", Fprocess_status, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 Return the status of PROCESS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 This is a symbol, one of these:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2579 run -- for a process that is running.
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2580 stop -- for a process stopped but continuable.
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2581 exit -- for a process that has exited.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 signal -- for a process that has got a fatal signal.
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2583 open -- for a network stream connection that is open.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 closed -- for a network stream connection that is closed.
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2585 nil -- if arg is a process name and no such process exists.
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2586
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 PROCESS may be a process, a buffer, the name of a process or buffer, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 nil, indicating the current buffer's process.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2589 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2590 (proc))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 {
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2592 Lisp_Object status_symbol;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 if (STRINGP (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 proc = Fget_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 proc = get_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 if (NILP (proc))
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2600 return Qnil;
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2601
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2602 status_symbol = XPROCESS (proc)->status_symbol;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 if (network_connection_p (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 {
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2605 if (EQ (status_symbol, Qrun))
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2606 status_symbol = Qopen;
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2607 else if (EQ (status_symbol, Qexit))
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2608 status_symbol = Qclosed;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 }
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2610 return status_symbol;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2613 DEFUN ("process-exit-status", Fprocess_exit_status, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 Return the exit status of PROCESS or the signal number that killed it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 If PROCESS has not yet exited or died, return 0.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2616 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2617 (proc))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 CHECK_PROCESS (proc);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
2620 return make_int (XPROCESS (proc)->exit_code);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 #ifdef SIGNALS_VIA_CHARACTERS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 /* Get signal character to send to process if SIGNALS_VIA_CHARACTERS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 process_signal_char (int tty_fd, int signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 /* If it's not a tty, pray that these default values work */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 if (!isatty(tty_fd)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 #define CNTL(ch) (037 & (ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 switch (signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 case SIGINT: return CNTL('C');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 case SIGQUIT: return CNTL('\\');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 #ifdef SIGTSTP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 case SIGTSTP: return CNTL('Z');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 #ifdef HAVE_TERMIOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 /* TERMIOS is the latest and bestest, and seems most likely to work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 If the system has it, use it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 struct termios t;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 tcgetattr (tty_fd, &t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 switch (signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 case SIGINT: return t.c_cc[VINTR];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 case SIGQUIT: return t.c_cc[VQUIT];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 # if defined (VSWTCH) && !defined (PREFER_VSUSP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 case SIGTSTP: return t.c_cc[VSWTCH];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 case SIGTSTP: return t.c_cc[VSUSP];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 # elif defined (TIOCGLTC) && defined (TIOCGETC) /* not HAVE_TERMIOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 /* On Berkeley descendants, the following IOCTL's retrieve the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 current control characters. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 struct tchars c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 struct ltchars lc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 switch (signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 case SIGINT: ioctl (tty_fd, TIOCGETC, &c); return c.t_intrc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 case SIGQUIT: ioctl (tty_fd, TIOCGETC, &c); return c.t_quitc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 # ifdef SIGTSTP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 case SIGTSTP: ioctl (tty_fd, TIOCGLTC, &lc); return lc.t_suspc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 # endif /* SIGTSTP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 # elif defined (TCGETA) /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 /* On SYSV descendants, the TCGETA ioctl retrieves the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 control characters. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 struct termio t;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 ioctl (tty_fd, TCGETA, &t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 switch (signo) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 case SIGINT: return t.c_cc[VINTR];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 case SIGQUIT: return t.c_cc[VQUIT];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 # ifdef SIGTSTP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 case SIGTSTP: return t.c_cc[VSWTCH];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 # endif /* SIGTSTP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691 # else /* ! defined (TCGETA) */
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
2692 #error ERROR! Using SIGNALS_VIA_CHARACTERS, but not HAVE_TERMIOS || (TIOCGLTC && TIOCGETC) || TCGETA
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 /* If your system configuration files define SIGNALS_VIA_CHARACTERS,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 you'd better be using one of the alternatives above! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 # endif /* ! defined (TCGETA) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 return '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 #endif /* SIGNALS_VIA_CHARACTERS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701 /* send a signal number SIGNO to PROCESS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 CURRENT_GROUP means send to the process group that currently owns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 the terminal being used to communicate with PROCESS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 This is used for various commands in shell mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 If NOMSG is zero, insert signal-announcements into process's buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 right away.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 If we can, we try to signal PROCESS by sending control characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 down the pty. This allows us to signal inferiors who have changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 their uid, for which killpg would return an EPERM error. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 process_send_signal (Lisp_Object process0, int signo,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 int current_group, int nomsg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 Lisp_Object proc = get_process (process0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 struct Lisp_Process *p = XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 int gid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 int no_pgrp = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722 if (network_connection_p (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 error ("Network connection %s is not a subprocess",
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2724 XSTRING_DATA (p->name));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725 if (p->infd < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 error ("Process %s is not active",
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2727 XSTRING_DATA (p->name));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 if (!p->pty_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 current_group = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 /* If we are using pgrps, get a pgrp number and make it negative. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 if (current_group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 #ifdef SIGNALS_VIA_CHARACTERS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 /* If possible, send signals to the entire pgrp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 by sending an input character to it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 char sigchar = process_signal_char(p->subtty, signo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 if (sigchar) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 send_process (proc, Qnil, (Bufbyte *) &sigchar, 0, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 #endif /* ! defined (SIGNALS_VIA_CHARACTERS) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
2747 #ifdef TIOCGPGRP
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 /* Get the pgrp using the tty itself, if we have that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749 Otherwise, use the pty to get the pgrp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 On pfa systems, saka@pfu.fujitsu.co.JP writes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 "TIOCGPGRP symbol defined in sys/ioctl.h at E50.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 But, TIOCGPGRP does not work on E50 ;-P works fine on E60"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 His patch indicates that if TIOCGPGRP returns an error, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 we should just assume that p->pid is also the process group id. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756 int err;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 err = ioctl ( (p->subtty != -1 ? p->subtty : p->infd), TIOCGPGRP, &gid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 #ifdef pfa
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 if (err == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 gid = - XINT (p->pid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 #endif /* ! defined (pfa) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 if (gid == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 no_pgrp = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 gid = - gid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 #else /* ! defined (TIOCGPGRP ) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 /* Can't select pgrps on this system, so we know that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 the child itself heads the pgrp. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 gid = - XINT (p->pid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 #endif /* ! defined (TIOCGPGRP ) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 gid = - XINT (p->pid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 switch (signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 #ifdef SIGCONT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 case SIGCONT:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 p->status_symbol = Qrun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783 p->exit_code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 p->tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 process_tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 if (!nomsg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 status_notify ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789 #endif /* ! defined (SIGCONT) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 case SIGINT:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 case SIGQUIT:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 case SIGKILL:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 flush_pending_output (p->infd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2797 /* If we don't have process groups, send the signal to the immediate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 subprocess. That isn't really right, but it's better than any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799 obvious alternative. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 if (no_pgrp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 kill (XINT (p->pid), signo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 /* gid may be a pid, or minus a pgrp's number */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807 #ifdef TIOCSIGSEND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 if (current_group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809 ioctl (p->infd, TIOCSIGSEND, signo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 gid = - XINT (p->pid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813 kill (gid, signo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 #else /* ! defined (TIOCSIGSEND) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 EMACS_KILLPG (-gid, signo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 #endif /* ! defined (TIOCSIGSEND) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2820 DEFUN ("interrupt-process", Finterrupt_process, 0, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821 Interrupt process PROCESS. May be process or name of one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 Nil or no arg means current buffer's process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 Second arg CURRENT-GROUP non-nil means send signal to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 the current process-group of the process's controlling terminal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825 rather than to the process's own process group.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826 If the process is a shell, this means interrupt current subjob
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 rather than the shell.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2828 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2829 (process, current_group))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 process_send_signal (process, SIGINT, !NILP (current_group), 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 return process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2836 DEFUN ("kill-process", Fkill_process, 0, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 Kill process PROCESS. May be process or name of one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 See function `interrupt-process' for more details on usage.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2839 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2840 (process, current_group))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 process_send_signal (process, SIGKILL, !NILP (current_group),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 return process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2848 DEFUN ("quit-process", Fquit_process, 0, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 Send QUIT signal to process PROCESS. May be process or name of one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 See function `interrupt-process' for more details on usage.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2851 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2852 (process, current_group))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 process_send_signal (process, SIGQUIT, !NILP (current_group),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 return process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2860 DEFUN ("stop-process", Fstop_process, 0, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 Stop process PROCESS. May be process or name of one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 See function `interrupt-process' for more details on usage.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2863 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2864 (process, current_group))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 #ifndef SIGTSTP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 error ("no SIGTSTP support");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 process_send_signal (process, SIGTSTP, !NILP (current_group),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873 return process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2876 DEFUN ("continue-process", Fcontinue_process, 0, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2877 Continue process PROCESS. May be process or name of one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2878 See function `interrupt-process' for more details on usage.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2879 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2880 (process, current_group))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2881 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2882 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2883 #ifdef SIGCONT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2884 process_send_signal (process, SIGCONT, !NILP (current_group),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2885 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2886 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2887 error ("no SIGCONT support");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2888 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2889 return process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2890 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2891
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2892 DEFUN ("signal-process", Fsignal_process, 2, 2,
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2893 "nProcess number: \nnSignal code: ", /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2894 Send the process with process id PID the signal with code SIGCODE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2895 PID must be an integer. The process need not be a child of this Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2896 SIGCODE may be an integer, or a symbol whose name is a signal name.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2897 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2898 (pid, sigcode))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2899 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2900 CHECK_INT (pid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2901
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2902 #define handle_signal(NAME, VALUE) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2903 else if (!strcmp ((CONST char *) name, NAME)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2904 XSETINT (sigcode, VALUE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2905
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2906 if (INTP (sigcode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2907 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2908 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2909 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2910 Bufbyte *name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2911
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2912 CHECK_SYMBOL (sigcode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2913 name = string_data (XSYMBOL (sigcode)->name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2914
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2915 if (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2916 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917 #ifdef SIGHUP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918 handle_signal ("SIGHUP", SIGHUP);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2920 #ifdef SIGINT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921 handle_signal ("SIGINT", SIGINT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2923 #ifdef SIGQUIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2924 handle_signal ("SIGQUIT", SIGQUIT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2925 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926 #ifdef SIGILL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927 handle_signal ("SIGILL", SIGILL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2928 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2929 #ifdef SIGABRT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2930 handle_signal ("SIGABRT", SIGABRT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2931 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2932 #ifdef SIGEMT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2933 handle_signal ("SIGEMT", SIGEMT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2934 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2935 #ifdef SIGKILL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2936 handle_signal ("SIGKILL", SIGKILL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2937 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2938 #ifdef SIGFPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2939 handle_signal ("SIGFPE", SIGFPE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2940 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2941 #ifdef SIGBUS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2942 handle_signal ("SIGBUS", SIGBUS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2943 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2944 #ifdef SIGSEGV
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2945 handle_signal ("SIGSEGV", SIGSEGV);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2946 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2947 #ifdef SIGSYS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2948 handle_signal ("SIGSYS", SIGSYS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2949 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2950 #ifdef SIGPIPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2951 handle_signal ("SIGPIPE", SIGPIPE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2952 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2953 #ifdef SIGALRM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2954 handle_signal ("SIGALRM", SIGALRM);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2955 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2956 #ifdef SIGTERM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2957 handle_signal ("SIGTERM", SIGTERM);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2958 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2959 #ifdef SIGURG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2960 handle_signal ("SIGURG", SIGURG);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2961 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2962 #ifdef SIGSTOP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2963 handle_signal ("SIGSTOP", SIGSTOP);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2964 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2965 #ifdef SIGTSTP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2966 handle_signal ("SIGTSTP", SIGTSTP);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2967 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968 #ifdef SIGCONT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969 handle_signal ("SIGCONT", SIGCONT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2970 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2971 #ifdef SIGCHLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2972 handle_signal ("SIGCHLD", SIGCHLD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2973 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2974 #ifdef SIGTTIN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2975 handle_signal ("SIGTTIN", SIGTTIN);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2976 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2977 #ifdef SIGTTOU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2978 handle_signal ("SIGTTOU", SIGTTOU);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2979 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2980 #ifdef SIGIO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2981 handle_signal ("SIGIO", SIGIO);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2982 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2983 #ifdef SIGXCPU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2984 handle_signal ("SIGXCPU", SIGXCPU);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986 #ifdef SIGXFSZ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987 handle_signal ("SIGXFSZ", SIGXFSZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2988 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2989 #ifdef SIGVTALRM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2990 handle_signal ("SIGVTALRM", SIGVTALRM);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 #ifdef SIGPROF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2993 handle_signal ("SIGPROF", SIGPROF);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2995 #ifdef SIGWINCH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2996 handle_signal ("SIGWINCH", SIGWINCH);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 #ifdef SIGINFO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999 handle_signal ("SIGINFO", SIGINFO);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3000 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3001 #ifdef SIGUSR1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002 handle_signal ("SIGUSR1", SIGUSR1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3004 #ifdef SIGUSR2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3005 handle_signal ("SIGUSR2", SIGUSR2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3006 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008 error ("Undefined signal name %s", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3011 #undef handle_signal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3012
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013 return make_int (kill (XINT (pid), XINT (sigcode)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3014 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3016 DEFUN ("process-send-eof", Fprocess_send_eof, 0, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3017 Make PROCESS see end-of-file in its input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018 PROCESS may be a process, a buffer, the name of a process or buffer, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3019 nil, indicating the current buffer's process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020 If PROCESS is a network connection, or is a process communicating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 through a pipe (as opposed to a pty), then you cannot send any more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 text to PROCESS after you call this function.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3023 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3024 (process))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029 proc = get_process (process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031 /* Make sure the process is really alive. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032 if (! EQ (XPROCESS (proc)->status_symbol, Qrun))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
3033 error ("Process %s not running", XSTRING_DATA (XPROCESS (proc)->name));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3035 if (XPROCESS (proc)->pty_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037 /* #### get_eof_char simply doesn't return the correct character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3038 here. Maybe it is needed to determine the right eof
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 character in init_process_fds but here it simply screws
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040 things up. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3041 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3042 Bufbyte eof_char = get_eof_char (XPROCESS (proc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3043 send_process (proc, Qnil, &eof_char, 0, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3044 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3045 send_process (proc, Qnil, (CONST Bufbyte *) "\004", 0, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3047 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050 close (XPROCESS (proc)->outfd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051 XPROCESS (proc)->outfd = open (NULL_DEVICE, O_WRONLY, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052 }
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
3053
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054 return process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059 /* deleting a process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3060 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 deactivate_process (Lisp_Object proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 int inchannel, outchannel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 struct Lisp_Process *p = XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 SIGTYPE (*old_sigpipe) (int) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069 inchannel = p->infd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3070 outchannel = p->outfd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3071
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 /* closing the outstream could result in SIGPIPE, so ignore it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073 old_sigpipe =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074 (SIGTYPE (*) (int)) signal (SIGPIPE, SIG_IGN);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075 if (!NILP (p->instream))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076 Lstream_close (XLSTREAM (p->instream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077 if (!NILP (p->outstream))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3078 Lstream_close (XLSTREAM (p->outstream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3081 if (inchannel >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3083 /* Beware SIGCHLD hereabouts. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3084 flush_pending_output (inchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3085 close_descriptor_pair (inchannel, outchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3086 if (!NILP (p->pid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3087 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3088 /* It's possible that we got as far in the process-creation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3089 process as creating the descriptors but didn't get so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3090 far as selecting the process for input. In this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091 case, p->pid is nil: p->pid is set at the same time that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092 the process is selected for input. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093 /* Must call this before setting the file descriptors to 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3094 event_stream_unselect_process (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3097 p->infd = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 p->outfd = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099 descriptor_to_process[inchannel] = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3101 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3104 remove_process (Lisp_Object proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106 Vprocess_list = delq_no_quit (proc, Vprocess_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3107 Fset_marker (XPROCESS (proc)->mark, Qnil, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3109 deactivate_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3110 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3111
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3112 DEFUN ("delete-process", Fdelete_process, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3113 Delete PROCESS: kill it and forget about it immediately.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3114 PROCESS may be a process or the name of one, or a buffer name.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3115 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3116 (proc))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3118 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3119 struct Lisp_Process *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3120 proc = get_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3121 p = XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3122 if (network_connection_p (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3123 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124 p->status_symbol = Qexit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3125 p->exit_code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3126 p->core_dumped = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3127 p->tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3128 process_tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3129 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3130 else if (p->infd >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3131 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3132 Fkill_process (proc, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3133 /* Do this now, since remove_process will make sigchld_handler do nothing. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3134 p->status_symbol = Qsignal;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3135 p->exit_code = SIGKILL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3136 p->core_dumped = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3137 p->tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138 process_tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139 status_notify ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141 remove_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3142 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 /* Kill all processes associated with `buffer'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 If `buffer' is nil, kill all processes */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149 kill_buffer_processes (Lisp_Object buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151 Lisp_Object tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 for (tail = Vprocess_list; GC_CONSP (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154 tail = XCDR (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3155 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156 Lisp_Object proc = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3157 if (GC_PROCESSP (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3158 && (GC_NILP (buffer) || GC_EQ (XPROCESS (proc)->buffer, buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3159 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160 if (network_connection_p (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3161 Fdelete_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162 else if (XPROCESS (proc)->infd >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163 process_send_signal (proc, SIGHUP, 0, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3168 #if 0 /* Unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170 count_active_processes (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 Lisp_Object tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 int count = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177 Lisp_Object status = XPROCESS (XCAR (tail))->status_symbol;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178 if ((EQ (status, Qrun) || EQ (status, Qstop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 count++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3182 return count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184 #endif /* Unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3185
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3186 DEFUN ("process-kill-without-query", Fprocess_kill_without_query, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3187 Say no query needed if PROCESS is running when Emacs is exited.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3188 Optional second argument if non-nil says to require a query.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3189 Value is t if a query was formerly required.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3190 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3191 (proc, require_query_p))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3193 int tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196 tem = XPROCESS (proc)->kill_without_query;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197 XPROCESS (proc)->kill_without_query = NILP (require_query_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3199 return tem ? Qnil : Qt;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3202 DEFUN ("process-kill-without-query-p", Fprocess_kill_without_query_p, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3203 Whether PROC will be killed without query if running when emacs is exited.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3204 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3205 (proc))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3206 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207 CHECK_PROCESS (proc);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3208 return XPROCESS (proc)->kill_without_query ? Qt : Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212 /* This is not named init_process in order to avoid a conflict with NS 3.3 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214 init_xemacs_process (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218 #ifdef SIGCHLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219 # ifndef CANNOT_DUMP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 if (! noninteractive || initialized)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 signal (SIGCHLD, sigchld_handler);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223 #endif /* SIGCHLD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225 Vprocess_list = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226 for (i = 0; i < MAXDESC; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 descriptor_to_process[i] = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229 proc_buffered_char[i] = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 }
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3232
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3235 xxDEFUN ("process-connection", Fprocess_connection, 0, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236 Return the connection type of `PROCESS'. This can be nil (pipe),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237 t or pty (pty) or stream (socket connection).
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3238 */
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
3239 (process))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3241 return XPROCESS (process)->type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 syms_of_process (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 defsymbol (&Qprocessp, "processp");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250 defsymbol (&Qrun, "run");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251 defsymbol (&Qstop, "stop");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252 defsymbol (&Qsignal, "signal");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 /* Qexit is already defined by syms_of_eval
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
3254 * defsymbol (&Qexit, "exit");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256 defsymbol (&Qopen, "open");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3257 defsymbol (&Qclosed, "closed");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3259 DEFSUBR (Fprocessp);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3260 DEFSUBR (Fget_process);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3261 DEFSUBR (Fget_buffer_process);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3262 DEFSUBR (Fdelete_process);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3263 DEFSUBR (Fprocess_status);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3264 DEFSUBR (Fprocess_exit_status);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3265 DEFSUBR (Fprocess_id);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3266 DEFSUBR (Fprocess_name);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3267 DEFSUBR (Fprocess_tty_name);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3268 DEFSUBR (Fprocess_command);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3269 DEFSUBR (Fset_process_buffer);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3270 DEFSUBR (Fprocess_buffer);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3271 DEFSUBR (Fprocess_mark);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3272 DEFSUBR (Fset_process_filter);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3273 DEFSUBR (Fprocess_filter);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3274 DEFSUBR (Fset_process_window_size);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3275 DEFSUBR (Fset_process_sentinel);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3276 DEFSUBR (Fprocess_sentinel);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3277 DEFSUBR (Fprocess_kill_without_query);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3278 DEFSUBR (Fprocess_kill_without_query_p);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3279 DEFSUBR (Fprocess_list);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3280 DEFSUBR (Fstart_process_internal);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3281 #ifdef HAVE_SOCKETS
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3282 DEFSUBR (Fopen_network_stream_internal);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3283 #endif /* HAVE_SOCKETS */
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3284 DEFSUBR (Fprocess_send_region);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3285 DEFSUBR (Fprocess_send_string);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3286 DEFSUBR (Finterrupt_process);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3287 DEFSUBR (Fkill_process);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3288 DEFSUBR (Fquit_process);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3289 DEFSUBR (Fstop_process);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3290 DEFSUBR (Fcontinue_process);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3291 DEFSUBR (Fprocess_send_eof);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3292 DEFSUBR (Fsignal_process);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
3293 /* DEFSUBR (Fprocess_connection); */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3294 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3295 DEFSUBR (Fprocess_input_coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3296 DEFSUBR (Fprocess_output_coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3297 DEFSUBR (Fset_process_input_coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3298 DEFSUBR (Fset_process_output_coding_system);
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
3299 DEFSUBR (Fprocess_coding_system);
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
3300 DEFSUBR (Fset_process_coding_system);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3301 #endif /* MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3302 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3304 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3305 vars_of_process (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3306 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3307 Fprovide (intern ("subprocesses"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3308 #ifdef HAVE_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3309 Fprovide (intern ("network-streams"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3310 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3311 staticpro (&Vprocess_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3313 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3314 *Non-nil means delete processes immediately when they exit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3315 nil means don't delete them until `list-processes' is run.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3316 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3318 delete_exited_processes = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3320 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3321 Control type of device used to communicate with subprocesses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3322 Values are nil to use a pipe, or t or `pty' to use a pty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3323 The value has no effect if the system has no ptys or if all ptys are busy:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3324 then a pipe is used in any case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3325 The value takes effect when `start-process' is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3326 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3327 Vprocess_connection_type = Qt;
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
3328
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
3329 #ifdef PROCESS_IO_BLOCKING
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
3330 DEFVAR_LISP ("network-stream-blocking-port-list", &network_stream_blocking_port_list /*
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
3331 List of port numbers or port names to set a blocking I/O mode with connection.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
3332 Nil value means to set a default(non-blocking) I/O mode.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
3333 The value takes effect when `open-network-stream-internal' is called.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
3334 */ );
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
3335 network_stream_blocking_port_list = Qnil;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
3336 #endif /* PROCESS_IO_BLOCKING */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3337 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3339 #endif /* not NO_SUBPROCESSES */