428
|
1 /* Asynchronous subprocess control for XEmacs.
|
|
2 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 1995
|
|
3 Free Software Foundation, Inc.
|
|
4 Copyright (C) 1995 Sun Microsystems, Inc.
|
784
|
5 Copyright (C) 1995, 1996, 2001, 2002 Ben Wing.
|
428
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
814
|
24 /* This file has been Mule-ized. */
|
428
|
25
|
|
26 /* This file has been split into process.c and process-unix.c by
|
|
27 Kirill M. Katsnelson <kkm@kis.ru>, so please bash him and not
|
814
|
28 the original author(s).
|
|
29
|
|
30 Non-synch-subprocess stuff (mostly process environment) moved from
|
853
|
31 callproc.c, 4-3-02, Ben Wing.
|
|
32
|
|
33 callproc.c deleted entirely 5-23-02, Ben Wing. Good riddance!
|
|
34 */
|
428
|
35
|
|
36 #include <config.h>
|
|
37
|
814
|
38 #if defined (NO_SUBPROCESSES)
|
|
39 #error "We don't support this anymore."
|
|
40 #endif
|
428
|
41
|
|
42 #include "lisp.h"
|
|
43
|
|
44 #include "buffer.h"
|
|
45 #include "commands.h"
|
800
|
46 #include "device.h"
|
428
|
47 #include "events.h"
|
800
|
48 #include "file-coding.h"
|
428
|
49 #include "frame.h"
|
|
50 #include "hash.h"
|
|
51 #include "insdel.h"
|
|
52 #include "lstream.h"
|
|
53 #include "opaque.h"
|
|
54 #include "process.h"
|
|
55 #include "procimpl.h"
|
816
|
56 #include "sysdep.h"
|
428
|
57 #include "window.h"
|
|
58
|
|
59 #include "sysfile.h"
|
|
60 #include "sysproc.h"
|
859
|
61 #include "syssignal.h"
|
428
|
62 #include "systime.h"
|
|
63 #include "systty.h"
|
|
64 #include "syswait.h"
|
|
65
|
863
|
66 Lisp_Object Qprocessp, Qprocess_live_p, Qprocess_readable_p;
|
428
|
67
|
|
68 /* Process methods */
|
|
69 struct process_methods the_process_methods;
|
|
70
|
|
71 /* a process object is a network connection when its pid field a cons
|
|
72 (name of name of port we are connected to . foreign host name) */
|
|
73
|
|
74 /* Valid values of process->status_symbol */
|
|
75 Lisp_Object Qrun, Qstop;
|
|
76 /* Qrun => Qopen, Qexit => Qclosed for "network connection" processes */
|
|
77 Lisp_Object Qopen, Qclosed;
|
|
78 /* Protocol families */
|
|
79 Lisp_Object Qtcp, Qudp;
|
|
80
|
|
81 #ifdef HAVE_MULTICAST
|
|
82 Lisp_Object Qmulticast; /* Will be used for occasional warnings */
|
|
83 #endif
|
|
84
|
|
85 /* t means use pty, nil means use a pipe,
|
|
86 maybe other values to come. */
|
|
87 Lisp_Object Vprocess_connection_type;
|
|
88
|
|
89 /* Read comments to DEFVAR of this */
|
|
90 int windowed_process_io;
|
|
91
|
|
92 #ifdef PROCESS_IO_BLOCKING
|
|
93 /* List of port numbers or port names to set a blocking I/O mode.
|
|
94 Nil means set a non-blocking I/O mode [default]. */
|
|
95 Lisp_Object network_stream_blocking_port_list;
|
|
96 #endif /* PROCESS_IO_BLOCKING */
|
|
97
|
|
98 /* Number of events of change of status of a process. */
|
|
99 volatile int process_tick;
|
|
100
|
|
101 /* Number of events for which the user or sentinel has been notified. */
|
|
102 static int update_tick;
|
|
103
|
|
104 /* Nonzero means delete a process right away if it exits. */
|
|
105 int delete_exited_processes;
|
|
106
|
853
|
107 /* Hash table which maps USIDs as returned by create_io_streams_cb to
|
428
|
108 process objects. Processes are not GC-protected through this! */
|
|
109 struct hash_table *usid_to_process;
|
|
110
|
|
111 /* List of process objects. */
|
|
112 Lisp_Object Vprocess_list;
|
|
113
|
442
|
114 Lisp_Object Vnull_device;
|
428
|
115
|
771
|
116 /* Cons of coding systems used to initialize process I/O on a newly-
|
|
117 created process. */
|
|
118 Lisp_Object Vdefault_process_coding_system;
|
853
|
119 /* Same for a network connection. */
|
|
120 Lisp_Object Vdefault_network_coding_system;
|
771
|
121
|
563
|
122 Lisp_Object Qprocess_error;
|
|
123 Lisp_Object Qnetwork_error;
|
|
124
|
771
|
125 Fixnum debug_process_io;
|
|
126
|
814
|
127 Lisp_Object Vshell_file_name;
|
|
128
|
|
129 /* The environment to pass to all subprocesses when they are started.
|
|
130 This is in the semi-bogus format of ("VAR=VAL" "VAR2=VAL2" ... )
|
|
131 */
|
|
132 Lisp_Object Vprocess_environment;
|
|
133
|
|
134 /* Make sure egetenv() not called too soon */
|
|
135 int env_initted;
|
|
136
|
|
137 Lisp_Object Vlisp_EXEC_SUFFIXES;
|
|
138
|
428
|
139
|
|
140
|
1204
|
141 static const struct memory_description process_description [] = {
|
|
142 #define MARKED_SLOT(x) { XD_LISP_OBJECT, offsetof (Lisp_Process, x) },
|
|
143 #include "process-slots.h"
|
934
|
144 { XD_END }
|
|
145 };
|
|
146
|
428
|
147 static Lisp_Object
|
444
|
148 mark_process (Lisp_Object object)
|
428
|
149 {
|
444
|
150 Lisp_Process *process = XPROCESS (object);
|
1204
|
151 #define MARKED_SLOT(x) mark_object (process->x);
|
|
152 #include "process-slots.h"
|
|
153 return Qnil;
|
428
|
154 }
|
|
155
|
|
156 static void
|
444
|
157 print_process (Lisp_Object object, Lisp_Object printcharfun, int escapeflag)
|
428
|
158 {
|
444
|
159 Lisp_Process *process = XPROCESS (object);
|
428
|
160
|
|
161 if (print_readably)
|
563
|
162 printing_unreadable_object ("#<process %s>", XSTRING_DATA (process->name));
|
428
|
163
|
|
164 if (!escapeflag)
|
|
165 {
|
444
|
166 print_internal (process->name, printcharfun, 0);
|
428
|
167 }
|
|
168 else
|
|
169 {
|
444
|
170 int netp = network_connection_p (object);
|
826
|
171 write_c_string (printcharfun,
|
|
172 netp ? GETTEXT ("#<network connection ") :
|
|
173 GETTEXT ("#<process "));
|
444
|
174 print_internal (process->name, printcharfun, 1);
|
826
|
175 write_c_string (printcharfun, (netp ? " " : " pid "));
|
444
|
176 print_internal (process->pid, printcharfun, 1);
|
800
|
177 write_fmt_string_lisp (printcharfun, " state:%S", 1, process->status_symbol);
|
444
|
178 MAYBE_PROCMETH (print_process_data, (process, printcharfun));
|
826
|
179 write_c_string (printcharfun, ">");
|
428
|
180 }
|
|
181 }
|
|
182
|
|
183 #ifdef HAVE_WINDOW_SYSTEM
|
440
|
184 extern void debug_process_finalization (Lisp_Process *p);
|
428
|
185 #endif /* HAVE_WINDOW_SYSTEM */
|
|
186
|
|
187 static void
|
|
188 finalize_process (void *header, int for_disksave)
|
|
189 {
|
|
190 /* #### this probably needs to be tied into the tty event loop */
|
|
191 /* #### when there is one */
|
440
|
192 Lisp_Process *p = (Lisp_Process *) header;
|
428
|
193 #ifdef HAVE_WINDOW_SYSTEM
|
|
194 if (!for_disksave)
|
|
195 {
|
|
196 debug_process_finalization (p);
|
|
197 }
|
|
198 #endif /* HAVE_WINDOW_SYSTEM */
|
|
199
|
|
200 if (p->process_data)
|
|
201 {
|
|
202 MAYBE_PROCMETH (finalize_process_data, (p, for_disksave));
|
|
203 if (!for_disksave)
|
1726
|
204 xfree (p->process_data, void *);
|
428
|
205 }
|
|
206 }
|
|
207
|
934
|
208 DEFINE_LRECORD_IMPLEMENTATION ("process", process,
|
|
209 0, /*dumpable-flag*/
|
|
210 mark_process, print_process, finalize_process,
|
|
211 0, 0, process_description, Lisp_Process);
|
428
|
212
|
|
213 /************************************************************************/
|
|
214 /* basic process accessors */
|
|
215 /************************************************************************/
|
|
216
|
771
|
217 /* This function returns low-level streams, connected directly to the child
|
|
218 process, rather than en/decoding streams */
|
428
|
219 void
|
853
|
220 get_process_streams (Lisp_Process *p, Lisp_Object *instr, Lisp_Object *outstr,
|
|
221 Lisp_Object *errstr)
|
428
|
222 {
|
|
223 assert (p);
|
853
|
224 assert (NILP (p->pipe_instream) || LSTREAMP (p->pipe_instream));
|
|
225 assert (NILP (p->pipe_outstream) || LSTREAMP (p->pipe_outstream));
|
|
226 assert (NILP (p->pipe_errstream) || LSTREAMP (p->pipe_errstream));
|
428
|
227 *instr = p->pipe_instream;
|
|
228 *outstr = p->pipe_outstream;
|
853
|
229 *errstr = p->pipe_errstream;
|
428
|
230 }
|
|
231
|
853
|
232 /* Given a USID referring to either a process's instream or errstream,
|
|
233 return the associated process. */
|
440
|
234 Lisp_Process *
|
428
|
235 get_process_from_usid (USID usid)
|
|
236 {
|
442
|
237 const void *vval;
|
428
|
238
|
|
239 assert (usid != USID_ERROR && usid != USID_DONTHASH);
|
|
240
|
442
|
241 if (gethash ((const void*)usid, usid_to_process, &vval))
|
428
|
242 {
|
444
|
243 Lisp_Object process;
|
826
|
244 process = VOID_TO_LISP (vval);
|
444
|
245 return XPROCESS (process);
|
428
|
246 }
|
|
247 else
|
|
248 return 0;
|
|
249 }
|
|
250
|
|
251 int
|
853
|
252 get_process_selected_p (Lisp_Process *p, int do_err)
|
428
|
253 {
|
853
|
254 return do_err ? p->err_selected : p->in_selected;
|
428
|
255 }
|
|
256
|
|
257 void
|
853
|
258 set_process_selected_p (Lisp_Process *p, int in_selected, int err_selected)
|
428
|
259 {
|
853
|
260 p->in_selected = !!in_selected;
|
|
261 p->err_selected = !!err_selected;
|
428
|
262 }
|
|
263
|
|
264 int
|
440
|
265 connected_via_filedesc_p (Lisp_Process *p)
|
428
|
266 {
|
|
267 return MAYBE_INT_PROCMETH (tooltalk_connection_p, (p));
|
|
268 }
|
|
269
|
|
270 #ifdef HAVE_SOCKETS
|
|
271 int
|
|
272 network_connection_p (Lisp_Object process)
|
|
273 {
|
|
274 return CONSP (XPROCESS (process)->pid);
|
|
275 }
|
|
276 #endif
|
|
277
|
|
278 DEFUN ("processp", Fprocessp, 1, 1, 0, /*
|
|
279 Return t if OBJECT is a process.
|
|
280 */
|
444
|
281 (object))
|
428
|
282 {
|
444
|
283 return PROCESSP (object) ? Qt : Qnil;
|
428
|
284 }
|
|
285
|
440
|
286 DEFUN ("process-live-p", Fprocess_live_p, 1, 1, 0, /*
|
|
287 Return t if OBJECT is a process that is alive.
|
|
288 */
|
444
|
289 (object))
|
440
|
290 {
|
444
|
291 return PROCESSP (object) && PROCESS_LIVE_P (XPROCESS (object))
|
|
292 ? Qt : Qnil;
|
440
|
293 }
|
|
294
|
863
|
295 #if 0
|
|
296 /* This is a reasonable definition for this new primitive. Kyle sez:
|
|
297
|
|
298 "The patch looks OK to me except for the creation and exporting of the
|
|
299 Fprocess_readable_p function. I don't think a new Lisp function
|
|
300 should be created until we know something actually needs it. If
|
|
301 we later want to give process-readable-p different semantics it
|
|
302 may be hard to do it and stay compatible with what we hastily
|
|
303 create today."
|
|
304
|
|
305 He's right, not yet. Let's discuss the semantics on XEmacs Design
|
|
306 before enabling this.
|
|
307 */
|
|
308 DEFUN ("process-readable-p", Fprocess_readable_p, 1, 1, 0, /*
|
|
309 Return t if OBJECT is a process from which input may be available.
|
|
310 */
|
|
311 (object))
|
|
312 {
|
|
313 return PROCESSP (object) && PROCESS_READABLE_P (XPROCESS (object))
|
|
314 ? Qt : Qnil;
|
|
315 }
|
|
316 #endif
|
|
317
|
428
|
318 DEFUN ("process-list", Fprocess_list, 0, 0, 0, /*
|
|
319 Return a list of all processes.
|
|
320 */
|
|
321 ())
|
|
322 {
|
|
323 return Fcopy_sequence (Vprocess_list);
|
|
324 }
|
|
325
|
|
326 DEFUN ("get-process", Fget_process, 1, 1, 0, /*
|
444
|
327 Return the process named PROCESS-NAME (a string), or nil if there is none.
|
|
328 PROCESS-NAME may also be a process; if so, the value is that process.
|
428
|
329 */
|
444
|
330 (process_name))
|
428
|
331 {
|
444
|
332 if (PROCESSP (process_name))
|
|
333 return process_name;
|
428
|
334
|
|
335 if (!gc_in_progress)
|
|
336 /* this only gets called during GC when emacs is going away as a result
|
|
337 of a signal or crash. */
|
444
|
338 CHECK_STRING (process_name);
|
428
|
339
|
444
|
340 {
|
|
341 LIST_LOOP_2 (process, Vprocess_list)
|
|
342 if (internal_equal (process_name, XPROCESS (process)->name, 0))
|
|
343 return process;
|
|
344 }
|
428
|
345 return Qnil;
|
|
346 }
|
|
347
|
|
348 DEFUN ("get-buffer-process", Fget_buffer_process, 1, 1, 0, /*
|
|
349 Return the (or, a) process associated with BUFFER.
|
|
350 BUFFER may be a buffer or the name of one.
|
|
351 */
|
444
|
352 (buffer))
|
428
|
353 {
|
444
|
354 if (NILP (buffer)) return Qnil;
|
|
355 buffer = Fget_buffer (buffer);
|
|
356 if (NILP (buffer)) return Qnil;
|
428
|
357
|
444
|
358 {
|
|
359 LIST_LOOP_2 (process, Vprocess_list)
|
|
360 if (EQ (XPROCESS (process)->buffer, buffer))
|
|
361 return process;
|
|
362 }
|
428
|
363 return Qnil;
|
|
364 }
|
|
365
|
|
366 /* This is how commands for the user decode process arguments. It
|
|
367 accepts a process, a process name, a buffer, a buffer name, or nil.
|
|
368 Buffers denote the first process in the buffer, and nil denotes the
|
|
369 current buffer. */
|
|
370
|
|
371 static Lisp_Object
|
|
372 get_process (Lisp_Object name)
|
|
373 {
|
444
|
374 Lisp_Object buffer;
|
428
|
375
|
|
376 #ifdef I18N3
|
|
377 /* #### Look more closely into translating process names. */
|
|
378 #endif
|
|
379
|
|
380 /* This may be called during a GC from process_send_signal() from
|
|
381 kill_buffer_processes() if emacs decides to abort(). */
|
|
382 if (PROCESSP (name))
|
|
383 return name;
|
444
|
384 else if (STRINGP (name))
|
428
|
385 {
|
444
|
386 Lisp_Object object = Fget_process (name);
|
|
387 if (PROCESSP (object))
|
|
388 return object;
|
|
389
|
|
390 buffer = Fget_buffer (name);
|
|
391 if (BUFFERP (buffer))
|
|
392 goto have_buffer_object;
|
|
393
|
563
|
394 invalid_argument ("Process does not exist", name);
|
428
|
395 }
|
|
396 else if (NILP (name))
|
444
|
397 {
|
|
398 buffer = Fcurrent_buffer ();
|
|
399 goto have_buffer_object;
|
|
400 }
|
|
401 else if (BUFFERP (name))
|
|
402 {
|
|
403 Lisp_Object process;
|
|
404 buffer = name;
|
428
|
405
|
444
|
406 have_buffer_object:
|
|
407 process = Fget_buffer_process (buffer);
|
|
408 if (PROCESSP (process))
|
|
409 return process;
|
|
410
|
563
|
411 invalid_argument ("Buffer has no process", buffer);
|
428
|
412 }
|
|
413 else
|
444
|
414 return get_process (Fsignal (Qwrong_type_argument,
|
771
|
415 (list2 (build_msg_string ("process or buffer or nil"),
|
444
|
416 name))));
|
428
|
417 }
|
|
418
|
|
419 DEFUN ("process-id", Fprocess_id, 1, 1, 0, /*
|
|
420 Return the process id of PROCESS.
|
|
421 This is the pid of the Unix process which PROCESS uses or talks to.
|
|
422 For a network connection, this value is a cons of
|
|
423 (foreign-network-port . foreign-host-name).
|
|
424 */
|
444
|
425 (process))
|
428
|
426 {
|
|
427 Lisp_Object pid;
|
444
|
428 CHECK_PROCESS (process);
|
428
|
429
|
444
|
430 pid = XPROCESS (process)->pid;
|
|
431 if (network_connection_p (process))
|
428
|
432 /* return Qnil; */
|
|
433 return Fcons (Fcar (pid), Fcdr (pid));
|
|
434 else
|
|
435 return pid;
|
|
436 }
|
|
437
|
|
438 DEFUN ("process-name", Fprocess_name, 1, 1, 0, /*
|
|
439 Return the name of PROCESS, as a string.
|
|
440 This is the name of the program invoked in PROCESS,
|
|
441 possibly modified to make it unique among process names.
|
|
442 */
|
444
|
443 (process))
|
428
|
444 {
|
444
|
445 CHECK_PROCESS (process);
|
|
446 return XPROCESS (process)->name;
|
428
|
447 }
|
|
448
|
|
449 DEFUN ("process-command", Fprocess_command, 1, 1, 0, /*
|
|
450 Return the command that was executed to start PROCESS.
|
|
451 This is a list of strings, the first string being the program executed
|
|
452 and the rest of the strings being the arguments given to it.
|
|
453 */
|
444
|
454 (process))
|
428
|
455 {
|
444
|
456 CHECK_PROCESS (process);
|
|
457 return XPROCESS (process)->command;
|
428
|
458 }
|
|
459
|
|
460
|
|
461 /************************************************************************/
|
|
462 /* creating a process */
|
|
463 /************************************************************************/
|
|
464
|
563
|
465 DOESNT_RETURN
|
|
466 report_process_error (const char *string, Lisp_Object data)
|
|
467 {
|
|
468 report_error_with_errno (Qprocess_error, string, data);
|
|
469 }
|
|
470
|
|
471 DOESNT_RETURN
|
|
472 report_network_error (const char *string, Lisp_Object data)
|
|
473 {
|
|
474 report_error_with_errno (Qnetwork_error, string, data);
|
|
475 }
|
|
476
|
428
|
477 Lisp_Object
|
|
478 make_process_internal (Lisp_Object name)
|
|
479 {
|
|
480 Lisp_Object val, name1;
|
|
481 int i;
|
440
|
482 Lisp_Process *p = alloc_lcrecord_type (Lisp_Process, &lrecord_process);
|
428
|
483
|
1204
|
484 #define MARKED_SLOT(x) p->x = Qnil;
|
|
485 #include "process-slots.h"
|
|
486
|
428
|
487 /* If name is already in use, modify it until it is unused. */
|
|
488 name1 = name;
|
|
489 for (i = 1; ; i++)
|
|
490 {
|
|
491 char suffix[10];
|
|
492 Lisp_Object tem = Fget_process (name1);
|
|
493 if (NILP (tem))
|
|
494 break;
|
|
495 sprintf (suffix, "<%d>", i);
|
|
496 name1 = concat2 (name, build_string (suffix));
|
|
497 }
|
|
498 name = name1;
|
|
499 p->name = name;
|
|
500
|
|
501 p->mark = Fmake_marker ();
|
853
|
502 p->stderr_mark = Fmake_marker ();
|
428
|
503 p->status_symbol = Qrun;
|
|
504
|
|
505 MAYBE_PROCMETH (alloc_process_data, (p));
|
|
506
|
793
|
507 val = wrap_process (p);
|
428
|
508
|
|
509 Vprocess_list = Fcons (val, Vprocess_list);
|
|
510 return val;
|
|
511 }
|
|
512
|
|
513 void
|
853
|
514 init_process_io_handles (Lisp_Process *p, void* in, void* out, void* err,
|
|
515 int flags)
|
428
|
516 {
|
853
|
517 USID in_usid, err_usid;
|
771
|
518 Lisp_Object incode, outcode;
|
|
519
|
853
|
520 if (flags & STREAM_NETWORK_CONNECTION)
|
|
521 {
|
|
522 if (!CONSP (Vdefault_network_coding_system) ||
|
|
523 NILP (incode = (find_coding_system_for_text_file
|
|
524 (Fcar (Vdefault_network_coding_system), 1))) ||
|
|
525 NILP (outcode = (find_coding_system_for_text_file
|
|
526 (Fcdr (Vdefault_network_coding_system), 0))))
|
|
527 signal_error (Qinvalid_state,
|
|
528 "Bogus value for `default-network-coding-system'",
|
|
529 Vdefault_network_coding_system);
|
|
530 }
|
|
531 else
|
|
532 {
|
|
533 if (!CONSP (Vdefault_process_coding_system) ||
|
|
534 NILP (incode = (find_coding_system_for_text_file
|
|
535 (Fcar (Vdefault_process_coding_system), 1))) ||
|
|
536 NILP (outcode = (find_coding_system_for_text_file
|
|
537 (Fcdr (Vdefault_process_coding_system), 0))))
|
|
538 signal_error (Qinvalid_state,
|
|
539 "Bogus value for `default-process-coding-system'",
|
|
540 Vdefault_process_coding_system);
|
|
541 }
|
771
|
542
|
784
|
543 if (!NILP (Vcoding_system_for_read) &&
|
|
544 NILP (incode = (find_coding_system_for_text_file
|
|
545 (Vcoding_system_for_read, 1))))
|
|
546 signal_error (Qinvalid_state,
|
|
547 "Bogus value for `coding-system-for-read'",
|
|
548 Vcoding_system_for_read);
|
|
549
|
|
550 if (!NILP (Vcoding_system_for_write) &&
|
|
551 NILP (outcode = (find_coding_system_for_text_file
|
|
552 (Vcoding_system_for_write, 0))))
|
|
553 signal_error (Qinvalid_state,
|
|
554 "Bogus value for `coding-system-for-write'",
|
|
555 Vcoding_system_for_write);
|
|
556
|
853
|
557 event_stream_create_io_streams (in, out, err,
|
|
558 &p->pipe_instream,
|
|
559 &p->pipe_outstream,
|
|
560 &p->pipe_errstream,
|
|
561 &in_usid, &err_usid,
|
|
562 flags);
|
428
|
563
|
853
|
564 if (in_usid == USID_ERROR || err_usid == USID_ERROR)
|
563
|
565 signal_error (Qprocess_error, "Setting up communication with subprocess",
|
853
|
566 wrap_process (p));
|
428
|
567
|
853
|
568 if (in_usid != USID_DONTHASH)
|
428
|
569 {
|
444
|
570 Lisp_Object process = Qnil;
|
793
|
571 process = wrap_process (p);
|
853
|
572 puthash ((const void*) in_usid, LISP_TO_VOID (process), usid_to_process);
|
428
|
573 }
|
|
574
|
853
|
575 if (err_usid != USID_DONTHASH)
|
|
576 {
|
|
577 Lisp_Object process = Qnil;
|
|
578 process = wrap_process (p);
|
|
579 puthash ((const void*) err_usid, LISP_TO_VOID (process),
|
|
580 usid_to_process);
|
|
581 }
|
|
582
|
|
583 MAYBE_PROCMETH (init_process_io_handles, (p, in, out, err, flags));
|
428
|
584
|
771
|
585 p->coding_instream =
|
800
|
586 make_coding_input_stream (XLSTREAM (p->pipe_instream), incode,
|
|
587 CODING_DECODE, 0);
|
853
|
588 if (!NILP (p->pipe_errstream))
|
|
589 p->coding_errstream =
|
|
590 make_coding_input_stream
|
|
591 (XLSTREAM (p->pipe_errstream), incode, CODING_DECODE, 0);
|
771
|
592 p->coding_outstream =
|
800
|
593 make_coding_output_stream (XLSTREAM (p->pipe_outstream), outcode,
|
|
594 CODING_ENCODE, 0);
|
428
|
595 }
|
|
596
|
|
597 static void
|
|
598 create_process (Lisp_Object process, Lisp_Object *argv, int nargv,
|
853
|
599 Lisp_Object program, Lisp_Object cur_dir,
|
|
600 int separate_err)
|
428
|
601 {
|
440
|
602 Lisp_Process *p = XPROCESS (process);
|
428
|
603 int pid;
|
|
604
|
|
605 /* *_create_process may change status_symbol, if the process
|
|
606 is a kind of "fire-and-forget" (no I/O, unwaitable) */
|
|
607 p->status_symbol = Qrun;
|
|
608 p->exit_code = 0;
|
|
609
|
853
|
610 pid = PROCMETH (create_process, (p, argv, nargv, program, cur_dir,
|
|
611 separate_err));
|
428
|
612
|
|
613 p->pid = make_int (pid);
|
863
|
614 if (PROCESS_READABLE_P (p))
|
853
|
615 event_stream_select_process (p, 1, 1);
|
428
|
616 }
|
|
617
|
|
618 /* This function is the unwind_protect form for Fstart_process_internal. If
|
444
|
619 PROCESS doesn't have its pid set, then we know someone has signalled
|
428
|
620 an error and the process wasn't started successfully, so we should
|
|
621 remove it from the process list. */
|
444
|
622 static void remove_process (Lisp_Object process);
|
428
|
623 static Lisp_Object
|
444
|
624 start_process_unwind (Lisp_Object process)
|
428
|
625 {
|
444
|
626 /* Was PROCESS started successfully? */
|
|
627 if (EQ (XPROCESS (process)->pid, Qnil))
|
|
628 remove_process (process);
|
428
|
629 return Qnil;
|
|
630 }
|
|
631
|
|
632 DEFUN ("start-process-internal", Fstart_process_internal, 3, MANY, 0, /*
|
853
|
633 Internal function to start a program in a subprocess.
|
|
634 Lisp callers should use `start-process' instead.
|
|
635
|
|
636 Returns the process object for it.
|
428
|
637 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS
|
|
638 NAME is name for process. It is modified if necessary to make it unique.
|
|
639 BUFFER is the buffer or (buffer-name) to associate with the process.
|
|
640 Process output goes at end of that buffer, unless you specify
|
|
641 an output stream or filter function to handle the output.
|
|
642 BUFFER may be also nil, meaning that this process is not associated
|
853
|
643 with any buffer.
|
|
644 BUFFER can also have the form (REAL-BUFFER STDERR-BUFFER); in that case,
|
|
645 REAL-BUFFER says what to do with standard output, as above,
|
|
646 while STDERR-BUFFER says what to do with standard error in the child.
|
|
647 STDERR-BUFFER may be nil (discard standard error output, unless a stderr
|
|
648 filter is set). Note that if you do not use this form at process creation,
|
|
649 stdout and stderr will be mixed in the output buffer, and this cannot be
|
|
650 changed, even by setting a stderr filter.
|
428
|
651 Third arg is program file name. It is searched for as in the shell.
|
|
652 Remaining arguments are strings to give program as arguments.
|
853
|
653
|
|
654 Read and write coding systems for the process are determined from
|
|
655 `coding-system-for-read' and `coding-system-for-write' (intended as
|
|
656 overriding coding systems to be *bound* by Lisp code, not set), or
|
|
657 from `default-process-coding-system' if either or both are nil. You can
|
|
658 change the coding systems later on using `set-process-coding-system',
|
|
659 `set-process-input-coding-system', or `set-process-output-coding-system'.
|
|
660
|
|
661 See also `set-process-filter' and `set-process-stderr-filter'.
|
428
|
662 */
|
|
663 (int nargs, Lisp_Object *args))
|
|
664 {
|
|
665 /* This function can call lisp */
|
853
|
666 Lisp_Object buffer, stderr_buffer, name, program, process, current_dir;
|
|
667 int separate_stderr;
|
428
|
668 Lisp_Object tem;
|
910
|
669 int i;
|
428
|
670 int speccount = specpdl_depth ();
|
|
671 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
672
|
|
673 name = args[0];
|
|
674 buffer = args[1];
|
|
675 program = args[2];
|
|
676 current_dir = Qnil;
|
|
677
|
|
678 /* Protect against various file handlers doing GCs below. */
|
|
679 GCPRO3 (buffer, program, current_dir);
|
|
680
|
853
|
681 if (CONSP (buffer))
|
|
682 {
|
|
683 if (!CONSP (XCDR (buffer)))
|
|
684 invalid_argument ("Invalid BUFFER argument to `start-process'",
|
|
685 buffer);
|
|
686 if (!NILP (XCDR (XCDR (buffer))))
|
|
687 invalid_argument ("Invalid BUFFER argument to `start-process'",
|
|
688 buffer);
|
|
689 stderr_buffer = XCAR (XCDR (buffer));
|
|
690 buffer = XCAR (buffer);
|
|
691 separate_stderr = 1;
|
|
692 }
|
|
693 else
|
|
694 {
|
|
695 stderr_buffer = Qnil;
|
|
696 separate_stderr = 0;
|
|
697 }
|
|
698
|
428
|
699 if (!NILP (buffer))
|
|
700 buffer = Fget_buffer_create (buffer);
|
853
|
701 if (!NILP (stderr_buffer))
|
|
702 stderr_buffer = Fget_buffer_create (stderr_buffer);
|
428
|
703
|
|
704 CHECK_STRING (name);
|
|
705 CHECK_STRING (program);
|
910
|
706 for (i = 3; i < nargs; ++i)
|
|
707 CHECK_STRING (args[i]);
|
428
|
708
|
|
709 /* Make sure that the child will be able to chdir to the current
|
502
|
710 buffer's current directory, or its unhandled equivalent. [[ We
|
428
|
711 can't just have the child check for an error when it does the
|
502
|
712 chdir, since it's in a vfork. ]] -- not any more, we don't use
|
|
713 vfork. -ben
|
428
|
714
|
502
|
715 Note: These calls are spread out to insure that the return values
|
|
716 of the calls (which may be newly-created strings) are properly
|
|
717 GC-protected. */
|
428
|
718 current_dir = current_buffer->directory;
|
502
|
719 /* If the current dir has no terminating slash, we'll get undesirable
|
|
720 results, so put the slash back. */
|
|
721 current_dir = Ffile_name_as_directory (current_dir);
|
428
|
722 current_dir = Funhandled_file_name_directory (current_dir);
|
|
723 current_dir = expand_and_dir_to_file (current_dir, Qnil);
|
|
724
|
|
725 #if 0 /* This loser breaks ange-ftp */
|
|
726 /* dmoore - if you re-enable this code, you have to gcprotect
|
|
727 current_buffer through the above calls. */
|
|
728 if (NILP (Ffile_accessible_directory_p (current_dir)))
|
563
|
729 signal_error (Qprocess_error, "Setting current directory",
|
|
730 current_buffer->directory);
|
428
|
731 #endif /* 0 */
|
|
732
|
|
733 /* If program file name is not absolute, search our path for it */
|
826
|
734 if (!IS_DIRECTORY_SEP (string_byte (program, 0))
|
428
|
735 && !(XSTRING_LENGTH (program) > 1
|
826
|
736 && IS_DEVICE_SEP (string_byte (program, 1))))
|
428
|
737 {
|
|
738 struct gcpro ngcpro1;
|
|
739
|
|
740 tem = Qnil;
|
|
741 NGCPRO1 (tem);
|
|
742 locate_file (Vexec_path, program, Vlisp_EXEC_SUFFIXES, &tem, X_OK);
|
|
743 if (NILP (tem))
|
563
|
744 signal_error (Qprocess_error, "Searching for program", program);
|
428
|
745 program = Fexpand_file_name (tem, Qnil);
|
|
746 NUNGCPRO;
|
|
747 }
|
|
748 else
|
|
749 {
|
442
|
750 /* we still need to canonicalize it and ensure it has the proper
|
|
751 ending, e.g. .exe */
|
|
752 struct gcpro ngcpro1;
|
|
753
|
|
754 tem = Qnil;
|
|
755 NGCPRO1 (tem);
|
|
756 locate_file (list1 (build_string ("")), program, Vlisp_EXEC_SUFFIXES,
|
|
757 &tem, X_OK);
|
|
758 if (NILP (tem))
|
563
|
759 signal_error (Qprocess_error, "Searching for program", program);
|
442
|
760 program = tem;
|
|
761 NUNGCPRO;
|
428
|
762 }
|
|
763
|
442
|
764 if (!NILP (Ffile_directory_p (program)))
|
|
765 invalid_operation ("Specified program for new process is a directory",
|
|
766 program);
|
|
767
|
444
|
768 process = make_process_internal (name);
|
428
|
769
|
444
|
770 XPROCESS (process)->buffer = buffer;
|
853
|
771 XPROCESS (process)->stderr_buffer = stderr_buffer;
|
|
772 XPROCESS (process)->separate_stderr = separate_stderr;
|
814
|
773 XPROCESS (process)->command = Flist (nargs - 2, args + 2);
|
428
|
774
|
|
775 /* Make the process marker point into the process buffer (if any). */
|
|
776 if (!NILP (buffer))
|
444
|
777 Fset_marker (XPROCESS (process)->mark,
|
428
|
778 make_int (BUF_ZV (XBUFFER (buffer))), buffer);
|
853
|
779 if (!NILP (stderr_buffer))
|
|
780 Fset_marker (XPROCESS (process)->stderr_mark,
|
|
781 make_int (BUF_ZV (XBUFFER (stderr_buffer))), stderr_buffer);
|
428
|
782
|
|
783 /* If an error occurs and we can't start the process, we want to
|
|
784 remove it from the process list. This means that each error
|
|
785 check in create_process doesn't need to call remove_process
|
|
786 itself; it's all taken care of here. */
|
444
|
787 record_unwind_protect (start_process_unwind, process);
|
428
|
788
|
853
|
789 create_process (process, args + 3, nargs - 3, program, current_dir,
|
|
790 separate_stderr);
|
428
|
791
|
|
792 UNGCPRO;
|
771
|
793 return unbind_to_1 (speccount, process);
|
428
|
794 }
|
|
795
|
|
796
|
|
797 #ifdef HAVE_SOCKETS
|
|
798
|
|
799
|
|
800 /* #### The network support is fairly synthetical. What we actually
|
|
801 need is a single function, which supports all datagram, stream and
|
|
802 packet stream connections, arbitrary protocol families should they
|
|
803 be supported by the target system, multicast groups, in both data
|
|
804 and control rooted/nonrooted flavors, service quality etc whatever
|
|
805 is supported by the underlying network.
|
|
806
|
|
807 It must accept a property list describing the connection. The current
|
|
808 functions must then go to lisp and provide a suitable list for the
|
|
809 generalized connection function.
|
|
810
|
|
811 Both UNIX and Win32 support BSD sockets, and there are many extensions
|
|
812 available (Sockets 2 spec).
|
|
813
|
|
814 A todo is define a consistent set of properties abstracting a
|
|
815 network connection. -kkm
|
|
816 */
|
|
817
|
|
818
|
|
819 /* open a TCP network connection to a given HOST/SERVICE. Treated
|
|
820 exactly like a normal process when reading and writing. Only
|
|
821 differences are in status display and process deletion. A network
|
|
822 connection has no PID; you cannot signal it. All you can do is
|
|
823 deactivate and close it via delete-process */
|
|
824
|
442
|
825 DEFUN ("open-network-stream-internal", Fopen_network_stream_internal, 4, 5,
|
|
826 0, /*
|
428
|
827 Open a TCP connection for a service to a host.
|
444
|
828 Return a process object to represent the connection.
|
428
|
829 Input and output work as for subprocesses; `delete-process' closes it.
|
|
830
|
|
831 NAME is name for process. It is modified if necessary to make it unique.
|
|
832 BUFFER is the buffer (or buffer-name) to associate with the process.
|
|
833 Process output goes at end of that buffer, unless you specify
|
|
834 an output stream or filter function to handle the output.
|
|
835 BUFFER may also be nil, meaning that this process is not associated
|
|
836 with any buffer.
|
444
|
837 Third arg HOST (a string) is the name of the host to connect to,
|
|
838 or its IP address.
|
|
839 Fourth arg SERVICE is the name of the service desired (a string),
|
|
840 or an integer specifying a port number to connect to.
|
|
841 Optional fifth arg PROTOCOL is a network protocol. Currently only 'tcp
|
428
|
842 (Transmission Control Protocol) and 'udp (User Datagram Protocol) are
|
|
843 supported. When omitted, 'tcp is assumed.
|
|
844
|
442
|
845 Output via `process-send-string' and input via buffer or filter (see
|
428
|
846 `set-process-filter') are stream-oriented. That means UDP datagrams are
|
|
847 not guaranteed to be sent and received in discrete packets. (But small
|
|
848 datagrams around 500 bytes that are not truncated by `process-send-string'
|
444
|
849 are usually fine.) Note further that the UDP protocol does not guard
|
|
850 against lost packets.
|
428
|
851 */
|
|
852 (name, buffer, host, service, protocol))
|
|
853 {
|
|
854 /* This function can GC */
|
444
|
855 Lisp_Object process = Qnil;
|
428
|
856 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, ngcpro1;
|
|
857 void *inch, *outch;
|
|
858
|
|
859 GCPRO5 (name, buffer, host, service, protocol);
|
|
860 CHECK_STRING (name);
|
|
861
|
771
|
862 if (NILP (protocol))
|
428
|
863 protocol = Qtcp;
|
|
864 else
|
|
865 CHECK_SYMBOL (protocol);
|
|
866
|
|
867 /* Since this code is inside HAVE_SOCKETS, existence of
|
|
868 open_network_stream is mandatory */
|
|
869 PROCMETH (open_network_stream, (name, host, service, protocol,
|
|
870 &inch, &outch));
|
|
871
|
|
872 if (!NILP (buffer))
|
|
873 buffer = Fget_buffer_create (buffer);
|
444
|
874 process = make_process_internal (name);
|
|
875 NGCPRO1 (process);
|
428
|
876
|
444
|
877 XPROCESS (process)->pid = Fcons (service, host);
|
|
878 XPROCESS (process)->buffer = buffer;
|
771
|
879 init_process_io_handles (XPROCESS (process), (void *) inch, (void *) outch,
|
853
|
880 (void *) -1,
|
428
|
881 STREAM_NETWORK_CONNECTION);
|
|
882
|
853
|
883 event_stream_select_process (XPROCESS (process), 1, 1);
|
428
|
884
|
1204
|
885 NUNGCPRO;
|
428
|
886 UNGCPRO;
|
444
|
887 return process;
|
428
|
888 }
|
|
889
|
|
890 #ifdef HAVE_MULTICAST
|
|
891
|
|
892 DEFUN ("open-multicast-group-internal", Fopen_multicast_group_internal, 5, 5, 0, /*
|
|
893 Open a multicast connection on the specified dest/port/ttl.
|
444
|
894 Return a process object to represent the connection.
|
428
|
895 Input and output work as for subprocesses; `delete-process' closes it.
|
|
896
|
|
897 NAME is name for process. It is modified if necessary to make it unique.
|
|
898 BUFFER is the buffer (or buffer-name) to associate with the process.
|
|
899 Process output goes at end of that buffer, unless you specify
|
|
900 an output stream or filter function to handle the output.
|
|
901 BUFFER may also be nil, meaning that this process is not associated
|
|
902 with any buffer.
|
|
903 Third, fourth and fifth args are the multicast destination group, port and ttl.
|
|
904 dest must be an internet address between 224.0.0.0 and 239.255.255.255
|
|
905 port is a communication port like in traditional unicast
|
|
906 ttl is the time-to-live (15 for site, 63 for region and 127 for world)
|
|
907 */
|
|
908 (name, buffer, dest, port, ttl))
|
|
909 {
|
|
910 /* This function can GC */
|
444
|
911 Lisp_Object process = Qnil;
|
428
|
912 struct gcpro gcpro1;
|
|
913 void *inch, *outch;
|
|
914
|
|
915 CHECK_STRING (name);
|
|
916
|
|
917 /* Since this code is inside HAVE_MULTICAST, existence of
|
771
|
918 open_multicast_group is mandatory */
|
428
|
919 PROCMETH (open_multicast_group, (name, dest, port, ttl,
|
|
920 &inch, &outch));
|
|
921
|
|
922 if (!NILP (buffer))
|
|
923 buffer = Fget_buffer_create (buffer);
|
|
924
|
444
|
925 process = make_process_internal (name);
|
|
926 GCPRO1 (process);
|
428
|
927
|
444
|
928 XPROCESS (process)->pid = Fcons (port, dest);
|
|
929 XPROCESS (process)->buffer = buffer;
|
853
|
930 init_process_io_handles (XPROCESS (process), (void *) inch, (void *) outch,
|
|
931 (void *) -1,
|
428
|
932 STREAM_NETWORK_CONNECTION);
|
|
933
|
853
|
934 event_stream_select_process (XPROCESS (process), 1, 1);
|
428
|
935
|
|
936 UNGCPRO;
|
444
|
937 return process;
|
428
|
938 }
|
|
939 #endif /* HAVE_MULTICAST */
|
|
940
|
|
941 #endif /* HAVE_SOCKETS */
|
|
942
|
|
943 Lisp_Object
|
|
944 canonicalize_host_name (Lisp_Object host)
|
|
945 {
|
|
946 return PROCMETH_OR_GIVEN (canonicalize_host_name, (host), host);
|
|
947 }
|
|
948
|
|
949
|
|
950 DEFUN ("set-process-window-size", Fset_process_window_size, 3, 3, 0, /*
|
|
951 Tell PROCESS that it has logical window size HEIGHT and WIDTH.
|
|
952 */
|
444
|
953 (process, height, width))
|
428
|
954 {
|
444
|
955 CHECK_PROCESS (process);
|
428
|
956 CHECK_NATNUM (height);
|
|
957 CHECK_NATNUM (width);
|
|
958 return
|
444
|
959 MAYBE_INT_PROCMETH (set_window_size,
|
|
960 (XPROCESS (process), XINT (height), XINT (width))) <= 0
|
428
|
961 ? Qnil : Qt;
|
|
962 }
|
|
963
|
|
964
|
|
965 /************************************************************************/
|
|
966 /* Process I/O */
|
|
967 /************************************************************************/
|
|
968
|
844
|
969 /* Set up PROCESS's buffer for insertion of process data at PROCESS's
|
|
970 mark.
|
|
971
|
|
972 Sets the current buffer to PROCESS's buffer, inhibits read only,
|
|
973 remembers current point, sets point to PROCESS'S mark, widens if
|
|
974 necessary.
|
|
975 */
|
|
976 static int
|
853
|
977 process_setup_for_insertion (Lisp_Object process, int read_stderr)
|
844
|
978 {
|
|
979 Lisp_Process *p = XPROCESS (process);
|
|
980 int spec = specpdl_depth ();
|
853
|
981 Lisp_Object buffer = read_stderr ? p->stderr_buffer : p->buffer;
|
|
982 Lisp_Object mark = read_stderr ? p->stderr_mark : p->mark;
|
|
983 struct buffer *buf = XBUFFER (buffer);
|
844
|
984 Charbpos output_pt;
|
|
985
|
|
986 if (buf != current_buffer)
|
|
987 {
|
|
988 record_unwind_protect (save_current_buffer_restore,
|
|
989 Fcurrent_buffer ());
|
|
990 set_buffer_internal (buf);
|
|
991 }
|
|
992
|
|
993 record_unwind_protect (save_excursion_restore, save_excursion_save ());
|
|
994 specbind (Qinhibit_read_only, Qt);
|
854
|
995
|
844
|
996 /* Insert new output into buffer
|
|
997 at the current end-of-output marker,
|
|
998 thus preserving logical ordering of input and output. */
|
853
|
999 if (XMARKER (mark)->buffer)
|
|
1000 output_pt = marker_position (mark);
|
844
|
1001 else
|
|
1002 output_pt = BUF_ZV (buf);
|
|
1003
|
|
1004 /* If the output marker is outside of the visible region, save
|
|
1005 the restriction and widen. */
|
|
1006 if (! (BUF_BEGV (buf) <= output_pt && output_pt <= BUF_ZV (buf)))
|
|
1007 {
|
|
1008 record_unwind_protect (save_restriction_restore,
|
|
1009 save_restriction_save (buf));
|
|
1010 Fwiden (wrap_buffer (buf));
|
|
1011 }
|
|
1012
|
|
1013 BUF_SET_PT (buf, output_pt);
|
|
1014 return spec;
|
|
1015 }
|
|
1016
|
428
|
1017 /* Read pending output from the process channel,
|
|
1018 starting with our buffered-ahead character if we have one.
|
|
1019 Yield number of characters read.
|
|
1020
|
|
1021 This function reads at most 1024 bytes.
|
|
1022 If you want to read all available subprocess output,
|
|
1023 you must call it repeatedly until it returns zero. */
|
|
1024
|
|
1025 Charcount
|
853
|
1026 read_process_output (Lisp_Object process, int read_stderr)
|
428
|
1027 {
|
|
1028 /* This function can GC */
|
|
1029 Bytecount nbytes, nchars;
|
867
|
1030 Ibyte chars[1025];
|
428
|
1031 Lisp_Object outstream;
|
444
|
1032 Lisp_Process *p = XPROCESS (process);
|
853
|
1033 Lisp_Object filter = read_stderr ? p->stderr_filter : p->filter;
|
|
1034 Lisp_Object buffer = read_stderr ? p->stderr_buffer : p->buffer;
|
|
1035 Lisp_Object mark = read_stderr ? p->stderr_mark : p->mark;
|
428
|
1036
|
|
1037 /* If there is a lot of output from the subprocess, the loop in
|
|
1038 execute_internal_event() might call read_process_output() more
|
|
1039 than once. If the filter that was executed from one of these
|
|
1040 calls set the filter to t, we have to stop now. Return -1 rather
|
|
1041 than 0 so execute_internal_event() doesn't close the process.
|
|
1042 Really, the loop in execute_internal_event() should check itself
|
|
1043 for a process-filter change, like in status_notify(); but the
|
|
1044 struct Lisp_Process is not exported outside of this file. */
|
863
|
1045 if (!PROCESS_READABLE_P (p))
|
853
|
1046 {
|
|
1047 errno = 0;
|
|
1048 return -1; /* already closed */
|
|
1049 }
|
428
|
1050
|
853
|
1051 if (!NILP (filter) && (p->filter_does_read))
|
428
|
1052 {
|
|
1053 Lisp_Object filter_result;
|
|
1054
|
|
1055 /* Some weird FSFmacs crap here with
|
853
|
1056 Vdeactivate_mark and current_buffer->keymap.
|
|
1057 Some FSF junk with running_asynch_code, to preserve the match
|
|
1058 data. Not necessary because we don't call process filters
|
|
1059 asynchronously (i.e. from within QUIT). */
|
|
1060 /* Don't catch errors here; we're not in any critical code. */
|
|
1061 filter_result = call2 (filter, process, Qnil);
|
428
|
1062 CHECK_INT (filter_result);
|
|
1063 return XINT (filter_result);
|
|
1064 }
|
|
1065
|
853
|
1066 nbytes = Lstream_read (read_stderr ? XLSTREAM (DATA_ERRSTREAM (p)) :
|
|
1067 XLSTREAM (DATA_INSTREAM (p)), chars,
|
771
|
1068 sizeof (chars) - 1);
|
428
|
1069 if (nbytes <= 0) return nbytes;
|
|
1070
|
771
|
1071 if (debug_process_io)
|
|
1072 {
|
|
1073 chars[nbytes] = '\0';
|
|
1074 stderr_out ("Read: %s\n", chars);
|
|
1075 }
|
|
1076
|
|
1077 /* !!#### if the coding system changed as a result of reading, we
|
|
1078 need to change the output coding system accordingly. */
|
428
|
1079 nchars = bytecount_to_charcount (chars, nbytes);
|
853
|
1080 outstream = filter;
|
428
|
1081 if (!NILP (outstream))
|
|
1082 {
|
853
|
1083 /* Some FSF junk with running_asynch_code, to preserve the match
|
|
1084 data. Not necessary because we don't call process filters
|
|
1085 asynchronously (i.e. from within QUIT). */
|
|
1086 /* Don't catch errors here; we're not in any critical code. */
|
|
1087 call2 (outstream, process, make_string (chars, nbytes));
|
428
|
1088 return nchars;
|
|
1089 }
|
|
1090
|
|
1091 /* If no filter, write into buffer if it isn't dead. */
|
853
|
1092 if (!NILP (buffer) && BUFFER_LIVE_P (XBUFFER (buffer)))
|
428
|
1093 {
|
844
|
1094 struct gcpro gcpro1;
|
853
|
1095 struct buffer *buf = XBUFFER (buffer);
|
|
1096 int spec = process_setup_for_insertion (process, read_stderr);
|
428
|
1097
|
844
|
1098 GCPRO1 (process);
|
428
|
1099
|
|
1100 #if 0
|
|
1101 /* This screws up initial display of the window. jla */
|
|
1102
|
|
1103 /* Insert before markers in case we are inserting where
|
|
1104 the buffer's mark is, and the user's next command is Meta-y. */
|
|
1105 buffer_insert_raw_string_1 (buf, -1, chars,
|
|
1106 nbytes, INSDEL_BEFORE_MARKERS);
|
|
1107 #else
|
|
1108 buffer_insert_raw_string (buf, chars, nbytes);
|
|
1109 #endif
|
|
1110
|
853
|
1111 Fset_marker (mark, make_int (BUF_PT (buf)), buffer);
|
|
1112
|
428
|
1113 MARK_MODELINE_CHANGED;
|
844
|
1114 unbind_to (spec);
|
428
|
1115 UNGCPRO;
|
|
1116 }
|
|
1117 return nchars;
|
|
1118 }
|
853
|
1119
|
|
1120 int
|
|
1121 process_has_separate_stderr (Lisp_Object process)
|
|
1122 {
|
|
1123 return XPROCESS (process)->separate_stderr;
|
|
1124 }
|
|
1125
|
859
|
1126 DEFUN ("process-has-separate-stderr-p", Fprocess_has_separate_stderr_p, 1, 1,
|
|
1127 0, /*
|
|
1128 Return non-nil if process has stderr separate from stdout.
|
|
1129 */
|
|
1130 (process))
|
|
1131 {
|
|
1132 CHECK_PROCESS (process);
|
|
1133 return process_has_separate_stderr (process) ? Qt : Qnil;
|
|
1134 }
|
|
1135
|
428
|
1136
|
|
1137 /* Sending data to subprocess */
|
|
1138
|
444
|
1139 /* send some data to process PROCESS. If NONRELOCATABLE is non-NULL, it
|
428
|
1140 specifies the address of the data. Otherwise, the data comes from the
|
|
1141 object RELOCATABLE (either a string or a buffer). START and LEN
|
|
1142 specify the offset and length of the data to send.
|
|
1143
|
665
|
1144 Note that START and LEN are in Charbpos's if RELOCATABLE is a buffer,
|
428
|
1145 and in Bytecounts otherwise. */
|
|
1146
|
|
1147 void
|
444
|
1148 send_process (Lisp_Object process,
|
867
|
1149 Lisp_Object relocatable, const Ibyte *nonrelocatable,
|
428
|
1150 int start, int len)
|
|
1151 {
|
|
1152 /* This function can GC */
|
|
1153 struct gcpro gcpro1, gcpro2;
|
|
1154 Lisp_Object lstream = Qnil;
|
|
1155
|
444
|
1156 GCPRO2 (process, lstream);
|
428
|
1157
|
444
|
1158 if (NILP (DATA_OUTSTREAM (XPROCESS (process))))
|
563
|
1159 invalid_operation ("Process not open for writing", process);
|
428
|
1160
|
|
1161 if (nonrelocatable)
|
|
1162 lstream =
|
|
1163 make_fixed_buffer_input_stream (nonrelocatable + start, len);
|
|
1164 else if (BUFFERP (relocatable))
|
|
1165 lstream = make_lisp_buffer_input_stream (XBUFFER (relocatable),
|
|
1166 start, start + len, 0);
|
|
1167 else
|
|
1168 lstream = make_lisp_string_input_stream (relocatable, start, len);
|
|
1169
|
771
|
1170 if (debug_process_io)
|
|
1171 {
|
|
1172 if (nonrelocatable)
|
|
1173 stderr_out ("Writing: %s\n", nonrelocatable);
|
|
1174 else
|
|
1175 {
|
|
1176 stderr_out ("Writing: ");
|
|
1177 print_internal (relocatable, Qexternal_debugging_output, 0);
|
|
1178 }
|
|
1179 }
|
|
1180
|
444
|
1181 PROCMETH (send_process, (process, XLSTREAM (lstream)));
|
428
|
1182
|
|
1183 UNGCPRO;
|
|
1184 Lstream_delete (XLSTREAM (lstream));
|
|
1185 }
|
|
1186
|
|
1187 DEFUN ("process-tty-name", Fprocess_tty_name, 1, 1, 0, /*
|
|
1188 Return the name of the terminal PROCESS uses, or nil if none.
|
|
1189 This is the terminal that the process itself reads and writes on,
|
|
1190 not the name of the pty that Emacs uses to talk with that terminal.
|
|
1191 */
|
444
|
1192 (process))
|
428
|
1193 {
|
444
|
1194 CHECK_PROCESS (process);
|
1204
|
1195 return XPROCESS (process)->tty_name;
|
428
|
1196 }
|
|
1197
|
|
1198 DEFUN ("set-process-buffer", Fset_process_buffer, 2, 2, 0, /*
|
|
1199 Set buffer associated with PROCESS to BUFFER (a buffer, or nil).
|
2297
|
1200 Output from PROCESS is inserted in this buffer unless PROCESS has a filter.
|
428
|
1201 */
|
444
|
1202 (process, buffer))
|
428
|
1203 {
|
444
|
1204 CHECK_PROCESS (process);
|
428
|
1205 if (!NILP (buffer))
|
|
1206 CHECK_BUFFER (buffer);
|
444
|
1207 XPROCESS (process)->buffer = buffer;
|
428
|
1208 return buffer;
|
|
1209 }
|
|
1210
|
|
1211 DEFUN ("process-buffer", Fprocess_buffer, 1, 1, 0, /*
|
|
1212 Return the buffer PROCESS is associated with.
|
2297
|
1213 Output from PROCESS is inserted in this buffer unless PROCESS has a filter.
|
|
1214 Set the buffer with `set-process-buffer'.
|
428
|
1215 */
|
444
|
1216 (process))
|
428
|
1217 {
|
444
|
1218 CHECK_PROCESS (process);
|
|
1219 return XPROCESS (process)->buffer;
|
428
|
1220 }
|
|
1221
|
853
|
1222 DEFUN ("set-process-stderr-buffer", Fset_process_stderr_buffer, 2, 2, 0, /*
|
2297
|
1223 Output from the stderr of PROCESS is inserted in this buffer unless
|
|
1224 PROCESS has a stderr filter.
|
853
|
1225 Set stderr buffer associated with PROCESS to BUFFER (a buffer, or nil).
|
|
1226 */
|
|
1227 (process, buffer))
|
|
1228 {
|
|
1229 CHECK_PROCESS (process);
|
|
1230 if (!XPROCESS (process)->separate_stderr)
|
|
1231 invalid_change ("stdout and stderr not separate", process);
|
|
1232 if (!NILP (buffer))
|
|
1233 CHECK_BUFFER (buffer);
|
|
1234 XPROCESS (process)->stderr_buffer = buffer;
|
|
1235 return buffer;
|
|
1236 }
|
|
1237
|
|
1238 DEFUN ("process-stderr-buffer", Fprocess_stderr_buffer, 1, 1, 0, /*
|
|
1239 Return the stderr buffer PROCESS is associated with.
|
2297
|
1240 Output from the stderr of PROCESS is inserted in this buffer unless PROCESS
|
|
1241 has a stderr filter. Set the buffer with `set-process-stderr-buffer'.
|
853
|
1242 */
|
|
1243 (process))
|
|
1244 {
|
|
1245 CHECK_PROCESS (process);
|
|
1246 if (!XPROCESS (process)->separate_stderr)
|
|
1247 invalid_change ("stdout and stderr not separate", process);
|
|
1248 return XPROCESS (process)->stderr_buffer;
|
|
1249 }
|
|
1250
|
428
|
1251 DEFUN ("process-mark", Fprocess_mark, 1, 1, 0, /*
|
|
1252 Return the marker for the end of the last output from PROCESS.
|
|
1253 */
|
444
|
1254 (process))
|
428
|
1255 {
|
444
|
1256 CHECK_PROCESS (process);
|
|
1257 return XPROCESS (process)->mark;
|
428
|
1258 }
|
|
1259
|
853
|
1260 DEFUN ("process-stderr-mark", Fprocess_stderr_mark, 1, 1, 0, /*
|
|
1261 Return the marker for the end of the last stderr output from PROCESS.
|
|
1262 */
|
|
1263 (process))
|
|
1264 {
|
|
1265 CHECK_PROCESS (process);
|
|
1266 if (!XPROCESS (process)->separate_stderr)
|
|
1267 invalid_operation ("stdout and stderr not separate", process);
|
|
1268 return XPROCESS (process)->stderr_mark;
|
|
1269 }
|
|
1270
|
428
|
1271 void
|
853
|
1272 set_process_filter (Lisp_Object process, Lisp_Object filter,
|
|
1273 int filter_does_read, int set_stderr)
|
428
|
1274 {
|
444
|
1275 CHECK_PROCESS (process);
|
853
|
1276 if (set_stderr && !XPROCESS (process)->separate_stderr)
|
|
1277 invalid_change ("stdout and stderr not separate", process);
|
863
|
1278 if (PROCESS_READABLE_P (XPROCESS (process)))
|
853
|
1279 {
|
|
1280 if (EQ (filter, Qt))
|
|
1281 event_stream_unselect_process (XPROCESS (process), !set_stderr,
|
|
1282 set_stderr);
|
|
1283 else
|
|
1284 event_stream_select_process (XPROCESS (process), !set_stderr,
|
|
1285 set_stderr);
|
|
1286 }
|
428
|
1287
|
853
|
1288 if (set_stderr)
|
|
1289 XPROCESS (process)->stderr_filter = filter;
|
|
1290 else
|
|
1291 XPROCESS (process)->filter = filter;
|
444
|
1292 XPROCESS (process)->filter_does_read = filter_does_read;
|
428
|
1293 }
|
|
1294
|
|
1295 DEFUN ("set-process-filter", Fset_process_filter, 2, 2, 0, /*
|
|
1296 Give PROCESS the filter function FILTER; nil means no filter.
|
853
|
1297 t means stop accepting output from the process. (If process was created
|
854
|
1298 with
|
853
|
1299 When a process has a filter, each time it does output
|
|
1300 the entire string of output is passed to the filter.
|
|
1301 The filter gets two arguments: the process and the string of output.
|
|
1302 If the process has a filter, its buffer is not used for output.
|
|
1303 */
|
|
1304 (process, filter))
|
|
1305 {
|
|
1306 set_process_filter (process, filter, 0, 0);
|
|
1307 return filter;
|
|
1308 }
|
|
1309
|
|
1310 DEFUN ("set-process-stderr-filter", Fset_process_stderr_filter, 2, 2, 0, /*
|
|
1311 Give PROCESS the stderr filter function FILTER; nil means no filter.
|
428
|
1312 t means stop accepting output from the process.
|
|
1313 When a process has a filter, each time it does output
|
|
1314 the entire string of output is passed to the filter.
|
|
1315 The filter gets two arguments: the process and the string of output.
|
|
1316 If the process has a filter, its buffer is not used for output.
|
|
1317 */
|
444
|
1318 (process, filter))
|
428
|
1319 {
|
853
|
1320 set_process_filter (process, filter, 0, 1);
|
428
|
1321 return filter;
|
|
1322 }
|
|
1323
|
|
1324 DEFUN ("process-filter", Fprocess_filter, 1, 1, 0, /*
|
|
1325 Return the filter function of PROCESS; nil if none.
|
|
1326 See `set-process-filter' for more info on filter functions.
|
|
1327 */
|
444
|
1328 (process))
|
428
|
1329 {
|
444
|
1330 CHECK_PROCESS (process);
|
|
1331 return XPROCESS (process)->filter;
|
428
|
1332 }
|
|
1333
|
853
|
1334 DEFUN ("process-stderr-filter", Fprocess_stderr_filter, 1, 1, 0, /*
|
|
1335 Return the filter function of PROCESS; nil if none.
|
|
1336 See `set-process-stderr-filter' for more info on filter functions.
|
|
1337 */
|
|
1338 (process))
|
|
1339 {
|
|
1340 CHECK_PROCESS (process);
|
|
1341 if (!XPROCESS (process)->separate_stderr)
|
|
1342 invalid_operation ("stdout and stderr not separate", process);
|
|
1343 return XPROCESS (process)->stderr_filter;
|
|
1344 }
|
|
1345
|
442
|
1346 DEFUN ("process-send-region", Fprocess_send_region, 3, 4, 0, /*
|
|
1347 Send current contents of the region between START and END as input to PROCESS.
|
444
|
1348 PROCESS may be a process or the name of a process, or a buffer or the
|
|
1349 name of a buffer, in which case the buffer's process is used. If it
|
|
1350 is nil, the current buffer's process is used.
|
442
|
1351 BUFFER specifies the buffer to look in; if nil, the current buffer is used.
|
853
|
1352 If the region is more than 100 or so characters long, it may be sent in
|
|
1353 several chunks. This may happen even for shorter regions. Output
|
444
|
1354 from processes can arrive in between chunks.
|
428
|
1355 */
|
442
|
1356 (process, start, end, buffer))
|
428
|
1357 {
|
|
1358 /* This function can GC */
|
665
|
1359 Charbpos bstart, bend;
|
442
|
1360 struct buffer *buf = decode_buffer (buffer, 0);
|
428
|
1361
|
793
|
1362 buffer = wrap_buffer (buf);
|
444
|
1363 process = get_process (process);
|
|
1364 get_buffer_range_char (buf, start, end, &bstart, &bend, 0);
|
442
|
1365
|
444
|
1366 send_process (process, buffer, 0, bstart, bend - bstart);
|
428
|
1367 return Qnil;
|
|
1368 }
|
|
1369
|
|
1370 DEFUN ("process-send-string", Fprocess_send_string, 2, 4, 0, /*
|
|
1371 Send PROCESS the contents of STRING as input.
|
444
|
1372 PROCESS may be a process or the name of a process, or a buffer or the
|
|
1373 name of a buffer, in which case the buffer's process is used. If it
|
|
1374 is nil, the current buffer's process is used.
|
|
1375 Optional arguments START and END specify part of STRING; see `substring'.
|
|
1376 If STRING is more than 100 or so characters long, it may be sent in
|
|
1377 several chunks. This may happen even for shorter strings. Output
|
|
1378 from processes can arrive in between chunks.
|
428
|
1379 */
|
444
|
1380 (process, string, start, end))
|
428
|
1381 {
|
|
1382 /* This function can GC */
|
444
|
1383 Bytecount bstart, bend;
|
428
|
1384
|
444
|
1385 process = get_process (process);
|
428
|
1386 CHECK_STRING (string);
|
444
|
1387 get_string_range_byte (string, start, end, &bstart, &bend,
|
428
|
1388 GB_HISTORICAL_STRING_BEHAVIOR);
|
|
1389
|
444
|
1390 send_process (process, string, 0, bstart, bend - bstart);
|
428
|
1391 return Qnil;
|
|
1392 }
|
|
1393
|
|
1394
|
|
1395 DEFUN ("process-input-coding-system", Fprocess_input_coding_system, 1, 1, 0, /*
|
|
1396 Return PROCESS's input coding system.
|
|
1397 */
|
|
1398 (process))
|
|
1399 {
|
|
1400 process = get_process (process);
|
863
|
1401 CHECK_READABLE_PROCESS (process);
|
771
|
1402 return (coding_stream_detected_coding_system
|
|
1403 (XLSTREAM (XPROCESS (process)->coding_instream)));
|
428
|
1404 }
|
|
1405
|
|
1406 DEFUN ("process-output-coding-system", Fprocess_output_coding_system, 1, 1, 0, /*
|
|
1407 Return PROCESS's output coding system.
|
|
1408 */
|
|
1409 (process))
|
|
1410 {
|
|
1411 process = get_process (process);
|
440
|
1412 CHECK_LIVE_PROCESS (process);
|
771
|
1413 return (coding_stream_coding_system
|
|
1414 (XLSTREAM (XPROCESS (process)->coding_outstream)));
|
428
|
1415 }
|
|
1416
|
|
1417 DEFUN ("process-coding-system", Fprocess_coding_system, 1, 1, 0, /*
|
|
1418 Return a pair of coding-system for decoding and encoding of PROCESS.
|
|
1419 */
|
|
1420 (process))
|
|
1421 {
|
|
1422 process = get_process (process);
|
863
|
1423 CHECK_READABLE_PROCESS (process);
|
771
|
1424 return Fcons (coding_stream_detected_coding_system
|
428
|
1425 (XLSTREAM (XPROCESS (process)->coding_instream)),
|
771
|
1426 coding_stream_coding_system
|
428
|
1427 (XLSTREAM (XPROCESS (process)->coding_outstream)));
|
|
1428 }
|
|
1429
|
|
1430 DEFUN ("set-process-input-coding-system", Fset_process_input_coding_system,
|
|
1431 2, 2, 0, /*
|
|
1432 Set PROCESS's input coding system to CODESYS.
|
771
|
1433 This is used for reading data from PROCESS.
|
428
|
1434 */
|
|
1435 (process, codesys))
|
|
1436 {
|
771
|
1437 codesys = get_coding_system_for_text_file (codesys, 1);
|
428
|
1438 process = get_process (process);
|
863
|
1439 CHECK_READABLE_PROCESS (process);
|
440
|
1440
|
771
|
1441 set_coding_stream_coding_system
|
428
|
1442 (XLSTREAM (XPROCESS (process)->coding_instream), codesys);
|
|
1443 return Qnil;
|
|
1444 }
|
|
1445
|
|
1446 DEFUN ("set-process-output-coding-system", Fset_process_output_coding_system,
|
|
1447 2, 2, 0, /*
|
|
1448 Set PROCESS's output coding system to CODESYS.
|
771
|
1449 This is used for writing data to PROCESS.
|
428
|
1450 */
|
|
1451 (process, codesys))
|
|
1452 {
|
771
|
1453 codesys = get_coding_system_for_text_file (codesys, 0);
|
428
|
1454 process = get_process (process);
|
440
|
1455 CHECK_LIVE_PROCESS (process);
|
|
1456
|
771
|
1457 set_coding_stream_coding_system
|
428
|
1458 (XLSTREAM (XPROCESS (process)->coding_outstream), codesys);
|
|
1459 return Qnil;
|
|
1460 }
|
|
1461
|
|
1462 DEFUN ("set-process-coding-system", Fset_process_coding_system,
|
|
1463 1, 3, 0, /*
|
|
1464 Set coding-systems of PROCESS to DECODING and ENCODING.
|
440
|
1465 DECODING will be used to decode subprocess output and ENCODING to
|
|
1466 encode subprocess input.
|
428
|
1467 */
|
|
1468 (process, decoding, encoding))
|
|
1469 {
|
|
1470 if (!NILP (decoding))
|
|
1471 Fset_process_input_coding_system (process, decoding);
|
|
1472
|
|
1473 if (!NILP (encoding))
|
|
1474 Fset_process_output_coding_system (process, encoding);
|
|
1475
|
|
1476 return Qnil;
|
|
1477 }
|
|
1478
|
|
1479
|
|
1480 /************************************************************************/
|
|
1481 /* process status */
|
|
1482 /************************************************************************/
|
|
1483
|
|
1484 static Lisp_Object
|
|
1485 exec_sentinel_unwind (Lisp_Object datum)
|
|
1486 {
|
853
|
1487 XPROCESS (XCAR (datum))->sentinel = XCDR (datum);
|
|
1488 free_cons (datum);
|
428
|
1489 return Qnil;
|
|
1490 }
|
|
1491
|
|
1492 static void
|
444
|
1493 exec_sentinel (Lisp_Object process, Lisp_Object reason)
|
428
|
1494 {
|
|
1495 /* This function can GC */
|
|
1496 int speccount = specpdl_depth ();
|
444
|
1497 Lisp_Process *p = XPROCESS (process);
|
428
|
1498 Lisp_Object sentinel = p->sentinel;
|
|
1499
|
|
1500 if (NILP (sentinel))
|
|
1501 return;
|
|
1502
|
|
1503 /* Some weird FSFmacs crap here with
|
|
1504 Vdeactivate_mark and current_buffer->keymap */
|
|
1505
|
853
|
1506 /* Some FSF junk with running_asynch_code, to preserve the match
|
|
1507 data. Not necessary because we don't call process filters
|
|
1508 asynchronously (i.e. from within QUIT). */
|
|
1509
|
428
|
1510 /* Zilch the sentinel while it's running, to avoid recursive invocations;
|
853
|
1511 assure that it gets restored no matter how the sentinel exits.
|
|
1512
|
|
1513 (#### Why is this necessary? Probably another relic of asynchronous
|
|
1514 calling of process filters/sentinels.) */
|
428
|
1515 p->sentinel = Qnil;
|
853
|
1516 record_unwind_protect (exec_sentinel_unwind,
|
|
1517 noseeum_cons (process, sentinel));
|
|
1518 /* Don't catch errors here; we're not in any critical code. */
|
|
1519 call2 (sentinel, process, reason);
|
771
|
1520 unbind_to (speccount);
|
428
|
1521 }
|
|
1522
|
|
1523 DEFUN ("set-process-sentinel", Fset_process_sentinel, 2, 2, 0, /*
|
|
1524 Give PROCESS the sentinel SENTINEL; nil for none.
|
|
1525 The sentinel is called as a function when the process changes state.
|
|
1526 It gets two arguments: the process, and a string describing the change.
|
|
1527 */
|
444
|
1528 (process, sentinel))
|
428
|
1529 {
|
444
|
1530 CHECK_PROCESS (process);
|
|
1531 XPROCESS (process)->sentinel = sentinel;
|
428
|
1532 return sentinel;
|
|
1533 }
|
|
1534
|
|
1535 DEFUN ("process-sentinel", Fprocess_sentinel, 1, 1, 0, /*
|
|
1536 Return the sentinel of PROCESS; nil if none.
|
|
1537 See `set-process-sentinel' for more info on sentinels.
|
|
1538 */
|
444
|
1539 (process))
|
428
|
1540 {
|
444
|
1541 CHECK_PROCESS (process);
|
|
1542 return XPROCESS (process)->sentinel;
|
428
|
1543 }
|
|
1544
|
|
1545
|
442
|
1546 const char *
|
428
|
1547 signal_name (int signum)
|
|
1548 {
|
|
1549 if (signum >= 0 && signum < NSIG)
|
442
|
1550 return (const char *) sys_siglist[signum];
|
428
|
1551
|
442
|
1552 return (const char *) GETTEXT ("unknown signal");
|
428
|
1553 }
|
|
1554
|
|
1555 void
|
|
1556 update_process_status (Lisp_Object p,
|
|
1557 Lisp_Object status_symbol,
|
|
1558 int exit_code,
|
|
1559 int core_dumped)
|
|
1560 {
|
|
1561 XPROCESS (p)->tick++;
|
|
1562 process_tick++;
|
|
1563 XPROCESS (p)->status_symbol = status_symbol;
|
|
1564 XPROCESS (p)->exit_code = exit_code;
|
|
1565 XPROCESS (p)->core_dumped = core_dumped;
|
|
1566 }
|
|
1567
|
|
1568 /* Return a string describing a process status list. */
|
|
1569
|
|
1570 static Lisp_Object
|
440
|
1571 status_message (Lisp_Process *p)
|
428
|
1572 {
|
|
1573 Lisp_Object symbol = p->status_symbol;
|
|
1574 int code = p->exit_code;
|
|
1575 int coredump = p->core_dumped;
|
|
1576 Lisp_Object string, string2;
|
|
1577
|
|
1578 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
|
|
1579 {
|
|
1580 string = build_string (signal_name (code));
|
|
1581 if (coredump)
|
771
|
1582 string2 = build_msg_string (" (core dumped)\n");
|
428
|
1583 else
|
|
1584 string2 = build_string ("\n");
|
793
|
1585 set_string_char (string, 0,
|
867
|
1586 DOWNCASE (0, string_ichar (string, 0)));
|
428
|
1587 return concat2 (string, string2);
|
|
1588 }
|
|
1589 else if (EQ (symbol, Qexit))
|
|
1590 {
|
|
1591 if (code == 0)
|
771
|
1592 return build_msg_string ("finished\n");
|
428
|
1593 string = Fnumber_to_string (make_int (code));
|
|
1594 if (coredump)
|
771
|
1595 string2 = build_msg_string (" (core dumped)\n");
|
428
|
1596 else
|
|
1597 string2 = build_string ("\n");
|
771
|
1598 return concat2 (build_msg_string ("exited abnormally with code "),
|
428
|
1599 concat2 (string, string2));
|
|
1600 }
|
|
1601 else
|
|
1602 return Fcopy_sequence (Fsymbol_name (symbol));
|
|
1603 }
|
|
1604
|
|
1605 /* Tell status_notify() to check for terminated processes. We do this
|
|
1606 because on some systems we sometimes miss SIGCHLD calls. (Not sure
|
853
|
1607 why.) This is also used under Mswin. */
|
428
|
1608
|
|
1609 void
|
|
1610 kick_status_notify (void)
|
|
1611 {
|
|
1612 process_tick++;
|
|
1613 }
|
|
1614
|
|
1615
|
|
1616 /* Report all recent events of a change in process status
|
|
1617 (either run the sentinel or output a message).
|
|
1618 This is done while Emacs is waiting for keyboard input. */
|
|
1619
|
|
1620 void
|
|
1621 status_notify (void)
|
|
1622 {
|
|
1623 /* This function can GC */
|
|
1624 Lisp_Object tail = Qnil;
|
|
1625 Lisp_Object symbol = Qnil;
|
|
1626 Lisp_Object msg = Qnil;
|
|
1627 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1628 /* process_tick is volatile, so we have to remember it now.
|
444
|
1629 Otherwise, we get a race condition if SIGCHLD happens during
|
428
|
1630 this function.
|
|
1631
|
|
1632 (Actually, this is not the case anymore. The code to
|
|
1633 update the process structures has been moved out of the
|
|
1634 SIGCHLD handler. But for the moment I'm leaving this
|
|
1635 stuff in -- it can't hurt.) */
|
|
1636 int temp_process_tick;
|
|
1637
|
|
1638 MAYBE_PROCMETH (reap_exited_processes, ());
|
|
1639
|
|
1640 temp_process_tick = process_tick;
|
|
1641
|
|
1642 if (update_tick == temp_process_tick)
|
|
1643 return;
|
|
1644
|
|
1645 /* We need to gcpro tail; if read_process_output calls a filter
|
|
1646 which deletes a process and removes the cons to which tail points
|
|
1647 from Vprocess_alist, and then causes a GC, tail is an unprotected
|
|
1648 reference. */
|
|
1649 GCPRO3 (tail, symbol, msg);
|
|
1650
|
|
1651 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
|
|
1652 {
|
444
|
1653 Lisp_Object process = XCAR (tail);
|
|
1654 Lisp_Process *p = XPROCESS (process);
|
428
|
1655 /* p->tick is also volatile. Same thing as above applies. */
|
|
1656 int this_process_tick;
|
|
1657
|
|
1658 /* #### extra check for terminated processes, in case a SIGCHLD
|
|
1659 got missed (this seems to happen sometimes, I'm not sure why).
|
|
1660 */
|
|
1661 if (INTP (p->pid))
|
|
1662 MAYBE_PROCMETH (update_status_if_terminated, (p));
|
|
1663
|
|
1664 this_process_tick = p->tick;
|
|
1665 if (this_process_tick != p->update_tick)
|
|
1666 {
|
|
1667 p->update_tick = this_process_tick;
|
|
1668
|
|
1669 /* If process is still active, read any output that remains. */
|
|
1670 while (!EQ (p->filter, Qt)
|
853
|
1671 && read_process_output (process, 0) > 0)
|
|
1672 ;
|
|
1673 while (p->separate_stderr && !EQ (p->stderr_filter, Qt)
|
|
1674 && read_process_output (process, 1) > 0)
|
428
|
1675 ;
|
|
1676
|
|
1677 /* Get the text to use for the message. */
|
|
1678 msg = status_message (p);
|
|
1679
|
|
1680 /* If process is terminated, deactivate it or delete it. */
|
|
1681 symbol = p->status_symbol;
|
|
1682
|
|
1683 if (EQ (symbol, Qsignal)
|
|
1684 || EQ (symbol, Qexit))
|
|
1685 {
|
|
1686 if (delete_exited_processes)
|
444
|
1687 remove_process (process);
|
428
|
1688 else
|
444
|
1689 deactivate_process (process);
|
428
|
1690 }
|
|
1691
|
|
1692 /* Now output the message suitably. */
|
|
1693 if (!NILP (p->sentinel))
|
444
|
1694 exec_sentinel (process, msg);
|
428
|
1695 /* Don't bother with a message in the buffer
|
|
1696 when a process becomes runnable. */
|
844
|
1697 else if (!EQ (symbol, Qrun) && !NILP (p->buffer) &&
|
|
1698 /* Avoid error if buffer is deleted
|
|
1699 (probably that's why the process is dead, too) */
|
|
1700 BUFFER_LIVE_P (XBUFFER (p->buffer)))
|
428
|
1701 {
|
844
|
1702 struct gcpro ngcpro1;
|
853
|
1703 int spec = process_setup_for_insertion (process, 0);
|
428
|
1704
|
844
|
1705 NGCPRO1 (process);
|
428
|
1706 buffer_insert_c_string (current_buffer, "\nProcess ");
|
|
1707 Finsert (1, &p->name);
|
|
1708 buffer_insert_c_string (current_buffer, " ");
|
|
1709 Finsert (1, &msg);
|
|
1710 Fset_marker (p->mark, make_int (BUF_PT (current_buffer)),
|
|
1711 p->buffer);
|
|
1712
|
844
|
1713 unbind_to (spec);
|
428
|
1714 NUNGCPRO;
|
|
1715 }
|
|
1716 }
|
|
1717 } /* end for */
|
|
1718
|
|
1719 /* in case buffers use %s in modeline-format */
|
|
1720 MARK_MODELINE_CHANGED;
|
|
1721 redisplay ();
|
|
1722
|
|
1723 update_tick = temp_process_tick;
|
|
1724
|
|
1725 UNGCPRO;
|
|
1726 }
|
|
1727
|
|
1728 DEFUN ("process-status", Fprocess_status, 1, 1, 0, /*
|
|
1729 Return the status of PROCESS.
|
|
1730 This is a symbol, one of these:
|
|
1731
|
|
1732 run -- for a process that is running.
|
|
1733 stop -- for a process stopped but continuable.
|
|
1734 exit -- for a process that has exited.
|
|
1735 signal -- for a process that has got a fatal signal.
|
|
1736 open -- for a network stream connection that is open.
|
|
1737 closed -- for a network stream connection that is closed.
|
|
1738 nil -- if arg is a process name and no such process exists.
|
|
1739
|
|
1740 PROCESS may be a process, a buffer, the name of a process or buffer, or
|
|
1741 nil, indicating the current buffer's process.
|
|
1742 */
|
444
|
1743 (process))
|
428
|
1744 {
|
|
1745 Lisp_Object status_symbol;
|
|
1746
|
444
|
1747 if (STRINGP (process))
|
|
1748 process = Fget_process (process);
|
428
|
1749 else
|
444
|
1750 process = get_process (process);
|
428
|
1751
|
444
|
1752 if (NILP (process))
|
428
|
1753 return Qnil;
|
|
1754
|
444
|
1755 status_symbol = XPROCESS (process)->status_symbol;
|
|
1756 if (network_connection_p (process))
|
428
|
1757 {
|
|
1758 if (EQ (status_symbol, Qrun))
|
|
1759 status_symbol = Qopen;
|
|
1760 else if (EQ (status_symbol, Qexit))
|
|
1761 status_symbol = Qclosed;
|
|
1762 }
|
|
1763 return status_symbol;
|
|
1764 }
|
|
1765
|
|
1766 DEFUN ("process-exit-status", Fprocess_exit_status, 1, 1, 0, /*
|
|
1767 Return the exit status of PROCESS or the signal number that killed it.
|
|
1768 If PROCESS has not yet exited or died, return 0.
|
|
1769 */
|
444
|
1770 (process))
|
428
|
1771 {
|
444
|
1772 CHECK_PROCESS (process);
|
|
1773 return make_int (XPROCESS (process)->exit_code);
|
428
|
1774 }
|
|
1775
|
|
1776
|
|
1777
|
442
|
1778 static int
|
|
1779 decode_signal (Lisp_Object signal_)
|
428
|
1780 {
|
442
|
1781 if (INTP (signal_))
|
|
1782 return XINT (signal_);
|
428
|
1783 else
|
|
1784 {
|
867
|
1785 Ibyte *name;
|
428
|
1786
|
442
|
1787 CHECK_SYMBOL (signal_);
|
793
|
1788 name = XSTRING_DATA (XSYMBOL (signal_)->name);
|
428
|
1789
|
793
|
1790 #define handle_signal(sym) do { \
|
|
1791 if (!qxestrcmp_c ( name, #sym)) \
|
|
1792 return sym; \
|
442
|
1793 } while (0)
|
428
|
1794
|
|
1795 handle_signal (SIGINT); /* ANSI */
|
|
1796 handle_signal (SIGILL); /* ANSI */
|
|
1797 handle_signal (SIGABRT); /* ANSI */
|
|
1798 handle_signal (SIGFPE); /* ANSI */
|
|
1799 handle_signal (SIGSEGV); /* ANSI */
|
|
1800 handle_signal (SIGTERM); /* ANSI */
|
|
1801
|
|
1802 #ifdef SIGHUP
|
|
1803 handle_signal (SIGHUP); /* POSIX */
|
|
1804 #endif
|
|
1805 #ifdef SIGQUIT
|
|
1806 handle_signal (SIGQUIT); /* POSIX */
|
|
1807 #endif
|
|
1808 #ifdef SIGTRAP
|
|
1809 handle_signal (SIGTRAP); /* POSIX */
|
|
1810 #endif
|
|
1811 #ifdef SIGKILL
|
|
1812 handle_signal (SIGKILL); /* POSIX */
|
|
1813 #endif
|
|
1814 #ifdef SIGUSR1
|
|
1815 handle_signal (SIGUSR1); /* POSIX */
|
|
1816 #endif
|
|
1817 #ifdef SIGUSR2
|
|
1818 handle_signal (SIGUSR2); /* POSIX */
|
|
1819 #endif
|
|
1820 #ifdef SIGPIPE
|
|
1821 handle_signal (SIGPIPE); /* POSIX */
|
|
1822 #endif
|
|
1823 #ifdef SIGALRM
|
|
1824 handle_signal (SIGALRM); /* POSIX */
|
|
1825 #endif
|
|
1826 #ifdef SIGCHLD
|
|
1827 handle_signal (SIGCHLD); /* POSIX */
|
|
1828 #endif
|
|
1829 #ifdef SIGCONT
|
|
1830 handle_signal (SIGCONT); /* POSIX */
|
|
1831 #endif
|
|
1832 #ifdef SIGSTOP
|
|
1833 handle_signal (SIGSTOP); /* POSIX */
|
|
1834 #endif
|
|
1835 #ifdef SIGTSTP
|
|
1836 handle_signal (SIGTSTP); /* POSIX */
|
|
1837 #endif
|
|
1838 #ifdef SIGTTIN
|
|
1839 handle_signal (SIGTTIN); /* POSIX */
|
|
1840 #endif
|
|
1841 #ifdef SIGTTOU
|
|
1842 handle_signal (SIGTTOU); /* POSIX */
|
|
1843 #endif
|
|
1844
|
|
1845 #ifdef SIGBUS
|
|
1846 handle_signal (SIGBUS); /* XPG5 */
|
|
1847 #endif
|
|
1848 #ifdef SIGPOLL
|
|
1849 handle_signal (SIGPOLL); /* XPG5 */
|
|
1850 #endif
|
|
1851 #ifdef SIGPROF
|
|
1852 handle_signal (SIGPROF); /* XPG5 */
|
|
1853 #endif
|
|
1854 #ifdef SIGSYS
|
|
1855 handle_signal (SIGSYS); /* XPG5 */
|
|
1856 #endif
|
|
1857 #ifdef SIGURG
|
|
1858 handle_signal (SIGURG); /* XPG5 */
|
|
1859 #endif
|
|
1860 #ifdef SIGXCPU
|
|
1861 handle_signal (SIGXCPU); /* XPG5 */
|
|
1862 #endif
|
|
1863 #ifdef SIGXFSZ
|
|
1864 handle_signal (SIGXFSZ); /* XPG5 */
|
|
1865 #endif
|
|
1866 #ifdef SIGVTALRM
|
|
1867 handle_signal (SIGVTALRM); /* XPG5 */
|
|
1868 #endif
|
|
1869
|
|
1870 #ifdef SIGIO
|
|
1871 handle_signal (SIGIO); /* BSD 4.2 */
|
|
1872 #endif
|
|
1873 #ifdef SIGWINCH
|
|
1874 handle_signal (SIGWINCH); /* BSD 4.3 */
|
|
1875 #endif
|
|
1876
|
|
1877 #ifdef SIGEMT
|
|
1878 handle_signal (SIGEMT);
|
|
1879 #endif
|
|
1880 #ifdef SIGINFO
|
|
1881 handle_signal (SIGINFO);
|
|
1882 #endif
|
|
1883 #ifdef SIGHWE
|
|
1884 handle_signal (SIGHWE);
|
|
1885 #endif
|
|
1886 #ifdef SIGPRE
|
|
1887 handle_signal (SIGPRE);
|
|
1888 #endif
|
|
1889 #ifdef SIGUME
|
|
1890 handle_signal (SIGUME);
|
|
1891 #endif
|
|
1892 #ifdef SIGDLK
|
|
1893 handle_signal (SIGDLK);
|
|
1894 #endif
|
|
1895 #ifdef SIGCPULIM
|
|
1896 handle_signal (SIGCPULIM);
|
|
1897 #endif
|
|
1898 #ifdef SIGIOT
|
|
1899 handle_signal (SIGIOT);
|
|
1900 #endif
|
|
1901 #ifdef SIGLOST
|
|
1902 handle_signal (SIGLOST);
|
|
1903 #endif
|
|
1904 #ifdef SIGSTKFLT
|
|
1905 handle_signal (SIGSTKFLT);
|
|
1906 #endif
|
|
1907 #ifdef SIGUNUSED
|
|
1908 handle_signal (SIGUNUSED);
|
|
1909 #endif
|
|
1910 #ifdef SIGDANGER
|
|
1911 handle_signal (SIGDANGER); /* AIX */
|
|
1912 #endif
|
|
1913 #ifdef SIGMSG
|
|
1914 handle_signal (SIGMSG);
|
|
1915 #endif
|
|
1916 #ifdef SIGSOUND
|
|
1917 handle_signal (SIGSOUND);
|
|
1918 #endif
|
|
1919 #ifdef SIGRETRACT
|
|
1920 handle_signal (SIGRETRACT);
|
|
1921 #endif
|
|
1922 #ifdef SIGGRANT
|
|
1923 handle_signal (SIGGRANT);
|
|
1924 #endif
|
|
1925 #ifdef SIGPWR
|
|
1926 handle_signal (SIGPWR);
|
|
1927 #endif
|
|
1928
|
|
1929 #undef handle_signal
|
|
1930
|
563
|
1931 invalid_constant ("Undefined signal name", signal_);
|
1204
|
1932 RETURN_NOT_REACHED (0);
|
442
|
1933 }
|
|
1934 }
|
|
1935
|
|
1936 /* Send signal number SIGNO to PROCESS.
|
|
1937 CURRENT-GROUP non-nil means send signal to the current
|
|
1938 foreground process group of the process's controlling terminal rather
|
|
1939 than to the process's own process group.
|
|
1940 This is used for various commands in shell mode.
|
|
1941 If NOMSG is zero, insert signal-announcements into process's buffers
|
|
1942 right away.
|
|
1943
|
|
1944 If we can, we try to signal PROCESS by sending control characters
|
|
1945 down the pty. This allows us to signal inferiors who have changed
|
|
1946 their uid, for which kill() would return an EPERM error, or to
|
|
1947 processes running on another computer through a remote login. */
|
|
1948
|
|
1949 static void
|
|
1950 process_send_signal (Lisp_Object process, int signo,
|
|
1951 int current_group, int nomsg)
|
|
1952 {
|
|
1953 /* This function can GC */
|
444
|
1954 process = get_process (process);
|
442
|
1955
|
444
|
1956 if (network_connection_p (process))
|
563
|
1957 invalid_operation ("Network connection is not a subprocess", process);
|
444
|
1958 CHECK_LIVE_PROCESS (process);
|
442
|
1959
|
444
|
1960 MAYBE_PROCMETH (kill_child_process, (process, signo, current_group, nomsg));
|
442
|
1961 }
|
|
1962
|
|
1963 DEFUN ("process-send-signal", Fprocess_send_signal, 1, 3, 0, /*
|
|
1964 Send signal SIGNAL to process PROCESS.
|
|
1965 SIGNAL may be an integer, or a symbol naming a signal, like `SIGSEGV'.
|
|
1966 PROCESS may be a process, a buffer, the name of a process or buffer, or
|
|
1967 nil, indicating the current buffer's process.
|
|
1968 Third arg CURRENT-GROUP non-nil means send signal to the current
|
|
1969 foreground process group of the process's controlling terminal rather
|
|
1970 than to the process's own process group.
|
|
1971 If the process is a shell that supports job control, this means
|
|
1972 send the signal to the current subjob rather than the shell.
|
|
1973 */
|
|
1974 (signal_, process, current_group))
|
|
1975 {
|
|
1976 /* This function can GC */
|
|
1977 process_send_signal (process, decode_signal (signal_),
|
|
1978 !NILP (current_group), 0);
|
|
1979 return process;
|
|
1980 }
|
|
1981
|
|
1982 DEFUN ("interrupt-process", Finterrupt_process, 0, 2, 0, /*
|
|
1983 Interrupt process PROCESS.
|
|
1984 See function `process-send-signal' for more details on usage.
|
|
1985 */
|
|
1986 (process, current_group))
|
|
1987 {
|
|
1988 /* This function can GC */
|
|
1989 process_send_signal (process, SIGINT, !NILP (current_group), 0);
|
|
1990 return process;
|
|
1991 }
|
|
1992
|
|
1993 DEFUN ("kill-process", Fkill_process, 0, 2, 0, /*
|
|
1994 Kill process PROCESS.
|
|
1995 See function `process-send-signal' for more details on usage.
|
|
1996 */
|
|
1997 (process, current_group))
|
|
1998 {
|
|
1999 /* This function can GC */
|
|
2000 #ifdef SIGKILL
|
|
2001 process_send_signal (process, SIGKILL, !NILP (current_group), 0);
|
|
2002 #else
|
563
|
2003 signal_error (Qunimplemented,
|
|
2004 "kill-process: Not supported on this system",
|
|
2005 Qunbound);
|
442
|
2006 #endif
|
|
2007 return process;
|
|
2008 }
|
|
2009
|
|
2010 DEFUN ("quit-process", Fquit_process, 0, 2, 0, /*
|
|
2011 Send QUIT signal to process PROCESS.
|
|
2012 See function `process-send-signal' for more details on usage.
|
|
2013 */
|
|
2014 (process, current_group))
|
|
2015 {
|
|
2016 /* This function can GC */
|
|
2017 #ifdef SIGQUIT
|
|
2018 process_send_signal (process, SIGQUIT, !NILP (current_group), 0);
|
|
2019 #else
|
563
|
2020 signal_error (Qunimplemented,
|
|
2021 "quit-process: Not supported on this system",
|
|
2022 Qunbound);
|
442
|
2023 #endif
|
|
2024 return process;
|
|
2025 }
|
|
2026
|
|
2027 DEFUN ("stop-process", Fstop_process, 0, 2, 0, /*
|
|
2028 Stop process PROCESS.
|
|
2029 See function `process-send-signal' for more details on usage.
|
|
2030 */
|
|
2031 (process, current_group))
|
|
2032 {
|
|
2033 /* This function can GC */
|
|
2034 #ifdef SIGTSTP
|
|
2035 process_send_signal (process, SIGTSTP, !NILP (current_group), 0);
|
|
2036 #else
|
563
|
2037 signal_error (Qunimplemented,
|
|
2038 "stop-process: Not supported on this system",
|
|
2039 Qunbound);
|
442
|
2040 #endif
|
|
2041 return process;
|
|
2042 }
|
|
2043
|
|
2044 DEFUN ("continue-process", Fcontinue_process, 0, 2, 0, /*
|
|
2045 Continue process PROCESS.
|
|
2046 See function `process-send-signal' for more details on usage.
|
|
2047 */
|
|
2048 (process, current_group))
|
|
2049 {
|
|
2050 /* This function can GC */
|
|
2051 #ifdef SIGCONT
|
|
2052 process_send_signal (process, SIGCONT, !NILP (current_group), 0);
|
|
2053 #else
|
563
|
2054 signal_error (Qunimplemented,
|
|
2055 "continue-process: Not supported on this system",
|
|
2056 Qunbound);
|
442
|
2057 #endif
|
|
2058 return process;
|
|
2059 }
|
|
2060
|
|
2061 DEFUN ("signal-process", Fsignal_process, 2, 2,
|
|
2062 "nProcess number: \nnSignal code: ", /*
|
|
2063 Send the process with process id PID the signal with code SIGNAL.
|
|
2064 PID must be an integer. The process need not be a child of this Emacs.
|
|
2065 SIGNAL may be an integer, or a symbol naming a signal, like `SIGSEGV'.
|
|
2066 */
|
|
2067 (pid, signal_))
|
|
2068 {
|
|
2069 CHECK_INT (pid);
|
|
2070
|
428
|
2071 return make_int (PROCMETH_OR_GIVEN (kill_process_by_pid,
|
442
|
2072 (XINT (pid), decode_signal (signal_)),
|
|
2073 -1));
|
428
|
2074 }
|
|
2075
|
|
2076 DEFUN ("process-send-eof", Fprocess_send_eof, 0, 1, 0, /*
|
|
2077 Make PROCESS see end-of-file in its input.
|
|
2078 PROCESS may be a process, a buffer, the name of a process or buffer, or
|
|
2079 nil, indicating the current buffer's process.
|
|
2080 If PROCESS is a network connection, or is a process communicating
|
|
2081 through a pipe (as opposed to a pty), then you cannot send any more
|
|
2082 text to PROCESS after you call this function.
|
|
2083 */
|
|
2084 (process))
|
|
2085 {
|
|
2086 /* This function can GC */
|
444
|
2087 process = get_process (process);
|
428
|
2088
|
|
2089 /* Make sure the process is really alive. */
|
444
|
2090 if (! EQ (XPROCESS (process)->status_symbol, Qrun))
|
563
|
2091 invalid_operation ("Process not running", process);
|
428
|
2092
|
444
|
2093 if (!MAYBE_INT_PROCMETH (process_send_eof, (process)))
|
428
|
2094 {
|
444
|
2095 if (!NILP (DATA_OUTSTREAM (XPROCESS (process))))
|
428
|
2096 {
|
853
|
2097 USID humpty, dumpty;
|
444
|
2098 Lstream_close (XLSTREAM (DATA_OUTSTREAM (XPROCESS (process))));
|
853
|
2099 event_stream_delete_io_streams (Qnil,
|
|
2100 XPROCESS (process)->pipe_outstream,
|
|
2101 Qnil, &humpty, &dumpty);
|
444
|
2102 XPROCESS (process)->pipe_outstream = Qnil;
|
|
2103 XPROCESS (process)->coding_outstream = Qnil;
|
428
|
2104 }
|
|
2105 }
|
|
2106
|
|
2107 return process;
|
|
2108 }
|
|
2109
|
|
2110
|
|
2111 /************************************************************************/
|
|
2112 /* deleting a process */
|
|
2113 /************************************************************************/
|
|
2114
|
|
2115 void
|
444
|
2116 deactivate_process (Lisp_Object process)
|
428
|
2117 {
|
444
|
2118 Lisp_Process *p = XPROCESS (process);
|
853
|
2119 USID in_usid, err_usid;
|
428
|
2120
|
|
2121 /* It's possible that we got as far in the process-creation
|
|
2122 process as creating the descriptors but didn't get so
|
|
2123 far as selecting the process for input. In this
|
|
2124 case, p->pid is nil: p->pid is set at the same time that
|
|
2125 the process is selected for input. */
|
|
2126 /* #### The comment does not look correct. event_stream_unselect_process
|
853
|
2127 is guarded by process->*_selected, so this is not a problem. - kkm*/
|
428
|
2128 /* Must call this before setting the streams to nil */
|
853
|
2129 event_stream_unselect_process (p, 1, 1);
|
428
|
2130
|
|
2131 if (!NILP (DATA_OUTSTREAM (p)))
|
|
2132 Lstream_close (XLSTREAM (DATA_OUTSTREAM (p)));
|
|
2133 if (!NILP (DATA_INSTREAM (p)))
|
|
2134 Lstream_close (XLSTREAM (DATA_INSTREAM (p)));
|
853
|
2135 if (!NILP (DATA_ERRSTREAM (p)))
|
|
2136 Lstream_close (XLSTREAM (DATA_ERRSTREAM (p)));
|
428
|
2137
|
|
2138 /* Provide minimal implementation for deactivate_process
|
|
2139 if there's no process-specific one */
|
|
2140 if (HAS_PROCMETH_P (deactivate_process))
|
853
|
2141 PROCMETH (deactivate_process, (p, &in_usid, &err_usid));
|
428
|
2142 else
|
853
|
2143 event_stream_delete_io_streams (p->pipe_instream,
|
|
2144 p->pipe_outstream,
|
|
2145 p->pipe_errstream,
|
|
2146 &in_usid, &err_usid);
|
428
|
2147
|
853
|
2148 if (in_usid != USID_DONTHASH)
|
|
2149 remhash ((const void*)in_usid, usid_to_process);
|
|
2150 if (err_usid != USID_DONTHASH)
|
|
2151 remhash ((const void*)err_usid, usid_to_process);
|
428
|
2152
|
|
2153 p->pipe_instream = Qnil;
|
|
2154 p->pipe_outstream = Qnil;
|
853
|
2155 p->pipe_errstream = Qnil;
|
428
|
2156 p->coding_instream = Qnil;
|
|
2157 p->coding_outstream = Qnil;
|
853
|
2158 p->coding_errstream = Qnil;
|
428
|
2159 }
|
|
2160
|
|
2161 static void
|
444
|
2162 remove_process (Lisp_Object process)
|
428
|
2163 {
|
444
|
2164 Vprocess_list = delq_no_quit (process, Vprocess_list);
|
428
|
2165
|
444
|
2166 deactivate_process (process);
|
428
|
2167 }
|
|
2168
|
|
2169 DEFUN ("delete-process", Fdelete_process, 1, 1, 0, /*
|
|
2170 Delete PROCESS: kill it and forget about it immediately.
|
|
2171 PROCESS may be a process or the name of one, or a buffer name.
|
|
2172 */
|
444
|
2173 (process))
|
428
|
2174 {
|
|
2175 /* This function can GC */
|
440
|
2176 Lisp_Process *p;
|
444
|
2177 process = get_process (process);
|
|
2178 p = XPROCESS (process);
|
|
2179 if (network_connection_p (process))
|
428
|
2180 {
|
|
2181 p->status_symbol = Qexit;
|
|
2182 p->exit_code = 0;
|
|
2183 p->core_dumped = 0;
|
|
2184 p->tick++;
|
|
2185 process_tick++;
|
|
2186 }
|
440
|
2187 else if (PROCESS_LIVE_P (p))
|
428
|
2188 {
|
444
|
2189 Fkill_process (process, Qnil);
|
428
|
2190 /* Do this now, since remove_process will make sigchld_handler do nothing. */
|
|
2191 p->status_symbol = Qsignal;
|
|
2192 p->exit_code = SIGKILL;
|
|
2193 p->core_dumped = 0;
|
|
2194 p->tick++;
|
|
2195 process_tick++;
|
|
2196 status_notify ();
|
|
2197 }
|
444
|
2198 remove_process (process);
|
428
|
2199 return Qnil;
|
|
2200 }
|
|
2201
|
|
2202 /* Kill all processes associated with `buffer'.
|
|
2203 If `buffer' is nil, kill all processes */
|
|
2204
|
|
2205 void
|
|
2206 kill_buffer_processes (Lisp_Object buffer)
|
|
2207 {
|
444
|
2208 LIST_LOOP_2 (process, Vprocess_list)
|
|
2209 if ((NILP (buffer) || EQ (XPROCESS (process)->buffer, buffer)))
|
|
2210 {
|
|
2211 if (network_connection_p (process))
|
|
2212 Fdelete_process (process);
|
|
2213 else if (PROCESS_LIVE_P (XPROCESS (process)))
|
|
2214 process_send_signal (process, SIGHUP, 0, 1);
|
|
2215 }
|
428
|
2216 }
|
|
2217
|
|
2218 DEFUN ("process-kill-without-query", Fprocess_kill_without_query, 1, 2, 0, /*
|
|
2219 Say no query needed if PROCESS is running when Emacs is exited.
|
|
2220 Optional second argument if non-nil says to require a query.
|
|
2221 Value is t if a query was formerly required.
|
|
2222 */
|
444
|
2223 (process, require_query_p))
|
428
|
2224 {
|
|
2225 int tem;
|
|
2226
|
444
|
2227 CHECK_PROCESS (process);
|
|
2228 tem = XPROCESS (process)->kill_without_query;
|
|
2229 XPROCESS (process)->kill_without_query = NILP (require_query_p);
|
428
|
2230
|
|
2231 return tem ? Qnil : Qt;
|
|
2232 }
|
|
2233
|
|
2234 DEFUN ("process-kill-without-query-p", Fprocess_kill_without_query_p, 1, 1, 0, /*
|
444
|
2235 Return t if PROCESS will be killed without query when emacs is exited.
|
428
|
2236 */
|
444
|
2237 (process))
|
428
|
2238 {
|
444
|
2239 CHECK_PROCESS (process);
|
|
2240 return XPROCESS (process)->kill_without_query ? Qt : Qnil;
|
428
|
2241 }
|
|
2242
|
|
2243
|
|
2244 #if 0
|
|
2245
|
826
|
2246 DEFUN ("process-connection", Fprocess_connection, 0, 1, 0, /*
|
428
|
2247 Return the connection type of `PROCESS'. This can be nil (pipe),
|
|
2248 t or pty (pty) or stream (socket connection).
|
|
2249 */
|
|
2250 (process))
|
|
2251 {
|
|
2252 return XPROCESS (process)->type;
|
|
2253 }
|
|
2254
|
|
2255 #endif /* 0 */
|
|
2256
|
814
|
2257
|
|
2258 static int
|
867
|
2259 getenv_internal (const Ibyte *var,
|
814
|
2260 Bytecount varlen,
|
867
|
2261 Ibyte **value,
|
814
|
2262 Bytecount *valuelen)
|
|
2263 {
|
|
2264 Lisp_Object scan;
|
|
2265
|
|
2266 assert (env_initted);
|
|
2267
|
|
2268 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
|
|
2269 {
|
|
2270 Lisp_Object entry = XCAR (scan);
|
|
2271
|
|
2272 if (STRINGP (entry)
|
|
2273 && XSTRING_LENGTH (entry) > varlen
|
826
|
2274 && string_byte (entry, varlen) == '='
|
814
|
2275 #ifdef WIN32_NATIVE
|
|
2276 /* NT environment variables are case insensitive. */
|
|
2277 && ! memicmp (XSTRING_DATA (entry), var, varlen)
|
|
2278 #else /* not WIN32_NATIVE */
|
|
2279 && ! memcmp (XSTRING_DATA (entry), var, varlen)
|
|
2280 #endif /* not WIN32_NATIVE */
|
|
2281 )
|
|
2282 {
|
|
2283 *value = XSTRING_DATA (entry) + (varlen + 1);
|
|
2284 *valuelen = XSTRING_LENGTH (entry) - (varlen + 1);
|
|
2285 return 1;
|
|
2286 }
|
|
2287 }
|
|
2288
|
|
2289 return 0;
|
|
2290 }
|
|
2291
|
|
2292 static void
|
867
|
2293 putenv_internal (const Ibyte *var,
|
814
|
2294 Bytecount varlen,
|
867
|
2295 const Ibyte *value,
|
814
|
2296 Bytecount valuelen)
|
|
2297 {
|
|
2298 Lisp_Object scan;
|
|
2299
|
|
2300 assert (env_initted);
|
|
2301
|
|
2302 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
|
|
2303 {
|
|
2304 Lisp_Object entry = XCAR (scan);
|
|
2305
|
|
2306 if (STRINGP (entry)
|
|
2307 && XSTRING_LENGTH (entry) > varlen
|
826
|
2308 && string_byte (entry, varlen) == '='
|
814
|
2309 #ifdef WIN32_NATIVE
|
|
2310 /* NT environment variables are case insensitive. */
|
|
2311 && ! memicmp (XSTRING_DATA (entry), var, varlen)
|
|
2312 #else /* not WIN32_NATIVE */
|
|
2313 && ! memcmp (XSTRING_DATA (entry), var, varlen)
|
|
2314 #endif /* not WIN32_NATIVE */
|
|
2315 )
|
|
2316 {
|
|
2317 XCAR (scan) = concat3 (make_string (var, varlen),
|
|
2318 build_string ("="),
|
|
2319 make_string (value, valuelen));
|
|
2320 return;
|
|
2321 }
|
|
2322 }
|
|
2323
|
|
2324 Vprocess_environment = Fcons (concat3 (make_string (var, varlen),
|
|
2325 build_string ("="),
|
|
2326 make_string (value, valuelen)),
|
|
2327 Vprocess_environment);
|
|
2328 }
|
|
2329
|
|
2330 /* NOTE:
|
|
2331
|
|
2332 FSF has this as a Lisp function, as follows. Generally moving things
|
|
2333 out of C and into Lisp is a good idea, but in this case the Lisp
|
|
2334 function is used so early in the startup sequence that it would be ugly
|
|
2335 to rearrange the early dumped code to accommodate this.
|
854
|
2336
|
814
|
2337 (defun getenv (variable)
|
|
2338 "Get the value of environment variable VARIABLE.
|
|
2339 VARIABLE should be a string. Value is nil if VARIABLE is undefined in
|
|
2340 the environment. Otherwise, value is a string.
|
|
2341
|
|
2342 This function consults the variable `process-environment'
|
|
2343 for its value."
|
|
2344 (interactive (list (read-envvar-name "Get environment variable: " t)))
|
|
2345 (let ((value (getenv-internal variable)))
|
|
2346 (when (interactive-p)
|
|
2347 (message "%s" (if value value "Not set")))
|
|
2348 value))
|
|
2349 */
|
|
2350
|
|
2351 DEFUN ("getenv", Fgetenv, 1, 2, "sEnvironment variable: \np", /*
|
|
2352 Return the value of environment variable VAR, as a string.
|
|
2353 VAR is a string, the name of the variable.
|
|
2354 When invoked interactively, prints the value in the echo area.
|
|
2355 */
|
|
2356 (var, interactivep))
|
|
2357 {
|
867
|
2358 Ibyte *value;
|
814
|
2359 Bytecount valuelen;
|
|
2360 Lisp_Object v = Qnil;
|
|
2361 struct gcpro gcpro1;
|
|
2362
|
|
2363 CHECK_STRING (var);
|
|
2364 GCPRO1 (v);
|
|
2365 if (getenv_internal (XSTRING_DATA (var), XSTRING_LENGTH (var),
|
|
2366 &value, &valuelen))
|
|
2367 v = make_string (value, valuelen);
|
|
2368 if (!NILP (interactivep))
|
|
2369 {
|
|
2370 if (NILP (v))
|
|
2371 message ("%s not defined in environment", XSTRING_DATA (var));
|
|
2372 else
|
|
2373 /* #### Should use Fprin1_to_string or Fprin1 to handle string
|
|
2374 containing quotes correctly. */
|
|
2375 message ("\"%s\"", value);
|
|
2376 }
|
|
2377 RETURN_UNGCPRO (v);
|
|
2378 }
|
|
2379
|
|
2380 /* A version of getenv that consults Vprocess_environment, easily
|
|
2381 callable from C.
|
|
2382
|
|
2383 (At init time, Vprocess_environment is initialized from the
|
|
2384 environment, stored in the global variable environ. [Note that
|
|
2385 at startup time, `environ' should be the same as the envp parameter
|
|
2386 passed to main(); however, later calls to putenv() may change
|
|
2387 `environ', making the envp parameter inaccurate.] Calls to getenv()
|
|
2388 and putenv() consult and modify `environ'. However, once
|
|
2389 Vprocess_environment is initted, XEmacs C code should *NEVER* call
|
|
2390 getenv() or putenv() directly, because (1) Lisp code that modifies
|
|
2391 the environment only modifies Vprocess_environment, not `environ';
|
|
2392 and (2) Vprocess_environment is in internal format but `environ'
|
|
2393 is in some external format, and getenv()/putenv() are not Mule-
|
|
2394 encapsulated.
|
|
2395
|
|
2396 WARNING: This value points into Lisp string data and thus will become
|
|
2397 invalid after a GC. */
|
|
2398
|
867
|
2399 Ibyte *
|
|
2400 egetenv (const CIbyte *var)
|
814
|
2401 {
|
|
2402 /* This cannot GC -- 7-28-00 ben */
|
867
|
2403 Ibyte *value;
|
814
|
2404 Bytecount valuelen;
|
|
2405
|
867
|
2406 if (getenv_internal ((const Ibyte *) var, strlen (var), &value, &valuelen))
|
814
|
2407 return value;
|
|
2408 else
|
|
2409 return 0;
|
|
2410 }
|
|
2411
|
|
2412 void
|
867
|
2413 eputenv (const CIbyte *var, const CIbyte *value)
|
814
|
2414 {
|
867
|
2415 putenv_internal ((Ibyte *) var, strlen (var), (Ibyte *) value,
|
814
|
2416 strlen (value));
|
|
2417 }
|
|
2418
|
|
2419
|
|
2420 /* This is not named init_process in order to avoid a conflict with NS 3.3 */
|
|
2421 void
|
|
2422 init_xemacs_process (void)
|
|
2423 {
|
|
2424 /* This function can GC */
|
|
2425
|
|
2426 MAYBE_PROCMETH (init_process, ());
|
|
2427
|
|
2428 Vprocess_list = Qnil;
|
|
2429
|
|
2430 if (usid_to_process)
|
|
2431 clrhash (usid_to_process);
|
|
2432 else
|
|
2433 usid_to_process = make_hash_table (32);
|
854
|
2434
|
814
|
2435 {
|
|
2436 /* jwz: always initialize Vprocess_environment, so that egetenv()
|
|
2437 works in temacs. */
|
|
2438 char **envp;
|
|
2439 Vprocess_environment = Qnil;
|
|
2440 for (envp = environ; envp && *envp; envp++)
|
|
2441 Vprocess_environment =
|
|
2442 Fcons (build_ext_string (*envp, Qnative), Vprocess_environment);
|
|
2443 /* This gets set back to 0 in disksave_object_finalization() */
|
|
2444 env_initted = 1;
|
|
2445 }
|
|
2446
|
|
2447 {
|
|
2448 /* Initialize shell-file-name from environment variables or best guess. */
|
|
2449 #ifdef WIN32_NATIVE
|
867
|
2450 const Ibyte *shell = egetenv ("SHELL");
|
814
|
2451 if (!shell) shell = egetenv ("COMSPEC");
|
|
2452 /* Should never happen! */
|
|
2453 if (!shell) shell =
|
867
|
2454 (Ibyte *) (GetVersion () & 0x80000000 ? "command" : "cmd");
|
814
|
2455 #else /* not WIN32_NATIVE */
|
867
|
2456 const Ibyte *shell = egetenv ("SHELL");
|
|
2457 if (!shell) shell = (Ibyte *) "/bin/sh";
|
814
|
2458 #endif
|
|
2459
|
|
2460 #if 0 /* defined (WIN32_NATIVE) */
|
|
2461 /* BAD BAD BAD. We do not wanting to be passing an XEmacs-created
|
|
2462 SHELL var down to some inferior Cygwin process, which might get
|
|
2463 screwed up.
|
854
|
2464
|
814
|
2465 There are a few broken apps (eterm/term.el, eterm/tshell.el,
|
|
2466 os-utils/terminal.el, texinfo/tex-mode.el) where this will
|
|
2467 cause problems. Those broken apps don't look at
|
|
2468 shell-file-name, instead just at explicit-shell-file-name,
|
|
2469 ESHELL and SHELL. They are apparently attempting to borrow
|
|
2470 what `M-x shell' uses, but that latter also looks at
|
|
2471 shell-file-name. What we want is for all of these apps to look
|
|
2472 at shell-file-name, so that the user can change the value of
|
|
2473 shell-file-name and everything will work out hunky-dorey.
|
|
2474 */
|
854
|
2475
|
814
|
2476 if (!egetenv ("SHELL"))
|
|
2477 {
|
867
|
2478 Ibyte *faux_var = alloca_array (Ibyte, 7 + qxestrlen (shell));
|
814
|
2479 qxesprintf (faux_var, "SHELL=%s", shell);
|
|
2480 Vprocess_environment = Fcons (build_intstring (faux_var),
|
|
2481 Vprocess_environment);
|
|
2482 }
|
|
2483 #endif /* 0 */
|
|
2484
|
|
2485 Vshell_file_name = build_intstring (shell);
|
|
2486 }
|
|
2487 }
|
|
2488
|
428
|
2489 void
|
|
2490 syms_of_process (void)
|
|
2491 {
|
442
|
2492 INIT_LRECORD_IMPLEMENTATION (process);
|
|
2493
|
563
|
2494 DEFSYMBOL (Qprocessp);
|
|
2495 DEFSYMBOL (Qprocess_live_p);
|
|
2496 DEFSYMBOL (Qrun);
|
|
2497 DEFSYMBOL (Qstop);
|
|
2498 DEFSYMBOL (Qopen);
|
|
2499 DEFSYMBOL (Qclosed);
|
863
|
2500 #if 0
|
|
2501 /* see comment at Fprocess_readable_p */
|
|
2502 DEFSYMBOL (&Qprocess_readable_p);
|
|
2503 #endif
|
563
|
2504 DEFSYMBOL (Qtcp);
|
|
2505 DEFSYMBOL (Qudp);
|
428
|
2506
|
|
2507 #ifdef HAVE_MULTICAST
|
563
|
2508 DEFSYMBOL (Qmulticast); /* Used for occasional warnings */
|
428
|
2509 #endif
|
|
2510
|
563
|
2511 DEFERROR_STANDARD (Qprocess_error, Qio_error);
|
|
2512 DEFERROR_STANDARD (Qnetwork_error, Qio_error);
|
|
2513
|
428
|
2514 DEFSUBR (Fprocessp);
|
440
|
2515 DEFSUBR (Fprocess_live_p);
|
863
|
2516 #if 0
|
|
2517 /* see comment at Fprocess_readable_p */
|
|
2518 DEFSUBR (Fprocess_readable_p);
|
|
2519 #endif
|
428
|
2520 DEFSUBR (Fget_process);
|
|
2521 DEFSUBR (Fget_buffer_process);
|
|
2522 DEFSUBR (Fdelete_process);
|
|
2523 DEFSUBR (Fprocess_status);
|
|
2524 DEFSUBR (Fprocess_exit_status);
|
|
2525 DEFSUBR (Fprocess_id);
|
|
2526 DEFSUBR (Fprocess_name);
|
|
2527 DEFSUBR (Fprocess_tty_name);
|
|
2528 DEFSUBR (Fprocess_command);
|
859
|
2529 DEFSUBR (Fprocess_has_separate_stderr_p);
|
428
|
2530 DEFSUBR (Fset_process_buffer);
|
853
|
2531 DEFSUBR (Fset_process_stderr_buffer);
|
428
|
2532 DEFSUBR (Fprocess_buffer);
|
|
2533 DEFSUBR (Fprocess_mark);
|
853
|
2534 DEFSUBR (Fprocess_stderr_buffer);
|
|
2535 DEFSUBR (Fprocess_stderr_mark);
|
428
|
2536 DEFSUBR (Fset_process_filter);
|
|
2537 DEFSUBR (Fprocess_filter);
|
853
|
2538 DEFSUBR (Fset_process_stderr_filter);
|
|
2539 DEFSUBR (Fprocess_stderr_filter);
|
428
|
2540 DEFSUBR (Fset_process_window_size);
|
|
2541 DEFSUBR (Fset_process_sentinel);
|
|
2542 DEFSUBR (Fprocess_sentinel);
|
|
2543 DEFSUBR (Fprocess_kill_without_query);
|
|
2544 DEFSUBR (Fprocess_kill_without_query_p);
|
|
2545 DEFSUBR (Fprocess_list);
|
|
2546 DEFSUBR (Fstart_process_internal);
|
|
2547 #ifdef HAVE_SOCKETS
|
|
2548 DEFSUBR (Fopen_network_stream_internal);
|
|
2549 #ifdef HAVE_MULTICAST
|
|
2550 DEFSUBR (Fopen_multicast_group_internal);
|
|
2551 #endif /* HAVE_MULTICAST */
|
|
2552 #endif /* HAVE_SOCKETS */
|
|
2553 DEFSUBR (Fprocess_send_region);
|
|
2554 DEFSUBR (Fprocess_send_string);
|
442
|
2555 DEFSUBR (Fprocess_send_signal);
|
428
|
2556 DEFSUBR (Finterrupt_process);
|
|
2557 DEFSUBR (Fkill_process);
|
|
2558 DEFSUBR (Fquit_process);
|
|
2559 DEFSUBR (Fstop_process);
|
|
2560 DEFSUBR (Fcontinue_process);
|
|
2561 DEFSUBR (Fprocess_send_eof);
|
|
2562 DEFSUBR (Fsignal_process);
|
|
2563 /* DEFSUBR (Fprocess_connection); */
|
|
2564 DEFSUBR (Fprocess_input_coding_system);
|
|
2565 DEFSUBR (Fprocess_output_coding_system);
|
|
2566 DEFSUBR (Fset_process_input_coding_system);
|
|
2567 DEFSUBR (Fset_process_output_coding_system);
|
|
2568 DEFSUBR (Fprocess_coding_system);
|
|
2569 DEFSUBR (Fset_process_coding_system);
|
814
|
2570 DEFSUBR (Fgetenv);
|
428
|
2571 }
|
|
2572
|
|
2573 void
|
|
2574 vars_of_process (void)
|
|
2575 {
|
|
2576 Fprovide (intern ("subprocesses"));
|
|
2577 #ifdef HAVE_SOCKETS
|
|
2578 Fprovide (intern ("network-streams"));
|
|
2579 #ifdef HAVE_MULTICAST
|
|
2580 Fprovide (intern ("multicast"));
|
|
2581 #endif /* HAVE_MULTICAST */
|
|
2582 #endif /* HAVE_SOCKETS */
|
|
2583 staticpro (&Vprocess_list);
|
|
2584
|
|
2585 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes /*
|
|
2586 *Non-nil means delete processes immediately when they exit.
|
|
2587 nil means don't delete them until `list-processes' is run.
|
|
2588 */ );
|
|
2589
|
|
2590 delete_exited_processes = 1;
|
|
2591
|
442
|
2592 DEFVAR_CONST_LISP ("null-device", &Vnull_device /*
|
|
2593 Name of the null device, which differs from system to system.
|
|
2594 The null device is a filename that acts as a sink for arbitrary amounts of
|
|
2595 data, which is discarded, or as a source for a zero-length file.
|
|
2596 It is available on all the systems that we currently support, but with
|
|
2597 different names (typically either `/dev/null' or `nul').
|
|
2598
|
|
2599 Note that there is also a /dev/zero on most modern Unix versions (including
|
|
2600 Cygwin), which acts like /dev/null when used as a sink, but as a source
|
|
2601 it sends a non-ending stream of zero bytes. It's used most often along
|
|
2602 with memory-mapping. We don't provide a Lisp variable for this because
|
|
2603 the operations needing this are lower level than what ELisp programs
|
|
2604 typically do, and in any case no equivalent exists under native MS Windows.
|
|
2605 */ );
|
|
2606 Vnull_device = build_string (NULL_DEVICE);
|
|
2607
|
428
|
2608 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type /*
|
|
2609 Control type of device used to communicate with subprocesses.
|
|
2610 Values are nil to use a pipe, or t or `pty' to use a pty.
|
|
2611 The value has no effect if the system has no ptys or if all ptys are busy:
|
|
2612 then a pipe is used in any case.
|
|
2613 The value takes effect when `start-process' is called.
|
|
2614 */ );
|
|
2615 Vprocess_connection_type = Qt;
|
|
2616
|
|
2617 DEFVAR_BOOL ("windowed-process-io", &windowed_process_io /*
|
|
2618 Enables input/output on standard handles of a windowed process.
|
|
2619 When this variable is nil (the default), XEmacs does not attempt to read
|
|
2620 standard output handle of a windowed process. Instead, the process is
|
|
2621 immediately marked as exited immediately upon successful launching. This is
|
|
2622 done because normal windowed processes do not use standard I/O, as they are
|
|
2623 not connected to any console.
|
|
2624
|
|
2625 When launching a specially crafted windowed process, which expects to be
|
|
2626 launched by XEmacs, or by other program which pipes its standard input and
|
|
2627 output, this variable must be set to non-nil, in which case XEmacs will
|
|
2628 treat this process just like a console process.
|
|
2629
|
|
2630 NOTE: You should never set this variable, only bind it.
|
|
2631
|
|
2632 Only Windows processes can be "windowed" or "console". This variable has no
|
|
2633 effect on UNIX processes, because all UNIX processes are "console".
|
|
2634 */ );
|
|
2635 windowed_process_io = 0;
|
|
2636
|
771
|
2637 DEFVAR_INT ("debug-process-io", &debug_process_io /*
|
|
2638 If non-zero, display data sent to or received from a process.
|
|
2639 */ );
|
|
2640 debug_process_io = 0;
|
|
2641
|
|
2642 DEFVAR_LISP ("default-process-coding-system",
|
|
2643 &Vdefault_process_coding_system /*
|
|
2644 Cons of coding systems used for process I/O by default.
|
|
2645 The car part is used for reading (decoding) data from a process, and
|
|
2646 the cdr part is used for writing (encoding) data to a process.
|
|
2647 */ );
|
|
2648 /* This below will get its default set correctly in code-init.el. */
|
|
2649 Vdefault_process_coding_system = Fcons (Qundecided, Qnil);
|
|
2650
|
853
|
2651 DEFVAR_LISP ("default-network-coding-system",
|
|
2652 &Vdefault_network_coding_system /*
|
|
2653 Cons of coding systems used for network I/O by default.
|
|
2654 The car part is used for reading (decoding) data from a process, and
|
|
2655 the cdr part is used for writing (encoding) data to a process.
|
|
2656 */ );
|
|
2657 Vdefault_network_coding_system = Fcons (Qundecided, Qnil);
|
|
2658
|
428
|
2659 #ifdef PROCESS_IO_BLOCKING
|
|
2660 DEFVAR_LISP ("network-stream-blocking-port-list", &network_stream_blocking_port_list /*
|
|
2661 List of port numbers or port names to set a blocking I/O mode with connection.
|
862
|
2662 Nil value means to set a default (non-blocking) I/O mode.
|
428
|
2663 The value takes effect when `open-network-stream-internal' is called.
|
|
2664 */ );
|
|
2665 network_stream_blocking_port_list = Qnil;
|
|
2666 #endif /* PROCESS_IO_BLOCKING */
|
814
|
2667
|
|
2668 /* This function can GC */
|
|
2669 DEFVAR_LISP ("shell-file-name", &Vshell_file_name /*
|
|
2670 *File name to load inferior shells from.
|
|
2671 Initialized from the SHELL environment variable.
|
|
2672 */ );
|
428
|
2673
|
814
|
2674 DEFVAR_LISP ("process-environment", &Vprocess_environment /*
|
|
2675 List of environment variables for subprocesses to inherit.
|
|
2676 Each element should be a string of the form ENVVARNAME=VALUE.
|
|
2677 The environment which Emacs inherits is placed in this variable
|
|
2678 when Emacs starts.
|
|
2679 */ );
|
|
2680
|
|
2681 Vlisp_EXEC_SUFFIXES = build_string (EXEC_SUFFIXES);
|
|
2682 staticpro (&Vlisp_EXEC_SUFFIXES);
|
|
2683 }
|