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