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