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