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
|
|
24 /* Synched up with: Mule 2.0, FSF 19.30. */
|
|
25
|
|
26 /* This file has been Mule-ized except for `start-process-internal'
|
|
27 and `open-network-stream-internal'. */
|
|
28
|
|
29 #include <config.h>
|
|
30
|
|
31 #if !defined (NO_SUBPROCESSES)
|
|
32
|
|
33 /* The entire file is within this conditional */
|
|
34
|
|
35 #include "lisp.h"
|
|
36
|
|
37 #include "buffer.h"
|
|
38 #include "commands.h"
|
|
39 #include "events.h"
|
|
40 #include "frame.h"
|
|
41 #include "insdel.h"
|
|
42 #include "lstream.h"
|
|
43 #include "opaque.h"
|
|
44 #include "process.h"
|
|
45 #include "sysdep.h"
|
|
46 #include "window.h"
|
|
47
|
|
48 #include <setjmp.h>
|
|
49 #include "sysfile.h"
|
|
50 #include "sysproc.h"
|
|
51 #include "systime.h"
|
|
52 #include "syssignal.h" /* Always include before systty.h */
|
|
53
|
|
54 #include "systty.h"
|
|
55 #include "syswait.h"
|
|
56
|
|
57 /* a process object is a network connection when its pid field a cons
|
|
58 (name of name of port we are connected to . foreign host name) */
|
|
59
|
|
60 /* Valid values of process->status_symbol */
|
|
61 Lisp_Object Qrun, Qstop; /* Qexit from eval.c, Qsignal from data.c. */
|
|
62 /* Qrun => Qopen, Qexit => Qclosed for "network connection" processes */
|
|
63 Lisp_Object Qopen, Qclosed;
|
|
64
|
|
65 /* t means use pty, nil means use a pipe,
|
|
66 maybe other values to come. */
|
|
67 static Lisp_Object Vprocess_connection_type;
|
|
68
|
|
69 /* FSFmacs says:
|
|
70
|
|
71 These next two vars are non-static since sysdep.c uses them in the
|
|
72 emulation of `select'. */
|
|
73 /* Number of events of change of status of a process. */
|
|
74 static volatile int process_tick;
|
|
75
|
|
76 /* Number of events for which the user or sentinel has been notified. */
|
|
77 static int update_tick;
|
|
78
|
|
79 /* Nonzero means delete a process right away if it exits. */
|
|
80 int delete_exited_processes;
|
|
81
|
|
82 /* Indexed by descriptor, gives the process (if any) for that descriptor */
|
|
83 Lisp_Object descriptor_to_process[MAXDESC];
|
|
84
|
|
85 /* List of process objects. */
|
|
86 Lisp_Object Vprocess_list;
|
|
87
|
|
88 Lisp_Object Qprocessp;
|
|
89
|
|
90 /* Buffered-ahead input char from process, indexed by channel.
|
|
91 -1 means empty (no char is buffered).
|
|
92 Used on sys V where the only way to tell if there is any
|
|
93 output from the process is to read at least one char.
|
|
94 Always -1 on systems that support FIONREAD. */
|
|
95
|
|
96 /* FSFmacs says:
|
|
97 Don't make static; need to access externally. */
|
|
98 static int proc_buffered_char[MAXDESC];
|
|
99
|
|
100 #ifdef HAVE_PTYS
|
|
101 /* The file name of the pty opened by allocate_pty. */
|
|
102
|
|
103 static char pty_name[24];
|
|
104 #endif
|
|
105
|
|
106
|
|
107 /************************************************************************/
|
|
108 /* the process Lisp object */
|
|
109 /************************************************************************/
|
|
110
|
|
111 /*
|
|
112 * Structure records pertinent information about open channels.
|
|
113 * There is one channel associated with each process.
|
|
114 */
|
|
115
|
|
116 struct Lisp_Process
|
|
117 {
|
|
118 struct lcrecord_header header;
|
|
119 /* Name of this process */
|
|
120 Lisp_Object name;
|
|
121 /* List of command arguments that this process was run with */
|
|
122 Lisp_Object command;
|
|
123 /* (funcall FILTER PROC STRING) (if FILTER is non-nil)
|
|
124 to dispose of a bunch of chars from the process all at once */
|
|
125 Lisp_Object filter;
|
|
126 /* (funcall SENTINEL PROCESS) when process state changes */
|
|
127 Lisp_Object sentinel;
|
|
128 /* Buffer that output is going to */
|
|
129 Lisp_Object buffer;
|
|
130 /* Marker set to end of last buffer-inserted output from this process */
|
|
131 Lisp_Object mark;
|
|
132 /* Lisp_Int of subprocess' PID, or a cons of
|
|
133 service/host if this is really a network connection */
|
|
134 Lisp_Object pid;
|
|
135 /* Non-0 if this is really a ToolTalk channel. */
|
|
136 int connected_via_filedesc_p;
|
|
137 #if 0 /* FSFmacs */
|
|
138 /* Perhaps it's cleaner this way, but FSFmacs
|
|
139 provides no way of retrieving this value, so I'll
|
|
140 leave this info with PID. */
|
|
141 /* Non-nil if this is really a child process */
|
|
142 Lisp_Object childp;
|
|
143 #endif
|
|
144
|
|
145 /* Symbol indicating status of process.
|
|
146 This may be a symbol: run, stop, exit, signal */
|
|
147 Lisp_Object status_symbol;
|
|
148
|
|
149
|
|
150 /* Exit code if process has terminated,
|
|
151 signal which stopped/interrupted process
|
|
152 or 0 if process is running */
|
|
153 int exit_code;
|
|
154 /* Number of this process */
|
|
155 /* Non-false if process has exited and "dumped core" on its way down */
|
|
156 char core_dumped;
|
|
157 /* Descriptor by which we read from this process. -1 for dead process */
|
|
158 int infd;
|
|
159 /* Descriptor by which we write to this process. -1 for dead process */
|
|
160 int outfd;
|
|
161 /* Descriptor for the tty which this process is using.
|
|
162 -1 if we didn't record it (on some systems, there's no need). */
|
|
163 int subtty;
|
|
164 /* Name of subprocess terminal. */
|
|
165 Lisp_Object tty_name;
|
|
166 /* Non-false if communicating through a pty. */
|
|
167 char pty_flag;
|
|
168 /* This next field is only actually used #ifdef ENERGIZE */
|
|
169 /* if this flag is not NIL, then filter will do the read on the
|
|
170 channel, rather than having a call to make_string.
|
|
171 This only works if the filter is a subr. */
|
|
172 char filter_does_read;
|
|
173 /* Non-nil means kill silently if Emacs is exited. */
|
|
174 char kill_without_query;
|
|
175 char selected;
|
|
176 /* Event-count of last event in which this process changed status. */
|
|
177 volatile int tick;
|
|
178 /* Event-count of last such event reported. */
|
|
179 int update_tick;
|
|
180 /* streams used in input and output */
|
|
181 Lisp_Object instream;
|
|
182 Lisp_Object outstream;
|
|
183 /* The actual filedesc stream used for output; may be different
|
|
184 than OUTSTREAM under Mule */
|
|
185 Lisp_Object filedesc_stream;
|
|
186 };
|
|
187
|
|
188 static Lisp_Object mark_process (Lisp_Object, void (*) (Lisp_Object));
|
|
189 static void print_process (Lisp_Object, Lisp_Object, int);
|
|
190 static void finalize_process (void *, int);
|
|
191 DEFINE_LRECORD_IMPLEMENTATION ("process", process,
|
|
192 mark_process, print_process, finalize_process,
|
|
193 0, 0, struct Lisp_Process);
|
|
194
|
|
195 static Lisp_Object
|
|
196 mark_process (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
197 {
|
|
198 struct Lisp_Process *proc = XPROCESS (obj);
|
|
199 ((markobj) (proc->name));
|
|
200 ((markobj) (proc->command));
|
|
201 ((markobj) (proc->filter));
|
|
202 ((markobj) (proc->sentinel));
|
|
203 ((markobj) (proc->buffer));
|
|
204 ((markobj) (proc->mark));
|
|
205 ((markobj) (proc->pid));
|
|
206 ((markobj) (proc->tty_name));
|
|
207 ((markobj) (proc->instream));
|
|
208 ((markobj) (proc->outstream));
|
|
209 ((markobj) (proc->filedesc_stream));
|
|
210 return (proc->status_symbol);
|
|
211 }
|
|
212
|
|
213 static void
|
|
214 print_process (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
215 {
|
|
216 struct Lisp_Process *proc = XPROCESS (obj);
|
|
217
|
|
218 if (print_readably)
|
|
219 error ("printing unreadable object #<process %s>",
|
16
|
220 XSTRING_DATA (proc->name));
|
0
|
221
|
|
222 if (!escapeflag)
|
|
223 {
|
|
224 print_internal (proc->name, printcharfun, 0);
|
|
225 }
|
|
226 else
|
|
227 {
|
|
228 int netp = network_connection_p (obj);
|
|
229 write_c_string (((netp) ? GETTEXT ("#<network connection ") :
|
|
230 GETTEXT ("#<process ")), printcharfun);
|
|
231 print_internal (proc->name, printcharfun, 1);
|
|
232 write_c_string (((netp) ? " " : " pid "), printcharfun);
|
|
233 print_internal (proc->pid, printcharfun, 1);
|
|
234 write_c_string (" state:", printcharfun);
|
|
235 print_internal (proc->status_symbol, printcharfun, 1);
|
|
236 write_c_string (">", printcharfun);
|
|
237 }
|
|
238 }
|
|
239
|
|
240 #ifdef HAVE_WINDOW_SYSTEM
|
|
241 extern void debug_process_finalization (struct Lisp_Process *p);
|
|
242 #endif /* HAVE_WINDOW_SYSTEM */
|
|
243
|
|
244 static void
|
|
245 finalize_process (void *header, int for_disksave)
|
|
246 {
|
|
247 if (for_disksave) return; /* hmm, what would this do anyway? */
|
|
248 /* #### this probably needs to be tied into the tty event loop */
|
|
249 /* #### when there is one */
|
|
250 #ifdef HAVE_WINDOW_SYSTEM
|
|
251 {
|
|
252 struct Lisp_Process *p = (struct Lisp_Process *) header;
|
|
253 debug_process_finalization (p);
|
|
254 }
|
|
255 #endif /* HAVE_WINDOW_SYSTEM */
|
|
256 }
|
|
257
|
|
258
|
|
259 /************************************************************************/
|
|
260 /* basic process accessors */
|
|
261 /************************************************************************/
|
|
262
|
|
263 static SIGTYPE
|
|
264 close_safely_handler (int signo)
|
|
265 {
|
|
266 EMACS_REESTABLISH_SIGNAL (signo, close_safely_handler);
|
|
267 SIGRETURN;
|
|
268 }
|
|
269
|
|
270 static void
|
|
271 close_safely (int fd)
|
|
272 {
|
|
273 stop_interrupts ();
|
|
274 signal (SIGALRM, close_safely_handler);
|
|
275 alarm (1);
|
|
276 close (fd);
|
|
277 alarm (0);
|
|
278 start_interrupts ();
|
|
279 }
|
|
280
|
|
281 static void
|
|
282 close_descriptor_pair (int in, int out)
|
|
283 {
|
|
284 if (in >= 0)
|
|
285 close (in);
|
|
286 if (out != in && out >= 0)
|
|
287 close (out);
|
|
288 }
|
|
289
|
|
290 /* Close all descriptors currently in use for communication
|
|
291 with subprocess. This is used in a newly-forked subprocess
|
|
292 to get rid of irrelevant descriptors. */
|
|
293
|
|
294 void
|
|
295 close_process_descs (void)
|
|
296 {
|
|
297 #ifndef WINDOWSNT
|
|
298 int i;
|
|
299 for (i = 0; i < MAXDESC; i++)
|
|
300 {
|
|
301 Lisp_Object process;
|
|
302 process = descriptor_to_process[i];
|
|
303 if (!NILP (process))
|
|
304 {
|
|
305 close_descriptor_pair (XPROCESS (process)->infd,
|
|
306 XPROCESS (process)->outfd);
|
|
307 }
|
|
308 }
|
|
309 #endif
|
|
310 }
|
|
311
|
|
312 void
|
|
313 get_process_file_descriptors (struct Lisp_Process *p, int *infd,
|
|
314 int *outfd)
|
|
315 {
|
|
316 if (! p) abort ();
|
|
317 /* the cast of MAXDESC is needed for some versions of Linux */
|
|
318 assert (p->infd >= -1 && p->infd < ((int) (MAXDESC)));
|
|
319 assert (p->outfd >= -1 && p->outfd < ((int) (MAXDESC)));
|
|
320 *infd = p->infd;
|
|
321 *outfd = p->outfd;
|
|
322 }
|
|
323
|
|
324 struct Lisp_Process *
|
|
325 get_process_from_input_descriptor (int infd)
|
|
326 {
|
|
327 Lisp_Object proc;
|
|
328
|
|
329 if ((infd < 0) || (infd >= ((int) (MAXDESC)))) abort ();
|
|
330 proc = descriptor_to_process[infd];
|
|
331 if (NILP (proc))
|
|
332 return 0;
|
|
333 else
|
|
334 return XPROCESS (proc);
|
|
335 }
|
|
336
|
|
337 int
|
|
338 get_process_selected_p (struct Lisp_Process *p)
|
|
339 {
|
|
340 return p->selected;
|
|
341 }
|
|
342
|
|
343 void
|
|
344 set_process_selected_p (struct Lisp_Process *p, int selected_p)
|
|
345 {
|
|
346 p->selected = !!selected_p;
|
|
347 }
|
|
348
|
|
349 #ifdef HAVE_SOCKETS
|
|
350 int
|
|
351 network_connection_p (Lisp_Object process)
|
|
352 {
|
|
353 return (GC_CONSP (XPROCESS (process)->pid));
|
|
354 }
|
|
355 #endif
|
|
356
|
|
357 int
|
|
358 connected_via_filedesc_p (struct Lisp_Process *p)
|
|
359 {
|
|
360 return p->connected_via_filedesc_p;
|
|
361 }
|
|
362
|
20
|
363 DEFUN ("processp", Fprocessp, 1, 1, 0, /*
|
0
|
364 Return t if OBJECT is a process.
|
20
|
365 */
|
|
366 (obj))
|
0
|
367 {
|
|
368 return ((PROCESSP (obj)) ? Qt : Qnil);
|
|
369 }
|
|
370
|
20
|
371 DEFUN ("process-list", Fprocess_list, 0, 0, 0, /*
|
0
|
372 Return a list of all processes.
|
20
|
373 */
|
|
374 ())
|
0
|
375 {
|
|
376 return Fcopy_sequence (Vprocess_list);
|
|
377 }
|
|
378
|
20
|
379 DEFUN ("get-process", Fget_process, 1, 1, 0, /*
|
0
|
380 Return the process named NAME, or nil if there is none.
|
20
|
381 */
|
|
382 (name))
|
0
|
383 {
|
|
384 Lisp_Object tail;
|
|
385
|
|
386 if (GC_PROCESSP (name))
|
|
387 return (name);
|
|
388
|
|
389 if (!gc_in_progress)
|
|
390 /* this only gets called during GC when emacs is going away as a result
|
|
391 of a signal or crash. */
|
|
392 CHECK_STRING (name);
|
|
393
|
|
394 for (tail = Vprocess_list; GC_CONSP (tail); tail = XCDR (tail))
|
|
395 {
|
|
396 Lisp_Object proc = XCAR (tail);
|
|
397 QUIT;
|
|
398 if (!NILP (Fequal (name, XPROCESS (proc)->name)))
|
|
399 return (XCAR (tail));
|
|
400 }
|
|
401 return Qnil;
|
|
402 }
|
|
403
|
20
|
404 DEFUN ("get-buffer-process", Fget_buffer_process, 1, 1, 0, /*
|
0
|
405 Return the (or, a) process associated with BUFFER.
|
|
406 BUFFER may be a buffer or the name of one.
|
20
|
407 */
|
|
408 (name))
|
0
|
409 {
|
|
410 Lisp_Object buf, tail, proc;
|
|
411
|
|
412 if (GC_NILP (name)) return Qnil;
|
|
413 buf = Fget_buffer (name);
|
|
414 if (GC_NILP (buf)) return Qnil;
|
|
415
|
|
416 #ifdef ENERGIZE
|
|
417 {
|
|
418 Lisp_Object p = energize_get_buffer_process (buf);
|
|
419 if (!GC_NILP (p)) return p;
|
|
420 }
|
|
421 #endif
|
|
422
|
|
423 for (tail = Vprocess_list; GC_CONSP (tail); tail = XCDR (tail))
|
|
424 {
|
|
425 /* jwz: do not quit here - it isn't necessary, as there is no way for
|
|
426 Vprocess_list to get circular or overwhelmingly long, and this
|
|
427 function is called from layout_mode_element under redisplay. */
|
|
428 /* QUIT; */
|
|
429 proc = XCAR (tail);
|
|
430 if (GC_PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf))
|
|
431 return proc;
|
|
432 }
|
|
433 return Qnil;
|
|
434 }
|
|
435
|
|
436 /* This is how commands for the user decode process arguments. It
|
|
437 accepts a process, a process name, a buffer, a buffer name, or nil.
|
|
438 Buffers denote the first process in the buffer, and nil denotes the
|
|
439 current buffer. */
|
|
440
|
|
441 static Lisp_Object
|
|
442 get_process (Lisp_Object name)
|
|
443 {
|
|
444 Lisp_Object proc;
|
|
445
|
|
446 #ifdef I18N3
|
|
447 /* #### Look more closely into translating process names. */
|
|
448 #endif
|
|
449
|
|
450 /* This may be called during a GC from process_send_signal() from
|
|
451 kill_buffer_processes() if emacs decides to abort(). */
|
|
452 if (GC_PROCESSP (name))
|
|
453 return name;
|
|
454
|
|
455 if (GC_NILP (name))
|
|
456 proc = Fget_buffer_process (Fcurrent_buffer ());
|
|
457 else
|
|
458 {
|
|
459 proc = Fget_process (name);
|
|
460 if (GC_NILP (proc))
|
|
461 proc = Fget_buffer_process (Fget_buffer (name));
|
|
462 }
|
|
463
|
|
464 if (!GC_NILP (proc))
|
|
465 return proc;
|
|
466
|
|
467 if (GC_NILP (name))
|
|
468 error ("Current buffer has no process");
|
|
469 else
|
16
|
470 error ("Process %s does not exist", XSTRING_DATA (name));
|
0
|
471 /* NOTREACHED */
|
|
472 return Qnil; /* warning suppression */
|
|
473 }
|
|
474
|
20
|
475 DEFUN ("process-id", Fprocess_id, 1, 1, 0, /*
|
0
|
476 Return the process id of PROCESS.
|
|
477 This is the pid of the Unix process which PROCESS uses or talks to.
|
|
478 For a network connection, this value is a cons of
|
|
479 (foreign-network-port . foreign-host-name).
|
20
|
480 */
|
|
481 (proc))
|
0
|
482 {
|
|
483 Lisp_Object pid;
|
|
484 CHECK_PROCESS (proc);
|
|
485
|
|
486 pid = XPROCESS (proc)->pid;
|
|
487 if (network_connection_p (proc))
|
|
488 /* return (Qnil); */
|
|
489 return (Fcons (Fcar (pid), Fcdr (pid)));
|
|
490 else
|
|
491 return (pid);
|
|
492 }
|
|
493
|
20
|
494 DEFUN ("process-name", Fprocess_name, 1, 1, 0, /*
|
0
|
495 Return the name of PROCESS, as a string.
|
|
496 This is the name of the program invoked in PROCESS,
|
|
497 possibly modified to make it unique among process names.
|
20
|
498 */
|
|
499 (proc))
|
0
|
500 {
|
|
501 CHECK_PROCESS (proc);
|
|
502 return XPROCESS (proc)->name;
|
|
503 }
|
|
504
|
20
|
505 DEFUN ("process-command", Fprocess_command, 1, 1, 0, /*
|
0
|
506 Return the command that was executed to start PROCESS.
|
|
507 This is a list of strings, the first string being the program executed
|
|
508 and the rest of the strings being the arguments given to it.
|
20
|
509 */
|
|
510 (proc))
|
0
|
511 {
|
|
512 CHECK_PROCESS (proc);
|
|
513 return XPROCESS (proc)->command;
|
|
514 }
|
|
515
|
|
516
|
|
517 /************************************************************************/
|
|
518 /* creating a process */
|
|
519 /************************************************************************/
|
|
520
|
|
521 static Lisp_Object
|
|
522 make_process_internal (Lisp_Object name)
|
|
523 {
|
|
524 Lisp_Object val, name1;
|
|
525 int i;
|
|
526 struct Lisp_Process *p
|
|
527 = alloc_lcrecord (sizeof (struct Lisp_Process), lrecord_process);
|
|
528
|
|
529 /* If name is already in use, modify it until it is unused. */
|
|
530 name1 = name;
|
|
531 for (i = 1; ; i++)
|
|
532 {
|
|
533 char suffix[10];
|
|
534 Lisp_Object tem = Fget_process (name1);
|
|
535 if (NILP (tem))
|
|
536 break;
|
|
537 sprintf (suffix, "<%d>", i);
|
|
538 name1 = concat2 (name, build_string (suffix));
|
|
539 }
|
|
540 name = name1;
|
|
541 p->name = name;
|
|
542
|
|
543 p->command = Qnil;
|
|
544 p->filter = Qnil;
|
|
545 p->sentinel = Qnil;
|
|
546 p->buffer = Qnil;
|
|
547 p->mark = Fmake_marker ();
|
|
548 p->pid = Qnil;
|
|
549 p->status_symbol = Qrun;
|
|
550 p->connected_via_filedesc_p = 0;
|
|
551 p->exit_code = 0;
|
|
552 p->core_dumped = 0;
|
|
553 p->infd = -1;
|
|
554 p->outfd = -1;
|
|
555 p->subtty = -1;
|
|
556 p->tty_name = Qnil;
|
|
557 p->pty_flag = 0;
|
|
558 p->filter_does_read = 0;
|
|
559 p->kill_without_query = 0;
|
|
560 p->selected = 0;
|
|
561 p->tick = 0;
|
|
562 p->update_tick = 0;
|
|
563 p->instream = Qnil;
|
|
564 p->outstream = Qnil;
|
|
565
|
|
566 XSETPROCESS (val, p);
|
|
567
|
|
568 Vprocess_list = Fcons (val, Vprocess_list);
|
|
569 return (val);
|
|
570 }
|
|
571
|
|
572 #ifdef HAVE_PTYS
|
|
573
|
|
574 /* Open an available pty, returning a file descriptor.
|
|
575 Return -1 on failure.
|
|
576 The file name of the terminal corresponding to the pty
|
|
577 is left in the variable pty_name. */
|
|
578
|
|
579 static int
|
|
580 allocate_pty (void)
|
|
581 {
|
|
582 struct stat stb;
|
|
583 int c, i;
|
|
584 int fd;
|
|
585
|
|
586 /* Some systems name their pseudoterminals so that there are gaps in
|
|
587 the usual sequence - for example, on HP9000/S700 systems, there
|
|
588 are no pseudoterminals with names ending in 'f'. So we wait for
|
|
589 three failures in a row before deciding that we've reached the
|
|
590 end of the ptys. */
|
|
591 int failed_count = 0;
|
|
592
|
|
593 #ifdef PTY_ITERATION
|
|
594 PTY_ITERATION
|
|
595 #else
|
|
596 for (c = FIRST_PTY_LETTER; c <= 'z'; c++)
|
|
597 for (i = 0; i < 16; i++)
|
|
598 #endif
|
|
599 {
|
|
600 #ifdef PTY_NAME_SPRINTF
|
|
601 PTY_NAME_SPRINTF
|
|
602 #else
|
|
603 sprintf (pty_name, "/dev/pty%c%x", c, i);
|
|
604 #endif /* no PTY_NAME_SPRINTF */
|
|
605
|
|
606 #ifdef PTY_OPEN
|
|
607 PTY_OPEN;
|
|
608 #else /* no PTY_OPEN */
|
|
609 #ifdef IRIS
|
|
610 /* Unusual IRIS code */
|
|
611 *ptyv = open ("/dev/ptc", O_RDWR | O_NDELAY, 0);
|
|
612 if (fd < 0)
|
|
613 return -1;
|
|
614 if (fstat (fd, &stb) < 0)
|
|
615 return -1;
|
|
616 #else /* not IRIS */
|
|
617 if (stat (pty_name, &stb) < 0)
|
|
618 {
|
|
619 failed_count++;
|
|
620 if (failed_count >= 3)
|
|
621 return -1;
|
|
622 }
|
|
623 else
|
|
624 failed_count = 0;
|
|
625 #ifdef O_NONBLOCK
|
|
626 fd = open (pty_name, O_RDWR | O_NONBLOCK, 0);
|
|
627 #else
|
|
628 fd = open (pty_name, O_RDWR | O_NDELAY, 0);
|
|
629 #endif
|
|
630 #endif /* not IRIS */
|
|
631 #endif /* no PTY_OPEN */
|
|
632
|
|
633 if (fd >= 0)
|
|
634 {
|
|
635 /* check to make certain that both sides are available
|
|
636 this avoids a nasty yet stupid bug in rlogins */
|
|
637 #ifdef PTY_TTY_NAME_SPRINTF
|
|
638 PTY_TTY_NAME_SPRINTF
|
|
639 #else
|
|
640 sprintf (pty_name, "/dev/tty%c%x", c, i);
|
|
641 #endif /* no PTY_TTY_NAME_SPRINTF */
|
|
642 #ifndef UNIPLUS
|
|
643 if (access (pty_name, 6) != 0)
|
|
644 {
|
|
645 close (fd);
|
|
646 #if !defined(IRIS) && !defined(__sgi)
|
|
647 continue;
|
|
648 #else
|
|
649 return -1;
|
|
650 #endif /* IRIS */
|
|
651 }
|
|
652 #endif /* not UNIPLUS */
|
|
653 setup_pty (fd);
|
|
654 return fd;
|
|
655 }
|
|
656 }
|
|
657 return -1;
|
|
658 }
|
|
659 #endif /* HAVE_PTYS */
|
|
660
|
|
661 static int
|
|
662 create_bidirectional_pipe (int *inchannel, int *outchannel,
|
|
663 volatile int *forkin, volatile int *forkout)
|
|
664 {
|
|
665 int sv[2];
|
|
666
|
|
667 #ifdef SKTPAIR
|
|
668 if (socketpair (AF_UNIX, SOCK_STREAM, 0, sv) < 0)
|
|
669 return -1;
|
|
670 *outchannel = *inchannel = sv[0];
|
|
671 *forkout = *forkin = sv[1];
|
|
672 #else /* not SKTPAIR */
|
|
673 #ifdef WINDOWSNT
|
|
674 pipe_with_inherited_out (sv);
|
|
675 *inchannel = sv[0];
|
|
676 *forkout = sv[1];
|
|
677
|
|
678 pipe_with_inherited_in (sv);
|
|
679 *forkin = sv[0];
|
|
680 *outchannel = sv[1];
|
|
681 #else /* not WINDOWSNT */
|
|
682 int temp;
|
|
683 temp = pipe (sv);
|
|
684 if (temp < 0) return -1;
|
|
685 *inchannel = sv[0];
|
|
686 *forkout = sv[1];
|
|
687 temp = pipe (sv);
|
|
688 if (temp < 0) return -1;
|
|
689 *outchannel = sv[1];
|
|
690 *forkin = sv[0];
|
|
691 #endif /* not WINDOWSNT */
|
|
692 #endif /* not SKTPAIR */
|
|
693 return 0;
|
|
694 }
|
|
695
|
|
696 #ifndef VMS /* VMS version of this function is in vmsproc.c. */
|
|
697
|
|
698 static Bufbyte
|
|
699 get_eof_char (struct Lisp_Process *p)
|
|
700 {
|
|
701 /* Figure out the eof character for the outfd of the given process.
|
|
702 * The following code is similar to that in process_send_signal, and
|
|
703 * should probably be merged with that code somehow. */
|
|
704
|
16
|
705 CONST Bufbyte ctrl_d = (Bufbyte) '\004';
|
|
706
|
|
707 if (!isatty (p->outfd))
|
|
708 return ctrl_d;
|
0
|
709 #ifdef HAVE_TERMIOS
|
16
|
710 {
|
|
711 struct termios t;
|
|
712 tcgetattr (p->outfd, &t);
|
|
713 #if 0
|
|
714 /* What is the following line designed to do??? -mrb */
|
|
715 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VEOF + 1))
|
|
716 return ctrl_d;
|
|
717 else
|
|
718 return (Bufbyte) t.c_cc[VEOF];
|
|
719 #endif
|
|
720 return t.c_cc[VEOF] == CDISABLE ? ctrl_d : (Bufbyte) t.c_cc[VEOF];
|
|
721 }
|
0
|
722 #else /* ! HAVE_TERMIOS */
|
|
723 /* On Berkeley descendants, the following IOCTL's retrieve the
|
|
724 current control characters. */
|
|
725 #if defined (TIOCGETC)
|
16
|
726 {
|
|
727 struct tchars c;
|
|
728 ioctl (p->outfd, TIOCGETC, &c);
|
|
729 return (Bufbyte) c.t_eofc;
|
|
730 }
|
0
|
731 #else /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
|
|
732 /* On SYSV descendants, the TCGETA ioctl retrieves the current control
|
|
733 characters. */
|
|
734 #ifdef TCGETA
|
16
|
735 {
|
|
736 struct termio t;
|
|
737 ioctl (p->outfd, TCGETA, &t);
|
|
738 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VINTR + 1))
|
|
739 return ctrl_d;
|
|
740 else
|
|
741 return (Bufbyte) t.c_cc[VINTR];
|
|
742 }
|
0
|
743 #else /* ! defined (TCGETA) */
|
|
744 /* Rather than complain, we'll just guess ^D, which is what
|
|
745 * earlier emacsen always used. */
|
16
|
746 return ctrl_d;
|
0
|
747 #endif /* ! defined (TCGETA) */
|
|
748 #endif /* ! defined (TIOCGETC) */
|
|
749 #endif /* ! defined (HAVE_TERMIOS) */
|
|
750 }
|
|
751
|
|
752 static int
|
|
753 get_pty_max_bytes (struct Lisp_Process *p)
|
|
754 {
|
|
755 int pty_max_bytes;
|
|
756
|
|
757 #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON)
|
|
758 pty_max_bytes = fpathconf (p->outfd, _PC_MAX_CANON);
|
|
759 if (pty_max_bytes < 0)
|
|
760 pty_max_bytes = 250;
|
|
761 #else
|
|
762 pty_max_bytes = 250;
|
|
763 #endif
|
|
764 /* Deduct one, to leave space for the eof. */
|
|
765 pty_max_bytes--;
|
|
766
|
|
767 return pty_max_bytes;
|
|
768 }
|
|
769
|
|
770 static void
|
|
771 init_process_fds (struct Lisp_Process *p, int in, int out)
|
|
772 {
|
|
773 p->infd = in;
|
|
774 p->outfd = out;
|
|
775 p->instream = make_filedesc_input_stream (in, 0, -1, 0);
|
|
776 p->outstream = make_filedesc_output_stream (out, 0, -1,
|
|
777 LSTR_BLOCKED_OK
|
|
778 | (p->pty_flag ?
|
|
779 LSTR_PTY_FLUSHING : 0));
|
|
780 p->filedesc_stream = p->outstream;
|
|
781 if (p->pty_flag)
|
|
782 {
|
|
783 Bufbyte eof_char = get_eof_char (p);
|
|
784 int pty_max_bytes = get_pty_max_bytes (p);
|
|
785 filedesc_stream_set_pty_flushing (XLSTREAM (p->outstream),
|
|
786 pty_max_bytes, eof_char);
|
|
787 }
|
|
788 }
|
|
789
|
|
790 static void
|
|
791 create_process (Lisp_Object process,
|
|
792 char **new_argv, CONST char *current_dir)
|
|
793 {
|
|
794 /* This function rewritten by wing@666.com. */
|
|
795
|
|
796 int pid, inchannel, outchannel;
|
|
797 /* Use volatile to protect variables from being clobbered by longjmp. */
|
|
798 volatile int forkin, forkout;
|
|
799 volatile int pty_flag = 0;
|
|
800 char **env;
|
|
801 struct Lisp_Process *p = XPROCESS (process);
|
|
802
|
|
803 env = environ;
|
|
804
|
|
805 inchannel = outchannel = forkin = forkout = -1;
|
|
806
|
|
807 #ifdef HAVE_PTYS
|
|
808 if (!NILP (Vprocess_connection_type))
|
|
809 {
|
|
810 /* find a new pty, open the master side, return the opened
|
|
811 file handle, and store the name of the corresponding slave
|
|
812 side in global variable pty_name. */
|
|
813 outchannel = inchannel = allocate_pty ();
|
|
814 }
|
|
815
|
|
816 if (inchannel >= 0)
|
|
817 {
|
|
818 /* You're "supposed" to now open the slave in the child.
|
|
819 On some systems, we can open it here; this allows for
|
|
820 better error checking. */
|
|
821 #ifndef USG
|
|
822 /* On USG systems it does not work to open the pty's tty here
|
|
823 and then close and reopen it in the child. */
|
|
824 #ifdef O_NOCTTY
|
|
825 /* Don't let this terminal become our controlling terminal
|
|
826 (in case we don't have one). */
|
|
827 forkout = forkin = open (pty_name, O_RDWR | O_NOCTTY, 0);
|
|
828 #else
|
|
829 forkout = forkin = open (pty_name, O_RDWR, 0);
|
|
830 #endif
|
|
831 if (forkin < 0)
|
|
832 goto io_failure;
|
|
833 #endif /* not USG */
|
|
834 p->pty_flag = pty_flag = 1;
|
|
835 }
|
|
836 else
|
|
837 #endif /* HAVE_PTYS */
|
|
838 if (create_bidirectional_pipe (&inchannel, &outchannel,
|
|
839 &forkin, &forkout) < 0)
|
|
840 goto io_failure;
|
|
841
|
|
842 #if 0
|
|
843 /* Replaced by close_process_descs */
|
|
844 set_exclusive_use (inchannel);
|
|
845 set_exclusive_use (outchannel);
|
|
846 #endif
|
|
847
|
|
848 set_descriptor_non_blocking (inchannel);
|
|
849
|
|
850 /* Record this as an active process, with its channels.
|
|
851 As a result, child_setup will close Emacs's side of the pipes. */
|
|
852 descriptor_to_process[inchannel] = process;
|
|
853 init_process_fds (p, inchannel, outchannel);
|
|
854 /* Record the tty descriptor used in the subprocess. */
|
|
855 p->subtty = forkin;
|
|
856 p->status_symbol = Qrun;
|
|
857 p->exit_code = 0;
|
|
858
|
|
859 {
|
|
860 /* child_setup must clobber environ on systems with true vfork.
|
|
861 Protect it from permanent change. */
|
|
862 char **save_environ = environ;
|
|
863
|
|
864 #ifdef EMACS_BTL
|
|
865 /* when performance monitoring is on, turn it off before the vfork(),
|
|
866 as the child has no handler for the signal -- when back in the
|
|
867 parent process, turn it back on if it was really on when you "turned
|
|
868 it off" */
|
|
869 int logging_on = cadillac_stop_logging (); /* #### rename me */
|
|
870 #endif
|
|
871
|
|
872 #ifndef WINDOWSNT
|
|
873 pid = vfork ();
|
|
874 if (pid == 0)
|
|
875 #endif /* not WINDOWSNT */
|
|
876 {
|
|
877 /**** Now we're in the child process ****/
|
|
878 int xforkin = forkin;
|
|
879 int xforkout = forkout;
|
|
880
|
|
881 if (!pty_flag)
|
|
882 EMACS_SEPARATE_PROCESS_GROUP ();
|
|
883 #ifdef HAVE_PTYS
|
|
884 else
|
|
885 {
|
|
886 /* Disconnect the current controlling terminal, pursuant to
|
|
887 making the pty be the controlling terminal of the process.
|
|
888 Also put us in our own process group. */
|
|
889
|
|
890 disconnect_controlling_terminal ();
|
|
891
|
|
892 /* Open the pty connection and make the pty's terminal
|
|
893 our controlling terminal.
|
|
894
|
|
895 On systems with TIOCSCTTY, we just use it to set
|
|
896 the controlling terminal. On other systems, the
|
|
897 first TTY we open becomes the controlling terminal.
|
|
898 So, we end up with four possibilities:
|
|
899
|
|
900 (1) on USG and TIOCSCTTY systems, we open the pty
|
|
901 and use TIOCSCTTY.
|
|
902 (2) on other USG systems, we just open the pty.
|
|
903 (3) on non-USG systems with TIOCSCTTY, we
|
|
904 just use TIOCSCTTY. (On non-USG systems, we
|
|
905 already opened the pty in the parent process.)
|
|
906 (4) on non-USG systems without TIOCSCTTY, we
|
|
907 close the pty and reopen it.
|
|
908
|
|
909 This would be cleaner if we didn't open the pty
|
|
910 in the parent process, but doing it that way
|
|
911 makes it possible to trap error conditions.
|
|
912 It's harder to convey an error from the child
|
|
913 process, and I don't feel like messing with
|
|
914 this now. */
|
|
915
|
|
916 /* There was some weirdo, probably wrong,
|
|
917 conditionalization on RTU and UNIPLUS here.
|
|
918 I deleted it. So sue me. */
|
|
919
|
|
920 /* SunOS has TIOCSCTTY but the close/open method
|
|
921 also works. */
|
|
922
|
|
923 # if defined (USG) || !defined (TIOCSCTTY)
|
|
924 /* Now close the pty (if we had it open) and reopen it.
|
|
925 This makes the pty the controlling terminal of the
|
|
926 subprocess. */
|
|
927 /* I wonder if close (open (pty_name, ...)) would work? */
|
|
928 if (xforkin >= 0)
|
|
929 close (xforkin);
|
|
930 xforkout = xforkin = open (pty_name, O_RDWR, 0);
|
|
931 if (xforkin < 0)
|
|
932 {
|
|
933 write (1, "Couldn't open the pty terminal ", 31);
|
|
934 write (1, pty_name, strlen (pty_name));
|
|
935 write (1, "\n", 1);
|
|
936 _exit (1);
|
|
937 }
|
|
938 # endif /* USG or not TIOCSCTTY */
|
|
939
|
|
940 /* Miscellaneous setup required for some systems.
|
|
941 Must be done before using tc* functions on xforkin.
|
|
942 This guarantees that isatty(xforkin) is true. */
|
|
943
|
|
944 # ifdef SETUP_SLAVE_PTY
|
|
945 SETUP_SLAVE_PTY;
|
|
946 # endif /* SETUP_SLAVE_PTY */
|
|
947
|
|
948 # ifdef TIOCSCTTY
|
|
949 /* We ignore the return value
|
|
950 because faith@cs.unc.edu says that is necessary on Linux. */
|
|
951 assert (isatty (xforkin));
|
|
952 ioctl (xforkin, TIOCSCTTY, 0);
|
|
953 # endif /* TIOCSCTTY */
|
|
954
|
|
955 /* Change the line discipline. */
|
|
956
|
|
957 # if defined (HAVE_TERMIOS) && defined (LDISC1)
|
|
958 {
|
|
959 struct termios t;
|
|
960 assert (isatty (xforkin));
|
|
961 tcgetattr (xforkin, &t);
|
|
962 t.c_lflag = LDISC1;
|
|
963 if (tcsetattr (xforkin, TCSANOW, &t) < 0)
|
|
964 perror ("create_process/tcsetattr LDISC1 failed\n");
|
|
965 }
|
|
966 # elif defined (NTTYDISC) && defined (TIOCSETD)
|
|
967 {
|
|
968 /* Use new line discipline. TIOCSETD is accepted and
|
|
969 ignored on Sys5.4 systems with ttcompat. */
|
|
970 int ldisc = NTTYDISC;
|
|
971 assert (isatty (xforkin));
|
|
972 ioctl (xforkin, TIOCSETD, &ldisc);
|
|
973 }
|
|
974 # endif /* TIOCSETD & NTTYDISC */
|
|
975
|
|
976 /* Make our process group be the foreground group
|
|
977 of our new controlling terminal. */
|
|
978
|
|
979 {
|
|
980 int piddly = EMACS_GET_PROCESS_GROUP ();
|
|
981 EMACS_SET_TTY_PROCESS_GROUP (xforkin, &piddly);
|
|
982 }
|
|
983
|
|
984 # ifdef AIX
|
|
985 /* On AIX, we've disabled SIGHUP above once we start a
|
|
986 child on a pty. Now reenable it in the child, so it
|
|
987 will die when we want it to. */
|
|
988 signal (SIGHUP, SIG_DFL);
|
|
989 # endif /* AIX */
|
|
990 }
|
|
991 #endif /* HAVE_PTYS */
|
|
992
|
|
993 signal (SIGINT, SIG_DFL);
|
|
994 signal (SIGQUIT, SIG_DFL);
|
|
995
|
|
996 #ifndef MSDOS
|
|
997 if (pty_flag)
|
|
998 {
|
|
999 /* Set up the terminal characteristics of the pty. */
|
|
1000 child_setup_tty (xforkout);
|
|
1001 }
|
|
1002
|
|
1003 #ifdef WINDOWSNT
|
|
1004 pid = child_setup (xforkin, xforkout, xforkout,
|
|
1005 new_argv, current_dir);
|
|
1006 #else /* not WINDOWSNT */
|
|
1007 child_setup (xforkin, xforkout, xforkout, new_argv, current_dir);
|
|
1008 #endif /* not WINDOWSNT */
|
|
1009 #endif /* not MSDOS */
|
|
1010 }
|
|
1011 #ifdef EMACS_BTL
|
|
1012 else if (logging_on)
|
|
1013 cadillac_start_logging (); /* #### rename me */
|
|
1014 #endif
|
|
1015
|
|
1016 environ = save_environ;
|
|
1017 }
|
|
1018
|
|
1019 if (pid < 0)
|
|
1020 {
|
|
1021 close_descriptor_pair (forkin, forkout);
|
|
1022 report_file_error ("Doing vfork", Qnil);
|
|
1023 }
|
|
1024
|
|
1025 p->pid = make_int (pid);
|
|
1026 /* p->subtty = -1; */
|
|
1027
|
|
1028 #ifdef WINDOWSNT
|
|
1029 register_child (pid, inchannel);
|
|
1030 #endif /* WINDOWSNT */
|
|
1031
|
|
1032 /* If the subfork execv fails, and it exits,
|
|
1033 this close hangs. I don't know why.
|
|
1034 So have an interrupt jar it loose. */
|
|
1035 if (forkin >= 0)
|
|
1036 close_safely (forkin);
|
|
1037 if (forkin != forkout && forkout >= 0)
|
|
1038 close (forkout);
|
|
1039
|
|
1040 #ifdef HAVE_PTYS
|
|
1041 if (pty_flag)
|
|
1042 XPROCESS (process)->tty_name = build_string (pty_name);
|
|
1043 else
|
|
1044 #endif
|
|
1045 XPROCESS (process)->tty_name = Qnil;
|
|
1046
|
|
1047 /* Notice that SIGCHLD was not blocked. (This is not possible on
|
|
1048 some systems.) No biggie if SIGCHLD occurs right around the
|
|
1049 time that this call happens, because SIGCHLD() does not actually
|
|
1050 deselect the process (that doesn't occur until the next time
|
|
1051 we're waiting for an event, when status_notify() is called). */
|
|
1052 event_stream_select_process (XPROCESS (process));
|
|
1053
|
|
1054 return;
|
|
1055
|
|
1056 io_failure:
|
|
1057 {
|
|
1058 int temp = errno;
|
|
1059 close_descriptor_pair (forkin, forkout);
|
|
1060 close_descriptor_pair (inchannel, outchannel);
|
|
1061 errno = temp;
|
|
1062 report_file_error ("Opening pty or pipe", Qnil);
|
|
1063 }
|
|
1064 }
|
|
1065 #endif /* not VMS */
|
|
1066
|
|
1067 /* This function is the unwind_protect form for Fstart_process_internal. If
|
|
1068 PROC doesn't have its pid set, then we know someone has signalled
|
|
1069 an error and the process wasn't started successfully, so we should
|
|
1070 remove it from the process list. */
|
|
1071 static void remove_process (Lisp_Object proc);
|
|
1072 static Lisp_Object
|
|
1073 start_process_unwind (Lisp_Object proc)
|
|
1074 {
|
|
1075 /* Was PROC started successfully? */
|
|
1076 if (EQ (XPROCESS (proc)->pid, Qnil))
|
|
1077 remove_process (proc);
|
|
1078 return Qnil;
|
|
1079 }
|
|
1080
|
20
|
1081 DEFUN ("start-process-internal", Fstart_process_internal, 3, MANY, 0, /*
|
0
|
1082 Start a program in a subprocess. Return the process object for it.
|
|
1083 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS
|
|
1084 NAME is name for process. It is modified if necessary to make it unique.
|
|
1085 BUFFER is the buffer or (buffer-name) to associate with the process.
|
|
1086 Process output goes at end of that buffer, unless you specify
|
|
1087 an output stream or filter function to handle the output.
|
|
1088 BUFFER may be also nil, meaning that this process is not associated
|
|
1089 with any buffer
|
|
1090 Third arg is program file name. It is searched for as in the shell.
|
|
1091 Remaining arguments are strings to give program as arguments.
|
|
1092 INCODE and OUTCODE specify the coding-system objects used in input/output
|
|
1093 from/to the process.
|
20
|
1094 */
|
|
1095 (int nargs, Lisp_Object *args))
|
0
|
1096 {
|
|
1097 /* !!#### This function has not been Mule-ized */
|
|
1098 /* This function can GC */
|
|
1099 Lisp_Object buffer, name, program, proc, current_dir;
|
|
1100 Lisp_Object tem;
|
|
1101 int speccount = specpdl_depth ();
|
|
1102 #ifdef VMS
|
|
1103 char *new_argv;
|
|
1104 int len;
|
|
1105 #else
|
|
1106 char **new_argv;
|
|
1107 #endif
|
|
1108 int i;
|
|
1109
|
|
1110 buffer = args[1];
|
|
1111 if (!NILP (buffer))
|
|
1112 buffer = Fget_buffer_create (buffer);
|
|
1113
|
|
1114 CHECK_STRING (args[0]); /* name */
|
|
1115 CHECK_STRING (args[2]); /* program */
|
|
1116
|
|
1117 /* Make sure that the child will be able to chdir to the current
|
|
1118 buffer's current directory, or its unhandled equivalent. We
|
|
1119 can't just have the child check for an error when it does the
|
|
1120 chdir, since it's in a vfork.
|
|
1121
|
|
1122 We have to GCPRO around this because Fexpand_file_name and
|
|
1123 Funhandled_file_name_directory might call a file name handling
|
|
1124 function. The argument list is protected by the caller, so all
|
|
1125 we really have to worry about is buffer. */
|
|
1126 {
|
|
1127 struct gcpro gcpro1, gcpro2; /* Caller gc-protects args[] */
|
|
1128
|
|
1129 current_dir = current_buffer->directory;
|
|
1130
|
|
1131 GCPRO2 (buffer, current_dir);
|
|
1132
|
|
1133 current_dir =
|
|
1134 expand_and_dir_to_file (Funhandled_file_name_directory (current_dir),
|
|
1135 Qnil);
|
|
1136 #if 0 /* This loser breaks ange-ftp */
|
|
1137 if (NILP (Ffile_accessible_directory_p (current_dir)))
|
|
1138 report_file_error ("Setting current directory",
|
|
1139 list1 (current_buffer->directory));
|
|
1140 #endif /* 0 */
|
|
1141
|
|
1142 UNGCPRO;
|
|
1143 }
|
|
1144
|
|
1145 name = args[0];
|
|
1146 program = args[2];
|
|
1147
|
|
1148 #ifdef VMS
|
|
1149 /* Make a one member argv with all args concatenated
|
|
1150 together separated by a blank. */
|
16
|
1151 len = XSTRING_LENGTH (program) + 2;
|
0
|
1152 for (i = 3; i < nargs; i++)
|
|
1153 {
|
|
1154 tem = args[i];
|
|
1155 CHECK_STRING (tem);
|
16
|
1156 len += XSTRING_LENGTH (tem) + 1; /* count the blank */
|
0
|
1157 }
|
|
1158 new_argv = (char *) alloca (len);
|
16
|
1159 strcpy (new_argv, XSTRING_DATA (program));
|
0
|
1160 for (i = 3; i < nargs; i++)
|
|
1161 {
|
|
1162 tem = args[i];
|
|
1163 CHECK_STRING (tem);
|
|
1164 strcat (new_argv, " ");
|
16
|
1165 strcat (new_argv, XSTRING_DATA (tem));
|
0
|
1166 }
|
|
1167 /* Need to add code here to check for program existence on VMS */
|
|
1168
|
|
1169 #else /* not VMS */
|
|
1170 new_argv = (char **)
|
|
1171 alloca ((nargs - 1) * sizeof (char *));
|
|
1172
|
16
|
1173 new_argv[0] = (char *) XSTRING_DATA (program);
|
0
|
1174
|
|
1175 /* If program file name is not absolute, search our path for it */
|
16
|
1176 if (!IS_DIRECTORY_SEP (XSTRING_BYTE (program, 0))
|
|
1177 && !(XSTRING_LENGTH (program) > 1
|
|
1178 && IS_DEVICE_SEP (XSTRING_BYTE (program, 1))))
|
0
|
1179 {
|
|
1180 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; /* Caller protects args[] */
|
|
1181 GCPRO4 (buffer, current_dir, name, program);
|
|
1182
|
|
1183 tem = Qnil;
|
|
1184 locate_file (Vexec_path, program, EXEC_SUFFIXES, &tem,
|
|
1185 X_OK);
|
|
1186 UNGCPRO;
|
|
1187 if (NILP (tem))
|
|
1188 report_file_error ("Searching for program", list1 (program));
|
|
1189 tem = Fexpand_file_name (tem, Qnil);
|
16
|
1190 new_argv[0] = (char *) XSTRING_DATA (tem);
|
0
|
1191 }
|
|
1192 else
|
|
1193 {
|
|
1194 if (!NILP (Ffile_directory_p (program)))
|
|
1195 error ("Specified program for new process is a directory");
|
|
1196 }
|
|
1197
|
|
1198 for (i = 3; i < nargs; i++)
|
|
1199 {
|
|
1200 tem = args[i];
|
|
1201 CHECK_STRING (tem);
|
16
|
1202 new_argv[i - 2] = (char *) XSTRING_DATA (tem);
|
0
|
1203 }
|
|
1204 new_argv[i - 2] = 0;
|
|
1205
|
|
1206 #endif /* not VMS */
|
|
1207
|
|
1208 proc = make_process_internal (name);
|
|
1209
|
|
1210 XPROCESS (proc)->buffer = buffer;
|
|
1211 XPROCESS (proc)->command = Flist (nargs - 2,
|
|
1212 args + 2);
|
|
1213
|
|
1214 /* Make the process marker point into the process buffer (if any). */
|
|
1215 if (!NILP (buffer))
|
|
1216 Fset_marker (XPROCESS (proc)->mark,
|
|
1217 make_int (BUF_ZV (XBUFFER (buffer))), buffer);
|
|
1218
|
|
1219 /* If an error occurs and we can't start the process, we want to
|
|
1220 remove it from the process list. This means that each error
|
|
1221 check in create_process doesn't need to call remove_process
|
|
1222 itself; it's all taken care of here. */
|
|
1223 record_unwind_protect (start_process_unwind, proc);
|
|
1224
|
16
|
1225 create_process (proc, new_argv, (char *) XSTRING_DATA (current_dir));
|
0
|
1226
|
|
1227 return unbind_to (speccount, proc);
|
|
1228 }
|
|
1229
|
|
1230
|
|
1231 /* connect to an existing file descriptor. This is very similar to
|
|
1232 open-network-stream except that it assumes that the connection has
|
|
1233 already been initialized. It is currently used for ToolTalk
|
|
1234 communication. */
|
|
1235
|
|
1236 /* This function used to be visible on the Lisp level, but there is no
|
|
1237 real point in doing that. Here is the doc string:
|
|
1238
|
|
1239 "Connect to an existing file descriptor.\n\
|
|
1240 Returns a subprocess-object to represent the connection.\n\
|
|
1241 Input and output work as for subprocesses; `delete-process' closes it.\n\
|
|
1242 Args are NAME BUFFER INFD OUTFD.\n\
|
|
1243 NAME is name for process. It is modified if necessary to make it unique.\n\
|
|
1244 BUFFER is the buffer (or buffer-name) to associate with the process.\n\
|
|
1245 Process output goes at end of that buffer, unless you specify\n\
|
|
1246 an output stream or filter function to handle the output.\n\
|
|
1247 BUFFER may be also nil, meaning that this process is not associated\n\
|
|
1248 with any buffer\n\
|
|
1249 INFD and OUTFD specify the file descriptors to use for input and\n\
|
|
1250 output, respectively."
|
|
1251 */
|
|
1252
|
|
1253 Lisp_Object
|
|
1254 connect_to_file_descriptor (Lisp_Object name, Lisp_Object buffer,
|
|
1255 Lisp_Object infd, Lisp_Object outfd)
|
|
1256 {
|
|
1257 /* This function can GC */
|
|
1258 Lisp_Object proc;
|
|
1259 int inch;
|
|
1260
|
|
1261 CHECK_STRING (name);
|
|
1262 CHECK_INT (infd);
|
|
1263 CHECK_INT (outfd);
|
|
1264
|
|
1265 inch = XINT (infd);
|
|
1266 if (!NILP (descriptor_to_process[inch]))
|
|
1267 error ("There is already a process connected to fd %d", inch);
|
|
1268 if (!NILP (buffer))
|
|
1269 buffer = Fget_buffer_create (buffer);
|
|
1270 proc = make_process_internal (name);
|
|
1271
|
|
1272 descriptor_to_process[inch] = proc;
|
|
1273
|
|
1274 XPROCESS (proc)->pid = Fcons (infd, name);
|
|
1275 XPROCESS (proc)->buffer = buffer;
|
|
1276 init_process_fds (XPROCESS (proc), inch, XINT (outfd));
|
|
1277 XPROCESS (proc)->connected_via_filedesc_p = 1;
|
|
1278
|
|
1279 event_stream_select_process (XPROCESS (proc));
|
|
1280
|
|
1281 return proc;
|
|
1282 }
|
|
1283
|
|
1284
|
|
1285 #ifdef HAVE_SOCKETS
|
|
1286
|
|
1287 static int
|
|
1288 get_internet_address (Lisp_Object host, struct sockaddr_in *address,
|
|
1289 Error_behavior errb)
|
|
1290 {
|
|
1291 struct hostent *host_info_ptr;
|
|
1292
|
|
1293 #ifndef HAVE_TERM
|
|
1294 memset (address, 0, sizeof (*address));
|
|
1295
|
|
1296 while (1)
|
|
1297 {
|
|
1298 #ifdef TRY_AGAIN
|
|
1299 h_errno = 0;
|
|
1300 #endif
|
|
1301 /* Some systems can't handle SIGIO/SIGALARM in gethostbyname. */
|
|
1302 slow_down_interrupts ();
|
16
|
1303 host_info_ptr = gethostbyname ((char *) XSTRING_DATA (host));
|
0
|
1304 speed_up_interrupts ();
|
|
1305 #ifdef TRY_AGAIN
|
|
1306 if (! (host_info_ptr == 0 && h_errno == TRY_AGAIN))
|
|
1307 #endif
|
|
1308 break;
|
|
1309 Fsleep_for (make_int (1));
|
|
1310 }
|
|
1311 if (host_info_ptr)
|
|
1312 {
|
|
1313 address->sin_family = host_info_ptr->h_addrtype;
|
|
1314 memcpy (&address->sin_addr, host_info_ptr->h_addr, host_info_ptr->h_length);
|
|
1315 }
|
|
1316 else
|
|
1317 {
|
|
1318 IN_ADDR numeric_addr;
|
|
1319 /* Attempt to interpret host as numeric inet address */
|
16
|
1320 numeric_addr = inet_addr ((char *) XSTRING_DATA (host));
|
0
|
1321 if (NUMERIC_ADDR_ERROR)
|
|
1322 {
|
|
1323 maybe_error (Qprocess, errb,
|
16
|
1324 "Unknown host \"%s\"", XSTRING_DATA (host));
|
0
|
1325 return 0;
|
|
1326 }
|
|
1327
|
|
1328 /* There was some broken code here that called strlen() here
|
|
1329 on (char *) &numeric_addr and even sometimes accessed
|
|
1330 uninitialized data. */
|
|
1331 address->sin_family = AF_INET;
|
|
1332 * (IN_ADDR *) &address->sin_addr = numeric_addr;
|
|
1333 }
|
|
1334
|
|
1335 return 1;
|
|
1336 }
|
|
1337
|
|
1338 /* open a TCP network connection to a given HOST/SERVICE. Treated
|
|
1339 exactly like a normal process when reading and writing. Only
|
|
1340 differences are in status display and process deletion. A network
|
|
1341 connection has no PID; you cannot signal it. All you can do is
|
|
1342 deactivate and close it via delete-process */
|
|
1343
|
20
|
1344 DEFUN ("open-network-stream-internal", Fopen_network_stream_internal, 4, 4, 0, /*
|
0
|
1345 Open a TCP connection for a service to a host.
|
|
1346 Returns a subprocess-object to represent the connection.
|
|
1347 Input and output work as for subprocesses; `delete-process' closes it.
|
|
1348 Args are NAME BUFFER HOST SERVICE.
|
|
1349 NAME is name for process. It is modified if necessary to make it unique.
|
|
1350 BUFFER is the buffer (or buffer-name) to associate with the process.
|
|
1351 Process output goes at end of that buffer, unless you specify
|
|
1352 an output stream or filter function to handle the output.
|
|
1353 BUFFER may be also nil, meaning that this process is not associated
|
|
1354 with any buffer
|
|
1355 Third arg is name of the host to connect to, or its IP address.
|
|
1356 Fourth arg SERVICE is name of the service desired, or an integer
|
|
1357 specifying a port number to connect to.
|
20
|
1358 */
|
|
1359 (name, buffer, host, service))
|
0
|
1360 {
|
|
1361 /* !!#### This function has not been Mule-ized */
|
|
1362 /* This function can GC */
|
|
1363 Lisp_Object proc;
|
|
1364 struct sockaddr_in address;
|
|
1365 int s, outch, inch;
|
|
1366 int port;
|
|
1367 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
16
|
1368 volatile int retry = 0;
|
0
|
1369 int retval;
|
|
1370
|
|
1371 GCPRO4 (name, buffer, host, service);
|
|
1372 CHECK_STRING (name);
|
|
1373 CHECK_STRING (host);
|
|
1374 if (INTP (service))
|
|
1375 port = htons ((unsigned short) XINT (service));
|
|
1376 else
|
|
1377 {
|
|
1378 struct servent *svc_info;
|
|
1379 CHECK_STRING (service);
|
16
|
1380 svc_info = getservbyname ((char *) XSTRING_DATA (service), "tcp");
|
0
|
1381 if (svc_info == 0)
|
|
1382 #ifdef WIN32
|
|
1383 error ("Unknown service \"%s\" (%d)",
|
16
|
1384 XSTRING_DATA (service), WSAGetLastError ());
|
0
|
1385 #else
|
16
|
1386 error ("Unknown service \"%s\"", XSTRING_DATA (service));
|
0
|
1387 #endif
|
|
1388 port = svc_info->s_port;
|
|
1389 }
|
|
1390
|
|
1391 get_internet_address (host, &address, ERROR_ME);
|
|
1392 address.sin_port = port;
|
|
1393
|
|
1394 s = socket (address.sin_family, SOCK_STREAM, 0);
|
|
1395 if (s < 0)
|
|
1396 report_file_error ("error creating socket", list1 (name));
|
|
1397
|
|
1398 /* Turn off interrupts here -- see comments below. There used to
|
|
1399 be code which called bind_polling_period() to slow the polling
|
|
1400 period down rather than turn it off, but that seems rather
|
|
1401 bogus to me. Best thing here is to use a non-blocking connect
|
|
1402 or something, to check for QUIT. */
|
|
1403
|
|
1404 /* Comments that are not quite valid: */
|
|
1405
|
|
1406 /* Kernel bugs (on Ultrix at least) cause lossage (not just EINTR)
|
|
1407 when connect is interrupted. So let's not let it get interrupted.
|
|
1408 Note we do not turn off polling, because polling is only used
|
|
1409 when not interrupt_input, and thus not normally used on the systems
|
|
1410 which have this bug. On systems which use polling, there's no way
|
|
1411 to quit if polling is turned off. */
|
|
1412
|
|
1413 /* Slow down polling. Some kernels have a bug which causes retrying
|
|
1414 connect to fail after a connect. */
|
|
1415
|
|
1416 slow_down_interrupts ();
|
|
1417
|
|
1418 loop:
|
|
1419
|
|
1420 /* A system call interrupted with a SIGALRM or SIGIO comes back
|
|
1421 here, with can_break_system_calls reset to 0. */
|
|
1422 SETJMP (break_system_call_jump);
|
|
1423 if (QUITP)
|
|
1424 {
|
|
1425 speed_up_interrupts ();
|
|
1426 REALLY_QUIT;
|
|
1427 /* In case something really weird happens ... */
|
|
1428 slow_down_interrupts ();
|
|
1429 }
|
|
1430
|
|
1431 /* Break out of connect with a signal (it isn't otherwise possible).
|
|
1432 Thus you don't get screwed with a hung network. */
|
|
1433 can_break_system_calls = 1;
|
|
1434 retval = connect (s, (struct sockaddr *) &address, sizeof (address));
|
|
1435 can_break_system_calls = 0;
|
|
1436 if (retval == -1 && errno != EISCONN)
|
|
1437 {
|
|
1438 int xerrno = errno;
|
|
1439 if (errno == EINTR)
|
|
1440 goto loop;
|
|
1441 if (errno == EADDRINUSE && retry < 20)
|
|
1442 {
|
|
1443 /* A delay here is needed on some FreeBSD systems,
|
|
1444 and it is harmless, since this retrying takes time anyway
|
|
1445 and should be infrequent. */
|
|
1446 Fsleep_for (make_int (1));
|
|
1447 retry++;
|
|
1448 goto loop;
|
|
1449 }
|
|
1450
|
|
1451 close (s);
|
|
1452
|
|
1453 speed_up_interrupts ();
|
|
1454
|
|
1455 errno = xerrno;
|
|
1456 report_file_error ("connection failed", list2 (host, name));
|
|
1457 }
|
|
1458
|
|
1459 speed_up_interrupts ();
|
|
1460
|
|
1461 #else /* HAVE_TERM */
|
|
1462 s = connect_server (0);
|
|
1463 if (s < 0)
|
|
1464 report_file_error ("error creating socket", Fcons (name, Qnil));
|
16
|
1465 send_command (s, C_PORT, 0, "%s:%d", XSTRING_DATA (host), ntohs (port));
|
0
|
1466 send_command (s, C_DUMB, 1, 0);
|
|
1467 #endif /* HAVE_TERM */
|
|
1468
|
|
1469 inch = s;
|
|
1470 outch = dup (s);
|
|
1471 if (outch < 0)
|
|
1472 {
|
|
1473 close (s); /* this used to be leaked; from Kyle Jones */
|
|
1474 report_file_error ("error duplicating socket", list1 (name));
|
|
1475 }
|
|
1476
|
|
1477 if (!NILP (buffer))
|
|
1478 buffer = Fget_buffer_create (buffer);
|
|
1479 proc = make_process_internal (name);
|
|
1480
|
|
1481 descriptor_to_process[inch] = proc;
|
|
1482
|
|
1483 set_descriptor_non_blocking (inch);
|
|
1484
|
|
1485 XPROCESS (proc)->pid = Fcons (service, host);
|
|
1486 XPROCESS (proc)->buffer = buffer;
|
|
1487 init_process_fds (XPROCESS (proc), inch, outch);
|
|
1488 XPROCESS (proc)->connected_via_filedesc_p = 0;
|
|
1489
|
|
1490 event_stream_select_process (XPROCESS (proc));
|
|
1491
|
|
1492 UNGCPRO;
|
|
1493 return proc;
|
|
1494 }
|
|
1495
|
|
1496 #endif /* HAVE_SOCKETS */
|
|
1497
|
|
1498 Lisp_Object
|
|
1499 canonicalize_host_name (Lisp_Object host)
|
|
1500 {
|
|
1501 #ifdef HAVE_SOCKETS
|
|
1502 /* #### for HAVE_TERM, you probably have to do something else. */
|
|
1503 struct sockaddr_in address;
|
|
1504
|
|
1505 if (!get_internet_address (host, &address, ERROR_ME_NOT))
|
|
1506 return host;
|
|
1507
|
|
1508 if (address.sin_family == AF_INET)
|
|
1509 return build_string (inet_ntoa (address.sin_addr));
|
|
1510 else
|
|
1511 /* #### any clue what to do here? */
|
|
1512 return host;
|
|
1513 #else
|
|
1514 return host;
|
|
1515 #endif
|
|
1516 }
|
|
1517
|
|
1518
|
20
|
1519 DEFUN ("set-process-window-size", Fset_process_window_size, 3, 3, 0, /*
|
0
|
1520 Tell PROCESS that it has logical window size HEIGHT and WIDTH.
|
20
|
1521 */
|
|
1522 (proc, height, width))
|
0
|
1523 {
|
|
1524 CHECK_PROCESS (proc);
|
|
1525 CHECK_NATNUM (height);
|
|
1526 CHECK_NATNUM (width);
|
|
1527 if (set_window_size (XPROCESS (proc)->infd, XINT (height), XINT (width))
|
|
1528 <= 0)
|
|
1529 return Qnil;
|
|
1530 else
|
|
1531 return Qt;
|
|
1532 }
|
|
1533
|
|
1534
|
|
1535 /************************************************************************/
|
|
1536 /* Process I/O */
|
|
1537 /************************************************************************/
|
|
1538
|
|
1539 /* (Faccept_process_output is now in event-stream.c) */
|
|
1540
|
|
1541 /* Some FSFmacs error handlers here. We handle this
|
|
1542 in call2_trapping_errors(). */
|
|
1543
|
|
1544 /* Read pending output from the process channel,
|
|
1545 starting with our buffered-ahead character if we have one.
|
|
1546 Yield number of characters read.
|
|
1547
|
|
1548 This function reads at most 1024 bytes.
|
|
1549 If you want to read all available subprocess output,
|
|
1550 you must call it repeatedly until it returns zero. */
|
|
1551
|
|
1552 Charcount
|
|
1553 read_process_output (Lisp_Object proc)
|
|
1554 {
|
|
1555 /* This function can GC */
|
|
1556 Bytecount nbytes, nchars;
|
|
1557 #ifdef VMS
|
|
1558 char *chars;
|
|
1559 #else
|
|
1560 Bufbyte chars[1024];
|
|
1561 #endif
|
|
1562 Lisp_Object outstream;
|
|
1563 struct Lisp_Process *p = XPROCESS (proc);
|
|
1564
|
|
1565 /* If there is a lot of output from the subprocess, the loop in
|
|
1566 execute_internal_event() might call read_process_output() more
|
|
1567 than once. If the filter that was executed from one of these
|
|
1568 calls set the filter to t, we have to stop now. Return -1 rather
|
|
1569 than 0 so execute_internal_event() doesn't close the process.
|
|
1570 Really, the loop in execute_internal_event() should check itself
|
|
1571 for a process-filter change, like in status_notify(); but the
|
|
1572 struct Lisp_Process is not exported outside of this file. */
|
|
1573 if (p->infd < 0)
|
|
1574 return -1; /* already closed */
|
|
1575
|
|
1576 if (!NILP (p->filter) && (p->filter_does_read))
|
|
1577 {
|
|
1578 Lisp_Object filter_result;
|
|
1579
|
|
1580 /* Some weird FSFmacs crap here with
|
|
1581 Vdeactivate_mark and current_buffer->keymap */
|
|
1582 running_asynch_code = 1;
|
|
1583 filter_result = call2_trapping_errors ("Error in process filter",
|
|
1584 p->filter, proc, Qnil);
|
|
1585 running_asynch_code = 0;
|
|
1586 restore_match_data ();
|
|
1587 CHECK_INT (filter_result);
|
|
1588 return XINT (filter_result);
|
|
1589 }
|
|
1590
|
|
1591 #ifdef VMS
|
|
1592 VMS_PROC_STUFF *vs, *get_vms_process_pointer();
|
|
1593
|
|
1594 vs = get_vms_process_pointer (XINT (p->pid));
|
|
1595 if (vs)
|
|
1596 {
|
|
1597 if (!vs->iosb[0])
|
|
1598 return(0); /* Really weird if it does this */
|
|
1599 if (!(vs->iosb[0] & 1))
|
|
1600 return -1; /* I/O error */
|
|
1601 }
|
|
1602 else
|
|
1603 error ("Could not get VMS process pointer");
|
|
1604 chars = vs->inputBuffer;
|
|
1605 nbytes = clean_vms_buffer (chars, vs->iosb[1]);
|
|
1606 if (nbytes <= 0)
|
|
1607 {
|
|
1608 start_vms_process_read (vs); /* Crank up the next read on the process */
|
|
1609 return 1; /* Nothing worth printing, say we got 1 */
|
|
1610 }
|
|
1611 #else /* not VMS */
|
|
1612
|
|
1613 #if 0 /* FSFmacs */
|
|
1614 /* #### equivalent code from FSFmacs. Would need some porting
|
|
1615 for Windows NT. */
|
|
1616 if (proc_buffered_char[channel] < 0)
|
|
1617 #ifdef WINDOWSNT
|
|
1618 nchars = read_child_output (channel, chars, sizeof (chars));
|
|
1619 #else
|
|
1620 nchars = read (channel, chars, sizeof chars);
|
|
1621 #endif
|
|
1622 else
|
|
1623 {
|
|
1624 chars[0] = proc_buffered_char[channel];
|
|
1625 proc_buffered_char[channel] = -1;
|
|
1626 #ifdef WINDOWSNT
|
|
1627 nchars = read_child_output (channel, chars + 1, sizeof (chars) - 1);
|
|
1628 #else
|
|
1629 nchars = read (channel, chars + 1, sizeof chars - 1);
|
|
1630 #endif
|
|
1631 if (nchars < 0)
|
|
1632 nchars = 1;
|
|
1633 else
|
|
1634 nchars = nchars + 1;
|
|
1635 }
|
|
1636 #endif /* FSFmacs */
|
|
1637
|
|
1638 nbytes = Lstream_read (XLSTREAM (p->instream), chars, sizeof (chars));
|
|
1639 if (nbytes <= 0) return nbytes;
|
|
1640 #endif /* not VMS */
|
|
1641
|
|
1642 nchars = bytecount_to_charcount (chars, nbytes);
|
|
1643 outstream = p->filter;
|
|
1644 if (!NILP (outstream))
|
|
1645 {
|
|
1646 /* We used to bind inhibit-quit to t here, but
|
|
1647 call2_trapping_errors() does that for us. */
|
|
1648 running_asynch_code = 1;
|
|
1649 call2_trapping_errors ("Error in process filter",
|
|
1650 outstream, proc, make_string (chars, nbytes));
|
|
1651 running_asynch_code = 0;
|
|
1652 restore_match_data ();
|
|
1653 #ifdef VMS
|
|
1654 start_vms_process_read (vs);
|
|
1655 #endif
|
|
1656 return (nchars);
|
|
1657 }
|
|
1658
|
|
1659 /* If no filter, write into buffer if it isn't dead. */
|
|
1660 if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer)))
|
|
1661 {
|
|
1662 Lisp_Object old_read_only = Qnil;
|
|
1663 Bufpos old_point;
|
|
1664 Bufpos old_begv;
|
|
1665 Bufpos old_zv;
|
|
1666 int old_zmacs_region_stays = zmacs_region_stays;
|
|
1667 struct gcpro gcpro1, gcpro2;
|
|
1668 struct buffer *buf = XBUFFER (p->buffer);
|
|
1669
|
|
1670 GCPRO2 (proc, old_read_only);
|
|
1671
|
|
1672 old_point = BUF_PT (buf);
|
|
1673 old_begv = BUF_BEGV (buf);
|
|
1674 old_zv = BUF_ZV (buf);
|
|
1675 old_read_only = buf->read_only;
|
|
1676 buf->read_only = Qnil;
|
|
1677
|
|
1678 /* Insert new output into buffer
|
|
1679 at the current end-of-output marker,
|
|
1680 thus preserving logical ordering of input and output. */
|
|
1681 if (XMARKER (p->mark)->buffer)
|
|
1682 BUF_SET_PT (buf,
|
|
1683 bufpos_clip_to_bounds (old_begv, marker_position (p->mark),
|
|
1684 old_zv));
|
|
1685 else
|
|
1686 BUF_SET_PT (buf, old_zv);
|
|
1687
|
|
1688 /* If the output marker is outside of the visible region, save
|
|
1689 the restriction and widen. */
|
|
1690 if (! (BUF_BEGV (buf) <= BUF_PT (buf) &&
|
|
1691 BUF_PT (buf) <= BUF_ZV (buf)))
|
|
1692 Fwiden (p->buffer);
|
|
1693
|
|
1694 /* Make sure opoint floats ahead of any new text, just as point
|
|
1695 would. */
|
|
1696 if (BUF_PT (buf) <= old_point)
|
|
1697 old_point += nchars;
|
|
1698
|
|
1699 /* Insert after old_begv, but before old_zv. */
|
|
1700 if (BUF_PT (buf) < old_begv)
|
|
1701 old_begv += nchars;
|
|
1702 if (BUF_PT (buf) <= old_zv)
|
|
1703 old_zv += nchars;
|
|
1704
|
|
1705 #if 0
|
|
1706 /* This screws up intial display of the window. jla */
|
|
1707
|
|
1708 /* Insert before markers in case we are inserting where
|
|
1709 the buffer's mark is, and the user's next command is Meta-y. */
|
|
1710 buffer_insert_raw_string_1 (buf, -1, chars,
|
|
1711 nbytes, INSDEL_BEFORE_MARKERS);
|
|
1712 #else
|
|
1713 buffer_insert_raw_string (buf, chars, nbytes);
|
|
1714 #endif
|
|
1715
|
|
1716 Fset_marker (p->mark, make_int (BUF_PT (buf)), p->buffer);
|
|
1717
|
|
1718 MARK_MODELINE_CHANGED;
|
|
1719
|
|
1720 /* If the restriction isn't what it should be, set it. */
|
|
1721 if (old_begv != BUF_BEGV (buf) || old_zv != BUF_ZV (buf))
|
|
1722 Fnarrow_to_region (make_int (old_begv), make_int (old_zv),
|
|
1723 p->buffer);
|
|
1724
|
|
1725 /* Handling the process output should not deactivate the mark. */
|
|
1726 zmacs_region_stays = old_zmacs_region_stays;
|
|
1727 buf->read_only = old_read_only;
|
|
1728 BUF_SET_PT (buf, old_point);
|
|
1729
|
|
1730 UNGCPRO;
|
|
1731 }
|
|
1732 #ifdef VMS
|
|
1733 start_vms_process_read (vs);
|
|
1734 #endif
|
|
1735 return (nchars);
|
|
1736 }
|
|
1737
|
|
1738 /* Sending data to subprocess */
|
|
1739
|
|
1740 static JMP_BUF send_process_frame;
|
|
1741
|
|
1742 static SIGTYPE
|
|
1743 send_process_trap (int signum)
|
|
1744 {
|
|
1745 EMACS_REESTABLISH_SIGNAL (signum, send_process_trap);
|
|
1746 EMACS_UNBLOCK_SIGNAL (signum);
|
|
1747 LONGJMP (send_process_frame, 1);
|
|
1748 }
|
|
1749
|
|
1750 /* send some data to process PROC. If NONRELOCATABLE is non-NULL, it
|
|
1751 specifies the address of the data. Otherwise, the data comes from the
|
|
1752 object RELOCATABLE (either a string or a buffer). START and LEN
|
|
1753 specify the offset and length of the data to send.
|
|
1754
|
|
1755 Note that START and LEN are in Bufpos's if RELOCATABLE is a buffer,
|
|
1756 and in Bytecounts otherwise. */
|
|
1757
|
|
1758 static void
|
|
1759 send_process (volatile Lisp_Object proc,
|
|
1760 Lisp_Object relocatable, CONST Bufbyte *nonrelocatable,
|
|
1761 int start, int len)
|
|
1762 {
|
|
1763 /* This function can GC */
|
|
1764 /* Use volatile to protect variables from being clobbered by longjmp. */
|
|
1765 struct gcpro gcpro1, gcpro2;
|
16
|
1766 SIGTYPE (*volatile old_sigpipe) (int) = 0;
|
0
|
1767 Lisp_Object lstream = Qnil;
|
|
1768 volatile struct Lisp_Process *p = XPROCESS (proc);
|
|
1769 #if defined (NO_UNION_TYPE) /* || !defined (__GNUC__) GCC bug only??? */
|
|
1770 /* #### ugh! There must be a better solution. */
|
|
1771 Lisp_Object defeat_volatile_kludge = (Lisp_Object) proc;
|
|
1772 #else
|
|
1773 Lisp_Object defeat_volatile_kludge = proc;
|
|
1774 #endif
|
|
1775
|
|
1776 #ifdef VMS
|
|
1777 VMS_PROC_STUFF *vs, *get_vms_process_pointer (int);
|
|
1778 #endif /* VMS */
|
|
1779
|
|
1780 GCPRO2 (defeat_volatile_kludge, lstream);
|
|
1781
|
|
1782 if (p->outfd < 0)
|
|
1783 signal_simple_error ("Process not open for writing", proc);
|
|
1784
|
|
1785 #ifdef VMS
|
|
1786 vs = get_vms_process_pointer (XINT (p->pid));
|
|
1787 if (vs == 0)
|
|
1788 error ("Could not find this process: %x",
|
|
1789 XINT (p->pid));
|
|
1790 else if (write_to_vms_process (vs, buf, len))
|
|
1791 ;
|
|
1792 #else
|
|
1793
|
|
1794 if (nonrelocatable)
|
|
1795 lstream =
|
|
1796 make_fixed_buffer_input_stream (nonrelocatable + start, len);
|
|
1797 else if (GC_BUFFERP (relocatable))
|
|
1798 lstream = make_lisp_buffer_input_stream (XBUFFER (relocatable),
|
|
1799 start, start + len, 0);
|
|
1800 else
|
|
1801 lstream = make_lisp_string_input_stream (relocatable, start, len);
|
|
1802
|
|
1803 if (!SETJMP (send_process_frame))
|
|
1804 {
|
|
1805 /* use a reasonable-sized buffer (somewhere around the size of the
|
|
1806 stream buffer) so as to avoid inundating the stream with blocked
|
|
1807 data. */
|
|
1808 Bufbyte chunkbuf[512];
|
|
1809 Bytecount chunklen;
|
|
1810
|
|
1811 while (1)
|
|
1812 {
|
|
1813 int writeret;
|
|
1814
|
|
1815 chunklen = Lstream_read (XLSTREAM (lstream), chunkbuf, 512);
|
|
1816 if (chunklen <= 0)
|
|
1817 break; /* perhaps should abort() if < 0?
|
|
1818 This should never happen. */
|
|
1819 old_sigpipe =
|
|
1820 (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
|
|
1821 /* Lstream_write() will never successfully write less than
|
|
1822 the amount sent in. In the worst case, it just buffers
|
|
1823 the unwritten data. */
|
|
1824 writeret = Lstream_write (XLSTREAM (p->outstream), chunkbuf,
|
|
1825 chunklen);
|
|
1826 signal (SIGPIPE, old_sigpipe);
|
|
1827 if (writeret < 0)
|
|
1828 /* This is a real error. Blocking errors are handled
|
|
1829 specially inside of the filedesc stream. */
|
|
1830 report_file_error ("writing to process",
|
|
1831 list1 (proc));
|
|
1832 while (filedesc_stream_was_blocked (XLSTREAM (p->filedesc_stream)))
|
|
1833 {
|
|
1834 /* Buffer is full. Wait, accepting input;
|
|
1835 that may allow the program
|
|
1836 to finish doing output and read more. */
|
|
1837 Faccept_process_output (Qnil, make_int (1), Qnil);
|
|
1838 old_sigpipe =
|
|
1839 (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
|
|
1840 Lstream_flush (XLSTREAM (p->filedesc_stream));
|
|
1841 signal (SIGPIPE, old_sigpipe);
|
|
1842 }
|
|
1843 }
|
|
1844 }
|
|
1845 #endif /* !VMS */
|
|
1846 else
|
|
1847 { /* We got here from a longjmp() from the SIGPIPE handler */
|
|
1848 signal (SIGPIPE, old_sigpipe);
|
|
1849 p->status_symbol = Qexit;
|
|
1850 p->exit_code = 256; /* #### SIGPIPE ??? */
|
|
1851 p->core_dumped = 0;
|
|
1852 p->tick++;
|
|
1853 process_tick++;
|
|
1854 deactivate_process (proc);
|
|
1855 #ifdef VMS
|
|
1856 error ("Error writing to process %s; closed it",
|
16
|
1857 XSTRING_DATA (p->name));
|
0
|
1858 #else
|
|
1859 error ("SIGPIPE raised on process %s; closed it",
|
16
|
1860 XSTRING_DATA (p->name));
|
0
|
1861 #endif
|
|
1862 }
|
|
1863 Lstream_flush (XLSTREAM (p->outstream));
|
|
1864 UNGCPRO;
|
|
1865 }
|
|
1866
|
20
|
1867 DEFUN ("process-tty-name", Fprocess_tty_name, 1, 1, 0, /*
|
0
|
1868 Return the name of the terminal PROCESS uses, or nil if none.
|
|
1869 This is the terminal that the process itself reads and writes on,
|
|
1870 not the name of the pty that Emacs uses to talk with that terminal.
|
20
|
1871 */
|
|
1872 (proc))
|
0
|
1873 {
|
|
1874 CHECK_PROCESS (proc);
|
|
1875 return XPROCESS (proc)->tty_name;
|
|
1876 }
|
|
1877
|
20
|
1878 DEFUN ("set-process-buffer", Fset_process_buffer, 2, 2, 0, /*
|
0
|
1879 Set buffer associated with PROCESS to BUFFER (a buffer, or nil).
|
20
|
1880 */
|
|
1881 (proc, buffer))
|
0
|
1882 {
|
|
1883 CHECK_PROCESS (proc);
|
|
1884 if (!NILP (buffer))
|
|
1885 CHECK_BUFFER (buffer);
|
|
1886 XPROCESS (proc)->buffer = buffer;
|
|
1887 return buffer;
|
|
1888 }
|
|
1889
|
20
|
1890 DEFUN ("process-buffer", Fprocess_buffer, 1, 1, 0, /*
|
0
|
1891 Return the buffer PROCESS is associated with.
|
|
1892 Output from PROCESS is inserted in this buffer
|
|
1893 unless PROCESS has a filter.
|
20
|
1894 */
|
|
1895 (proc))
|
0
|
1896 {
|
|
1897 CHECK_PROCESS (proc);
|
|
1898 return XPROCESS (proc)->buffer;
|
|
1899 }
|
|
1900
|
20
|
1901 DEFUN ("process-mark", Fprocess_mark, 1, 1, 0, /*
|
0
|
1902 Return the marker for the end of the last output from PROCESS.
|
20
|
1903 */
|
|
1904 (proc))
|
0
|
1905 {
|
|
1906 CHECK_PROCESS (proc);
|
|
1907 #ifdef ENERGIZE
|
|
1908 if (EQ (proc, Venergize_process)) /* per buffer rather than per process */
|
|
1909 return Fenergize_user_input_buffer_mark (Qnil); /* ## current_buffer ok? */
|
|
1910 #endif
|
|
1911 return XPROCESS (proc)->mark;
|
|
1912 }
|
|
1913
|
|
1914 void
|
|
1915 set_process_filter (Lisp_Object proc, Lisp_Object filter, int filter_does_read)
|
|
1916 {
|
|
1917 CHECK_PROCESS (proc);
|
|
1918 if (PROCESS_LIVE_P (proc))
|
|
1919 if (EQ (filter, Qt))
|
|
1920 event_stream_unselect_process (XPROCESS (proc));
|
|
1921 else
|
|
1922 event_stream_select_process (XPROCESS (proc));
|
|
1923
|
|
1924 XPROCESS (proc)->filter = filter;
|
|
1925 XPROCESS (proc)->filter_does_read = filter_does_read;
|
|
1926 }
|
|
1927
|
20
|
1928 DEFUN ("set-process-filter", Fset_process_filter, 2, 2, 0, /*
|
0
|
1929 Give PROCESS the filter function FILTER; nil means no filter.
|
|
1930 t means stop accepting output from the process.
|
|
1931 When a process has a filter, each time it does output
|
|
1932 the entire string of output is passed to the filter.
|
|
1933 The filter gets two arguments: the process and the string of output.
|
|
1934 If the process has a filter, its buffer is not used for output.
|
20
|
1935 */
|
|
1936 (proc, filter))
|
0
|
1937 {
|
|
1938 set_process_filter (proc, filter, 0);
|
|
1939 return filter;
|
|
1940 }
|
|
1941
|
20
|
1942 DEFUN ("process-filter", Fprocess_filter, 1, 1, 0, /*
|
0
|
1943 Return the filter function of PROCESS; nil if none.
|
|
1944 See `set-process-filter' for more info on filter functions.
|
20
|
1945 */
|
|
1946 (proc))
|
0
|
1947 {
|
|
1948 CHECK_PROCESS (proc);
|
|
1949 return XPROCESS (proc)->filter;
|
|
1950 }
|
|
1951
|
20
|
1952 DEFUN ("process-send-region", Fprocess_send_region, 3, 3, 0, /*
|
0
|
1953 Send current contents of region as input to PROCESS.
|
|
1954 PROCESS may be a process name or an actual process.
|
|
1955 Called from program, takes three arguments, PROCESS, START and END.
|
|
1956 If the region is more than 500 or so characters long,
|
|
1957 it is sent in several bunches. This may happen even for shorter regions.
|
|
1958 Output from processes can arrive in between bunches.
|
20
|
1959 */
|
|
1960 (process, start, end))
|
0
|
1961 {
|
|
1962 /* This function can GC */
|
|
1963 Lisp_Object proc = get_process (process);
|
|
1964 Bufpos st, en;
|
|
1965
|
|
1966 get_buffer_range_char (current_buffer, start, end, &st, &en, 0);
|
|
1967
|
|
1968 send_process (proc, Fcurrent_buffer (), 0,
|
|
1969 st, en - st);
|
|
1970 return (Qnil);
|
|
1971 }
|
|
1972
|
20
|
1973 DEFUN ("process-send-string", Fprocess_send_string, 2, 4, 0, /*
|
0
|
1974 Send PROCESS the contents of STRING as input.
|
|
1975 PROCESS may be a process name or an actual process.
|
|
1976 Optional arguments FROM and TO specify part of STRING, see `substring'.
|
|
1977 If STRING is more than 500 or so characters long,
|
|
1978 it is sent in several bunches. This may happen even for shorter strings.
|
|
1979 Output from processes can arrive in between bunches.
|
20
|
1980 */
|
|
1981 (process, string, from, to))
|
0
|
1982 {
|
|
1983 /* This function can GC */
|
|
1984 Lisp_Object proc;
|
|
1985 Bytecount len;
|
|
1986 Bytecount bfr, bto;
|
|
1987
|
|
1988 proc = get_process (process);
|
|
1989 CHECK_STRING (string);
|
|
1990 get_string_range_byte (string, from, to, &bfr, &bto,
|
|
1991 GB_HISTORICAL_STRING_BEHAVIOR);
|
|
1992 len = bto - bfr;
|
|
1993
|
|
1994 send_process (proc, string, 0, bfr, len);
|
|
1995 return (Qnil);
|
|
1996 }
|
|
1997
|
|
1998
|
|
1999 /************************************************************************/
|
|
2000 /* process status */
|
|
2001 /************************************************************************/
|
|
2002
|
|
2003 /* Some FSFmacs error handlers here. We handle this
|
|
2004 in call2_trapping_errors(). */
|
|
2005
|
|
2006 static Lisp_Object
|
|
2007 exec_sentinel_unwind (Lisp_Object datum)
|
|
2008 {
|
|
2009 struct Lisp_Cons *d = XCONS (datum);
|
|
2010 XPROCESS (d->car)->sentinel = d->cdr;
|
|
2011 free_cons (d);
|
|
2012 return Qnil;
|
|
2013 }
|
|
2014
|
|
2015 static void
|
|
2016 exec_sentinel (Lisp_Object proc, Lisp_Object reason)
|
|
2017 {
|
|
2018 /* This function can GC */
|
|
2019 Lisp_Object sentinel;
|
|
2020 struct Lisp_Process *p = XPROCESS (proc);
|
|
2021 int speccount = specpdl_depth ();
|
|
2022
|
|
2023 sentinel = p->sentinel;
|
|
2024 if (NILP (sentinel))
|
|
2025 return;
|
|
2026
|
|
2027 /* Some weird FSFmacs crap here with
|
|
2028 Vdeactivate_mark and current_buffer->keymap */
|
|
2029
|
|
2030 /* Zilch the sentinel while it's running, to avoid recursive invocations;
|
|
2031 assure that it gets restored no matter how the sentinel exits. */
|
|
2032 p->sentinel = Qnil;
|
|
2033 record_unwind_protect (exec_sentinel_unwind, noseeum_cons (proc, sentinel));
|
|
2034 /* We used to bind inhibit-quit to t here, but call2_trapping_errors()
|
|
2035 does that for us. */
|
|
2036 running_asynch_code = 1;
|
|
2037 call2_trapping_errors ("Error in process sentinel",
|
|
2038 sentinel, proc, reason);
|
|
2039 running_asynch_code = 0;
|
|
2040 restore_match_data ();
|
|
2041 unbind_to (speccount, Qnil);
|
|
2042 }
|
|
2043
|
20
|
2044 DEFUN ("set-process-sentinel", Fset_process_sentinel, 2, 2, 0, /*
|
0
|
2045 Give PROCESS the sentinel SENTINEL; nil for none.
|
|
2046 The sentinel is called as a function when the process changes state.
|
|
2047 It gets two arguments: the process, and a string describing the change.
|
20
|
2048 */
|
|
2049 (proc, sentinel))
|
0
|
2050 {
|
|
2051 CHECK_PROCESS (proc);
|
|
2052 XPROCESS (proc)->sentinel = sentinel;
|
|
2053 return sentinel;
|
|
2054 }
|
|
2055
|
20
|
2056 DEFUN ("process-sentinel", Fprocess_sentinel, 1, 1, 0, /*
|
0
|
2057 Return the sentinel of PROCESS; nil if none.
|
|
2058 See `set-process-sentinel' for more info on sentinels.
|
20
|
2059 */
|
|
2060 (proc))
|
0
|
2061 {
|
|
2062 CHECK_PROCESS (proc);
|
|
2063 return XPROCESS (proc)->sentinel;
|
|
2064 }
|
|
2065
|
|
2066
|
|
2067 CONST char *
|
|
2068 signal_name (int signum)
|
|
2069 {
|
|
2070 if (signum >= 0 && signum < NSIG)
|
|
2071 #ifndef VMS
|
|
2072 return ((CONST char *) sys_siglist[signum]);
|
|
2073 #else
|
|
2074 return ((CONST char *) sys_errlist[signum]);
|
|
2075 #endif
|
|
2076 return ((CONST char *) GETTEXT ("unknown signal"));
|
|
2077 }
|
|
2078
|
|
2079 /* Compute the Lisp form of the process status from
|
|
2080 the numeric status that was returned by `wait'. */
|
|
2081
|
|
2082 static void
|
|
2083 update_status_from_wait_code (struct Lisp_Process *p, WAITTYPE *w_fmh)
|
|
2084 {
|
|
2085 /* C compiler lossage when attempting to pass w directly */
|
|
2086 WAITTYPE w = *w_fmh;
|
|
2087
|
|
2088 if (WIFSTOPPED (w))
|
|
2089 {
|
|
2090 p->status_symbol = Qstop;
|
|
2091 p->exit_code = WSTOPSIG (w);
|
|
2092 p->core_dumped = 0;
|
|
2093 }
|
|
2094 else if (WIFEXITED (w))
|
|
2095 {
|
|
2096 p->status_symbol = Qexit;
|
|
2097 p->exit_code = WRETCODE (w);
|
|
2098 p->core_dumped = ((WCOREDUMP (w)) ? 1 : 0);
|
|
2099 }
|
|
2100 else if (WIFSIGNALED (w))
|
|
2101 {
|
|
2102 p->status_symbol = Qsignal;
|
|
2103 p->exit_code = (int) WTERMSIG (w);
|
|
2104 p->core_dumped = ((WCOREDUMP (w)) ? 1 : 0);
|
|
2105 }
|
|
2106 else
|
|
2107 {
|
|
2108 p->status_symbol = Qrun;
|
|
2109 p->exit_code = 0;
|
|
2110 }
|
|
2111 }
|
|
2112
|
|
2113 void
|
|
2114 update_process_status (Lisp_Object p,
|
|
2115 Lisp_Object status_symbol,
|
|
2116 int exit_code,
|
|
2117 int core_dumped)
|
|
2118 {
|
|
2119 XPROCESS (p)->tick++;
|
|
2120 process_tick++;
|
|
2121 XPROCESS (p)->status_symbol = status_symbol;
|
|
2122 XPROCESS (p)->exit_code = exit_code;
|
|
2123 XPROCESS (p)->core_dumped = core_dumped;
|
|
2124 }
|
|
2125
|
|
2126 #ifdef SIGCHLD
|
|
2127
|
|
2128 #define MAX_EXITED_PROCESSES 1000
|
|
2129 static volatile pid_t exited_processes[MAX_EXITED_PROCESSES];
|
|
2130 static volatile WAITTYPE exited_processes_status[MAX_EXITED_PROCESSES];
|
|
2131 static volatile int exited_processes_index;
|
|
2132
|
|
2133 static volatile int sigchld_happened;
|
|
2134
|
|
2135 /* For any processes that have changed status and are recorded
|
|
2136 and such, update the corresponding struct Lisp_Process.
|
|
2137 We separate this from record_exited_processes() so that
|
|
2138 we never have to call this function from within a signal
|
|
2139 handler. We block SIGCHLD in case record_exited_processes()
|
|
2140 is called from a signal handler. */
|
|
2141
|
|
2142 static void
|
|
2143 reap_exited_processes (void)
|
|
2144 {
|
|
2145 int i;
|
|
2146 struct Lisp_Process *p;
|
|
2147
|
|
2148 EMACS_BLOCK_SIGNAL (SIGCHLD);
|
|
2149 for (i = 0; i < exited_processes_index; i++)
|
|
2150 {
|
|
2151 int pid = exited_processes[i];
|
|
2152 WAITTYPE w = exited_processes_status[i];
|
|
2153
|
|
2154 /* Find the process that signaled us, and record its status. */
|
|
2155
|
|
2156 p = 0;
|
|
2157 {
|
|
2158 Lisp_Object tail;
|
|
2159 LIST_LOOP (tail, Vprocess_list)
|
|
2160 {
|
|
2161 Lisp_Object proc = XCAR (tail);
|
|
2162 p = XPROCESS (proc);
|
|
2163 if (INTP (p->pid) && XINT (p->pid) == pid)
|
|
2164 break;
|
|
2165 p = 0;
|
|
2166 }
|
|
2167 }
|
|
2168
|
|
2169 if (p)
|
|
2170 {
|
|
2171 /* Change the status of the process that was found. */
|
|
2172 p->tick++;
|
|
2173 process_tick++;
|
|
2174 update_status_from_wait_code (p, &w);
|
|
2175
|
|
2176 /* If process has terminated, stop waiting for its output. */
|
|
2177 if (WIFSIGNALED (w) || WIFEXITED (w))
|
|
2178 {
|
|
2179 if (p->infd >= 0)
|
|
2180 {
|
|
2181 /* We can't just call event_stream->unselect_process_cb (p)
|
|
2182 here, because that calls XtRemoveInput, which is not
|
|
2183 necessarily reentrant, so we can't call this at interrupt
|
|
2184 level.
|
|
2185 */
|
|
2186 }
|
|
2187 }
|
|
2188 }
|
|
2189 else
|
|
2190 {
|
|
2191 /* There was no asynchronous process found for that id. Check
|
|
2192 if we have a synchronous process. Only set sync process status
|
|
2193 if there is one, so we work OK with the waitpid() call in
|
|
2194 wait_for_termination(). */
|
|
2195 if (synch_process_alive != 0)
|
|
2196 { /* Set the global sync process status variables. */
|
|
2197 synch_process_alive = 0;
|
|
2198
|
|
2199 /* Report the status of the synchronous process. */
|
|
2200 if (WIFEXITED (w))
|
|
2201 synch_process_retcode = WRETCODE (w);
|
|
2202 else if (WIFSIGNALED (w))
|
|
2203 synch_process_death = signal_name (WTERMSIG (w));
|
|
2204 }
|
|
2205 }
|
|
2206 }
|
|
2207
|
|
2208 exited_processes_index = 0;
|
|
2209
|
|
2210 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
|
|
2211 }
|
|
2212
|
|
2213 /* On receipt of a signal that a child status has changed,
|
|
2214 loop asking about children with changed statuses until
|
|
2215 the system says there are no more. All we do is record
|
|
2216 the processes and wait status.
|
|
2217
|
|
2218 This function could be called from within the SIGCHLD
|
|
2219 handler, so it must be completely reentrant. When
|
|
2220 not called from a SIGCHLD handler, BLOCK_SIGCHLD should
|
|
2221 be non-zero so that SIGCHLD is blocked while this
|
|
2222 function is running. (This is necessary so avoid
|
|
2223 race conditions with the SIGCHLD_HAPPENED flag). */
|
|
2224
|
|
2225 static void
|
|
2226 record_exited_processes (int block_sigchld)
|
|
2227 {
|
|
2228 if (block_sigchld)
|
|
2229 EMACS_BLOCK_SIGNAL (SIGCHLD);
|
|
2230
|
|
2231 while (sigchld_happened)
|
|
2232 {
|
|
2233 int pid;
|
|
2234 WAITTYPE w;
|
|
2235
|
|
2236 /* Keep trying to get a status until we get a definitive result. */
|
|
2237 do
|
|
2238 {
|
|
2239 errno = 0;
|
|
2240 #ifdef WNOHANG
|
|
2241 # ifndef WUNTRACED
|
|
2242 # define WUNTRACED 0
|
|
2243 # endif /* not WUNTRACED */
|
|
2244 # ifdef HAVE_WAITPID
|
|
2245 pid = waitpid ((pid_t) -1, &w, WNOHANG | WUNTRACED);
|
|
2246 # else
|
|
2247 pid = wait3 (&w, WNOHANG | WUNTRACED, 0);
|
|
2248 # endif
|
|
2249 #else /* not WNOHANG */
|
|
2250 pid = wait (&w);
|
|
2251 #endif /* not WNOHANG */
|
|
2252 }
|
|
2253 while (pid <= 0 && errno == EINTR);
|
|
2254
|
|
2255 if (pid <= 0)
|
|
2256 break;
|
|
2257
|
|
2258 if (exited_processes_index < MAX_EXITED_PROCESSES)
|
|
2259 {
|
|
2260 exited_processes[exited_processes_index] = pid;
|
|
2261 exited_processes_status[exited_processes_index] = w;
|
|
2262 exited_processes_index++;
|
|
2263 }
|
|
2264
|
|
2265 /* On systems with WNOHANG, we just ignore the number
|
|
2266 of times that SIGCHLD was signalled, and keep looping
|
|
2267 until there are no more processes to wait on. If we
|
|
2268 don't have WNOHANG, we have to rely on the count in
|
|
2269 SIGCHLD_HAPPENED. */
|
|
2270 #ifndef WNOHANG
|
|
2271 sigchld_happened--;
|
|
2272 #endif /* not WNOHANG */
|
|
2273 }
|
|
2274
|
|
2275 sigchld_happened = 0;
|
|
2276
|
|
2277 if (block_sigchld)
|
|
2278 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
|
|
2279 }
|
|
2280
|
|
2281 /** USG WARNING: Although it is not obvious from the documentation
|
|
2282 in signal(2), on a USG system the SIGCLD handler MUST NOT call
|
|
2283 signal() before executing at least one wait(), otherwise the handler
|
|
2284 will be called again, resulting in an infinite loop. The relevant
|
|
2285 portion of the documentation reads "SIGCLD signals will be queued
|
|
2286 and the signal-catching function will be continually reentered until
|
|
2287 the queue is empty". Invoking signal() causes the kernel to reexamine
|
|
2288 the SIGCLD queue. Fred Fish, UniSoft Systems Inc.
|
|
2289
|
|
2290 (Note that now this only applies in SYS V Release 2 and before.
|
|
2291 On SYS V Release 3, we use sigset() to set the signal handler for
|
|
2292 the first time, and so we don't have to reestablish the signal handler
|
|
2293 in the handler below. On SYS V Release 4, we don't get this weirdo
|
|
2294 behavior when we use sigaction(), which we do use.) */
|
|
2295
|
|
2296 static SIGTYPE
|
|
2297 sigchld_handler (int signo)
|
|
2298 {
|
|
2299 #ifdef OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
|
|
2300 int old_errno = errno;
|
|
2301
|
|
2302 sigchld_happened++;
|
|
2303 record_exited_processes (0);
|
|
2304 errno = old_errno;
|
|
2305 #else
|
|
2306 sigchld_happened++;
|
|
2307 #endif
|
|
2308 signal_fake_event ();
|
|
2309 /* WARNING - must come after wait3() for USG systems */
|
|
2310 EMACS_REESTABLISH_SIGNAL (signo, sigchld_handler);
|
|
2311 SIGRETURN;
|
|
2312 }
|
|
2313
|
|
2314 #endif /* SIGCHLD */
|
|
2315
|
|
2316 /* Return a string describing a process status list. */
|
|
2317
|
|
2318 static Lisp_Object
|
|
2319 status_message (struct Lisp_Process *p)
|
|
2320 {
|
|
2321 Lisp_Object symbol = p->status_symbol;
|
|
2322 int code = p->exit_code;
|
|
2323 int coredump = p->core_dumped;
|
|
2324 Lisp_Object string, string2;
|
|
2325
|
|
2326 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
|
|
2327 {
|
|
2328 string = build_string (signal_name (code));
|
|
2329 if (coredump)
|
|
2330 string2 = build_translated_string (" (core dumped)\n");
|
|
2331 else
|
|
2332 string2 = build_string ("\n");
|
|
2333 set_string_char (XSTRING (string), 0,
|
|
2334 DOWNCASE (current_buffer,
|
|
2335 string_char (XSTRING (string), 0)));
|
|
2336 return concat2 (string, string2);
|
|
2337 }
|
|
2338 else if (EQ (symbol, Qexit))
|
|
2339 {
|
|
2340 if (code == 0)
|
|
2341 return build_translated_string ("finished\n");
|
|
2342 string = Fnumber_to_string (make_int (code));
|
|
2343 if (coredump)
|
|
2344 string2 = build_translated_string (" (core dumped)\n");
|
|
2345 else
|
|
2346 string2 = build_string ("\n");
|
|
2347 return concat2 (build_translated_string ("exited abnormally with code "),
|
|
2348 concat2 (string, string2));
|
|
2349 }
|
|
2350 else
|
|
2351 return Fcopy_sequence (Fsymbol_name (symbol));
|
|
2352 }
|
|
2353
|
|
2354 /* Tell status_notify() to check for terminated processes. We do this
|
|
2355 because on some systems we sometimes miss SIGCHLD calls. (Not sure
|
|
2356 why.) */
|
|
2357
|
|
2358 void
|
|
2359 kick_status_notify (void)
|
|
2360 {
|
|
2361 process_tick++;
|
|
2362 }
|
|
2363
|
|
2364 /* Report all recent events of a change in process status
|
|
2365 (either run the sentinel or output a message).
|
|
2366 This is done while Emacs is waiting for keyboard input. */
|
|
2367
|
|
2368 void
|
|
2369 status_notify (void)
|
|
2370 {
|
|
2371 /* This function can GC */
|
|
2372 Lisp_Object tail = Qnil;
|
|
2373 Lisp_Object symbol = Qnil;
|
|
2374 Lisp_Object msg = Qnil;
|
|
2375 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
2376 /* process_tick is volatile, so we have to remember it now.
|
|
2377 Otherwise, we get a race condition is SIGCHLD happens during
|
|
2378 this function.
|
|
2379
|
|
2380 (Actually, this is not the case anymore. The code to
|
|
2381 update the process structures has been moved out of the
|
|
2382 SIGCHLD handler. But for the moment I'm leaving this
|
|
2383 stuff in -- it can't hurt.) */
|
|
2384 int temp_process_tick;
|
|
2385
|
|
2386 #ifdef SIGCHLD
|
|
2387 #ifndef OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
|
|
2388 record_exited_processes (1);
|
|
2389 #endif
|
|
2390 reap_exited_processes ();
|
|
2391 #endif
|
|
2392
|
|
2393 temp_process_tick = process_tick;
|
|
2394
|
|
2395 if (update_tick == temp_process_tick)
|
|
2396 return;
|
|
2397
|
|
2398 /* We need to gcpro tail; if read_process_output calls a filter
|
|
2399 which deletes a process and removes the cons to which tail points
|
|
2400 from Vprocess_alist, and then causes a GC, tail is an unprotected
|
|
2401 reference. */
|
|
2402 GCPRO3 (tail, symbol, msg);
|
|
2403
|
|
2404 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
|
|
2405 {
|
|
2406 Lisp_Object proc = XCAR (tail);
|
|
2407 struct Lisp_Process *p = XPROCESS (proc);
|
|
2408 /* p->tick is also volatile. Same thing as above applies. */
|
|
2409 int this_process_tick;
|
|
2410
|
|
2411 #ifdef HAVE_WAITPID
|
|
2412 /* #### extra check for terminated processes, in case a SIGCHLD
|
|
2413 got missed (this seems to happen sometimes, I'm not sure why).
|
|
2414 */
|
|
2415 {
|
|
2416 WAITTYPE w;
|
|
2417 #ifdef SIGCHLD
|
|
2418 EMACS_BLOCK_SIGNAL (SIGCHLD);
|
|
2419 #endif
|
|
2420 if (INTP (p->pid) &&
|
|
2421 waitpid (XINT (p->pid), &w, WNOHANG) == XINT (p->pid))
|
|
2422 {
|
|
2423 p->tick++;
|
|
2424 update_status_from_wait_code (p, &w);
|
|
2425 }
|
|
2426 #ifdef SIGCHLD
|
|
2427 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
|
|
2428 #endif
|
|
2429 }
|
|
2430 #endif
|
|
2431 this_process_tick = p->tick;
|
|
2432 if (this_process_tick != p->update_tick)
|
|
2433 {
|
|
2434 p->update_tick = this_process_tick;
|
|
2435
|
|
2436 /* If process is still active, read any output that remains. */
|
|
2437 while (!EQ (p->filter, Qt)
|
|
2438 && read_process_output (proc) > 0)
|
|
2439 ;
|
|
2440
|
|
2441 /* Get the text to use for the message. */
|
|
2442 msg = status_message (p);
|
|
2443
|
|
2444 /* If process is terminated, deactivate it or delete it. */
|
|
2445 symbol = p->status_symbol;
|
|
2446
|
|
2447 if (EQ (symbol, Qsignal)
|
|
2448 || EQ (symbol, Qexit))
|
|
2449 {
|
|
2450 if (delete_exited_processes)
|
|
2451 remove_process (proc);
|
|
2452 else
|
|
2453 deactivate_process (proc);
|
|
2454 }
|
|
2455
|
|
2456 /* Now output the message suitably. */
|
|
2457 if (!NILP (p->sentinel))
|
|
2458 exec_sentinel (proc, msg);
|
|
2459 /* Don't bother with a message in the buffer
|
|
2460 when a process becomes runnable. */
|
|
2461 else if (!EQ (symbol, Qrun) && !NILP (p->buffer))
|
|
2462 {
|
|
2463 Lisp_Object old_read_only = Qnil;
|
|
2464 Lisp_Object old = Fcurrent_buffer ();
|
|
2465 Bufpos opoint;
|
|
2466 struct gcpro ngcpro1, ngcpro2;
|
|
2467
|
|
2468 /* Avoid error if buffer is deleted
|
|
2469 (probably that's why the process is dead, too) */
|
|
2470 if (!BUFFER_LIVE_P (XBUFFER (p->buffer)))
|
|
2471 continue;
|
|
2472
|
|
2473 NGCPRO2 (old, old_read_only);
|
|
2474 Fset_buffer (p->buffer);
|
|
2475 opoint = BUF_PT (current_buffer);
|
|
2476 /* Insert new output into buffer
|
|
2477 at the current end-of-output marker,
|
|
2478 thus preserving logical ordering of input and output. */
|
|
2479 if (XMARKER (p->mark)->buffer)
|
|
2480 BUF_SET_PT (current_buffer, marker_position (p->mark));
|
|
2481 else
|
|
2482 BUF_SET_PT (current_buffer, BUF_ZV (current_buffer));
|
|
2483 if (BUF_PT (current_buffer) <= opoint)
|
|
2484 opoint += (string_char_length (XSTRING (msg))
|
|
2485 + string_char_length (XSTRING (p->name))
|
|
2486 + 10);
|
|
2487
|
|
2488 old_read_only = current_buffer->read_only;
|
|
2489 current_buffer->read_only = Qnil;
|
|
2490 buffer_insert_c_string (current_buffer, "\nProcess ");
|
|
2491 Finsert (1, &p->name);
|
|
2492 buffer_insert_c_string (current_buffer, " ");
|
|
2493 Finsert (1, &msg);
|
|
2494 current_buffer->read_only = old_read_only;
|
|
2495 Fset_marker (p->mark, make_int (BUF_PT (current_buffer)),
|
|
2496 p->buffer);
|
|
2497
|
|
2498 BUF_SET_PT (current_buffer, opoint);
|
|
2499 Fset_buffer (old);
|
|
2500 NUNGCPRO;
|
|
2501 }
|
|
2502 }
|
|
2503 } /* end for */
|
|
2504
|
|
2505 /* in case buffers use %s in modeline-format */
|
|
2506 MARK_MODELINE_CHANGED;
|
|
2507 redisplay ();
|
|
2508
|
|
2509 update_tick = temp_process_tick;
|
|
2510
|
|
2511 UNGCPRO;
|
|
2512 }
|
|
2513
|
20
|
2514 DEFUN ("process-status", Fprocess_status, 1, 1, 0, /*
|
0
|
2515 Return the status of PROCESS.
|
|
2516 This is a symbol, one of these:
|
|
2517
|
|
2518 run -- for a process that is running.
|
|
2519 stop -- for a process stopped but continuable.
|
|
2520 exit -- for a process that has exited.
|
|
2521 signal -- for a process that has got a fatal signal.
|
|
2522 open -- for a network stream connection that is open.
|
|
2523 closed -- for a network stream connection that is closed.
|
|
2524 nil -- if arg is a process name and no such process exists.
|
|
2525 PROCESS may be a process, a buffer, the name of a process or buffer, or
|
|
2526 nil, indicating the current buffer's process.
|
20
|
2527 */
|
|
2528 (proc))
|
0
|
2529 {
|
|
2530 Lisp_Object status;
|
|
2531
|
|
2532 if (STRINGP (proc))
|
|
2533 proc = Fget_process (proc);
|
|
2534 else
|
|
2535 proc = get_process (proc);
|
|
2536
|
|
2537 if (NILP (proc))
|
|
2538 return proc;
|
|
2539
|
|
2540 status = XPROCESS (proc)->status_symbol;
|
|
2541 if (network_connection_p (proc))
|
|
2542 {
|
|
2543 if (EQ (status, Qrun))
|
|
2544 status = Qopen;
|
|
2545 else if (EQ (status, Qexit))
|
|
2546 status = Qclosed;
|
|
2547 }
|
|
2548 return (status);
|
|
2549 }
|
|
2550
|
20
|
2551 DEFUN ("process-exit-status", Fprocess_exit_status, 1, 1, 0, /*
|
0
|
2552 Return the exit status of PROCESS or the signal number that killed it.
|
|
2553 If PROCESS has not yet exited or died, return 0.
|
20
|
2554 */
|
|
2555 (proc))
|
0
|
2556 {
|
|
2557 CHECK_PROCESS (proc);
|
|
2558 return (make_int (XPROCESS (proc)->exit_code));
|
|
2559 }
|
|
2560
|
|
2561
|
|
2562 #ifdef SIGNALS_VIA_CHARACTERS
|
|
2563 /* Get signal character to send to process if SIGNALS_VIA_CHARACTERS */
|
|
2564
|
|
2565 static int
|
|
2566 process_signal_char (int tty_fd, int signo)
|
|
2567 {
|
|
2568 /* If it's not a tty, pray that these default values work */
|
|
2569 if (!isatty(tty_fd)) {
|
|
2570 #define CNTL(ch) (037 & (ch))
|
|
2571 switch (signo)
|
|
2572 {
|
|
2573 case SIGINT: return CNTL('C');
|
|
2574 case SIGQUIT: return CNTL('\\');
|
|
2575 #ifdef SIGTSTP
|
|
2576 case SIGTSTP: return CNTL('Z');
|
|
2577 #endif
|
|
2578 }
|
|
2579 }
|
|
2580
|
|
2581 #ifdef HAVE_TERMIOS
|
|
2582 /* TERMIOS is the latest and bestest, and seems most likely to work.
|
|
2583 If the system has it, use it. */
|
|
2584 {
|
|
2585 struct termios t;
|
|
2586 tcgetattr (tty_fd, &t);
|
|
2587 switch (signo)
|
|
2588 {
|
|
2589 case SIGINT: return t.c_cc[VINTR];
|
|
2590 case SIGQUIT: return t.c_cc[VQUIT];
|
|
2591 # if defined (VSWTCH) && !defined (PREFER_VSUSP)
|
|
2592 case SIGTSTP: return t.c_cc[VSWTCH];
|
|
2593 # else
|
|
2594 case SIGTSTP: return t.c_cc[VSUSP];
|
|
2595 # endif
|
|
2596 }
|
|
2597 }
|
|
2598
|
|
2599 # elif defined (TIOCGLTC) && defined (TIOCGETC) /* not HAVE_TERMIOS */
|
|
2600 {
|
|
2601 /* On Berkeley descendants, the following IOCTL's retrieve the
|
|
2602 current control characters. */
|
|
2603 struct tchars c;
|
|
2604 struct ltchars lc;
|
|
2605 switch (signo)
|
|
2606 {
|
|
2607 case SIGINT: ioctl (tty_fd, TIOCGETC, &c); return c.t_intrc;
|
|
2608 case SIGQUIT: ioctl (tty_fd, TIOCGETC, &c); return c.t_quitc;
|
|
2609 # ifdef SIGTSTP
|
|
2610 case SIGTSTP: ioctl (tty_fd, TIOCGLTC, &lc); return lc.t_suspc;
|
|
2611 # endif /* SIGTSTP */
|
|
2612 }
|
|
2613 }
|
|
2614
|
|
2615 # elif defined (TCGETA) /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
|
|
2616 {
|
|
2617 /* On SYSV descendants, the TCGETA ioctl retrieves the current
|
|
2618 control characters. */
|
|
2619 struct termio t;
|
|
2620 ioctl (tty_fd, TCGETA, &t);
|
|
2621 switch (signo) {
|
|
2622 case SIGINT: return t.c_cc[VINTR];
|
|
2623 case SIGQUIT: return t.c_cc[VQUIT];
|
|
2624 # ifdef SIGTSTP
|
|
2625 case SIGTSTP: return t.c_cc[VSWTCH];
|
|
2626 # endif /* SIGTSTP */
|
|
2627 }
|
|
2628 }
|
|
2629 # else /* ! defined (TCGETA) */
|
|
2630 #error ERROR! Using SIGNALS_VIA_CHARACTERS, but not (TIOCGLTC && TIOCGETC) || TCGETA
|
|
2631 /* If your system configuration files define SIGNALS_VIA_CHARACTERS,
|
|
2632 you'd better be using one of the alternatives above! */
|
|
2633 # endif /* ! defined (TCGETA) */
|
|
2634 return '\0';
|
|
2635 }
|
|
2636 #endif /* SIGNALS_VIA_CHARACTERS */
|
|
2637
|
|
2638
|
|
2639 /* send a signal number SIGNO to PROCESS.
|
|
2640 CURRENT_GROUP means send to the process group that currently owns
|
|
2641 the terminal being used to communicate with PROCESS.
|
|
2642 This is used for various commands in shell mode.
|
|
2643 If NOMSG is zero, insert signal-announcements into process's buffers
|
|
2644 right away.
|
|
2645
|
|
2646 If we can, we try to signal PROCESS by sending control characters
|
|
2647 down the pty. This allows us to signal inferiors who have changed
|
|
2648 their uid, for which killpg would return an EPERM error. */
|
|
2649
|
|
2650 static void
|
|
2651 process_send_signal (Lisp_Object process0, int signo,
|
|
2652 int current_group, int nomsg)
|
|
2653 {
|
|
2654 /* This function can GC */
|
|
2655 Lisp_Object proc = get_process (process0);
|
|
2656 struct Lisp_Process *p = XPROCESS (proc);
|
|
2657 int gid;
|
|
2658 int no_pgrp = 0;
|
|
2659
|
|
2660 if (network_connection_p (proc))
|
|
2661 error ("Network connection %s is not a subprocess",
|
16
|
2662 XSTRING_DATA (p->name));
|
0
|
2663 if (p->infd < 0)
|
|
2664 error ("Process %s is not active",
|
16
|
2665 XSTRING_DATA (p->name));
|
0
|
2666
|
|
2667 if (!p->pty_flag)
|
|
2668 current_group = 0;
|
|
2669
|
|
2670 /* If we are using pgrps, get a pgrp number and make it negative. */
|
|
2671 if (current_group)
|
|
2672 {
|
|
2673 #ifdef SIGNALS_VIA_CHARACTERS
|
|
2674 /* If possible, send signals to the entire pgrp
|
|
2675 by sending an input character to it. */
|
|
2676 {
|
|
2677 char sigchar = process_signal_char(p->subtty, signo);
|
|
2678 if (sigchar) {
|
|
2679 send_process (proc, Qnil, (Bufbyte *) &sigchar, 0, 1);
|
|
2680 return;
|
|
2681 }
|
|
2682 }
|
|
2683 #endif /* ! defined (SIGNALS_VIA_CHARACTERS) */
|
|
2684
|
|
2685 #ifdef TIOCGPGRP
|
|
2686 /* Get the pgrp using the tty itself, if we have that.
|
|
2687 Otherwise, use the pty to get the pgrp.
|
|
2688 On pfa systems, saka@pfu.fujitsu.co.JP writes:
|
|
2689 "TIOCGPGRP symbol defined in sys/ioctl.h at E50.
|
|
2690 But, TIOCGPGRP does not work on E50 ;-P works fine on E60"
|
|
2691 His patch indicates that if TIOCGPGRP returns an error, then
|
|
2692 we should just assume that p->pid is also the process group id. */
|
|
2693 {
|
|
2694 int err;
|
|
2695
|
|
2696 err = ioctl ( (p->subtty != -1 ? p->subtty : p->infd), TIOCGPGRP, &gid);
|
|
2697
|
|
2698 #ifdef pfa
|
|
2699 if (err == -1)
|
|
2700 gid = - XINT (p->pid);
|
|
2701 #endif /* ! defined (pfa) */
|
|
2702 }
|
|
2703 if (gid == -1)
|
|
2704 no_pgrp = 1;
|
|
2705 else
|
|
2706 gid = - gid;
|
|
2707 #else /* ! defined (TIOCGPGRP ) */
|
|
2708 /* Can't select pgrps on this system, so we know that
|
|
2709 the child itself heads the pgrp. */
|
|
2710 gid = - XINT (p->pid);
|
|
2711 #endif /* ! defined (TIOCGPGRP ) */
|
|
2712 }
|
|
2713 else
|
|
2714 gid = - XINT (p->pid);
|
|
2715
|
|
2716 switch (signo)
|
|
2717 {
|
|
2718 #ifdef SIGCONT
|
|
2719 case SIGCONT:
|
|
2720 p->status_symbol = Qrun;
|
|
2721 p->exit_code = 0;
|
|
2722 p->tick++;
|
|
2723 process_tick++;
|
|
2724 if (!nomsg)
|
|
2725 status_notify ();
|
|
2726 break;
|
|
2727 #endif /* ! defined (SIGCONT) */
|
|
2728 case SIGINT:
|
|
2729 #ifdef VMS
|
|
2730 send_process (proc, Qnil, (Bufbyte *) "\003", 0,
|
|
2731 1); /* ^C */
|
|
2732 goto whoosh;
|
|
2733 #endif
|
|
2734 case SIGQUIT:
|
|
2735 #ifdef VMS
|
|
2736 send_process (proc, Qnil, (Bufbyte *) "\031", 0,
|
|
2737 1); /* ^Y */
|
|
2738 goto whoosh;
|
|
2739 #endif
|
|
2740 case SIGKILL:
|
|
2741 #ifdef VMS
|
|
2742 sys$forcex (&(XINT (p->pid)), 0, 1);
|
|
2743 whoosh:
|
|
2744 #endif
|
|
2745 flush_pending_output (p->infd);
|
|
2746 break;
|
|
2747 }
|
|
2748
|
|
2749 /* If we don't have process groups, send the signal to the immediate
|
|
2750 subprocess. That isn't really right, but it's better than any
|
|
2751 obvious alternative. */
|
|
2752 if (no_pgrp)
|
|
2753 {
|
|
2754 kill (XINT (p->pid), signo);
|
|
2755 return;
|
|
2756 }
|
|
2757
|
|
2758 /* gid may be a pid, or minus a pgrp's number */
|
|
2759 #ifdef TIOCSIGSEND
|
|
2760 if (current_group)
|
|
2761 ioctl (p->infd, TIOCSIGSEND, signo);
|
|
2762 else
|
|
2763 {
|
|
2764 gid = - XINT (p->pid);
|
|
2765 kill (gid, signo);
|
|
2766 }
|
|
2767 #else /* ! defined (TIOCSIGSEND) */
|
|
2768 EMACS_KILLPG (-gid, signo);
|
|
2769 #endif /* ! defined (TIOCSIGSEND) */
|
|
2770 }
|
|
2771
|
20
|
2772 DEFUN ("interrupt-process", Finterrupt_process, 0, 2, 0, /*
|
0
|
2773 Interrupt process PROCESS. May be process or name of one.
|
|
2774 Nil or no arg means current buffer's process.
|
|
2775 Second arg CURRENT-GROUP non-nil means send signal to
|
|
2776 the current process-group of the process's controlling terminal
|
|
2777 rather than to the process's own process group.
|
|
2778 If the process is a shell, this means interrupt current subjob
|
|
2779 rather than the shell.
|
20
|
2780 */
|
|
2781 (process, current_group))
|
0
|
2782 {
|
|
2783 /* This function can GC */
|
|
2784 process_send_signal (process, SIGINT, !NILP (current_group), 0);
|
|
2785 return process;
|
|
2786 }
|
|
2787
|
20
|
2788 DEFUN ("kill-process", Fkill_process, 0, 2, 0, /*
|
0
|
2789 Kill process PROCESS. May be process or name of one.
|
|
2790 See function `interrupt-process' for more details on usage.
|
20
|
2791 */
|
|
2792 (process, current_group))
|
0
|
2793 {
|
|
2794 /* This function can GC */
|
|
2795 process_send_signal (process, SIGKILL, !NILP (current_group),
|
|
2796 0);
|
|
2797 return process;
|
|
2798 }
|
|
2799
|
20
|
2800 DEFUN ("quit-process", Fquit_process, 0, 2, 0, /*
|
0
|
2801 Send QUIT signal to process PROCESS. May be process or name of one.
|
|
2802 See function `interrupt-process' for more details on usage.
|
20
|
2803 */
|
|
2804 (process, current_group))
|
0
|
2805 {
|
|
2806 /* This function can GC */
|
|
2807 process_send_signal (process, SIGQUIT, !NILP (current_group),
|
|
2808 0);
|
|
2809 return process;
|
|
2810 }
|
|
2811
|
20
|
2812 DEFUN ("stop-process", Fstop_process, 0, 2, 0, /*
|
0
|
2813 Stop process PROCESS. May be process or name of one.
|
|
2814 See function `interrupt-process' for more details on usage.
|
20
|
2815 */
|
|
2816 (process, current_group))
|
0
|
2817 {
|
|
2818 /* This function can GC */
|
|
2819 #ifndef SIGTSTP
|
|
2820 error ("no SIGTSTP support");
|
|
2821 #else
|
|
2822 process_send_signal (process, SIGTSTP, !NILP (current_group),
|
|
2823 0);
|
|
2824 #endif
|
|
2825 return process;
|
|
2826 }
|
|
2827
|
20
|
2828 DEFUN ("continue-process", Fcontinue_process, 0, 2, 0, /*
|
0
|
2829 Continue process PROCESS. May be process or name of one.
|
|
2830 See function `interrupt-process' for more details on usage.
|
20
|
2831 */
|
|
2832 (process, current_group))
|
0
|
2833 {
|
|
2834 /* This function can GC */
|
|
2835 #ifdef SIGCONT
|
|
2836 process_send_signal (process, SIGCONT, !NILP (current_group),
|
|
2837 0);
|
|
2838 #else
|
|
2839 error ("no SIGCONT support");
|
|
2840 #endif
|
|
2841 return process;
|
|
2842 }
|
|
2843
|
20
|
2844 DEFUN ("signal-process", Fsignal_process, 2, 2,
|
|
2845 "nProcess number: \nnSignal code: ", /*
|
0
|
2846 Send the process with process id PID the signal with code SIGCODE.
|
|
2847 PID must be an integer. The process need not be a child of this Emacs.
|
|
2848 SIGCODE may be an integer, or a symbol whose name is a signal name.
|
20
|
2849 */
|
|
2850 (pid, sigcode))
|
0
|
2851 {
|
|
2852 CHECK_INT (pid);
|
|
2853
|
|
2854 #define handle_signal(NAME, VALUE) \
|
|
2855 else if (!strcmp ((CONST char *) name, NAME)) \
|
|
2856 XSETINT (sigcode, VALUE)
|
|
2857
|
|
2858 if (INTP (sigcode))
|
|
2859 ;
|
|
2860 else
|
|
2861 {
|
|
2862 Bufbyte *name;
|
|
2863
|
|
2864 CHECK_SYMBOL (sigcode);
|
|
2865 name = string_data (XSYMBOL (sigcode)->name);
|
|
2866
|
|
2867 if (0)
|
|
2868 ;
|
|
2869 #ifdef SIGHUP
|
|
2870 handle_signal ("SIGHUP", SIGHUP);
|
|
2871 #endif
|
|
2872 #ifdef SIGINT
|
|
2873 handle_signal ("SIGINT", SIGINT);
|
|
2874 #endif
|
|
2875 #ifdef SIGQUIT
|
|
2876 handle_signal ("SIGQUIT", SIGQUIT);
|
|
2877 #endif
|
|
2878 #ifdef SIGILL
|
|
2879 handle_signal ("SIGILL", SIGILL);
|
|
2880 #endif
|
|
2881 #ifdef SIGABRT
|
|
2882 handle_signal ("SIGABRT", SIGABRT);
|
|
2883 #endif
|
|
2884 #ifdef SIGEMT
|
|
2885 handle_signal ("SIGEMT", SIGEMT);
|
|
2886 #endif
|
|
2887 #ifdef SIGKILL
|
|
2888 handle_signal ("SIGKILL", SIGKILL);
|
|
2889 #endif
|
|
2890 #ifdef SIGFPE
|
|
2891 handle_signal ("SIGFPE", SIGFPE);
|
|
2892 #endif
|
|
2893 #ifdef SIGBUS
|
|
2894 handle_signal ("SIGBUS", SIGBUS);
|
|
2895 #endif
|
|
2896 #ifdef SIGSEGV
|
|
2897 handle_signal ("SIGSEGV", SIGSEGV);
|
|
2898 #endif
|
|
2899 #ifdef SIGSYS
|
|
2900 handle_signal ("SIGSYS", SIGSYS);
|
|
2901 #endif
|
|
2902 #ifdef SIGPIPE
|
|
2903 handle_signal ("SIGPIPE", SIGPIPE);
|
|
2904 #endif
|
|
2905 #ifdef SIGALRM
|
|
2906 handle_signal ("SIGALRM", SIGALRM);
|
|
2907 #endif
|
|
2908 #ifdef SIGTERM
|
|
2909 handle_signal ("SIGTERM", SIGTERM);
|
|
2910 #endif
|
|
2911 #ifdef SIGURG
|
|
2912 handle_signal ("SIGURG", SIGURG);
|
|
2913 #endif
|
|
2914 #ifdef SIGSTOP
|
|
2915 handle_signal ("SIGSTOP", SIGSTOP);
|
|
2916 #endif
|
|
2917 #ifdef SIGTSTP
|
|
2918 handle_signal ("SIGTSTP", SIGTSTP);
|
|
2919 #endif
|
|
2920 #ifdef SIGCONT
|
|
2921 handle_signal ("SIGCONT", SIGCONT);
|
|
2922 #endif
|
|
2923 #ifdef SIGCHLD
|
|
2924 handle_signal ("SIGCHLD", SIGCHLD);
|
|
2925 #endif
|
|
2926 #ifdef SIGTTIN
|
|
2927 handle_signal ("SIGTTIN", SIGTTIN);
|
|
2928 #endif
|
|
2929 #ifdef SIGTTOU
|
|
2930 handle_signal ("SIGTTOU", SIGTTOU);
|
|
2931 #endif
|
|
2932 #ifdef SIGIO
|
|
2933 handle_signal ("SIGIO", SIGIO);
|
|
2934 #endif
|
|
2935 #ifdef SIGXCPU
|
|
2936 handle_signal ("SIGXCPU", SIGXCPU);
|
|
2937 #endif
|
|
2938 #ifdef SIGXFSZ
|
|
2939 handle_signal ("SIGXFSZ", SIGXFSZ);
|
|
2940 #endif
|
|
2941 #ifdef SIGVTALRM
|
|
2942 handle_signal ("SIGVTALRM", SIGVTALRM);
|
|
2943 #endif
|
|
2944 #ifdef SIGPROF
|
|
2945 handle_signal ("SIGPROF", SIGPROF);
|
|
2946 #endif
|
|
2947 #ifdef SIGWINCH
|
|
2948 handle_signal ("SIGWINCH", SIGWINCH);
|
|
2949 #endif
|
|
2950 #ifdef SIGINFO
|
|
2951 handle_signal ("SIGINFO", SIGINFO);
|
|
2952 #endif
|
|
2953 #ifdef SIGUSR1
|
|
2954 handle_signal ("SIGUSR1", SIGUSR1);
|
|
2955 #endif
|
|
2956 #ifdef SIGUSR2
|
|
2957 handle_signal ("SIGUSR2", SIGUSR2);
|
|
2958 #endif
|
|
2959 else
|
|
2960 error ("Undefined signal name %s", name);
|
|
2961 }
|
|
2962
|
|
2963 #undef handle_signal
|
|
2964
|
|
2965 #ifdef WINDOWSNT
|
|
2966 /* Only works for kill-type signals */
|
|
2967 return make_int (win32_kill_process (XINT (pid), XINT (sigcode)));
|
|
2968 #else
|
|
2969 return make_int (kill (XINT (pid), XINT (sigcode)));
|
|
2970 #endif
|
|
2971 }
|
|
2972
|
20
|
2973 DEFUN ("process-send-eof", Fprocess_send_eof, 0, 1, 0, /*
|
0
|
2974 Make PROCESS see end-of-file in its input.
|
|
2975 PROCESS may be a process, a buffer, the name of a process or buffer, or
|
|
2976 nil, indicating the current buffer's process.
|
|
2977 If PROCESS is a network connection, or is a process communicating
|
|
2978 through a pipe (as opposed to a pty), then you cannot send any more
|
|
2979 text to PROCESS after you call this function.
|
20
|
2980 */
|
|
2981 (process))
|
0
|
2982 {
|
|
2983 /* This function can GC */
|
|
2984 Lisp_Object proc;
|
|
2985
|
|
2986 proc = get_process (process);
|
|
2987
|
|
2988 /* Make sure the process is really alive. */
|
|
2989 if (! EQ (XPROCESS (proc)->status_symbol, Qrun))
|
16
|
2990 error ("Process %s not running", XSTRING_DATA (XPROCESS (proc)->name));
|
0
|
2991
|
|
2992 #ifdef VMS
|
|
2993 send_process (proc, Qnil, (Bufbyte *) "\032", 0, 1); /* ^Z */
|
|
2994 #else
|
|
2995 if (XPROCESS (proc)->pty_flag)
|
|
2996 {
|
|
2997 /* #### get_eof_char simply doesn't return the correct character
|
|
2998 here. Maybe it is needed to determine the right eof
|
|
2999 character in init_process_fds but here it simply screws
|
|
3000 things up. */
|
|
3001 #if 0
|
|
3002 Bufbyte eof_char = get_eof_char (XPROCESS (proc));
|
|
3003 send_process (proc, Qnil, &eof_char, 0, 1);
|
|
3004 #else
|
|
3005 send_process (proc, Qnil, (CONST Bufbyte *) "\004", 0, 1);
|
|
3006 #endif
|
|
3007 }
|
|
3008 else
|
|
3009 {
|
|
3010 close (XPROCESS (proc)->outfd);
|
|
3011 XPROCESS (proc)->outfd = open (NULL_DEVICE, O_WRONLY, 0);
|
|
3012 }
|
|
3013 #endif /* !VMS */
|
|
3014 return process;
|
|
3015 }
|
|
3016
|
|
3017
|
|
3018 /************************************************************************/
|
|
3019 /* deleting a process */
|
|
3020 /************************************************************************/
|
|
3021
|
|
3022 void
|
|
3023 deactivate_process (Lisp_Object proc)
|
|
3024 {
|
|
3025 int inchannel, outchannel;
|
|
3026 struct Lisp_Process *p = XPROCESS (proc);
|
|
3027 SIGTYPE (*old_sigpipe) (int) = 0;
|
|
3028
|
|
3029 inchannel = p->infd;
|
|
3030 outchannel = p->outfd;
|
|
3031
|
|
3032 /* closing the outstream could result in SIGPIPE, so ignore it. */
|
|
3033 old_sigpipe =
|
|
3034 (SIGTYPE (*) (int)) signal (SIGPIPE, SIG_IGN);
|
|
3035 if (!NILP (p->instream))
|
|
3036 Lstream_close (XLSTREAM (p->instream));
|
|
3037 if (!NILP (p->outstream))
|
|
3038 Lstream_close (XLSTREAM (p->outstream));
|
|
3039 signal (SIGPIPE, old_sigpipe);
|
|
3040
|
|
3041 if (inchannel >= 0)
|
|
3042 {
|
|
3043 /* Beware SIGCHLD hereabouts. */
|
|
3044 flush_pending_output (inchannel);
|
|
3045 close_descriptor_pair (inchannel, outchannel);
|
|
3046 if (!NILP (p->pid))
|
|
3047 {
|
|
3048 /* It's possible that we got as far in the process-creation
|
|
3049 process as creating the descriptors but didn't get so
|
|
3050 far as selecting the process for input. In this
|
|
3051 case, p->pid is nil: p->pid is set at the same time that
|
|
3052 the process is selected for input. */
|
|
3053 #ifdef VMS
|
|
3054 {
|
|
3055 VMS_PROC_STUFF *get_vms_process_pointer (), *vs;
|
|
3056 if (outchannel >= 0)
|
|
3057 sys$dassgn (outchannel);
|
|
3058 vs = get_vms_process_pointer (XINT (p->pid));
|
|
3059 if (vs)
|
|
3060 give_back_vms_process_stuff (vs);
|
|
3061 }
|
|
3062 #endif /* VMS */
|
|
3063 /* Must call this before setting the file descriptors to 0 */
|
|
3064 event_stream_unselect_process (p);
|
|
3065 }
|
|
3066
|
|
3067 p->infd = -1;
|
|
3068 p->outfd = -1;
|
|
3069 descriptor_to_process[inchannel] = Qnil;
|
|
3070 }
|
|
3071 }
|
|
3072
|
|
3073 static void
|
|
3074 remove_process (Lisp_Object proc)
|
|
3075 {
|
|
3076 Vprocess_list = delq_no_quit (proc, Vprocess_list);
|
|
3077 Fset_marker (XPROCESS (proc)->mark, Qnil, Qnil);
|
|
3078
|
|
3079 deactivate_process (proc);
|
|
3080 }
|
|
3081
|
20
|
3082 DEFUN ("delete-process", Fdelete_process, 1, 1, 0, /*
|
0
|
3083 Delete PROCESS: kill it and forget about it immediately.
|
|
3084 PROCESS may be a process or the name of one, or a buffer name.
|
20
|
3085 */
|
|
3086 (proc))
|
0
|
3087 {
|
|
3088 /* This function can GC */
|
|
3089 struct Lisp_Process *p;
|
|
3090 proc = get_process (proc);
|
|
3091 p = XPROCESS (proc);
|
|
3092 if (network_connection_p (proc))
|
|
3093 {
|
|
3094 p->status_symbol = Qexit;
|
|
3095 p->exit_code = 0;
|
|
3096 p->core_dumped = 0;
|
|
3097 p->tick++;
|
|
3098 process_tick++;
|
|
3099 }
|
|
3100 else if (p->infd >= 0)
|
|
3101 {
|
|
3102 Fkill_process (proc, Qnil);
|
|
3103 /* Do this now, since remove_process will make sigchld_handler do nothing. */
|
|
3104 p->status_symbol = Qsignal;
|
|
3105 p->exit_code = SIGKILL;
|
|
3106 p->core_dumped = 0;
|
|
3107 p->tick++;
|
|
3108 process_tick++;
|
|
3109 status_notify ();
|
|
3110 }
|
|
3111 remove_process (proc);
|
|
3112 return Qnil;
|
|
3113 }
|
|
3114
|
|
3115 /* Kill all processes associated with `buffer'.
|
|
3116 If `buffer' is nil, kill all processes */
|
|
3117
|
|
3118 void
|
|
3119 kill_buffer_processes (Lisp_Object buffer)
|
|
3120 {
|
|
3121 Lisp_Object tail;
|
|
3122
|
|
3123 for (tail = Vprocess_list; GC_CONSP (tail);
|
|
3124 tail = XCDR (tail))
|
|
3125 {
|
|
3126 Lisp_Object proc = XCAR (tail);
|
|
3127 if (GC_PROCESSP (proc)
|
|
3128 && (GC_NILP (buffer) || GC_EQ (XPROCESS (proc)->buffer, buffer)))
|
|
3129 {
|
|
3130 if (network_connection_p (proc))
|
|
3131 Fdelete_process (proc);
|
|
3132 else if (XPROCESS (proc)->infd >= 0)
|
|
3133 process_send_signal (proc, SIGHUP, 0, 1);
|
|
3134 }
|
|
3135 }
|
|
3136 }
|
|
3137
|
|
3138 #if 0 /* Unused */
|
|
3139 int
|
|
3140 count_active_processes (void)
|
|
3141 {
|
|
3142 Lisp_Object tail;
|
|
3143 int count = 0;
|
|
3144
|
|
3145 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
|
|
3146 {
|
|
3147 Lisp_Object status = XPROCESS (XCAR (tail))->status_symbol;
|
|
3148 if ((EQ (status, Qrun) || EQ (status, Qstop)))
|
|
3149 count++;
|
|
3150 }
|
|
3151
|
|
3152 return count;
|
|
3153 }
|
|
3154 #endif /* Unused */
|
|
3155
|
20
|
3156 DEFUN ("process-kill-without-query", Fprocess_kill_without_query, 1, 2, 0, /*
|
0
|
3157 Say no query needed if PROCESS is running when Emacs is exited.
|
|
3158 Optional second argument if non-nil says to require a query.
|
|
3159 Value is t if a query was formerly required.
|
20
|
3160 */
|
|
3161 (proc, require_query_p))
|
0
|
3162 {
|
|
3163 int tem;
|
|
3164
|
|
3165 CHECK_PROCESS (proc);
|
|
3166 tem = XPROCESS (proc)->kill_without_query;
|
|
3167 XPROCESS (proc)->kill_without_query = NILP (require_query_p);
|
|
3168
|
|
3169 return (tem ? Qnil : Qt);
|
|
3170 }
|
|
3171
|
20
|
3172 DEFUN ("process-kill-without-query-p", Fprocess_kill_without_query_p, 1, 1, 0, /*
|
0
|
3173 Whether PROC will be killed without query if running when emacs is exited.
|
20
|
3174 */
|
|
3175 (proc))
|
0
|
3176 {
|
|
3177 CHECK_PROCESS (proc);
|
|
3178 return (XPROCESS (proc)->kill_without_query ? Qt : Qnil);
|
|
3179 }
|
|
3180
|
|
3181
|
|
3182 /* This is not named init_process in order to avoid a conflict with NS 3.3 */
|
|
3183 void
|
|
3184 init_xemacs_process (void)
|
|
3185 {
|
|
3186 int i;
|
|
3187
|
|
3188 #ifdef SIGCHLD
|
|
3189 # ifndef CANNOT_DUMP
|
|
3190 if (! noninteractive || initialized)
|
|
3191 # endif
|
|
3192 signal (SIGCHLD, sigchld_handler);
|
|
3193 #endif /* SIGCHLD */
|
|
3194
|
|
3195 Vprocess_list = Qnil;
|
|
3196 for (i = 0; i < MAXDESC; i++)
|
|
3197 {
|
|
3198 descriptor_to_process[i] = Qnil;
|
|
3199 proc_buffered_char[i] = -1;
|
|
3200 }
|
|
3201 }
|
|
3202 #if 0
|
|
3203
|
|
3204 xxDEFUN ("process-connection", Fprocess_connection, Sprocess_connection,
|
|
3205 0, 1, 0 /*
|
|
3206 Return the connection type of `PROCESS'. This can be nil (pipe),
|
|
3207 t or pty (pty) or stream (socket connection).
|
|
3208 */ )
|
|
3209 (process)
|
|
3210 Lisp_Object process;
|
|
3211 {
|
|
3212 return XPROCESS (process)->type;
|
|
3213 }
|
|
3214
|
|
3215 #endif /* 0 */
|
|
3216
|
|
3217 void
|
|
3218 syms_of_process (void)
|
|
3219 {
|
|
3220 defsymbol (&Qprocessp, "processp");
|
|
3221 defsymbol (&Qrun, "run");
|
|
3222 defsymbol (&Qstop, "stop");
|
|
3223 defsymbol (&Qsignal, "signal");
|
|
3224 /* Qexit is already defined by syms_of_eval
|
|
3225 * defsymbol (&Qexit, "exit");
|
|
3226 */
|
|
3227 defsymbol (&Qopen, "open");
|
|
3228 defsymbol (&Qclosed, "closed");
|
|
3229
|
20
|
3230 DEFSUBR (Fprocessp);
|
|
3231 DEFSUBR (Fget_process);
|
|
3232 DEFSUBR (Fget_buffer_process);
|
|
3233 DEFSUBR (Fdelete_process);
|
|
3234 DEFSUBR (Fprocess_status);
|
|
3235 DEFSUBR (Fprocess_exit_status);
|
|
3236 DEFSUBR (Fprocess_id);
|
|
3237 DEFSUBR (Fprocess_name);
|
|
3238 DEFSUBR (Fprocess_tty_name);
|
|
3239 DEFSUBR (Fprocess_command);
|
|
3240 DEFSUBR (Fset_process_buffer);
|
|
3241 DEFSUBR (Fprocess_buffer);
|
|
3242 DEFSUBR (Fprocess_mark);
|
|
3243 DEFSUBR (Fset_process_filter);
|
|
3244 DEFSUBR (Fprocess_filter);
|
|
3245 DEFSUBR (Fset_process_window_size);
|
|
3246 DEFSUBR (Fset_process_sentinel);
|
|
3247 DEFSUBR (Fprocess_sentinel);
|
|
3248 DEFSUBR (Fprocess_kill_without_query);
|
|
3249 DEFSUBR (Fprocess_kill_without_query_p);
|
|
3250 DEFSUBR (Fprocess_list);
|
|
3251 DEFSUBR (Fstart_process_internal);
|
0
|
3252 #ifdef HAVE_SOCKETS
|
20
|
3253 DEFSUBR (Fopen_network_stream_internal);
|
0
|
3254 #endif /* HAVE_SOCKETS */
|
20
|
3255 DEFSUBR (Fprocess_send_region);
|
|
3256 DEFSUBR (Fprocess_send_string);
|
|
3257 DEFSUBR (Finterrupt_process);
|
|
3258 DEFSUBR (Fkill_process);
|
|
3259 DEFSUBR (Fquit_process);
|
|
3260 DEFSUBR (Fstop_process);
|
|
3261 DEFSUBR (Fcontinue_process);
|
|
3262 DEFSUBR (Fprocess_send_eof);
|
|
3263 DEFSUBR (Fsignal_process);
|
|
3264 /* DEFSUBR (Fprocess_connection); */
|
0
|
3265 }
|
|
3266
|
|
3267 void
|
|
3268 vars_of_process (void)
|
|
3269 {
|
|
3270 Fprovide (intern ("subprocesses"));
|
|
3271 #ifdef HAVE_SOCKETS
|
|
3272 Fprovide (intern ("network-streams"));
|
|
3273 #endif
|
|
3274 staticpro (&Vprocess_list);
|
|
3275
|
|
3276 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes /*
|
|
3277 *Non-nil means delete processes immediately when they exit.
|
|
3278 nil means don't delete them until `list-processes' is run.
|
|
3279 */ );
|
|
3280
|
|
3281 delete_exited_processes = 1;
|
|
3282
|
|
3283 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type /*
|
|
3284 Control type of device used to communicate with subprocesses.
|
|
3285 Values are nil to use a pipe, or t or `pty' to use a pty.
|
|
3286 The value has no effect if the system has no ptys or if all ptys are busy:
|
|
3287 then a pipe is used in any case.
|
|
3288 The value takes effect when `start-process' is called.
|
|
3289 */ );
|
|
3290 Vprocess_connection_type = Qt;
|
|
3291 }
|
|
3292
|
|
3293 #endif /* not NO_SUBPROCESSES */
|