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