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 */
|
|
71 Lisp_Object Qrun, Qstop; /* Qexit from eval.c, Qsignal from data.c. */
|
|
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
|
153
|
85 #ifdef PROCESS_IO_BLOCKING
|
|
86 /* List of port numbers or port names to set a blocking I/O mode.
|
|
87 Nil means set a non-blocking I/O mode [default]. */
|
263
|
88 Lisp_Object network_stream_blocking_port_list;
|
153
|
89 #endif /* PROCESS_IO_BLOCKING */
|
|
90
|
0
|
91 /* Number of events of change of status of a process. */
|
263
|
92 volatile int process_tick;
|
0
|
93
|
|
94 /* Number of events for which the user or sentinel has been notified. */
|
|
95 static int update_tick;
|
|
96
|
|
97 /* Nonzero means delete a process right away if it exits. */
|
|
98 int delete_exited_processes;
|
|
99
|
263
|
100 /* Hashtable which maps USIDs as returned by create_stream_pair_cb to
|
|
101 process objects. Processes are not GC-protected through this! */
|
|
102 c_hashtable usid_to_process;
|
0
|
103
|
|
104 /* List of process objects. */
|
|
105 Lisp_Object Vprocess_list;
|
|
106
|
|
107
|
|
108 static Lisp_Object mark_process (Lisp_Object, void (*) (Lisp_Object));
|
|
109 static void print_process (Lisp_Object, Lisp_Object, int);
|
|
110 static void finalize_process (void *, int);
|
|
111 DEFINE_LRECORD_IMPLEMENTATION ("process", process,
|
|
112 mark_process, print_process, finalize_process,
|
|
113 0, 0, struct Lisp_Process);
|
|
114
|
|
115 static Lisp_Object
|
|
116 mark_process (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
117 {
|
|
118 struct Lisp_Process *proc = XPROCESS (obj);
|
263
|
119 MAYBE_PROCMETH (mark_process_data, (proc, markobj));
|
0
|
120 ((markobj) (proc->name));
|
|
121 ((markobj) (proc->command));
|
|
122 ((markobj) (proc->filter));
|
|
123 ((markobj) (proc->sentinel));
|
|
124 ((markobj) (proc->buffer));
|
|
125 ((markobj) (proc->mark));
|
|
126 ((markobj) (proc->pid));
|
263
|
127 ((markobj) (proc->pipe_instream));
|
|
128 ((markobj) (proc->pipe_outstream));
|
|
129 #ifdef FILE_CODING
|
|
130 ((markobj) (proc->coding_instream));
|
|
131 ((markobj) (proc->coding_outstream));
|
|
132 #endif
|
173
|
133 return proc->status_symbol;
|
0
|
134 }
|
|
135
|
|
136 static void
|
|
137 print_process (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
138 {
|
|
139 struct Lisp_Process *proc = XPROCESS (obj);
|
185
|
140
|
0
|
141 if (print_readably)
|
|
142 error ("printing unreadable object #<process %s>",
|
16
|
143 XSTRING_DATA (proc->name));
|
185
|
144
|
0
|
145 if (!escapeflag)
|
|
146 {
|
|
147 print_internal (proc->name, printcharfun, 0);
|
|
148 }
|
|
149 else
|
|
150 {
|
|
151 int netp = network_connection_p (obj);
|
|
152 write_c_string (((netp) ? GETTEXT ("#<network connection ") :
|
|
153 GETTEXT ("#<process ")), printcharfun);
|
|
154 print_internal (proc->name, printcharfun, 1);
|
|
155 write_c_string (((netp) ? " " : " pid "), printcharfun);
|
|
156 print_internal (proc->pid, printcharfun, 1);
|
|
157 write_c_string (" state:", printcharfun);
|
|
158 print_internal (proc->status_symbol, printcharfun, 1);
|
263
|
159 MAYBE_PROCMETH (print_process_data, (proc, printcharfun));
|
0
|
160 write_c_string (">", printcharfun);
|
|
161 }
|
|
162 }
|
|
163
|
|
164 #ifdef HAVE_WINDOW_SYSTEM
|
|
165 extern void debug_process_finalization (struct Lisp_Process *p);
|
|
166 #endif /* HAVE_WINDOW_SYSTEM */
|
|
167
|
|
168 static void
|
|
169 finalize_process (void *header, int for_disksave)
|
|
170 {
|
|
171 /* #### this probably needs to be tied into the tty event loop */
|
|
172 /* #### when there is one */
|
263
|
173 struct Lisp_Process *p = (struct Lisp_Process *) header;
|
0
|
174 #ifdef HAVE_WINDOW_SYSTEM
|
263
|
175 if (!for_disksave)
|
|
176 {
|
|
177 debug_process_finalization (p);
|
|
178 }
|
0
|
179 #endif /* HAVE_WINDOW_SYSTEM */
|
263
|
180
|
|
181 if (p->process_data)
|
|
182 {
|
|
183 MAYBE_PROCMETH (finalize_process_data, (p, for_disksave));
|
|
184 if (!for_disksave)
|
|
185 xfree (p->process_data);
|
|
186 }
|
0
|
187 }
|
|
188
|
|
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);
|
|
474
|
|
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
|
|
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
|
|
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));
|
|
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;
|
263
|
718 init_process_io_handles (XPROCESS (proc), (void*)inch, (void*)outch, 0);
|
0
|
719
|
|
720 event_stream_select_process (XPROCESS (proc));
|
|
721
|
|
722 UNGCPRO;
|
263
|
723 NUNGCPRO;
|
0
|
724 return proc;
|
|
725 }
|
|
726
|
259
|
727 #ifdef HAVE_MULTICAST
|
|
728
|
|
729 DEFUN ("open-multicast-group-internal", Fopen_multicast_group_internal, 5, 5, 0, /*
|
|
730 Open a multicast connection on the specified dest/port/ttl.
|
|
731 Returns a subprocess-object to represent the connection.
|
|
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.
|
|
740 Third, fourth and fifth args are the multicast destination group, port and ttl.
|
|
741 dest must be an internet address between 224.0.0.0 and 239.255.255.255
|
|
742 port is a communication port like in traditional unicast
|
|
743 ttl is the time-to-live (15 for site, 63 for region and 127 for world)
|
|
744 */
|
|
745 (name, buffer, dest, port, ttl))
|
|
746 {
|
|
747 /* !!#### This function has not been Mule-ized */
|
|
748 /* This function can GC */
|
263
|
749 Lisp_Object proc = Qnil;
|
259
|
750 struct gcpro gcpro1;
|
263
|
751 void *inch, *outch;
|
259
|
752
|
263
|
753 CHECK_STRING (name);
|
|
754
|
|
755 /* Since this code is inside HAVE_MULTICAST, existence of
|
|
756 open_network_stream is mandatory */
|
|
757 PROCMETH (open_multicast_group, (name, dest, port, ttl,
|
|
758 &inch, &outch));
|
259
|
759
|
|
760 if (!NILP (buffer))
|
|
761 buffer = Fget_buffer_create (buffer);
|
|
762
|
|
763 proc = make_process_internal (name);
|
|
764 GCPRO1 (proc);
|
|
765
|
|
766 XPROCESS (proc)->pid = Fcons (port, dest);
|
|
767 XPROCESS (proc)->buffer = buffer;
|
263
|
768 init_process_io_handles (XPROCESS (proc), (void*)inch, (void*)outch, 0);
|
259
|
769
|
|
770 event_stream_select_process (XPROCESS (proc));
|
|
771
|
|
772 UNGCPRO;
|
|
773 return proc;
|
|
774 }
|
|
775 #endif /* HAVE_MULTICAST */
|
|
776
|
0
|
777 #endif /* HAVE_SOCKETS */
|
|
778
|
|
779 Lisp_Object
|
|
780 canonicalize_host_name (Lisp_Object host)
|
|
781 {
|
263
|
782 return PROCMETH_OR_GIVEN (canonicalize_host_name, (host), host);
|
0
|
783 }
|
|
784
|
|
785
|
20
|
786 DEFUN ("set-process-window-size", Fset_process_window_size, 3, 3, 0, /*
|
0
|
787 Tell PROCESS that it has logical window size HEIGHT and WIDTH.
|
20
|
788 */
|
|
789 (proc, height, width))
|
0
|
790 {
|
|
791 CHECK_PROCESS (proc);
|
|
792 CHECK_NATNUM (height);
|
|
793 CHECK_NATNUM (width);
|
263
|
794 return
|
|
795 MAYBE_INT_PROCMETH (set_window_size, (XPROCESS (proc), XINT (height), XINT (width))) <= 0
|
|
796 ? Qnil : Qt;
|
0
|
797 }
|
|
798
|
|
799
|
|
800 /************************************************************************/
|
|
801 /* Process I/O */
|
|
802 /************************************************************************/
|
|
803
|
|
804 /* Read pending output from the process channel,
|
|
805 starting with our buffered-ahead character if we have one.
|
|
806 Yield number of characters read.
|
|
807
|
|
808 This function reads at most 1024 bytes.
|
|
809 If you want to read all available subprocess output,
|
|
810 you must call it repeatedly until it returns zero. */
|
|
811
|
|
812 Charcount
|
|
813 read_process_output (Lisp_Object proc)
|
|
814 {
|
|
815 /* This function can GC */
|
|
816 Bytecount nbytes, nchars;
|
|
817 Bufbyte chars[1024];
|
|
818 Lisp_Object outstream;
|
|
819 struct Lisp_Process *p = XPROCESS (proc);
|
|
820
|
|
821 /* If there is a lot of output from the subprocess, the loop in
|
|
822 execute_internal_event() might call read_process_output() more
|
|
823 than once. If the filter that was executed from one of these
|
|
824 calls set the filter to t, we have to stop now. Return -1 rather
|
|
825 than 0 so execute_internal_event() doesn't close the process.
|
|
826 Really, the loop in execute_internal_event() should check itself
|
|
827 for a process-filter change, like in status_notify(); but the
|
|
828 struct Lisp_Process is not exported outside of this file. */
|
263
|
829 if (NILP(p->pipe_instream))
|
0
|
830 return -1; /* already closed */
|
|
831
|
|
832 if (!NILP (p->filter) && (p->filter_does_read))
|
|
833 {
|
|
834 Lisp_Object filter_result;
|
|
835
|
|
836 /* Some weird FSFmacs crap here with
|
|
837 Vdeactivate_mark and current_buffer->keymap */
|
|
838 running_asynch_code = 1;
|
|
839 filter_result = call2_trapping_errors ("Error in process filter",
|
|
840 p->filter, proc, Qnil);
|
|
841 running_asynch_code = 0;
|
|
842 restore_match_data ();
|
|
843 CHECK_INT (filter_result);
|
|
844 return XINT (filter_result);
|
|
845 }
|
|
846
|
263
|
847 nbytes = Lstream_read (XLSTREAM (DATA_INSTREAM(p)), chars, sizeof (chars));
|
0
|
848 if (nbytes <= 0) return nbytes;
|
|
849
|
|
850 nchars = bytecount_to_charcount (chars, nbytes);
|
|
851 outstream = p->filter;
|
|
852 if (!NILP (outstream))
|
|
853 {
|
|
854 /* We used to bind inhibit-quit to t here, but
|
|
855 call2_trapping_errors() does that for us. */
|
|
856 running_asynch_code = 1;
|
|
857 call2_trapping_errors ("Error in process filter",
|
|
858 outstream, proc, make_string (chars, nbytes));
|
|
859 running_asynch_code = 0;
|
|
860 restore_match_data ();
|
173
|
861 return nchars;
|
0
|
862 }
|
|
863
|
|
864 /* If no filter, write into buffer if it isn't dead. */
|
|
865 if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer)))
|
|
866 {
|
|
867 Lisp_Object old_read_only = Qnil;
|
|
868 Bufpos old_point;
|
|
869 Bufpos old_begv;
|
|
870 Bufpos old_zv;
|
|
871 int old_zmacs_region_stays = zmacs_region_stays;
|
|
872 struct gcpro gcpro1, gcpro2;
|
|
873 struct buffer *buf = XBUFFER (p->buffer);
|
|
874
|
|
875 GCPRO2 (proc, old_read_only);
|
|
876
|
|
877 old_point = BUF_PT (buf);
|
|
878 old_begv = BUF_BEGV (buf);
|
|
879 old_zv = BUF_ZV (buf);
|
|
880 old_read_only = buf->read_only;
|
|
881 buf->read_only = Qnil;
|
|
882
|
|
883 /* Insert new output into buffer
|
|
884 at the current end-of-output marker,
|
|
885 thus preserving logical ordering of input and output. */
|
|
886 if (XMARKER (p->mark)->buffer)
|
|
887 BUF_SET_PT (buf,
|
|
888 bufpos_clip_to_bounds (old_begv, marker_position (p->mark),
|
|
889 old_zv));
|
|
890 else
|
|
891 BUF_SET_PT (buf, old_zv);
|
|
892
|
|
893 /* If the output marker is outside of the visible region, save
|
|
894 the restriction and widen. */
|
|
895 if (! (BUF_BEGV (buf) <= BUF_PT (buf) &&
|
|
896 BUF_PT (buf) <= BUF_ZV (buf)))
|
|
897 Fwiden (p->buffer);
|
|
898
|
|
899 /* Make sure opoint floats ahead of any new text, just as point
|
|
900 would. */
|
|
901 if (BUF_PT (buf) <= old_point)
|
|
902 old_point += nchars;
|
|
903
|
|
904 /* Insert after old_begv, but before old_zv. */
|
|
905 if (BUF_PT (buf) < old_begv)
|
|
906 old_begv += nchars;
|
|
907 if (BUF_PT (buf) <= old_zv)
|
|
908 old_zv += nchars;
|
|
909
|
|
910 #if 0
|
|
911 /* This screws up intial display of the window. jla */
|
|
912
|
|
913 /* Insert before markers in case we are inserting where
|
|
914 the buffer's mark is, and the user's next command is Meta-y. */
|
|
915 buffer_insert_raw_string_1 (buf, -1, chars,
|
|
916 nbytes, INSDEL_BEFORE_MARKERS);
|
|
917 #else
|
|
918 buffer_insert_raw_string (buf, chars, nbytes);
|
|
919 #endif
|
|
920
|
|
921 Fset_marker (p->mark, make_int (BUF_PT (buf)), p->buffer);
|
|
922
|
|
923 MARK_MODELINE_CHANGED;
|
|
924
|
|
925 /* If the restriction isn't what it should be, set it. */
|
|
926 if (old_begv != BUF_BEGV (buf) || old_zv != BUF_ZV (buf))
|
161
|
927 {
|
|
928 Fwiden(p->buffer);
|
|
929 old_begv = bufpos_clip_to_bounds (BUF_BEG (buf),
|
|
930 old_begv,
|
|
931 BUF_Z (buf));
|
|
932 old_zv = bufpos_clip_to_bounds (BUF_BEG (buf),
|
|
933 old_zv,
|
|
934 BUF_Z (buf));
|
|
935 Fnarrow_to_region (make_int (old_begv), make_int (old_zv),
|
|
936 p->buffer);
|
|
937 }
|
0
|
938
|
|
939 /* Handling the process output should not deactivate the mark. */
|
|
940 zmacs_region_stays = old_zmacs_region_stays;
|
|
941 buf->read_only = old_read_only;
|
161
|
942 old_point = bufpos_clip_to_bounds (BUF_BEGV (buf),
|
|
943 old_point,
|
|
944 BUF_ZV (buf));
|
0
|
945 BUF_SET_PT (buf, old_point);
|
|
946
|
|
947 UNGCPRO;
|
|
948 }
|
173
|
949 return nchars;
|
0
|
950 }
|
263
|
951
|
0
|
952 /* Sending data to subprocess */
|
|
953
|
|
954 /* send some data to process PROC. If NONRELOCATABLE is non-NULL, it
|
|
955 specifies the address of the data. Otherwise, the data comes from the
|
|
956 object RELOCATABLE (either a string or a buffer). START and LEN
|
|
957 specify the offset and length of the data to send.
|
|
958
|
|
959 Note that START and LEN are in Bufpos's if RELOCATABLE is a buffer,
|
|
960 and in Bytecounts otherwise. */
|
|
961
|
263
|
962 void
|
|
963 send_process (Lisp_Object proc,
|
0
|
964 Lisp_Object relocatable, CONST Bufbyte *nonrelocatable,
|
|
965 int start, int len)
|
|
966 {
|
|
967 /* This function can GC */
|
|
968 struct gcpro gcpro1, gcpro2;
|
|
969 Lisp_Object lstream = Qnil;
|
|
970
|
263
|
971 GCPRO2 (proc, lstream);
|
0
|
972
|
263
|
973 if (NILP (DATA_OUTSTREAM (XPROCESS (proc))))
|
0
|
974 signal_simple_error ("Process not open for writing", proc);
|
|
975
|
|
976 if (nonrelocatable)
|
|
977 lstream =
|
|
978 make_fixed_buffer_input_stream (nonrelocatable + start, len);
|
|
979 else if (GC_BUFFERP (relocatable))
|
|
980 lstream = make_lisp_buffer_input_stream (XBUFFER (relocatable),
|
|
981 start, start + len, 0);
|
|
982 else
|
|
983 lstream = make_lisp_string_input_stream (relocatable, start, len);
|
|
984
|
263
|
985 PROCMETH (send_process, (proc, XLSTREAM (lstream)));
|
0
|
986
|
|
987 UNGCPRO;
|
185
|
988 Lstream_delete (XLSTREAM (lstream));
|
0
|
989 }
|
|
990
|
20
|
991 DEFUN ("process-tty-name", Fprocess_tty_name, 1, 1, 0, /*
|
0
|
992 Return the name of the terminal PROCESS uses, or nil if none.
|
|
993 This is the terminal that the process itself reads and writes on,
|
|
994 not the name of the pty that Emacs uses to talk with that terminal.
|
20
|
995 */
|
|
996 (proc))
|
0
|
997 {
|
|
998 CHECK_PROCESS (proc);
|
263
|
999 return MAYBE_LISP_PROCMETH (get_tty_name, (XPROCESS (proc)));
|
0
|
1000 }
|
|
1001
|
20
|
1002 DEFUN ("set-process-buffer", Fset_process_buffer, 2, 2, 0, /*
|
0
|
1003 Set buffer associated with PROCESS to BUFFER (a buffer, or nil).
|
20
|
1004 */
|
|
1005 (proc, buffer))
|
0
|
1006 {
|
|
1007 CHECK_PROCESS (proc);
|
|
1008 if (!NILP (buffer))
|
|
1009 CHECK_BUFFER (buffer);
|
|
1010 XPROCESS (proc)->buffer = buffer;
|
|
1011 return buffer;
|
|
1012 }
|
|
1013
|
20
|
1014 DEFUN ("process-buffer", Fprocess_buffer, 1, 1, 0, /*
|
0
|
1015 Return the buffer PROCESS is associated with.
|
|
1016 Output from PROCESS is inserted in this buffer
|
|
1017 unless PROCESS has a filter.
|
20
|
1018 */
|
|
1019 (proc))
|
0
|
1020 {
|
|
1021 CHECK_PROCESS (proc);
|
|
1022 return XPROCESS (proc)->buffer;
|
|
1023 }
|
|
1024
|
20
|
1025 DEFUN ("process-mark", Fprocess_mark, 1, 1, 0, /*
|
0
|
1026 Return the marker for the end of the last output from PROCESS.
|
20
|
1027 */
|
|
1028 (proc))
|
0
|
1029 {
|
|
1030 CHECK_PROCESS (proc);
|
|
1031 return XPROCESS (proc)->mark;
|
|
1032 }
|
|
1033
|
|
1034 void
|
|
1035 set_process_filter (Lisp_Object proc, Lisp_Object filter, int filter_does_read)
|
|
1036 {
|
|
1037 CHECK_PROCESS (proc);
|
233
|
1038 if (PROCESS_LIVE_P (proc)) {
|
0
|
1039 if (EQ (filter, Qt))
|
|
1040 event_stream_unselect_process (XPROCESS (proc));
|
|
1041 else
|
|
1042 event_stream_select_process (XPROCESS (proc));
|
233
|
1043 }
|
0
|
1044
|
|
1045 XPROCESS (proc)->filter = filter;
|
|
1046 XPROCESS (proc)->filter_does_read = filter_does_read;
|
|
1047 }
|
|
1048
|
20
|
1049 DEFUN ("set-process-filter", Fset_process_filter, 2, 2, 0, /*
|
0
|
1050 Give PROCESS the filter function FILTER; nil means no filter.
|
|
1051 t means stop accepting output from the process.
|
|
1052 When a process has a filter, each time it does output
|
|
1053 the entire string of output is passed to the filter.
|
|
1054 The filter gets two arguments: the process and the string of output.
|
|
1055 If the process has a filter, its buffer is not used for output.
|
20
|
1056 */
|
|
1057 (proc, filter))
|
0
|
1058 {
|
|
1059 set_process_filter (proc, filter, 0);
|
|
1060 return filter;
|
|
1061 }
|
|
1062
|
20
|
1063 DEFUN ("process-filter", Fprocess_filter, 1, 1, 0, /*
|
0
|
1064 Return the filter function of PROCESS; nil if none.
|
|
1065 See `set-process-filter' for more info on filter functions.
|
20
|
1066 */
|
|
1067 (proc))
|
0
|
1068 {
|
|
1069 CHECK_PROCESS (proc);
|
|
1070 return XPROCESS (proc)->filter;
|
|
1071 }
|
|
1072
|
20
|
1073 DEFUN ("process-send-region", Fprocess_send_region, 3, 3, 0, /*
|
0
|
1074 Send current contents of region as input to PROCESS.
|
|
1075 PROCESS may be a process name or an actual process.
|
|
1076 Called from program, takes three arguments, PROCESS, START and END.
|
|
1077 If the region is more than 500 or so characters long,
|
|
1078 it is sent in several bunches. This may happen even for shorter regions.
|
|
1079 Output from processes can arrive in between bunches.
|
20
|
1080 */
|
|
1081 (process, start, end))
|
0
|
1082 {
|
|
1083 /* This function can GC */
|
|
1084 Lisp_Object proc = get_process (process);
|
|
1085 Bufpos st, en;
|
|
1086
|
|
1087 get_buffer_range_char (current_buffer, start, end, &st, &en, 0);
|
|
1088
|
|
1089 send_process (proc, Fcurrent_buffer (), 0,
|
|
1090 st, en - st);
|
173
|
1091 return Qnil;
|
0
|
1092 }
|
|
1093
|
20
|
1094 DEFUN ("process-send-string", Fprocess_send_string, 2, 4, 0, /*
|
0
|
1095 Send PROCESS the contents of STRING as input.
|
|
1096 PROCESS may be a process name or an actual process.
|
|
1097 Optional arguments FROM and TO specify part of STRING, see `substring'.
|
|
1098 If STRING is more than 500 or so characters long,
|
|
1099 it is sent in several bunches. This may happen even for shorter strings.
|
|
1100 Output from processes can arrive in between bunches.
|
20
|
1101 */
|
|
1102 (process, string, from, to))
|
0
|
1103 {
|
|
1104 /* This function can GC */
|
|
1105 Lisp_Object proc;
|
|
1106 Bytecount len;
|
|
1107 Bytecount bfr, bto;
|
|
1108
|
|
1109 proc = get_process (process);
|
|
1110 CHECK_STRING (string);
|
|
1111 get_string_range_byte (string, from, to, &bfr, &bto,
|
|
1112 GB_HISTORICAL_STRING_BEHAVIOR);
|
|
1113 len = bto - bfr;
|
|
1114
|
|
1115 send_process (proc, string, 0, bfr, len);
|
173
|
1116 return Qnil;
|
0
|
1117 }
|
|
1118
|
259
|
1119 #ifdef FILE_CODING
|
70
|
1120
|
|
1121 DEFUN ("process-input-coding-system", Fprocess_input_coding_system, 1, 1, 0, /*
|
|
1122 Return PROCESS's input coding system.
|
|
1123 */
|
|
1124 (process))
|
|
1125 {
|
|
1126 process = get_process (process);
|
263
|
1127 return decoding_stream_coding_system (XLSTREAM (XPROCESS (process)->coding_instream) );
|
70
|
1128 }
|
|
1129
|
|
1130 DEFUN ("process-output-coding-system", Fprocess_output_coding_system, 1, 1, 0, /*
|
|
1131 Return PROCESS's output coding system.
|
|
1132 */
|
|
1133 (process))
|
|
1134 {
|
|
1135 process = get_process (process);
|
263
|
1136 return encoding_stream_coding_system (XLSTREAM (XPROCESS (process)->coding_outstream));
|
70
|
1137 }
|
|
1138
|
120
|
1139 DEFUN ("process-coding-system", Fprocess_coding_system, 1, 1, 0, /*
|
|
1140 Return a pair of coding-system for decoding and encoding of PROCESS.
|
|
1141 */
|
|
1142 (process))
|
|
1143 {
|
|
1144 process = get_process (process);
|
175
|
1145 return Fcons (decoding_stream_coding_system
|
263
|
1146 (XLSTREAM (XPROCESS (process)->coding_instream)),
|
175
|
1147 encoding_stream_coding_system
|
263
|
1148 (XLSTREAM (XPROCESS (process)->coding_outstream)));
|
120
|
1149 }
|
|
1150
|
70
|
1151 DEFUN ("set-process-input-coding-system",
|
|
1152 Fset_process_input_coding_system, 2, 2, 0, /*
|
|
1153 Set PROCESS's input coding system to CODESYS.
|
|
1154 */
|
|
1155 (process, codesys))
|
|
1156 {
|
|
1157 codesys = Fget_coding_system (codesys);
|
|
1158 process = get_process (process);
|
263
|
1159 set_decoding_stream_coding_system ( XLSTREAM ( XPROCESS (process)->coding_instream ), codesys);
|
70
|
1160 return Qnil;
|
|
1161 }
|
|
1162
|
|
1163 DEFUN ("set-process-output-coding-system",
|
|
1164 Fset_process_output_coding_system, 2, 2, 0, /*
|
|
1165 Set PROCESS's output coding system to CODESYS.
|
|
1166 */
|
|
1167 (process, codesys))
|
|
1168 {
|
|
1169 codesys = Fget_coding_system (codesys);
|
|
1170 process = get_process (process);
|
|
1171 set_encoding_stream_coding_system
|
263
|
1172 ( XLSTREAM ( XPROCESS (process)->coding_outstream), codesys);
|
70
|
1173 return Qnil;
|
|
1174 }
|
|
1175
|
120
|
1176 DEFUN ("set-process-coding-system",
|
|
1177 Fset_process_coding_system, 1, 3, 0, /*
|
|
1178 Set coding-systems of PROCESS to DECODING and ENCODING.
|
|
1179 */
|
|
1180 (process, decoding, encoding))
|
|
1181 {
|
|
1182 if(!NILP(decoding)){
|
|
1183 Fset_process_input_coding_system(process, decoding);
|
|
1184 }
|
|
1185 if(!NILP(encoding)){
|
|
1186 Fset_process_output_coding_system(process, encoding);
|
|
1187 }
|
|
1188 return Qnil;
|
|
1189 }
|
|
1190
|
263
|
1191 #endif /* FILE_CODING */
|
0
|
1192
|
|
1193 /************************************************************************/
|
|
1194 /* process status */
|
|
1195 /************************************************************************/
|
|
1196
|
|
1197 static Lisp_Object
|
|
1198 exec_sentinel_unwind (Lisp_Object datum)
|
|
1199 {
|
|
1200 struct Lisp_Cons *d = XCONS (datum);
|
|
1201 XPROCESS (d->car)->sentinel = d->cdr;
|
|
1202 free_cons (d);
|
|
1203 return Qnil;
|
|
1204 }
|
|
1205
|
|
1206 static void
|
|
1207 exec_sentinel (Lisp_Object proc, Lisp_Object reason)
|
|
1208 {
|
|
1209 /* This function can GC */
|
175
|
1210 int speccount = specpdl_depth ();
|
0
|
1211 struct Lisp_Process *p = XPROCESS (proc);
|
175
|
1212 Lisp_Object sentinel = p->sentinel;
|
|
1213
|
0
|
1214 if (NILP (sentinel))
|
|
1215 return;
|
|
1216
|
|
1217 /* Some weird FSFmacs crap here with
|
|
1218 Vdeactivate_mark and current_buffer->keymap */
|
|
1219
|
|
1220 /* Zilch the sentinel while it's running, to avoid recursive invocations;
|
|
1221 assure that it gets restored no matter how the sentinel exits. */
|
|
1222 p->sentinel = Qnil;
|
|
1223 record_unwind_protect (exec_sentinel_unwind, noseeum_cons (proc, sentinel));
|
|
1224 /* We used to bind inhibit-quit to t here, but call2_trapping_errors()
|
|
1225 does that for us. */
|
|
1226 running_asynch_code = 1;
|
175
|
1227 call2_trapping_errors ("Error in process sentinel", sentinel, proc, reason);
|
0
|
1228 running_asynch_code = 0;
|
|
1229 restore_match_data ();
|
|
1230 unbind_to (speccount, Qnil);
|
|
1231 }
|
|
1232
|
20
|
1233 DEFUN ("set-process-sentinel", Fset_process_sentinel, 2, 2, 0, /*
|
0
|
1234 Give PROCESS the sentinel SENTINEL; nil for none.
|
|
1235 The sentinel is called as a function when the process changes state.
|
|
1236 It gets two arguments: the process, and a string describing the change.
|
20
|
1237 */
|
|
1238 (proc, sentinel))
|
0
|
1239 {
|
|
1240 CHECK_PROCESS (proc);
|
|
1241 XPROCESS (proc)->sentinel = sentinel;
|
|
1242 return sentinel;
|
|
1243 }
|
|
1244
|
20
|
1245 DEFUN ("process-sentinel", Fprocess_sentinel, 1, 1, 0, /*
|
0
|
1246 Return the sentinel of PROCESS; nil if none.
|
|
1247 See `set-process-sentinel' for more info on sentinels.
|
20
|
1248 */
|
|
1249 (proc))
|
0
|
1250 {
|
|
1251 CHECK_PROCESS (proc);
|
|
1252 return XPROCESS (proc)->sentinel;
|
|
1253 }
|
|
1254
|
|
1255
|
|
1256 CONST char *
|
|
1257 signal_name (int signum)
|
|
1258 {
|
|
1259 if (signum >= 0 && signum < NSIG)
|
173
|
1260 return (CONST char *) sys_siglist[signum];
|
209
|
1261
|
173
|
1262 return (CONST char *) GETTEXT ("unknown signal");
|
0
|
1263 }
|
|
1264
|
|
1265 void
|
|
1266 update_process_status (Lisp_Object p,
|
|
1267 Lisp_Object status_symbol,
|
|
1268 int exit_code,
|
|
1269 int core_dumped)
|
|
1270 {
|
|
1271 XPROCESS (p)->tick++;
|
|
1272 process_tick++;
|
|
1273 XPROCESS (p)->status_symbol = status_symbol;
|
|
1274 XPROCESS (p)->exit_code = exit_code;
|
|
1275 XPROCESS (p)->core_dumped = core_dumped;
|
|
1276 }
|
|
1277
|
|
1278 /* Return a string describing a process status list. */
|
|
1279
|
185
|
1280 static Lisp_Object
|
0
|
1281 status_message (struct Lisp_Process *p)
|
|
1282 {
|
|
1283 Lisp_Object symbol = p->status_symbol;
|
|
1284 int code = p->exit_code;
|
|
1285 int coredump = p->core_dumped;
|
|
1286 Lisp_Object string, string2;
|
|
1287
|
|
1288 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
|
|
1289 {
|
|
1290 string = build_string (signal_name (code));
|
|
1291 if (coredump)
|
|
1292 string2 = build_translated_string (" (core dumped)\n");
|
|
1293 else
|
|
1294 string2 = build_string ("\n");
|
|
1295 set_string_char (XSTRING (string), 0,
|
|
1296 DOWNCASE (current_buffer,
|
|
1297 string_char (XSTRING (string), 0)));
|
|
1298 return concat2 (string, string2);
|
|
1299 }
|
|
1300 else if (EQ (symbol, Qexit))
|
|
1301 {
|
|
1302 if (code == 0)
|
|
1303 return build_translated_string ("finished\n");
|
|
1304 string = Fnumber_to_string (make_int (code));
|
|
1305 if (coredump)
|
|
1306 string2 = build_translated_string (" (core dumped)\n");
|
|
1307 else
|
|
1308 string2 = build_string ("\n");
|
|
1309 return concat2 (build_translated_string ("exited abnormally with code "),
|
|
1310 concat2 (string, string2));
|
|
1311 }
|
|
1312 else
|
|
1313 return Fcopy_sequence (Fsymbol_name (symbol));
|
|
1314 }
|
|
1315
|
|
1316 /* Tell status_notify() to check for terminated processes. We do this
|
|
1317 because on some systems we sometimes miss SIGCHLD calls. (Not sure
|
|
1318 why.) */
|
|
1319
|
|
1320 void
|
|
1321 kick_status_notify (void)
|
|
1322 {
|
|
1323 process_tick++;
|
|
1324 }
|
|
1325
|
263
|
1326
|
0
|
1327 /* Report all recent events of a change in process status
|
|
1328 (either run the sentinel or output a message).
|
|
1329 This is done while Emacs is waiting for keyboard input. */
|
|
1330
|
|
1331 void
|
|
1332 status_notify (void)
|
|
1333 {
|
|
1334 /* This function can GC */
|
|
1335 Lisp_Object tail = Qnil;
|
|
1336 Lisp_Object symbol = Qnil;
|
|
1337 Lisp_Object msg = Qnil;
|
|
1338 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1339 /* process_tick is volatile, so we have to remember it now.
|
|
1340 Otherwise, we get a race condition is SIGCHLD happens during
|
|
1341 this function.
|
|
1342
|
|
1343 (Actually, this is not the case anymore. The code to
|
|
1344 update the process structures has been moved out of the
|
|
1345 SIGCHLD handler. But for the moment I'm leaving this
|
|
1346 stuff in -- it can't hurt.) */
|
|
1347 int temp_process_tick;
|
|
1348
|
263
|
1349 MAYBE_PROCMETH (reap_exited_processes, ());
|
0
|
1350
|
|
1351 temp_process_tick = process_tick;
|
|
1352
|
|
1353 if (update_tick == temp_process_tick)
|
|
1354 return;
|
|
1355
|
|
1356 /* We need to gcpro tail; if read_process_output calls a filter
|
|
1357 which deletes a process and removes the cons to which tail points
|
|
1358 from Vprocess_alist, and then causes a GC, tail is an unprotected
|
|
1359 reference. */
|
|
1360 GCPRO3 (tail, symbol, msg);
|
|
1361
|
|
1362 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
|
|
1363 {
|
|
1364 Lisp_Object proc = XCAR (tail);
|
|
1365 struct Lisp_Process *p = XPROCESS (proc);
|
|
1366 /* p->tick is also volatile. Same thing as above applies. */
|
|
1367 int this_process_tick;
|
|
1368
|
|
1369 /* #### extra check for terminated processes, in case a SIGCHLD
|
|
1370 got missed (this seems to happen sometimes, I'm not sure why).
|
|
1371 */
|
263
|
1372 if (INTP (p->pid))
|
|
1373 MAYBE_PROCMETH (update_status_if_terminated, (p));
|
|
1374
|
0
|
1375 this_process_tick = p->tick;
|
|
1376 if (this_process_tick != p->update_tick)
|
|
1377 {
|
|
1378 p->update_tick = this_process_tick;
|
|
1379
|
|
1380 /* If process is still active, read any output that remains. */
|
|
1381 while (!EQ (p->filter, Qt)
|
|
1382 && read_process_output (proc) > 0)
|
|
1383 ;
|
|
1384
|
|
1385 /* Get the text to use for the message. */
|
|
1386 msg = status_message (p);
|
|
1387
|
|
1388 /* If process is terminated, deactivate it or delete it. */
|
|
1389 symbol = p->status_symbol;
|
|
1390
|
185
|
1391 if (EQ (symbol, Qsignal)
|
0
|
1392 || EQ (symbol, Qexit))
|
|
1393 {
|
|
1394 if (delete_exited_processes)
|
|
1395 remove_process (proc);
|
|
1396 else
|
|
1397 deactivate_process (proc);
|
|
1398 }
|
|
1399
|
|
1400 /* Now output the message suitably. */
|
|
1401 if (!NILP (p->sentinel))
|
|
1402 exec_sentinel (proc, msg);
|
|
1403 /* Don't bother with a message in the buffer
|
|
1404 when a process becomes runnable. */
|
|
1405 else if (!EQ (symbol, Qrun) && !NILP (p->buffer))
|
|
1406 {
|
161
|
1407 Lisp_Object old_read_only = Qnil;
|
|
1408 Lisp_Object old = Fcurrent_buffer ();
|
|
1409 Bufpos opoint;
|
|
1410 struct gcpro ngcpro1, ngcpro2;
|
0
|
1411
|
|
1412 /* Avoid error if buffer is deleted
|
|
1413 (probably that's why the process is dead, too) */
|
|
1414 if (!BUFFER_LIVE_P (XBUFFER (p->buffer)))
|
|
1415 continue;
|
|
1416
|
161
|
1417 NGCPRO2 (old, old_read_only);
|
0
|
1418 Fset_buffer (p->buffer);
|
161
|
1419 opoint = BUF_PT (current_buffer);
|
0
|
1420 /* Insert new output into buffer
|
|
1421 at the current end-of-output marker,
|
|
1422 thus preserving logical ordering of input and output. */
|
|
1423 if (XMARKER (p->mark)->buffer)
|
|
1424 BUF_SET_PT (current_buffer, marker_position (p->mark));
|
|
1425 else
|
|
1426 BUF_SET_PT (current_buffer, BUF_ZV (current_buffer));
|
161
|
1427 if (BUF_PT (current_buffer) <= opoint)
|
|
1428 opoint += (string_char_length (XSTRING (msg))
|
|
1429 + string_char_length (XSTRING (p->name))
|
|
1430 + 10);
|
|
1431
|
|
1432 old_read_only = current_buffer->read_only;
|
|
1433 current_buffer->read_only = Qnil;
|
0
|
1434 buffer_insert_c_string (current_buffer, "\nProcess ");
|
|
1435 Finsert (1, &p->name);
|
|
1436 buffer_insert_c_string (current_buffer, " ");
|
|
1437 Finsert (1, &msg);
|
161
|
1438 current_buffer->read_only = old_read_only;
|
0
|
1439 Fset_marker (p->mark, make_int (BUF_PT (current_buffer)),
|
|
1440 p->buffer);
|
161
|
1441
|
|
1442 opoint = bufpos_clip_to_bounds(BUF_BEGV (XBUFFER (p->buffer)),
|
|
1443 opoint,
|
|
1444 BUF_ZV (XBUFFER (p->buffer)));
|
|
1445 BUF_SET_PT (current_buffer, opoint);
|
|
1446 Fset_buffer (old);
|
|
1447 NUNGCPRO;
|
0
|
1448 }
|
|
1449 }
|
|
1450 } /* end for */
|
|
1451
|
|
1452 /* in case buffers use %s in modeline-format */
|
|
1453 MARK_MODELINE_CHANGED;
|
|
1454 redisplay ();
|
|
1455
|
|
1456 update_tick = temp_process_tick;
|
|
1457
|
|
1458 UNGCPRO;
|
|
1459 }
|
|
1460
|
20
|
1461 DEFUN ("process-status", Fprocess_status, 1, 1, 0, /*
|
0
|
1462 Return the status of PROCESS.
|
|
1463 This is a symbol, one of these:
|
|
1464
|
175
|
1465 run -- for a process that is running.
|
|
1466 stop -- for a process stopped but continuable.
|
|
1467 exit -- for a process that has exited.
|
0
|
1468 signal -- for a process that has got a fatal signal.
|
175
|
1469 open -- for a network stream connection that is open.
|
0
|
1470 closed -- for a network stream connection that is closed.
|
175
|
1471 nil -- if arg is a process name and no such process exists.
|
|
1472
|
0
|
1473 PROCESS may be a process, a buffer, the name of a process or buffer, or
|
|
1474 nil, indicating the current buffer's process.
|
20
|
1475 */
|
|
1476 (proc))
|
0
|
1477 {
|
175
|
1478 Lisp_Object status_symbol;
|
0
|
1479
|
|
1480 if (STRINGP (proc))
|
|
1481 proc = Fget_process (proc);
|
|
1482 else
|
|
1483 proc = get_process (proc);
|
|
1484
|
|
1485 if (NILP (proc))
|
175
|
1486 return Qnil;
|
|
1487
|
|
1488 status_symbol = XPROCESS (proc)->status_symbol;
|
0
|
1489 if (network_connection_p (proc))
|
|
1490 {
|
175
|
1491 if (EQ (status_symbol, Qrun))
|
|
1492 status_symbol = Qopen;
|
|
1493 else if (EQ (status_symbol, Qexit))
|
|
1494 status_symbol = Qclosed;
|
0
|
1495 }
|
175
|
1496 return status_symbol;
|
0
|
1497 }
|
|
1498
|
20
|
1499 DEFUN ("process-exit-status", Fprocess_exit_status, 1, 1, 0, /*
|
0
|
1500 Return the exit status of PROCESS or the signal number that killed it.
|
|
1501 If PROCESS has not yet exited or died, return 0.
|
20
|
1502 */
|
|
1503 (proc))
|
0
|
1504 {
|
|
1505 CHECK_PROCESS (proc);
|
173
|
1506 return make_int (XPROCESS (proc)->exit_code);
|
0
|
1507 }
|
|
1508
|
|
1509
|
|
1510
|
|
1511 /* send a signal number SIGNO to PROCESS.
|
|
1512 CURRENT_GROUP means send to the process group that currently owns
|
|
1513 the terminal being used to communicate with PROCESS.
|
|
1514 This is used for various commands in shell mode.
|
|
1515 If NOMSG is zero, insert signal-announcements into process's buffers
|
|
1516 right away.
|
|
1517
|
|
1518 If we can, we try to signal PROCESS by sending control characters
|
|
1519 down the pty. This allows us to signal inferiors who have changed
|
|
1520 their uid, for which killpg would return an EPERM error. */
|
|
1521
|
|
1522 static void
|
263
|
1523 process_send_signal (Lisp_Object process, int signo,
|
0
|
1524 int current_group, int nomsg)
|
|
1525 {
|
|
1526 /* This function can GC */
|
263
|
1527 Lisp_Object proc = get_process (process);
|
0
|
1528
|
|
1529 if (network_connection_p (proc))
|
|
1530 error ("Network connection %s is not a subprocess",
|
263
|
1531 XSTRING_DATA (XPROCESS(proc)->name));
|
|
1532 if (!PROCESS_LIVE_P (proc))
|
0
|
1533 error ("Process %s is not active",
|
263
|
1534 XSTRING_DATA (XPROCESS(proc)->name));
|
0
|
1535
|
263
|
1536 MAYBE_PROCMETH (kill_child_process, (proc, signo, current_group, nomsg));
|
0
|
1537 }
|
|
1538
|
20
|
1539 DEFUN ("interrupt-process", Finterrupt_process, 0, 2, 0, /*
|
0
|
1540 Interrupt process PROCESS. May be process or name of one.
|
|
1541 Nil or no arg means current buffer's process.
|
|
1542 Second arg CURRENT-GROUP non-nil means send signal to
|
|
1543 the current process-group of the process's controlling terminal
|
|
1544 rather than to the process's own process group.
|
|
1545 If the process is a shell, this means interrupt current subjob
|
|
1546 rather than the shell.
|
20
|
1547 */
|
|
1548 (process, current_group))
|
0
|
1549 {
|
|
1550 /* This function can GC */
|
|
1551 process_send_signal (process, SIGINT, !NILP (current_group), 0);
|
|
1552 return process;
|
|
1553 }
|
|
1554
|
20
|
1555 DEFUN ("kill-process", Fkill_process, 0, 2, 0, /*
|
0
|
1556 Kill process PROCESS. May be process or name of one.
|
|
1557 See function `interrupt-process' for more details on usage.
|
20
|
1558 */
|
|
1559 (process, current_group))
|
0
|
1560 {
|
|
1561 /* This function can GC */
|
263
|
1562 process_send_signal (process, SIGKILL, !NILP (current_group), 0);
|
0
|
1563 return process;
|
|
1564 }
|
|
1565
|
20
|
1566 DEFUN ("quit-process", Fquit_process, 0, 2, 0, /*
|
0
|
1567 Send QUIT signal to process PROCESS. May be process or name of one.
|
|
1568 See function `interrupt-process' for more details on usage.
|
20
|
1569 */
|
|
1570 (process, current_group))
|
0
|
1571 {
|
|
1572 /* This function can GC */
|
263
|
1573 process_send_signal (process, SIGQUIT, !NILP (current_group), 0);
|
0
|
1574 return process;
|
|
1575 }
|
|
1576
|
20
|
1577 DEFUN ("stop-process", Fstop_process, 0, 2, 0, /*
|
0
|
1578 Stop process PROCESS. May be process or name of one.
|
|
1579 See function `interrupt-process' for more details on usage.
|
20
|
1580 */
|
|
1581 (process, current_group))
|
0
|
1582 {
|
|
1583 /* This function can GC */
|
263
|
1584 #ifdef SIGTSTP
|
|
1585 process_send_signal (process, SIGTSTP, !NILP (current_group), 0);
|
0
|
1586 #else
|
263
|
1587 error ("stop-process: Not supported on this system");
|
0
|
1588 #endif
|
|
1589 return process;
|
|
1590 }
|
|
1591
|
20
|
1592 DEFUN ("continue-process", Fcontinue_process, 0, 2, 0, /*
|
0
|
1593 Continue process PROCESS. May be process or name of one.
|
|
1594 See function `interrupt-process' for more details on usage.
|
20
|
1595 */
|
|
1596 (process, current_group))
|
0
|
1597 {
|
|
1598 /* This function can GC */
|
|
1599 #ifdef SIGCONT
|
263
|
1600 process_send_signal (process, SIGCONT, !NILP (current_group), 0);
|
0
|
1601 #else
|
263
|
1602 error ("continue-process: Not supported on this system");
|
0
|
1603 #endif
|
|
1604 return process;
|
|
1605 }
|
|
1606
|
20
|
1607 DEFUN ("signal-process", Fsignal_process, 2, 2,
|
|
1608 "nProcess number: \nnSignal code: ", /*
|
0
|
1609 Send the process with process id PID the signal with code SIGCODE.
|
|
1610 PID must be an integer. The process need not be a child of this Emacs.
|
|
1611 SIGCODE may be an integer, or a symbol whose name is a signal name.
|
20
|
1612 */
|
|
1613 (pid, sigcode))
|
0
|
1614 {
|
|
1615 CHECK_INT (pid);
|
|
1616
|
|
1617 #define handle_signal(NAME, VALUE) \
|
|
1618 else if (!strcmp ((CONST char *) name, NAME)) \
|
|
1619 XSETINT (sigcode, VALUE)
|
|
1620
|
|
1621 if (INTP (sigcode))
|
|
1622 ;
|
|
1623 else
|
|
1624 {
|
|
1625 Bufbyte *name;
|
|
1626
|
|
1627 CHECK_SYMBOL (sigcode);
|
|
1628 name = string_data (XSYMBOL (sigcode)->name);
|
|
1629
|
|
1630 if (0)
|
|
1631 ;
|
|
1632 #ifdef SIGHUP
|
|
1633 handle_signal ("SIGHUP", SIGHUP);
|
|
1634 #endif
|
|
1635 #ifdef SIGINT
|
|
1636 handle_signal ("SIGINT", SIGINT);
|
|
1637 #endif
|
|
1638 #ifdef SIGQUIT
|
|
1639 handle_signal ("SIGQUIT", SIGQUIT);
|
|
1640 #endif
|
|
1641 #ifdef SIGILL
|
|
1642 handle_signal ("SIGILL", SIGILL);
|
|
1643 #endif
|
|
1644 #ifdef SIGABRT
|
|
1645 handle_signal ("SIGABRT", SIGABRT);
|
|
1646 #endif
|
|
1647 #ifdef SIGEMT
|
|
1648 handle_signal ("SIGEMT", SIGEMT);
|
|
1649 #endif
|
|
1650 #ifdef SIGKILL
|
|
1651 handle_signal ("SIGKILL", SIGKILL);
|
|
1652 #endif
|
|
1653 #ifdef SIGFPE
|
|
1654 handle_signal ("SIGFPE", SIGFPE);
|
|
1655 #endif
|
|
1656 #ifdef SIGBUS
|
|
1657 handle_signal ("SIGBUS", SIGBUS);
|
|
1658 #endif
|
|
1659 #ifdef SIGSEGV
|
|
1660 handle_signal ("SIGSEGV", SIGSEGV);
|
|
1661 #endif
|
|
1662 #ifdef SIGSYS
|
|
1663 handle_signal ("SIGSYS", SIGSYS);
|
|
1664 #endif
|
|
1665 #ifdef SIGPIPE
|
|
1666 handle_signal ("SIGPIPE", SIGPIPE);
|
|
1667 #endif
|
|
1668 #ifdef SIGALRM
|
|
1669 handle_signal ("SIGALRM", SIGALRM);
|
|
1670 #endif
|
|
1671 #ifdef SIGTERM
|
|
1672 handle_signal ("SIGTERM", SIGTERM);
|
|
1673 #endif
|
|
1674 #ifdef SIGURG
|
|
1675 handle_signal ("SIGURG", SIGURG);
|
|
1676 #endif
|
|
1677 #ifdef SIGSTOP
|
|
1678 handle_signal ("SIGSTOP", SIGSTOP);
|
|
1679 #endif
|
|
1680 #ifdef SIGTSTP
|
|
1681 handle_signal ("SIGTSTP", SIGTSTP);
|
|
1682 #endif
|
|
1683 #ifdef SIGCONT
|
|
1684 handle_signal ("SIGCONT", SIGCONT);
|
|
1685 #endif
|
|
1686 #ifdef SIGCHLD
|
|
1687 handle_signal ("SIGCHLD", SIGCHLD);
|
|
1688 #endif
|
|
1689 #ifdef SIGTTIN
|
|
1690 handle_signal ("SIGTTIN", SIGTTIN);
|
|
1691 #endif
|
|
1692 #ifdef SIGTTOU
|
|
1693 handle_signal ("SIGTTOU", SIGTTOU);
|
|
1694 #endif
|
|
1695 #ifdef SIGIO
|
|
1696 handle_signal ("SIGIO", SIGIO);
|
|
1697 #endif
|
|
1698 #ifdef SIGXCPU
|
|
1699 handle_signal ("SIGXCPU", SIGXCPU);
|
|
1700 #endif
|
|
1701 #ifdef SIGXFSZ
|
|
1702 handle_signal ("SIGXFSZ", SIGXFSZ);
|
|
1703 #endif
|
|
1704 #ifdef SIGVTALRM
|
|
1705 handle_signal ("SIGVTALRM", SIGVTALRM);
|
|
1706 #endif
|
|
1707 #ifdef SIGPROF
|
|
1708 handle_signal ("SIGPROF", SIGPROF);
|
|
1709 #endif
|
|
1710 #ifdef SIGWINCH
|
|
1711 handle_signal ("SIGWINCH", SIGWINCH);
|
|
1712 #endif
|
|
1713 #ifdef SIGINFO
|
|
1714 handle_signal ("SIGINFO", SIGINFO);
|
|
1715 #endif
|
|
1716 #ifdef SIGUSR1
|
|
1717 handle_signal ("SIGUSR1", SIGUSR1);
|
|
1718 #endif
|
|
1719 #ifdef SIGUSR2
|
|
1720 handle_signal ("SIGUSR2", SIGUSR2);
|
|
1721 #endif
|
|
1722 else
|
|
1723 error ("Undefined signal name %s", name);
|
|
1724 }
|
|
1725
|
|
1726 #undef handle_signal
|
|
1727
|
263
|
1728 return make_int (PROCMETH_OR_GIVEN (kill_process_by_pid,
|
|
1729 (XINT (pid), XINT (sigcode)), -1));
|
0
|
1730 }
|
|
1731
|
20
|
1732 DEFUN ("process-send-eof", Fprocess_send_eof, 0, 1, 0, /*
|
0
|
1733 Make PROCESS see end-of-file in its input.
|
|
1734 PROCESS may be a process, a buffer, the name of a process or buffer, or
|
|
1735 nil, indicating the current buffer's process.
|
|
1736 If PROCESS is a network connection, or is a process communicating
|
|
1737 through a pipe (as opposed to a pty), then you cannot send any more
|
|
1738 text to PROCESS after you call this function.
|
20
|
1739 */
|
|
1740 (process))
|
0
|
1741 {
|
|
1742 /* This function can GC */
|
|
1743 Lisp_Object proc;
|
|
1744
|
|
1745 proc = get_process (process);
|
|
1746
|
|
1747 /* Make sure the process is really alive. */
|
|
1748 if (! EQ (XPROCESS (proc)->status_symbol, Qrun))
|
16
|
1749 error ("Process %s not running", XSTRING_DATA (XPROCESS (proc)->name));
|
0
|
1750
|
263
|
1751 if (!MAYBE_INT_PROCMETH (process_send_eof, (proc)))
|
0
|
1752 {
|
267
|
1753 if (!NILP (DATA_OUTSTREAM (XPROCESS (proc))))
|
|
1754 {
|
|
1755 Lstream_close (XLSTREAM (DATA_OUTSTREAM (XPROCESS (proc))));
|
|
1756 event_stream_delete_stream_pair (Qnil, XPROCESS (proc)->pipe_outstream);
|
|
1757 XPROCESS (proc)->pipe_outstream = Qnil;
|
263
|
1758 #ifdef FILE_CODING
|
267
|
1759 XPROCESS (proc)->coding_outstream = Qnil;
|
0
|
1760 #endif
|
267
|
1761 }
|
0
|
1762 }
|
209
|
1763
|
0
|
1764 return process;
|
|
1765 }
|
|
1766
|
|
1767
|
|
1768 /************************************************************************/
|
|
1769 /* deleting a process */
|
|
1770 /************************************************************************/
|
|
1771
|
|
1772 void
|
|
1773 deactivate_process (Lisp_Object proc)
|
|
1774 {
|
|
1775 struct Lisp_Process *p = XPROCESS (proc);
|
263
|
1776 USID usid;
|
0
|
1777
|
263
|
1778 /* It's possible that we got as far in the process-creation
|
|
1779 process as creating the descriptors but didn't get so
|
|
1780 far as selecting the process for input. In this
|
|
1781 case, p->pid is nil: p->pid is set at the same time that
|
|
1782 the process is selected for input. */
|
|
1783 /* #### The comment does not look correct. event_stream_unselect_process
|
|
1784 is guarded by process->selected, so this is not a problem. - kkm*/
|
|
1785 /* Must call this before setting the streams to nil */
|
|
1786 event_stream_unselect_process (p);
|
0
|
1787
|
267
|
1788 if (!NILP (DATA_OUTSTREAM (p)))
|
|
1789 Lstream_close (XLSTREAM (DATA_OUTSTREAM (p)));
|
|
1790 if (!NILP (DATA_INSTREAM (p)))
|
|
1791 Lstream_close (XLSTREAM (DATA_INSTREAM (p)));
|
|
1792
|
263
|
1793 /* Provide minimal implementation for deactivate_process
|
|
1794 if there's no process-specific one */
|
|
1795 if (HAS_PROCMETH_P (deactivate_process))
|
|
1796 usid = PROCMETH (deactivate_process, (p));
|
|
1797 else
|
|
1798 usid = event_stream_delete_stream_pair (p->pipe_instream,
|
|
1799 p->pipe_outstream);
|
0
|
1800
|
263
|
1801 if (usid != USID_DONTHASH)
|
|
1802 remhash ((CONST void*)usid, usid_to_process);
|
|
1803
|
|
1804 p->pipe_instream = Qnil;
|
|
1805 p->pipe_outstream = Qnil;
|
|
1806 #ifdef FILE_CODING
|
|
1807 p->coding_instream = Qnil;
|
|
1808 p->coding_outstream = Qnil;
|
|
1809 #endif
|
0
|
1810 }
|
|
1811
|
|
1812 static void
|
|
1813 remove_process (Lisp_Object proc)
|
|
1814 {
|
|
1815 Vprocess_list = delq_no_quit (proc, Vprocess_list);
|
|
1816 Fset_marker (XPROCESS (proc)->mark, Qnil, Qnil);
|
|
1817
|
|
1818 deactivate_process (proc);
|
|
1819 }
|
|
1820
|
20
|
1821 DEFUN ("delete-process", Fdelete_process, 1, 1, 0, /*
|
0
|
1822 Delete PROCESS: kill it and forget about it immediately.
|
|
1823 PROCESS may be a process or the name of one, or a buffer name.
|
20
|
1824 */
|
|
1825 (proc))
|
0
|
1826 {
|
|
1827 /* This function can GC */
|
|
1828 struct Lisp_Process *p;
|
|
1829 proc = get_process (proc);
|
|
1830 p = XPROCESS (proc);
|
|
1831 if (network_connection_p (proc))
|
|
1832 {
|
|
1833 p->status_symbol = Qexit;
|
|
1834 p->exit_code = 0;
|
|
1835 p->core_dumped = 0;
|
|
1836 p->tick++;
|
|
1837 process_tick++;
|
|
1838 }
|
263
|
1839 else if (!NILP(p->pipe_instream))
|
0
|
1840 {
|
|
1841 Fkill_process (proc, Qnil);
|
|
1842 /* Do this now, since remove_process will make sigchld_handler do nothing. */
|
|
1843 p->status_symbol = Qsignal;
|
|
1844 p->exit_code = SIGKILL;
|
|
1845 p->core_dumped = 0;
|
|
1846 p->tick++;
|
|
1847 process_tick++;
|
|
1848 status_notify ();
|
|
1849 }
|
|
1850 remove_process (proc);
|
|
1851 return Qnil;
|
|
1852 }
|
|
1853
|
|
1854 /* Kill all processes associated with `buffer'.
|
|
1855 If `buffer' is nil, kill all processes */
|
|
1856
|
|
1857 void
|
|
1858 kill_buffer_processes (Lisp_Object buffer)
|
|
1859 {
|
|
1860 Lisp_Object tail;
|
|
1861
|
|
1862 for (tail = Vprocess_list; GC_CONSP (tail);
|
|
1863 tail = XCDR (tail))
|
|
1864 {
|
|
1865 Lisp_Object proc = XCAR (tail);
|
|
1866 if (GC_PROCESSP (proc)
|
|
1867 && (GC_NILP (buffer) || GC_EQ (XPROCESS (proc)->buffer, buffer)))
|
|
1868 {
|
|
1869 if (network_connection_p (proc))
|
|
1870 Fdelete_process (proc);
|
263
|
1871 else if (!NILP (XPROCESS (proc)->pipe_instream))
|
0
|
1872 process_send_signal (proc, SIGHUP, 0, 1);
|
|
1873 }
|
|
1874 }
|
|
1875 }
|
|
1876
|
20
|
1877 DEFUN ("process-kill-without-query", Fprocess_kill_without_query, 1, 2, 0, /*
|
0
|
1878 Say no query needed if PROCESS is running when Emacs is exited.
|
|
1879 Optional second argument if non-nil says to require a query.
|
|
1880 Value is t if a query was formerly required.
|
20
|
1881 */
|
|
1882 (proc, require_query_p))
|
0
|
1883 {
|
|
1884 int tem;
|
|
1885
|
|
1886 CHECK_PROCESS (proc);
|
|
1887 tem = XPROCESS (proc)->kill_without_query;
|
|
1888 XPROCESS (proc)->kill_without_query = NILP (require_query_p);
|
|
1889
|
173
|
1890 return tem ? Qnil : Qt;
|
0
|
1891 }
|
|
1892
|
20
|
1893 DEFUN ("process-kill-without-query-p", Fprocess_kill_without_query_p, 1, 1, 0, /*
|
0
|
1894 Whether PROC will be killed without query if running when emacs is exited.
|
20
|
1895 */
|
|
1896 (proc))
|
0
|
1897 {
|
|
1898 CHECK_PROCESS (proc);
|
173
|
1899 return XPROCESS (proc)->kill_without_query ? Qt : Qnil;
|
0
|
1900 }
|
|
1901
|
|
1902
|
|
1903 /* This is not named init_process in order to avoid a conflict with NS 3.3 */
|
|
1904 void
|
|
1905 init_xemacs_process (void)
|
|
1906 {
|
263
|
1907 MAYBE_PROCMETH (init_process, ());
|
0
|
1908
|
|
1909 Vprocess_list = Qnil;
|
263
|
1910 usid_to_process = make_hashtable (32);
|
0
|
1911 }
|
149
|
1912
|
0
|
1913 #if 0
|
|
1914
|
149
|
1915 xxDEFUN ("process-connection", Fprocess_connection, 0, 1, 0, /*
|
0
|
1916 Return the connection type of `PROCESS'. This can be nil (pipe),
|
|
1917 t or pty (pty) or stream (socket connection).
|
149
|
1918 */
|
|
1919 (process))
|
0
|
1920 {
|
|
1921 return XPROCESS (process)->type;
|
|
1922 }
|
|
1923
|
|
1924 #endif /* 0 */
|
|
1925
|
|
1926 void
|
|
1927 syms_of_process (void)
|
|
1928 {
|
|
1929 defsymbol (&Qprocessp, "processp");
|
|
1930 defsymbol (&Qrun, "run");
|
|
1931 defsymbol (&Qstop, "stop");
|
|
1932 defsymbol (&Qsignal, "signal");
|
|
1933 /* Qexit is already defined by syms_of_eval
|
185
|
1934 * defsymbol (&Qexit, "exit");
|
0
|
1935 */
|
|
1936 defsymbol (&Qopen, "open");
|
|
1937 defsymbol (&Qclosed, "closed");
|
|
1938
|
263
|
1939 defsymbol (&Qtcpip, "tcp/ip");
|
|
1940
|
259
|
1941 #ifdef HAVE_MULTICAST
|
|
1942 defsymbol(&Qmulticast, "multicast"); /* Used for occasional warnings */
|
|
1943 #endif
|
|
1944
|
20
|
1945 DEFSUBR (Fprocessp);
|
|
1946 DEFSUBR (Fget_process);
|
|
1947 DEFSUBR (Fget_buffer_process);
|
|
1948 DEFSUBR (Fdelete_process);
|
|
1949 DEFSUBR (Fprocess_status);
|
|
1950 DEFSUBR (Fprocess_exit_status);
|
|
1951 DEFSUBR (Fprocess_id);
|
|
1952 DEFSUBR (Fprocess_name);
|
|
1953 DEFSUBR (Fprocess_tty_name);
|
|
1954 DEFSUBR (Fprocess_command);
|
|
1955 DEFSUBR (Fset_process_buffer);
|
|
1956 DEFSUBR (Fprocess_buffer);
|
|
1957 DEFSUBR (Fprocess_mark);
|
|
1958 DEFSUBR (Fset_process_filter);
|
|
1959 DEFSUBR (Fprocess_filter);
|
|
1960 DEFSUBR (Fset_process_window_size);
|
|
1961 DEFSUBR (Fset_process_sentinel);
|
|
1962 DEFSUBR (Fprocess_sentinel);
|
|
1963 DEFSUBR (Fprocess_kill_without_query);
|
|
1964 DEFSUBR (Fprocess_kill_without_query_p);
|
|
1965 DEFSUBR (Fprocess_list);
|
|
1966 DEFSUBR (Fstart_process_internal);
|
0
|
1967 #ifdef HAVE_SOCKETS
|
20
|
1968 DEFSUBR (Fopen_network_stream_internal);
|
259
|
1969 #ifdef HAVE_MULTICAST
|
|
1970 DEFSUBR (Fopen_multicast_group_internal);
|
|
1971 #endif /* HAVE_MULTICAST */
|
0
|
1972 #endif /* HAVE_SOCKETS */
|
20
|
1973 DEFSUBR (Fprocess_send_region);
|
|
1974 DEFSUBR (Fprocess_send_string);
|
|
1975 DEFSUBR (Finterrupt_process);
|
|
1976 DEFSUBR (Fkill_process);
|
|
1977 DEFSUBR (Fquit_process);
|
|
1978 DEFSUBR (Fstop_process);
|
|
1979 DEFSUBR (Fcontinue_process);
|
|
1980 DEFSUBR (Fprocess_send_eof);
|
|
1981 DEFSUBR (Fsignal_process);
|
|
1982 /* DEFSUBR (Fprocess_connection); */
|
259
|
1983 #ifdef FILE_CODING
|
70
|
1984 DEFSUBR (Fprocess_input_coding_system);
|
|
1985 DEFSUBR (Fprocess_output_coding_system);
|
|
1986 DEFSUBR (Fset_process_input_coding_system);
|
|
1987 DEFSUBR (Fset_process_output_coding_system);
|
120
|
1988 DEFSUBR (Fprocess_coding_system);
|
|
1989 DEFSUBR (Fset_process_coding_system);
|
263
|
1990 #endif /* FILE_CODING */
|
0
|
1991 }
|
|
1992
|
|
1993 void
|
|
1994 vars_of_process (void)
|
|
1995 {
|
|
1996 Fprovide (intern ("subprocesses"));
|
|
1997 #ifdef HAVE_SOCKETS
|
|
1998 Fprovide (intern ("network-streams"));
|
259
|
1999 #ifdef HAVE_MULTICAST
|
|
2000 Fprovide (intern ("multicast"));
|
|
2001 #endif /* HAVE_MULTICAST */
|
|
2002 #endif /* HAVE_SOCKETS */
|
0
|
2003 staticpro (&Vprocess_list);
|
|
2004
|
|
2005 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes /*
|
|
2006 *Non-nil means delete processes immediately when they exit.
|
|
2007 nil means don't delete them until `list-processes' is run.
|
|
2008 */ );
|
|
2009
|
|
2010 delete_exited_processes = 1;
|
|
2011
|
|
2012 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type /*
|
|
2013 Control type of device used to communicate with subprocesses.
|
|
2014 Values are nil to use a pipe, or t or `pty' to use a pty.
|
|
2015 The value has no effect if the system has no ptys or if all ptys are busy:
|
|
2016 then a pipe is used in any case.
|
|
2017 The value takes effect when `start-process' is called.
|
|
2018 */ );
|
|
2019 Vprocess_connection_type = Qt;
|
153
|
2020
|
|
2021 #ifdef PROCESS_IO_BLOCKING
|
|
2022 DEFVAR_LISP ("network-stream-blocking-port-list", &network_stream_blocking_port_list /*
|
|
2023 List of port numbers or port names to set a blocking I/O mode with connection.
|
|
2024 Nil value means to set a default(non-blocking) I/O mode.
|
|
2025 The value takes effect when `open-network-stream-internal' is called.
|
|
2026 */ );
|
|
2027 network_stream_blocking_port_list = Qnil;
|
|
2028 #endif /* PROCESS_IO_BLOCKING */
|
0
|
2029 }
|
|
2030
|
|
2031 #endif /* not NO_SUBPROCESSES */
|