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