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