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