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