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