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