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