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