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