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