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