annotate src/process.c @ 207:e45d5e7c476e r20-4b2

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