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));
|
|
219 return (proc->status_symbol);
|
|
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 {
|
|
362 return (GC_CONSP (XPROCESS (process)->pid));
|
|
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 {
|
|
377 return ((PROCESSP (obj)) ? Qt : Qnil);
|
|
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))
|
|
396 return (name);
|
|
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)))
|
|
408 return (XCAR (tail));
|
|
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))
|
|
506 /* return (Qnil); */
|
|
507 return (Fcons (Fcar (pid), Fcdr (pid)));
|
|
508 else
|
|
509 return (pid);
|
|
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);
|
|
587 return (val);
|
|
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
|
|
892 pid = vfork ();
|
|
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);
|
|
1041 report_file_error ("Doing vfork", Qnil);
|
|
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 {
|
|
1306 struct hostent *host_info_ptr;
|
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;
|
|
1385 int port;
|
|
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 int block_port;
|
|
1513
|
|
1514 if (STRINGP (tail_port))
|
|
1515 {
|
|
1516 struct servent *svc_info;
|
|
1517 CHECK_STRING (tail_port);
|
|
1518 svc_info = getservbyname ((char *) XSTRING_DATA (tail_port), "tcp");
|
|
1519 if ((svc_info != 0) && (svc_info->s_port == port))
|
|
1520 break;
|
|
1521 else
|
|
1522 continue;
|
|
1523 }
|
|
1524 else if ((INTP (tail_port)) && (htons ((unsigned short) XINT (tail_port)) == port))
|
|
1525 break;
|
|
1526 }
|
|
1527
|
|
1528 if (!CONSP (tail))
|
|
1529 {
|
|
1530 #endif /* PROCESS_IO_BLOCKING */
|
0
|
1531 set_descriptor_non_blocking (inch);
|
153
|
1532 #ifdef PROCESS_IO_BLOCKING
|
|
1533 }
|
|
1534 }
|
|
1535 #endif /* PROCESS_IO_BLOCKING */
|
0
|
1536
|
|
1537 XPROCESS (proc)->pid = Fcons (service, host);
|
|
1538 XPROCESS (proc)->buffer = buffer;
|
|
1539 init_process_fds (XPROCESS (proc), inch, outch);
|
|
1540 XPROCESS (proc)->connected_via_filedesc_p = 0;
|
|
1541
|
|
1542 event_stream_select_process (XPROCESS (proc));
|
|
1543
|
|
1544 UNGCPRO;
|
|
1545 return proc;
|
|
1546 }
|
|
1547
|
|
1548 #endif /* HAVE_SOCKETS */
|
|
1549
|
|
1550 Lisp_Object
|
|
1551 canonicalize_host_name (Lisp_Object host)
|
|
1552 {
|
|
1553 #ifdef HAVE_SOCKETS
|
|
1554 /* #### for HAVE_TERM, you probably have to do something else. */
|
|
1555 struct sockaddr_in address;
|
|
1556
|
|
1557 if (!get_internet_address (host, &address, ERROR_ME_NOT))
|
|
1558 return host;
|
|
1559
|
|
1560 if (address.sin_family == AF_INET)
|
|
1561 return build_string (inet_ntoa (address.sin_addr));
|
|
1562 else
|
|
1563 /* #### any clue what to do here? */
|
|
1564 return host;
|
|
1565 #else
|
|
1566 return host;
|
|
1567 #endif
|
|
1568 }
|
|
1569
|
|
1570
|
20
|
1571 DEFUN ("set-process-window-size", Fset_process_window_size, 3, 3, 0, /*
|
0
|
1572 Tell PROCESS that it has logical window size HEIGHT and WIDTH.
|
20
|
1573 */
|
|
1574 (proc, height, width))
|
0
|
1575 {
|
|
1576 CHECK_PROCESS (proc);
|
|
1577 CHECK_NATNUM (height);
|
|
1578 CHECK_NATNUM (width);
|
|
1579 if (set_window_size (XPROCESS (proc)->infd, XINT (height), XINT (width))
|
|
1580 <= 0)
|
|
1581 return Qnil;
|
|
1582 else
|
|
1583 return Qt;
|
|
1584 }
|
|
1585
|
|
1586
|
|
1587 /************************************************************************/
|
|
1588 /* Process I/O */
|
|
1589 /************************************************************************/
|
|
1590
|
|
1591 /* (Faccept_process_output is now in event-stream.c) */
|
|
1592
|
|
1593 /* Some FSFmacs error handlers here. We handle this
|
|
1594 in call2_trapping_errors(). */
|
|
1595
|
|
1596 /* Read pending output from the process channel,
|
|
1597 starting with our buffered-ahead character if we have one.
|
|
1598 Yield number of characters read.
|
|
1599
|
|
1600 This function reads at most 1024 bytes.
|
|
1601 If you want to read all available subprocess output,
|
|
1602 you must call it repeatedly until it returns zero. */
|
|
1603
|
|
1604 Charcount
|
|
1605 read_process_output (Lisp_Object proc)
|
|
1606 {
|
|
1607 /* This function can GC */
|
|
1608 Bytecount nbytes, nchars;
|
|
1609 #ifdef VMS
|
|
1610 char *chars;
|
|
1611 #else
|
|
1612 Bufbyte chars[1024];
|
|
1613 #endif
|
|
1614 Lisp_Object outstream;
|
|
1615 struct Lisp_Process *p = XPROCESS (proc);
|
|
1616
|
|
1617 /* If there is a lot of output from the subprocess, the loop in
|
|
1618 execute_internal_event() might call read_process_output() more
|
|
1619 than once. If the filter that was executed from one of these
|
|
1620 calls set the filter to t, we have to stop now. Return -1 rather
|
|
1621 than 0 so execute_internal_event() doesn't close the process.
|
|
1622 Really, the loop in execute_internal_event() should check itself
|
|
1623 for a process-filter change, like in status_notify(); but the
|
|
1624 struct Lisp_Process is not exported outside of this file. */
|
|
1625 if (p->infd < 0)
|
|
1626 return -1; /* already closed */
|
|
1627
|
|
1628 if (!NILP (p->filter) && (p->filter_does_read))
|
|
1629 {
|
|
1630 Lisp_Object filter_result;
|
|
1631
|
|
1632 /* Some weird FSFmacs crap here with
|
|
1633 Vdeactivate_mark and current_buffer->keymap */
|
|
1634 running_asynch_code = 1;
|
|
1635 filter_result = call2_trapping_errors ("Error in process filter",
|
|
1636 p->filter, proc, Qnil);
|
|
1637 running_asynch_code = 0;
|
|
1638 restore_match_data ();
|
|
1639 CHECK_INT (filter_result);
|
|
1640 return XINT (filter_result);
|
|
1641 }
|
|
1642
|
|
1643 #ifdef VMS
|
|
1644 VMS_PROC_STUFF *vs, *get_vms_process_pointer();
|
|
1645
|
|
1646 vs = get_vms_process_pointer (XINT (p->pid));
|
|
1647 if (vs)
|
|
1648 {
|
|
1649 if (!vs->iosb[0])
|
|
1650 return(0); /* Really weird if it does this */
|
|
1651 if (!(vs->iosb[0] & 1))
|
|
1652 return -1; /* I/O error */
|
|
1653 }
|
|
1654 else
|
|
1655 error ("Could not get VMS process pointer");
|
|
1656 chars = vs->inputBuffer;
|
|
1657 nbytes = clean_vms_buffer (chars, vs->iosb[1]);
|
|
1658 if (nbytes <= 0)
|
|
1659 {
|
|
1660 start_vms_process_read (vs); /* Crank up the next read on the process */
|
|
1661 return 1; /* Nothing worth printing, say we got 1 */
|
|
1662 }
|
|
1663 #else /* not VMS */
|
|
1664
|
|
1665 #if 0 /* FSFmacs */
|
|
1666 /* #### equivalent code from FSFmacs. Would need some porting
|
|
1667 for Windows NT. */
|
|
1668 if (proc_buffered_char[channel] < 0)
|
|
1669 #ifdef WINDOWSNT
|
|
1670 nchars = read_child_output (channel, chars, sizeof (chars));
|
|
1671 #else
|
|
1672 nchars = read (channel, chars, sizeof chars);
|
|
1673 #endif
|
|
1674 else
|
|
1675 {
|
|
1676 chars[0] = proc_buffered_char[channel];
|
|
1677 proc_buffered_char[channel] = -1;
|
|
1678 #ifdef WINDOWSNT
|
|
1679 nchars = read_child_output (channel, chars + 1, sizeof (chars) - 1);
|
|
1680 #else
|
|
1681 nchars = read (channel, chars + 1, sizeof chars - 1);
|
|
1682 #endif
|
|
1683 if (nchars < 0)
|
|
1684 nchars = 1;
|
|
1685 else
|
|
1686 nchars = nchars + 1;
|
|
1687 }
|
|
1688 #endif /* FSFmacs */
|
|
1689
|
|
1690 nbytes = Lstream_read (XLSTREAM (p->instream), chars, sizeof (chars));
|
|
1691 if (nbytes <= 0) return nbytes;
|
|
1692 #endif /* not VMS */
|
|
1693
|
|
1694 nchars = bytecount_to_charcount (chars, nbytes);
|
|
1695 outstream = p->filter;
|
|
1696 if (!NILP (outstream))
|
|
1697 {
|
|
1698 /* We used to bind inhibit-quit to t here, but
|
|
1699 call2_trapping_errors() does that for us. */
|
|
1700 running_asynch_code = 1;
|
|
1701 call2_trapping_errors ("Error in process filter",
|
|
1702 outstream, proc, make_string (chars, nbytes));
|
|
1703 running_asynch_code = 0;
|
|
1704 restore_match_data ();
|
|
1705 #ifdef VMS
|
|
1706 start_vms_process_read (vs);
|
|
1707 #endif
|
|
1708 return (nchars);
|
|
1709 }
|
|
1710
|
|
1711 /* If no filter, write into buffer if it isn't dead. */
|
|
1712 if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer)))
|
|
1713 {
|
|
1714 Lisp_Object old_read_only = Qnil;
|
|
1715 Bufpos old_point;
|
|
1716 Bufpos old_begv;
|
|
1717 Bufpos old_zv;
|
|
1718 int old_zmacs_region_stays = zmacs_region_stays;
|
|
1719 struct gcpro gcpro1, gcpro2;
|
|
1720 struct buffer *buf = XBUFFER (p->buffer);
|
|
1721
|
|
1722 GCPRO2 (proc, old_read_only);
|
|
1723
|
|
1724 old_point = BUF_PT (buf);
|
|
1725 old_begv = BUF_BEGV (buf);
|
|
1726 old_zv = BUF_ZV (buf);
|
|
1727 old_read_only = buf->read_only;
|
|
1728 buf->read_only = Qnil;
|
|
1729
|
|
1730 /* Insert new output into buffer
|
|
1731 at the current end-of-output marker,
|
|
1732 thus preserving logical ordering of input and output. */
|
|
1733 if (XMARKER (p->mark)->buffer)
|
|
1734 BUF_SET_PT (buf,
|
|
1735 bufpos_clip_to_bounds (old_begv, marker_position (p->mark),
|
|
1736 old_zv));
|
|
1737 else
|
|
1738 BUF_SET_PT (buf, old_zv);
|
|
1739
|
|
1740 /* If the output marker is outside of the visible region, save
|
|
1741 the restriction and widen. */
|
|
1742 if (! (BUF_BEGV (buf) <= BUF_PT (buf) &&
|
|
1743 BUF_PT (buf) <= BUF_ZV (buf)))
|
|
1744 Fwiden (p->buffer);
|
|
1745
|
|
1746 /* Make sure opoint floats ahead of any new text, just as point
|
|
1747 would. */
|
|
1748 if (BUF_PT (buf) <= old_point)
|
|
1749 old_point += nchars;
|
|
1750
|
|
1751 /* Insert after old_begv, but before old_zv. */
|
|
1752 if (BUF_PT (buf) < old_begv)
|
|
1753 old_begv += nchars;
|
|
1754 if (BUF_PT (buf) <= old_zv)
|
|
1755 old_zv += nchars;
|
|
1756
|
|
1757 #if 0
|
|
1758 /* This screws up intial display of the window. jla */
|
|
1759
|
|
1760 /* Insert before markers in case we are inserting where
|
|
1761 the buffer's mark is, and the user's next command is Meta-y. */
|
|
1762 buffer_insert_raw_string_1 (buf, -1, chars,
|
|
1763 nbytes, INSDEL_BEFORE_MARKERS);
|
|
1764 #else
|
|
1765 buffer_insert_raw_string (buf, chars, nbytes);
|
|
1766 #endif
|
|
1767
|
|
1768 Fset_marker (p->mark, make_int (BUF_PT (buf)), p->buffer);
|
|
1769
|
|
1770 MARK_MODELINE_CHANGED;
|
|
1771
|
|
1772 /* If the restriction isn't what it should be, set it. */
|
|
1773 if (old_begv != BUF_BEGV (buf) || old_zv != BUF_ZV (buf))
|
161
|
1774 {
|
|
1775 Fwiden(p->buffer);
|
|
1776 old_begv = bufpos_clip_to_bounds (BUF_BEG (buf),
|
|
1777 old_begv,
|
|
1778 BUF_Z (buf));
|
|
1779 old_zv = bufpos_clip_to_bounds (BUF_BEG (buf),
|
|
1780 old_zv,
|
|
1781 BUF_Z (buf));
|
|
1782 Fnarrow_to_region (make_int (old_begv), make_int (old_zv),
|
|
1783 p->buffer);
|
|
1784 }
|
0
|
1785
|
|
1786 /* Handling the process output should not deactivate the mark. */
|
|
1787 zmacs_region_stays = old_zmacs_region_stays;
|
|
1788 buf->read_only = old_read_only;
|
161
|
1789 old_point = bufpos_clip_to_bounds (BUF_BEGV (buf),
|
|
1790 old_point,
|
|
1791 BUF_ZV (buf));
|
0
|
1792 BUF_SET_PT (buf, old_point);
|
|
1793
|
|
1794 UNGCPRO;
|
|
1795 }
|
|
1796 #ifdef VMS
|
|
1797 start_vms_process_read (vs);
|
|
1798 #endif
|
|
1799 return (nchars);
|
|
1800 }
|
|
1801
|
|
1802 /* Sending data to subprocess */
|
|
1803
|
|
1804 static JMP_BUF send_process_frame;
|
|
1805
|
|
1806 static SIGTYPE
|
|
1807 send_process_trap (int signum)
|
|
1808 {
|
|
1809 EMACS_REESTABLISH_SIGNAL (signum, send_process_trap);
|
|
1810 EMACS_UNBLOCK_SIGNAL (signum);
|
|
1811 LONGJMP (send_process_frame, 1);
|
|
1812 }
|
|
1813
|
|
1814 /* send some data to process PROC. If NONRELOCATABLE is non-NULL, it
|
|
1815 specifies the address of the data. Otherwise, the data comes from the
|
|
1816 object RELOCATABLE (either a string or a buffer). START and LEN
|
|
1817 specify the offset and length of the data to send.
|
|
1818
|
|
1819 Note that START and LEN are in Bufpos's if RELOCATABLE is a buffer,
|
|
1820 and in Bytecounts otherwise. */
|
|
1821
|
|
1822 static void
|
|
1823 send_process (volatile Lisp_Object proc,
|
|
1824 Lisp_Object relocatable, CONST Bufbyte *nonrelocatable,
|
|
1825 int start, int len)
|
|
1826 {
|
|
1827 /* This function can GC */
|
|
1828 /* Use volatile to protect variables from being clobbered by longjmp. */
|
|
1829 struct gcpro gcpro1, gcpro2;
|
16
|
1830 SIGTYPE (*volatile old_sigpipe) (int) = 0;
|
0
|
1831 Lisp_Object lstream = Qnil;
|
|
1832 volatile struct Lisp_Process *p = XPROCESS (proc);
|
|
1833 #if defined (NO_UNION_TYPE) /* || !defined (__GNUC__) GCC bug only??? */
|
|
1834 /* #### ugh! There must be a better solution. */
|
|
1835 Lisp_Object defeat_volatile_kludge = (Lisp_Object) proc;
|
|
1836 #else
|
|
1837 Lisp_Object defeat_volatile_kludge = proc;
|
|
1838 #endif
|
|
1839
|
|
1840 #ifdef VMS
|
|
1841 VMS_PROC_STUFF *vs, *get_vms_process_pointer (int);
|
|
1842 #endif /* VMS */
|
|
1843
|
|
1844 GCPRO2 (defeat_volatile_kludge, lstream);
|
|
1845
|
|
1846 if (p->outfd < 0)
|
|
1847 signal_simple_error ("Process not open for writing", proc);
|
|
1848
|
|
1849 #ifdef VMS
|
|
1850 vs = get_vms_process_pointer (XINT (p->pid));
|
|
1851 if (vs == 0)
|
|
1852 error ("Could not find this process: %x",
|
|
1853 XINT (p->pid));
|
|
1854 else if (write_to_vms_process (vs, buf, len))
|
|
1855 ;
|
|
1856 #else
|
|
1857
|
|
1858 if (nonrelocatable)
|
|
1859 lstream =
|
|
1860 make_fixed_buffer_input_stream (nonrelocatable + start, len);
|
|
1861 else if (GC_BUFFERP (relocatable))
|
|
1862 lstream = make_lisp_buffer_input_stream (XBUFFER (relocatable),
|
|
1863 start, start + len, 0);
|
|
1864 else
|
|
1865 lstream = make_lisp_string_input_stream (relocatable, start, len);
|
|
1866
|
|
1867 if (!SETJMP (send_process_frame))
|
|
1868 {
|
|
1869 /* use a reasonable-sized buffer (somewhere around the size of the
|
|
1870 stream buffer) so as to avoid inundating the stream with blocked
|
|
1871 data. */
|
|
1872 Bufbyte chunkbuf[512];
|
|
1873 Bytecount chunklen;
|
|
1874
|
|
1875 while (1)
|
|
1876 {
|
|
1877 int writeret;
|
|
1878
|
|
1879 chunklen = Lstream_read (XLSTREAM (lstream), chunkbuf, 512);
|
|
1880 if (chunklen <= 0)
|
|
1881 break; /* perhaps should abort() if < 0?
|
|
1882 This should never happen. */
|
|
1883 old_sigpipe =
|
|
1884 (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
|
|
1885 /* Lstream_write() will never successfully write less than
|
|
1886 the amount sent in. In the worst case, it just buffers
|
|
1887 the unwritten data. */
|
|
1888 writeret = Lstream_write (XLSTREAM (p->outstream), chunkbuf,
|
|
1889 chunklen);
|
|
1890 signal (SIGPIPE, old_sigpipe);
|
|
1891 if (writeret < 0)
|
|
1892 /* This is a real error. Blocking errors are handled
|
|
1893 specially inside of the filedesc stream. */
|
|
1894 report_file_error ("writing to process",
|
|
1895 list1 (proc));
|
|
1896 while (filedesc_stream_was_blocked (XLSTREAM (p->filedesc_stream)))
|
|
1897 {
|
|
1898 /* Buffer is full. Wait, accepting input;
|
|
1899 that may allow the program
|
|
1900 to finish doing output and read more. */
|
|
1901 Faccept_process_output (Qnil, make_int (1), Qnil);
|
|
1902 old_sigpipe =
|
|
1903 (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
|
|
1904 Lstream_flush (XLSTREAM (p->filedesc_stream));
|
|
1905 signal (SIGPIPE, old_sigpipe);
|
|
1906 }
|
|
1907 }
|
|
1908 }
|
|
1909 #endif /* !VMS */
|
|
1910 else
|
|
1911 { /* We got here from a longjmp() from the SIGPIPE handler */
|
|
1912 signal (SIGPIPE, old_sigpipe);
|
|
1913 p->status_symbol = Qexit;
|
|
1914 p->exit_code = 256; /* #### SIGPIPE ??? */
|
|
1915 p->core_dumped = 0;
|
|
1916 p->tick++;
|
|
1917 process_tick++;
|
|
1918 deactivate_process (proc);
|
|
1919 #ifdef VMS
|
|
1920 error ("Error writing to process %s; closed it",
|
70
|
1921 XSTRING_DATA (p->name));
|
0
|
1922 #else
|
|
1923 error ("SIGPIPE raised on process %s; closed it",
|
70
|
1924 XSTRING_DATA (p->name));
|
0
|
1925 #endif
|
|
1926 }
|
|
1927 Lstream_flush (XLSTREAM (p->outstream));
|
|
1928 UNGCPRO;
|
|
1929 }
|
|
1930
|
20
|
1931 DEFUN ("process-tty-name", Fprocess_tty_name, 1, 1, 0, /*
|
0
|
1932 Return the name of the terminal PROCESS uses, or nil if none.
|
|
1933 This is the terminal that the process itself reads and writes on,
|
|
1934 not the name of the pty that Emacs uses to talk with that terminal.
|
20
|
1935 */
|
|
1936 (proc))
|
0
|
1937 {
|
|
1938 CHECK_PROCESS (proc);
|
|
1939 return XPROCESS (proc)->tty_name;
|
|
1940 }
|
|
1941
|
20
|
1942 DEFUN ("set-process-buffer", Fset_process_buffer, 2, 2, 0, /*
|
0
|
1943 Set buffer associated with PROCESS to BUFFER (a buffer, or nil).
|
20
|
1944 */
|
|
1945 (proc, buffer))
|
0
|
1946 {
|
|
1947 CHECK_PROCESS (proc);
|
|
1948 if (!NILP (buffer))
|
|
1949 CHECK_BUFFER (buffer);
|
|
1950 XPROCESS (proc)->buffer = buffer;
|
|
1951 return buffer;
|
|
1952 }
|
|
1953
|
20
|
1954 DEFUN ("process-buffer", Fprocess_buffer, 1, 1, 0, /*
|
0
|
1955 Return the buffer PROCESS is associated with.
|
|
1956 Output from PROCESS is inserted in this buffer
|
|
1957 unless PROCESS has a filter.
|
20
|
1958 */
|
|
1959 (proc))
|
0
|
1960 {
|
|
1961 CHECK_PROCESS (proc);
|
|
1962 return XPROCESS (proc)->buffer;
|
|
1963 }
|
|
1964
|
20
|
1965 DEFUN ("process-mark", Fprocess_mark, 1, 1, 0, /*
|
0
|
1966 Return the marker for the end of the last output from PROCESS.
|
20
|
1967 */
|
|
1968 (proc))
|
0
|
1969 {
|
|
1970 CHECK_PROCESS (proc);
|
|
1971 #ifdef ENERGIZE
|
|
1972 if (EQ (proc, Venergize_process)) /* per buffer rather than per process */
|
|
1973 return Fenergize_user_input_buffer_mark (Qnil); /* ## current_buffer ok? */
|
|
1974 #endif
|
|
1975 return XPROCESS (proc)->mark;
|
|
1976 }
|
|
1977
|
|
1978 void
|
|
1979 set_process_filter (Lisp_Object proc, Lisp_Object filter, int filter_does_read)
|
|
1980 {
|
|
1981 CHECK_PROCESS (proc);
|
|
1982 if (PROCESS_LIVE_P (proc))
|
|
1983 if (EQ (filter, Qt))
|
|
1984 event_stream_unselect_process (XPROCESS (proc));
|
|
1985 else
|
|
1986 event_stream_select_process (XPROCESS (proc));
|
|
1987
|
|
1988 XPROCESS (proc)->filter = filter;
|
|
1989 XPROCESS (proc)->filter_does_read = filter_does_read;
|
|
1990 }
|
|
1991
|
20
|
1992 DEFUN ("set-process-filter", Fset_process_filter, 2, 2, 0, /*
|
0
|
1993 Give PROCESS the filter function FILTER; nil means no filter.
|
|
1994 t means stop accepting output from the process.
|
|
1995 When a process has a filter, each time it does output
|
|
1996 the entire string of output is passed to the filter.
|
|
1997 The filter gets two arguments: the process and the string of output.
|
|
1998 If the process has a filter, its buffer is not used for output.
|
20
|
1999 */
|
|
2000 (proc, filter))
|
0
|
2001 {
|
|
2002 set_process_filter (proc, filter, 0);
|
|
2003 return filter;
|
|
2004 }
|
|
2005
|
20
|
2006 DEFUN ("process-filter", Fprocess_filter, 1, 1, 0, /*
|
0
|
2007 Return the filter function of PROCESS; nil if none.
|
|
2008 See `set-process-filter' for more info on filter functions.
|
20
|
2009 */
|
|
2010 (proc))
|
0
|
2011 {
|
|
2012 CHECK_PROCESS (proc);
|
|
2013 return XPROCESS (proc)->filter;
|
|
2014 }
|
|
2015
|
20
|
2016 DEFUN ("process-send-region", Fprocess_send_region, 3, 3, 0, /*
|
0
|
2017 Send current contents of region as input to PROCESS.
|
|
2018 PROCESS may be a process name or an actual process.
|
|
2019 Called from program, takes three arguments, PROCESS, START and END.
|
|
2020 If the region is more than 500 or so characters long,
|
|
2021 it is sent in several bunches. This may happen even for shorter regions.
|
|
2022 Output from processes can arrive in between bunches.
|
20
|
2023 */
|
|
2024 (process, start, end))
|
0
|
2025 {
|
|
2026 /* This function can GC */
|
|
2027 Lisp_Object proc = get_process (process);
|
|
2028 Bufpos st, en;
|
|
2029
|
|
2030 get_buffer_range_char (current_buffer, start, end, &st, &en, 0);
|
|
2031
|
|
2032 send_process (proc, Fcurrent_buffer (), 0,
|
|
2033 st, en - st);
|
|
2034 return (Qnil);
|
|
2035 }
|
|
2036
|
20
|
2037 DEFUN ("process-send-string", Fprocess_send_string, 2, 4, 0, /*
|
0
|
2038 Send PROCESS the contents of STRING as input.
|
|
2039 PROCESS may be a process name or an actual process.
|
|
2040 Optional arguments FROM and TO specify part of STRING, see `substring'.
|
|
2041 If STRING is more than 500 or so characters long,
|
|
2042 it is sent in several bunches. This may happen even for shorter strings.
|
|
2043 Output from processes can arrive in between bunches.
|
20
|
2044 */
|
|
2045 (process, string, from, to))
|
0
|
2046 {
|
|
2047 /* This function can GC */
|
|
2048 Lisp_Object proc;
|
|
2049 Bytecount len;
|
|
2050 Bytecount bfr, bto;
|
|
2051
|
|
2052 proc = get_process (process);
|
|
2053 CHECK_STRING (string);
|
|
2054 get_string_range_byte (string, from, to, &bfr, &bto,
|
|
2055 GB_HISTORICAL_STRING_BEHAVIOR);
|
|
2056 len = bto - bfr;
|
|
2057
|
|
2058 send_process (proc, string, 0, bfr, len);
|
|
2059 return (Qnil);
|
|
2060 }
|
|
2061
|
70
|
2062 #ifdef MULE
|
|
2063
|
|
2064 DEFUN ("process-input-coding-system", Fprocess_input_coding_system, 1, 1, 0, /*
|
|
2065 Return PROCESS's input coding system.
|
|
2066 */
|
|
2067 (process))
|
|
2068 {
|
|
2069 process = get_process (process);
|
|
2070 return decoding_stream_coding_system (XLSTREAM ( XPROCESS (process)->instream) );
|
|
2071 }
|
|
2072
|
|
2073 DEFUN ("process-output-coding-system", Fprocess_output_coding_system, 1, 1, 0, /*
|
|
2074 Return PROCESS's output coding system.
|
|
2075 */
|
|
2076 (process))
|
|
2077 {
|
|
2078 process = get_process (process);
|
|
2079 return encoding_stream_coding_system (XLSTREAM (XPROCESS (process)->outstream));
|
|
2080 }
|
|
2081
|
120
|
2082 DEFUN ("process-coding-system", Fprocess_coding_system, 1, 1, 0, /*
|
|
2083 Return a pair of coding-system for decoding and encoding of PROCESS.
|
|
2084 */
|
|
2085 (process))
|
|
2086 {
|
|
2087 process = get_process (process);
|
|
2088 return Fcons(decoding_stream_coding_system
|
|
2089 (XLSTREAM (XPROCESS (process)->instream)),
|
|
2090 encoding_stream_coding_system
|
|
2091 (XLSTREAM (XPROCESS (process)->outstream)) );
|
|
2092 }
|
|
2093
|
70
|
2094 DEFUN ("set-process-input-coding-system",
|
|
2095 Fset_process_input_coding_system, 2, 2, 0, /*
|
|
2096 Set PROCESS's input coding system to CODESYS.
|
|
2097 */
|
|
2098 (process, codesys))
|
|
2099 {
|
|
2100 codesys = Fget_coding_system (codesys);
|
|
2101 process = get_process (process);
|
|
2102 set_decoding_stream_coding_system ( XLSTREAM ( XPROCESS (process)->instream ), codesys);
|
|
2103 return Qnil;
|
|
2104 }
|
|
2105
|
|
2106 DEFUN ("set-process-output-coding-system",
|
|
2107 Fset_process_output_coding_system, 2, 2, 0, /*
|
|
2108 Set PROCESS's output coding system to CODESYS.
|
|
2109 */
|
|
2110 (process, codesys))
|
|
2111 {
|
|
2112 codesys = Fget_coding_system (codesys);
|
|
2113 process = get_process (process);
|
|
2114 set_encoding_stream_coding_system
|
|
2115 ( XLSTREAM ( XPROCESS (process)->outstream), codesys);
|
|
2116 return Qnil;
|
|
2117 }
|
|
2118
|
120
|
2119 DEFUN ("set-process-coding-system",
|
|
2120 Fset_process_coding_system, 1, 3, 0, /*
|
|
2121 Set coding-systems of PROCESS to DECODING and ENCODING.
|
|
2122 */
|
|
2123 (process, decoding, encoding))
|
|
2124 {
|
|
2125 if(!NILP(decoding)){
|
|
2126 Fset_process_input_coding_system(process, decoding);
|
|
2127 }
|
|
2128 if(!NILP(encoding)){
|
|
2129 Fset_process_output_coding_system(process, encoding);
|
|
2130 }
|
|
2131 return Qnil;
|
|
2132 }
|
|
2133
|
70
|
2134 #endif /* MULE */
|
|
2135
|
0
|
2136
|
|
2137 /************************************************************************/
|
|
2138 /* process status */
|
|
2139 /************************************************************************/
|
|
2140
|
|
2141 /* Some FSFmacs error handlers here. We handle this
|
|
2142 in call2_trapping_errors(). */
|
|
2143
|
|
2144 static Lisp_Object
|
|
2145 exec_sentinel_unwind (Lisp_Object datum)
|
|
2146 {
|
|
2147 struct Lisp_Cons *d = XCONS (datum);
|
|
2148 XPROCESS (d->car)->sentinel = d->cdr;
|
|
2149 free_cons (d);
|
|
2150 return Qnil;
|
|
2151 }
|
|
2152
|
|
2153 static void
|
|
2154 exec_sentinel (Lisp_Object proc, Lisp_Object reason)
|
|
2155 {
|
|
2156 /* This function can GC */
|
|
2157 Lisp_Object sentinel;
|
|
2158 struct Lisp_Process *p = XPROCESS (proc);
|
|
2159 int speccount = specpdl_depth ();
|
|
2160
|
|
2161 sentinel = p->sentinel;
|
|
2162 if (NILP (sentinel))
|
|
2163 return;
|
|
2164
|
|
2165 /* Some weird FSFmacs crap here with
|
|
2166 Vdeactivate_mark and current_buffer->keymap */
|
|
2167
|
|
2168 /* Zilch the sentinel while it's running, to avoid recursive invocations;
|
|
2169 assure that it gets restored no matter how the sentinel exits. */
|
|
2170 p->sentinel = Qnil;
|
|
2171 record_unwind_protect (exec_sentinel_unwind, noseeum_cons (proc, sentinel));
|
|
2172 /* We used to bind inhibit-quit to t here, but call2_trapping_errors()
|
|
2173 does that for us. */
|
|
2174 running_asynch_code = 1;
|
|
2175 call2_trapping_errors ("Error in process sentinel",
|
|
2176 sentinel, proc, reason);
|
|
2177 running_asynch_code = 0;
|
|
2178 restore_match_data ();
|
|
2179 unbind_to (speccount, Qnil);
|
|
2180 }
|
|
2181
|
20
|
2182 DEFUN ("set-process-sentinel", Fset_process_sentinel, 2, 2, 0, /*
|
0
|
2183 Give PROCESS the sentinel SENTINEL; nil for none.
|
|
2184 The sentinel is called as a function when the process changes state.
|
|
2185 It gets two arguments: the process, and a string describing the change.
|
20
|
2186 */
|
|
2187 (proc, sentinel))
|
0
|
2188 {
|
|
2189 CHECK_PROCESS (proc);
|
|
2190 XPROCESS (proc)->sentinel = sentinel;
|
|
2191 return sentinel;
|
|
2192 }
|
|
2193
|
20
|
2194 DEFUN ("process-sentinel", Fprocess_sentinel, 1, 1, 0, /*
|
0
|
2195 Return the sentinel of PROCESS; nil if none.
|
|
2196 See `set-process-sentinel' for more info on sentinels.
|
20
|
2197 */
|
|
2198 (proc))
|
0
|
2199 {
|
|
2200 CHECK_PROCESS (proc);
|
|
2201 return XPROCESS (proc)->sentinel;
|
|
2202 }
|
|
2203
|
|
2204
|
|
2205 CONST char *
|
|
2206 signal_name (int signum)
|
|
2207 {
|
|
2208 if (signum >= 0 && signum < NSIG)
|
|
2209 #ifndef VMS
|
|
2210 return ((CONST char *) sys_siglist[signum]);
|
|
2211 #else
|
|
2212 return ((CONST char *) sys_errlist[signum]);
|
|
2213 #endif
|
|
2214 return ((CONST char *) GETTEXT ("unknown signal"));
|
|
2215 }
|
|
2216
|
|
2217 /* Compute the Lisp form of the process status from
|
|
2218 the numeric status that was returned by `wait'. */
|
|
2219
|
|
2220 static void
|
155
|
2221 update_status_from_wait_code (struct Lisp_Process *p, int *w_fmh)
|
0
|
2222 {
|
|
2223 /* C compiler lossage when attempting to pass w directly */
|
155
|
2224 int w = *w_fmh;
|
0
|
2225
|
|
2226 if (WIFSTOPPED (w))
|
|
2227 {
|
|
2228 p->status_symbol = Qstop;
|
|
2229 p->exit_code = WSTOPSIG (w);
|
|
2230 p->core_dumped = 0;
|
|
2231 }
|
|
2232 else if (WIFEXITED (w))
|
|
2233 {
|
|
2234 p->status_symbol = Qexit;
|
155
|
2235 p->exit_code = WEXITSTATUS (w);
|
|
2236 p->core_dumped = 0;
|
0
|
2237 }
|
|
2238 else if (WIFSIGNALED (w))
|
|
2239 {
|
|
2240 p->status_symbol = Qsignal;
|
155
|
2241 p->exit_code = WTERMSIG (w);
|
|
2242 p->core_dumped = WCOREDUMP (w);
|
0
|
2243 }
|
|
2244 else
|
|
2245 {
|
|
2246 p->status_symbol = Qrun;
|
|
2247 p->exit_code = 0;
|
|
2248 }
|
|
2249 }
|
|
2250
|
|
2251 void
|
|
2252 update_process_status (Lisp_Object p,
|
|
2253 Lisp_Object status_symbol,
|
|
2254 int exit_code,
|
|
2255 int core_dumped)
|
|
2256 {
|
|
2257 XPROCESS (p)->tick++;
|
|
2258 process_tick++;
|
|
2259 XPROCESS (p)->status_symbol = status_symbol;
|
|
2260 XPROCESS (p)->exit_code = exit_code;
|
|
2261 XPROCESS (p)->core_dumped = core_dumped;
|
|
2262 }
|
|
2263
|
|
2264 #ifdef SIGCHLD
|
|
2265
|
|
2266 #define MAX_EXITED_PROCESSES 1000
|
|
2267 static volatile pid_t exited_processes[MAX_EXITED_PROCESSES];
|
155
|
2268 static volatile int exited_processes_status[MAX_EXITED_PROCESSES];
|
0
|
2269 static volatile int exited_processes_index;
|
|
2270
|
|
2271 static volatile int sigchld_happened;
|
|
2272
|
|
2273 /* For any processes that have changed status and are recorded
|
|
2274 and such, update the corresponding struct Lisp_Process.
|
|
2275 We separate this from record_exited_processes() so that
|
|
2276 we never have to call this function from within a signal
|
|
2277 handler. We block SIGCHLD in case record_exited_processes()
|
|
2278 is called from a signal handler. */
|
|
2279
|
|
2280 static void
|
|
2281 reap_exited_processes (void)
|
|
2282 {
|
|
2283 int i;
|
|
2284 struct Lisp_Process *p;
|
|
2285
|
114
|
2286 if (exited_processes_index <= 0)
|
|
2287 {
|
|
2288 return;
|
|
2289 }
|
|
2290
|
100
|
2291 #ifdef EMACS_BLOCK_SIGNAL
|
0
|
2292 EMACS_BLOCK_SIGNAL (SIGCHLD);
|
100
|
2293 #endif
|
0
|
2294 for (i = 0; i < exited_processes_index; i++)
|
|
2295 {
|
|
2296 int pid = exited_processes[i];
|
155
|
2297 int w = exited_processes_status[i];
|
0
|
2298
|
|
2299 /* Find the process that signaled us, and record its status. */
|
|
2300
|
|
2301 p = 0;
|
|
2302 {
|
|
2303 Lisp_Object tail;
|
|
2304 LIST_LOOP (tail, Vprocess_list)
|
|
2305 {
|
|
2306 Lisp_Object proc = XCAR (tail);
|
|
2307 p = XPROCESS (proc);
|
|
2308 if (INTP (p->pid) && XINT (p->pid) == pid)
|
|
2309 break;
|
|
2310 p = 0;
|
|
2311 }
|
|
2312 }
|
|
2313
|
|
2314 if (p)
|
|
2315 {
|
|
2316 /* Change the status of the process that was found. */
|
|
2317 p->tick++;
|
|
2318 process_tick++;
|
|
2319 update_status_from_wait_code (p, &w);
|
|
2320
|
|
2321 /* If process has terminated, stop waiting for its output. */
|
|
2322 if (WIFSIGNALED (w) || WIFEXITED (w))
|
|
2323 {
|
|
2324 if (p->infd >= 0)
|
|
2325 {
|
|
2326 /* We can't just call event_stream->unselect_process_cb (p)
|
|
2327 here, because that calls XtRemoveInput, which is not
|
|
2328 necessarily reentrant, so we can't call this at interrupt
|
|
2329 level.
|
|
2330 */
|
|
2331 }
|
|
2332 }
|
|
2333 }
|
|
2334 else
|
|
2335 {
|
|
2336 /* There was no asynchronous process found for that id. Check
|
|
2337 if we have a synchronous process. Only set sync process status
|
|
2338 if there is one, so we work OK with the waitpid() call in
|
|
2339 wait_for_termination(). */
|
|
2340 if (synch_process_alive != 0)
|
|
2341 { /* Set the global sync process status variables. */
|
|
2342 synch_process_alive = 0;
|
|
2343
|
|
2344 /* Report the status of the synchronous process. */
|
|
2345 if (WIFEXITED (w))
|
155
|
2346 synch_process_retcode = WEXITSTATUS (w);
|
0
|
2347 else if (WIFSIGNALED (w))
|
|
2348 synch_process_death = signal_name (WTERMSIG (w));
|
|
2349 }
|
|
2350 }
|
|
2351 }
|
|
2352
|
|
2353 exited_processes_index = 0;
|
|
2354
|
|
2355 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
|
|
2356 }
|
|
2357
|
|
2358 /* On receipt of a signal that a child status has changed,
|
|
2359 loop asking about children with changed statuses until
|
|
2360 the system says there are no more. All we do is record
|
|
2361 the processes and wait status.
|
|
2362
|
|
2363 This function could be called from within the SIGCHLD
|
|
2364 handler, so it must be completely reentrant. When
|
|
2365 not called from a SIGCHLD handler, BLOCK_SIGCHLD should
|
|
2366 be non-zero so that SIGCHLD is blocked while this
|
|
2367 function is running. (This is necessary so avoid
|
|
2368 race conditions with the SIGCHLD_HAPPENED flag). */
|
|
2369
|
|
2370 static void
|
|
2371 record_exited_processes (int block_sigchld)
|
|
2372 {
|
114
|
2373 if (!sigchld_happened)
|
|
2374 {
|
|
2375 return;
|
|
2376 }
|
|
2377
|
102
|
2378 #ifdef EMACS_BLOCK_SIGNAL
|
0
|
2379 if (block_sigchld)
|
|
2380 EMACS_BLOCK_SIGNAL (SIGCHLD);
|
100
|
2381 #endif
|
0
|
2382
|
|
2383 while (sigchld_happened)
|
|
2384 {
|
|
2385 int pid;
|
155
|
2386 int w;
|
0
|
2387
|
|
2388 /* Keep trying to get a status until we get a definitive result. */
|
|
2389 do
|
|
2390 {
|
|
2391 errno = 0;
|
|
2392 #ifdef WNOHANG
|
|
2393 # ifndef WUNTRACED
|
|
2394 # define WUNTRACED 0
|
|
2395 # endif /* not WUNTRACED */
|
|
2396 # ifdef HAVE_WAITPID
|
|
2397 pid = waitpid ((pid_t) -1, &w, WNOHANG | WUNTRACED);
|
|
2398 # else
|
|
2399 pid = wait3 (&w, WNOHANG | WUNTRACED, 0);
|
|
2400 # endif
|
|
2401 #else /* not WNOHANG */
|
|
2402 pid = wait (&w);
|
|
2403 #endif /* not WNOHANG */
|
|
2404 }
|
|
2405 while (pid <= 0 && errno == EINTR);
|
|
2406
|
|
2407 if (pid <= 0)
|
|
2408 break;
|
|
2409
|
|
2410 if (exited_processes_index < MAX_EXITED_PROCESSES)
|
|
2411 {
|
|
2412 exited_processes[exited_processes_index] = pid;
|
|
2413 exited_processes_status[exited_processes_index] = w;
|
|
2414 exited_processes_index++;
|
|
2415 }
|
|
2416
|
|
2417 /* On systems with WNOHANG, we just ignore the number
|
|
2418 of times that SIGCHLD was signalled, and keep looping
|
|
2419 until there are no more processes to wait on. If we
|
|
2420 don't have WNOHANG, we have to rely on the count in
|
|
2421 SIGCHLD_HAPPENED. */
|
|
2422 #ifndef WNOHANG
|
|
2423 sigchld_happened--;
|
|
2424 #endif /* not WNOHANG */
|
|
2425 }
|
|
2426
|
|
2427 sigchld_happened = 0;
|
|
2428
|
|
2429 if (block_sigchld)
|
|
2430 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
|
|
2431 }
|
|
2432
|
|
2433 /** USG WARNING: Although it is not obvious from the documentation
|
|
2434 in signal(2), on a USG system the SIGCLD handler MUST NOT call
|
|
2435 signal() before executing at least one wait(), otherwise the handler
|
|
2436 will be called again, resulting in an infinite loop. The relevant
|
|
2437 portion of the documentation reads "SIGCLD signals will be queued
|
|
2438 and the signal-catching function will be continually reentered until
|
|
2439 the queue is empty". Invoking signal() causes the kernel to reexamine
|
|
2440 the SIGCLD queue. Fred Fish, UniSoft Systems Inc.
|
|
2441
|
|
2442 (Note that now this only applies in SYS V Release 2 and before.
|
|
2443 On SYS V Release 3, we use sigset() to set the signal handler for
|
|
2444 the first time, and so we don't have to reestablish the signal handler
|
|
2445 in the handler below. On SYS V Release 4, we don't get this weirdo
|
|
2446 behavior when we use sigaction(), which we do use.) */
|
|
2447
|
|
2448 static SIGTYPE
|
|
2449 sigchld_handler (int signo)
|
|
2450 {
|
|
2451 #ifdef OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
|
|
2452 int old_errno = errno;
|
|
2453
|
|
2454 sigchld_happened++;
|
|
2455 record_exited_processes (0);
|
|
2456 errno = old_errno;
|
|
2457 #else
|
|
2458 sigchld_happened++;
|
|
2459 #endif
|
|
2460 signal_fake_event ();
|
|
2461 /* WARNING - must come after wait3() for USG systems */
|
|
2462 EMACS_REESTABLISH_SIGNAL (signo, sigchld_handler);
|
|
2463 SIGRETURN;
|
|
2464 }
|
|
2465
|
|
2466 #endif /* SIGCHLD */
|
|
2467
|
|
2468 /* Return a string describing a process status list. */
|
|
2469
|
|
2470 static Lisp_Object
|
|
2471 status_message (struct Lisp_Process *p)
|
|
2472 {
|
|
2473 Lisp_Object symbol = p->status_symbol;
|
|
2474 int code = p->exit_code;
|
|
2475 int coredump = p->core_dumped;
|
|
2476 Lisp_Object string, string2;
|
|
2477
|
|
2478 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
|
|
2479 {
|
|
2480 string = build_string (signal_name (code));
|
|
2481 if (coredump)
|
|
2482 string2 = build_translated_string (" (core dumped)\n");
|
|
2483 else
|
|
2484 string2 = build_string ("\n");
|
|
2485 set_string_char (XSTRING (string), 0,
|
|
2486 DOWNCASE (current_buffer,
|
|
2487 string_char (XSTRING (string), 0)));
|
|
2488 return concat2 (string, string2);
|
|
2489 }
|
|
2490 else if (EQ (symbol, Qexit))
|
|
2491 {
|
|
2492 if (code == 0)
|
|
2493 return build_translated_string ("finished\n");
|
|
2494 string = Fnumber_to_string (make_int (code));
|
|
2495 if (coredump)
|
|
2496 string2 = build_translated_string (" (core dumped)\n");
|
|
2497 else
|
|
2498 string2 = build_string ("\n");
|
|
2499 return concat2 (build_translated_string ("exited abnormally with code "),
|
|
2500 concat2 (string, string2));
|
|
2501 }
|
|
2502 else
|
|
2503 return Fcopy_sequence (Fsymbol_name (symbol));
|
|
2504 }
|
|
2505
|
|
2506 /* Tell status_notify() to check for terminated processes. We do this
|
|
2507 because on some systems we sometimes miss SIGCHLD calls. (Not sure
|
|
2508 why.) */
|
|
2509
|
|
2510 void
|
|
2511 kick_status_notify (void)
|
|
2512 {
|
|
2513 process_tick++;
|
|
2514 }
|
|
2515
|
|
2516 /* Report all recent events of a change in process status
|
|
2517 (either run the sentinel or output a message).
|
|
2518 This is done while Emacs is waiting for keyboard input. */
|
|
2519
|
|
2520 void
|
|
2521 status_notify (void)
|
|
2522 {
|
|
2523 /* This function can GC */
|
|
2524 Lisp_Object tail = Qnil;
|
|
2525 Lisp_Object symbol = Qnil;
|
|
2526 Lisp_Object msg = Qnil;
|
|
2527 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
2528 /* process_tick is volatile, so we have to remember it now.
|
|
2529 Otherwise, we get a race condition is SIGCHLD happens during
|
|
2530 this function.
|
|
2531
|
|
2532 (Actually, this is not the case anymore. The code to
|
|
2533 update the process structures has been moved out of the
|
|
2534 SIGCHLD handler. But for the moment I'm leaving this
|
|
2535 stuff in -- it can't hurt.) */
|
|
2536 int temp_process_tick;
|
|
2537
|
|
2538 #ifdef SIGCHLD
|
|
2539 #ifndef OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
|
|
2540 record_exited_processes (1);
|
|
2541 #endif
|
|
2542 reap_exited_processes ();
|
|
2543 #endif
|
|
2544
|
|
2545 temp_process_tick = process_tick;
|
|
2546
|
|
2547 if (update_tick == temp_process_tick)
|
|
2548 return;
|
|
2549
|
|
2550 /* We need to gcpro tail; if read_process_output calls a filter
|
|
2551 which deletes a process and removes the cons to which tail points
|
|
2552 from Vprocess_alist, and then causes a GC, tail is an unprotected
|
|
2553 reference. */
|
|
2554 GCPRO3 (tail, symbol, msg);
|
|
2555
|
|
2556 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
|
|
2557 {
|
|
2558 Lisp_Object proc = XCAR (tail);
|
|
2559 struct Lisp_Process *p = XPROCESS (proc);
|
|
2560 /* p->tick is also volatile. Same thing as above applies. */
|
|
2561 int this_process_tick;
|
|
2562
|
|
2563 #ifdef HAVE_WAITPID
|
|
2564 /* #### extra check for terminated processes, in case a SIGCHLD
|
|
2565 got missed (this seems to happen sometimes, I'm not sure why).
|
|
2566 */
|
|
2567 {
|
155
|
2568 int w;
|
0
|
2569 #ifdef SIGCHLD
|
|
2570 EMACS_BLOCK_SIGNAL (SIGCHLD);
|
|
2571 #endif
|
|
2572 if (INTP (p->pid) &&
|
|
2573 waitpid (XINT (p->pid), &w, WNOHANG) == XINT (p->pid))
|
|
2574 {
|
|
2575 p->tick++;
|
|
2576 update_status_from_wait_code (p, &w);
|
|
2577 }
|
|
2578 #ifdef SIGCHLD
|
|
2579 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
|
|
2580 #endif
|
|
2581 }
|
|
2582 #endif
|
|
2583 this_process_tick = p->tick;
|
|
2584 if (this_process_tick != p->update_tick)
|
|
2585 {
|
|
2586 p->update_tick = this_process_tick;
|
|
2587
|
|
2588 /* If process is still active, read any output that remains. */
|
|
2589 while (!EQ (p->filter, Qt)
|
|
2590 && read_process_output (proc) > 0)
|
|
2591 ;
|
|
2592
|
|
2593 /* Get the text to use for the message. */
|
|
2594 msg = status_message (p);
|
|
2595
|
|
2596 /* If process is terminated, deactivate it or delete it. */
|
|
2597 symbol = p->status_symbol;
|
|
2598
|
|
2599 if (EQ (symbol, Qsignal)
|
|
2600 || EQ (symbol, Qexit))
|
|
2601 {
|
|
2602 if (delete_exited_processes)
|
|
2603 remove_process (proc);
|
|
2604 else
|
|
2605 deactivate_process (proc);
|
|
2606 }
|
|
2607
|
|
2608 /* Now output the message suitably. */
|
|
2609 if (!NILP (p->sentinel))
|
|
2610 exec_sentinel (proc, msg);
|
|
2611 /* Don't bother with a message in the buffer
|
|
2612 when a process becomes runnable. */
|
|
2613 else if (!EQ (symbol, Qrun) && !NILP (p->buffer))
|
|
2614 {
|
161
|
2615 Lisp_Object old_read_only = Qnil;
|
|
2616 Lisp_Object old = Fcurrent_buffer ();
|
|
2617 Bufpos opoint;
|
|
2618 struct gcpro ngcpro1, ngcpro2;
|
0
|
2619
|
|
2620 /* Avoid error if buffer is deleted
|
|
2621 (probably that's why the process is dead, too) */
|
|
2622 if (!BUFFER_LIVE_P (XBUFFER (p->buffer)))
|
|
2623 continue;
|
|
2624
|
161
|
2625 NGCPRO2 (old, old_read_only);
|
0
|
2626 Fset_buffer (p->buffer);
|
161
|
2627 opoint = BUF_PT (current_buffer);
|
0
|
2628 /* Insert new output into buffer
|
|
2629 at the current end-of-output marker,
|
|
2630 thus preserving logical ordering of input and output. */
|
|
2631 if (XMARKER (p->mark)->buffer)
|
|
2632 BUF_SET_PT (current_buffer, marker_position (p->mark));
|
|
2633 else
|
|
2634 BUF_SET_PT (current_buffer, BUF_ZV (current_buffer));
|
161
|
2635 if (BUF_PT (current_buffer) <= opoint)
|
|
2636 opoint += (string_char_length (XSTRING (msg))
|
|
2637 + string_char_length (XSTRING (p->name))
|
|
2638 + 10);
|
|
2639
|
|
2640 old_read_only = current_buffer->read_only;
|
|
2641 current_buffer->read_only = Qnil;
|
0
|
2642 buffer_insert_c_string (current_buffer, "\nProcess ");
|
|
2643 Finsert (1, &p->name);
|
|
2644 buffer_insert_c_string (current_buffer, " ");
|
|
2645 Finsert (1, &msg);
|
161
|
2646 current_buffer->read_only = old_read_only;
|
0
|
2647 Fset_marker (p->mark, make_int (BUF_PT (current_buffer)),
|
|
2648 p->buffer);
|
161
|
2649
|
|
2650 opoint = bufpos_clip_to_bounds(BUF_BEGV (XBUFFER (p->buffer)),
|
|
2651 opoint,
|
|
2652 BUF_ZV (XBUFFER (p->buffer)));
|
|
2653 BUF_SET_PT (current_buffer, opoint);
|
|
2654 Fset_buffer (old);
|
|
2655 NUNGCPRO;
|
0
|
2656 }
|
|
2657 }
|
|
2658 } /* end for */
|
|
2659
|
|
2660 /* in case buffers use %s in modeline-format */
|
|
2661 MARK_MODELINE_CHANGED;
|
|
2662 redisplay ();
|
|
2663
|
|
2664 update_tick = temp_process_tick;
|
|
2665
|
|
2666 UNGCPRO;
|
|
2667 }
|
|
2668
|
20
|
2669 DEFUN ("process-status", Fprocess_status, 1, 1, 0, /*
|
0
|
2670 Return the status of PROCESS.
|
|
2671 This is a symbol, one of these:
|
|
2672
|
|
2673 run -- for a process that is running.
|
|
2674 stop -- for a process stopped but continuable.
|
|
2675 exit -- for a process that has exited.
|
|
2676 signal -- for a process that has got a fatal signal.
|
|
2677 open -- for a network stream connection that is open.
|
|
2678 closed -- for a network stream connection that is closed.
|
|
2679 nil -- if arg is a process name and no such process exists.
|
|
2680 PROCESS may be a process, a buffer, the name of a process or buffer, or
|
|
2681 nil, indicating the current buffer's process.
|
20
|
2682 */
|
|
2683 (proc))
|
0
|
2684 {
|
|
2685 Lisp_Object status;
|
|
2686
|
|
2687 if (STRINGP (proc))
|
|
2688 proc = Fget_process (proc);
|
|
2689 else
|
|
2690 proc = get_process (proc);
|
|
2691
|
|
2692 if (NILP (proc))
|
|
2693 return proc;
|
|
2694
|
|
2695 status = XPROCESS (proc)->status_symbol;
|
|
2696 if (network_connection_p (proc))
|
|
2697 {
|
|
2698 if (EQ (status, Qrun))
|
|
2699 status = Qopen;
|
|
2700 else if (EQ (status, Qexit))
|
|
2701 status = Qclosed;
|
|
2702 }
|
|
2703 return (status);
|
|
2704 }
|
|
2705
|
20
|
2706 DEFUN ("process-exit-status", Fprocess_exit_status, 1, 1, 0, /*
|
0
|
2707 Return the exit status of PROCESS or the signal number that killed it.
|
|
2708 If PROCESS has not yet exited or died, return 0.
|
20
|
2709 */
|
|
2710 (proc))
|
0
|
2711 {
|
|
2712 CHECK_PROCESS (proc);
|
|
2713 return (make_int (XPROCESS (proc)->exit_code));
|
|
2714 }
|
|
2715
|
|
2716
|
|
2717 #ifdef SIGNALS_VIA_CHARACTERS
|
|
2718 /* Get signal character to send to process if SIGNALS_VIA_CHARACTERS */
|
|
2719
|
|
2720 static int
|
|
2721 process_signal_char (int tty_fd, int signo)
|
|
2722 {
|
|
2723 /* If it's not a tty, pray that these default values work */
|
|
2724 if (!isatty(tty_fd)) {
|
|
2725 #define CNTL(ch) (037 & (ch))
|
|
2726 switch (signo)
|
|
2727 {
|
|
2728 case SIGINT: return CNTL('C');
|
|
2729 case SIGQUIT: return CNTL('\\');
|
|
2730 #ifdef SIGTSTP
|
|
2731 case SIGTSTP: return CNTL('Z');
|
|
2732 #endif
|
|
2733 }
|
|
2734 }
|
|
2735
|
|
2736 #ifdef HAVE_TERMIOS
|
|
2737 /* TERMIOS is the latest and bestest, and seems most likely to work.
|
|
2738 If the system has it, use it. */
|
|
2739 {
|
|
2740 struct termios t;
|
|
2741 tcgetattr (tty_fd, &t);
|
|
2742 switch (signo)
|
|
2743 {
|
|
2744 case SIGINT: return t.c_cc[VINTR];
|
|
2745 case SIGQUIT: return t.c_cc[VQUIT];
|
|
2746 # if defined (VSWTCH) && !defined (PREFER_VSUSP)
|
|
2747 case SIGTSTP: return t.c_cc[VSWTCH];
|
|
2748 # else
|
|
2749 case SIGTSTP: return t.c_cc[VSUSP];
|
|
2750 # endif
|
|
2751 }
|
|
2752 }
|
|
2753
|
|
2754 # elif defined (TIOCGLTC) && defined (TIOCGETC) /* not HAVE_TERMIOS */
|
|
2755 {
|
|
2756 /* On Berkeley descendants, the following IOCTL's retrieve the
|
|
2757 current control characters. */
|
|
2758 struct tchars c;
|
|
2759 struct ltchars lc;
|
|
2760 switch (signo)
|
|
2761 {
|
|
2762 case SIGINT: ioctl (tty_fd, TIOCGETC, &c); return c.t_intrc;
|
|
2763 case SIGQUIT: ioctl (tty_fd, TIOCGETC, &c); return c.t_quitc;
|
|
2764 # ifdef SIGTSTP
|
|
2765 case SIGTSTP: ioctl (tty_fd, TIOCGLTC, &lc); return lc.t_suspc;
|
|
2766 # endif /* SIGTSTP */
|
|
2767 }
|
|
2768 }
|
|
2769
|
|
2770 # elif defined (TCGETA) /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
|
|
2771 {
|
|
2772 /* On SYSV descendants, the TCGETA ioctl retrieves the current
|
|
2773 control characters. */
|
|
2774 struct termio t;
|
|
2775 ioctl (tty_fd, TCGETA, &t);
|
|
2776 switch (signo) {
|
|
2777 case SIGINT: return t.c_cc[VINTR];
|
|
2778 case SIGQUIT: return t.c_cc[VQUIT];
|
|
2779 # ifdef SIGTSTP
|
|
2780 case SIGTSTP: return t.c_cc[VSWTCH];
|
|
2781 # endif /* SIGTSTP */
|
|
2782 }
|
|
2783 }
|
|
2784 # else /* ! defined (TCGETA) */
|
|
2785 #error ERROR! Using SIGNALS_VIA_CHARACTERS, but not (TIOCGLTC && TIOCGETC) || TCGETA
|
|
2786 /* If your system configuration files define SIGNALS_VIA_CHARACTERS,
|
|
2787 you'd better be using one of the alternatives above! */
|
|
2788 # endif /* ! defined (TCGETA) */
|
|
2789 return '\0';
|
|
2790 }
|
|
2791 #endif /* SIGNALS_VIA_CHARACTERS */
|
|
2792
|
|
2793
|
|
2794 /* send a signal number SIGNO to PROCESS.
|
|
2795 CURRENT_GROUP means send to the process group that currently owns
|
|
2796 the terminal being used to communicate with PROCESS.
|
|
2797 This is used for various commands in shell mode.
|
|
2798 If NOMSG is zero, insert signal-announcements into process's buffers
|
|
2799 right away.
|
|
2800
|
|
2801 If we can, we try to signal PROCESS by sending control characters
|
|
2802 down the pty. This allows us to signal inferiors who have changed
|
|
2803 their uid, for which killpg would return an EPERM error. */
|
|
2804
|
|
2805 static void
|
|
2806 process_send_signal (Lisp_Object process0, int signo,
|
|
2807 int current_group, int nomsg)
|
|
2808 {
|
|
2809 /* This function can GC */
|
|
2810 Lisp_Object proc = get_process (process0);
|
|
2811 struct Lisp_Process *p = XPROCESS (proc);
|
|
2812 int gid;
|
|
2813 int no_pgrp = 0;
|
|
2814
|
|
2815 if (network_connection_p (proc))
|
|
2816 error ("Network connection %s is not a subprocess",
|
70
|
2817 XSTRING_DATA (p->name));
|
0
|
2818 if (p->infd < 0)
|
|
2819 error ("Process %s is not active",
|
70
|
2820 XSTRING_DATA (p->name));
|
0
|
2821
|
|
2822 if (!p->pty_flag)
|
|
2823 current_group = 0;
|
|
2824
|
|
2825 /* If we are using pgrps, get a pgrp number and make it negative. */
|
|
2826 if (current_group)
|
|
2827 {
|
|
2828 #ifdef SIGNALS_VIA_CHARACTERS
|
|
2829 /* If possible, send signals to the entire pgrp
|
|
2830 by sending an input character to it. */
|
|
2831 {
|
|
2832 char sigchar = process_signal_char(p->subtty, signo);
|
|
2833 if (sigchar) {
|
|
2834 send_process (proc, Qnil, (Bufbyte *) &sigchar, 0, 1);
|
|
2835 return;
|
|
2836 }
|
|
2837 }
|
|
2838 #endif /* ! defined (SIGNALS_VIA_CHARACTERS) */
|
|
2839
|
|
2840 #ifdef TIOCGPGRP
|
|
2841 /* Get the pgrp using the tty itself, if we have that.
|
|
2842 Otherwise, use the pty to get the pgrp.
|
|
2843 On pfa systems, saka@pfu.fujitsu.co.JP writes:
|
|
2844 "TIOCGPGRP symbol defined in sys/ioctl.h at E50.
|
|
2845 But, TIOCGPGRP does not work on E50 ;-P works fine on E60"
|
|
2846 His patch indicates that if TIOCGPGRP returns an error, then
|
|
2847 we should just assume that p->pid is also the process group id. */
|
|
2848 {
|
|
2849 int err;
|
|
2850
|
|
2851 err = ioctl ( (p->subtty != -1 ? p->subtty : p->infd), TIOCGPGRP, &gid);
|
|
2852
|
|
2853 #ifdef pfa
|
|
2854 if (err == -1)
|
|
2855 gid = - XINT (p->pid);
|
|
2856 #endif /* ! defined (pfa) */
|
|
2857 }
|
|
2858 if (gid == -1)
|
|
2859 no_pgrp = 1;
|
|
2860 else
|
|
2861 gid = - gid;
|
|
2862 #else /* ! defined (TIOCGPGRP ) */
|
|
2863 /* Can't select pgrps on this system, so we know that
|
|
2864 the child itself heads the pgrp. */
|
|
2865 gid = - XINT (p->pid);
|
|
2866 #endif /* ! defined (TIOCGPGRP ) */
|
|
2867 }
|
|
2868 else
|
|
2869 gid = - XINT (p->pid);
|
|
2870
|
|
2871 switch (signo)
|
|
2872 {
|
|
2873 #ifdef SIGCONT
|
|
2874 case SIGCONT:
|
|
2875 p->status_symbol = Qrun;
|
|
2876 p->exit_code = 0;
|
|
2877 p->tick++;
|
|
2878 process_tick++;
|
|
2879 if (!nomsg)
|
|
2880 status_notify ();
|
|
2881 break;
|
|
2882 #endif /* ! defined (SIGCONT) */
|
|
2883 case SIGINT:
|
|
2884 #ifdef VMS
|
|
2885 send_process (proc, Qnil, (Bufbyte *) "\003", 0,
|
|
2886 1); /* ^C */
|
|
2887 goto whoosh;
|
|
2888 #endif
|
|
2889 case SIGQUIT:
|
|
2890 #ifdef VMS
|
|
2891 send_process (proc, Qnil, (Bufbyte *) "\031", 0,
|
|
2892 1); /* ^Y */
|
|
2893 goto whoosh;
|
|
2894 #endif
|
|
2895 case SIGKILL:
|
|
2896 #ifdef VMS
|
|
2897 sys$forcex (&(XINT (p->pid)), 0, 1);
|
|
2898 whoosh:
|
|
2899 #endif
|
|
2900 flush_pending_output (p->infd);
|
|
2901 break;
|
|
2902 }
|
|
2903
|
|
2904 /* If we don't have process groups, send the signal to the immediate
|
|
2905 subprocess. That isn't really right, but it's better than any
|
|
2906 obvious alternative. */
|
|
2907 if (no_pgrp)
|
|
2908 {
|
|
2909 kill (XINT (p->pid), signo);
|
|
2910 return;
|
|
2911 }
|
|
2912
|
|
2913 /* gid may be a pid, or minus a pgrp's number */
|
|
2914 #ifdef TIOCSIGSEND
|
|
2915 if (current_group)
|
|
2916 ioctl (p->infd, TIOCSIGSEND, signo);
|
|
2917 else
|
|
2918 {
|
|
2919 gid = - XINT (p->pid);
|
|
2920 kill (gid, signo);
|
|
2921 }
|
|
2922 #else /* ! defined (TIOCSIGSEND) */
|
|
2923 EMACS_KILLPG (-gid, signo);
|
|
2924 #endif /* ! defined (TIOCSIGSEND) */
|
|
2925 }
|
|
2926
|
20
|
2927 DEFUN ("interrupt-process", Finterrupt_process, 0, 2, 0, /*
|
0
|
2928 Interrupt process PROCESS. May be process or name of one.
|
|
2929 Nil or no arg means current buffer's process.
|
|
2930 Second arg CURRENT-GROUP non-nil means send signal to
|
|
2931 the current process-group of the process's controlling terminal
|
|
2932 rather than to the process's own process group.
|
|
2933 If the process is a shell, this means interrupt current subjob
|
|
2934 rather than the shell.
|
20
|
2935 */
|
|
2936 (process, current_group))
|
0
|
2937 {
|
|
2938 /* This function can GC */
|
|
2939 process_send_signal (process, SIGINT, !NILP (current_group), 0);
|
|
2940 return process;
|
|
2941 }
|
|
2942
|
20
|
2943 DEFUN ("kill-process", Fkill_process, 0, 2, 0, /*
|
0
|
2944 Kill process PROCESS. May be process or name of one.
|
|
2945 See function `interrupt-process' for more details on usage.
|
20
|
2946 */
|
|
2947 (process, current_group))
|
0
|
2948 {
|
|
2949 /* This function can GC */
|
|
2950 process_send_signal (process, SIGKILL, !NILP (current_group),
|
|
2951 0);
|
|
2952 return process;
|
|
2953 }
|
|
2954
|
20
|
2955 DEFUN ("quit-process", Fquit_process, 0, 2, 0, /*
|
0
|
2956 Send QUIT signal to process PROCESS. May be process or name of one.
|
|
2957 See function `interrupt-process' for more details on usage.
|
20
|
2958 */
|
|
2959 (process, current_group))
|
0
|
2960 {
|
|
2961 /* This function can GC */
|
|
2962 process_send_signal (process, SIGQUIT, !NILP (current_group),
|
|
2963 0);
|
|
2964 return process;
|
|
2965 }
|
|
2966
|
20
|
2967 DEFUN ("stop-process", Fstop_process, 0, 2, 0, /*
|
0
|
2968 Stop process PROCESS. May be process or name of one.
|
|
2969 See function `interrupt-process' for more details on usage.
|
20
|
2970 */
|
|
2971 (process, current_group))
|
0
|
2972 {
|
|
2973 /* This function can GC */
|
|
2974 #ifndef SIGTSTP
|
|
2975 error ("no SIGTSTP support");
|
|
2976 #else
|
|
2977 process_send_signal (process, SIGTSTP, !NILP (current_group),
|
|
2978 0);
|
|
2979 #endif
|
|
2980 return process;
|
|
2981 }
|
|
2982
|
20
|
2983 DEFUN ("continue-process", Fcontinue_process, 0, 2, 0, /*
|
0
|
2984 Continue process PROCESS. May be process or name of one.
|
|
2985 See function `interrupt-process' for more details on usage.
|
20
|
2986 */
|
|
2987 (process, current_group))
|
0
|
2988 {
|
|
2989 /* This function can GC */
|
|
2990 #ifdef SIGCONT
|
|
2991 process_send_signal (process, SIGCONT, !NILP (current_group),
|
|
2992 0);
|
|
2993 #else
|
|
2994 error ("no SIGCONT support");
|
|
2995 #endif
|
|
2996 return process;
|
|
2997 }
|
|
2998
|
20
|
2999 DEFUN ("signal-process", Fsignal_process, 2, 2,
|
|
3000 "nProcess number: \nnSignal code: ", /*
|
0
|
3001 Send the process with process id PID the signal with code SIGCODE.
|
|
3002 PID must be an integer. The process need not be a child of this Emacs.
|
|
3003 SIGCODE may be an integer, or a symbol whose name is a signal name.
|
20
|
3004 */
|
|
3005 (pid, sigcode))
|
0
|
3006 {
|
|
3007 CHECK_INT (pid);
|
|
3008
|
|
3009 #define handle_signal(NAME, VALUE) \
|
|
3010 else if (!strcmp ((CONST char *) name, NAME)) \
|
|
3011 XSETINT (sigcode, VALUE)
|
|
3012
|
|
3013 if (INTP (sigcode))
|
|
3014 ;
|
|
3015 else
|
|
3016 {
|
|
3017 Bufbyte *name;
|
|
3018
|
|
3019 CHECK_SYMBOL (sigcode);
|
|
3020 name = string_data (XSYMBOL (sigcode)->name);
|
|
3021
|
|
3022 if (0)
|
|
3023 ;
|
|
3024 #ifdef SIGHUP
|
|
3025 handle_signal ("SIGHUP", SIGHUP);
|
|
3026 #endif
|
|
3027 #ifdef SIGINT
|
|
3028 handle_signal ("SIGINT", SIGINT);
|
|
3029 #endif
|
|
3030 #ifdef SIGQUIT
|
|
3031 handle_signal ("SIGQUIT", SIGQUIT);
|
|
3032 #endif
|
|
3033 #ifdef SIGILL
|
|
3034 handle_signal ("SIGILL", SIGILL);
|
|
3035 #endif
|
|
3036 #ifdef SIGABRT
|
|
3037 handle_signal ("SIGABRT", SIGABRT);
|
|
3038 #endif
|
|
3039 #ifdef SIGEMT
|
|
3040 handle_signal ("SIGEMT", SIGEMT);
|
|
3041 #endif
|
|
3042 #ifdef SIGKILL
|
|
3043 handle_signal ("SIGKILL", SIGKILL);
|
|
3044 #endif
|
|
3045 #ifdef SIGFPE
|
|
3046 handle_signal ("SIGFPE", SIGFPE);
|
|
3047 #endif
|
|
3048 #ifdef SIGBUS
|
|
3049 handle_signal ("SIGBUS", SIGBUS);
|
|
3050 #endif
|
|
3051 #ifdef SIGSEGV
|
|
3052 handle_signal ("SIGSEGV", SIGSEGV);
|
|
3053 #endif
|
|
3054 #ifdef SIGSYS
|
|
3055 handle_signal ("SIGSYS", SIGSYS);
|
|
3056 #endif
|
|
3057 #ifdef SIGPIPE
|
|
3058 handle_signal ("SIGPIPE", SIGPIPE);
|
|
3059 #endif
|
|
3060 #ifdef SIGALRM
|
|
3061 handle_signal ("SIGALRM", SIGALRM);
|
|
3062 #endif
|
|
3063 #ifdef SIGTERM
|
|
3064 handle_signal ("SIGTERM", SIGTERM);
|
|
3065 #endif
|
|
3066 #ifdef SIGURG
|
|
3067 handle_signal ("SIGURG", SIGURG);
|
|
3068 #endif
|
|
3069 #ifdef SIGSTOP
|
|
3070 handle_signal ("SIGSTOP", SIGSTOP);
|
|
3071 #endif
|
|
3072 #ifdef SIGTSTP
|
|
3073 handle_signal ("SIGTSTP", SIGTSTP);
|
|
3074 #endif
|
|
3075 #ifdef SIGCONT
|
|
3076 handle_signal ("SIGCONT", SIGCONT);
|
|
3077 #endif
|
|
3078 #ifdef SIGCHLD
|
|
3079 handle_signal ("SIGCHLD", SIGCHLD);
|
|
3080 #endif
|
|
3081 #ifdef SIGTTIN
|
|
3082 handle_signal ("SIGTTIN", SIGTTIN);
|
|
3083 #endif
|
|
3084 #ifdef SIGTTOU
|
|
3085 handle_signal ("SIGTTOU", SIGTTOU);
|
|
3086 #endif
|
|
3087 #ifdef SIGIO
|
|
3088 handle_signal ("SIGIO", SIGIO);
|
|
3089 #endif
|
|
3090 #ifdef SIGXCPU
|
|
3091 handle_signal ("SIGXCPU", SIGXCPU);
|
|
3092 #endif
|
|
3093 #ifdef SIGXFSZ
|
|
3094 handle_signal ("SIGXFSZ", SIGXFSZ);
|
|
3095 #endif
|
|
3096 #ifdef SIGVTALRM
|
|
3097 handle_signal ("SIGVTALRM", SIGVTALRM);
|
|
3098 #endif
|
|
3099 #ifdef SIGPROF
|
|
3100 handle_signal ("SIGPROF", SIGPROF);
|
|
3101 #endif
|
|
3102 #ifdef SIGWINCH
|
|
3103 handle_signal ("SIGWINCH", SIGWINCH);
|
|
3104 #endif
|
|
3105 #ifdef SIGINFO
|
|
3106 handle_signal ("SIGINFO", SIGINFO);
|
|
3107 #endif
|
|
3108 #ifdef SIGUSR1
|
|
3109 handle_signal ("SIGUSR1", SIGUSR1);
|
|
3110 #endif
|
|
3111 #ifdef SIGUSR2
|
|
3112 handle_signal ("SIGUSR2", SIGUSR2);
|
|
3113 #endif
|
|
3114 else
|
|
3115 error ("Undefined signal name %s", name);
|
|
3116 }
|
|
3117
|
|
3118 #undef handle_signal
|
|
3119
|
|
3120 return make_int (kill (XINT (pid), XINT (sigcode)));
|
|
3121 }
|
|
3122
|
20
|
3123 DEFUN ("process-send-eof", Fprocess_send_eof, 0, 1, 0, /*
|
0
|
3124 Make PROCESS see end-of-file in its input.
|
|
3125 PROCESS may be a process, a buffer, the name of a process or buffer, or
|
|
3126 nil, indicating the current buffer's process.
|
|
3127 If PROCESS is a network connection, or is a process communicating
|
|
3128 through a pipe (as opposed to a pty), then you cannot send any more
|
|
3129 text to PROCESS after you call this function.
|
20
|
3130 */
|
|
3131 (process))
|
0
|
3132 {
|
|
3133 /* This function can GC */
|
|
3134 Lisp_Object proc;
|
|
3135
|
|
3136 proc = get_process (process);
|
|
3137
|
|
3138 /* Make sure the process is really alive. */
|
|
3139 if (! EQ (XPROCESS (proc)->status_symbol, Qrun))
|
16
|
3140 error ("Process %s not running", XSTRING_DATA (XPROCESS (proc)->name));
|
0
|
3141
|
|
3142 #ifdef VMS
|
|
3143 send_process (proc, Qnil, (Bufbyte *) "\032", 0, 1); /* ^Z */
|
|
3144 #else
|
|
3145 if (XPROCESS (proc)->pty_flag)
|
|
3146 {
|
|
3147 /* #### get_eof_char simply doesn't return the correct character
|
|
3148 here. Maybe it is needed to determine the right eof
|
|
3149 character in init_process_fds but here it simply screws
|
|
3150 things up. */
|
|
3151 #if 0
|
|
3152 Bufbyte eof_char = get_eof_char (XPROCESS (proc));
|
|
3153 send_process (proc, Qnil, &eof_char, 0, 1);
|
|
3154 #else
|
|
3155 send_process (proc, Qnil, (CONST Bufbyte *) "\004", 0, 1);
|
|
3156 #endif
|
|
3157 }
|
|
3158 else
|
|
3159 {
|
|
3160 close (XPROCESS (proc)->outfd);
|
|
3161 XPROCESS (proc)->outfd = open (NULL_DEVICE, O_WRONLY, 0);
|
|
3162 }
|
|
3163 #endif /* !VMS */
|
|
3164 return process;
|
|
3165 }
|
|
3166
|
|
3167
|
|
3168 /************************************************************************/
|
|
3169 /* deleting a process */
|
|
3170 /************************************************************************/
|
|
3171
|
|
3172 void
|
|
3173 deactivate_process (Lisp_Object proc)
|
|
3174 {
|
|
3175 int inchannel, outchannel;
|
|
3176 struct Lisp_Process *p = XPROCESS (proc);
|
|
3177 SIGTYPE (*old_sigpipe) (int) = 0;
|
|
3178
|
|
3179 inchannel = p->infd;
|
|
3180 outchannel = p->outfd;
|
|
3181
|
|
3182 /* closing the outstream could result in SIGPIPE, so ignore it. */
|
|
3183 old_sigpipe =
|
|
3184 (SIGTYPE (*) (int)) signal (SIGPIPE, SIG_IGN);
|
|
3185 if (!NILP (p->instream))
|
|
3186 Lstream_close (XLSTREAM (p->instream));
|
|
3187 if (!NILP (p->outstream))
|
|
3188 Lstream_close (XLSTREAM (p->outstream));
|
|
3189 signal (SIGPIPE, old_sigpipe);
|
|
3190
|
|
3191 if (inchannel >= 0)
|
|
3192 {
|
|
3193 /* Beware SIGCHLD hereabouts. */
|
|
3194 flush_pending_output (inchannel);
|
|
3195 close_descriptor_pair (inchannel, outchannel);
|
|
3196 if (!NILP (p->pid))
|
|
3197 {
|
|
3198 /* It's possible that we got as far in the process-creation
|
|
3199 process as creating the descriptors but didn't get so
|
|
3200 far as selecting the process for input. In this
|
|
3201 case, p->pid is nil: p->pid is set at the same time that
|
|
3202 the process is selected for input. */
|
|
3203 #ifdef VMS
|
|
3204 {
|
|
3205 VMS_PROC_STUFF *get_vms_process_pointer (), *vs;
|
|
3206 if (outchannel >= 0)
|
|
3207 sys$dassgn (outchannel);
|
|
3208 vs = get_vms_process_pointer (XINT (p->pid));
|
|
3209 if (vs)
|
|
3210 give_back_vms_process_stuff (vs);
|
|
3211 }
|
|
3212 #endif /* VMS */
|
|
3213 /* Must call this before setting the file descriptors to 0 */
|
|
3214 event_stream_unselect_process (p);
|
|
3215 }
|
|
3216
|
|
3217 p->infd = -1;
|
|
3218 p->outfd = -1;
|
|
3219 descriptor_to_process[inchannel] = Qnil;
|
|
3220 }
|
|
3221 }
|
|
3222
|
|
3223 static void
|
|
3224 remove_process (Lisp_Object proc)
|
|
3225 {
|
|
3226 Vprocess_list = delq_no_quit (proc, Vprocess_list);
|
|
3227 Fset_marker (XPROCESS (proc)->mark, Qnil, Qnil);
|
|
3228
|
|
3229 deactivate_process (proc);
|
|
3230 }
|
|
3231
|
20
|
3232 DEFUN ("delete-process", Fdelete_process, 1, 1, 0, /*
|
0
|
3233 Delete PROCESS: kill it and forget about it immediately.
|
|
3234 PROCESS may be a process or the name of one, or a buffer name.
|
20
|
3235 */
|
|
3236 (proc))
|
0
|
3237 {
|
|
3238 /* This function can GC */
|
|
3239 struct Lisp_Process *p;
|
|
3240 proc = get_process (proc);
|
|
3241 p = XPROCESS (proc);
|
|
3242 if (network_connection_p (proc))
|
|
3243 {
|
|
3244 p->status_symbol = Qexit;
|
|
3245 p->exit_code = 0;
|
|
3246 p->core_dumped = 0;
|
|
3247 p->tick++;
|
|
3248 process_tick++;
|
|
3249 }
|
|
3250 else if (p->infd >= 0)
|
|
3251 {
|
|
3252 Fkill_process (proc, Qnil);
|
|
3253 /* Do this now, since remove_process will make sigchld_handler do nothing. */
|
|
3254 p->status_symbol = Qsignal;
|
|
3255 p->exit_code = SIGKILL;
|
|
3256 p->core_dumped = 0;
|
|
3257 p->tick++;
|
|
3258 process_tick++;
|
|
3259 status_notify ();
|
|
3260 }
|
|
3261 remove_process (proc);
|
|
3262 return Qnil;
|
|
3263 }
|
|
3264
|
|
3265 /* Kill all processes associated with `buffer'.
|
|
3266 If `buffer' is nil, kill all processes */
|
|
3267
|
|
3268 void
|
|
3269 kill_buffer_processes (Lisp_Object buffer)
|
|
3270 {
|
|
3271 Lisp_Object tail;
|
|
3272
|
|
3273 for (tail = Vprocess_list; GC_CONSP (tail);
|
|
3274 tail = XCDR (tail))
|
|
3275 {
|
|
3276 Lisp_Object proc = XCAR (tail);
|
|
3277 if (GC_PROCESSP (proc)
|
|
3278 && (GC_NILP (buffer) || GC_EQ (XPROCESS (proc)->buffer, buffer)))
|
|
3279 {
|
|
3280 if (network_connection_p (proc))
|
|
3281 Fdelete_process (proc);
|
|
3282 else if (XPROCESS (proc)->infd >= 0)
|
|
3283 process_send_signal (proc, SIGHUP, 0, 1);
|
|
3284 }
|
|
3285 }
|
|
3286 }
|
|
3287
|
|
3288 #if 0 /* Unused */
|
|
3289 int
|
|
3290 count_active_processes (void)
|
|
3291 {
|
|
3292 Lisp_Object tail;
|
|
3293 int count = 0;
|
|
3294
|
|
3295 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
|
|
3296 {
|
|
3297 Lisp_Object status = XPROCESS (XCAR (tail))->status_symbol;
|
|
3298 if ((EQ (status, Qrun) || EQ (status, Qstop)))
|
|
3299 count++;
|
|
3300 }
|
|
3301
|
|
3302 return count;
|
|
3303 }
|
|
3304 #endif /* Unused */
|
|
3305
|
20
|
3306 DEFUN ("process-kill-without-query", Fprocess_kill_without_query, 1, 2, 0, /*
|
0
|
3307 Say no query needed if PROCESS is running when Emacs is exited.
|
|
3308 Optional second argument if non-nil says to require a query.
|
|
3309 Value is t if a query was formerly required.
|
20
|
3310 */
|
|
3311 (proc, require_query_p))
|
0
|
3312 {
|
|
3313 int tem;
|
|
3314
|
|
3315 CHECK_PROCESS (proc);
|
|
3316 tem = XPROCESS (proc)->kill_without_query;
|
|
3317 XPROCESS (proc)->kill_without_query = NILP (require_query_p);
|
|
3318
|
|
3319 return (tem ? Qnil : Qt);
|
|
3320 }
|
|
3321
|
20
|
3322 DEFUN ("process-kill-without-query-p", Fprocess_kill_without_query_p, 1, 1, 0, /*
|
0
|
3323 Whether PROC will be killed without query if running when emacs is exited.
|
20
|
3324 */
|
|
3325 (proc))
|
0
|
3326 {
|
|
3327 CHECK_PROCESS (proc);
|
|
3328 return (XPROCESS (proc)->kill_without_query ? Qt : Qnil);
|
|
3329 }
|
|
3330
|
|
3331
|
|
3332 /* This is not named init_process in order to avoid a conflict with NS 3.3 */
|
|
3333 void
|
|
3334 init_xemacs_process (void)
|
|
3335 {
|
|
3336 int i;
|
|
3337
|
|
3338 #ifdef SIGCHLD
|
|
3339 # ifndef CANNOT_DUMP
|
|
3340 if (! noninteractive || initialized)
|
|
3341 # endif
|
|
3342 signal (SIGCHLD, sigchld_handler);
|
|
3343 #endif /* SIGCHLD */
|
|
3344
|
|
3345 Vprocess_list = Qnil;
|
|
3346 for (i = 0; i < MAXDESC; i++)
|
|
3347 {
|
|
3348 descriptor_to_process[i] = Qnil;
|
|
3349 proc_buffered_char[i] = -1;
|
|
3350 }
|
|
3351 }
|
149
|
3352
|
0
|
3353 #if 0
|
|
3354
|
149
|
3355 xxDEFUN ("process-connection", Fprocess_connection, 0, 1, 0, /*
|
0
|
3356 Return the connection type of `PROCESS'. This can be nil (pipe),
|
|
3357 t or pty (pty) or stream (socket connection).
|
149
|
3358 */
|
|
3359 (process))
|
0
|
3360 {
|
|
3361 return XPROCESS (process)->type;
|
|
3362 }
|
|
3363
|
|
3364 #endif /* 0 */
|
|
3365
|
|
3366 void
|
|
3367 syms_of_process (void)
|
|
3368 {
|
|
3369 defsymbol (&Qprocessp, "processp");
|
|
3370 defsymbol (&Qrun, "run");
|
|
3371 defsymbol (&Qstop, "stop");
|
|
3372 defsymbol (&Qsignal, "signal");
|
|
3373 /* Qexit is already defined by syms_of_eval
|
|
3374 * defsymbol (&Qexit, "exit");
|
|
3375 */
|
|
3376 defsymbol (&Qopen, "open");
|
|
3377 defsymbol (&Qclosed, "closed");
|
|
3378
|
20
|
3379 DEFSUBR (Fprocessp);
|
|
3380 DEFSUBR (Fget_process);
|
|
3381 DEFSUBR (Fget_buffer_process);
|
|
3382 DEFSUBR (Fdelete_process);
|
|
3383 DEFSUBR (Fprocess_status);
|
|
3384 DEFSUBR (Fprocess_exit_status);
|
|
3385 DEFSUBR (Fprocess_id);
|
|
3386 DEFSUBR (Fprocess_name);
|
|
3387 DEFSUBR (Fprocess_tty_name);
|
|
3388 DEFSUBR (Fprocess_command);
|
|
3389 DEFSUBR (Fset_process_buffer);
|
|
3390 DEFSUBR (Fprocess_buffer);
|
|
3391 DEFSUBR (Fprocess_mark);
|
|
3392 DEFSUBR (Fset_process_filter);
|
|
3393 DEFSUBR (Fprocess_filter);
|
|
3394 DEFSUBR (Fset_process_window_size);
|
|
3395 DEFSUBR (Fset_process_sentinel);
|
|
3396 DEFSUBR (Fprocess_sentinel);
|
|
3397 DEFSUBR (Fprocess_kill_without_query);
|
|
3398 DEFSUBR (Fprocess_kill_without_query_p);
|
|
3399 DEFSUBR (Fprocess_list);
|
|
3400 DEFSUBR (Fstart_process_internal);
|
0
|
3401 #ifdef HAVE_SOCKETS
|
20
|
3402 DEFSUBR (Fopen_network_stream_internal);
|
0
|
3403 #endif /* HAVE_SOCKETS */
|
20
|
3404 DEFSUBR (Fprocess_send_region);
|
|
3405 DEFSUBR (Fprocess_send_string);
|
|
3406 DEFSUBR (Finterrupt_process);
|
|
3407 DEFSUBR (Fkill_process);
|
|
3408 DEFSUBR (Fquit_process);
|
|
3409 DEFSUBR (Fstop_process);
|
|
3410 DEFSUBR (Fcontinue_process);
|
|
3411 DEFSUBR (Fprocess_send_eof);
|
|
3412 DEFSUBR (Fsignal_process);
|
|
3413 /* DEFSUBR (Fprocess_connection); */
|
70
|
3414 #ifdef MULE
|
|
3415 DEFSUBR (Fprocess_input_coding_system);
|
|
3416 DEFSUBR (Fprocess_output_coding_system);
|
|
3417 DEFSUBR (Fset_process_input_coding_system);
|
|
3418 DEFSUBR (Fset_process_output_coding_system);
|
120
|
3419 DEFSUBR (Fprocess_coding_system);
|
|
3420 DEFSUBR (Fset_process_coding_system);
|
70
|
3421 #endif /* MULE */
|
0
|
3422 }
|
|
3423
|
|
3424 void
|
|
3425 vars_of_process (void)
|
|
3426 {
|
|
3427 Fprovide (intern ("subprocesses"));
|
|
3428 #ifdef HAVE_SOCKETS
|
|
3429 Fprovide (intern ("network-streams"));
|
|
3430 #endif
|
|
3431 staticpro (&Vprocess_list);
|
|
3432
|
|
3433 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes /*
|
|
3434 *Non-nil means delete processes immediately when they exit.
|
|
3435 nil means don't delete them until `list-processes' is run.
|
|
3436 */ );
|
|
3437
|
|
3438 delete_exited_processes = 1;
|
|
3439
|
|
3440 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type /*
|
|
3441 Control type of device used to communicate with subprocesses.
|
|
3442 Values are nil to use a pipe, or t or `pty' to use a pty.
|
|
3443 The value has no effect if the system has no ptys or if all ptys are busy:
|
|
3444 then a pipe is used in any case.
|
|
3445 The value takes effect when `start-process' is called.
|
|
3446 */ );
|
|
3447 Vprocess_connection_type = Qt;
|
153
|
3448
|
|
3449 #ifdef PROCESS_IO_BLOCKING
|
|
3450 DEFVAR_LISP ("network-stream-blocking-port-list", &network_stream_blocking_port_list /*
|
|
3451 List of port numbers or port names to set a blocking I/O mode with connection.
|
|
3452 Nil value means to set a default(non-blocking) I/O mode.
|
|
3453 The value takes effect when `open-network-stream-internal' is called.
|
|
3454 */ );
|
|
3455 network_stream_blocking_port_list = Qnil;
|
|
3456 #endif /* PROCESS_IO_BLOCKING */
|
0
|
3457 }
|
|
3458
|
|
3459 #endif /* not NO_SUBPROCESSES */
|