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
|
|
871 /* Read pending output from the process channel,
|
|
872 starting with our buffered-ahead character if we have one.
|
|
873 Yield number of characters read.
|
|
874
|
|
875 This function reads at most 1024 bytes.
|
|
876 If you want to read all available subprocess output,
|
|
877 you must call it repeatedly until it returns zero. */
|
|
878
|
|
879 Charcount
|
444
|
880 read_process_output (Lisp_Object process)
|
428
|
881 {
|
|
882 /* This function can GC */
|
|
883 Bytecount nbytes, nchars;
|
771
|
884 Intbyte chars[1025];
|
428
|
885 Lisp_Object outstream;
|
444
|
886 Lisp_Process *p = XPROCESS (process);
|
428
|
887
|
|
888 /* If there is a lot of output from the subprocess, the loop in
|
|
889 execute_internal_event() might call read_process_output() more
|
|
890 than once. If the filter that was executed from one of these
|
|
891 calls set the filter to t, we have to stop now. Return -1 rather
|
|
892 than 0 so execute_internal_event() doesn't close the process.
|
|
893 Really, the loop in execute_internal_event() should check itself
|
|
894 for a process-filter change, like in status_notify(); but the
|
|
895 struct Lisp_Process is not exported outside of this file. */
|
440
|
896 if (!PROCESS_LIVE_P (p))
|
428
|
897 return -1; /* already closed */
|
|
898
|
|
899 if (!NILP (p->filter) && (p->filter_does_read))
|
|
900 {
|
|
901 Lisp_Object filter_result;
|
|
902
|
|
903 /* Some weird FSFmacs crap here with
|
|
904 Vdeactivate_mark and current_buffer->keymap */
|
|
905 running_asynch_code = 1;
|
|
906 filter_result = call2_trapping_errors ("Error in process filter",
|
444
|
907 p->filter, process, Qnil);
|
428
|
908 running_asynch_code = 0;
|
|
909 restore_match_data ();
|
|
910 CHECK_INT (filter_result);
|
|
911 return XINT (filter_result);
|
|
912 }
|
|
913
|
771
|
914 nbytes = Lstream_read (XLSTREAM (DATA_INSTREAM (p)), chars,
|
|
915 sizeof (chars) - 1);
|
428
|
916 if (nbytes <= 0) return nbytes;
|
|
917
|
771
|
918 if (debug_process_io)
|
|
919 {
|
|
920 chars[nbytes] = '\0';
|
|
921 stderr_out ("Read: %s\n", chars);
|
|
922 }
|
|
923
|
|
924 /* !!#### if the coding system changed as a result of reading, we
|
|
925 need to change the output coding system accordingly. */
|
428
|
926 nchars = bytecount_to_charcount (chars, nbytes);
|
|
927 outstream = p->filter;
|
|
928 if (!NILP (outstream))
|
|
929 {
|
|
930 /* We used to bind inhibit-quit to t here, but
|
|
931 call2_trapping_errors() does that for us. */
|
|
932 running_asynch_code = 1;
|
|
933 call2_trapping_errors ("Error in process filter",
|
444
|
934 outstream, process, make_string (chars, nbytes));
|
428
|
935 running_asynch_code = 0;
|
|
936 restore_match_data ();
|
|
937 return nchars;
|
|
938 }
|
|
939
|
|
940 /* If no filter, write into buffer if it isn't dead. */
|
|
941 if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer)))
|
|
942 {
|
|
943 Lisp_Object old_read_only = Qnil;
|
665
|
944 Charbpos old_point;
|
|
945 Charbpos old_begv;
|
|
946 Charbpos old_zv;
|
428
|
947 struct gcpro gcpro1, gcpro2;
|
|
948 struct buffer *buf = XBUFFER (p->buffer);
|
|
949
|
444
|
950 GCPRO2 (process, old_read_only);
|
428
|
951
|
|
952 old_point = BUF_PT (buf);
|
|
953 old_begv = BUF_BEGV (buf);
|
|
954 old_zv = BUF_ZV (buf);
|
|
955 old_read_only = buf->read_only;
|
|
956 buf->read_only = Qnil;
|
|
957
|
|
958 /* Insert new output into buffer
|
|
959 at the current end-of-output marker,
|
|
960 thus preserving logical ordering of input and output. */
|
|
961 if (XMARKER (p->mark)->buffer)
|
|
962 BUF_SET_PT (buf,
|
665
|
963 charbpos_clip_to_bounds (old_begv, marker_position (p->mark),
|
428
|
964 old_zv));
|
|
965 else
|
|
966 BUF_SET_PT (buf, old_zv);
|
|
967
|
|
968 /* If the output marker is outside of the visible region, save
|
|
969 the restriction and widen. */
|
|
970 if (! (BUF_BEGV (buf) <= BUF_PT (buf) &&
|
|
971 BUF_PT (buf) <= BUF_ZV (buf)))
|
|
972 Fwiden (p->buffer);
|
|
973
|
|
974 /* Make sure opoint floats ahead of any new text, just as point
|
|
975 would. */
|
|
976 if (BUF_PT (buf) <= old_point)
|
|
977 old_point += nchars;
|
|
978
|
|
979 /* Insert after old_begv, but before old_zv. */
|
|
980 if (BUF_PT (buf) < old_begv)
|
|
981 old_begv += nchars;
|
|
982 if (BUF_PT (buf) <= old_zv)
|
|
983 old_zv += nchars;
|
|
984
|
|
985 #if 0
|
|
986 /* This screws up initial display of the window. jla */
|
|
987
|
|
988 /* Insert before markers in case we are inserting where
|
|
989 the buffer's mark is, and the user's next command is Meta-y. */
|
|
990 buffer_insert_raw_string_1 (buf, -1, chars,
|
|
991 nbytes, INSDEL_BEFORE_MARKERS);
|
|
992 #else
|
|
993 buffer_insert_raw_string (buf, chars, nbytes);
|
|
994 #endif
|
|
995
|
|
996 Fset_marker (p->mark, make_int (BUF_PT (buf)), p->buffer);
|
|
997
|
|
998 MARK_MODELINE_CHANGED;
|
|
999
|
|
1000 /* If the restriction isn't what it should be, set it. */
|
|
1001 if (old_begv != BUF_BEGV (buf) || old_zv != BUF_ZV (buf))
|
|
1002 {
|
|
1003 Fwiden(p->buffer);
|
665
|
1004 old_begv = charbpos_clip_to_bounds (BUF_BEG (buf),
|
428
|
1005 old_begv,
|
|
1006 BUF_Z (buf));
|
665
|
1007 old_zv = charbpos_clip_to_bounds (BUF_BEG (buf),
|
428
|
1008 old_zv,
|
|
1009 BUF_Z (buf));
|
|
1010 Fnarrow_to_region (make_int (old_begv), make_int (old_zv),
|
|
1011 p->buffer);
|
|
1012 }
|
|
1013
|
|
1014 buf->read_only = old_read_only;
|
665
|
1015 old_point = charbpos_clip_to_bounds (BUF_BEGV (buf),
|
428
|
1016 old_point,
|
|
1017 BUF_ZV (buf));
|
|
1018 BUF_SET_PT (buf, old_point);
|
|
1019
|
|
1020 UNGCPRO;
|
|
1021 }
|
|
1022 return nchars;
|
|
1023 }
|
|
1024
|
|
1025 /* Sending data to subprocess */
|
|
1026
|
444
|
1027 /* send some data to process PROCESS. If NONRELOCATABLE is non-NULL, it
|
428
|
1028 specifies the address of the data. Otherwise, the data comes from the
|
|
1029 object RELOCATABLE (either a string or a buffer). START and LEN
|
|
1030 specify the offset and length of the data to send.
|
|
1031
|
665
|
1032 Note that START and LEN are in Charbpos's if RELOCATABLE is a buffer,
|
428
|
1033 and in Bytecounts otherwise. */
|
|
1034
|
|
1035 void
|
444
|
1036 send_process (Lisp_Object process,
|
665
|
1037 Lisp_Object relocatable, const Intbyte *nonrelocatable,
|
428
|
1038 int start, int len)
|
|
1039 {
|
|
1040 /* This function can GC */
|
|
1041 struct gcpro gcpro1, gcpro2;
|
|
1042 Lisp_Object lstream = Qnil;
|
|
1043
|
444
|
1044 GCPRO2 (process, lstream);
|
428
|
1045
|
444
|
1046 if (NILP (DATA_OUTSTREAM (XPROCESS (process))))
|
563
|
1047 invalid_operation ("Process not open for writing", process);
|
428
|
1048
|
|
1049 if (nonrelocatable)
|
|
1050 lstream =
|
|
1051 make_fixed_buffer_input_stream (nonrelocatable + start, len);
|
|
1052 else if (BUFFERP (relocatable))
|
|
1053 lstream = make_lisp_buffer_input_stream (XBUFFER (relocatable),
|
|
1054 start, start + len, 0);
|
|
1055 else
|
|
1056 lstream = make_lisp_string_input_stream (relocatable, start, len);
|
|
1057
|
771
|
1058 if (debug_process_io)
|
|
1059 {
|
|
1060 if (nonrelocatable)
|
|
1061 stderr_out ("Writing: %s\n", nonrelocatable);
|
|
1062 else
|
|
1063 {
|
|
1064 stderr_out ("Writing: ");
|
|
1065 print_internal (relocatable, Qexternal_debugging_output, 0);
|
|
1066 }
|
|
1067 }
|
|
1068
|
444
|
1069 PROCMETH (send_process, (process, XLSTREAM (lstream)));
|
428
|
1070
|
|
1071 UNGCPRO;
|
|
1072 Lstream_delete (XLSTREAM (lstream));
|
|
1073 }
|
|
1074
|
|
1075 DEFUN ("process-tty-name", Fprocess_tty_name, 1, 1, 0, /*
|
|
1076 Return the name of the terminal PROCESS uses, or nil if none.
|
|
1077 This is the terminal that the process itself reads and writes on,
|
|
1078 not the name of the pty that Emacs uses to talk with that terminal.
|
|
1079 */
|
444
|
1080 (process))
|
428
|
1081 {
|
444
|
1082 CHECK_PROCESS (process);
|
|
1083 return MAYBE_LISP_PROCMETH (get_tty_name, (XPROCESS (process)));
|
428
|
1084 }
|
|
1085
|
|
1086 DEFUN ("set-process-buffer", Fset_process_buffer, 2, 2, 0, /*
|
|
1087 Set buffer associated with PROCESS to BUFFER (a buffer, or nil).
|
|
1088 */
|
444
|
1089 (process, buffer))
|
428
|
1090 {
|
444
|
1091 CHECK_PROCESS (process);
|
428
|
1092 if (!NILP (buffer))
|
|
1093 CHECK_BUFFER (buffer);
|
444
|
1094 XPROCESS (process)->buffer = buffer;
|
428
|
1095 return buffer;
|
|
1096 }
|
|
1097
|
|
1098 DEFUN ("process-buffer", Fprocess_buffer, 1, 1, 0, /*
|
|
1099 Return the buffer PROCESS is associated with.
|
|
1100 Output from PROCESS is inserted in this buffer
|
|
1101 unless PROCESS has a filter.
|
|
1102 */
|
444
|
1103 (process))
|
428
|
1104 {
|
444
|
1105 CHECK_PROCESS (process);
|
|
1106 return XPROCESS (process)->buffer;
|
428
|
1107 }
|
|
1108
|
|
1109 DEFUN ("process-mark", Fprocess_mark, 1, 1, 0, /*
|
|
1110 Return the marker for the end of the last output from PROCESS.
|
|
1111 */
|
444
|
1112 (process))
|
428
|
1113 {
|
444
|
1114 CHECK_PROCESS (process);
|
|
1115 return XPROCESS (process)->mark;
|
428
|
1116 }
|
|
1117
|
|
1118 void
|
444
|
1119 set_process_filter (Lisp_Object process, Lisp_Object filter, int filter_does_read)
|
428
|
1120 {
|
444
|
1121 CHECK_PROCESS (process);
|
|
1122 if (PROCESS_LIVE_P (XPROCESS (process))) {
|
428
|
1123 if (EQ (filter, Qt))
|
444
|
1124 event_stream_unselect_process (XPROCESS (process));
|
428
|
1125 else
|
444
|
1126 event_stream_select_process (XPROCESS (process));
|
428
|
1127 }
|
|
1128
|
444
|
1129 XPROCESS (process)->filter = filter;
|
|
1130 XPROCESS (process)->filter_does_read = filter_does_read;
|
428
|
1131 }
|
|
1132
|
|
1133 DEFUN ("set-process-filter", Fset_process_filter, 2, 2, 0, /*
|
|
1134 Give PROCESS the filter function FILTER; nil means no filter.
|
|
1135 t means stop accepting output from the process.
|
|
1136 When a process has a filter, each time it does output
|
|
1137 the entire string of output is passed to the filter.
|
|
1138 The filter gets two arguments: the process and the string of output.
|
|
1139 If the process has a filter, its buffer is not used for output.
|
|
1140 */
|
444
|
1141 (process, filter))
|
428
|
1142 {
|
444
|
1143 set_process_filter (process, filter, 0);
|
428
|
1144 return filter;
|
|
1145 }
|
|
1146
|
|
1147 DEFUN ("process-filter", Fprocess_filter, 1, 1, 0, /*
|
|
1148 Return the filter function of PROCESS; nil if none.
|
|
1149 See `set-process-filter' for more info on filter functions.
|
|
1150 */
|
444
|
1151 (process))
|
428
|
1152 {
|
444
|
1153 CHECK_PROCESS (process);
|
|
1154 return XPROCESS (process)->filter;
|
428
|
1155 }
|
|
1156
|
442
|
1157 DEFUN ("process-send-region", Fprocess_send_region, 3, 4, 0, /*
|
|
1158 Send current contents of the region between START and END as input to PROCESS.
|
444
|
1159 PROCESS may be a process or the name of a process, or a buffer or the
|
|
1160 name of a buffer, in which case the buffer's process is used. If it
|
|
1161 is nil, the current buffer's process is used.
|
442
|
1162 BUFFER specifies the buffer to look in; if nil, the current buffer is used.
|
444
|
1163 If STRING is more than 100 or so characters long, it may be sent in
|
|
1164 several chunks. This may happen even for shorter strings. Output
|
|
1165 from processes can arrive in between chunks.
|
428
|
1166 */
|
442
|
1167 (process, start, end, buffer))
|
428
|
1168 {
|
|
1169 /* This function can GC */
|
665
|
1170 Charbpos bstart, bend;
|
442
|
1171 struct buffer *buf = decode_buffer (buffer, 0);
|
428
|
1172
|
793
|
1173 buffer = wrap_buffer (buf);
|
444
|
1174 process = get_process (process);
|
|
1175 get_buffer_range_char (buf, start, end, &bstart, &bend, 0);
|
442
|
1176
|
444
|
1177 send_process (process, buffer, 0, bstart, bend - bstart);
|
428
|
1178 return Qnil;
|
|
1179 }
|
|
1180
|
|
1181 DEFUN ("process-send-string", Fprocess_send_string, 2, 4, 0, /*
|
|
1182 Send PROCESS the contents of STRING as input.
|
444
|
1183 PROCESS may be a process or the name of a process, or a buffer or the
|
|
1184 name of a buffer, in which case the buffer's process is used. If it
|
|
1185 is nil, the current buffer's process is used.
|
|
1186 Optional arguments START and END specify part of STRING; see `substring'.
|
|
1187 If STRING is more than 100 or so characters long, it may be sent in
|
|
1188 several chunks. This may happen even for shorter strings. Output
|
|
1189 from processes can arrive in between chunks.
|
428
|
1190 */
|
444
|
1191 (process, string, start, end))
|
428
|
1192 {
|
|
1193 /* This function can GC */
|
444
|
1194 Bytecount bstart, bend;
|
428
|
1195
|
444
|
1196 process = get_process (process);
|
428
|
1197 CHECK_STRING (string);
|
444
|
1198 get_string_range_byte (string, start, end, &bstart, &bend,
|
428
|
1199 GB_HISTORICAL_STRING_BEHAVIOR);
|
|
1200
|
444
|
1201 send_process (process, string, 0, bstart, bend - bstart);
|
428
|
1202 return Qnil;
|
|
1203 }
|
|
1204
|
|
1205
|
|
1206 DEFUN ("process-input-coding-system", Fprocess_input_coding_system, 1, 1, 0, /*
|
|
1207 Return PROCESS's input coding system.
|
|
1208 */
|
|
1209 (process))
|
|
1210 {
|
|
1211 process = get_process (process);
|
440
|
1212 CHECK_LIVE_PROCESS (process);
|
771
|
1213 return (coding_stream_detected_coding_system
|
|
1214 (XLSTREAM (XPROCESS (process)->coding_instream)));
|
428
|
1215 }
|
|
1216
|
|
1217 DEFUN ("process-output-coding-system", Fprocess_output_coding_system, 1, 1, 0, /*
|
|
1218 Return PROCESS's output coding system.
|
|
1219 */
|
|
1220 (process))
|
|
1221 {
|
|
1222 process = get_process (process);
|
440
|
1223 CHECK_LIVE_PROCESS (process);
|
771
|
1224 return (coding_stream_coding_system
|
|
1225 (XLSTREAM (XPROCESS (process)->coding_outstream)));
|
428
|
1226 }
|
|
1227
|
|
1228 DEFUN ("process-coding-system", Fprocess_coding_system, 1, 1, 0, /*
|
|
1229 Return a pair of coding-system for decoding and encoding of PROCESS.
|
|
1230 */
|
|
1231 (process))
|
|
1232 {
|
|
1233 process = get_process (process);
|
440
|
1234 CHECK_LIVE_PROCESS (process);
|
771
|
1235 return Fcons (coding_stream_detected_coding_system
|
428
|
1236 (XLSTREAM (XPROCESS (process)->coding_instream)),
|
771
|
1237 coding_stream_coding_system
|
428
|
1238 (XLSTREAM (XPROCESS (process)->coding_outstream)));
|
|
1239 }
|
|
1240
|
|
1241 DEFUN ("set-process-input-coding-system", Fset_process_input_coding_system,
|
|
1242 2, 2, 0, /*
|
|
1243 Set PROCESS's input coding system to CODESYS.
|
771
|
1244 This is used for reading data from PROCESS.
|
428
|
1245 */
|
|
1246 (process, codesys))
|
|
1247 {
|
771
|
1248 codesys = get_coding_system_for_text_file (codesys, 1);
|
428
|
1249 process = get_process (process);
|
440
|
1250 CHECK_LIVE_PROCESS (process);
|
|
1251
|
771
|
1252 set_coding_stream_coding_system
|
428
|
1253 (XLSTREAM (XPROCESS (process)->coding_instream), codesys);
|
|
1254 return Qnil;
|
|
1255 }
|
|
1256
|
|
1257 DEFUN ("set-process-output-coding-system", Fset_process_output_coding_system,
|
|
1258 2, 2, 0, /*
|
|
1259 Set PROCESS's output coding system to CODESYS.
|
771
|
1260 This is used for writing data to PROCESS.
|
428
|
1261 */
|
|
1262 (process, codesys))
|
|
1263 {
|
771
|
1264 codesys = get_coding_system_for_text_file (codesys, 0);
|
428
|
1265 process = get_process (process);
|
440
|
1266 CHECK_LIVE_PROCESS (process);
|
|
1267
|
771
|
1268 set_coding_stream_coding_system
|
428
|
1269 (XLSTREAM (XPROCESS (process)->coding_outstream), codesys);
|
|
1270 return Qnil;
|
|
1271 }
|
|
1272
|
|
1273 DEFUN ("set-process-coding-system", Fset_process_coding_system,
|
|
1274 1, 3, 0, /*
|
|
1275 Set coding-systems of PROCESS to DECODING and ENCODING.
|
440
|
1276 DECODING will be used to decode subprocess output and ENCODING to
|
|
1277 encode subprocess input.
|
428
|
1278 */
|
|
1279 (process, decoding, encoding))
|
|
1280 {
|
|
1281 if (!NILP (decoding))
|
|
1282 Fset_process_input_coding_system (process, decoding);
|
|
1283
|
|
1284 if (!NILP (encoding))
|
|
1285 Fset_process_output_coding_system (process, encoding);
|
|
1286
|
|
1287 return Qnil;
|
|
1288 }
|
|
1289
|
|
1290
|
|
1291 /************************************************************************/
|
|
1292 /* process status */
|
|
1293 /************************************************************************/
|
|
1294
|
|
1295 static Lisp_Object
|
|
1296 exec_sentinel_unwind (Lisp_Object datum)
|
|
1297 {
|
440
|
1298 Lisp_Cons *d = XCONS (datum);
|
428
|
1299 XPROCESS (d->car)->sentinel = d->cdr;
|
|
1300 free_cons (d);
|
|
1301 return Qnil;
|
|
1302 }
|
|
1303
|
|
1304 static void
|
444
|
1305 exec_sentinel (Lisp_Object process, Lisp_Object reason)
|
428
|
1306 {
|
|
1307 /* This function can GC */
|
|
1308 int speccount = specpdl_depth ();
|
444
|
1309 Lisp_Process *p = XPROCESS (process);
|
428
|
1310 Lisp_Object sentinel = p->sentinel;
|
|
1311
|
|
1312 if (NILP (sentinel))
|
|
1313 return;
|
|
1314
|
|
1315 /* Some weird FSFmacs crap here with
|
|
1316 Vdeactivate_mark and current_buffer->keymap */
|
|
1317
|
|
1318 /* Zilch the sentinel while it's running, to avoid recursive invocations;
|
|
1319 assure that it gets restored no matter how the sentinel exits. */
|
|
1320 p->sentinel = Qnil;
|
444
|
1321 record_unwind_protect (exec_sentinel_unwind, noseeum_cons (process, sentinel));
|
428
|
1322 /* We used to bind inhibit-quit to t here, but call2_trapping_errors()
|
|
1323 does that for us. */
|
|
1324 running_asynch_code = 1;
|
444
|
1325 call2_trapping_errors ("Error in process sentinel", sentinel, process, reason);
|
428
|
1326 running_asynch_code = 0;
|
|
1327 restore_match_data ();
|
771
|
1328 unbind_to (speccount);
|
428
|
1329 }
|
|
1330
|
|
1331 DEFUN ("set-process-sentinel", Fset_process_sentinel, 2, 2, 0, /*
|
|
1332 Give PROCESS the sentinel SENTINEL; nil for none.
|
|
1333 The sentinel is called as a function when the process changes state.
|
|
1334 It gets two arguments: the process, and a string describing the change.
|
|
1335 */
|
444
|
1336 (process, sentinel))
|
428
|
1337 {
|
444
|
1338 CHECK_PROCESS (process);
|
|
1339 XPROCESS (process)->sentinel = sentinel;
|
428
|
1340 return sentinel;
|
|
1341 }
|
|
1342
|
|
1343 DEFUN ("process-sentinel", Fprocess_sentinel, 1, 1, 0, /*
|
|
1344 Return the sentinel of PROCESS; nil if none.
|
|
1345 See `set-process-sentinel' for more info on sentinels.
|
|
1346 */
|
444
|
1347 (process))
|
428
|
1348 {
|
444
|
1349 CHECK_PROCESS (process);
|
|
1350 return XPROCESS (process)->sentinel;
|
428
|
1351 }
|
|
1352
|
|
1353
|
442
|
1354 const char *
|
428
|
1355 signal_name (int signum)
|
|
1356 {
|
|
1357 if (signum >= 0 && signum < NSIG)
|
442
|
1358 return (const char *) sys_siglist[signum];
|
428
|
1359
|
442
|
1360 return (const char *) GETTEXT ("unknown signal");
|
428
|
1361 }
|
|
1362
|
|
1363 void
|
|
1364 update_process_status (Lisp_Object p,
|
|
1365 Lisp_Object status_symbol,
|
|
1366 int exit_code,
|
|
1367 int core_dumped)
|
|
1368 {
|
|
1369 XPROCESS (p)->tick++;
|
|
1370 process_tick++;
|
|
1371 XPROCESS (p)->status_symbol = status_symbol;
|
|
1372 XPROCESS (p)->exit_code = exit_code;
|
|
1373 XPROCESS (p)->core_dumped = core_dumped;
|
|
1374 }
|
|
1375
|
|
1376 /* Return a string describing a process status list. */
|
|
1377
|
|
1378 static Lisp_Object
|
440
|
1379 status_message (Lisp_Process *p)
|
428
|
1380 {
|
|
1381 Lisp_Object symbol = p->status_symbol;
|
|
1382 int code = p->exit_code;
|
|
1383 int coredump = p->core_dumped;
|
|
1384 Lisp_Object string, string2;
|
|
1385
|
|
1386 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
|
|
1387 {
|
|
1388 string = build_string (signal_name (code));
|
|
1389 if (coredump)
|
771
|
1390 string2 = build_msg_string (" (core dumped)\n");
|
428
|
1391 else
|
|
1392 string2 = build_string ("\n");
|
793
|
1393 set_string_char (string, 0,
|
826
|
1394 DOWNCASE (0, string_emchar (string, 0)));
|
428
|
1395 return concat2 (string, string2);
|
|
1396 }
|
|
1397 else if (EQ (symbol, Qexit))
|
|
1398 {
|
|
1399 if (code == 0)
|
771
|
1400 return build_msg_string ("finished\n");
|
428
|
1401 string = Fnumber_to_string (make_int (code));
|
|
1402 if (coredump)
|
771
|
1403 string2 = build_msg_string (" (core dumped)\n");
|
428
|
1404 else
|
|
1405 string2 = build_string ("\n");
|
771
|
1406 return concat2 (build_msg_string ("exited abnormally with code "),
|
428
|
1407 concat2 (string, string2));
|
|
1408 }
|
|
1409 else
|
|
1410 return Fcopy_sequence (Fsymbol_name (symbol));
|
|
1411 }
|
|
1412
|
|
1413 /* Tell status_notify() to check for terminated processes. We do this
|
|
1414 because on some systems we sometimes miss SIGCHLD calls. (Not sure
|
|
1415 why.) */
|
|
1416
|
|
1417 void
|
|
1418 kick_status_notify (void)
|
|
1419 {
|
|
1420 process_tick++;
|
|
1421 }
|
|
1422
|
|
1423
|
|
1424 /* Report all recent events of a change in process status
|
|
1425 (either run the sentinel or output a message).
|
|
1426 This is done while Emacs is waiting for keyboard input. */
|
|
1427
|
|
1428 void
|
|
1429 status_notify (void)
|
|
1430 {
|
|
1431 /* This function can GC */
|
|
1432 Lisp_Object tail = Qnil;
|
|
1433 Lisp_Object symbol = Qnil;
|
|
1434 Lisp_Object msg = Qnil;
|
|
1435 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1436 /* process_tick is volatile, so we have to remember it now.
|
444
|
1437 Otherwise, we get a race condition if SIGCHLD happens during
|
428
|
1438 this function.
|
|
1439
|
|
1440 (Actually, this is not the case anymore. The code to
|
|
1441 update the process structures has been moved out of the
|
|
1442 SIGCHLD handler. But for the moment I'm leaving this
|
|
1443 stuff in -- it can't hurt.) */
|
|
1444 int temp_process_tick;
|
|
1445
|
|
1446 MAYBE_PROCMETH (reap_exited_processes, ());
|
|
1447
|
|
1448 temp_process_tick = process_tick;
|
|
1449
|
|
1450 if (update_tick == temp_process_tick)
|
|
1451 return;
|
|
1452
|
|
1453 /* We need to gcpro tail; if read_process_output calls a filter
|
|
1454 which deletes a process and removes the cons to which tail points
|
|
1455 from Vprocess_alist, and then causes a GC, tail is an unprotected
|
|
1456 reference. */
|
|
1457 GCPRO3 (tail, symbol, msg);
|
|
1458
|
|
1459 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
|
|
1460 {
|
444
|
1461 Lisp_Object process = XCAR (tail);
|
|
1462 Lisp_Process *p = XPROCESS (process);
|
428
|
1463 /* p->tick is also volatile. Same thing as above applies. */
|
|
1464 int this_process_tick;
|
|
1465
|
|
1466 /* #### extra check for terminated processes, in case a SIGCHLD
|
|
1467 got missed (this seems to happen sometimes, I'm not sure why).
|
|
1468 */
|
|
1469 if (INTP (p->pid))
|
|
1470 MAYBE_PROCMETH (update_status_if_terminated, (p));
|
|
1471
|
|
1472 this_process_tick = p->tick;
|
|
1473 if (this_process_tick != p->update_tick)
|
|
1474 {
|
|
1475 p->update_tick = this_process_tick;
|
|
1476
|
|
1477 /* If process is still active, read any output that remains. */
|
|
1478 while (!EQ (p->filter, Qt)
|
444
|
1479 && read_process_output (process) > 0)
|
428
|
1480 ;
|
|
1481
|
|
1482 /* Get the text to use for the message. */
|
|
1483 msg = status_message (p);
|
|
1484
|
|
1485 /* If process is terminated, deactivate it or delete it. */
|
|
1486 symbol = p->status_symbol;
|
|
1487
|
|
1488 if (EQ (symbol, Qsignal)
|
|
1489 || EQ (symbol, Qexit))
|
|
1490 {
|
|
1491 if (delete_exited_processes)
|
444
|
1492 remove_process (process);
|
428
|
1493 else
|
444
|
1494 deactivate_process (process);
|
428
|
1495 }
|
|
1496
|
|
1497 /* Now output the message suitably. */
|
|
1498 if (!NILP (p->sentinel))
|
444
|
1499 exec_sentinel (process, msg);
|
428
|
1500 /* Don't bother with a message in the buffer
|
|
1501 when a process becomes runnable. */
|
|
1502 else if (!EQ (symbol, Qrun) && !NILP (p->buffer))
|
|
1503 {
|
|
1504 Lisp_Object old_read_only = Qnil;
|
|
1505 Lisp_Object old = Fcurrent_buffer ();
|
665
|
1506 Charbpos opoint;
|
428
|
1507 struct gcpro ngcpro1, ngcpro2;
|
|
1508
|
|
1509 /* Avoid error if buffer is deleted
|
|
1510 (probably that's why the process is dead, too) */
|
|
1511 if (!BUFFER_LIVE_P (XBUFFER (p->buffer)))
|
|
1512 continue;
|
|
1513
|
|
1514 NGCPRO2 (old, old_read_only);
|
|
1515 Fset_buffer (p->buffer);
|
|
1516 opoint = BUF_PT (current_buffer);
|
|
1517 /* Insert new output into buffer
|
|
1518 at the current end-of-output marker,
|
|
1519 thus preserving logical ordering of input and output. */
|
|
1520 if (XMARKER (p->mark)->buffer)
|
|
1521 BUF_SET_PT (current_buffer, marker_position (p->mark));
|
|
1522 else
|
|
1523 BUF_SET_PT (current_buffer, BUF_ZV (current_buffer));
|
|
1524 if (BUF_PT (current_buffer) <= opoint)
|
826
|
1525 opoint += (string_char_length (msg)
|
|
1526 + string_char_length (p->name)
|
428
|
1527 + 10);
|
|
1528
|
|
1529 old_read_only = current_buffer->read_only;
|
|
1530 current_buffer->read_only = Qnil;
|
|
1531 buffer_insert_c_string (current_buffer, "\nProcess ");
|
|
1532 Finsert (1, &p->name);
|
|
1533 buffer_insert_c_string (current_buffer, " ");
|
|
1534 Finsert (1, &msg);
|
|
1535 current_buffer->read_only = old_read_only;
|
|
1536 Fset_marker (p->mark, make_int (BUF_PT (current_buffer)),
|
|
1537 p->buffer);
|
|
1538
|
665
|
1539 opoint = charbpos_clip_to_bounds(BUF_BEGV (XBUFFER (p->buffer)),
|
428
|
1540 opoint,
|
|
1541 BUF_ZV (XBUFFER (p->buffer)));
|
|
1542 BUF_SET_PT (current_buffer, opoint);
|
|
1543 Fset_buffer (old);
|
|
1544 NUNGCPRO;
|
|
1545 }
|
|
1546 }
|
|
1547 } /* end for */
|
|
1548
|
|
1549 /* in case buffers use %s in modeline-format */
|
|
1550 MARK_MODELINE_CHANGED;
|
|
1551 redisplay ();
|
|
1552
|
|
1553 update_tick = temp_process_tick;
|
|
1554
|
|
1555 UNGCPRO;
|
|
1556 }
|
|
1557
|
|
1558 DEFUN ("process-status", Fprocess_status, 1, 1, 0, /*
|
|
1559 Return the status of PROCESS.
|
|
1560 This is a symbol, one of these:
|
|
1561
|
|
1562 run -- for a process that is running.
|
|
1563 stop -- for a process stopped but continuable.
|
|
1564 exit -- for a process that has exited.
|
|
1565 signal -- for a process that has got a fatal signal.
|
|
1566 open -- for a network stream connection that is open.
|
|
1567 closed -- for a network stream connection that is closed.
|
|
1568 nil -- if arg is a process name and no such process exists.
|
|
1569
|
|
1570 PROCESS may be a process, a buffer, the name of a process or buffer, or
|
|
1571 nil, indicating the current buffer's process.
|
|
1572 */
|
444
|
1573 (process))
|
428
|
1574 {
|
|
1575 Lisp_Object status_symbol;
|
|
1576
|
444
|
1577 if (STRINGP (process))
|
|
1578 process = Fget_process (process);
|
428
|
1579 else
|
444
|
1580 process = get_process (process);
|
428
|
1581
|
444
|
1582 if (NILP (process))
|
428
|
1583 return Qnil;
|
|
1584
|
444
|
1585 status_symbol = XPROCESS (process)->status_symbol;
|
|
1586 if (network_connection_p (process))
|
428
|
1587 {
|
|
1588 if (EQ (status_symbol, Qrun))
|
|
1589 status_symbol = Qopen;
|
|
1590 else if (EQ (status_symbol, Qexit))
|
|
1591 status_symbol = Qclosed;
|
|
1592 }
|
|
1593 return status_symbol;
|
|
1594 }
|
|
1595
|
|
1596 DEFUN ("process-exit-status", Fprocess_exit_status, 1, 1, 0, /*
|
|
1597 Return the exit status of PROCESS or the signal number that killed it.
|
|
1598 If PROCESS has not yet exited or died, return 0.
|
|
1599 */
|
444
|
1600 (process))
|
428
|
1601 {
|
444
|
1602 CHECK_PROCESS (process);
|
|
1603 return make_int (XPROCESS (process)->exit_code);
|
428
|
1604 }
|
|
1605
|
|
1606
|
|
1607
|
442
|
1608 static int
|
|
1609 decode_signal (Lisp_Object signal_)
|
428
|
1610 {
|
442
|
1611 if (INTP (signal_))
|
|
1612 return XINT (signal_);
|
428
|
1613 else
|
|
1614 {
|
665
|
1615 Intbyte *name;
|
428
|
1616
|
442
|
1617 CHECK_SYMBOL (signal_);
|
793
|
1618 name = XSTRING_DATA (XSYMBOL (signal_)->name);
|
428
|
1619
|
793
|
1620 #define handle_signal(sym) do { \
|
|
1621 if (!qxestrcmp_c ( name, #sym)) \
|
|
1622 return sym; \
|
442
|
1623 } while (0)
|
428
|
1624
|
|
1625 handle_signal (SIGINT); /* ANSI */
|
|
1626 handle_signal (SIGILL); /* ANSI */
|
|
1627 handle_signal (SIGABRT); /* ANSI */
|
|
1628 handle_signal (SIGFPE); /* ANSI */
|
|
1629 handle_signal (SIGSEGV); /* ANSI */
|
|
1630 handle_signal (SIGTERM); /* ANSI */
|
|
1631
|
|
1632 #ifdef SIGHUP
|
|
1633 handle_signal (SIGHUP); /* POSIX */
|
|
1634 #endif
|
|
1635 #ifdef SIGQUIT
|
|
1636 handle_signal (SIGQUIT); /* POSIX */
|
|
1637 #endif
|
|
1638 #ifdef SIGTRAP
|
|
1639 handle_signal (SIGTRAP); /* POSIX */
|
|
1640 #endif
|
|
1641 #ifdef SIGKILL
|
|
1642 handle_signal (SIGKILL); /* POSIX */
|
|
1643 #endif
|
|
1644 #ifdef SIGUSR1
|
|
1645 handle_signal (SIGUSR1); /* POSIX */
|
|
1646 #endif
|
|
1647 #ifdef SIGUSR2
|
|
1648 handle_signal (SIGUSR2); /* POSIX */
|
|
1649 #endif
|
|
1650 #ifdef SIGPIPE
|
|
1651 handle_signal (SIGPIPE); /* POSIX */
|
|
1652 #endif
|
|
1653 #ifdef SIGALRM
|
|
1654 handle_signal (SIGALRM); /* POSIX */
|
|
1655 #endif
|
|
1656 #ifdef SIGCHLD
|
|
1657 handle_signal (SIGCHLD); /* POSIX */
|
|
1658 #endif
|
|
1659 #ifdef SIGCONT
|
|
1660 handle_signal (SIGCONT); /* POSIX */
|
|
1661 #endif
|
|
1662 #ifdef SIGSTOP
|
|
1663 handle_signal (SIGSTOP); /* POSIX */
|
|
1664 #endif
|
|
1665 #ifdef SIGTSTP
|
|
1666 handle_signal (SIGTSTP); /* POSIX */
|
|
1667 #endif
|
|
1668 #ifdef SIGTTIN
|
|
1669 handle_signal (SIGTTIN); /* POSIX */
|
|
1670 #endif
|
|
1671 #ifdef SIGTTOU
|
|
1672 handle_signal (SIGTTOU); /* POSIX */
|
|
1673 #endif
|
|
1674
|
|
1675 #ifdef SIGBUS
|
|
1676 handle_signal (SIGBUS); /* XPG5 */
|
|
1677 #endif
|
|
1678 #ifdef SIGPOLL
|
|
1679 handle_signal (SIGPOLL); /* XPG5 */
|
|
1680 #endif
|
|
1681 #ifdef SIGPROF
|
|
1682 handle_signal (SIGPROF); /* XPG5 */
|
|
1683 #endif
|
|
1684 #ifdef SIGSYS
|
|
1685 handle_signal (SIGSYS); /* XPG5 */
|
|
1686 #endif
|
|
1687 #ifdef SIGURG
|
|
1688 handle_signal (SIGURG); /* XPG5 */
|
|
1689 #endif
|
|
1690 #ifdef SIGXCPU
|
|
1691 handle_signal (SIGXCPU); /* XPG5 */
|
|
1692 #endif
|
|
1693 #ifdef SIGXFSZ
|
|
1694 handle_signal (SIGXFSZ); /* XPG5 */
|
|
1695 #endif
|
|
1696 #ifdef SIGVTALRM
|
|
1697 handle_signal (SIGVTALRM); /* XPG5 */
|
|
1698 #endif
|
|
1699
|
|
1700 #ifdef SIGIO
|
|
1701 handle_signal (SIGIO); /* BSD 4.2 */
|
|
1702 #endif
|
|
1703 #ifdef SIGWINCH
|
|
1704 handle_signal (SIGWINCH); /* BSD 4.3 */
|
|
1705 #endif
|
|
1706
|
|
1707 #ifdef SIGEMT
|
|
1708 handle_signal (SIGEMT);
|
|
1709 #endif
|
|
1710 #ifdef SIGINFO
|
|
1711 handle_signal (SIGINFO);
|
|
1712 #endif
|
|
1713 #ifdef SIGHWE
|
|
1714 handle_signal (SIGHWE);
|
|
1715 #endif
|
|
1716 #ifdef SIGPRE
|
|
1717 handle_signal (SIGPRE);
|
|
1718 #endif
|
|
1719 #ifdef SIGUME
|
|
1720 handle_signal (SIGUME);
|
|
1721 #endif
|
|
1722 #ifdef SIGDLK
|
|
1723 handle_signal (SIGDLK);
|
|
1724 #endif
|
|
1725 #ifdef SIGCPULIM
|
|
1726 handle_signal (SIGCPULIM);
|
|
1727 #endif
|
|
1728 #ifdef SIGIOT
|
|
1729 handle_signal (SIGIOT);
|
|
1730 #endif
|
|
1731 #ifdef SIGLOST
|
|
1732 handle_signal (SIGLOST);
|
|
1733 #endif
|
|
1734 #ifdef SIGSTKFLT
|
|
1735 handle_signal (SIGSTKFLT);
|
|
1736 #endif
|
|
1737 #ifdef SIGUNUSED
|
|
1738 handle_signal (SIGUNUSED);
|
|
1739 #endif
|
|
1740 #ifdef SIGDANGER
|
|
1741 handle_signal (SIGDANGER); /* AIX */
|
|
1742 #endif
|
|
1743 #ifdef SIGMSG
|
|
1744 handle_signal (SIGMSG);
|
|
1745 #endif
|
|
1746 #ifdef SIGSOUND
|
|
1747 handle_signal (SIGSOUND);
|
|
1748 #endif
|
|
1749 #ifdef SIGRETRACT
|
|
1750 handle_signal (SIGRETRACT);
|
|
1751 #endif
|
|
1752 #ifdef SIGGRANT
|
|
1753 handle_signal (SIGGRANT);
|
|
1754 #endif
|
|
1755 #ifdef SIGPWR
|
|
1756 handle_signal (SIGPWR);
|
|
1757 #endif
|
|
1758
|
|
1759 #undef handle_signal
|
|
1760
|
563
|
1761 invalid_constant ("Undefined signal name", signal_);
|
801
|
1762 RETURN_NOT_REACHED (0)
|
442
|
1763 }
|
|
1764 }
|
|
1765
|
|
1766 /* Send signal number SIGNO to PROCESS.
|
|
1767 CURRENT-GROUP non-nil means send signal to the current
|
|
1768 foreground process group of the process's controlling terminal rather
|
|
1769 than to the process's own process group.
|
|
1770 This is used for various commands in shell mode.
|
|
1771 If NOMSG is zero, insert signal-announcements into process's buffers
|
|
1772 right away.
|
|
1773
|
|
1774 If we can, we try to signal PROCESS by sending control characters
|
|
1775 down the pty. This allows us to signal inferiors who have changed
|
|
1776 their uid, for which kill() would return an EPERM error, or to
|
|
1777 processes running on another computer through a remote login. */
|
|
1778
|
|
1779 static void
|
|
1780 process_send_signal (Lisp_Object process, int signo,
|
|
1781 int current_group, int nomsg)
|
|
1782 {
|
|
1783 /* This function can GC */
|
444
|
1784 process = get_process (process);
|
442
|
1785
|
444
|
1786 if (network_connection_p (process))
|
563
|
1787 invalid_operation ("Network connection is not a subprocess", process);
|
444
|
1788 CHECK_LIVE_PROCESS (process);
|
442
|
1789
|
444
|
1790 MAYBE_PROCMETH (kill_child_process, (process, signo, current_group, nomsg));
|
442
|
1791 }
|
|
1792
|
|
1793 DEFUN ("process-send-signal", Fprocess_send_signal, 1, 3, 0, /*
|
|
1794 Send signal SIGNAL to process PROCESS.
|
|
1795 SIGNAL may be an integer, or a symbol naming a signal, like `SIGSEGV'.
|
|
1796 PROCESS may be a process, a buffer, the name of a process or buffer, or
|
|
1797 nil, indicating the current buffer's process.
|
|
1798 Third arg CURRENT-GROUP non-nil means send signal to the current
|
|
1799 foreground process group of the process's controlling terminal rather
|
|
1800 than to the process's own process group.
|
|
1801 If the process is a shell that supports job control, this means
|
|
1802 send the signal to the current subjob rather than the shell.
|
|
1803 */
|
|
1804 (signal_, process, current_group))
|
|
1805 {
|
|
1806 /* This function can GC */
|
|
1807 process_send_signal (process, decode_signal (signal_),
|
|
1808 !NILP (current_group), 0);
|
|
1809 return process;
|
|
1810 }
|
|
1811
|
|
1812 DEFUN ("interrupt-process", Finterrupt_process, 0, 2, 0, /*
|
|
1813 Interrupt process PROCESS.
|
|
1814 See function `process-send-signal' for more details on usage.
|
|
1815 */
|
|
1816 (process, current_group))
|
|
1817 {
|
|
1818 /* This function can GC */
|
|
1819 process_send_signal (process, SIGINT, !NILP (current_group), 0);
|
|
1820 return process;
|
|
1821 }
|
|
1822
|
|
1823 DEFUN ("kill-process", Fkill_process, 0, 2, 0, /*
|
|
1824 Kill process PROCESS.
|
|
1825 See function `process-send-signal' for more details on usage.
|
|
1826 */
|
|
1827 (process, current_group))
|
|
1828 {
|
|
1829 /* This function can GC */
|
|
1830 #ifdef SIGKILL
|
|
1831 process_send_signal (process, SIGKILL, !NILP (current_group), 0);
|
|
1832 #else
|
563
|
1833 signal_error (Qunimplemented,
|
|
1834 "kill-process: Not supported on this system",
|
|
1835 Qunbound);
|
442
|
1836 #endif
|
|
1837 return process;
|
|
1838 }
|
|
1839
|
|
1840 DEFUN ("quit-process", Fquit_process, 0, 2, 0, /*
|
|
1841 Send QUIT signal to process PROCESS.
|
|
1842 See function `process-send-signal' for more details on usage.
|
|
1843 */
|
|
1844 (process, current_group))
|
|
1845 {
|
|
1846 /* This function can GC */
|
|
1847 #ifdef SIGQUIT
|
|
1848 process_send_signal (process, SIGQUIT, !NILP (current_group), 0);
|
|
1849 #else
|
563
|
1850 signal_error (Qunimplemented,
|
|
1851 "quit-process: Not supported on this system",
|
|
1852 Qunbound);
|
442
|
1853 #endif
|
|
1854 return process;
|
|
1855 }
|
|
1856
|
|
1857 DEFUN ("stop-process", Fstop_process, 0, 2, 0, /*
|
|
1858 Stop process PROCESS.
|
|
1859 See function `process-send-signal' for more details on usage.
|
|
1860 */
|
|
1861 (process, current_group))
|
|
1862 {
|
|
1863 /* This function can GC */
|
|
1864 #ifdef SIGTSTP
|
|
1865 process_send_signal (process, SIGTSTP, !NILP (current_group), 0);
|
|
1866 #else
|
563
|
1867 signal_error (Qunimplemented,
|
|
1868 "stop-process: Not supported on this system",
|
|
1869 Qunbound);
|
442
|
1870 #endif
|
|
1871 return process;
|
|
1872 }
|
|
1873
|
|
1874 DEFUN ("continue-process", Fcontinue_process, 0, 2, 0, /*
|
|
1875 Continue process PROCESS.
|
|
1876 See function `process-send-signal' for more details on usage.
|
|
1877 */
|
|
1878 (process, current_group))
|
|
1879 {
|
|
1880 /* This function can GC */
|
|
1881 #ifdef SIGCONT
|
|
1882 process_send_signal (process, SIGCONT, !NILP (current_group), 0);
|
|
1883 #else
|
563
|
1884 signal_error (Qunimplemented,
|
|
1885 "continue-process: Not supported on this system",
|
|
1886 Qunbound);
|
442
|
1887 #endif
|
|
1888 return process;
|
|
1889 }
|
|
1890
|
|
1891 DEFUN ("signal-process", Fsignal_process, 2, 2,
|
|
1892 "nProcess number: \nnSignal code: ", /*
|
|
1893 Send the process with process id PID the signal with code SIGNAL.
|
|
1894 PID must be an integer. The process need not be a child of this Emacs.
|
|
1895 SIGNAL may be an integer, or a symbol naming a signal, like `SIGSEGV'.
|
|
1896 */
|
|
1897 (pid, signal_))
|
|
1898 {
|
|
1899 CHECK_INT (pid);
|
|
1900
|
428
|
1901 return make_int (PROCMETH_OR_GIVEN (kill_process_by_pid,
|
442
|
1902 (XINT (pid), decode_signal (signal_)),
|
|
1903 -1));
|
428
|
1904 }
|
|
1905
|
|
1906 DEFUN ("process-send-eof", Fprocess_send_eof, 0, 1, 0, /*
|
|
1907 Make PROCESS see end-of-file in its input.
|
|
1908 PROCESS may be a process, a buffer, the name of a process or buffer, or
|
|
1909 nil, indicating the current buffer's process.
|
|
1910 If PROCESS is a network connection, or is a process communicating
|
|
1911 through a pipe (as opposed to a pty), then you cannot send any more
|
|
1912 text to PROCESS after you call this function.
|
|
1913 */
|
|
1914 (process))
|
|
1915 {
|
|
1916 /* This function can GC */
|
444
|
1917 process = get_process (process);
|
428
|
1918
|
|
1919 /* Make sure the process is really alive. */
|
444
|
1920 if (! EQ (XPROCESS (process)->status_symbol, Qrun))
|
563
|
1921 invalid_operation ("Process not running", process);
|
428
|
1922
|
444
|
1923 if (!MAYBE_INT_PROCMETH (process_send_eof, (process)))
|
428
|
1924 {
|
444
|
1925 if (!NILP (DATA_OUTSTREAM (XPROCESS (process))))
|
428
|
1926 {
|
444
|
1927 Lstream_close (XLSTREAM (DATA_OUTSTREAM (XPROCESS (process))));
|
|
1928 event_stream_delete_stream_pair (Qnil, XPROCESS (process)->pipe_outstream);
|
|
1929 XPROCESS (process)->pipe_outstream = Qnil;
|
|
1930 XPROCESS (process)->coding_outstream = Qnil;
|
428
|
1931 }
|
|
1932 }
|
|
1933
|
|
1934 return process;
|
|
1935 }
|
|
1936
|
|
1937
|
|
1938 /************************************************************************/
|
|
1939 /* deleting a process */
|
|
1940 /************************************************************************/
|
|
1941
|
|
1942 void
|
444
|
1943 deactivate_process (Lisp_Object process)
|
428
|
1944 {
|
444
|
1945 Lisp_Process *p = XPROCESS (process);
|
428
|
1946 USID usid;
|
|
1947
|
|
1948 /* It's possible that we got as far in the process-creation
|
|
1949 process as creating the descriptors but didn't get so
|
|
1950 far as selecting the process for input. In this
|
|
1951 case, p->pid is nil: p->pid is set at the same time that
|
|
1952 the process is selected for input. */
|
|
1953 /* #### The comment does not look correct. event_stream_unselect_process
|
|
1954 is guarded by process->selected, so this is not a problem. - kkm*/
|
|
1955 /* Must call this before setting the streams to nil */
|
|
1956 event_stream_unselect_process (p);
|
|
1957
|
|
1958 if (!NILP (DATA_OUTSTREAM (p)))
|
|
1959 Lstream_close (XLSTREAM (DATA_OUTSTREAM (p)));
|
|
1960 if (!NILP (DATA_INSTREAM (p)))
|
|
1961 Lstream_close (XLSTREAM (DATA_INSTREAM (p)));
|
|
1962
|
|
1963 /* Provide minimal implementation for deactivate_process
|
|
1964 if there's no process-specific one */
|
|
1965 if (HAS_PROCMETH_P (deactivate_process))
|
|
1966 usid = PROCMETH (deactivate_process, (p));
|
|
1967 else
|
|
1968 usid = event_stream_delete_stream_pair (p->pipe_instream,
|
|
1969 p->pipe_outstream);
|
|
1970
|
|
1971 if (usid != USID_DONTHASH)
|
442
|
1972 remhash ((const void*)usid, usid_to_process);
|
428
|
1973
|
|
1974 p->pipe_instream = Qnil;
|
|
1975 p->pipe_outstream = Qnil;
|
|
1976 p->coding_instream = Qnil;
|
|
1977 p->coding_outstream = Qnil;
|
|
1978 }
|
|
1979
|
|
1980 static void
|
444
|
1981 remove_process (Lisp_Object process)
|
428
|
1982 {
|
444
|
1983 Vprocess_list = delq_no_quit (process, Vprocess_list);
|
|
1984 Fset_marker (XPROCESS (process)->mark, Qnil, Qnil);
|
428
|
1985
|
444
|
1986 deactivate_process (process);
|
428
|
1987 }
|
|
1988
|
|
1989 DEFUN ("delete-process", Fdelete_process, 1, 1, 0, /*
|
|
1990 Delete PROCESS: kill it and forget about it immediately.
|
|
1991 PROCESS may be a process or the name of one, or a buffer name.
|
|
1992 */
|
444
|
1993 (process))
|
428
|
1994 {
|
|
1995 /* This function can GC */
|
440
|
1996 Lisp_Process *p;
|
444
|
1997 process = get_process (process);
|
|
1998 p = XPROCESS (process);
|
|
1999 if (network_connection_p (process))
|
428
|
2000 {
|
|
2001 p->status_symbol = Qexit;
|
|
2002 p->exit_code = 0;
|
|
2003 p->core_dumped = 0;
|
|
2004 p->tick++;
|
|
2005 process_tick++;
|
|
2006 }
|
440
|
2007 else if (PROCESS_LIVE_P (p))
|
428
|
2008 {
|
444
|
2009 Fkill_process (process, Qnil);
|
428
|
2010 /* Do this now, since remove_process will make sigchld_handler do nothing. */
|
|
2011 p->status_symbol = Qsignal;
|
|
2012 p->exit_code = SIGKILL;
|
|
2013 p->core_dumped = 0;
|
|
2014 p->tick++;
|
|
2015 process_tick++;
|
|
2016 status_notify ();
|
|
2017 }
|
444
|
2018 remove_process (process);
|
428
|
2019 return Qnil;
|
|
2020 }
|
|
2021
|
|
2022 /* Kill all processes associated with `buffer'.
|
|
2023 If `buffer' is nil, kill all processes */
|
|
2024
|
|
2025 void
|
|
2026 kill_buffer_processes (Lisp_Object buffer)
|
|
2027 {
|
444
|
2028 LIST_LOOP_2 (process, Vprocess_list)
|
|
2029 if ((NILP (buffer) || EQ (XPROCESS (process)->buffer, buffer)))
|
|
2030 {
|
|
2031 if (network_connection_p (process))
|
|
2032 Fdelete_process (process);
|
|
2033 else if (PROCESS_LIVE_P (XPROCESS (process)))
|
|
2034 process_send_signal (process, SIGHUP, 0, 1);
|
|
2035 }
|
428
|
2036 }
|
|
2037
|
|
2038 DEFUN ("process-kill-without-query", Fprocess_kill_without_query, 1, 2, 0, /*
|
|
2039 Say no query needed if PROCESS is running when Emacs is exited.
|
|
2040 Optional second argument if non-nil says to require a query.
|
|
2041 Value is t if a query was formerly required.
|
|
2042 */
|
444
|
2043 (process, require_query_p))
|
428
|
2044 {
|
|
2045 int tem;
|
|
2046
|
444
|
2047 CHECK_PROCESS (process);
|
|
2048 tem = XPROCESS (process)->kill_without_query;
|
|
2049 XPROCESS (process)->kill_without_query = NILP (require_query_p);
|
428
|
2050
|
|
2051 return tem ? Qnil : Qt;
|
|
2052 }
|
|
2053
|
|
2054 DEFUN ("process-kill-without-query-p", Fprocess_kill_without_query_p, 1, 1, 0, /*
|
444
|
2055 Return t if PROCESS will be killed without query when emacs is exited.
|
428
|
2056 */
|
444
|
2057 (process))
|
428
|
2058 {
|
444
|
2059 CHECK_PROCESS (process);
|
|
2060 return XPROCESS (process)->kill_without_query ? Qt : Qnil;
|
428
|
2061 }
|
|
2062
|
|
2063
|
|
2064 #if 0
|
|
2065
|
826
|
2066 DEFUN ("process-connection", Fprocess_connection, 0, 1, 0, /*
|
428
|
2067 Return the connection type of `PROCESS'. This can be nil (pipe),
|
|
2068 t or pty (pty) or stream (socket connection).
|
|
2069 */
|
|
2070 (process))
|
|
2071 {
|
|
2072 return XPROCESS (process)->type;
|
|
2073 }
|
|
2074
|
|
2075 #endif /* 0 */
|
|
2076
|
814
|
2077
|
|
2078 static int
|
|
2079 getenv_internal (const Intbyte *var,
|
|
2080 Bytecount varlen,
|
|
2081 Intbyte **value,
|
|
2082 Bytecount *valuelen)
|
|
2083 {
|
|
2084 Lisp_Object scan;
|
|
2085
|
|
2086 assert (env_initted);
|
|
2087
|
|
2088 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
|
|
2089 {
|
|
2090 Lisp_Object entry = XCAR (scan);
|
|
2091
|
|
2092 if (STRINGP (entry)
|
|
2093 && XSTRING_LENGTH (entry) > varlen
|
826
|
2094 && string_byte (entry, varlen) == '='
|
814
|
2095 #ifdef WIN32_NATIVE
|
|
2096 /* NT environment variables are case insensitive. */
|
|
2097 && ! memicmp (XSTRING_DATA (entry), var, varlen)
|
|
2098 #else /* not WIN32_NATIVE */
|
|
2099 && ! memcmp (XSTRING_DATA (entry), var, varlen)
|
|
2100 #endif /* not WIN32_NATIVE */
|
|
2101 )
|
|
2102 {
|
|
2103 *value = XSTRING_DATA (entry) + (varlen + 1);
|
|
2104 *valuelen = XSTRING_LENGTH (entry) - (varlen + 1);
|
|
2105 return 1;
|
|
2106 }
|
|
2107 }
|
|
2108
|
|
2109 return 0;
|
|
2110 }
|
|
2111
|
|
2112 static void
|
|
2113 putenv_internal (const Intbyte *var,
|
|
2114 Bytecount varlen,
|
|
2115 const Intbyte *value,
|
|
2116 Bytecount valuelen)
|
|
2117 {
|
|
2118 Lisp_Object scan;
|
|
2119
|
|
2120 assert (env_initted);
|
|
2121
|
|
2122 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
|
|
2123 {
|
|
2124 Lisp_Object entry = XCAR (scan);
|
|
2125
|
|
2126 if (STRINGP (entry)
|
|
2127 && XSTRING_LENGTH (entry) > varlen
|
826
|
2128 && string_byte (entry, varlen) == '='
|
814
|
2129 #ifdef WIN32_NATIVE
|
|
2130 /* NT environment variables are case insensitive. */
|
|
2131 && ! memicmp (XSTRING_DATA (entry), var, varlen)
|
|
2132 #else /* not WIN32_NATIVE */
|
|
2133 && ! memcmp (XSTRING_DATA (entry), var, varlen)
|
|
2134 #endif /* not WIN32_NATIVE */
|
|
2135 )
|
|
2136 {
|
|
2137 XCAR (scan) = concat3 (make_string (var, varlen),
|
|
2138 build_string ("="),
|
|
2139 make_string (value, valuelen));
|
|
2140 return;
|
|
2141 }
|
|
2142 }
|
|
2143
|
|
2144 Vprocess_environment = Fcons (concat3 (make_string (var, varlen),
|
|
2145 build_string ("="),
|
|
2146 make_string (value, valuelen)),
|
|
2147 Vprocess_environment);
|
|
2148 }
|
|
2149
|
|
2150 /* NOTE:
|
|
2151
|
|
2152 FSF has this as a Lisp function, as follows. Generally moving things
|
|
2153 out of C and into Lisp is a good idea, but in this case the Lisp
|
|
2154 function is used so early in the startup sequence that it would be ugly
|
|
2155 to rearrange the early dumped code to accommodate this.
|
|
2156
|
|
2157 (defun getenv (variable)
|
|
2158 "Get the value of environment variable VARIABLE.
|
|
2159 VARIABLE should be a string. Value is nil if VARIABLE is undefined in
|
|
2160 the environment. Otherwise, value is a string.
|
|
2161
|
|
2162 This function consults the variable `process-environment'
|
|
2163 for its value."
|
|
2164 (interactive (list (read-envvar-name "Get environment variable: " t)))
|
|
2165 (let ((value (getenv-internal variable)))
|
|
2166 (when (interactive-p)
|
|
2167 (message "%s" (if value value "Not set")))
|
|
2168 value))
|
|
2169 */
|
|
2170
|
|
2171 DEFUN ("getenv", Fgetenv, 1, 2, "sEnvironment variable: \np", /*
|
|
2172 Return the value of environment variable VAR, as a string.
|
|
2173 VAR is a string, the name of the variable.
|
|
2174 When invoked interactively, prints the value in the echo area.
|
|
2175 */
|
|
2176 (var, interactivep))
|
|
2177 {
|
|
2178 Intbyte *value;
|
|
2179 Bytecount valuelen;
|
|
2180 Lisp_Object v = Qnil;
|
|
2181 struct gcpro gcpro1;
|
|
2182
|
|
2183 CHECK_STRING (var);
|
|
2184 GCPRO1 (v);
|
|
2185 if (getenv_internal (XSTRING_DATA (var), XSTRING_LENGTH (var),
|
|
2186 &value, &valuelen))
|
|
2187 v = make_string (value, valuelen);
|
|
2188 if (!NILP (interactivep))
|
|
2189 {
|
|
2190 if (NILP (v))
|
|
2191 message ("%s not defined in environment", XSTRING_DATA (var));
|
|
2192 else
|
|
2193 /* #### Should use Fprin1_to_string or Fprin1 to handle string
|
|
2194 containing quotes correctly. */
|
|
2195 message ("\"%s\"", value);
|
|
2196 }
|
|
2197 RETURN_UNGCPRO (v);
|
|
2198 }
|
|
2199
|
|
2200 /* A version of getenv that consults Vprocess_environment, easily
|
|
2201 callable from C.
|
|
2202
|
|
2203 (At init time, Vprocess_environment is initialized from the
|
|
2204 environment, stored in the global variable environ. [Note that
|
|
2205 at startup time, `environ' should be the same as the envp parameter
|
|
2206 passed to main(); however, later calls to putenv() may change
|
|
2207 `environ', making the envp parameter inaccurate.] Calls to getenv()
|
|
2208 and putenv() consult and modify `environ'. However, once
|
|
2209 Vprocess_environment is initted, XEmacs C code should *NEVER* call
|
|
2210 getenv() or putenv() directly, because (1) Lisp code that modifies
|
|
2211 the environment only modifies Vprocess_environment, not `environ';
|
|
2212 and (2) Vprocess_environment is in internal format but `environ'
|
|
2213 is in some external format, and getenv()/putenv() are not Mule-
|
|
2214 encapsulated.
|
|
2215
|
|
2216 WARNING: This value points into Lisp string data and thus will become
|
|
2217 invalid after a GC. */
|
|
2218
|
|
2219 Intbyte *
|
|
2220 egetenv (const CIntbyte *var)
|
|
2221 {
|
|
2222 /* This cannot GC -- 7-28-00 ben */
|
|
2223 Intbyte *value;
|
|
2224 Bytecount valuelen;
|
|
2225
|
|
2226 if (getenv_internal ((const Intbyte *) var, strlen (var), &value, &valuelen))
|
|
2227 return value;
|
|
2228 else
|
|
2229 return 0;
|
|
2230 }
|
|
2231
|
|
2232 void
|
|
2233 eputenv (const CIntbyte *var, const CIntbyte *value)
|
|
2234 {
|
|
2235 putenv_internal ((Intbyte *) var, strlen (var), (Intbyte *) value,
|
|
2236 strlen (value));
|
|
2237 }
|
|
2238
|
|
2239
|
|
2240 /* This is not named init_process in order to avoid a conflict with NS 3.3 */
|
|
2241 void
|
|
2242 init_xemacs_process (void)
|
|
2243 {
|
|
2244 /* This function can GC */
|
|
2245
|
|
2246 MAYBE_PROCMETH (init_process, ());
|
|
2247
|
|
2248 Vprocess_list = Qnil;
|
|
2249
|
|
2250 if (usid_to_process)
|
|
2251 clrhash (usid_to_process);
|
|
2252 else
|
|
2253 usid_to_process = make_hash_table (32);
|
|
2254
|
|
2255 {
|
|
2256 /* jwz: always initialize Vprocess_environment, so that egetenv()
|
|
2257 works in temacs. */
|
|
2258 char **envp;
|
|
2259 Vprocess_environment = Qnil;
|
|
2260 for (envp = environ; envp && *envp; envp++)
|
|
2261 Vprocess_environment =
|
|
2262 Fcons (build_ext_string (*envp, Qnative), Vprocess_environment);
|
|
2263 /* This gets set back to 0 in disksave_object_finalization() */
|
|
2264 env_initted = 1;
|
|
2265 }
|
|
2266
|
|
2267 {
|
|
2268 /* Initialize shell-file-name from environment variables or best guess. */
|
|
2269 #ifdef WIN32_NATIVE
|
|
2270 const Intbyte *shell = egetenv ("SHELL");
|
|
2271 if (!shell) shell = egetenv ("COMSPEC");
|
|
2272 /* Should never happen! */
|
|
2273 if (!shell) shell =
|
|
2274 (Intbyte *) (GetVersion () & 0x80000000 ? "command" : "cmd");
|
|
2275 #else /* not WIN32_NATIVE */
|
|
2276 const Intbyte *shell = egetenv ("SHELL");
|
|
2277 if (!shell) shell = (Intbyte *) "/bin/sh";
|
|
2278 #endif
|
|
2279
|
|
2280 #if 0 /* defined (WIN32_NATIVE) */
|
|
2281 /* BAD BAD BAD. We do not wanting to be passing an XEmacs-created
|
|
2282 SHELL var down to some inferior Cygwin process, which might get
|
|
2283 screwed up.
|
|
2284
|
|
2285 There are a few broken apps (eterm/term.el, eterm/tshell.el,
|
|
2286 os-utils/terminal.el, texinfo/tex-mode.el) where this will
|
|
2287 cause problems. Those broken apps don't look at
|
|
2288 shell-file-name, instead just at explicit-shell-file-name,
|
|
2289 ESHELL and SHELL. They are apparently attempting to borrow
|
|
2290 what `M-x shell' uses, but that latter also looks at
|
|
2291 shell-file-name. What we want is for all of these apps to look
|
|
2292 at shell-file-name, so that the user can change the value of
|
|
2293 shell-file-name and everything will work out hunky-dorey.
|
|
2294 */
|
|
2295
|
|
2296 if (!egetenv ("SHELL"))
|
|
2297 {
|
|
2298 Intbyte *faux_var = alloca_array (Intbyte, 7 + qxestrlen (shell));
|
|
2299 qxesprintf (faux_var, "SHELL=%s", shell);
|
|
2300 Vprocess_environment = Fcons (build_intstring (faux_var),
|
|
2301 Vprocess_environment);
|
|
2302 }
|
|
2303 #endif /* 0 */
|
|
2304
|
|
2305 Vshell_file_name = build_intstring (shell);
|
|
2306 }
|
|
2307 }
|
|
2308
|
428
|
2309 void
|
|
2310 syms_of_process (void)
|
|
2311 {
|
442
|
2312 INIT_LRECORD_IMPLEMENTATION (process);
|
|
2313
|
563
|
2314 DEFSYMBOL (Qprocessp);
|
|
2315 DEFSYMBOL (Qprocess_live_p);
|
|
2316 DEFSYMBOL (Qrun);
|
|
2317 DEFSYMBOL (Qstop);
|
|
2318 DEFSYMBOL (Qopen);
|
|
2319 DEFSYMBOL (Qclosed);
|
428
|
2320
|
563
|
2321 DEFSYMBOL (Qtcp);
|
|
2322 DEFSYMBOL (Qudp);
|
428
|
2323
|
|
2324 #ifdef HAVE_MULTICAST
|
563
|
2325 DEFSYMBOL (Qmulticast); /* Used for occasional warnings */
|
428
|
2326 #endif
|
|
2327
|
563
|
2328 DEFERROR_STANDARD (Qprocess_error, Qio_error);
|
|
2329 DEFERROR_STANDARD (Qnetwork_error, Qio_error);
|
|
2330
|
428
|
2331 DEFSUBR (Fprocessp);
|
440
|
2332 DEFSUBR (Fprocess_live_p);
|
428
|
2333 DEFSUBR (Fget_process);
|
|
2334 DEFSUBR (Fget_buffer_process);
|
|
2335 DEFSUBR (Fdelete_process);
|
|
2336 DEFSUBR (Fprocess_status);
|
|
2337 DEFSUBR (Fprocess_exit_status);
|
|
2338 DEFSUBR (Fprocess_id);
|
|
2339 DEFSUBR (Fprocess_name);
|
|
2340 DEFSUBR (Fprocess_tty_name);
|
|
2341 DEFSUBR (Fprocess_command);
|
|
2342 DEFSUBR (Fset_process_buffer);
|
|
2343 DEFSUBR (Fprocess_buffer);
|
|
2344 DEFSUBR (Fprocess_mark);
|
|
2345 DEFSUBR (Fset_process_filter);
|
|
2346 DEFSUBR (Fprocess_filter);
|
|
2347 DEFSUBR (Fset_process_window_size);
|
|
2348 DEFSUBR (Fset_process_sentinel);
|
|
2349 DEFSUBR (Fprocess_sentinel);
|
|
2350 DEFSUBR (Fprocess_kill_without_query);
|
|
2351 DEFSUBR (Fprocess_kill_without_query_p);
|
|
2352 DEFSUBR (Fprocess_list);
|
|
2353 DEFSUBR (Fstart_process_internal);
|
|
2354 #ifdef HAVE_SOCKETS
|
|
2355 DEFSUBR (Fopen_network_stream_internal);
|
|
2356 #ifdef HAVE_MULTICAST
|
|
2357 DEFSUBR (Fopen_multicast_group_internal);
|
|
2358 #endif /* HAVE_MULTICAST */
|
|
2359 #endif /* HAVE_SOCKETS */
|
|
2360 DEFSUBR (Fprocess_send_region);
|
|
2361 DEFSUBR (Fprocess_send_string);
|
442
|
2362 DEFSUBR (Fprocess_send_signal);
|
428
|
2363 DEFSUBR (Finterrupt_process);
|
|
2364 DEFSUBR (Fkill_process);
|
|
2365 DEFSUBR (Fquit_process);
|
|
2366 DEFSUBR (Fstop_process);
|
|
2367 DEFSUBR (Fcontinue_process);
|
|
2368 DEFSUBR (Fprocess_send_eof);
|
|
2369 DEFSUBR (Fsignal_process);
|
|
2370 /* DEFSUBR (Fprocess_connection); */
|
|
2371 DEFSUBR (Fprocess_input_coding_system);
|
|
2372 DEFSUBR (Fprocess_output_coding_system);
|
|
2373 DEFSUBR (Fset_process_input_coding_system);
|
|
2374 DEFSUBR (Fset_process_output_coding_system);
|
|
2375 DEFSUBR (Fprocess_coding_system);
|
|
2376 DEFSUBR (Fset_process_coding_system);
|
814
|
2377 DEFSUBR (Fgetenv);
|
428
|
2378 }
|
|
2379
|
|
2380 void
|
|
2381 vars_of_process (void)
|
|
2382 {
|
|
2383 Fprovide (intern ("subprocesses"));
|
|
2384 #ifdef HAVE_SOCKETS
|
|
2385 Fprovide (intern ("network-streams"));
|
|
2386 #ifdef HAVE_MULTICAST
|
|
2387 Fprovide (intern ("multicast"));
|
|
2388 #endif /* HAVE_MULTICAST */
|
|
2389 #endif /* HAVE_SOCKETS */
|
|
2390 staticpro (&Vprocess_list);
|
|
2391
|
|
2392 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes /*
|
|
2393 *Non-nil means delete processes immediately when they exit.
|
|
2394 nil means don't delete them until `list-processes' is run.
|
|
2395 */ );
|
|
2396
|
|
2397 delete_exited_processes = 1;
|
|
2398
|
442
|
2399 DEFVAR_CONST_LISP ("null-device", &Vnull_device /*
|
|
2400 Name of the null device, which differs from system to system.
|
|
2401 The null device is a filename that acts as a sink for arbitrary amounts of
|
|
2402 data, which is discarded, or as a source for a zero-length file.
|
|
2403 It is available on all the systems that we currently support, but with
|
|
2404 different names (typically either `/dev/null' or `nul').
|
|
2405
|
|
2406 Note that there is also a /dev/zero on most modern Unix versions (including
|
|
2407 Cygwin), which acts like /dev/null when used as a sink, but as a source
|
|
2408 it sends a non-ending stream of zero bytes. It's used most often along
|
|
2409 with memory-mapping. We don't provide a Lisp variable for this because
|
|
2410 the operations needing this are lower level than what ELisp programs
|
|
2411 typically do, and in any case no equivalent exists under native MS Windows.
|
|
2412 */ );
|
|
2413 Vnull_device = build_string (NULL_DEVICE);
|
|
2414
|
428
|
2415 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type /*
|
|
2416 Control type of device used to communicate with subprocesses.
|
|
2417 Values are nil to use a pipe, or t or `pty' to use a pty.
|
|
2418 The value has no effect if the system has no ptys or if all ptys are busy:
|
|
2419 then a pipe is used in any case.
|
|
2420 The value takes effect when `start-process' is called.
|
|
2421 */ );
|
|
2422 Vprocess_connection_type = Qt;
|
|
2423
|
|
2424 DEFVAR_BOOL ("windowed-process-io", &windowed_process_io /*
|
|
2425 Enables input/output on standard handles of a windowed process.
|
|
2426 When this variable is nil (the default), XEmacs does not attempt to read
|
|
2427 standard output handle of a windowed process. Instead, the process is
|
|
2428 immediately marked as exited immediately upon successful launching. This is
|
|
2429 done because normal windowed processes do not use standard I/O, as they are
|
|
2430 not connected to any console.
|
|
2431
|
|
2432 When launching a specially crafted windowed process, which expects to be
|
|
2433 launched by XEmacs, or by other program which pipes its standard input and
|
|
2434 output, this variable must be set to non-nil, in which case XEmacs will
|
|
2435 treat this process just like a console process.
|
|
2436
|
|
2437 NOTE: You should never set this variable, only bind it.
|
|
2438
|
|
2439 Only Windows processes can be "windowed" or "console". This variable has no
|
|
2440 effect on UNIX processes, because all UNIX processes are "console".
|
|
2441 */ );
|
|
2442 windowed_process_io = 0;
|
|
2443
|
771
|
2444 DEFVAR_INT ("debug-process-io", &debug_process_io /*
|
|
2445 If non-zero, display data sent to or received from a process.
|
|
2446 */ );
|
|
2447 debug_process_io = 0;
|
|
2448
|
|
2449 DEFVAR_LISP ("default-process-coding-system",
|
|
2450 &Vdefault_process_coding_system /*
|
|
2451 Cons of coding systems used for process I/O by default.
|
|
2452 The car part is used for reading (decoding) data from a process, and
|
|
2453 the cdr part is used for writing (encoding) data to a process.
|
|
2454 */ );
|
|
2455 /* This below will get its default set correctly in code-init.el. */
|
|
2456 Vdefault_process_coding_system = Fcons (Qundecided, Qnil);
|
|
2457
|
428
|
2458 #ifdef PROCESS_IO_BLOCKING
|
|
2459 DEFVAR_LISP ("network-stream-blocking-port-list", &network_stream_blocking_port_list /*
|
|
2460 List of port numbers or port names to set a blocking I/O mode with connection.
|
|
2461 Nil value means to set a default(non-blocking) I/O mode.
|
|
2462 The value takes effect when `open-network-stream-internal' is called.
|
|
2463 */ );
|
|
2464 network_stream_blocking_port_list = Qnil;
|
|
2465 #endif /* PROCESS_IO_BLOCKING */
|
814
|
2466
|
|
2467 /* This function can GC */
|
|
2468 DEFVAR_LISP ("shell-file-name", &Vshell_file_name /*
|
|
2469 *File name to load inferior shells from.
|
|
2470 Initialized from the SHELL environment variable.
|
|
2471 */ );
|
428
|
2472
|
814
|
2473 DEFVAR_LISP ("process-environment", &Vprocess_environment /*
|
|
2474 List of environment variables for subprocesses to inherit.
|
|
2475 Each element should be a string of the form ENVVARNAME=VALUE.
|
|
2476 The environment which Emacs inherits is placed in this variable
|
|
2477 when Emacs starts.
|
|
2478 */ );
|
|
2479
|
|
2480 Vlisp_EXEC_SUFFIXES = build_string (EXEC_SUFFIXES);
|
|
2481 staticpro (&Vlisp_EXEC_SUFFIXES);
|
|
2482 }
|