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