0
|
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.
|
|
5 Copyright (C) 1995, 1996 Ben Wing.
|
|
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
|
259
|
24 /* This file has been Mule-ized except for `start-process-internal',
|
|
25 `open-network-stream-internal' and `open-multicast-group-internal'. */
|
0
|
26
|
263
|
27 /* This file has been split into process.c and process-unix.c by
|
|
28 Kirill M. Katsnelson <kkm@kis.ru>, so please bash him and not
|
|
29 the original author(s) */
|
|
30
|
0
|
31 #include <config.h>
|
|
32
|
|
33 #if !defined (NO_SUBPROCESSES)
|
|
34
|
|
35 /* The entire file is within this conditional */
|
|
36
|
|
37 #include "lisp.h"
|
|
38
|
|
39 #include "buffer.h"
|
|
40 #include "commands.h"
|
|
41 #include "events.h"
|
|
42 #include "frame.h"
|
263
|
43 #include "hash.h"
|
0
|
44 #include "insdel.h"
|
|
45 #include "lstream.h"
|
|
46 #include "opaque.h"
|
|
47 #include "process.h"
|
263
|
48 #include "procimpl.h"
|
0
|
49 #include "sysdep.h"
|
|
50 #include "window.h"
|
259
|
51 #ifdef FILE_CODING
|
|
52 #include "file-coding.h"
|
70
|
53 #endif
|
0
|
54
|
|
55 #include "sysfile.h"
|
|
56 #include "sysproc.h"
|
|
57 #include "systime.h"
|
|
58 #include "syssignal.h" /* Always include before systty.h */
|
|
59 #include "systty.h"
|
|
60 #include "syswait.h"
|
|
61
|
263
|
62 Lisp_Object Qprocessp;
|
|
63
|
|
64 /* Process methods */
|
|
65 struct process_methods the_process_methods;
|
|
66
|
0
|
67 /* a process object is a network connection when its pid field a cons
|
|
68 (name of name of port we are connected to . foreign host name) */
|
|
69
|
|
70 /* Valid values of process->status_symbol */
|
272
|
71 Lisp_Object Qrun, Qstop;
|
0
|
72 /* Qrun => Qopen, Qexit => Qclosed for "network connection" processes */
|
|
73 Lisp_Object Qopen, Qclosed;
|
263
|
74 /* Protocol families */
|
|
75 Lisp_Object Qtcpip;
|
0
|
76
|
259
|
77 #ifdef HAVE_MULTICAST
|
|
78 Lisp_Object Qmulticast; /* Will be used for occasional warnings */
|
|
79 #endif
|
|
80
|
0
|
81 /* t means use pty, nil means use a pipe,
|
|
82 maybe other values to come. */
|
263
|
83 Lisp_Object Vprocess_connection_type;
|
0
|
84
|
278
|
85 /* Read comments to DEFVAR of this */
|
|
86 int windowed_process_io;
|
|
87
|
153
|
88 #ifdef PROCESS_IO_BLOCKING
|
|
89 /* List of port numbers or port names to set a blocking I/O mode.
|
|
90 Nil means set a non-blocking I/O mode [default]. */
|
263
|
91 Lisp_Object network_stream_blocking_port_list;
|
153
|
92 #endif /* PROCESS_IO_BLOCKING */
|
|
93
|
0
|
94 /* Number of events of change of status of a process. */
|
263
|
95 volatile int process_tick;
|
0
|
96
|
|
97 /* Number of events for which the user or sentinel has been notified. */
|
|
98 static int update_tick;
|
|
99
|
|
100 /* Nonzero means delete a process right away if it exits. */
|
|
101 int delete_exited_processes;
|
|
102
|
263
|
103 /* Hashtable which maps USIDs as returned by create_stream_pair_cb to
|
|
104 process objects. Processes are not GC-protected through this! */
|
|
105 c_hashtable usid_to_process;
|
0
|
106
|
|
107 /* List of process objects. */
|
|
108 Lisp_Object Vprocess_list;
|
|
109
|
|
110
|
|
111
|
|
112 static Lisp_Object
|
|
113 mark_process (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
114 {
|
|
115 struct Lisp_Process *proc = XPROCESS (obj);
|
263
|
116 MAYBE_PROCMETH (mark_process_data, (proc, markobj));
|
0
|
117 ((markobj) (proc->name));
|
|
118 ((markobj) (proc->command));
|
|
119 ((markobj) (proc->filter));
|
|
120 ((markobj) (proc->sentinel));
|
|
121 ((markobj) (proc->buffer));
|
|
122 ((markobj) (proc->mark));
|
|
123 ((markobj) (proc->pid));
|
263
|
124 ((markobj) (proc->pipe_instream));
|
|
125 ((markobj) (proc->pipe_outstream));
|
|
126 #ifdef FILE_CODING
|
|
127 ((markobj) (proc->coding_instream));
|
|
128 ((markobj) (proc->coding_outstream));
|
|
129 #endif
|
173
|
130 return proc->status_symbol;
|
0
|
131 }
|
|
132
|
|
133 static void
|
|
134 print_process (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
135 {
|
|
136 struct Lisp_Process *proc = XPROCESS (obj);
|
185
|
137
|
0
|
138 if (print_readably)
|
|
139 error ("printing unreadable object #<process %s>",
|
16
|
140 XSTRING_DATA (proc->name));
|
185
|
141
|
0
|
142 if (!escapeflag)
|
|
143 {
|
|
144 print_internal (proc->name, printcharfun, 0);
|
|
145 }
|
|
146 else
|
|
147 {
|
|
148 int netp = network_connection_p (obj);
|
|
149 write_c_string (((netp) ? GETTEXT ("#<network connection ") :
|
|
150 GETTEXT ("#<process ")), printcharfun);
|
|
151 print_internal (proc->name, printcharfun, 1);
|
|
152 write_c_string (((netp) ? " " : " pid "), printcharfun);
|
|
153 print_internal (proc->pid, printcharfun, 1);
|
|
154 write_c_string (" state:", printcharfun);
|
|
155 print_internal (proc->status_symbol, printcharfun, 1);
|
263
|
156 MAYBE_PROCMETH (print_process_data, (proc, printcharfun));
|
0
|
157 write_c_string (">", printcharfun);
|
|
158 }
|
|
159 }
|
|
160
|
|
161 #ifdef HAVE_WINDOW_SYSTEM
|
|
162 extern void debug_process_finalization (struct Lisp_Process *p);
|
|
163 #endif /* HAVE_WINDOW_SYSTEM */
|
|
164
|
|
165 static void
|
|
166 finalize_process (void *header, int for_disksave)
|
|
167 {
|
|
168 /* #### this probably needs to be tied into the tty event loop */
|
|
169 /* #### when there is one */
|
263
|
170 struct Lisp_Process *p = (struct Lisp_Process *) header;
|
0
|
171 #ifdef HAVE_WINDOW_SYSTEM
|
263
|
172 if (!for_disksave)
|
|
173 {
|
|
174 debug_process_finalization (p);
|
|
175 }
|
0
|
176 #endif /* HAVE_WINDOW_SYSTEM */
|
263
|
177
|
|
178 if (p->process_data)
|
|
179 {
|
|
180 MAYBE_PROCMETH (finalize_process_data, (p, for_disksave));
|
|
181 if (!for_disksave)
|
|
182 xfree (p->process_data);
|
|
183 }
|
0
|
184 }
|
|
185
|
272
|
186 DEFINE_LRECORD_IMPLEMENTATION ("process", process,
|
|
187 mark_process, print_process, finalize_process,
|
|
188 0, 0, struct Lisp_Process);
|
0
|
189
|
|
190 /************************************************************************/
|
|
191 /* basic process accessors */
|
|
192 /************************************************************************/
|
|
193
|
263
|
194 /* Under FILE_CODING, this function returns low-level streams, connected
|
|
195 directrly to the child process, rather than en/decoding FILE_CODING
|
|
196 streams */
|
|
197 void
|
|
198 get_process_streams (struct Lisp_Process *p,
|
|
199 Lisp_Object *instr, Lisp_Object *outstr)
|
0
|
200 {
|
263
|
201 assert (p);
|
|
202 assert (NILP (p->pipe_instream) || LSTREAMP(p->pipe_instream));
|
|
203 assert (NILP (p->pipe_outstream) || LSTREAMP(p->pipe_outstream));
|
|
204 *instr = p->pipe_instream;
|
|
205 *outstr = p->pipe_outstream;
|
0
|
206 }
|
|
207
|
|
208 struct Lisp_Process *
|
263
|
209 get_process_from_usid (USID usid)
|
0
|
210 {
|
263
|
211 CONST void *vval;
|
|
212
|
|
213 assert (usid != USID_ERROR && usid != USID_DONTHASH);
|
0
|
214
|
263
|
215 if (gethash ((CONST void*)usid, usid_to_process, &vval))
|
|
216 {
|
|
217 Lisp_Object proc;
|
|
218 CVOID_TO_LISP (proc, vval);
|
|
219 return XPROCESS (proc);
|
|
220 }
|
|
221 else
|
0
|
222 return 0;
|
|
223 }
|
|
224
|
|
225 int
|
|
226 get_process_selected_p (struct Lisp_Process *p)
|
|
227 {
|
|
228 return p->selected;
|
|
229 }
|
|
230
|
|
231 void
|
|
232 set_process_selected_p (struct Lisp_Process *p, int selected_p)
|
|
233 {
|
|
234 p->selected = !!selected_p;
|
|
235 }
|
|
236
|
263
|
237 int
|
|
238 connected_via_filedesc_p (struct Lisp_Process *p)
|
|
239 {
|
|
240 return MAYBE_INT_PROCMETH (tooltalk_connection_p, (p));
|
|
241 }
|
|
242
|
0
|
243 #ifdef HAVE_SOCKETS
|
|
244 int
|
|
245 network_connection_p (Lisp_Object process)
|
|
246 {
|
173
|
247 return GC_CONSP (XPROCESS (process)->pid);
|
0
|
248 }
|
|
249 #endif
|
|
250
|
20
|
251 DEFUN ("processp", Fprocessp, 1, 1, 0, /*
|
0
|
252 Return t if OBJECT is a process.
|
20
|
253 */
|
|
254 (obj))
|
0
|
255 {
|
173
|
256 return PROCESSP (obj) ? Qt : Qnil;
|
0
|
257 }
|
|
258
|
20
|
259 DEFUN ("process-list", Fprocess_list, 0, 0, 0, /*
|
0
|
260 Return a list of all processes.
|
20
|
261 */
|
|
262 ())
|
0
|
263 {
|
|
264 return Fcopy_sequence (Vprocess_list);
|
|
265 }
|
|
266
|
20
|
267 DEFUN ("get-process", Fget_process, 1, 1, 0, /*
|
0
|
268 Return the process named NAME, or nil if there is none.
|
20
|
269 */
|
|
270 (name))
|
0
|
271 {
|
|
272 Lisp_Object tail;
|
|
273
|
|
274 if (GC_PROCESSP (name))
|
173
|
275 return name;
|
0
|
276
|
|
277 if (!gc_in_progress)
|
|
278 /* this only gets called during GC when emacs is going away as a result
|
|
279 of a signal or crash. */
|
|
280 CHECK_STRING (name);
|
|
281
|
|
282 for (tail = Vprocess_list; GC_CONSP (tail); tail = XCDR (tail))
|
|
283 {
|
|
284 Lisp_Object proc = XCAR (tail);
|
|
285 QUIT;
|
195
|
286 if (internal_equal (name, XPROCESS (proc)->name, 0))
|
173
|
287 return XCAR (tail);
|
0
|
288 }
|
|
289 return Qnil;
|
|
290 }
|
|
291
|
20
|
292 DEFUN ("get-buffer-process", Fget_buffer_process, 1, 1, 0, /*
|
0
|
293 Return the (or, a) process associated with BUFFER.
|
|
294 BUFFER may be a buffer or the name of one.
|
20
|
295 */
|
|
296 (name))
|
0
|
297 {
|
|
298 Lisp_Object buf, tail, proc;
|
|
299
|
|
300 if (GC_NILP (name)) return Qnil;
|
|
301 buf = Fget_buffer (name);
|
|
302 if (GC_NILP (buf)) return Qnil;
|
|
303
|
|
304 for (tail = Vprocess_list; GC_CONSP (tail); tail = XCDR (tail))
|
|
305 {
|
|
306 /* jwz: do not quit here - it isn't necessary, as there is no way for
|
|
307 Vprocess_list to get circular or overwhelmingly long, and this
|
|
308 function is called from layout_mode_element under redisplay. */
|
|
309 /* QUIT; */
|
|
310 proc = XCAR (tail);
|
|
311 if (GC_PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf))
|
|
312 return proc;
|
|
313 }
|
|
314 return Qnil;
|
|
315 }
|
|
316
|
|
317 /* This is how commands for the user decode process arguments. It
|
|
318 accepts a process, a process name, a buffer, a buffer name, or nil.
|
|
319 Buffers denote the first process in the buffer, and nil denotes the
|
|
320 current buffer. */
|
|
321
|
|
322 static Lisp_Object
|
|
323 get_process (Lisp_Object name)
|
|
324 {
|
136
|
325 Lisp_Object proc, obj;
|
0
|
326
|
|
327 #ifdef I18N3
|
|
328 /* #### Look more closely into translating process names. */
|
|
329 #endif
|
|
330
|
|
331 /* This may be called during a GC from process_send_signal() from
|
|
332 kill_buffer_processes() if emacs decides to abort(). */
|
|
333 if (GC_PROCESSP (name))
|
|
334 return name;
|
|
335
|
136
|
336 if (GC_STRINGP (name))
|
|
337 {
|
|
338 obj = Fget_process (name);
|
|
339 if (GC_NILP (obj))
|
|
340 obj = Fget_buffer (name);
|
|
341 if (GC_NILP (obj))
|
|
342 error ("Process %s does not exist", XSTRING_DATA (name));
|
|
343 }
|
|
344 else if (GC_NILP (name))
|
|
345 obj = Fcurrent_buffer ();
|
|
346 else
|
|
347 obj = name;
|
|
348
|
|
349 /* Now obj should be either a buffer object or a process object.
|
|
350 */
|
|
351 if (GC_BUFFERP (obj))
|
|
352 {
|
|
353 proc = Fget_buffer_process (obj);
|
|
354 if (GC_NILP (proc))
|
|
355 error ("Buffer %s has no process", XSTRING_DATA (XBUFFER(obj)->name));
|
|
356 }
|
0
|
357 else
|
|
358 {
|
263
|
359 /* #### This was commented out. Although, simple
|
|
360 (kill-process 7 "qqq") resulted in a falat error. - kkm */
|
|
361 CHECK_PROCESS (obj);
|
136
|
362 proc = obj;
|
0
|
363 }
|
136
|
364 return proc;
|
0
|
365 }
|
|
366
|
20
|
367 DEFUN ("process-id", Fprocess_id, 1, 1, 0, /*
|
0
|
368 Return the process id of PROCESS.
|
|
369 This is the pid of the Unix process which PROCESS uses or talks to.
|
|
370 For a network connection, this value is a cons of
|
|
371 (foreign-network-port . foreign-host-name).
|
20
|
372 */
|
|
373 (proc))
|
0
|
374 {
|
|
375 Lisp_Object pid;
|
|
376 CHECK_PROCESS (proc);
|
|
377
|
|
378 pid = XPROCESS (proc)->pid;
|
|
379 if (network_connection_p (proc))
|
173
|
380 /* return Qnil; */
|
|
381 return Fcons (Fcar (pid), Fcdr (pid));
|
0
|
382 else
|
173
|
383 return pid;
|
0
|
384 }
|
|
385
|
20
|
386 DEFUN ("process-name", Fprocess_name, 1, 1, 0, /*
|
0
|
387 Return the name of PROCESS, as a string.
|
|
388 This is the name of the program invoked in PROCESS,
|
|
389 possibly modified to make it unique among process names.
|
20
|
390 */
|
|
391 (proc))
|
0
|
392 {
|
|
393 CHECK_PROCESS (proc);
|
|
394 return XPROCESS (proc)->name;
|
|
395 }
|
|
396
|
20
|
397 DEFUN ("process-command", Fprocess_command, 1, 1, 0, /*
|
0
|
398 Return the command that was executed to start PROCESS.
|
|
399 This is a list of strings, the first string being the program executed
|
|
400 and the rest of the strings being the arguments given to it.
|
20
|
401 */
|
|
402 (proc))
|
0
|
403 {
|
|
404 CHECK_PROCESS (proc);
|
|
405 return XPROCESS (proc)->command;
|
|
406 }
|
|
407
|
|
408
|
|
409 /************************************************************************/
|
|
410 /* creating a process */
|
|
411 /************************************************************************/
|
|
412
|
263
|
413 Lisp_Object
|
0
|
414 make_process_internal (Lisp_Object name)
|
|
415 {
|
|
416 Lisp_Object val, name1;
|
|
417 int i;
|
185
|
418 struct Lisp_Process *p =
|
|
419 alloc_lcrecord_type (struct Lisp_Process, lrecord_process);
|
0
|
420
|
|
421 /* If name is already in use, modify it until it is unused. */
|
|
422 name1 = name;
|
|
423 for (i = 1; ; i++)
|
|
424 {
|
|
425 char suffix[10];
|
|
426 Lisp_Object tem = Fget_process (name1);
|
185
|
427 if (NILP (tem))
|
0
|
428 break;
|
|
429 sprintf (suffix, "<%d>", i);
|
|
430 name1 = concat2 (name, build_string (suffix));
|
|
431 }
|
|
432 name = name1;
|
|
433 p->name = name;
|
|
434
|
|
435 p->command = Qnil;
|
|
436 p->filter = Qnil;
|
|
437 p->sentinel = Qnil;
|
|
438 p->buffer = Qnil;
|
|
439 p->mark = Fmake_marker ();
|
|
440 p->pid = Qnil;
|
|
441 p->status_symbol = Qrun;
|
|
442 p->exit_code = 0;
|
|
443 p->core_dumped = 0;
|
|
444 p->filter_does_read = 0;
|
|
445 p->kill_without_query = 0;
|
|
446 p->selected = 0;
|
|
447 p->tick = 0;
|
|
448 p->update_tick = 0;
|
263
|
449 p->pipe_instream = Qnil;
|
|
450 p->pipe_outstream = Qnil;
|
|
451 #ifdef FILE_CODING
|
|
452 p->coding_instream = Qnil;
|
|
453 p->coding_outstream = Qnil;
|
|
454 #endif
|
|
455
|
|
456 p->process_data = 0;
|
|
457 MAYBE_PROCMETH (alloc_process_data, (p));
|
0
|
458
|
|
459 XSETPROCESS (val, p);
|
|
460
|
|
461 Vprocess_list = Fcons (val, Vprocess_list);
|
173
|
462 return val;
|
0
|
463 }
|
|
464
|
263
|
465 void
|
|
466 init_process_io_handles (struct Lisp_Process *p, void* in, void* out, int flags)
|
0
|
467 {
|
263
|
468 USID usid = event_stream_create_stream_pair (in, out,
|
|
469 &p->pipe_instream, &p->pipe_outstream,
|
|
470 flags);
|
0
|
471
|
263
|
472 if (usid == USID_ERROR)
|
|
473 report_file_error ("Setting up communication with subprocess", Qnil);
|
272
|
474
|
263
|
475 if (usid != USID_DONTHASH)
|
0
|
476 {
|
263
|
477 Lisp_Object proc = Qnil;
|
|
478 XSETPROCESS (proc, p);
|
|
479 puthash ((CONST void*)usid, LISP_TO_VOID (proc), usid_to_process);
|
0
|
480 }
|
259
|
481
|
263
|
482 MAYBE_PROCMETH (init_process_io_handles, (p, in, out, flags));
|
259
|
483
|
263
|
484 #ifdef FILE_CODING
|
|
485 p->coding_instream = make_decoding_input_stream
|
|
486 (XLSTREAM (p->pipe_instream),
|
120
|
487 Fget_coding_system (Vcoding_system_for_read));
|
263
|
488 Lstream_set_character_mode (XLSTREAM (p->coding_instream));
|
|
489 p->coding_outstream = make_encoding_output_stream
|
|
490 (XLSTREAM (p->pipe_outstream),
|
120
|
491 Fget_coding_system (Vcoding_system_for_write));
|
70
|
492 /* CODE_CNTL (&out_state[outchannel]) |= CC_END; !!####
|
|
493 What's going on here? */
|
263
|
494 #endif /* FILE_CODING */
|
0
|
495 }
|
|
496
|
|
497 static void
|
185
|
498 create_process (Lisp_Object process,
|
0
|
499 char **new_argv, CONST char *current_dir)
|
|
500 {
|
|
501 struct Lisp_Process *p = XPROCESS (process);
|
263
|
502 int pid;
|
0
|
503
|
263
|
504 /* *_create_process may change status_symbol, if the process
|
|
505 is a kind of "fire-and-forget" (no I/O, unwaitable) */
|
0
|
506 p->status_symbol = Qrun;
|
|
507 p->exit_code = 0;
|
|
508
|
263
|
509 pid = PROCMETH (create_process, (p, new_argv, current_dir));
|
0
|
510
|
|
511 p->pid = make_int (pid);
|
263
|
512 if (!NILP(p->pipe_instream))
|
|
513 event_stream_select_process (p);
|
0
|
514 }
|
|
515
|
|
516 /* This function is the unwind_protect form for Fstart_process_internal. If
|
|
517 PROC doesn't have its pid set, then we know someone has signalled
|
|
518 an error and the process wasn't started successfully, so we should
|
|
519 remove it from the process list. */
|
|
520 static void remove_process (Lisp_Object proc);
|
|
521 static Lisp_Object
|
|
522 start_process_unwind (Lisp_Object proc)
|
|
523 {
|
|
524 /* Was PROC started successfully? */
|
|
525 if (EQ (XPROCESS (proc)->pid, Qnil))
|
|
526 remove_process (proc);
|
|
527 return Qnil;
|
|
528 }
|
|
529
|
20
|
530 DEFUN ("start-process-internal", Fstart_process_internal, 3, MANY, 0, /*
|
0
|
531 Start a program in a subprocess. Return the process object for it.
|
|
532 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS
|
|
533 NAME is name for process. It is modified if necessary to make it unique.
|
|
534 BUFFER is the buffer or (buffer-name) to associate with the process.
|
|
535 Process output goes at end of that buffer, unless you specify
|
|
536 an output stream or filter function to handle the output.
|
|
537 BUFFER may be also nil, meaning that this process is not associated
|
|
538 with any buffer
|
|
539 Third arg is program file name. It is searched for as in the shell.
|
|
540 Remaining arguments are strings to give program as arguments.
|
|
541 INCODE and OUTCODE specify the coding-system objects used in input/output
|
|
542 from/to the process.
|
20
|
543 */
|
|
544 (int nargs, Lisp_Object *args))
|
0
|
545 {
|
120
|
546 /* This function can call lisp */
|
0
|
547 /* !!#### This function has not been Mule-ized */
|
|
548 Lisp_Object buffer, name, program, proc, current_dir;
|
|
549 Lisp_Object tem;
|
|
550 int speccount = specpdl_depth ();
|
120
|
551 struct gcpro gcpro1, gcpro2, gcpro3;
|
0
|
552 char **new_argv;
|
|
553 int i;
|
|
554
|
120
|
555 name = args[0];
|
0
|
556 buffer = args[1];
|
120
|
557 program = args[2];
|
|
558 current_dir = Qnil;
|
|
559
|
|
560 /* Protect against various file handlers doing GCs below. */
|
|
561 GCPRO3 (buffer, program, current_dir);
|
|
562
|
0
|
563 if (!NILP (buffer))
|
|
564 buffer = Fget_buffer_create (buffer);
|
|
565
|
120
|
566 CHECK_STRING (name);
|
|
567 CHECK_STRING (program);
|
0
|
568
|
|
569 /* Make sure that the child will be able to chdir to the current
|
|
570 buffer's current directory, or its unhandled equivalent. We
|
|
571 can't just have the child check for an error when it does the
|
|
572 chdir, since it's in a vfork.
|
|
573
|
120
|
574 Note: these assignments and calls are like this in order to insure
|
|
575 "caller protects args" GC semantics. */
|
|
576 current_dir = current_buffer->directory;
|
|
577 current_dir = Funhandled_file_name_directory (current_dir);
|
|
578 current_dir = expand_and_dir_to_file (current_dir, Qnil);
|
|
579
|
0
|
580 #if 0 /* This loser breaks ange-ftp */
|
120
|
581 /* dmoore - if you re-enable this code, you have to gcprotect
|
|
582 current_buffer through the above calls. */
|
|
583 if (NILP (Ffile_accessible_directory_p (current_dir)))
|
|
584 report_file_error ("Setting current directory",
|
|
585 list1 (current_buffer->directory));
|
0
|
586 #endif /* 0 */
|
|
587
|
|
588 /* If program file name is not absolute, search our path for it */
|
82
|
589 if (!IS_DIRECTORY_SEP (XSTRING_BYTE (program, 0))
|
16
|
590 && !(XSTRING_LENGTH (program) > 1
|
82
|
591 && IS_DEVICE_SEP (XSTRING_BYTE (program, 1))))
|
0
|
592 {
|
120
|
593 struct gcpro ngcpro1;
|
70
|
594
|
0
|
595 tem = Qnil;
|
120
|
596 NGCPRO1 (tem);
|
0
|
597 locate_file (Vexec_path, program, EXEC_SUFFIXES, &tem,
|
|
598 X_OK);
|
|
599 if (NILP (tem))
|
|
600 report_file_error ("Searching for program", list1 (program));
|
120
|
601 program = Fexpand_file_name (tem, Qnil);
|
|
602 NUNGCPRO;
|
0
|
603 }
|
|
604 else
|
|
605 {
|
|
606 if (!NILP (Ffile_directory_p (program)))
|
|
607 error ("Specified program for new process is a directory");
|
|
608 }
|
|
609
|
120
|
610 /* Nothing below here GCs so our string pointers shouldn't move. */
|
185
|
611 new_argv = alloca_array (char *, nargs - 1);
|
120
|
612 new_argv[0] = (char *) XSTRING_DATA (program);
|
0
|
613 for (i = 3; i < nargs; i++)
|
|
614 {
|
|
615 tem = args[i];
|
|
616 CHECK_STRING (tem);
|
16
|
617 new_argv[i - 2] = (char *) XSTRING_DATA (tem);
|
0
|
618 }
|
|
619 new_argv[i - 2] = 0;
|
|
620
|
|
621 proc = make_process_internal (name);
|
|
622
|
|
623 XPROCESS (proc)->buffer = buffer;
|
|
624 XPROCESS (proc)->command = Flist (nargs - 2,
|
|
625 args + 2);
|
|
626
|
|
627 /* Make the process marker point into the process buffer (if any). */
|
|
628 if (!NILP (buffer))
|
|
629 Fset_marker (XPROCESS (proc)->mark,
|
|
630 make_int (BUF_ZV (XBUFFER (buffer))), buffer);
|
|
631
|
|
632 /* If an error occurs and we can't start the process, we want to
|
|
633 remove it from the process list. This means that each error
|
|
634 check in create_process doesn't need to call remove_process
|
|
635 itself; it's all taken care of here. */
|
|
636 record_unwind_protect (start_process_unwind, proc);
|
|
637
|
16
|
638 create_process (proc, new_argv, (char *) XSTRING_DATA (current_dir));
|
0
|
639
|
120
|
640 UNGCPRO;
|
0
|
641 return unbind_to (speccount, proc);
|
|
642 }
|
|
643
|
|
644
|
|
645 #ifdef HAVE_SOCKETS
|
|
646
|
|
647
|
263
|
648 /* #### The network support is fairly synthetical. What we actually
|
|
649 need is a single function, which supports all datagram, stream and
|
|
650 packet stream connections, arbitrary protocol families should they
|
|
651 be supported by the target system, multicast groups, in both data
|
|
652 and control rooted/nonrooted flavors, service quality etc whatever
|
|
653 is supported by the underlying network.
|
0
|
654
|
263
|
655 It must accept a property list describing the connection. The current
|
|
656 functions must then go to lisp and provide a suitable list for the
|
|
657 generalized connection function.
|
0
|
658
|
263
|
659 Both UNIX ans Win32 support BSD sockets, and there are many extensions
|
272
|
660 availalble (Sockets 2 spec).
|
0
|
661
|
263
|
662 A todo is define a consistent set of properties abstracting a
|
|
663 network connection. -kkm
|
|
664 */
|
|
665
|
0
|
666
|
|
667 /* open a TCP network connection to a given HOST/SERVICE. Treated
|
|
668 exactly like a normal process when reading and writing. Only
|
|
669 differences are in status display and process deletion. A network
|
|
670 connection has no PID; you cannot signal it. All you can do is
|
|
671 deactivate and close it via delete-process */
|
|
672
|
263
|
673 DEFUN ("open-network-stream-internal", Fopen_network_stream_internal, 4, 5, 0, /*
|
0
|
674 Open a TCP connection for a service to a host.
|
|
675 Returns a subprocess-object to represent the connection.
|
|
676 Input and output work as for subprocesses; `delete-process' closes it.
|
70
|
677
|
0
|
678 NAME is name for process. It is modified if necessary to make it unique.
|
|
679 BUFFER is the buffer (or buffer-name) to associate with the process.
|
|
680 Process output goes at end of that buffer, unless you specify
|
|
681 an output stream or filter function to handle the output.
|
70
|
682 BUFFER may also be nil, meaning that this process is not associated
|
|
683 with any buffer.
|
0
|
684 Third arg is name of the host to connect to, or its IP address.
|
|
685 Fourth arg SERVICE is name of the service desired, or an integer
|
|
686 specifying a port number to connect to.
|
263
|
687 Fifth argument FAMILY is a protocol family. When omitted, 'tcp/ip
|
272
|
688 \(Internet protocol family TCP/IP) is assumed.
|
20
|
689 */
|
263
|
690 (name, buffer, host, service, family))
|
0
|
691 {
|
|
692 /* !!#### This function has not been Mule-ized */
|
|
693 /* This function can GC */
|
263
|
694 Lisp_Object proc = Qnil;
|
|
695 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, ngcpro1;
|
|
696 void *inch, *outch;
|
0
|
697
|
263
|
698 GCPRO5 (name, buffer, host, service, family);
|
0
|
699 CHECK_STRING (name);
|
|
700
|
263
|
701 if (NILP(family))
|
|
702 family = Qtcpip;
|
|
703 else
|
|
704 CHECK_SYMBOL (family);
|
0
|
705
|
263
|
706 /* Since this code is inside HAVE_SOCKETS, existence of
|
|
707 open_network_stream is mandatory */
|
|
708 PROCMETH (open_network_stream, (name, host, service, family,
|
|
709 &inch, &outch));
|
272
|
710
|
0
|
711 if (!NILP (buffer))
|
|
712 buffer = Fget_buffer_create (buffer);
|
|
713 proc = make_process_internal (name);
|
263
|
714 NGCPRO1 (proc);
|
0
|
715
|
|
716 XPROCESS (proc)->pid = Fcons (service, host);
|
|
717 XPROCESS (proc)->buffer = buffer;
|
282
|
718 init_process_io_handles (XPROCESS (proc), (void*)inch, (void*)outch,
|
|
719 STREAM_NETWORK_CONNECTION);
|
0
|
720
|
|
721 event_stream_select_process (XPROCESS (proc));
|
|
722
|
|
723 UNGCPRO;
|
263
|
724 NUNGCPRO;
|
0
|
725 return proc;
|
|
726 }
|
|
727
|
259
|
728 #ifdef HAVE_MULTICAST
|
|
729
|
|
730 DEFUN ("open-multicast-group-internal", Fopen_multicast_group_internal, 5, 5, 0, /*
|
|
731 Open a multicast connection on the specified dest/port/ttl.
|
|
732 Returns a subprocess-object to represent the connection.
|
|
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.
|
|
741 Third, fourth and fifth args are the multicast destination group, port and ttl.
|
|
742 dest must be an internet address between 224.0.0.0 and 239.255.255.255
|
|
743 port is a communication port like in traditional unicast
|
|
744 ttl is the time-to-live (15 for site, 63 for region and 127 for world)
|
|
745 */
|
|
746 (name, buffer, dest, port, ttl))
|
|
747 {
|
|
748 /* !!#### This function has not been Mule-ized */
|
|
749 /* This function can GC */
|
263
|
750 Lisp_Object proc = Qnil;
|
259
|
751 struct gcpro gcpro1;
|
263
|
752 void *inch, *outch;
|
259
|
753
|
263
|
754 CHECK_STRING (name);
|
|
755
|
|
756 /* Since this code is inside HAVE_MULTICAST, existence of
|
|
757 open_network_stream is mandatory */
|
|
758 PROCMETH (open_multicast_group, (name, dest, port, ttl,
|
|
759 &inch, &outch));
|
272
|
760
|
259
|
761 if (!NILP (buffer))
|
|
762 buffer = Fget_buffer_create (buffer);
|
|
763
|
|
764 proc = make_process_internal (name);
|
|
765 GCPRO1 (proc);
|
|
766
|
|
767 XPROCESS (proc)->pid = Fcons (port, dest);
|
|
768 XPROCESS (proc)->buffer = buffer;
|
282
|
769 init_process_io_handles (XPROCESS (proc), (void*)inch, (void*)outch,
|
|
770 STREAM_NETWORK_CONNECTION);
|
272
|
771
|
259
|
772 event_stream_select_process (XPROCESS (proc));
|
272
|
773
|
259
|
774 UNGCPRO;
|
|
775 return proc;
|
|
776 }
|
|
777 #endif /* HAVE_MULTICAST */
|
|
778
|
0
|
779 #endif /* HAVE_SOCKETS */
|
|
780
|
|
781 Lisp_Object
|
|
782 canonicalize_host_name (Lisp_Object host)
|
|
783 {
|
263
|
784 return PROCMETH_OR_GIVEN (canonicalize_host_name, (host), host);
|
0
|
785 }
|
|
786
|
|
787
|
20
|
788 DEFUN ("set-process-window-size", Fset_process_window_size, 3, 3, 0, /*
|
0
|
789 Tell PROCESS that it has logical window size HEIGHT and WIDTH.
|
20
|
790 */
|
|
791 (proc, height, width))
|
0
|
792 {
|
|
793 CHECK_PROCESS (proc);
|
|
794 CHECK_NATNUM (height);
|
|
795 CHECK_NATNUM (width);
|
263
|
796 return
|
|
797 MAYBE_INT_PROCMETH (set_window_size, (XPROCESS (proc), XINT (height), XINT (width))) <= 0
|
|
798 ? Qnil : Qt;
|
0
|
799 }
|
|
800
|
|
801
|
|
802 /************************************************************************/
|
|
803 /* Process I/O */
|
|
804 /************************************************************************/
|
|
805
|
|
806 /* Read pending output from the process channel,
|
|
807 starting with our buffered-ahead character if we have one.
|
|
808 Yield number of characters read.
|
|
809
|
|
810 This function reads at most 1024 bytes.
|
|
811 If you want to read all available subprocess output,
|
|
812 you must call it repeatedly until it returns zero. */
|
|
813
|
|
814 Charcount
|
|
815 read_process_output (Lisp_Object proc)
|
|
816 {
|
|
817 /* This function can GC */
|
|
818 Bytecount nbytes, nchars;
|
|
819 Bufbyte chars[1024];
|
|
820 Lisp_Object outstream;
|
|
821 struct Lisp_Process *p = XPROCESS (proc);
|
|
822
|
|
823 /* If there is a lot of output from the subprocess, the loop in
|
|
824 execute_internal_event() might call read_process_output() more
|
|
825 than once. If the filter that was executed from one of these
|
|
826 calls set the filter to t, we have to stop now. Return -1 rather
|
|
827 than 0 so execute_internal_event() doesn't close the process.
|
|
828 Really, the loop in execute_internal_event() should check itself
|
|
829 for a process-filter change, like in status_notify(); but the
|
|
830 struct Lisp_Process is not exported outside of this file. */
|
263
|
831 if (NILP(p->pipe_instream))
|
0
|
832 return -1; /* already closed */
|
|
833
|
|
834 if (!NILP (p->filter) && (p->filter_does_read))
|
|
835 {
|
|
836 Lisp_Object filter_result;
|
|
837
|
|
838 /* Some weird FSFmacs crap here with
|
|
839 Vdeactivate_mark and current_buffer->keymap */
|
|
840 running_asynch_code = 1;
|
|
841 filter_result = call2_trapping_errors ("Error in process filter",
|
|
842 p->filter, proc, Qnil);
|
|
843 running_asynch_code = 0;
|
|
844 restore_match_data ();
|
|
845 CHECK_INT (filter_result);
|
|
846 return XINT (filter_result);
|
|
847 }
|
|
848
|
263
|
849 nbytes = Lstream_read (XLSTREAM (DATA_INSTREAM(p)), chars, sizeof (chars));
|
0
|
850 if (nbytes <= 0) return nbytes;
|
|
851
|
|
852 nchars = bytecount_to_charcount (chars, nbytes);
|
|
853 outstream = p->filter;
|
|
854 if (!NILP (outstream))
|
|
855 {
|
|
856 /* We used to bind inhibit-quit to t here, but
|
|
857 call2_trapping_errors() does that for us. */
|
|
858 running_asynch_code = 1;
|
|
859 call2_trapping_errors ("Error in process filter",
|
|
860 outstream, proc, make_string (chars, nbytes));
|
|
861 running_asynch_code = 0;
|
|
862 restore_match_data ();
|
173
|
863 return nchars;
|
0
|
864 }
|
|
865
|
|
866 /* If no filter, write into buffer if it isn't dead. */
|
|
867 if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer)))
|
|
868 {
|
|
869 Lisp_Object old_read_only = Qnil;
|
|
870 Bufpos old_point;
|
|
871 Bufpos old_begv;
|
|
872 Bufpos old_zv;
|
|
873 int old_zmacs_region_stays = zmacs_region_stays;
|
|
874 struct gcpro gcpro1, gcpro2;
|
|
875 struct buffer *buf = XBUFFER (p->buffer);
|
|
876
|
|
877 GCPRO2 (proc, old_read_only);
|
|
878
|
|
879 old_point = BUF_PT (buf);
|
|
880 old_begv = BUF_BEGV (buf);
|
|
881 old_zv = BUF_ZV (buf);
|
|
882 old_read_only = buf->read_only;
|
|
883 buf->read_only = Qnil;
|
|
884
|
|
885 /* Insert new output into buffer
|
|
886 at the current end-of-output marker,
|
|
887 thus preserving logical ordering of input and output. */
|
|
888 if (XMARKER (p->mark)->buffer)
|
|
889 BUF_SET_PT (buf,
|
|
890 bufpos_clip_to_bounds (old_begv, marker_position (p->mark),
|
|
891 old_zv));
|
|
892 else
|
|
893 BUF_SET_PT (buf, old_zv);
|
|
894
|
|
895 /* If the output marker is outside of the visible region, save
|
|
896 the restriction and widen. */
|
|
897 if (! (BUF_BEGV (buf) <= BUF_PT (buf) &&
|
|
898 BUF_PT (buf) <= BUF_ZV (buf)))
|
|
899 Fwiden (p->buffer);
|
|
900
|
|
901 /* Make sure opoint floats ahead of any new text, just as point
|
|
902 would. */
|
|
903 if (BUF_PT (buf) <= old_point)
|
|
904 old_point += nchars;
|
|
905
|
|
906 /* Insert after old_begv, but before old_zv. */
|
|
907 if (BUF_PT (buf) < old_begv)
|
|
908 old_begv += nchars;
|
|
909 if (BUF_PT (buf) <= old_zv)
|
|
910 old_zv += nchars;
|
|
911
|
|
912 #if 0
|
|
913 /* This screws up intial display of the window. jla */
|
|
914
|
|
915 /* Insert before markers in case we are inserting where
|
|
916 the buffer's mark is, and the user's next command is Meta-y. */
|
|
917 buffer_insert_raw_string_1 (buf, -1, chars,
|
|
918 nbytes, INSDEL_BEFORE_MARKERS);
|
|
919 #else
|
|
920 buffer_insert_raw_string (buf, chars, nbytes);
|
|
921 #endif
|
|
922
|
|
923 Fset_marker (p->mark, make_int (BUF_PT (buf)), p->buffer);
|
|
924
|
|
925 MARK_MODELINE_CHANGED;
|
|
926
|
|
927 /* If the restriction isn't what it should be, set it. */
|
|
928 if (old_begv != BUF_BEGV (buf) || old_zv != BUF_ZV (buf))
|
161
|
929 {
|
|
930 Fwiden(p->buffer);
|
|
931 old_begv = bufpos_clip_to_bounds (BUF_BEG (buf),
|
|
932 old_begv,
|
|
933 BUF_Z (buf));
|
|
934 old_zv = bufpos_clip_to_bounds (BUF_BEG (buf),
|
|
935 old_zv,
|
|
936 BUF_Z (buf));
|
|
937 Fnarrow_to_region (make_int (old_begv), make_int (old_zv),
|
|
938 p->buffer);
|
|
939 }
|
0
|
940
|
|
941 /* Handling the process output should not deactivate the mark. */
|
|
942 zmacs_region_stays = old_zmacs_region_stays;
|
|
943 buf->read_only = old_read_only;
|
161
|
944 old_point = bufpos_clip_to_bounds (BUF_BEGV (buf),
|
|
945 old_point,
|
|
946 BUF_ZV (buf));
|
0
|
947 BUF_SET_PT (buf, old_point);
|
|
948
|
|
949 UNGCPRO;
|
|
950 }
|
173
|
951 return nchars;
|
0
|
952 }
|
263
|
953
|
0
|
954 /* Sending data to subprocess */
|
|
955
|
|
956 /* send some data to process PROC. If NONRELOCATABLE is non-NULL, it
|
|
957 specifies the address of the data. Otherwise, the data comes from the
|
|
958 object RELOCATABLE (either a string or a buffer). START and LEN
|
|
959 specify the offset and length of the data to send.
|
|
960
|
|
961 Note that START and LEN are in Bufpos's if RELOCATABLE is a buffer,
|
|
962 and in Bytecounts otherwise. */
|
|
963
|
263
|
964 void
|
|
965 send_process (Lisp_Object proc,
|
0
|
966 Lisp_Object relocatable, CONST Bufbyte *nonrelocatable,
|
|
967 int start, int len)
|
|
968 {
|
|
969 /* This function can GC */
|
|
970 struct gcpro gcpro1, gcpro2;
|
|
971 Lisp_Object lstream = Qnil;
|
|
972
|
263
|
973 GCPRO2 (proc, lstream);
|
0
|
974
|
263
|
975 if (NILP (DATA_OUTSTREAM (XPROCESS (proc))))
|
0
|
976 signal_simple_error ("Process not open for writing", proc);
|
|
977
|
|
978 if (nonrelocatable)
|
|
979 lstream =
|
|
980 make_fixed_buffer_input_stream (nonrelocatable + start, len);
|
|
981 else if (GC_BUFFERP (relocatable))
|
|
982 lstream = make_lisp_buffer_input_stream (XBUFFER (relocatable),
|
|
983 start, start + len, 0);
|
|
984 else
|
|
985 lstream = make_lisp_string_input_stream (relocatable, start, len);
|
|
986
|
263
|
987 PROCMETH (send_process, (proc, XLSTREAM (lstream)));
|
0
|
988
|
|
989 UNGCPRO;
|
185
|
990 Lstream_delete (XLSTREAM (lstream));
|
0
|
991 }
|
|
992
|
20
|
993 DEFUN ("process-tty-name", Fprocess_tty_name, 1, 1, 0, /*
|
0
|
994 Return the name of the terminal PROCESS uses, or nil if none.
|
|
995 This is the terminal that the process itself reads and writes on,
|
|
996 not the name of the pty that Emacs uses to talk with that terminal.
|
20
|
997 */
|
|
998 (proc))
|
0
|
999 {
|
|
1000 CHECK_PROCESS (proc);
|
263
|
1001 return MAYBE_LISP_PROCMETH (get_tty_name, (XPROCESS (proc)));
|
0
|
1002 }
|
|
1003
|
20
|
1004 DEFUN ("set-process-buffer", Fset_process_buffer, 2, 2, 0, /*
|
0
|
1005 Set buffer associated with PROCESS to BUFFER (a buffer, or nil).
|
20
|
1006 */
|
|
1007 (proc, buffer))
|
0
|
1008 {
|
|
1009 CHECK_PROCESS (proc);
|
|
1010 if (!NILP (buffer))
|
|
1011 CHECK_BUFFER (buffer);
|
|
1012 XPROCESS (proc)->buffer = buffer;
|
|
1013 return buffer;
|
|
1014 }
|
|
1015
|
20
|
1016 DEFUN ("process-buffer", Fprocess_buffer, 1, 1, 0, /*
|
0
|
1017 Return the buffer PROCESS is associated with.
|
|
1018 Output from PROCESS is inserted in this buffer
|
|
1019 unless PROCESS has a filter.
|
20
|
1020 */
|
|
1021 (proc))
|
0
|
1022 {
|
|
1023 CHECK_PROCESS (proc);
|
|
1024 return XPROCESS (proc)->buffer;
|
|
1025 }
|
|
1026
|
20
|
1027 DEFUN ("process-mark", Fprocess_mark, 1, 1, 0, /*
|
0
|
1028 Return the marker for the end of the last output from PROCESS.
|
20
|
1029 */
|
|
1030 (proc))
|
0
|
1031 {
|
|
1032 CHECK_PROCESS (proc);
|
|
1033 return XPROCESS (proc)->mark;
|
|
1034 }
|
|
1035
|
|
1036 void
|
|
1037 set_process_filter (Lisp_Object proc, Lisp_Object filter, int filter_does_read)
|
|
1038 {
|
|
1039 CHECK_PROCESS (proc);
|
233
|
1040 if (PROCESS_LIVE_P (proc)) {
|
0
|
1041 if (EQ (filter, Qt))
|
|
1042 event_stream_unselect_process (XPROCESS (proc));
|
|
1043 else
|
|
1044 event_stream_select_process (XPROCESS (proc));
|
233
|
1045 }
|
0
|
1046
|
|
1047 XPROCESS (proc)->filter = filter;
|
|
1048 XPROCESS (proc)->filter_does_read = filter_does_read;
|
|
1049 }
|
|
1050
|
20
|
1051 DEFUN ("set-process-filter", Fset_process_filter, 2, 2, 0, /*
|
0
|
1052 Give PROCESS the filter function FILTER; nil means no filter.
|
|
1053 t means stop accepting output from the process.
|
|
1054 When a process has a filter, each time it does output
|
|
1055 the entire string of output is passed to the filter.
|
|
1056 The filter gets two arguments: the process and the string of output.
|
|
1057 If the process has a filter, its buffer is not used for output.
|
20
|
1058 */
|
|
1059 (proc, filter))
|
0
|
1060 {
|
|
1061 set_process_filter (proc, filter, 0);
|
|
1062 return filter;
|
|
1063 }
|
|
1064
|
20
|
1065 DEFUN ("process-filter", Fprocess_filter, 1, 1, 0, /*
|
0
|
1066 Return the filter function of PROCESS; nil if none.
|
|
1067 See `set-process-filter' for more info on filter functions.
|
20
|
1068 */
|
|
1069 (proc))
|
0
|
1070 {
|
|
1071 CHECK_PROCESS (proc);
|
|
1072 return XPROCESS (proc)->filter;
|
|
1073 }
|
|
1074
|
20
|
1075 DEFUN ("process-send-region", Fprocess_send_region, 3, 3, 0, /*
|
0
|
1076 Send current contents of region as input to PROCESS.
|
|
1077 PROCESS may be a process name or an actual process.
|
|
1078 Called from program, takes three arguments, PROCESS, START and END.
|
|
1079 If the region is more than 500 or so characters long,
|
|
1080 it is sent in several bunches. This may happen even for shorter regions.
|
|
1081 Output from processes can arrive in between bunches.
|
20
|
1082 */
|
|
1083 (process, start, end))
|
0
|
1084 {
|
|
1085 /* This function can GC */
|
|
1086 Lisp_Object proc = get_process (process);
|
|
1087 Bufpos st, en;
|
|
1088
|
|
1089 get_buffer_range_char (current_buffer, start, end, &st, &en, 0);
|
|
1090
|
|
1091 send_process (proc, Fcurrent_buffer (), 0,
|
|
1092 st, en - st);
|
173
|
1093 return Qnil;
|
0
|
1094 }
|
|
1095
|
20
|
1096 DEFUN ("process-send-string", Fprocess_send_string, 2, 4, 0, /*
|
0
|
1097 Send PROCESS the contents of STRING as input.
|
|
1098 PROCESS may be a process name or an actual process.
|
|
1099 Optional arguments FROM and TO specify part of STRING, see `substring'.
|
|
1100 If STRING is more than 500 or so characters long,
|
|
1101 it is sent in several bunches. This may happen even for shorter strings.
|
|
1102 Output from processes can arrive in between bunches.
|
20
|
1103 */
|
|
1104 (process, string, from, to))
|
0
|
1105 {
|
|
1106 /* This function can GC */
|
|
1107 Lisp_Object proc;
|
|
1108 Bytecount len;
|
|
1109 Bytecount bfr, bto;
|
|
1110
|
|
1111 proc = get_process (process);
|
|
1112 CHECK_STRING (string);
|
|
1113 get_string_range_byte (string, from, to, &bfr, &bto,
|
|
1114 GB_HISTORICAL_STRING_BEHAVIOR);
|
|
1115 len = bto - bfr;
|
|
1116
|
|
1117 send_process (proc, string, 0, bfr, len);
|
173
|
1118 return Qnil;
|
0
|
1119 }
|
|
1120
|
259
|
1121 #ifdef FILE_CODING
|
70
|
1122
|
|
1123 DEFUN ("process-input-coding-system", Fprocess_input_coding_system, 1, 1, 0, /*
|
|
1124 Return PROCESS's input coding system.
|
|
1125 */
|
|
1126 (process))
|
|
1127 {
|
|
1128 process = get_process (process);
|
263
|
1129 return decoding_stream_coding_system (XLSTREAM (XPROCESS (process)->coding_instream) );
|
70
|
1130 }
|
|
1131
|
|
1132 DEFUN ("process-output-coding-system", Fprocess_output_coding_system, 1, 1, 0, /*
|
|
1133 Return PROCESS's output coding system.
|
|
1134 */
|
|
1135 (process))
|
|
1136 {
|
|
1137 process = get_process (process);
|
263
|
1138 return encoding_stream_coding_system (XLSTREAM (XPROCESS (process)->coding_outstream));
|
70
|
1139 }
|
|
1140
|
120
|
1141 DEFUN ("process-coding-system", Fprocess_coding_system, 1, 1, 0, /*
|
|
1142 Return a pair of coding-system for decoding and encoding of PROCESS.
|
|
1143 */
|
|
1144 (process))
|
|
1145 {
|
|
1146 process = get_process (process);
|
175
|
1147 return Fcons (decoding_stream_coding_system
|
263
|
1148 (XLSTREAM (XPROCESS (process)->coding_instream)),
|
175
|
1149 encoding_stream_coding_system
|
263
|
1150 (XLSTREAM (XPROCESS (process)->coding_outstream)));
|
120
|
1151 }
|
|
1152
|
280
|
1153 DEFUN ("set-process-input-coding-system", Fset_process_input_coding_system,
|
|
1154 2, 2, 0, /*
|
70
|
1155 Set PROCESS's input coding system to CODESYS.
|
|
1156 */
|
|
1157 (process, codesys))
|
|
1158 {
|
|
1159 codesys = Fget_coding_system (codesys);
|
|
1160 process = get_process (process);
|
280
|
1161 set_decoding_stream_coding_system
|
|
1162 (XLSTREAM (XPROCESS (process)->coding_instream), codesys);
|
70
|
1163 return Qnil;
|
|
1164 }
|
|
1165
|
280
|
1166 DEFUN ("set-process-output-coding-system", Fset_process_output_coding_system,
|
|
1167 2, 2, 0, /*
|
70
|
1168 Set PROCESS's output coding system to CODESYS.
|
|
1169 */
|
|
1170 (process, codesys))
|
|
1171 {
|
|
1172 codesys = Fget_coding_system (codesys);
|
|
1173 process = get_process (process);
|
|
1174 set_encoding_stream_coding_system
|
280
|
1175 (XLSTREAM (XPROCESS (process)->coding_outstream), codesys);
|
70
|
1176 return Qnil;
|
|
1177 }
|
|
1178
|
280
|
1179 DEFUN ("set-process-coding-system", Fset_process_coding_system,
|
|
1180 1, 3, 0, /*
|
120
|
1181 Set coding-systems of PROCESS to DECODING and ENCODING.
|
|
1182 */
|
|
1183 (process, decoding, encoding))
|
|
1184 {
|
280
|
1185 if (!NILP (decoding))
|
|
1186 Fset_process_input_coding_system (process, decoding);
|
|
1187
|
|
1188 if (!NILP (encoding))
|
|
1189 Fset_process_output_coding_system (process, encoding);
|
|
1190
|
120
|
1191 return Qnil;
|
|
1192 }
|
|
1193
|
263
|
1194 #endif /* FILE_CODING */
|
0
|
1195
|
|
1196 /************************************************************************/
|
|
1197 /* process status */
|
|
1198 /************************************************************************/
|
|
1199
|
|
1200 static Lisp_Object
|
|
1201 exec_sentinel_unwind (Lisp_Object datum)
|
|
1202 {
|
|
1203 struct Lisp_Cons *d = XCONS (datum);
|
|
1204 XPROCESS (d->car)->sentinel = d->cdr;
|
|
1205 free_cons (d);
|
|
1206 return Qnil;
|
|
1207 }
|
|
1208
|
|
1209 static void
|
|
1210 exec_sentinel (Lisp_Object proc, Lisp_Object reason)
|
|
1211 {
|
|
1212 /* This function can GC */
|
175
|
1213 int speccount = specpdl_depth ();
|
0
|
1214 struct Lisp_Process *p = XPROCESS (proc);
|
175
|
1215 Lisp_Object sentinel = p->sentinel;
|
|
1216
|
0
|
1217 if (NILP (sentinel))
|
|
1218 return;
|
|
1219
|
|
1220 /* Some weird FSFmacs crap here with
|
|
1221 Vdeactivate_mark and current_buffer->keymap */
|
|
1222
|
|
1223 /* Zilch the sentinel while it's running, to avoid recursive invocations;
|
|
1224 assure that it gets restored no matter how the sentinel exits. */
|
|
1225 p->sentinel = Qnil;
|
|
1226 record_unwind_protect (exec_sentinel_unwind, noseeum_cons (proc, sentinel));
|
|
1227 /* We used to bind inhibit-quit to t here, but call2_trapping_errors()
|
|
1228 does that for us. */
|
|
1229 running_asynch_code = 1;
|
175
|
1230 call2_trapping_errors ("Error in process sentinel", sentinel, proc, reason);
|
0
|
1231 running_asynch_code = 0;
|
|
1232 restore_match_data ();
|
|
1233 unbind_to (speccount, Qnil);
|
|
1234 }
|
|
1235
|
20
|
1236 DEFUN ("set-process-sentinel", Fset_process_sentinel, 2, 2, 0, /*
|
0
|
1237 Give PROCESS the sentinel SENTINEL; nil for none.
|
|
1238 The sentinel is called as a function when the process changes state.
|
|
1239 It gets two arguments: the process, and a string describing the change.
|
20
|
1240 */
|
|
1241 (proc, sentinel))
|
0
|
1242 {
|
|
1243 CHECK_PROCESS (proc);
|
|
1244 XPROCESS (proc)->sentinel = sentinel;
|
|
1245 return sentinel;
|
|
1246 }
|
|
1247
|
20
|
1248 DEFUN ("process-sentinel", Fprocess_sentinel, 1, 1, 0, /*
|
0
|
1249 Return the sentinel of PROCESS; nil if none.
|
|
1250 See `set-process-sentinel' for more info on sentinels.
|
20
|
1251 */
|
|
1252 (proc))
|
0
|
1253 {
|
|
1254 CHECK_PROCESS (proc);
|
|
1255 return XPROCESS (proc)->sentinel;
|
|
1256 }
|
|
1257
|
|
1258
|
|
1259 CONST char *
|
|
1260 signal_name (int signum)
|
|
1261 {
|
|
1262 if (signum >= 0 && signum < NSIG)
|
173
|
1263 return (CONST char *) sys_siglist[signum];
|
209
|
1264
|
173
|
1265 return (CONST char *) GETTEXT ("unknown signal");
|
0
|
1266 }
|
|
1267
|
|
1268 void
|
|
1269 update_process_status (Lisp_Object p,
|
|
1270 Lisp_Object status_symbol,
|
|
1271 int exit_code,
|
|
1272 int core_dumped)
|
|
1273 {
|
|
1274 XPROCESS (p)->tick++;
|
|
1275 process_tick++;
|
|
1276 XPROCESS (p)->status_symbol = status_symbol;
|
|
1277 XPROCESS (p)->exit_code = exit_code;
|
|
1278 XPROCESS (p)->core_dumped = core_dumped;
|
|
1279 }
|
|
1280
|
|
1281 /* Return a string describing a process status list. */
|
|
1282
|
185
|
1283 static Lisp_Object
|
0
|
1284 status_message (struct Lisp_Process *p)
|
|
1285 {
|
|
1286 Lisp_Object symbol = p->status_symbol;
|
|
1287 int code = p->exit_code;
|
|
1288 int coredump = p->core_dumped;
|
|
1289 Lisp_Object string, string2;
|
|
1290
|
|
1291 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
|
|
1292 {
|
|
1293 string = build_string (signal_name (code));
|
|
1294 if (coredump)
|
|
1295 string2 = build_translated_string (" (core dumped)\n");
|
|
1296 else
|
|
1297 string2 = build_string ("\n");
|
|
1298 set_string_char (XSTRING (string), 0,
|
|
1299 DOWNCASE (current_buffer,
|
|
1300 string_char (XSTRING (string), 0)));
|
|
1301 return concat2 (string, string2);
|
|
1302 }
|
|
1303 else if (EQ (symbol, Qexit))
|
|
1304 {
|
|
1305 if (code == 0)
|
|
1306 return build_translated_string ("finished\n");
|
|
1307 string = Fnumber_to_string (make_int (code));
|
|
1308 if (coredump)
|
|
1309 string2 = build_translated_string (" (core dumped)\n");
|
|
1310 else
|
|
1311 string2 = build_string ("\n");
|
|
1312 return concat2 (build_translated_string ("exited abnormally with code "),
|
|
1313 concat2 (string, string2));
|
|
1314 }
|
|
1315 else
|
|
1316 return Fcopy_sequence (Fsymbol_name (symbol));
|
|
1317 }
|
|
1318
|
|
1319 /* Tell status_notify() to check for terminated processes. We do this
|
|
1320 because on some systems we sometimes miss SIGCHLD calls. (Not sure
|
|
1321 why.) */
|
|
1322
|
|
1323 void
|
|
1324 kick_status_notify (void)
|
|
1325 {
|
|
1326 process_tick++;
|
|
1327 }
|
|
1328
|
263
|
1329
|
0
|
1330 /* Report all recent events of a change in process status
|
|
1331 (either run the sentinel or output a message).
|
|
1332 This is done while Emacs is waiting for keyboard input. */
|
|
1333
|
|
1334 void
|
|
1335 status_notify (void)
|
|
1336 {
|
|
1337 /* This function can GC */
|
|
1338 Lisp_Object tail = Qnil;
|
|
1339 Lisp_Object symbol = Qnil;
|
|
1340 Lisp_Object msg = Qnil;
|
|
1341 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1342 /* process_tick is volatile, so we have to remember it now.
|
|
1343 Otherwise, we get a race condition is SIGCHLD happens during
|
|
1344 this function.
|
|
1345
|
|
1346 (Actually, this is not the case anymore. The code to
|
|
1347 update the process structures has been moved out of the
|
|
1348 SIGCHLD handler. But for the moment I'm leaving this
|
|
1349 stuff in -- it can't hurt.) */
|
|
1350 int temp_process_tick;
|
|
1351
|
263
|
1352 MAYBE_PROCMETH (reap_exited_processes, ());
|
0
|
1353
|
|
1354 temp_process_tick = process_tick;
|
|
1355
|
|
1356 if (update_tick == temp_process_tick)
|
|
1357 return;
|
|
1358
|
|
1359 /* We need to gcpro tail; if read_process_output calls a filter
|
|
1360 which deletes a process and removes the cons to which tail points
|
|
1361 from Vprocess_alist, and then causes a GC, tail is an unprotected
|
|
1362 reference. */
|
|
1363 GCPRO3 (tail, symbol, msg);
|
|
1364
|
|
1365 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
|
|
1366 {
|
|
1367 Lisp_Object proc = XCAR (tail);
|
|
1368 struct Lisp_Process *p = XPROCESS (proc);
|
|
1369 /* p->tick is also volatile. Same thing as above applies. */
|
|
1370 int this_process_tick;
|
|
1371
|
|
1372 /* #### extra check for terminated processes, in case a SIGCHLD
|
|
1373 got missed (this seems to happen sometimes, I'm not sure why).
|
|
1374 */
|
263
|
1375 if (INTP (p->pid))
|
|
1376 MAYBE_PROCMETH (update_status_if_terminated, (p));
|
|
1377
|
0
|
1378 this_process_tick = p->tick;
|
|
1379 if (this_process_tick != p->update_tick)
|
|
1380 {
|
|
1381 p->update_tick = this_process_tick;
|
|
1382
|
|
1383 /* If process is still active, read any output that remains. */
|
|
1384 while (!EQ (p->filter, Qt)
|
|
1385 && read_process_output (proc) > 0)
|
|
1386 ;
|
|
1387
|
|
1388 /* Get the text to use for the message. */
|
|
1389 msg = status_message (p);
|
|
1390
|
|
1391 /* If process is terminated, deactivate it or delete it. */
|
|
1392 symbol = p->status_symbol;
|
|
1393
|
185
|
1394 if (EQ (symbol, Qsignal)
|
0
|
1395 || EQ (symbol, Qexit))
|
|
1396 {
|
|
1397 if (delete_exited_processes)
|
|
1398 remove_process (proc);
|
|
1399 else
|
|
1400 deactivate_process (proc);
|
|
1401 }
|
|
1402
|
|
1403 /* Now output the message suitably. */
|
|
1404 if (!NILP (p->sentinel))
|
|
1405 exec_sentinel (proc, msg);
|
|
1406 /* Don't bother with a message in the buffer
|
|
1407 when a process becomes runnable. */
|
|
1408 else if (!EQ (symbol, Qrun) && !NILP (p->buffer))
|
|
1409 {
|
161
|
1410 Lisp_Object old_read_only = Qnil;
|
|
1411 Lisp_Object old = Fcurrent_buffer ();
|
|
1412 Bufpos opoint;
|
|
1413 struct gcpro ngcpro1, ngcpro2;
|
0
|
1414
|
|
1415 /* Avoid error if buffer is deleted
|
|
1416 (probably that's why the process is dead, too) */
|
|
1417 if (!BUFFER_LIVE_P (XBUFFER (p->buffer)))
|
|
1418 continue;
|
|
1419
|
161
|
1420 NGCPRO2 (old, old_read_only);
|
0
|
1421 Fset_buffer (p->buffer);
|
161
|
1422 opoint = BUF_PT (current_buffer);
|
0
|
1423 /* Insert new output into buffer
|
|
1424 at the current end-of-output marker,
|
|
1425 thus preserving logical ordering of input and output. */
|
|
1426 if (XMARKER (p->mark)->buffer)
|
|
1427 BUF_SET_PT (current_buffer, marker_position (p->mark));
|
|
1428 else
|
|
1429 BUF_SET_PT (current_buffer, BUF_ZV (current_buffer));
|
161
|
1430 if (BUF_PT (current_buffer) <= opoint)
|
|
1431 opoint += (string_char_length (XSTRING (msg))
|
|
1432 + string_char_length (XSTRING (p->name))
|
|
1433 + 10);
|
|
1434
|
|
1435 old_read_only = current_buffer->read_only;
|
|
1436 current_buffer->read_only = Qnil;
|
0
|
1437 buffer_insert_c_string (current_buffer, "\nProcess ");
|
|
1438 Finsert (1, &p->name);
|
|
1439 buffer_insert_c_string (current_buffer, " ");
|
|
1440 Finsert (1, &msg);
|
161
|
1441 current_buffer->read_only = old_read_only;
|
0
|
1442 Fset_marker (p->mark, make_int (BUF_PT (current_buffer)),
|
|
1443 p->buffer);
|
161
|
1444
|
|
1445 opoint = bufpos_clip_to_bounds(BUF_BEGV (XBUFFER (p->buffer)),
|
|
1446 opoint,
|
|
1447 BUF_ZV (XBUFFER (p->buffer)));
|
|
1448 BUF_SET_PT (current_buffer, opoint);
|
|
1449 Fset_buffer (old);
|
|
1450 NUNGCPRO;
|
0
|
1451 }
|
|
1452 }
|
|
1453 } /* end for */
|
|
1454
|
|
1455 /* in case buffers use %s in modeline-format */
|
|
1456 MARK_MODELINE_CHANGED;
|
|
1457 redisplay ();
|
|
1458
|
|
1459 update_tick = temp_process_tick;
|
|
1460
|
|
1461 UNGCPRO;
|
|
1462 }
|
|
1463
|
20
|
1464 DEFUN ("process-status", Fprocess_status, 1, 1, 0, /*
|
0
|
1465 Return the status of PROCESS.
|
|
1466 This is a symbol, one of these:
|
|
1467
|
175
|
1468 run -- for a process that is running.
|
|
1469 stop -- for a process stopped but continuable.
|
|
1470 exit -- for a process that has exited.
|
0
|
1471 signal -- for a process that has got a fatal signal.
|
175
|
1472 open -- for a network stream connection that is open.
|
0
|
1473 closed -- for a network stream connection that is closed.
|
175
|
1474 nil -- if arg is a process name and no such process exists.
|
|
1475
|
0
|
1476 PROCESS may be a process, a buffer, the name of a process or buffer, or
|
|
1477 nil, indicating the current buffer's process.
|
20
|
1478 */
|
|
1479 (proc))
|
0
|
1480 {
|
175
|
1481 Lisp_Object status_symbol;
|
0
|
1482
|
|
1483 if (STRINGP (proc))
|
|
1484 proc = Fget_process (proc);
|
|
1485 else
|
|
1486 proc = get_process (proc);
|
|
1487
|
|
1488 if (NILP (proc))
|
175
|
1489 return Qnil;
|
|
1490
|
|
1491 status_symbol = XPROCESS (proc)->status_symbol;
|
0
|
1492 if (network_connection_p (proc))
|
|
1493 {
|
175
|
1494 if (EQ (status_symbol, Qrun))
|
|
1495 status_symbol = Qopen;
|
|
1496 else if (EQ (status_symbol, Qexit))
|
|
1497 status_symbol = Qclosed;
|
0
|
1498 }
|
175
|
1499 return status_symbol;
|
0
|
1500 }
|
|
1501
|
20
|
1502 DEFUN ("process-exit-status", Fprocess_exit_status, 1, 1, 0, /*
|
0
|
1503 Return the exit status of PROCESS or the signal number that killed it.
|
|
1504 If PROCESS has not yet exited or died, return 0.
|
20
|
1505 */
|
|
1506 (proc))
|
0
|
1507 {
|
|
1508 CHECK_PROCESS (proc);
|
173
|
1509 return make_int (XPROCESS (proc)->exit_code);
|
0
|
1510 }
|
|
1511
|
|
1512
|
|
1513
|
|
1514 /* send a signal number SIGNO to PROCESS.
|
|
1515 CURRENT_GROUP means send to the process group that currently owns
|
|
1516 the terminal being used to communicate with PROCESS.
|
|
1517 This is used for various commands in shell mode.
|
|
1518 If NOMSG is zero, insert signal-announcements into process's buffers
|
|
1519 right away.
|
|
1520
|
|
1521 If we can, we try to signal PROCESS by sending control characters
|
|
1522 down the pty. This allows us to signal inferiors who have changed
|
|
1523 their uid, for which killpg would return an EPERM error. */
|
|
1524
|
|
1525 static void
|
263
|
1526 process_send_signal (Lisp_Object process, int signo,
|
0
|
1527 int current_group, int nomsg)
|
|
1528 {
|
|
1529 /* This function can GC */
|
263
|
1530 Lisp_Object proc = get_process (process);
|
0
|
1531
|
|
1532 if (network_connection_p (proc))
|
|
1533 error ("Network connection %s is not a subprocess",
|
263
|
1534 XSTRING_DATA (XPROCESS(proc)->name));
|
|
1535 if (!PROCESS_LIVE_P (proc))
|
0
|
1536 error ("Process %s is not active",
|
263
|
1537 XSTRING_DATA (XPROCESS(proc)->name));
|
0
|
1538
|
263
|
1539 MAYBE_PROCMETH (kill_child_process, (proc, signo, current_group, nomsg));
|
0
|
1540 }
|
|
1541
|
20
|
1542 DEFUN ("interrupt-process", Finterrupt_process, 0, 2, 0, /*
|
0
|
1543 Interrupt process PROCESS. May be process or name of one.
|
|
1544 Nil or no arg means current buffer's process.
|
|
1545 Second arg CURRENT-GROUP non-nil means send signal to
|
|
1546 the current process-group of the process's controlling terminal
|
|
1547 rather than to the process's own process group.
|
|
1548 If the process is a shell, this means interrupt current subjob
|
|
1549 rather than the shell.
|
20
|
1550 */
|
|
1551 (process, current_group))
|
0
|
1552 {
|
|
1553 /* This function can GC */
|
|
1554 process_send_signal (process, SIGINT, !NILP (current_group), 0);
|
|
1555 return process;
|
|
1556 }
|
|
1557
|
20
|
1558 DEFUN ("kill-process", Fkill_process, 0, 2, 0, /*
|
0
|
1559 Kill process PROCESS. May be process or name of one.
|
|
1560 See function `interrupt-process' for more details on usage.
|
20
|
1561 */
|
|
1562 (process, current_group))
|
0
|
1563 {
|
|
1564 /* This function can GC */
|
280
|
1565 #ifdef SIGKILL
|
263
|
1566 process_send_signal (process, SIGKILL, !NILP (current_group), 0);
|
280
|
1567 #else
|
|
1568 error ("kill-process: Not supported on this system");
|
|
1569 #endif
|
0
|
1570 return process;
|
|
1571 }
|
|
1572
|
20
|
1573 DEFUN ("quit-process", Fquit_process, 0, 2, 0, /*
|
0
|
1574 Send QUIT signal to process PROCESS. May be process or name of one.
|
|
1575 See function `interrupt-process' for more details on usage.
|
20
|
1576 */
|
|
1577 (process, current_group))
|
0
|
1578 {
|
|
1579 /* This function can GC */
|
280
|
1580 #ifdef SIGQUIT
|
263
|
1581 process_send_signal (process, SIGQUIT, !NILP (current_group), 0);
|
280
|
1582 #else
|
|
1583 error ("quit-process: Not supported on this system");
|
|
1584 #endif
|
0
|
1585 return process;
|
|
1586 }
|
|
1587
|
20
|
1588 DEFUN ("stop-process", Fstop_process, 0, 2, 0, /*
|
0
|
1589 Stop process PROCESS. May be process or name of one.
|
|
1590 See function `interrupt-process' for more details on usage.
|
20
|
1591 */
|
|
1592 (process, current_group))
|
0
|
1593 {
|
|
1594 /* This function can GC */
|
263
|
1595 #ifdef SIGTSTP
|
|
1596 process_send_signal (process, SIGTSTP, !NILP (current_group), 0);
|
0
|
1597 #else
|
263
|
1598 error ("stop-process: Not supported on this system");
|
0
|
1599 #endif
|
|
1600 return process;
|
|
1601 }
|
|
1602
|
20
|
1603 DEFUN ("continue-process", Fcontinue_process, 0, 2, 0, /*
|
0
|
1604 Continue process PROCESS. May be process or name of one.
|
|
1605 See function `interrupt-process' for more details on usage.
|
20
|
1606 */
|
|
1607 (process, current_group))
|
0
|
1608 {
|
|
1609 /* This function can GC */
|
|
1610 #ifdef SIGCONT
|
263
|
1611 process_send_signal (process, SIGCONT, !NILP (current_group), 0);
|
0
|
1612 #else
|
263
|
1613 error ("continue-process: Not supported on this system");
|
0
|
1614 #endif
|
|
1615 return process;
|
|
1616 }
|
|
1617
|
20
|
1618 DEFUN ("signal-process", Fsignal_process, 2, 2,
|
|
1619 "nProcess number: \nnSignal code: ", /*
|
0
|
1620 Send the process with process id PID the signal with code SIGCODE.
|
|
1621 PID must be an integer. The process need not be a child of this Emacs.
|
|
1622 SIGCODE may be an integer, or a symbol whose name is a signal name.
|
20
|
1623 */
|
|
1624 (pid, sigcode))
|
0
|
1625 {
|
|
1626 CHECK_INT (pid);
|
|
1627
|
|
1628 if (INTP (sigcode))
|
|
1629 ;
|
|
1630 else
|
|
1631 {
|
|
1632 Bufbyte *name;
|
|
1633
|
|
1634 CHECK_SYMBOL (sigcode);
|
|
1635 name = string_data (XSYMBOL (sigcode)->name);
|
|
1636
|
280
|
1637 #define handle_signal(signal) \
|
|
1638 else if (!strcmp ((CONST char *) name, #signal)) \
|
|
1639 XSETINT (sigcode, signal)
|
|
1640
|
0
|
1641 if (0)
|
|
1642 ;
|
280
|
1643 handle_signal (SIGINT); /* ANSI */
|
|
1644 handle_signal (SIGILL); /* ANSI */
|
|
1645 handle_signal (SIGABRT); /* ANSI */
|
|
1646 handle_signal (SIGFPE); /* ANSI */
|
|
1647 handle_signal (SIGSEGV); /* ANSI */
|
|
1648 handle_signal (SIGTERM); /* ANSI */
|
|
1649
|
0
|
1650 #ifdef SIGHUP
|
280
|
1651 handle_signal (SIGHUP); /* POSIX */
|
0
|
1652 #endif
|
|
1653 #ifdef SIGQUIT
|
280
|
1654 handle_signal (SIGQUIT); /* POSIX */
|
0
|
1655 #endif
|
280
|
1656 #ifdef SIGTRAP
|
|
1657 handle_signal (SIGTRAP); /* POSIX */
|
0
|
1658 #endif
|
|
1659 #ifdef SIGKILL
|
280
|
1660 handle_signal (SIGKILL); /* POSIX */
|
|
1661 #endif
|
|
1662 #ifdef SIGUSR1
|
|
1663 handle_signal (SIGUSR1); /* POSIX */
|
|
1664 #endif
|
|
1665 #ifdef SIGUSR2
|
|
1666 handle_signal (SIGUSR2); /* POSIX */
|
0
|
1667 #endif
|
280
|
1668 #ifdef SIGPIPE
|
|
1669 handle_signal (SIGPIPE); /* POSIX */
|
|
1670 #endif
|
|
1671 #ifdef SIGALRM
|
|
1672 handle_signal (SIGALRM); /* POSIX */
|
|
1673 #endif
|
|
1674 #ifdef SIGCHLD
|
|
1675 handle_signal (SIGCHLD); /* POSIX */
|
|
1676 #endif
|
|
1677 #ifdef SIGCONT
|
|
1678 handle_signal (SIGCONT); /* POSIX */
|
0
|
1679 #endif
|
280
|
1680 #ifdef SIGSTOP
|
|
1681 handle_signal (SIGSTOP); /* POSIX */
|
|
1682 #endif
|
|
1683 #ifdef SIGTSTP
|
|
1684 handle_signal (SIGTSTP); /* POSIX */
|
|
1685 #endif
|
|
1686 #ifdef SIGTTIN
|
|
1687 handle_signal (SIGTTIN); /* POSIX */
|
0
|
1688 #endif
|
280
|
1689 #ifdef SIGTTOU
|
|
1690 handle_signal (SIGTTOU); /* POSIX */
|
|
1691 #endif
|
|
1692
|
|
1693 #ifdef SIGBUS
|
|
1694 handle_signal (SIGBUS); /* XPG5 */
|
|
1695 #endif
|
|
1696 #ifdef SIGPOLL
|
|
1697 handle_signal (SIGPOLL); /* XPG5 */
|
|
1698 #endif
|
|
1699 #ifdef SIGPROF
|
|
1700 handle_signal (SIGPROF); /* XPG5 */
|
0
|
1701 #endif
|
|
1702 #ifdef SIGSYS
|
280
|
1703 handle_signal (SIGSYS); /* XPG5 */
|
0
|
1704 #endif
|
|
1705 #ifdef SIGURG
|
280
|
1706 handle_signal (SIGURG); /* XPG5 */
|
0
|
1707 #endif
|
|
1708 #ifdef SIGXCPU
|
280
|
1709 handle_signal (SIGXCPU); /* XPG5 */
|
0
|
1710 #endif
|
|
1711 #ifdef SIGXFSZ
|
280
|
1712 handle_signal (SIGXFSZ); /* XPG5 */
|
0
|
1713 #endif
|
|
1714 #ifdef SIGVTALRM
|
280
|
1715 handle_signal (SIGVTALRM); /* XPG5 */
|
0
|
1716 #endif
|
280
|
1717
|
|
1718 #ifdef SIGIO
|
|
1719 handle_signal (SIGIO); /* BSD 4.2 */
|
0
|
1720 #endif
|
|
1721 #ifdef SIGWINCH
|
280
|
1722 handle_signal (SIGWINCH); /* BSD 4.3 */
|
|
1723 #endif
|
|
1724
|
|
1725 #ifdef SIGEMT
|
|
1726 handle_signal (SIGEMT);
|
0
|
1727 #endif
|
|
1728 #ifdef SIGINFO
|
280
|
1729 handle_signal (SIGINFO);
|
|
1730 #endif
|
|
1731 #ifdef SIGHWE
|
|
1732 handle_signal (SIGHWE);
|
|
1733 #endif
|
|
1734 #ifdef SIGPRE
|
|
1735 handle_signal (SIGPRE);
|
|
1736 #endif
|
|
1737 #ifdef SIGUME
|
|
1738 handle_signal (SIGUME);
|
|
1739 #endif
|
|
1740 #ifdef SIGDLK
|
|
1741 handle_signal (SIGDLK);
|
|
1742 #endif
|
|
1743 #ifdef SIGCPULIM
|
|
1744 handle_signal (SIGCPULIM);
|
|
1745 #endif
|
|
1746 #ifdef SIGIOT
|
|
1747 handle_signal (SIGIOT);
|
|
1748 #endif
|
|
1749 #ifdef SIGLOST
|
|
1750 handle_signal (SIGLOST);
|
0
|
1751 #endif
|
280
|
1752 #ifdef SIGSTKFLT
|
|
1753 handle_signal (SIGSTKFLT);
|
|
1754 #endif
|
|
1755 #ifdef SIGUNUSED
|
|
1756 handle_signal (SIGUNUSED);
|
|
1757 #endif
|
|
1758 #ifdef SIGDANGER
|
|
1759 handle_signal (SIGDANGER);
|
|
1760 #endif
|
|
1761 #ifdef SIGMSG
|
|
1762 handle_signal (SIGMSG);
|
0
|
1763 #endif
|
280
|
1764 #ifdef SIGSOUND
|
|
1765 handle_signal (SIGSOUND);
|
|
1766 #endif
|
|
1767 #ifdef SIGRETRACT
|
|
1768 handle_signal (SIGRETRACT);
|
|
1769 #endif
|
|
1770 #ifdef SIGGRANT
|
|
1771 handle_signal (SIGGRANT);
|
|
1772 #endif
|
|
1773 #ifdef SIGPWR
|
|
1774 handle_signal (SIGPWR);
|
0
|
1775 #endif
|
|
1776 else
|
|
1777 error ("Undefined signal name %s", name);
|
|
1778 }
|
|
1779
|
|
1780 #undef handle_signal
|
|
1781
|
263
|
1782 return make_int (PROCMETH_OR_GIVEN (kill_process_by_pid,
|
|
1783 (XINT (pid), XINT (sigcode)), -1));
|
0
|
1784 }
|
|
1785
|
20
|
1786 DEFUN ("process-send-eof", Fprocess_send_eof, 0, 1, 0, /*
|
0
|
1787 Make PROCESS see end-of-file in its input.
|
|
1788 PROCESS may be a process, a buffer, the name of a process or buffer, or
|
|
1789 nil, indicating the current buffer's process.
|
|
1790 If PROCESS is a network connection, or is a process communicating
|
|
1791 through a pipe (as opposed to a pty), then you cannot send any more
|
|
1792 text to PROCESS after you call this function.
|
20
|
1793 */
|
|
1794 (process))
|
0
|
1795 {
|
|
1796 /* This function can GC */
|
280
|
1797 Lisp_Object proc = get_process (process);
|
0
|
1798
|
|
1799 /* Make sure the process is really alive. */
|
|
1800 if (! EQ (XPROCESS (proc)->status_symbol, Qrun))
|
16
|
1801 error ("Process %s not running", XSTRING_DATA (XPROCESS (proc)->name));
|
0
|
1802
|
263
|
1803 if (!MAYBE_INT_PROCMETH (process_send_eof, (proc)))
|
0
|
1804 {
|
267
|
1805 if (!NILP (DATA_OUTSTREAM (XPROCESS (proc))))
|
|
1806 {
|
|
1807 Lstream_close (XLSTREAM (DATA_OUTSTREAM (XPROCESS (proc))));
|
|
1808 event_stream_delete_stream_pair (Qnil, XPROCESS (proc)->pipe_outstream);
|
|
1809 XPROCESS (proc)->pipe_outstream = Qnil;
|
263
|
1810 #ifdef FILE_CODING
|
267
|
1811 XPROCESS (proc)->coding_outstream = Qnil;
|
0
|
1812 #endif
|
267
|
1813 }
|
0
|
1814 }
|
209
|
1815
|
0
|
1816 return process;
|
|
1817 }
|
|
1818
|
|
1819
|
|
1820 /************************************************************************/
|
|
1821 /* deleting a process */
|
|
1822 /************************************************************************/
|
|
1823
|
|
1824 void
|
|
1825 deactivate_process (Lisp_Object proc)
|
|
1826 {
|
|
1827 struct Lisp_Process *p = XPROCESS (proc);
|
263
|
1828 USID usid;
|
0
|
1829
|
263
|
1830 /* It's possible that we got as far in the process-creation
|
|
1831 process as creating the descriptors but didn't get so
|
|
1832 far as selecting the process for input. In this
|
|
1833 case, p->pid is nil: p->pid is set at the same time that
|
|
1834 the process is selected for input. */
|
|
1835 /* #### The comment does not look correct. event_stream_unselect_process
|
|
1836 is guarded by process->selected, so this is not a problem. - kkm*/
|
|
1837 /* Must call this before setting the streams to nil */
|
|
1838 event_stream_unselect_process (p);
|
0
|
1839
|
267
|
1840 if (!NILP (DATA_OUTSTREAM (p)))
|
|
1841 Lstream_close (XLSTREAM (DATA_OUTSTREAM (p)));
|
|
1842 if (!NILP (DATA_INSTREAM (p)))
|
|
1843 Lstream_close (XLSTREAM (DATA_INSTREAM (p)));
|
|
1844
|
263
|
1845 /* Provide minimal implementation for deactivate_process
|
|
1846 if there's no process-specific one */
|
|
1847 if (HAS_PROCMETH_P (deactivate_process))
|
|
1848 usid = PROCMETH (deactivate_process, (p));
|
|
1849 else
|
|
1850 usid = event_stream_delete_stream_pair (p->pipe_instream,
|
|
1851 p->pipe_outstream);
|
0
|
1852
|
263
|
1853 if (usid != USID_DONTHASH)
|
|
1854 remhash ((CONST void*)usid, usid_to_process);
|
|
1855
|
|
1856 p->pipe_instream = Qnil;
|
|
1857 p->pipe_outstream = Qnil;
|
|
1858 #ifdef FILE_CODING
|
|
1859 p->coding_instream = Qnil;
|
|
1860 p->coding_outstream = Qnil;
|
|
1861 #endif
|
0
|
1862 }
|
|
1863
|
|
1864 static void
|
|
1865 remove_process (Lisp_Object proc)
|
|
1866 {
|
|
1867 Vprocess_list = delq_no_quit (proc, Vprocess_list);
|
|
1868 Fset_marker (XPROCESS (proc)->mark, Qnil, Qnil);
|
|
1869
|
|
1870 deactivate_process (proc);
|
|
1871 }
|
|
1872
|
20
|
1873 DEFUN ("delete-process", Fdelete_process, 1, 1, 0, /*
|
0
|
1874 Delete PROCESS: kill it and forget about it immediately.
|
|
1875 PROCESS may be a process or the name of one, or a buffer name.
|
20
|
1876 */
|
|
1877 (proc))
|
0
|
1878 {
|
|
1879 /* This function can GC */
|
|
1880 struct Lisp_Process *p;
|
|
1881 proc = get_process (proc);
|
|
1882 p = XPROCESS (proc);
|
|
1883 if (network_connection_p (proc))
|
|
1884 {
|
|
1885 p->status_symbol = Qexit;
|
|
1886 p->exit_code = 0;
|
|
1887 p->core_dumped = 0;
|
|
1888 p->tick++;
|
|
1889 process_tick++;
|
|
1890 }
|
263
|
1891 else if (!NILP(p->pipe_instream))
|
0
|
1892 {
|
|
1893 Fkill_process (proc, Qnil);
|
|
1894 /* Do this now, since remove_process will make sigchld_handler do nothing. */
|
|
1895 p->status_symbol = Qsignal;
|
|
1896 p->exit_code = SIGKILL;
|
|
1897 p->core_dumped = 0;
|
|
1898 p->tick++;
|
|
1899 process_tick++;
|
|
1900 status_notify ();
|
|
1901 }
|
|
1902 remove_process (proc);
|
|
1903 return Qnil;
|
|
1904 }
|
|
1905
|
|
1906 /* Kill all processes associated with `buffer'.
|
|
1907 If `buffer' is nil, kill all processes */
|
|
1908
|
|
1909 void
|
|
1910 kill_buffer_processes (Lisp_Object buffer)
|
|
1911 {
|
|
1912 Lisp_Object tail;
|
|
1913
|
|
1914 for (tail = Vprocess_list; GC_CONSP (tail);
|
|
1915 tail = XCDR (tail))
|
|
1916 {
|
|
1917 Lisp_Object proc = XCAR (tail);
|
|
1918 if (GC_PROCESSP (proc)
|
|
1919 && (GC_NILP (buffer) || GC_EQ (XPROCESS (proc)->buffer, buffer)))
|
|
1920 {
|
|
1921 if (network_connection_p (proc))
|
|
1922 Fdelete_process (proc);
|
263
|
1923 else if (!NILP (XPROCESS (proc)->pipe_instream))
|
0
|
1924 process_send_signal (proc, SIGHUP, 0, 1);
|
|
1925 }
|
|
1926 }
|
|
1927 }
|
|
1928
|
20
|
1929 DEFUN ("process-kill-without-query", Fprocess_kill_without_query, 1, 2, 0, /*
|
0
|
1930 Say no query needed if PROCESS is running when Emacs is exited.
|
|
1931 Optional second argument if non-nil says to require a query.
|
|
1932 Value is t if a query was formerly required.
|
20
|
1933 */
|
|
1934 (proc, require_query_p))
|
0
|
1935 {
|
|
1936 int tem;
|
|
1937
|
|
1938 CHECK_PROCESS (proc);
|
|
1939 tem = XPROCESS (proc)->kill_without_query;
|
|
1940 XPROCESS (proc)->kill_without_query = NILP (require_query_p);
|
|
1941
|
173
|
1942 return tem ? Qnil : Qt;
|
0
|
1943 }
|
|
1944
|
20
|
1945 DEFUN ("process-kill-without-query-p", Fprocess_kill_without_query_p, 1, 1, 0, /*
|
0
|
1946 Whether PROC will be killed without query if running when emacs is exited.
|
20
|
1947 */
|
|
1948 (proc))
|
0
|
1949 {
|
|
1950 CHECK_PROCESS (proc);
|
173
|
1951 return XPROCESS (proc)->kill_without_query ? Qt : Qnil;
|
0
|
1952 }
|
|
1953
|
|
1954
|
|
1955 /* This is not named init_process in order to avoid a conflict with NS 3.3 */
|
|
1956 void
|
|
1957 init_xemacs_process (void)
|
|
1958 {
|
263
|
1959 MAYBE_PROCMETH (init_process, ());
|
0
|
1960
|
|
1961 Vprocess_list = Qnil;
|
263
|
1962 usid_to_process = make_hashtable (32);
|
0
|
1963 }
|
149
|
1964
|
0
|
1965 #if 0
|
|
1966
|
149
|
1967 xxDEFUN ("process-connection", Fprocess_connection, 0, 1, 0, /*
|
0
|
1968 Return the connection type of `PROCESS'. This can be nil (pipe),
|
|
1969 t or pty (pty) or stream (socket connection).
|
149
|
1970 */
|
|
1971 (process))
|
0
|
1972 {
|
|
1973 return XPROCESS (process)->type;
|
|
1974 }
|
|
1975
|
|
1976 #endif /* 0 */
|
|
1977
|
|
1978 void
|
|
1979 syms_of_process (void)
|
|
1980 {
|
|
1981 defsymbol (&Qprocessp, "processp");
|
|
1982 defsymbol (&Qrun, "run");
|
|
1983 defsymbol (&Qstop, "stop");
|
|
1984 defsymbol (&Qopen, "open");
|
|
1985 defsymbol (&Qclosed, "closed");
|
|
1986
|
263
|
1987 defsymbol (&Qtcpip, "tcp/ip");
|
|
1988
|
259
|
1989 #ifdef HAVE_MULTICAST
|
|
1990 defsymbol(&Qmulticast, "multicast"); /* Used for occasional warnings */
|
|
1991 #endif
|
|
1992
|
20
|
1993 DEFSUBR (Fprocessp);
|
|
1994 DEFSUBR (Fget_process);
|
|
1995 DEFSUBR (Fget_buffer_process);
|
|
1996 DEFSUBR (Fdelete_process);
|
|
1997 DEFSUBR (Fprocess_status);
|
|
1998 DEFSUBR (Fprocess_exit_status);
|
|
1999 DEFSUBR (Fprocess_id);
|
|
2000 DEFSUBR (Fprocess_name);
|
|
2001 DEFSUBR (Fprocess_tty_name);
|
|
2002 DEFSUBR (Fprocess_command);
|
|
2003 DEFSUBR (Fset_process_buffer);
|
|
2004 DEFSUBR (Fprocess_buffer);
|
|
2005 DEFSUBR (Fprocess_mark);
|
|
2006 DEFSUBR (Fset_process_filter);
|
|
2007 DEFSUBR (Fprocess_filter);
|
|
2008 DEFSUBR (Fset_process_window_size);
|
|
2009 DEFSUBR (Fset_process_sentinel);
|
|
2010 DEFSUBR (Fprocess_sentinel);
|
|
2011 DEFSUBR (Fprocess_kill_without_query);
|
|
2012 DEFSUBR (Fprocess_kill_without_query_p);
|
|
2013 DEFSUBR (Fprocess_list);
|
|
2014 DEFSUBR (Fstart_process_internal);
|
0
|
2015 #ifdef HAVE_SOCKETS
|
20
|
2016 DEFSUBR (Fopen_network_stream_internal);
|
259
|
2017 #ifdef HAVE_MULTICAST
|
|
2018 DEFSUBR (Fopen_multicast_group_internal);
|
|
2019 #endif /* HAVE_MULTICAST */
|
0
|
2020 #endif /* HAVE_SOCKETS */
|
20
|
2021 DEFSUBR (Fprocess_send_region);
|
|
2022 DEFSUBR (Fprocess_send_string);
|
|
2023 DEFSUBR (Finterrupt_process);
|
|
2024 DEFSUBR (Fkill_process);
|
|
2025 DEFSUBR (Fquit_process);
|
|
2026 DEFSUBR (Fstop_process);
|
|
2027 DEFSUBR (Fcontinue_process);
|
|
2028 DEFSUBR (Fprocess_send_eof);
|
|
2029 DEFSUBR (Fsignal_process);
|
|
2030 /* DEFSUBR (Fprocess_connection); */
|
259
|
2031 #ifdef FILE_CODING
|
70
|
2032 DEFSUBR (Fprocess_input_coding_system);
|
|
2033 DEFSUBR (Fprocess_output_coding_system);
|
|
2034 DEFSUBR (Fset_process_input_coding_system);
|
|
2035 DEFSUBR (Fset_process_output_coding_system);
|
120
|
2036 DEFSUBR (Fprocess_coding_system);
|
|
2037 DEFSUBR (Fset_process_coding_system);
|
263
|
2038 #endif /* FILE_CODING */
|
0
|
2039 }
|
|
2040
|
|
2041 void
|
|
2042 vars_of_process (void)
|
|
2043 {
|
|
2044 Fprovide (intern ("subprocesses"));
|
|
2045 #ifdef HAVE_SOCKETS
|
|
2046 Fprovide (intern ("network-streams"));
|
259
|
2047 #ifdef HAVE_MULTICAST
|
|
2048 Fprovide (intern ("multicast"));
|
|
2049 #endif /* HAVE_MULTICAST */
|
|
2050 #endif /* HAVE_SOCKETS */
|
0
|
2051 staticpro (&Vprocess_list);
|
|
2052
|
|
2053 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes /*
|
|
2054 *Non-nil means delete processes immediately when they exit.
|
|
2055 nil means don't delete them until `list-processes' is run.
|
|
2056 */ );
|
|
2057
|
|
2058 delete_exited_processes = 1;
|
|
2059
|
|
2060 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type /*
|
|
2061 Control type of device used to communicate with subprocesses.
|
|
2062 Values are nil to use a pipe, or t or `pty' to use a pty.
|
|
2063 The value has no effect if the system has no ptys or if all ptys are busy:
|
|
2064 then a pipe is used in any case.
|
|
2065 The value takes effect when `start-process' is called.
|
|
2066 */ );
|
|
2067 Vprocess_connection_type = Qt;
|
153
|
2068
|
278
|
2069 DEFVAR_BOOL ("windowed-process-io", &windowed_process_io /*
|
|
2070 Enables input/ouptut on standard handles of a windowed process.
|
|
2071 When this variable is nil (the default), XEmacs does not attempt to read
|
|
2072 standard output handle of a windowed process. Instead, the process is
|
|
2073 immediately marked as exited immediately upon successful launching. This is
|
|
2074 done because normal windowed processes do not use stadnard I/O, as they are
|
|
2075 not connected to any console.
|
|
2076
|
|
2077 When launching a specially crafted windowed process, which expects to be
|
|
2078 launched by XEmacs, or by other program which pipes its standard input and
|
|
2079 output, this variable must be set to non-nil, in which case XEmacs will
|
|
2080 treat this process just like a console process.
|
|
2081
|
|
2082 NOTE: You should never set this variable, only bind it.
|
|
2083
|
|
2084 Only Windows processes can be "windowed" or "console". This variable has no
|
|
2085 effect on UNIX processes, because all UNIX processes are "console".
|
|
2086 */ );
|
|
2087 windowed_process_io = 0;
|
|
2088
|
153
|
2089 #ifdef PROCESS_IO_BLOCKING
|
|
2090 DEFVAR_LISP ("network-stream-blocking-port-list", &network_stream_blocking_port_list /*
|
|
2091 List of port numbers or port names to set a blocking I/O mode with connection.
|
|
2092 Nil value means to set a default(non-blocking) I/O mode.
|
|
2093 The value takes effect when `open-network-stream-internal' is called.
|
|
2094 */ );
|
|
2095 network_stream_blocking_port_list = Qnil;
|
|
2096 #endif /* PROCESS_IO_BLOCKING */
|
0
|
2097 }
|
|
2098
|
|
2099 #endif /* not NO_SUBPROCESSES */
|