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