0
|
1 /* Asynchronous subprocess control for XEmacs.
|
|
2 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 1995
|
|
3 Free Software Foundation, Inc.
|
|
4 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
5 Copyright (C) 1995, 1996 Ben Wing.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Mule 2.0, FSF 19.30. */
|
|
25
|
|
26 /* This file has been Mule-ized except for `start-process-internal'
|
|
27 and `open-network-stream-internal'. */
|
|
28
|
|
29 #include <config.h>
|
|
30
|
|
31 #if !defined (NO_SUBPROCESSES)
|
|
32
|
|
33 /* The entire file is within this conditional */
|
|
34
|
|
35 #include "lisp.h"
|
|
36
|
|
37 #include "buffer.h"
|
|
38 #include "commands.h"
|
|
39 #include "events.h"
|
|
40 #include "frame.h"
|
|
41 #include "insdel.h"
|
|
42 #include "lstream.h"
|
|
43 #include "opaque.h"
|
|
44 #include "process.h"
|
|
45 #include "sysdep.h"
|
|
46 #include "window.h"
|
70
|
47 #ifdef MULE
|
|
48 #include "mule-coding.h"
|
|
49 #endif
|
0
|
50
|
|
51 #include <setjmp.h>
|
|
52 #include "sysfile.h"
|
|
53 #include "sysproc.h"
|
|
54 #include "systime.h"
|
|
55 #include "syssignal.h" /* Always include before systty.h */
|
|
56
|
|
57 #include "systty.h"
|
|
58 #include "syswait.h"
|
|
59
|
|
60 /* a process object is a network connection when its pid field a cons
|
|
61 (name of name of port we are connected to . foreign host name) */
|
|
62
|
|
63 /* Valid values of process->status_symbol */
|
|
64 Lisp_Object Qrun, Qstop; /* Qexit from eval.c, Qsignal from data.c. */
|
|
65 /* Qrun => Qopen, Qexit => Qclosed for "network connection" processes */
|
|
66 Lisp_Object Qopen, Qclosed;
|
|
67
|
|
68 /* t means use pty, nil means use a pipe,
|
|
69 maybe other values to come. */
|
|
70 static Lisp_Object Vprocess_connection_type;
|
|
71
|
153
|
72 #ifdef PROCESS_IO_BLOCKING
|
|
73 /* List of port numbers or port names to set a blocking I/O mode.
|
|
74 Nil means set a non-blocking I/O mode [default]. */
|
|
75 static Lisp_Object network_stream_blocking_port_list;
|
|
76 #endif /* PROCESS_IO_BLOCKING */
|
|
77
|
0
|
78 /* FSFmacs says:
|
|
79
|
|
80 These next two vars are non-static since sysdep.c uses them in the
|
|
81 emulation of `select'. */
|
|
82 /* Number of events of change of status of a process. */
|
|
83 static volatile int process_tick;
|
|
84
|
|
85 /* Number of events for which the user or sentinel has been notified. */
|
|
86 static int update_tick;
|
|
87
|
|
88 /* Nonzero means delete a process right away if it exits. */
|
|
89 int delete_exited_processes;
|
|
90
|
|
91 /* Indexed by descriptor, gives the process (if any) for that descriptor */
|
|
92 Lisp_Object descriptor_to_process[MAXDESC];
|
|
93
|
|
94 /* List of process objects. */
|
|
95 Lisp_Object Vprocess_list;
|
|
96
|
|
97 Lisp_Object Qprocessp;
|
|
98
|
|
99 /* Buffered-ahead input char from process, indexed by channel.
|
|
100 -1 means empty (no char is buffered).
|
|
101 Used on sys V where the only way to tell if there is any
|
|
102 output from the process is to read at least one char.
|
|
103 Always -1 on systems that support FIONREAD. */
|
|
104
|
|
105 /* FSFmacs says:
|
|
106 Don't make static; need to access externally. */
|
|
107 static int proc_buffered_char[MAXDESC];
|
|
108
|
|
109 #ifdef HAVE_PTYS
|
|
110 /* The file name of the pty opened by allocate_pty. */
|
|
111
|
|
112 static char pty_name[24];
|
|
113 #endif
|
|
114
|
|
115
|
|
116 /************************************************************************/
|
|
117 /* the process Lisp object */
|
|
118 /************************************************************************/
|
|
119
|
|
120 /*
|
|
121 * Structure records pertinent information about open channels.
|
|
122 * There is one channel associated with each process.
|
|
123 */
|
|
124
|
|
125 struct Lisp_Process
|
|
126 {
|
|
127 struct lcrecord_header header;
|
|
128 /* Name of this process */
|
|
129 Lisp_Object name;
|
|
130 /* List of command arguments that this process was run with */
|
|
131 Lisp_Object command;
|
|
132 /* (funcall FILTER PROC STRING) (if FILTER is non-nil)
|
|
133 to dispose of a bunch of chars from the process all at once */
|
|
134 Lisp_Object filter;
|
|
135 /* (funcall SENTINEL PROCESS) when process state changes */
|
|
136 Lisp_Object sentinel;
|
|
137 /* Buffer that output is going to */
|
|
138 Lisp_Object buffer;
|
|
139 /* Marker set to end of last buffer-inserted output from this process */
|
|
140 Lisp_Object mark;
|
|
141 /* Lisp_Int of subprocess' PID, or a cons of
|
|
142 service/host if this is really a network connection */
|
|
143 Lisp_Object pid;
|
|
144 /* Non-0 if this is really a ToolTalk channel. */
|
|
145 int connected_via_filedesc_p;
|
|
146 #if 0 /* FSFmacs */
|
|
147 /* Perhaps it's cleaner this way, but FSFmacs
|
|
148 provides no way of retrieving this value, so I'll
|
|
149 leave this info with PID. */
|
|
150 /* Non-nil if this is really a child process */
|
|
151 Lisp_Object childp;
|
|
152 #endif
|
|
153
|
|
154 /* Symbol indicating status of process.
|
|
155 This may be a symbol: run, stop, exit, signal */
|
|
156 Lisp_Object status_symbol;
|
|
157
|
|
158
|
|
159 /* Exit code if process has terminated,
|
|
160 signal which stopped/interrupted process
|
|
161 or 0 if process is running */
|
|
162 int exit_code;
|
|
163 /* Number of this process */
|
|
164 /* Non-false if process has exited and "dumped core" on its way down */
|
|
165 char core_dumped;
|
|
166 /* Descriptor by which we read from this process. -1 for dead process */
|
|
167 int infd;
|
|
168 /* Descriptor by which we write to this process. -1 for dead process */
|
|
169 int outfd;
|
|
170 /* Descriptor for the tty which this process is using.
|
|
171 -1 if we didn't record it (on some systems, there's no need). */
|
|
172 int subtty;
|
|
173 /* Name of subprocess terminal. */
|
|
174 Lisp_Object tty_name;
|
|
175 /* Non-false if communicating through a pty. */
|
|
176 char pty_flag;
|
|
177 /* This next field is only actually used #ifdef ENERGIZE */
|
|
178 /* if this flag is not NIL, then filter will do the read on the
|
|
179 channel, rather than having a call to make_string.
|
|
180 This only works if the filter is a subr. */
|
|
181 char filter_does_read;
|
|
182 /* Non-nil means kill silently if Emacs is exited. */
|
|
183 char kill_without_query;
|
|
184 char selected;
|
|
185 /* Event-count of last event in which this process changed status. */
|
|
186 volatile int tick;
|
|
187 /* Event-count of last such event reported. */
|
|
188 int update_tick;
|
|
189 /* streams used in input and output */
|
|
190 Lisp_Object instream;
|
|
191 Lisp_Object outstream;
|
|
192 /* The actual filedesc stream used for output; may be different
|
|
193 than OUTSTREAM under Mule */
|
|
194 Lisp_Object filedesc_stream;
|
|
195 };
|
|
196
|
|
197 static Lisp_Object mark_process (Lisp_Object, void (*) (Lisp_Object));
|
|
198 static void print_process (Lisp_Object, Lisp_Object, int);
|
|
199 static void finalize_process (void *, int);
|
|
200 DEFINE_LRECORD_IMPLEMENTATION ("process", process,
|
|
201 mark_process, print_process, finalize_process,
|
|
202 0, 0, struct Lisp_Process);
|
|
203
|
|
204 static Lisp_Object
|
|
205 mark_process (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
206 {
|
|
207 struct Lisp_Process *proc = XPROCESS (obj);
|
|
208 ((markobj) (proc->name));
|
|
209 ((markobj) (proc->command));
|
|
210 ((markobj) (proc->filter));
|
|
211 ((markobj) (proc->sentinel));
|
|
212 ((markobj) (proc->buffer));
|
|
213 ((markobj) (proc->mark));
|
|
214 ((markobj) (proc->pid));
|
|
215 ((markobj) (proc->tty_name));
|
|
216 ((markobj) (proc->instream));
|
|
217 ((markobj) (proc->outstream));
|
|
218 ((markobj) (proc->filedesc_stream));
|
173
|
219 return proc->status_symbol;
|
0
|
220 }
|
|
221
|
|
222 static void
|
|
223 print_process (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
224 {
|
|
225 struct Lisp_Process *proc = XPROCESS (obj);
|
185
|
226
|
0
|
227 if (print_readably)
|
|
228 error ("printing unreadable object #<process %s>",
|
16
|
229 XSTRING_DATA (proc->name));
|
185
|
230
|
0
|
231 if (!escapeflag)
|
|
232 {
|
|
233 print_internal (proc->name, printcharfun, 0);
|
|
234 }
|
|
235 else
|
|
236 {
|
|
237 int netp = network_connection_p (obj);
|
|
238 write_c_string (((netp) ? GETTEXT ("#<network connection ") :
|
|
239 GETTEXT ("#<process ")), printcharfun);
|
|
240 print_internal (proc->name, printcharfun, 1);
|
|
241 write_c_string (((netp) ? " " : " pid "), printcharfun);
|
|
242 print_internal (proc->pid, printcharfun, 1);
|
|
243 write_c_string (" state:", printcharfun);
|
|
244 print_internal (proc->status_symbol, printcharfun, 1);
|
|
245 write_c_string (">", printcharfun);
|
|
246 }
|
|
247 }
|
|
248
|
|
249 #ifdef HAVE_WINDOW_SYSTEM
|
|
250 extern void debug_process_finalization (struct Lisp_Process *p);
|
|
251 #endif /* HAVE_WINDOW_SYSTEM */
|
|
252
|
|
253 static void
|
|
254 finalize_process (void *header, int for_disksave)
|
|
255 {
|
|
256 if (for_disksave) return; /* hmm, what would this do anyway? */
|
|
257 /* #### this probably needs to be tied into the tty event loop */
|
|
258 /* #### when there is one */
|
|
259 #ifdef HAVE_WINDOW_SYSTEM
|
|
260 {
|
|
261 struct Lisp_Process *p = (struct Lisp_Process *) header;
|
|
262 debug_process_finalization (p);
|
|
263 }
|
|
264 #endif /* HAVE_WINDOW_SYSTEM */
|
|
265 }
|
|
266
|
|
267
|
|
268 /************************************************************************/
|
|
269 /* basic process accessors */
|
|
270 /************************************************************************/
|
|
271
|
|
272 static SIGTYPE
|
|
273 close_safely_handler (int signo)
|
|
274 {
|
|
275 EMACS_REESTABLISH_SIGNAL (signo, close_safely_handler);
|
|
276 SIGRETURN;
|
|
277 }
|
|
278
|
|
279 static void
|
|
280 close_safely (int fd)
|
|
281 {
|
|
282 stop_interrupts ();
|
|
283 signal (SIGALRM, close_safely_handler);
|
|
284 alarm (1);
|
|
285 close (fd);
|
|
286 alarm (0);
|
|
287 start_interrupts ();
|
|
288 }
|
|
289
|
|
290 static void
|
|
291 close_descriptor_pair (int in, int out)
|
|
292 {
|
|
293 if (in >= 0)
|
|
294 close (in);
|
|
295 if (out != in && out >= 0)
|
|
296 close (out);
|
|
297 }
|
|
298
|
|
299 /* Close all descriptors currently in use for communication
|
|
300 with subprocess. This is used in a newly-forked subprocess
|
|
301 to get rid of irrelevant descriptors. */
|
|
302
|
|
303 void
|
|
304 close_process_descs (void)
|
|
305 {
|
|
306 #ifndef WINDOWSNT
|
|
307 int i;
|
|
308 for (i = 0; i < MAXDESC; i++)
|
|
309 {
|
|
310 Lisp_Object process;
|
|
311 process = descriptor_to_process[i];
|
|
312 if (!NILP (process))
|
|
313 {
|
|
314 close_descriptor_pair (XPROCESS (process)->infd,
|
|
315 XPROCESS (process)->outfd);
|
|
316 }
|
|
317 }
|
|
318 #endif
|
|
319 }
|
|
320
|
|
321 void
|
|
322 get_process_file_descriptors (struct Lisp_Process *p, int *infd,
|
|
323 int *outfd)
|
|
324 {
|
|
325 if (! p) abort ();
|
|
326 /* the cast of MAXDESC is needed for some versions of Linux */
|
|
327 assert (p->infd >= -1 && p->infd < ((int) (MAXDESC)));
|
|
328 assert (p->outfd >= -1 && p->outfd < ((int) (MAXDESC)));
|
|
329 *infd = p->infd;
|
|
330 *outfd = p->outfd;
|
|
331 }
|
|
332
|
|
333 struct Lisp_Process *
|
|
334 get_process_from_input_descriptor (int infd)
|
|
335 {
|
|
336 Lisp_Object proc;
|
|
337
|
|
338 if ((infd < 0) || (infd >= ((int) (MAXDESC)))) abort ();
|
|
339 proc = descriptor_to_process[infd];
|
|
340 if (NILP (proc))
|
|
341 return 0;
|
|
342 else
|
|
343 return XPROCESS (proc);
|
|
344 }
|
|
345
|
|
346 int
|
|
347 get_process_selected_p (struct Lisp_Process *p)
|
|
348 {
|
|
349 return p->selected;
|
|
350 }
|
|
351
|
|
352 void
|
|
353 set_process_selected_p (struct Lisp_Process *p, int selected_p)
|
|
354 {
|
|
355 p->selected = !!selected_p;
|
|
356 }
|
|
357
|
|
358 #ifdef HAVE_SOCKETS
|
|
359 int
|
|
360 network_connection_p (Lisp_Object process)
|
|
361 {
|
173
|
362 return GC_CONSP (XPROCESS (process)->pid);
|
0
|
363 }
|
|
364 #endif
|
|
365
|
|
366 int
|
|
367 connected_via_filedesc_p (struct Lisp_Process *p)
|
|
368 {
|
|
369 return p->connected_via_filedesc_p;
|
|
370 }
|
|
371
|
20
|
372 DEFUN ("processp", Fprocessp, 1, 1, 0, /*
|
0
|
373 Return t if OBJECT is a process.
|
20
|
374 */
|
|
375 (obj))
|
0
|
376 {
|
173
|
377 return PROCESSP (obj) ? Qt : Qnil;
|
0
|
378 }
|
|
379
|
20
|
380 DEFUN ("process-list", Fprocess_list, 0, 0, 0, /*
|
0
|
381 Return a list of all processes.
|
20
|
382 */
|
|
383 ())
|
0
|
384 {
|
|
385 return Fcopy_sequence (Vprocess_list);
|
|
386 }
|
|
387
|
20
|
388 DEFUN ("get-process", Fget_process, 1, 1, 0, /*
|
0
|
389 Return the process named NAME, or nil if there is none.
|
20
|
390 */
|
|
391 (name))
|
0
|
392 {
|
|
393 Lisp_Object tail;
|
|
394
|
|
395 if (GC_PROCESSP (name))
|
173
|
396 return name;
|
0
|
397
|
|
398 if (!gc_in_progress)
|
|
399 /* this only gets called during GC when emacs is going away as a result
|
|
400 of a signal or crash. */
|
|
401 CHECK_STRING (name);
|
|
402
|
|
403 for (tail = Vprocess_list; GC_CONSP (tail); tail = XCDR (tail))
|
|
404 {
|
|
405 Lisp_Object proc = XCAR (tail);
|
|
406 QUIT;
|
195
|
407 if (internal_equal (name, XPROCESS (proc)->name, 0))
|
173
|
408 return XCAR (tail);
|
0
|
409 }
|
|
410 return Qnil;
|
|
411 }
|
|
412
|
20
|
413 DEFUN ("get-buffer-process", Fget_buffer_process, 1, 1, 0, /*
|
0
|
414 Return the (or, a) process associated with BUFFER.
|
|
415 BUFFER may be a buffer or the name of one.
|
20
|
416 */
|
|
417 (name))
|
0
|
418 {
|
|
419 Lisp_Object buf, tail, proc;
|
|
420
|
|
421 if (GC_NILP (name)) return Qnil;
|
|
422 buf = Fget_buffer (name);
|
|
423 if (GC_NILP (buf)) return Qnil;
|
|
424
|
|
425 #ifdef ENERGIZE
|
|
426 {
|
|
427 Lisp_Object p = energize_get_buffer_process (buf);
|
|
428 if (!GC_NILP (p)) return p;
|
|
429 }
|
|
430 #endif
|
|
431
|
|
432 for (tail = Vprocess_list; GC_CONSP (tail); tail = XCDR (tail))
|
|
433 {
|
|
434 /* jwz: do not quit here - it isn't necessary, as there is no way for
|
|
435 Vprocess_list to get circular or overwhelmingly long, and this
|
|
436 function is called from layout_mode_element under redisplay. */
|
|
437 /* QUIT; */
|
|
438 proc = XCAR (tail);
|
|
439 if (GC_PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf))
|
|
440 return proc;
|
|
441 }
|
|
442 return Qnil;
|
|
443 }
|
|
444
|
|
445 /* This is how commands for the user decode process arguments. It
|
|
446 accepts a process, a process name, a buffer, a buffer name, or nil.
|
|
447 Buffers denote the first process in the buffer, and nil denotes the
|
|
448 current buffer. */
|
|
449
|
|
450 static Lisp_Object
|
|
451 get_process (Lisp_Object name)
|
|
452 {
|
136
|
453 Lisp_Object proc, obj;
|
0
|
454
|
|
455 #ifdef I18N3
|
|
456 /* #### Look more closely into translating process names. */
|
|
457 #endif
|
|
458
|
|
459 /* This may be called during a GC from process_send_signal() from
|
|
460 kill_buffer_processes() if emacs decides to abort(). */
|
|
461 if (GC_PROCESSP (name))
|
|
462 return name;
|
|
463
|
136
|
464 if (GC_STRINGP (name))
|
|
465 {
|
|
466 obj = Fget_process (name);
|
|
467 if (GC_NILP (obj))
|
|
468 obj = Fget_buffer (name);
|
|
469 if (GC_NILP (obj))
|
|
470 error ("Process %s does not exist", XSTRING_DATA (name));
|
|
471 }
|
|
472 else if (GC_NILP (name))
|
|
473 obj = Fcurrent_buffer ();
|
|
474 else
|
|
475 obj = name;
|
|
476
|
|
477 /* Now obj should be either a buffer object or a process object.
|
|
478 */
|
|
479 if (GC_BUFFERP (obj))
|
|
480 {
|
|
481 proc = Fget_buffer_process (obj);
|
|
482 if (GC_NILP (proc))
|
|
483 error ("Buffer %s has no process", XSTRING_DATA (XBUFFER(obj)->name));
|
|
484 }
|
0
|
485 else
|
|
486 {
|
136
|
487 /* fsf: CHECK_PROCESS (obj, 0); */
|
|
488 proc = obj;
|
0
|
489 }
|
136
|
490 return proc;
|
0
|
491 }
|
|
492
|
20
|
493 DEFUN ("process-id", Fprocess_id, 1, 1, 0, /*
|
0
|
494 Return the process id of PROCESS.
|
|
495 This is the pid of the Unix process which PROCESS uses or talks to.
|
|
496 For a network connection, this value is a cons of
|
|
497 (foreign-network-port . foreign-host-name).
|
20
|
498 */
|
|
499 (proc))
|
0
|
500 {
|
|
501 Lisp_Object pid;
|
|
502 CHECK_PROCESS (proc);
|
|
503
|
|
504 pid = XPROCESS (proc)->pid;
|
|
505 if (network_connection_p (proc))
|
173
|
506 /* return Qnil; */
|
|
507 return Fcons (Fcar (pid), Fcdr (pid));
|
0
|
508 else
|
173
|
509 return pid;
|
0
|
510 }
|
|
511
|
20
|
512 DEFUN ("process-name", Fprocess_name, 1, 1, 0, /*
|
0
|
513 Return the name of PROCESS, as a string.
|
|
514 This is the name of the program invoked in PROCESS,
|
|
515 possibly modified to make it unique among process names.
|
20
|
516 */
|
|
517 (proc))
|
0
|
518 {
|
|
519 CHECK_PROCESS (proc);
|
|
520 return XPROCESS (proc)->name;
|
|
521 }
|
|
522
|
20
|
523 DEFUN ("process-command", Fprocess_command, 1, 1, 0, /*
|
0
|
524 Return the command that was executed to start PROCESS.
|
|
525 This is a list of strings, the first string being the program executed
|
|
526 and the rest of the strings being the arguments given to it.
|
20
|
527 */
|
|
528 (proc))
|
0
|
529 {
|
|
530 CHECK_PROCESS (proc);
|
|
531 return XPROCESS (proc)->command;
|
|
532 }
|
|
533
|
|
534
|
|
535 /************************************************************************/
|
|
536 /* creating a process */
|
|
537 /************************************************************************/
|
|
538
|
|
539 static Lisp_Object
|
|
540 make_process_internal (Lisp_Object name)
|
|
541 {
|
|
542 Lisp_Object val, name1;
|
|
543 int i;
|
185
|
544 struct Lisp_Process *p =
|
|
545 alloc_lcrecord_type (struct Lisp_Process, lrecord_process);
|
0
|
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);
|
185
|
553 if (NILP (tem))
|
0
|
554 break;
|
|
555 sprintf (suffix, "<%d>", i);
|
|
556 name1 = concat2 (name, build_string (suffix));
|
|
557 }
|
|
558 name = name1;
|
|
559 p->name = name;
|
|
560
|
|
561 p->command = Qnil;
|
|
562 p->filter = Qnil;
|
|
563 p->sentinel = Qnil;
|
|
564 p->buffer = Qnil;
|
|
565 p->mark = Fmake_marker ();
|
|
566 p->pid = Qnil;
|
|
567 p->status_symbol = Qrun;
|
|
568 p->connected_via_filedesc_p = 0;
|
|
569 p->exit_code = 0;
|
|
570 p->core_dumped = 0;
|
|
571 p->infd = -1;
|
|
572 p->outfd = -1;
|
|
573 p->subtty = -1;
|
|
574 p->tty_name = Qnil;
|
|
575 p->pty_flag = 0;
|
|
576 p->filter_does_read = 0;
|
|
577 p->kill_without_query = 0;
|
|
578 p->selected = 0;
|
|
579 p->tick = 0;
|
|
580 p->update_tick = 0;
|
|
581 p->instream = Qnil;
|
|
582 p->outstream = Qnil;
|
|
583
|
|
584 XSETPROCESS (val, p);
|
|
585
|
|
586 Vprocess_list = Fcons (val, Vprocess_list);
|
173
|
587 return val;
|
0
|
588 }
|
|
589
|
|
590 #ifdef HAVE_PTYS
|
|
591
|
|
592 /* Open an available pty, returning a file descriptor.
|
|
593 Return -1 on failure.
|
|
594 The file name of the terminal corresponding to the pty
|
|
595 is left in the variable pty_name. */
|
|
596
|
|
597 static int
|
|
598 allocate_pty (void)
|
|
599 {
|
|
600 struct stat stb;
|
|
601 int c, i;
|
|
602 int fd;
|
|
603
|
|
604 /* Some systems name their pseudoterminals so that there are gaps in
|
|
605 the usual sequence - for example, on HP9000/S700 systems, there
|
|
606 are no pseudoterminals with names ending in 'f'. So we wait for
|
|
607 three failures in a row before deciding that we've reached the
|
|
608 end of the ptys. */
|
|
609 int failed_count = 0;
|
|
610
|
|
611 #ifdef PTY_ITERATION
|
|
612 PTY_ITERATION
|
|
613 #else
|
|
614 for (c = FIRST_PTY_LETTER; c <= 'z'; c++)
|
|
615 for (i = 0; i < 16; i++)
|
|
616 #endif
|
|
617 {
|
|
618 #ifdef PTY_NAME_SPRINTF
|
|
619 PTY_NAME_SPRINTF
|
|
620 #else
|
|
621 sprintf (pty_name, "/dev/pty%c%x", c, i);
|
|
622 #endif /* no PTY_NAME_SPRINTF */
|
|
623
|
|
624 #ifdef PTY_OPEN
|
|
625 PTY_OPEN;
|
|
626 #else /* no PTY_OPEN */
|
|
627 #ifdef IRIS
|
|
628 /* Unusual IRIS code */
|
|
629 *ptyv = open ("/dev/ptc", O_RDWR | O_NDELAY, 0);
|
|
630 if (fd < 0)
|
|
631 return -1;
|
|
632 if (fstat (fd, &stb) < 0)
|
|
633 return -1;
|
|
634 #else /* not IRIS */
|
|
635 if (stat (pty_name, &stb) < 0)
|
|
636 {
|
|
637 failed_count++;
|
|
638 if (failed_count >= 3)
|
|
639 return -1;
|
|
640 }
|
|
641 else
|
|
642 failed_count = 0;
|
|
643 #ifdef O_NONBLOCK
|
|
644 fd = open (pty_name, O_RDWR | O_NONBLOCK, 0);
|
|
645 #else
|
|
646 fd = open (pty_name, O_RDWR | O_NDELAY, 0);
|
|
647 #endif
|
|
648 #endif /* not IRIS */
|
|
649 #endif /* no PTY_OPEN */
|
|
650
|
|
651 if (fd >= 0)
|
|
652 {
|
|
653 /* check to make certain that both sides are available
|
|
654 this avoids a nasty yet stupid bug in rlogins */
|
|
655 #ifdef PTY_TTY_NAME_SPRINTF
|
|
656 PTY_TTY_NAME_SPRINTF
|
|
657 #else
|
|
658 sprintf (pty_name, "/dev/tty%c%x", c, i);
|
|
659 #endif /* no PTY_TTY_NAME_SPRINTF */
|
|
660 #ifndef UNIPLUS
|
|
661 if (access (pty_name, 6) != 0)
|
|
662 {
|
|
663 close (fd);
|
|
664 #if !defined(IRIS) && !defined(__sgi)
|
|
665 continue;
|
|
666 #else
|
|
667 return -1;
|
|
668 #endif /* IRIS */
|
|
669 }
|
|
670 #endif /* not UNIPLUS */
|
|
671 setup_pty (fd);
|
|
672 return fd;
|
|
673 }
|
|
674 }
|
|
675 return -1;
|
|
676 }
|
|
677 #endif /* HAVE_PTYS */
|
|
678
|
|
679 static int
|
|
680 create_bidirectional_pipe (int *inchannel, int *outchannel,
|
|
681 volatile int *forkin, volatile int *forkout)
|
|
682 {
|
|
683 int sv[2];
|
|
684
|
|
685 #ifdef SKTPAIR
|
|
686 if (socketpair (AF_UNIX, SOCK_STREAM, 0, sv) < 0)
|
|
687 return -1;
|
|
688 *outchannel = *inchannel = sv[0];
|
|
689 *forkout = *forkin = sv[1];
|
|
690 #else /* not SKTPAIR */
|
|
691 int temp;
|
|
692 temp = pipe (sv);
|
|
693 if (temp < 0) return -1;
|
|
694 *inchannel = sv[0];
|
|
695 *forkout = sv[1];
|
|
696 temp = pipe (sv);
|
|
697 if (temp < 0) return -1;
|
|
698 *outchannel = sv[1];
|
|
699 *forkin = sv[0];
|
|
700 #endif /* not SKTPAIR */
|
|
701 return 0;
|
|
702 }
|
|
703
|
|
704 #ifndef VMS /* VMS version of this function is in vmsproc.c. */
|
|
705
|
|
706 static Bufbyte
|
|
707 get_eof_char (struct Lisp_Process *p)
|
|
708 {
|
|
709 /* Figure out the eof character for the outfd of the given process.
|
185
|
710 * The following code is similar to that in process_send_signal, and
|
0
|
711 * should probably be merged with that code somehow. */
|
|
712
|
16
|
713 CONST Bufbyte ctrl_d = (Bufbyte) '\004';
|
185
|
714
|
16
|
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) */
|
185
|
752 /* Rather than complain, we'll just guess ^D, which is what
|
0
|
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
|
185
|
810 create_process (Lisp_Object process,
|
0
|
811 char **new_argv, CONST char *current_dir)
|
|
812 {
|
|
813 /* This function rewritten by wing@666.com. */
|
|
814
|
|
815 int pid, inchannel, outchannel;
|
|
816 /* Use volatile to protect variables from being clobbered by longjmp. */
|
|
817 volatile int forkin, forkout;
|
|
818 volatile int pty_flag = 0;
|
|
819 char **env;
|
|
820 struct Lisp_Process *p = XPROCESS (process);
|
|
821
|
|
822 env = environ;
|
|
823
|
|
824 inchannel = outchannel = forkin = forkout = -1;
|
|
825
|
|
826 #ifdef HAVE_PTYS
|
|
827 if (!NILP (Vprocess_connection_type))
|
|
828 {
|
|
829 /* find a new pty, open the master side, return the opened
|
|
830 file handle, and store the name of the corresponding slave
|
|
831 side in global variable pty_name. */
|
|
832 outchannel = inchannel = allocate_pty ();
|
|
833 }
|
|
834
|
|
835 if (inchannel >= 0)
|
|
836 {
|
|
837 /* You're "supposed" to now open the slave in the child.
|
|
838 On some systems, we can open it here; this allows for
|
|
839 better error checking. */
|
|
840 #ifndef USG
|
|
841 /* On USG systems it does not work to open the pty's tty here
|
|
842 and then close and reopen it in the child. */
|
|
843 #ifdef O_NOCTTY
|
|
844 /* Don't let this terminal become our controlling terminal
|
|
845 (in case we don't have one). */
|
|
846 forkout = forkin = open (pty_name, O_RDWR | O_NOCTTY, 0);
|
|
847 #else
|
|
848 forkout = forkin = open (pty_name, O_RDWR, 0);
|
|
849 #endif
|
|
850 if (forkin < 0)
|
|
851 goto io_failure;
|
|
852 #endif /* not USG */
|
|
853 p->pty_flag = pty_flag = 1;
|
|
854 }
|
|
855 else
|
|
856 #endif /* HAVE_PTYS */
|
|
857 if (create_bidirectional_pipe (&inchannel, &outchannel,
|
|
858 &forkin, &forkout) < 0)
|
|
859 goto io_failure;
|
|
860
|
|
861 #if 0
|
|
862 /* Replaced by close_process_descs */
|
|
863 set_exclusive_use (inchannel);
|
|
864 set_exclusive_use (outchannel);
|
|
865 #endif
|
|
866
|
|
867 set_descriptor_non_blocking (inchannel);
|
|
868
|
|
869 /* Record this as an active process, with its channels.
|
|
870 As a result, child_setup will close Emacs's side of the pipes. */
|
|
871 descriptor_to_process[inchannel] = process;
|
|
872 init_process_fds (p, inchannel, outchannel);
|
|
873 /* Record the tty descriptor used in the subprocess. */
|
|
874 p->subtty = forkin;
|
|
875 p->status_symbol = Qrun;
|
|
876 p->exit_code = 0;
|
|
877
|
|
878 {
|
|
879 /* child_setup must clobber environ on systems with true vfork.
|
|
880 Protect it from permanent change. */
|
|
881 char **save_environ = environ;
|
|
882
|
|
883 #ifdef EMACS_BTL
|
|
884 /* when performance monitoring is on, turn it off before the vfork(),
|
|
885 as the child has no handler for the signal -- when back in the
|
|
886 parent process, turn it back on if it was really on when you "turned
|
|
887 it off" */
|
|
888 int logging_on = cadillac_stop_logging (); /* #### rename me */
|
|
889 #endif
|
|
890
|
|
891 #ifndef WINDOWSNT
|
167
|
892 pid = fork ();
|
0
|
893 if (pid == 0)
|
|
894 #endif /* not WINDOWSNT */
|
|
895 {
|
|
896 /**** Now we're in the child process ****/
|
|
897 int xforkin = forkin;
|
|
898 int xforkout = forkout;
|
|
899
|
|
900 if (!pty_flag)
|
|
901 EMACS_SEPARATE_PROCESS_GROUP ();
|
|
902 #ifdef HAVE_PTYS
|
|
903 else
|
|
904 {
|
|
905 /* Disconnect the current controlling terminal, pursuant to
|
|
906 making the pty be the controlling terminal of the process.
|
|
907 Also put us in our own process group. */
|
|
908
|
|
909 disconnect_controlling_terminal ();
|
|
910
|
|
911 /* Open the pty connection and make the pty's terminal
|
|
912 our controlling terminal.
|
|
913
|
|
914 On systems with TIOCSCTTY, we just use it to set
|
|
915 the controlling terminal. On other systems, the
|
|
916 first TTY we open becomes the controlling terminal.
|
|
917 So, we end up with four possibilities:
|
|
918
|
|
919 (1) on USG and TIOCSCTTY systems, we open the pty
|
|
920 and use TIOCSCTTY.
|
|
921 (2) on other USG systems, we just open the pty.
|
|
922 (3) on non-USG systems with TIOCSCTTY, we
|
|
923 just use TIOCSCTTY. (On non-USG systems, we
|
|
924 already opened the pty in the parent process.)
|
|
925 (4) on non-USG systems without TIOCSCTTY, we
|
|
926 close the pty and reopen it.
|
|
927
|
|
928 This would be cleaner if we didn't open the pty
|
|
929 in the parent process, but doing it that way
|
|
930 makes it possible to trap error conditions.
|
|
931 It's harder to convey an error from the child
|
|
932 process, and I don't feel like messing with
|
|
933 this now. */
|
|
934
|
|
935 /* There was some weirdo, probably wrong,
|
|
936 conditionalization on RTU and UNIPLUS here.
|
|
937 I deleted it. So sue me. */
|
|
938
|
|
939 /* SunOS has TIOCSCTTY but the close/open method
|
|
940 also works. */
|
|
941
|
|
942 # if defined (USG) || !defined (TIOCSCTTY)
|
|
943 /* Now close the pty (if we had it open) and reopen it.
|
|
944 This makes the pty the controlling terminal of the
|
|
945 subprocess. */
|
|
946 /* I wonder if close (open (pty_name, ...)) would work? */
|
|
947 if (xforkin >= 0)
|
|
948 close (xforkin);
|
|
949 xforkout = xforkin = open (pty_name, O_RDWR, 0);
|
|
950 if (xforkin < 0)
|
|
951 {
|
|
952 write (1, "Couldn't open the pty terminal ", 31);
|
|
953 write (1, pty_name, strlen (pty_name));
|
|
954 write (1, "\n", 1);
|
|
955 _exit (1);
|
|
956 }
|
|
957 # endif /* USG or not TIOCSCTTY */
|
|
958
|
|
959 /* Miscellaneous setup required for some systems.
|
|
960 Must be done before using tc* functions on xforkin.
|
|
961 This guarantees that isatty(xforkin) is true. */
|
185
|
962
|
0
|
963 # ifdef SETUP_SLAVE_PTY
|
|
964 SETUP_SLAVE_PTY;
|
|
965 # endif /* SETUP_SLAVE_PTY */
|
185
|
966
|
0
|
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);
|
185
|
1025 #else /* not WINDOWSNT */
|
0
|
1026 child_setup (xforkin, xforkout, xforkout, new_argv, current_dir);
|
|
1027 #endif /* not WINDOWSNT */
|
|
1028 #endif /* not MSDOS */
|
|
1029 }
|
|
1030 #ifdef EMACS_BTL
|
|
1031 else if (logging_on)
|
|
1032 cadillac_start_logging (); /* #### rename me */
|
|
1033 #endif
|
|
1034
|
|
1035 environ = save_environ;
|
|
1036 }
|
|
1037
|
|
1038 if (pid < 0)
|
|
1039 {
|
|
1040 close_descriptor_pair (forkin, forkout);
|
167
|
1041 report_file_error ("Doing fork", Qnil);
|
0
|
1042 }
|
|
1043
|
|
1044 p->pid = make_int (pid);
|
120
|
1045 /* #### dmoore - why is this commented out, otherwise we leave
|
|
1046 subtty = forkin, but then we close forkin just below. */
|
0
|
1047 /* p->subtty = -1; */
|
|
1048
|
|
1049 #ifdef WINDOWSNT
|
|
1050 register_child (pid, inchannel);
|
|
1051 #endif /* WINDOWSNT */
|
|
1052
|
|
1053 /* If the subfork execv fails, and it exits,
|
|
1054 this close hangs. I don't know why.
|
|
1055 So have an interrupt jar it loose. */
|
|
1056 if (forkin >= 0)
|
|
1057 close_safely (forkin);
|
|
1058 if (forkin != forkout && forkout >= 0)
|
|
1059 close (forkout);
|
|
1060
|
|
1061 #ifdef HAVE_PTYS
|
|
1062 if (pty_flag)
|
|
1063 XPROCESS (process)->tty_name = build_string (pty_name);
|
|
1064 else
|
|
1065 #endif
|
|
1066 XPROCESS (process)->tty_name = Qnil;
|
|
1067
|
|
1068 /* Notice that SIGCHLD was not blocked. (This is not possible on
|
|
1069 some systems.) No biggie if SIGCHLD occurs right around the
|
|
1070 time that this call happens, because SIGCHLD() does not actually
|
|
1071 deselect the process (that doesn't occur until the next time
|
|
1072 we're waiting for an event, when status_notify() is called). */
|
|
1073 event_stream_select_process (XPROCESS (process));
|
|
1074
|
|
1075 return;
|
|
1076
|
|
1077 io_failure:
|
|
1078 {
|
|
1079 int temp = errno;
|
|
1080 close_descriptor_pair (forkin, forkout);
|
|
1081 close_descriptor_pair (inchannel, outchannel);
|
|
1082 errno = temp;
|
|
1083 report_file_error ("Opening pty or pipe", Qnil);
|
|
1084 }
|
|
1085 }
|
|
1086 #endif /* not VMS */
|
|
1087
|
|
1088 /* This function is the unwind_protect form for Fstart_process_internal. If
|
|
1089 PROC doesn't have its pid set, then we know someone has signalled
|
|
1090 an error and the process wasn't started successfully, so we should
|
|
1091 remove it from the process list. */
|
|
1092 static void remove_process (Lisp_Object proc);
|
|
1093 static Lisp_Object
|
|
1094 start_process_unwind (Lisp_Object proc)
|
|
1095 {
|
|
1096 /* Was PROC started successfully? */
|
|
1097 if (EQ (XPROCESS (proc)->pid, Qnil))
|
|
1098 remove_process (proc);
|
|
1099 return Qnil;
|
|
1100 }
|
|
1101
|
20
|
1102 DEFUN ("start-process-internal", Fstart_process_internal, 3, MANY, 0, /*
|
0
|
1103 Start a program in a subprocess. Return the process object for it.
|
|
1104 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS
|
|
1105 NAME is name for process. It is modified if necessary to make it unique.
|
|
1106 BUFFER is the buffer or (buffer-name) to associate with the process.
|
|
1107 Process output goes at end of that buffer, unless you specify
|
|
1108 an output stream or filter function to handle the output.
|
|
1109 BUFFER may be also nil, meaning that this process is not associated
|
|
1110 with any buffer
|
|
1111 Third arg is program file name. It is searched for as in the shell.
|
|
1112 Remaining arguments are strings to give program as arguments.
|
|
1113 INCODE and OUTCODE specify the coding-system objects used in input/output
|
|
1114 from/to the process.
|
20
|
1115 */
|
|
1116 (int nargs, Lisp_Object *args))
|
0
|
1117 {
|
120
|
1118 /* This function can call lisp */
|
0
|
1119 /* !!#### This function has not been Mule-ized */
|
|
1120 Lisp_Object buffer, name, program, proc, current_dir;
|
|
1121 Lisp_Object tem;
|
|
1122 int speccount = specpdl_depth ();
|
120
|
1123 struct gcpro gcpro1, gcpro2, gcpro3;
|
0
|
1124 #ifdef VMS
|
|
1125 char *new_argv;
|
|
1126 int len;
|
|
1127 #else
|
|
1128 char **new_argv;
|
|
1129 #endif
|
|
1130 int i;
|
|
1131
|
120
|
1132 name = args[0];
|
0
|
1133 buffer = args[1];
|
120
|
1134 program = args[2];
|
|
1135 current_dir = Qnil;
|
|
1136
|
|
1137 /* Protect against various file handlers doing GCs below. */
|
|
1138 GCPRO3 (buffer, program, current_dir);
|
|
1139
|
0
|
1140 if (!NILP (buffer))
|
|
1141 buffer = Fget_buffer_create (buffer);
|
|
1142
|
120
|
1143 CHECK_STRING (name);
|
|
1144 CHECK_STRING (program);
|
0
|
1145
|
|
1146 /* Make sure that the child will be able to chdir to the current
|
|
1147 buffer's current directory, or its unhandled equivalent. We
|
|
1148 can't just have the child check for an error when it does the
|
|
1149 chdir, since it's in a vfork.
|
|
1150
|
120
|
1151 Note: these assignments and calls are like this in order to insure
|
|
1152 "caller protects args" GC semantics. */
|
|
1153 current_dir = current_buffer->directory;
|
|
1154 current_dir = Funhandled_file_name_directory (current_dir);
|
|
1155 current_dir = expand_and_dir_to_file (current_dir, Qnil);
|
|
1156
|
0
|
1157 #if 0 /* This loser breaks ange-ftp */
|
120
|
1158 /* dmoore - if you re-enable this code, you have to gcprotect
|
|
1159 current_buffer through the above calls. */
|
|
1160 if (NILP (Ffile_accessible_directory_p (current_dir)))
|
|
1161 report_file_error ("Setting current directory",
|
|
1162 list1 (current_buffer->directory));
|
0
|
1163 #endif /* 0 */
|
|
1164
|
|
1165 #ifdef VMS
|
|
1166 /* Make a one member argv with all args concatenated
|
|
1167 together separated by a blank. */
|
16
|
1168 len = XSTRING_LENGTH (program) + 2;
|
0
|
1169 for (i = 3; i < nargs; i++)
|
|
1170 {
|
|
1171 tem = args[i];
|
|
1172 CHECK_STRING (tem);
|
16
|
1173 len += XSTRING_LENGTH (tem) + 1; /* count the blank */
|
0
|
1174 }
|
|
1175 new_argv = (char *) alloca (len);
|
16
|
1176 strcpy (new_argv, XSTRING_DATA (program));
|
0
|
1177 for (i = 3; i < nargs; i++)
|
|
1178 {
|
|
1179 tem = args[i];
|
|
1180 CHECK_STRING (tem);
|
|
1181 strcat (new_argv, " ");
|
16
|
1182 strcat (new_argv, XSTRING_DATA (tem));
|
0
|
1183 }
|
|
1184 /* Need to add code here to check for program existence on VMS */
|
|
1185
|
|
1186 #else /* not VMS */
|
|
1187 /* If program file name is not absolute, search our path for it */
|
82
|
1188 if (!IS_DIRECTORY_SEP (XSTRING_BYTE (program, 0))
|
16
|
1189 && !(XSTRING_LENGTH (program) > 1
|
82
|
1190 && IS_DEVICE_SEP (XSTRING_BYTE (program, 1))))
|
0
|
1191 {
|
120
|
1192 struct gcpro ngcpro1;
|
70
|
1193
|
0
|
1194 tem = Qnil;
|
120
|
1195 NGCPRO1 (tem);
|
0
|
1196 locate_file (Vexec_path, program, EXEC_SUFFIXES, &tem,
|
|
1197 X_OK);
|
|
1198 if (NILP (tem))
|
|
1199 report_file_error ("Searching for program", list1 (program));
|
120
|
1200 program = Fexpand_file_name (tem, Qnil);
|
|
1201 NUNGCPRO;
|
0
|
1202 }
|
|
1203 else
|
|
1204 {
|
|
1205 if (!NILP (Ffile_directory_p (program)))
|
|
1206 error ("Specified program for new process is a directory");
|
|
1207 }
|
|
1208
|
120
|
1209 /* Nothing below here GCs so our string pointers shouldn't move. */
|
185
|
1210 new_argv = alloca_array (char *, nargs - 1);
|
120
|
1211 new_argv[0] = (char *) XSTRING_DATA (program);
|
0
|
1212 for (i = 3; i < nargs; i++)
|
|
1213 {
|
|
1214 tem = args[i];
|
|
1215 CHECK_STRING (tem);
|
16
|
1216 new_argv[i - 2] = (char *) XSTRING_DATA (tem);
|
0
|
1217 }
|
|
1218 new_argv[i - 2] = 0;
|
|
1219
|
|
1220 #endif /* not VMS */
|
|
1221
|
|
1222 proc = make_process_internal (name);
|
|
1223
|
|
1224 XPROCESS (proc)->buffer = buffer;
|
|
1225 XPROCESS (proc)->command = Flist (nargs - 2,
|
|
1226 args + 2);
|
|
1227
|
|
1228 /* Make the process marker point into the process buffer (if any). */
|
|
1229 if (!NILP (buffer))
|
|
1230 Fset_marker (XPROCESS (proc)->mark,
|
|
1231 make_int (BUF_ZV (XBUFFER (buffer))), buffer);
|
|
1232
|
|
1233 /* If an error occurs and we can't start the process, we want to
|
|
1234 remove it from the process list. This means that each error
|
|
1235 check in create_process doesn't need to call remove_process
|
|
1236 itself; it's all taken care of here. */
|
|
1237 record_unwind_protect (start_process_unwind, proc);
|
|
1238
|
16
|
1239 create_process (proc, new_argv, (char *) XSTRING_DATA (current_dir));
|
0
|
1240
|
120
|
1241 UNGCPRO;
|
0
|
1242 return unbind_to (speccount, proc);
|
|
1243 }
|
|
1244
|
|
1245
|
|
1246 /* connect to an existing file descriptor. This is very similar to
|
|
1247 open-network-stream except that it assumes that the connection has
|
|
1248 already been initialized. It is currently used for ToolTalk
|
|
1249 communication. */
|
|
1250
|
|
1251 /* This function used to be visible on the Lisp level, but there is no
|
|
1252 real point in doing that. Here is the doc string:
|
|
1253
|
|
1254 "Connect to an existing file descriptor.\n\
|
|
1255 Returns a subprocess-object to represent the connection.\n\
|
|
1256 Input and output work as for subprocesses; `delete-process' closes it.\n\
|
|
1257 Args are NAME BUFFER INFD OUTFD.\n\
|
|
1258 NAME is name for process. It is modified if necessary to make it unique.\n\
|
|
1259 BUFFER is the buffer (or buffer-name) to associate with the process.\n\
|
|
1260 Process output goes at end of that buffer, unless you specify\n\
|
|
1261 an output stream or filter function to handle the output.\n\
|
|
1262 BUFFER may be also nil, meaning that this process is not associated\n\
|
|
1263 with any buffer\n\
|
|
1264 INFD and OUTFD specify the file descriptors to use for input and\n\
|
|
1265 output, respectively."
|
|
1266 */
|
|
1267
|
|
1268 Lisp_Object
|
|
1269 connect_to_file_descriptor (Lisp_Object name, Lisp_Object buffer,
|
|
1270 Lisp_Object infd, Lisp_Object outfd)
|
|
1271 {
|
|
1272 /* This function can GC */
|
|
1273 Lisp_Object proc;
|
|
1274 int inch;
|
|
1275
|
|
1276 CHECK_STRING (name);
|
|
1277 CHECK_INT (infd);
|
|
1278 CHECK_INT (outfd);
|
|
1279
|
|
1280 inch = XINT (infd);
|
|
1281 if (!NILP (descriptor_to_process[inch]))
|
|
1282 error ("There is already a process connected to fd %d", inch);
|
|
1283 if (!NILP (buffer))
|
|
1284 buffer = Fget_buffer_create (buffer);
|
|
1285 proc = make_process_internal (name);
|
|
1286
|
|
1287 descriptor_to_process[inch] = proc;
|
|
1288
|
|
1289 XPROCESS (proc)->pid = Fcons (infd, name);
|
|
1290 XPROCESS (proc)->buffer = buffer;
|
|
1291 init_process_fds (XPROCESS (proc), inch, XINT (outfd));
|
|
1292 XPROCESS (proc)->connected_via_filedesc_p = 1;
|
|
1293
|
|
1294 event_stream_select_process (XPROCESS (proc));
|
|
1295
|
|
1296 return proc;
|
|
1297 }
|
|
1298
|
|
1299
|
|
1300 #ifdef HAVE_SOCKETS
|
|
1301
|
|
1302 static int
|
|
1303 get_internet_address (Lisp_Object host, struct sockaddr_in *address,
|
|
1304 Error_behavior errb)
|
|
1305 {
|
173
|
1306 struct hostent *host_info_ptr = NULL;
|
108
|
1307 #ifdef TRY_AGAIN
|
|
1308 int count = 0;
|
|
1309 #endif
|
0
|
1310
|
|
1311 #ifndef HAVE_TERM
|
|
1312 memset (address, 0, sizeof (*address));
|
|
1313
|
|
1314 while (1)
|
|
1315 {
|
|
1316 #ifdef TRY_AGAIN
|
108
|
1317 if (count++ > 10) break;
|
0
|
1318 h_errno = 0;
|
|
1319 #endif
|
|
1320 /* Some systems can't handle SIGIO/SIGALARM in gethostbyname. */
|
|
1321 slow_down_interrupts ();
|
16
|
1322 host_info_ptr = gethostbyname ((char *) XSTRING_DATA (host));
|
0
|
1323 speed_up_interrupts ();
|
|
1324 #ifdef TRY_AGAIN
|
|
1325 if (! (host_info_ptr == 0 && h_errno == TRY_AGAIN))
|
|
1326 #endif
|
|
1327 break;
|
|
1328 Fsleep_for (make_int (1));
|
|
1329 }
|
|
1330 if (host_info_ptr)
|
|
1331 {
|
|
1332 address->sin_family = host_info_ptr->h_addrtype;
|
|
1333 memcpy (&address->sin_addr, host_info_ptr->h_addr, host_info_ptr->h_length);
|
|
1334 }
|
|
1335 else
|
|
1336 {
|
|
1337 IN_ADDR numeric_addr;
|
|
1338 /* Attempt to interpret host as numeric inet address */
|
16
|
1339 numeric_addr = inet_addr ((char *) XSTRING_DATA (host));
|
0
|
1340 if (NUMERIC_ADDR_ERROR)
|
|
1341 {
|
|
1342 maybe_error (Qprocess, errb,
|
16
|
1343 "Unknown host \"%s\"", XSTRING_DATA (host));
|
0
|
1344 return 0;
|
|
1345 }
|
|
1346
|
|
1347 /* There was some broken code here that called strlen() here
|
|
1348 on (char *) &numeric_addr and even sometimes accessed
|
|
1349 uninitialized data. */
|
|
1350 address->sin_family = AF_INET;
|
|
1351 * (IN_ADDR *) &address->sin_addr = numeric_addr;
|
|
1352 }
|
|
1353
|
|
1354 return 1;
|
|
1355 }
|
|
1356
|
|
1357 /* open a TCP network connection to a given HOST/SERVICE. Treated
|
|
1358 exactly like a normal process when reading and writing. Only
|
|
1359 differences are in status display and process deletion. A network
|
|
1360 connection has no PID; you cannot signal it. All you can do is
|
|
1361 deactivate and close it via delete-process */
|
|
1362
|
20
|
1363 DEFUN ("open-network-stream-internal", Fopen_network_stream_internal, 4, 4, 0, /*
|
0
|
1364 Open a TCP connection for a service to a host.
|
|
1365 Returns a subprocess-object to represent the connection.
|
|
1366 Input and output work as for subprocesses; `delete-process' closes it.
|
70
|
1367
|
0
|
1368 NAME is name for process. It is modified if necessary to make it unique.
|
|
1369 BUFFER is the buffer (or buffer-name) to associate with the process.
|
|
1370 Process output goes at end of that buffer, unless you specify
|
|
1371 an output stream or filter function to handle the output.
|
70
|
1372 BUFFER may also be nil, meaning that this process is not associated
|
|
1373 with any buffer.
|
0
|
1374 Third arg is name of the host to connect to, or its IP address.
|
|
1375 Fourth arg SERVICE is name of the service desired, or an integer
|
|
1376 specifying a port number to connect to.
|
20
|
1377 */
|
|
1378 (name, buffer, host, service))
|
0
|
1379 {
|
|
1380 /* !!#### This function has not been Mule-ized */
|
|
1381 /* This function can GC */
|
|
1382 Lisp_Object proc;
|
|
1383 struct sockaddr_in address;
|
|
1384 int s, outch, inch;
|
169
|
1385 volatile int port;
|
0
|
1386 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
16
|
1387 volatile int retry = 0;
|
0
|
1388 int retval;
|
|
1389
|
|
1390 GCPRO4 (name, buffer, host, service);
|
|
1391 CHECK_STRING (name);
|
|
1392 CHECK_STRING (host);
|
|
1393 if (INTP (service))
|
|
1394 port = htons ((unsigned short) XINT (service));
|
|
1395 else
|
|
1396 {
|
|
1397 struct servent *svc_info;
|
|
1398 CHECK_STRING (service);
|
16
|
1399 svc_info = getservbyname ((char *) XSTRING_DATA (service), "tcp");
|
0
|
1400 if (svc_info == 0)
|
|
1401 #ifdef WIN32
|
|
1402 error ("Unknown service \"%s\" (%d)",
|
16
|
1403 XSTRING_DATA (service), WSAGetLastError ());
|
0
|
1404 #else
|
16
|
1405 error ("Unknown service \"%s\"", XSTRING_DATA (service));
|
0
|
1406 #endif
|
|
1407 port = svc_info->s_port;
|
|
1408 }
|
|
1409
|
|
1410 get_internet_address (host, &address, ERROR_ME);
|
|
1411 address.sin_port = port;
|
|
1412
|
|
1413 s = socket (address.sin_family, SOCK_STREAM, 0);
|
185
|
1414 if (s < 0)
|
0
|
1415 report_file_error ("error creating socket", list1 (name));
|
|
1416
|
|
1417 /* Turn off interrupts here -- see comments below. There used to
|
|
1418 be code which called bind_polling_period() to slow the polling
|
|
1419 period down rather than turn it off, but that seems rather
|
|
1420 bogus to me. Best thing here is to use a non-blocking connect
|
|
1421 or something, to check for QUIT. */
|
|
1422
|
|
1423 /* Comments that are not quite valid: */
|
|
1424
|
|
1425 /* Kernel bugs (on Ultrix at least) cause lossage (not just EINTR)
|
|
1426 when connect is interrupted. So let's not let it get interrupted.
|
|
1427 Note we do not turn off polling, because polling is only used
|
|
1428 when not interrupt_input, and thus not normally used on the systems
|
|
1429 which have this bug. On systems which use polling, there's no way
|
|
1430 to quit if polling is turned off. */
|
|
1431
|
|
1432 /* Slow down polling. Some kernels have a bug which causes retrying
|
|
1433 connect to fail after a connect. */
|
|
1434
|
|
1435 slow_down_interrupts ();
|
|
1436
|
|
1437 loop:
|
|
1438
|
|
1439 /* A system call interrupted with a SIGALRM or SIGIO comes back
|
|
1440 here, with can_break_system_calls reset to 0. */
|
|
1441 SETJMP (break_system_call_jump);
|
|
1442 if (QUITP)
|
|
1443 {
|
|
1444 speed_up_interrupts ();
|
|
1445 REALLY_QUIT;
|
|
1446 /* In case something really weird happens ... */
|
|
1447 slow_down_interrupts ();
|
|
1448 }
|
|
1449
|
|
1450 /* Break out of connect with a signal (it isn't otherwise possible).
|
|
1451 Thus you don't get screwed with a hung network. */
|
|
1452 can_break_system_calls = 1;
|
|
1453 retval = connect (s, (struct sockaddr *) &address, sizeof (address));
|
|
1454 can_break_system_calls = 0;
|
|
1455 if (retval == -1 && errno != EISCONN)
|
|
1456 {
|
|
1457 int xerrno = errno;
|
|
1458 if (errno == EINTR)
|
|
1459 goto loop;
|
|
1460 if (errno == EADDRINUSE && retry < 20)
|
|
1461 {
|
|
1462 /* A delay here is needed on some FreeBSD systems,
|
|
1463 and it is harmless, since this retrying takes time anyway
|
104
|
1464 and should be infrequent.
|
|
1465 `sleep-for' allowed for quitting this loop with interrupts
|
|
1466 slowed down so it can't be used here. Async timers should
|
|
1467 already be disabled at this point so we can use `sleep'. */
|
|
1468 sleep (1);
|
0
|
1469 retry++;
|
|
1470 goto loop;
|
|
1471 }
|
|
1472
|
|
1473 close (s);
|
|
1474
|
|
1475 speed_up_interrupts ();
|
|
1476
|
|
1477 errno = xerrno;
|
|
1478 report_file_error ("connection failed", list2 (host, name));
|
|
1479 }
|
|
1480
|
|
1481 speed_up_interrupts ();
|
|
1482
|
|
1483 #else /* HAVE_TERM */
|
|
1484 s = connect_server (0);
|
|
1485 if (s < 0)
|
|
1486 report_file_error ("error creating socket", Fcons (name, Qnil));
|
16
|
1487 send_command (s, C_PORT, 0, "%s:%d", XSTRING_DATA (host), ntohs (port));
|
0
|
1488 send_command (s, C_DUMB, 1, 0);
|
|
1489 #endif /* HAVE_TERM */
|
|
1490
|
|
1491 inch = s;
|
|
1492 outch = dup (s);
|
|
1493 if (outch < 0)
|
|
1494 {
|
|
1495 close (s); /* this used to be leaked; from Kyle Jones */
|
|
1496 report_file_error ("error duplicating socket", list1 (name));
|
|
1497 }
|
|
1498
|
|
1499 if (!NILP (buffer))
|
|
1500 buffer = Fget_buffer_create (buffer);
|
|
1501 proc = make_process_internal (name);
|
|
1502
|
|
1503 descriptor_to_process[inch] = proc;
|
|
1504
|
153
|
1505 #ifdef PROCESS_IO_BLOCKING
|
|
1506 {
|
|
1507 Lisp_Object tail;
|
|
1508
|
|
1509 for (tail = network_stream_blocking_port_list; CONSP (tail); tail = XCDR (tail))
|
|
1510 {
|
|
1511 Lisp_Object tail_port = XCAR (tail);
|
|
1512
|
|
1513 if (STRINGP (tail_port))
|
|
1514 {
|
|
1515 struct servent *svc_info;
|
|
1516 CHECK_STRING (tail_port);
|
|
1517 svc_info = getservbyname ((char *) XSTRING_DATA (tail_port), "tcp");
|
|
1518 if ((svc_info != 0) && (svc_info->s_port == port))
|
|
1519 break;
|
|
1520 else
|
|
1521 continue;
|
|
1522 }
|
|
1523 else if ((INTP (tail_port)) && (htons ((unsigned short) XINT (tail_port)) == port))
|
|
1524 break;
|
|
1525 }
|
|
1526
|
|
1527 if (!CONSP (tail))
|
|
1528 {
|
|
1529 #endif /* PROCESS_IO_BLOCKING */
|
0
|
1530 set_descriptor_non_blocking (inch);
|
153
|
1531 #ifdef PROCESS_IO_BLOCKING
|
|
1532 }
|
|
1533 }
|
|
1534 #endif /* PROCESS_IO_BLOCKING */
|
0
|
1535
|
|
1536 XPROCESS (proc)->pid = Fcons (service, host);
|
|
1537 XPROCESS (proc)->buffer = buffer;
|
|
1538 init_process_fds (XPROCESS (proc), inch, outch);
|
|
1539 XPROCESS (proc)->connected_via_filedesc_p = 0;
|
|
1540
|
|
1541 event_stream_select_process (XPROCESS (proc));
|
|
1542
|
|
1543 UNGCPRO;
|
|
1544 return proc;
|
|
1545 }
|
|
1546
|
|
1547 #endif /* HAVE_SOCKETS */
|
|
1548
|
|
1549 Lisp_Object
|
|
1550 canonicalize_host_name (Lisp_Object host)
|
|
1551 {
|
|
1552 #ifdef HAVE_SOCKETS
|
|
1553 /* #### for HAVE_TERM, you probably have to do something else. */
|
|
1554 struct sockaddr_in address;
|
|
1555
|
|
1556 if (!get_internet_address (host, &address, ERROR_ME_NOT))
|
|
1557 return host;
|
|
1558
|
|
1559 if (address.sin_family == AF_INET)
|
|
1560 return build_string (inet_ntoa (address.sin_addr));
|
|
1561 else
|
|
1562 /* #### any clue what to do here? */
|
|
1563 return host;
|
|
1564 #else
|
|
1565 return host;
|
|
1566 #endif
|
|
1567 }
|
|
1568
|
|
1569
|
20
|
1570 DEFUN ("set-process-window-size", Fset_process_window_size, 3, 3, 0, /*
|
0
|
1571 Tell PROCESS that it has logical window size HEIGHT and WIDTH.
|
20
|
1572 */
|
|
1573 (proc, height, width))
|
0
|
1574 {
|
|
1575 CHECK_PROCESS (proc);
|
|
1576 CHECK_NATNUM (height);
|
|
1577 CHECK_NATNUM (width);
|
|
1578 if (set_window_size (XPROCESS (proc)->infd, XINT (height), XINT (width))
|
|
1579 <= 0)
|
|
1580 return Qnil;
|
|
1581 else
|
|
1582 return Qt;
|
|
1583 }
|
|
1584
|
|
1585
|
|
1586 /************************************************************************/
|
|
1587 /* Process I/O */
|
|
1588 /************************************************************************/
|
|
1589
|
|
1590 /* (Faccept_process_output is now in event-stream.c) */
|
|
1591
|
|
1592 /* Some FSFmacs error handlers here. We handle this
|
|
1593 in call2_trapping_errors(). */
|
|
1594
|
|
1595 /* Read pending output from the process channel,
|
|
1596 starting with our buffered-ahead character if we have one.
|
|
1597 Yield number of characters read.
|
|
1598
|
|
1599 This function reads at most 1024 bytes.
|
|
1600 If you want to read all available subprocess output,
|
|
1601 you must call it repeatedly until it returns zero. */
|
|
1602
|
|
1603 Charcount
|
|
1604 read_process_output (Lisp_Object proc)
|
|
1605 {
|
|
1606 /* This function can GC */
|
|
1607 Bytecount nbytes, nchars;
|
|
1608 #ifdef VMS
|
|
1609 char *chars;
|
|
1610 #else
|
|
1611 Bufbyte chars[1024];
|
|
1612 #endif
|
|
1613 Lisp_Object outstream;
|
|
1614 struct Lisp_Process *p = XPROCESS (proc);
|
|
1615
|
|
1616 /* If there is a lot of output from the subprocess, the loop in
|
|
1617 execute_internal_event() might call read_process_output() more
|
|
1618 than once. If the filter that was executed from one of these
|
|
1619 calls set the filter to t, we have to stop now. Return -1 rather
|
|
1620 than 0 so execute_internal_event() doesn't close the process.
|
|
1621 Really, the loop in execute_internal_event() should check itself
|
|
1622 for a process-filter change, like in status_notify(); but the
|
|
1623 struct Lisp_Process is not exported outside of this file. */
|
|
1624 if (p->infd < 0)
|
|
1625 return -1; /* already closed */
|
|
1626
|
|
1627 if (!NILP (p->filter) && (p->filter_does_read))
|
|
1628 {
|
|
1629 Lisp_Object filter_result;
|
|
1630
|
|
1631 /* Some weird FSFmacs crap here with
|
|
1632 Vdeactivate_mark and current_buffer->keymap */
|
|
1633 running_asynch_code = 1;
|
|
1634 filter_result = call2_trapping_errors ("Error in process filter",
|
|
1635 p->filter, proc, Qnil);
|
|
1636 running_asynch_code = 0;
|
|
1637 restore_match_data ();
|
|
1638 CHECK_INT (filter_result);
|
|
1639 return XINT (filter_result);
|
|
1640 }
|
|
1641
|
|
1642 #ifdef VMS
|
|
1643 VMS_PROC_STUFF *vs, *get_vms_process_pointer();
|
|
1644
|
|
1645 vs = get_vms_process_pointer (XINT (p->pid));
|
|
1646 if (vs)
|
|
1647 {
|
|
1648 if (!vs->iosb[0])
|
173
|
1649 return 0; /* Really weird if it does this */
|
0
|
1650 if (!(vs->iosb[0] & 1))
|
|
1651 return -1; /* I/O error */
|
|
1652 }
|
|
1653 else
|
|
1654 error ("Could not get VMS process pointer");
|
|
1655 chars = vs->inputBuffer;
|
|
1656 nbytes = clean_vms_buffer (chars, vs->iosb[1]);
|
|
1657 if (nbytes <= 0)
|
|
1658 {
|
|
1659 start_vms_process_read (vs); /* Crank up the next read on the process */
|
|
1660 return 1; /* Nothing worth printing, say we got 1 */
|
|
1661 }
|
|
1662 #else /* not VMS */
|
|
1663
|
|
1664 #if 0 /* FSFmacs */
|
|
1665 /* #### equivalent code from FSFmacs. Would need some porting
|
|
1666 for Windows NT. */
|
|
1667 if (proc_buffered_char[channel] < 0)
|
|
1668 #ifdef WINDOWSNT
|
|
1669 nchars = read_child_output (channel, chars, sizeof (chars));
|
|
1670 #else
|
|
1671 nchars = read (channel, chars, sizeof chars);
|
|
1672 #endif
|
|
1673 else
|
|
1674 {
|
|
1675 chars[0] = proc_buffered_char[channel];
|
|
1676 proc_buffered_char[channel] = -1;
|
|
1677 #ifdef WINDOWSNT
|
|
1678 nchars = read_child_output (channel, chars + 1, sizeof (chars) - 1);
|
|
1679 #else
|
|
1680 nchars = read (channel, chars + 1, sizeof chars - 1);
|
|
1681 #endif
|
|
1682 if (nchars < 0)
|
|
1683 nchars = 1;
|
|
1684 else
|
|
1685 nchars = nchars + 1;
|
|
1686 }
|
|
1687 #endif /* FSFmacs */
|
|
1688
|
|
1689 nbytes = Lstream_read (XLSTREAM (p->instream), chars, sizeof (chars));
|
|
1690 if (nbytes <= 0) return nbytes;
|
|
1691 #endif /* not VMS */
|
|
1692
|
|
1693 nchars = bytecount_to_charcount (chars, nbytes);
|
|
1694 outstream = p->filter;
|
|
1695 if (!NILP (outstream))
|
|
1696 {
|
|
1697 /* We used to bind inhibit-quit to t here, but
|
|
1698 call2_trapping_errors() does that for us. */
|
|
1699 running_asynch_code = 1;
|
|
1700 call2_trapping_errors ("Error in process filter",
|
|
1701 outstream, proc, make_string (chars, nbytes));
|
|
1702 running_asynch_code = 0;
|
|
1703 restore_match_data ();
|
|
1704 #ifdef VMS
|
|
1705 start_vms_process_read (vs);
|
|
1706 #endif
|
173
|
1707 return nchars;
|
0
|
1708 }
|
|
1709
|
|
1710 /* If no filter, write into buffer if it isn't dead. */
|
|
1711 if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer)))
|
|
1712 {
|
|
1713 Lisp_Object old_read_only = Qnil;
|
|
1714 Bufpos old_point;
|
|
1715 Bufpos old_begv;
|
|
1716 Bufpos old_zv;
|
|
1717 int old_zmacs_region_stays = zmacs_region_stays;
|
|
1718 struct gcpro gcpro1, gcpro2;
|
|
1719 struct buffer *buf = XBUFFER (p->buffer);
|
|
1720
|
|
1721 GCPRO2 (proc, old_read_only);
|
|
1722
|
|
1723 old_point = BUF_PT (buf);
|
|
1724 old_begv = BUF_BEGV (buf);
|
|
1725 old_zv = BUF_ZV (buf);
|
|
1726 old_read_only = buf->read_only;
|
|
1727 buf->read_only = Qnil;
|
|
1728
|
|
1729 /* Insert new output into buffer
|
|
1730 at the current end-of-output marker,
|
|
1731 thus preserving logical ordering of input and output. */
|
|
1732 if (XMARKER (p->mark)->buffer)
|
|
1733 BUF_SET_PT (buf,
|
|
1734 bufpos_clip_to_bounds (old_begv, marker_position (p->mark),
|
|
1735 old_zv));
|
|
1736 else
|
|
1737 BUF_SET_PT (buf, old_zv);
|
|
1738
|
|
1739 /* If the output marker is outside of the visible region, save
|
|
1740 the restriction and widen. */
|
|
1741 if (! (BUF_BEGV (buf) <= BUF_PT (buf) &&
|
|
1742 BUF_PT (buf) <= BUF_ZV (buf)))
|
|
1743 Fwiden (p->buffer);
|
|
1744
|
|
1745 /* Make sure opoint floats ahead of any new text, just as point
|
|
1746 would. */
|
|
1747 if (BUF_PT (buf) <= old_point)
|
|
1748 old_point += nchars;
|
|
1749
|
|
1750 /* Insert after old_begv, but before old_zv. */
|
|
1751 if (BUF_PT (buf) < old_begv)
|
|
1752 old_begv += nchars;
|
|
1753 if (BUF_PT (buf) <= old_zv)
|
|
1754 old_zv += nchars;
|
|
1755
|
|
1756 #if 0
|
|
1757 /* This screws up intial display of the window. jla */
|
|
1758
|
|
1759 /* Insert before markers in case we are inserting where
|
|
1760 the buffer's mark is, and the user's next command is Meta-y. */
|
|
1761 buffer_insert_raw_string_1 (buf, -1, chars,
|
|
1762 nbytes, INSDEL_BEFORE_MARKERS);
|
|
1763 #else
|
|
1764 buffer_insert_raw_string (buf, chars, nbytes);
|
|
1765 #endif
|
|
1766
|
|
1767 Fset_marker (p->mark, make_int (BUF_PT (buf)), p->buffer);
|
|
1768
|
|
1769 MARK_MODELINE_CHANGED;
|
|
1770
|
|
1771 /* If the restriction isn't what it should be, set it. */
|
|
1772 if (old_begv != BUF_BEGV (buf) || old_zv != BUF_ZV (buf))
|
161
|
1773 {
|
|
1774 Fwiden(p->buffer);
|
|
1775 old_begv = bufpos_clip_to_bounds (BUF_BEG (buf),
|
|
1776 old_begv,
|
|
1777 BUF_Z (buf));
|
|
1778 old_zv = bufpos_clip_to_bounds (BUF_BEG (buf),
|
|
1779 old_zv,
|
|
1780 BUF_Z (buf));
|
|
1781 Fnarrow_to_region (make_int (old_begv), make_int (old_zv),
|
|
1782 p->buffer);
|
|
1783 }
|
0
|
1784
|
|
1785 /* Handling the process output should not deactivate the mark. */
|
|
1786 zmacs_region_stays = old_zmacs_region_stays;
|
|
1787 buf->read_only = old_read_only;
|
161
|
1788 old_point = bufpos_clip_to_bounds (BUF_BEGV (buf),
|
|
1789 old_point,
|
|
1790 BUF_ZV (buf));
|
0
|
1791 BUF_SET_PT (buf, old_point);
|
|
1792
|
|
1793 UNGCPRO;
|
|
1794 }
|
|
1795 #ifdef VMS
|
|
1796 start_vms_process_read (vs);
|
|
1797 #endif
|
173
|
1798 return nchars;
|
0
|
1799 }
|
|
1800
|
|
1801 /* Sending data to subprocess */
|
|
1802
|
|
1803 static JMP_BUF send_process_frame;
|
|
1804
|
|
1805 static SIGTYPE
|
|
1806 send_process_trap (int signum)
|
|
1807 {
|
|
1808 EMACS_REESTABLISH_SIGNAL (signum, send_process_trap);
|
|
1809 EMACS_UNBLOCK_SIGNAL (signum);
|
|
1810 LONGJMP (send_process_frame, 1);
|
|
1811 }
|
|
1812
|
|
1813 /* send some data to process PROC. If NONRELOCATABLE is non-NULL, it
|
|
1814 specifies the address of the data. Otherwise, the data comes from the
|
|
1815 object RELOCATABLE (either a string or a buffer). START and LEN
|
|
1816 specify the offset and length of the data to send.
|
|
1817
|
|
1818 Note that START and LEN are in Bufpos's if RELOCATABLE is a buffer,
|
|
1819 and in Bytecounts otherwise. */
|
|
1820
|
|
1821 static void
|
|
1822 send_process (volatile Lisp_Object proc,
|
|
1823 Lisp_Object relocatable, CONST Bufbyte *nonrelocatable,
|
|
1824 int start, int len)
|
|
1825 {
|
|
1826 /* This function can GC */
|
|
1827 /* Use volatile to protect variables from being clobbered by longjmp. */
|
|
1828 struct gcpro gcpro1, gcpro2;
|
16
|
1829 SIGTYPE (*volatile old_sigpipe) (int) = 0;
|
0
|
1830 Lisp_Object lstream = Qnil;
|
|
1831 volatile struct Lisp_Process *p = XPROCESS (proc);
|
|
1832 #if defined (NO_UNION_TYPE) /* || !defined (__GNUC__) GCC bug only??? */
|
|
1833 /* #### ugh! There must be a better solution. */
|
|
1834 Lisp_Object defeat_volatile_kludge = (Lisp_Object) proc;
|
|
1835 #else
|
|
1836 Lisp_Object defeat_volatile_kludge = proc;
|
|
1837 #endif
|
|
1838
|
|
1839 #ifdef VMS
|
|
1840 VMS_PROC_STUFF *vs, *get_vms_process_pointer (int);
|
|
1841 #endif /* VMS */
|
|
1842
|
|
1843 GCPRO2 (defeat_volatile_kludge, lstream);
|
|
1844
|
|
1845 if (p->outfd < 0)
|
|
1846 signal_simple_error ("Process not open for writing", proc);
|
|
1847
|
|
1848 #ifdef VMS
|
|
1849 vs = get_vms_process_pointer (XINT (p->pid));
|
|
1850 if (vs == 0)
|
|
1851 error ("Could not find this process: %x",
|
|
1852 XINT (p->pid));
|
|
1853 else if (write_to_vms_process (vs, buf, len))
|
|
1854 ;
|
|
1855 #else
|
|
1856
|
|
1857 if (nonrelocatable)
|
|
1858 lstream =
|
|
1859 make_fixed_buffer_input_stream (nonrelocatable + start, len);
|
|
1860 else if (GC_BUFFERP (relocatable))
|
|
1861 lstream = make_lisp_buffer_input_stream (XBUFFER (relocatable),
|
|
1862 start, start + len, 0);
|
|
1863 else
|
|
1864 lstream = make_lisp_string_input_stream (relocatable, start, len);
|
|
1865
|
|
1866 if (!SETJMP (send_process_frame))
|
|
1867 {
|
|
1868 /* use a reasonable-sized buffer (somewhere around the size of the
|
|
1869 stream buffer) so as to avoid inundating the stream with blocked
|
|
1870 data. */
|
|
1871 Bufbyte chunkbuf[512];
|
|
1872 Bytecount chunklen;
|
|
1873
|
|
1874 while (1)
|
|
1875 {
|
|
1876 int writeret;
|
|
1877
|
|
1878 chunklen = Lstream_read (XLSTREAM (lstream), chunkbuf, 512);
|
|
1879 if (chunklen <= 0)
|
|
1880 break; /* perhaps should abort() if < 0?
|
|
1881 This should never happen. */
|
|
1882 old_sigpipe =
|
|
1883 (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
|
|
1884 /* Lstream_write() will never successfully write less than
|
|
1885 the amount sent in. In the worst case, it just buffers
|
|
1886 the unwritten data. */
|
|
1887 writeret = Lstream_write (XLSTREAM (p->outstream), chunkbuf,
|
|
1888 chunklen);
|
|
1889 signal (SIGPIPE, old_sigpipe);
|
|
1890 if (writeret < 0)
|
|
1891 /* This is a real error. Blocking errors are handled
|
|
1892 specially inside of the filedesc stream. */
|
|
1893 report_file_error ("writing to process",
|
|
1894 list1 (proc));
|
|
1895 while (filedesc_stream_was_blocked (XLSTREAM (p->filedesc_stream)))
|
|
1896 {
|
185
|
1897 /* Buffer is full. Wait, accepting input;
|
0
|
1898 that may allow the program
|
|
1899 to finish doing output and read more. */
|
|
1900 Faccept_process_output (Qnil, make_int (1), Qnil);
|
|
1901 old_sigpipe =
|
|
1902 (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
|
|
1903 Lstream_flush (XLSTREAM (p->filedesc_stream));
|
|
1904 signal (SIGPIPE, old_sigpipe);
|
|
1905 }
|
|
1906 }
|
|
1907 }
|
|
1908 #endif /* !VMS */
|
|
1909 else
|
|
1910 { /* We got here from a longjmp() from the SIGPIPE handler */
|
|
1911 signal (SIGPIPE, old_sigpipe);
|
|
1912 p->status_symbol = Qexit;
|
|
1913 p->exit_code = 256; /* #### SIGPIPE ??? */
|
|
1914 p->core_dumped = 0;
|
|
1915 p->tick++;
|
|
1916 process_tick++;
|
|
1917 deactivate_process (proc);
|
|
1918 #ifdef VMS
|
|
1919 error ("Error writing to process %s; closed it",
|
70
|
1920 XSTRING_DATA (p->name));
|
0
|
1921 #else
|
|
1922 error ("SIGPIPE raised on process %s; closed it",
|
70
|
1923 XSTRING_DATA (p->name));
|
0
|
1924 #endif
|
|
1925 }
|
207
|
1926 old_sigpipe = (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
|
0
|
1927 Lstream_flush (XLSTREAM (p->outstream));
|
207
|
1928 signal (SIGPIPE, old_sigpipe);
|
0
|
1929 UNGCPRO;
|
185
|
1930 Lstream_delete (XLSTREAM (lstream));
|
0
|
1931 }
|
|
1932
|
20
|
1933 DEFUN ("process-tty-name", Fprocess_tty_name, 1, 1, 0, /*
|
0
|
1934 Return the name of the terminal PROCESS uses, or nil if none.
|
|
1935 This is the terminal that the process itself reads and writes on,
|
|
1936 not the name of the pty that Emacs uses to talk with that terminal.
|
20
|
1937 */
|
|
1938 (proc))
|
0
|
1939 {
|
|
1940 CHECK_PROCESS (proc);
|
|
1941 return XPROCESS (proc)->tty_name;
|
|
1942 }
|
|
1943
|
20
|
1944 DEFUN ("set-process-buffer", Fset_process_buffer, 2, 2, 0, /*
|
0
|
1945 Set buffer associated with PROCESS to BUFFER (a buffer, or nil).
|
20
|
1946 */
|
|
1947 (proc, buffer))
|
0
|
1948 {
|
|
1949 CHECK_PROCESS (proc);
|
|
1950 if (!NILP (buffer))
|
|
1951 CHECK_BUFFER (buffer);
|
|
1952 XPROCESS (proc)->buffer = buffer;
|
|
1953 return buffer;
|
|
1954 }
|
|
1955
|
20
|
1956 DEFUN ("process-buffer", Fprocess_buffer, 1, 1, 0, /*
|
0
|
1957 Return the buffer PROCESS is associated with.
|
|
1958 Output from PROCESS is inserted in this buffer
|
|
1959 unless PROCESS has a filter.
|
20
|
1960 */
|
|
1961 (proc))
|
0
|
1962 {
|
|
1963 CHECK_PROCESS (proc);
|
|
1964 return XPROCESS (proc)->buffer;
|
|
1965 }
|
|
1966
|
20
|
1967 DEFUN ("process-mark", Fprocess_mark, 1, 1, 0, /*
|
0
|
1968 Return the marker for the end of the last output from PROCESS.
|
20
|
1969 */
|
|
1970 (proc))
|
0
|
1971 {
|
|
1972 CHECK_PROCESS (proc);
|
|
1973 #ifdef ENERGIZE
|
|
1974 if (EQ (proc, Venergize_process)) /* per buffer rather than per process */
|
|
1975 return Fenergize_user_input_buffer_mark (Qnil); /* ## current_buffer ok? */
|
|
1976 #endif
|
|
1977 return XPROCESS (proc)->mark;
|
|
1978 }
|
|
1979
|
|
1980 void
|
|
1981 set_process_filter (Lisp_Object proc, Lisp_Object filter, int filter_does_read)
|
|
1982 {
|
|
1983 CHECK_PROCESS (proc);
|
|
1984 if (PROCESS_LIVE_P (proc))
|
|
1985 if (EQ (filter, Qt))
|
|
1986 event_stream_unselect_process (XPROCESS (proc));
|
|
1987 else
|
|
1988 event_stream_select_process (XPROCESS (proc));
|
|
1989
|
|
1990 XPROCESS (proc)->filter = filter;
|
|
1991 XPROCESS (proc)->filter_does_read = filter_does_read;
|
|
1992 }
|
|
1993
|
20
|
1994 DEFUN ("set-process-filter", Fset_process_filter, 2, 2, 0, /*
|
0
|
1995 Give PROCESS the filter function FILTER; nil means no filter.
|
|
1996 t means stop accepting output from the process.
|
|
1997 When a process has a filter, each time it does output
|
|
1998 the entire string of output is passed to the filter.
|
|
1999 The filter gets two arguments: the process and the string of output.
|
|
2000 If the process has a filter, its buffer is not used for output.
|
20
|
2001 */
|
|
2002 (proc, filter))
|
0
|
2003 {
|
|
2004 set_process_filter (proc, filter, 0);
|
|
2005 return filter;
|
|
2006 }
|
|
2007
|
20
|
2008 DEFUN ("process-filter", Fprocess_filter, 1, 1, 0, /*
|
0
|
2009 Return the filter function of PROCESS; nil if none.
|
|
2010 See `set-process-filter' for more info on filter functions.
|
20
|
2011 */
|
|
2012 (proc))
|
0
|
2013 {
|
|
2014 CHECK_PROCESS (proc);
|
|
2015 return XPROCESS (proc)->filter;
|
|
2016 }
|
|
2017
|
20
|
2018 DEFUN ("process-send-region", Fprocess_send_region, 3, 3, 0, /*
|
0
|
2019 Send current contents of region as input to PROCESS.
|
|
2020 PROCESS may be a process name or an actual process.
|
|
2021 Called from program, takes three arguments, PROCESS, START and END.
|
|
2022 If the region is more than 500 or so characters long,
|
|
2023 it is sent in several bunches. This may happen even for shorter regions.
|
|
2024 Output from processes can arrive in between bunches.
|
20
|
2025 */
|
|
2026 (process, start, end))
|
0
|
2027 {
|
|
2028 /* This function can GC */
|
|
2029 Lisp_Object proc = get_process (process);
|
|
2030 Bufpos st, en;
|
|
2031
|
|
2032 get_buffer_range_char (current_buffer, start, end, &st, &en, 0);
|
|
2033
|
|
2034 send_process (proc, Fcurrent_buffer (), 0,
|
|
2035 st, en - st);
|
173
|
2036 return Qnil;
|
0
|
2037 }
|
|
2038
|
20
|
2039 DEFUN ("process-send-string", Fprocess_send_string, 2, 4, 0, /*
|
0
|
2040 Send PROCESS the contents of STRING as input.
|
|
2041 PROCESS may be a process name or an actual process.
|
|
2042 Optional arguments FROM and TO specify part of STRING, see `substring'.
|
|
2043 If STRING is more than 500 or so characters long,
|
|
2044 it is sent in several bunches. This may happen even for shorter strings.
|
|
2045 Output from processes can arrive in between bunches.
|
20
|
2046 */
|
|
2047 (process, string, from, to))
|
0
|
2048 {
|
|
2049 /* This function can GC */
|
|
2050 Lisp_Object proc;
|
|
2051 Bytecount len;
|
|
2052 Bytecount bfr, bto;
|
|
2053
|
|
2054 proc = get_process (process);
|
|
2055 CHECK_STRING (string);
|
|
2056 get_string_range_byte (string, from, to, &bfr, &bto,
|
|
2057 GB_HISTORICAL_STRING_BEHAVIOR);
|
|
2058 len = bto - bfr;
|
|
2059
|
|
2060 send_process (proc, string, 0, bfr, len);
|
173
|
2061 return Qnil;
|
0
|
2062 }
|
|
2063
|
70
|
2064 #ifdef MULE
|
|
2065
|
|
2066 DEFUN ("process-input-coding-system", Fprocess_input_coding_system, 1, 1, 0, /*
|
|
2067 Return PROCESS's input coding system.
|
|
2068 */
|
|
2069 (process))
|
|
2070 {
|
|
2071 process = get_process (process);
|
|
2072 return decoding_stream_coding_system (XLSTREAM ( XPROCESS (process)->instream) );
|
|
2073 }
|
|
2074
|
|
2075 DEFUN ("process-output-coding-system", Fprocess_output_coding_system, 1, 1, 0, /*
|
|
2076 Return PROCESS's output coding system.
|
|
2077 */
|
|
2078 (process))
|
|
2079 {
|
|
2080 process = get_process (process);
|
|
2081 return encoding_stream_coding_system (XLSTREAM (XPROCESS (process)->outstream));
|
|
2082 }
|
|
2083
|
120
|
2084 DEFUN ("process-coding-system", Fprocess_coding_system, 1, 1, 0, /*
|
|
2085 Return a pair of coding-system for decoding and encoding of PROCESS.
|
|
2086 */
|
|
2087 (process))
|
|
2088 {
|
|
2089 process = get_process (process);
|
175
|
2090 return Fcons (decoding_stream_coding_system
|
|
2091 (XLSTREAM (XPROCESS (process)->instream)),
|
|
2092 encoding_stream_coding_system
|
|
2093 (XLSTREAM (XPROCESS (process)->outstream)));
|
120
|
2094 }
|
|
2095
|
70
|
2096 DEFUN ("set-process-input-coding-system",
|
|
2097 Fset_process_input_coding_system, 2, 2, 0, /*
|
|
2098 Set PROCESS's input coding system to CODESYS.
|
|
2099 */
|
|
2100 (process, codesys))
|
|
2101 {
|
|
2102 codesys = Fget_coding_system (codesys);
|
|
2103 process = get_process (process);
|
|
2104 set_decoding_stream_coding_system ( XLSTREAM ( XPROCESS (process)->instream ), codesys);
|
|
2105 return Qnil;
|
|
2106 }
|
|
2107
|
|
2108 DEFUN ("set-process-output-coding-system",
|
|
2109 Fset_process_output_coding_system, 2, 2, 0, /*
|
|
2110 Set PROCESS's output coding system to CODESYS.
|
|
2111 */
|
|
2112 (process, codesys))
|
|
2113 {
|
|
2114 codesys = Fget_coding_system (codesys);
|
|
2115 process = get_process (process);
|
|
2116 set_encoding_stream_coding_system
|
|
2117 ( XLSTREAM ( XPROCESS (process)->outstream), codesys);
|
|
2118 return Qnil;
|
|
2119 }
|
|
2120
|
120
|
2121 DEFUN ("set-process-coding-system",
|
|
2122 Fset_process_coding_system, 1, 3, 0, /*
|
|
2123 Set coding-systems of PROCESS to DECODING and ENCODING.
|
|
2124 */
|
|
2125 (process, decoding, encoding))
|
|
2126 {
|
|
2127 if(!NILP(decoding)){
|
|
2128 Fset_process_input_coding_system(process, decoding);
|
|
2129 }
|
|
2130 if(!NILP(encoding)){
|
|
2131 Fset_process_output_coding_system(process, encoding);
|
|
2132 }
|
|
2133 return Qnil;
|
|
2134 }
|
|
2135
|
70
|
2136 #endif /* MULE */
|
|
2137
|
0
|
2138
|
|
2139 /************************************************************************/
|
|
2140 /* process status */
|
|
2141 /************************************************************************/
|
|
2142
|
|
2143 /* Some FSFmacs error handlers here. We handle this
|
|
2144 in call2_trapping_errors(). */
|
|
2145
|
|
2146 static Lisp_Object
|
|
2147 exec_sentinel_unwind (Lisp_Object datum)
|
|
2148 {
|
|
2149 struct Lisp_Cons *d = XCONS (datum);
|
|
2150 XPROCESS (d->car)->sentinel = d->cdr;
|
|
2151 free_cons (d);
|
|
2152 return Qnil;
|
|
2153 }
|
|
2154
|
|
2155 static void
|
|
2156 exec_sentinel (Lisp_Object proc, Lisp_Object reason)
|
|
2157 {
|
|
2158 /* This function can GC */
|
175
|
2159 int speccount = specpdl_depth ();
|
0
|
2160 struct Lisp_Process *p = XPROCESS (proc);
|
175
|
2161 Lisp_Object sentinel = p->sentinel;
|
|
2162
|
0
|
2163 if (NILP (sentinel))
|
|
2164 return;
|
|
2165
|
|
2166 /* Some weird FSFmacs crap here with
|
|
2167 Vdeactivate_mark and current_buffer->keymap */
|
|
2168
|
|
2169 /* Zilch the sentinel while it's running, to avoid recursive invocations;
|
|
2170 assure that it gets restored no matter how the sentinel exits. */
|
|
2171 p->sentinel = Qnil;
|
|
2172 record_unwind_protect (exec_sentinel_unwind, noseeum_cons (proc, sentinel));
|
|
2173 /* We used to bind inhibit-quit to t here, but call2_trapping_errors()
|
|
2174 does that for us. */
|
|
2175 running_asynch_code = 1;
|
175
|
2176 call2_trapping_errors ("Error in process sentinel", sentinel, proc, reason);
|
0
|
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
|
173
|
2210 return (CONST char *) sys_siglist[signum];
|
0
|
2211 #else
|
173
|
2212 return (CONST char *) sys_errlist[signum];
|
0
|
2213 #endif
|
173
|
2214 return (CONST char *) GETTEXT ("unknown signal");
|
0
|
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);
|
185
|
2320
|
0
|
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;
|
185
|
2354
|
0
|
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;
|
185
|
2387
|
0
|
2388 /* Keep trying to get a status until we get a definitive result. */
|
185
|
2389 do
|
0
|
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);
|
185
|
2406
|
0
|
2407 if (pid <= 0)
|
|
2408 break;
|
185
|
2409
|
0
|
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 }
|
185
|
2416
|
0
|
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.
|
185
|
2441
|
0
|
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
|
185
|
2470 static Lisp_Object
|
0
|
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
|
185
|
2599 if (EQ (symbol, Qsignal)
|
0
|
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
|
175
|
2673 run -- for a process that is running.
|
|
2674 stop -- for a process stopped but continuable.
|
|
2675 exit -- for a process that has exited.
|
0
|
2676 signal -- for a process that has got a fatal signal.
|
175
|
2677 open -- for a network stream connection that is open.
|
0
|
2678 closed -- for a network stream connection that is closed.
|
175
|
2679 nil -- if arg is a process name and no such process exists.
|
|
2680
|
0
|
2681 PROCESS may be a process, a buffer, the name of a process or buffer, or
|
|
2682 nil, indicating the current buffer's process.
|
20
|
2683 */
|
|
2684 (proc))
|
0
|
2685 {
|
175
|
2686 Lisp_Object status_symbol;
|
0
|
2687
|
|
2688 if (STRINGP (proc))
|
|
2689 proc = Fget_process (proc);
|
|
2690 else
|
|
2691 proc = get_process (proc);
|
|
2692
|
|
2693 if (NILP (proc))
|
175
|
2694 return Qnil;
|
|
2695
|
|
2696 status_symbol = XPROCESS (proc)->status_symbol;
|
0
|
2697 if (network_connection_p (proc))
|
|
2698 {
|
175
|
2699 if (EQ (status_symbol, Qrun))
|
|
2700 status_symbol = Qopen;
|
|
2701 else if (EQ (status_symbol, Qexit))
|
|
2702 status_symbol = Qclosed;
|
0
|
2703 }
|
175
|
2704 return status_symbol;
|
0
|
2705 }
|
|
2706
|
20
|
2707 DEFUN ("process-exit-status", Fprocess_exit_status, 1, 1, 0, /*
|
0
|
2708 Return the exit status of PROCESS or the signal number that killed it.
|
|
2709 If PROCESS has not yet exited or died, return 0.
|
20
|
2710 */
|
|
2711 (proc))
|
0
|
2712 {
|
|
2713 CHECK_PROCESS (proc);
|
173
|
2714 return make_int (XPROCESS (proc)->exit_code);
|
0
|
2715 }
|
|
2716
|
|
2717
|
|
2718 #ifdef SIGNALS_VIA_CHARACTERS
|
|
2719 /* Get signal character to send to process if SIGNALS_VIA_CHARACTERS */
|
|
2720
|
|
2721 static int
|
|
2722 process_signal_char (int tty_fd, int signo)
|
|
2723 {
|
|
2724 /* If it's not a tty, pray that these default values work */
|
|
2725 if (!isatty(tty_fd)) {
|
|
2726 #define CNTL(ch) (037 & (ch))
|
|
2727 switch (signo)
|
|
2728 {
|
|
2729 case SIGINT: return CNTL('C');
|
|
2730 case SIGQUIT: return CNTL('\\');
|
|
2731 #ifdef SIGTSTP
|
|
2732 case SIGTSTP: return CNTL('Z');
|
|
2733 #endif
|
|
2734 }
|
|
2735 }
|
|
2736
|
|
2737 #ifdef HAVE_TERMIOS
|
|
2738 /* TERMIOS is the latest and bestest, and seems most likely to work.
|
|
2739 If the system has it, use it. */
|
|
2740 {
|
|
2741 struct termios t;
|
|
2742 tcgetattr (tty_fd, &t);
|
|
2743 switch (signo)
|
|
2744 {
|
|
2745 case SIGINT: return t.c_cc[VINTR];
|
|
2746 case SIGQUIT: return t.c_cc[VQUIT];
|
|
2747 # if defined (VSWTCH) && !defined (PREFER_VSUSP)
|
|
2748 case SIGTSTP: return t.c_cc[VSWTCH];
|
|
2749 # else
|
|
2750 case SIGTSTP: return t.c_cc[VSUSP];
|
|
2751 # endif
|
|
2752 }
|
|
2753 }
|
|
2754
|
|
2755 # elif defined (TIOCGLTC) && defined (TIOCGETC) /* not HAVE_TERMIOS */
|
|
2756 {
|
|
2757 /* On Berkeley descendants, the following IOCTL's retrieve the
|
|
2758 current control characters. */
|
|
2759 struct tchars c;
|
|
2760 struct ltchars lc;
|
|
2761 switch (signo)
|
|
2762 {
|
|
2763 case SIGINT: ioctl (tty_fd, TIOCGETC, &c); return c.t_intrc;
|
|
2764 case SIGQUIT: ioctl (tty_fd, TIOCGETC, &c); return c.t_quitc;
|
|
2765 # ifdef SIGTSTP
|
|
2766 case SIGTSTP: ioctl (tty_fd, TIOCGLTC, &lc); return lc.t_suspc;
|
|
2767 # endif /* SIGTSTP */
|
|
2768 }
|
|
2769 }
|
|
2770
|
|
2771 # elif defined (TCGETA) /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
|
|
2772 {
|
|
2773 /* On SYSV descendants, the TCGETA ioctl retrieves the current
|
|
2774 control characters. */
|
|
2775 struct termio t;
|
|
2776 ioctl (tty_fd, TCGETA, &t);
|
|
2777 switch (signo) {
|
|
2778 case SIGINT: return t.c_cc[VINTR];
|
|
2779 case SIGQUIT: return t.c_cc[VQUIT];
|
|
2780 # ifdef SIGTSTP
|
|
2781 case SIGTSTP: return t.c_cc[VSWTCH];
|
|
2782 # endif /* SIGTSTP */
|
|
2783 }
|
|
2784 }
|
|
2785 # else /* ! defined (TCGETA) */
|
175
|
2786 #error ERROR! Using SIGNALS_VIA_CHARACTERS, but not HAVE_TERMIOS || (TIOCGLTC && TIOCGETC) || TCGETA
|
0
|
2787 /* If your system configuration files define SIGNALS_VIA_CHARACTERS,
|
|
2788 you'd better be using one of the alternatives above! */
|
|
2789 # endif /* ! defined (TCGETA) */
|
|
2790 return '\0';
|
|
2791 }
|
|
2792 #endif /* SIGNALS_VIA_CHARACTERS */
|
|
2793
|
|
2794
|
|
2795 /* send a signal number SIGNO to PROCESS.
|
|
2796 CURRENT_GROUP means send to the process group that currently owns
|
|
2797 the terminal being used to communicate with PROCESS.
|
|
2798 This is used for various commands in shell mode.
|
|
2799 If NOMSG is zero, insert signal-announcements into process's buffers
|
|
2800 right away.
|
|
2801
|
|
2802 If we can, we try to signal PROCESS by sending control characters
|
|
2803 down the pty. This allows us to signal inferiors who have changed
|
|
2804 their uid, for which killpg would return an EPERM error. */
|
|
2805
|
|
2806 static void
|
|
2807 process_send_signal (Lisp_Object process0, int signo,
|
|
2808 int current_group, int nomsg)
|
|
2809 {
|
|
2810 /* This function can GC */
|
|
2811 Lisp_Object proc = get_process (process0);
|
|
2812 struct Lisp_Process *p = XPROCESS (proc);
|
|
2813 int gid;
|
|
2814 int no_pgrp = 0;
|
|
2815
|
|
2816 if (network_connection_p (proc))
|
|
2817 error ("Network connection %s is not a subprocess",
|
70
|
2818 XSTRING_DATA (p->name));
|
0
|
2819 if (p->infd < 0)
|
|
2820 error ("Process %s is not active",
|
70
|
2821 XSTRING_DATA (p->name));
|
0
|
2822
|
|
2823 if (!p->pty_flag)
|
|
2824 current_group = 0;
|
|
2825
|
|
2826 /* If we are using pgrps, get a pgrp number and make it negative. */
|
|
2827 if (current_group)
|
|
2828 {
|
|
2829 #ifdef SIGNALS_VIA_CHARACTERS
|
|
2830 /* If possible, send signals to the entire pgrp
|
|
2831 by sending an input character to it. */
|
|
2832 {
|
|
2833 char sigchar = process_signal_char(p->subtty, signo);
|
|
2834 if (sigchar) {
|
|
2835 send_process (proc, Qnil, (Bufbyte *) &sigchar, 0, 1);
|
|
2836 return;
|
|
2837 }
|
|
2838 }
|
|
2839 #endif /* ! defined (SIGNALS_VIA_CHARACTERS) */
|
|
2840
|
185
|
2841 #ifdef TIOCGPGRP
|
0
|
2842 /* Get the pgrp using the tty itself, if we have that.
|
|
2843 Otherwise, use the pty to get the pgrp.
|
|
2844 On pfa systems, saka@pfu.fujitsu.co.JP writes:
|
|
2845 "TIOCGPGRP symbol defined in sys/ioctl.h at E50.
|
|
2846 But, TIOCGPGRP does not work on E50 ;-P works fine on E60"
|
|
2847 His patch indicates that if TIOCGPGRP returns an error, then
|
|
2848 we should just assume that p->pid is also the process group id. */
|
|
2849 {
|
|
2850 int err;
|
|
2851
|
|
2852 err = ioctl ( (p->subtty != -1 ? p->subtty : p->infd), TIOCGPGRP, &gid);
|
|
2853
|
|
2854 #ifdef pfa
|
|
2855 if (err == -1)
|
|
2856 gid = - XINT (p->pid);
|
|
2857 #endif /* ! defined (pfa) */
|
|
2858 }
|
|
2859 if (gid == -1)
|
|
2860 no_pgrp = 1;
|
|
2861 else
|
|
2862 gid = - gid;
|
|
2863 #else /* ! defined (TIOCGPGRP ) */
|
|
2864 /* Can't select pgrps on this system, so we know that
|
|
2865 the child itself heads the pgrp. */
|
|
2866 gid = - XINT (p->pid);
|
|
2867 #endif /* ! defined (TIOCGPGRP ) */
|
|
2868 }
|
|
2869 else
|
|
2870 gid = - XINT (p->pid);
|
|
2871
|
|
2872 switch (signo)
|
|
2873 {
|
|
2874 #ifdef SIGCONT
|
|
2875 case SIGCONT:
|
|
2876 p->status_symbol = Qrun;
|
|
2877 p->exit_code = 0;
|
|
2878 p->tick++;
|
|
2879 process_tick++;
|
|
2880 if (!nomsg)
|
|
2881 status_notify ();
|
|
2882 break;
|
|
2883 #endif /* ! defined (SIGCONT) */
|
|
2884 case SIGINT:
|
|
2885 #ifdef VMS
|
|
2886 send_process (proc, Qnil, (Bufbyte *) "\003", 0,
|
|
2887 1); /* ^C */
|
|
2888 goto whoosh;
|
|
2889 #endif
|
|
2890 case SIGQUIT:
|
|
2891 #ifdef VMS
|
|
2892 send_process (proc, Qnil, (Bufbyte *) "\031", 0,
|
|
2893 1); /* ^Y */
|
|
2894 goto whoosh;
|
|
2895 #endif
|
|
2896 case SIGKILL:
|
|
2897 #ifdef VMS
|
|
2898 sys$forcex (&(XINT (p->pid)), 0, 1);
|
|
2899 whoosh:
|
|
2900 #endif
|
|
2901 flush_pending_output (p->infd);
|
|
2902 break;
|
|
2903 }
|
|
2904
|
|
2905 /* If we don't have process groups, send the signal to the immediate
|
|
2906 subprocess. That isn't really right, but it's better than any
|
|
2907 obvious alternative. */
|
|
2908 if (no_pgrp)
|
|
2909 {
|
|
2910 kill (XINT (p->pid), signo);
|
|
2911 return;
|
|
2912 }
|
|
2913
|
|
2914 /* gid may be a pid, or minus a pgrp's number */
|
|
2915 #ifdef TIOCSIGSEND
|
|
2916 if (current_group)
|
|
2917 ioctl (p->infd, TIOCSIGSEND, signo);
|
|
2918 else
|
|
2919 {
|
|
2920 gid = - XINT (p->pid);
|
|
2921 kill (gid, signo);
|
|
2922 }
|
|
2923 #else /* ! defined (TIOCSIGSEND) */
|
|
2924 EMACS_KILLPG (-gid, signo);
|
|
2925 #endif /* ! defined (TIOCSIGSEND) */
|
|
2926 }
|
|
2927
|
20
|
2928 DEFUN ("interrupt-process", Finterrupt_process, 0, 2, 0, /*
|
0
|
2929 Interrupt process PROCESS. May be process or name of one.
|
|
2930 Nil or no arg means current buffer's process.
|
|
2931 Second arg CURRENT-GROUP non-nil means send signal to
|
|
2932 the current process-group of the process's controlling terminal
|
|
2933 rather than to the process's own process group.
|
|
2934 If the process is a shell, this means interrupt current subjob
|
|
2935 rather than the shell.
|
20
|
2936 */
|
|
2937 (process, current_group))
|
0
|
2938 {
|
|
2939 /* This function can GC */
|
|
2940 process_send_signal (process, SIGINT, !NILP (current_group), 0);
|
|
2941 return process;
|
|
2942 }
|
|
2943
|
20
|
2944 DEFUN ("kill-process", Fkill_process, 0, 2, 0, /*
|
0
|
2945 Kill process PROCESS. May be process or name of one.
|
|
2946 See function `interrupt-process' for more details on usage.
|
20
|
2947 */
|
|
2948 (process, current_group))
|
0
|
2949 {
|
|
2950 /* This function can GC */
|
|
2951 process_send_signal (process, SIGKILL, !NILP (current_group),
|
|
2952 0);
|
|
2953 return process;
|
|
2954 }
|
|
2955
|
20
|
2956 DEFUN ("quit-process", Fquit_process, 0, 2, 0, /*
|
0
|
2957 Send QUIT signal to process PROCESS. May be process or name of one.
|
|
2958 See function `interrupt-process' for more details on usage.
|
20
|
2959 */
|
|
2960 (process, current_group))
|
0
|
2961 {
|
|
2962 /* This function can GC */
|
|
2963 process_send_signal (process, SIGQUIT, !NILP (current_group),
|
|
2964 0);
|
|
2965 return process;
|
|
2966 }
|
|
2967
|
20
|
2968 DEFUN ("stop-process", Fstop_process, 0, 2, 0, /*
|
0
|
2969 Stop process PROCESS. May be process or name of one.
|
|
2970 See function `interrupt-process' for more details on usage.
|
20
|
2971 */
|
|
2972 (process, current_group))
|
0
|
2973 {
|
|
2974 /* This function can GC */
|
|
2975 #ifndef SIGTSTP
|
|
2976 error ("no SIGTSTP support");
|
|
2977 #else
|
|
2978 process_send_signal (process, SIGTSTP, !NILP (current_group),
|
|
2979 0);
|
|
2980 #endif
|
|
2981 return process;
|
|
2982 }
|
|
2983
|
20
|
2984 DEFUN ("continue-process", Fcontinue_process, 0, 2, 0, /*
|
0
|
2985 Continue process PROCESS. May be process or name of one.
|
|
2986 See function `interrupt-process' for more details on usage.
|
20
|
2987 */
|
|
2988 (process, current_group))
|
0
|
2989 {
|
|
2990 /* This function can GC */
|
|
2991 #ifdef SIGCONT
|
|
2992 process_send_signal (process, SIGCONT, !NILP (current_group),
|
|
2993 0);
|
|
2994 #else
|
|
2995 error ("no SIGCONT support");
|
|
2996 #endif
|
|
2997 return process;
|
|
2998 }
|
|
2999
|
20
|
3000 DEFUN ("signal-process", Fsignal_process, 2, 2,
|
|
3001 "nProcess number: \nnSignal code: ", /*
|
0
|
3002 Send the process with process id PID the signal with code SIGCODE.
|
|
3003 PID must be an integer. The process need not be a child of this Emacs.
|
|
3004 SIGCODE may be an integer, or a symbol whose name is a signal name.
|
20
|
3005 */
|
|
3006 (pid, sigcode))
|
0
|
3007 {
|
|
3008 CHECK_INT (pid);
|
|
3009
|
|
3010 #define handle_signal(NAME, VALUE) \
|
|
3011 else if (!strcmp ((CONST char *) name, NAME)) \
|
|
3012 XSETINT (sigcode, VALUE)
|
|
3013
|
|
3014 if (INTP (sigcode))
|
|
3015 ;
|
|
3016 else
|
|
3017 {
|
|
3018 Bufbyte *name;
|
|
3019
|
|
3020 CHECK_SYMBOL (sigcode);
|
|
3021 name = string_data (XSYMBOL (sigcode)->name);
|
|
3022
|
|
3023 if (0)
|
|
3024 ;
|
|
3025 #ifdef SIGHUP
|
|
3026 handle_signal ("SIGHUP", SIGHUP);
|
|
3027 #endif
|
|
3028 #ifdef SIGINT
|
|
3029 handle_signal ("SIGINT", SIGINT);
|
|
3030 #endif
|
|
3031 #ifdef SIGQUIT
|
|
3032 handle_signal ("SIGQUIT", SIGQUIT);
|
|
3033 #endif
|
|
3034 #ifdef SIGILL
|
|
3035 handle_signal ("SIGILL", SIGILL);
|
|
3036 #endif
|
|
3037 #ifdef SIGABRT
|
|
3038 handle_signal ("SIGABRT", SIGABRT);
|
|
3039 #endif
|
|
3040 #ifdef SIGEMT
|
|
3041 handle_signal ("SIGEMT", SIGEMT);
|
|
3042 #endif
|
|
3043 #ifdef SIGKILL
|
|
3044 handle_signal ("SIGKILL", SIGKILL);
|
|
3045 #endif
|
|
3046 #ifdef SIGFPE
|
|
3047 handle_signal ("SIGFPE", SIGFPE);
|
|
3048 #endif
|
|
3049 #ifdef SIGBUS
|
|
3050 handle_signal ("SIGBUS", SIGBUS);
|
|
3051 #endif
|
|
3052 #ifdef SIGSEGV
|
|
3053 handle_signal ("SIGSEGV", SIGSEGV);
|
|
3054 #endif
|
|
3055 #ifdef SIGSYS
|
|
3056 handle_signal ("SIGSYS", SIGSYS);
|
|
3057 #endif
|
|
3058 #ifdef SIGPIPE
|
|
3059 handle_signal ("SIGPIPE", SIGPIPE);
|
|
3060 #endif
|
|
3061 #ifdef SIGALRM
|
|
3062 handle_signal ("SIGALRM", SIGALRM);
|
|
3063 #endif
|
|
3064 #ifdef SIGTERM
|
|
3065 handle_signal ("SIGTERM", SIGTERM);
|
|
3066 #endif
|
|
3067 #ifdef SIGURG
|
|
3068 handle_signal ("SIGURG", SIGURG);
|
|
3069 #endif
|
|
3070 #ifdef SIGSTOP
|
|
3071 handle_signal ("SIGSTOP", SIGSTOP);
|
|
3072 #endif
|
|
3073 #ifdef SIGTSTP
|
|
3074 handle_signal ("SIGTSTP", SIGTSTP);
|
|
3075 #endif
|
|
3076 #ifdef SIGCONT
|
|
3077 handle_signal ("SIGCONT", SIGCONT);
|
|
3078 #endif
|
|
3079 #ifdef SIGCHLD
|
|
3080 handle_signal ("SIGCHLD", SIGCHLD);
|
|
3081 #endif
|
|
3082 #ifdef SIGTTIN
|
|
3083 handle_signal ("SIGTTIN", SIGTTIN);
|
|
3084 #endif
|
|
3085 #ifdef SIGTTOU
|
|
3086 handle_signal ("SIGTTOU", SIGTTOU);
|
|
3087 #endif
|
|
3088 #ifdef SIGIO
|
|
3089 handle_signal ("SIGIO", SIGIO);
|
|
3090 #endif
|
|
3091 #ifdef SIGXCPU
|
|
3092 handle_signal ("SIGXCPU", SIGXCPU);
|
|
3093 #endif
|
|
3094 #ifdef SIGXFSZ
|
|
3095 handle_signal ("SIGXFSZ", SIGXFSZ);
|
|
3096 #endif
|
|
3097 #ifdef SIGVTALRM
|
|
3098 handle_signal ("SIGVTALRM", SIGVTALRM);
|
|
3099 #endif
|
|
3100 #ifdef SIGPROF
|
|
3101 handle_signal ("SIGPROF", SIGPROF);
|
|
3102 #endif
|
|
3103 #ifdef SIGWINCH
|
|
3104 handle_signal ("SIGWINCH", SIGWINCH);
|
|
3105 #endif
|
|
3106 #ifdef SIGINFO
|
|
3107 handle_signal ("SIGINFO", SIGINFO);
|
|
3108 #endif
|
|
3109 #ifdef SIGUSR1
|
|
3110 handle_signal ("SIGUSR1", SIGUSR1);
|
|
3111 #endif
|
|
3112 #ifdef SIGUSR2
|
|
3113 handle_signal ("SIGUSR2", SIGUSR2);
|
|
3114 #endif
|
|
3115 else
|
|
3116 error ("Undefined signal name %s", name);
|
|
3117 }
|
|
3118
|
|
3119 #undef handle_signal
|
|
3120
|
|
3121 return make_int (kill (XINT (pid), XINT (sigcode)));
|
|
3122 }
|
|
3123
|
20
|
3124 DEFUN ("process-send-eof", Fprocess_send_eof, 0, 1, 0, /*
|
0
|
3125 Make PROCESS see end-of-file in its input.
|
|
3126 PROCESS may be a process, a buffer, the name of a process or buffer, or
|
|
3127 nil, indicating the current buffer's process.
|
|
3128 If PROCESS is a network connection, or is a process communicating
|
|
3129 through a pipe (as opposed to a pty), then you cannot send any more
|
|
3130 text to PROCESS after you call this function.
|
20
|
3131 */
|
|
3132 (process))
|
0
|
3133 {
|
|
3134 /* This function can GC */
|
|
3135 Lisp_Object proc;
|
|
3136
|
|
3137 proc = get_process (process);
|
|
3138
|
|
3139 /* Make sure the process is really alive. */
|
|
3140 if (! EQ (XPROCESS (proc)->status_symbol, Qrun))
|
16
|
3141 error ("Process %s not running", XSTRING_DATA (XPROCESS (proc)->name));
|
0
|
3142
|
|
3143 #ifdef VMS
|
|
3144 send_process (proc, Qnil, (Bufbyte *) "\032", 0, 1); /* ^Z */
|
|
3145 #else
|
|
3146 if (XPROCESS (proc)->pty_flag)
|
|
3147 {
|
|
3148 /* #### get_eof_char simply doesn't return the correct character
|
|
3149 here. Maybe it is needed to determine the right eof
|
|
3150 character in init_process_fds but here it simply screws
|
|
3151 things up. */
|
|
3152 #if 0
|
|
3153 Bufbyte eof_char = get_eof_char (XPROCESS (proc));
|
|
3154 send_process (proc, Qnil, &eof_char, 0, 1);
|
|
3155 #else
|
|
3156 send_process (proc, Qnil, (CONST Bufbyte *) "\004", 0, 1);
|
|
3157 #endif
|
|
3158 }
|
|
3159 else
|
|
3160 {
|
|
3161 close (XPROCESS (proc)->outfd);
|
|
3162 XPROCESS (proc)->outfd = open (NULL_DEVICE, O_WRONLY, 0);
|
|
3163 }
|
|
3164 #endif /* !VMS */
|
|
3165 return process;
|
|
3166 }
|
|
3167
|
|
3168
|
|
3169 /************************************************************************/
|
|
3170 /* deleting a process */
|
|
3171 /************************************************************************/
|
|
3172
|
|
3173 void
|
|
3174 deactivate_process (Lisp_Object proc)
|
|
3175 {
|
|
3176 int inchannel, outchannel;
|
|
3177 struct Lisp_Process *p = XPROCESS (proc);
|
|
3178 SIGTYPE (*old_sigpipe) (int) = 0;
|
|
3179
|
|
3180 inchannel = p->infd;
|
|
3181 outchannel = p->outfd;
|
|
3182
|
|
3183 /* closing the outstream could result in SIGPIPE, so ignore it. */
|
|
3184 old_sigpipe =
|
|
3185 (SIGTYPE (*) (int)) signal (SIGPIPE, SIG_IGN);
|
|
3186 if (!NILP (p->instream))
|
|
3187 Lstream_close (XLSTREAM (p->instream));
|
|
3188 if (!NILP (p->outstream))
|
|
3189 Lstream_close (XLSTREAM (p->outstream));
|
|
3190 signal (SIGPIPE, old_sigpipe);
|
|
3191
|
|
3192 if (inchannel >= 0)
|
|
3193 {
|
|
3194 /* Beware SIGCHLD hereabouts. */
|
|
3195 flush_pending_output (inchannel);
|
|
3196 close_descriptor_pair (inchannel, outchannel);
|
|
3197 if (!NILP (p->pid))
|
|
3198 {
|
|
3199 /* It's possible that we got as far in the process-creation
|
|
3200 process as creating the descriptors but didn't get so
|
|
3201 far as selecting the process for input. In this
|
|
3202 case, p->pid is nil: p->pid is set at the same time that
|
|
3203 the process is selected for input. */
|
|
3204 #ifdef VMS
|
|
3205 {
|
|
3206 VMS_PROC_STUFF *get_vms_process_pointer (), *vs;
|
185
|
3207 if (outchannel >= 0)
|
0
|
3208 sys$dassgn (outchannel);
|
|
3209 vs = get_vms_process_pointer (XINT (p->pid));
|
|
3210 if (vs)
|
|
3211 give_back_vms_process_stuff (vs);
|
|
3212 }
|
|
3213 #endif /* VMS */
|
|
3214 /* Must call this before setting the file descriptors to 0 */
|
|
3215 event_stream_unselect_process (p);
|
|
3216 }
|
|
3217
|
|
3218 p->infd = -1;
|
|
3219 p->outfd = -1;
|
|
3220 descriptor_to_process[inchannel] = Qnil;
|
|
3221 }
|
|
3222 }
|
|
3223
|
|
3224 static void
|
|
3225 remove_process (Lisp_Object proc)
|
|
3226 {
|
|
3227 Vprocess_list = delq_no_quit (proc, Vprocess_list);
|
|
3228 Fset_marker (XPROCESS (proc)->mark, Qnil, Qnil);
|
|
3229
|
|
3230 deactivate_process (proc);
|
|
3231 }
|
|
3232
|
20
|
3233 DEFUN ("delete-process", Fdelete_process, 1, 1, 0, /*
|
0
|
3234 Delete PROCESS: kill it and forget about it immediately.
|
|
3235 PROCESS may be a process or the name of one, or a buffer name.
|
20
|
3236 */
|
|
3237 (proc))
|
0
|
3238 {
|
|
3239 /* This function can GC */
|
|
3240 struct Lisp_Process *p;
|
|
3241 proc = get_process (proc);
|
|
3242 p = XPROCESS (proc);
|
|
3243 if (network_connection_p (proc))
|
|
3244 {
|
|
3245 p->status_symbol = Qexit;
|
|
3246 p->exit_code = 0;
|
|
3247 p->core_dumped = 0;
|
|
3248 p->tick++;
|
|
3249 process_tick++;
|
|
3250 }
|
|
3251 else if (p->infd >= 0)
|
|
3252 {
|
|
3253 Fkill_process (proc, Qnil);
|
|
3254 /* Do this now, since remove_process will make sigchld_handler do nothing. */
|
|
3255 p->status_symbol = Qsignal;
|
|
3256 p->exit_code = SIGKILL;
|
|
3257 p->core_dumped = 0;
|
|
3258 p->tick++;
|
|
3259 process_tick++;
|
|
3260 status_notify ();
|
|
3261 }
|
|
3262 remove_process (proc);
|
|
3263 return Qnil;
|
|
3264 }
|
|
3265
|
|
3266 /* Kill all processes associated with `buffer'.
|
|
3267 If `buffer' is nil, kill all processes */
|
|
3268
|
|
3269 void
|
|
3270 kill_buffer_processes (Lisp_Object buffer)
|
|
3271 {
|
|
3272 Lisp_Object tail;
|
|
3273
|
|
3274 for (tail = Vprocess_list; GC_CONSP (tail);
|
|
3275 tail = XCDR (tail))
|
|
3276 {
|
|
3277 Lisp_Object proc = XCAR (tail);
|
|
3278 if (GC_PROCESSP (proc)
|
|
3279 && (GC_NILP (buffer) || GC_EQ (XPROCESS (proc)->buffer, buffer)))
|
|
3280 {
|
|
3281 if (network_connection_p (proc))
|
|
3282 Fdelete_process (proc);
|
|
3283 else if (XPROCESS (proc)->infd >= 0)
|
|
3284 process_send_signal (proc, SIGHUP, 0, 1);
|
|
3285 }
|
|
3286 }
|
|
3287 }
|
|
3288
|
|
3289 #if 0 /* Unused */
|
|
3290 int
|
|
3291 count_active_processes (void)
|
|
3292 {
|
|
3293 Lisp_Object tail;
|
|
3294 int count = 0;
|
|
3295
|
|
3296 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
|
|
3297 {
|
|
3298 Lisp_Object status = XPROCESS (XCAR (tail))->status_symbol;
|
|
3299 if ((EQ (status, Qrun) || EQ (status, Qstop)))
|
|
3300 count++;
|
|
3301 }
|
|
3302
|
|
3303 return count;
|
|
3304 }
|
|
3305 #endif /* Unused */
|
|
3306
|
20
|
3307 DEFUN ("process-kill-without-query", Fprocess_kill_without_query, 1, 2, 0, /*
|
0
|
3308 Say no query needed if PROCESS is running when Emacs is exited.
|
|
3309 Optional second argument if non-nil says to require a query.
|
|
3310 Value is t if a query was formerly required.
|
20
|
3311 */
|
|
3312 (proc, require_query_p))
|
0
|
3313 {
|
|
3314 int tem;
|
|
3315
|
|
3316 CHECK_PROCESS (proc);
|
|
3317 tem = XPROCESS (proc)->kill_without_query;
|
|
3318 XPROCESS (proc)->kill_without_query = NILP (require_query_p);
|
|
3319
|
173
|
3320 return tem ? Qnil : Qt;
|
0
|
3321 }
|
|
3322
|
20
|
3323 DEFUN ("process-kill-without-query-p", Fprocess_kill_without_query_p, 1, 1, 0, /*
|
0
|
3324 Whether PROC will be killed without query if running when emacs is exited.
|
20
|
3325 */
|
|
3326 (proc))
|
0
|
3327 {
|
|
3328 CHECK_PROCESS (proc);
|
173
|
3329 return XPROCESS (proc)->kill_without_query ? Qt : Qnil;
|
0
|
3330 }
|
|
3331
|
|
3332
|
|
3333 /* This is not named init_process in order to avoid a conflict with NS 3.3 */
|
|
3334 void
|
|
3335 init_xemacs_process (void)
|
|
3336 {
|
|
3337 int i;
|
|
3338
|
|
3339 #ifdef SIGCHLD
|
|
3340 # ifndef CANNOT_DUMP
|
|
3341 if (! noninteractive || initialized)
|
|
3342 # endif
|
|
3343 signal (SIGCHLD, sigchld_handler);
|
|
3344 #endif /* SIGCHLD */
|
|
3345
|
|
3346 Vprocess_list = Qnil;
|
|
3347 for (i = 0; i < MAXDESC; i++)
|
|
3348 {
|
|
3349 descriptor_to_process[i] = Qnil;
|
|
3350 proc_buffered_char[i] = -1;
|
|
3351 }
|
|
3352 }
|
149
|
3353
|
0
|
3354 #if 0
|
|
3355
|
149
|
3356 xxDEFUN ("process-connection", Fprocess_connection, 0, 1, 0, /*
|
0
|
3357 Return the connection type of `PROCESS'. This can be nil (pipe),
|
|
3358 t or pty (pty) or stream (socket connection).
|
149
|
3359 */
|
|
3360 (process))
|
0
|
3361 {
|
|
3362 return XPROCESS (process)->type;
|
|
3363 }
|
|
3364
|
|
3365 #endif /* 0 */
|
|
3366
|
|
3367 void
|
|
3368 syms_of_process (void)
|
|
3369 {
|
|
3370 defsymbol (&Qprocessp, "processp");
|
|
3371 defsymbol (&Qrun, "run");
|
|
3372 defsymbol (&Qstop, "stop");
|
|
3373 defsymbol (&Qsignal, "signal");
|
|
3374 /* Qexit is already defined by syms_of_eval
|
185
|
3375 * defsymbol (&Qexit, "exit");
|
0
|
3376 */
|
|
3377 defsymbol (&Qopen, "open");
|
|
3378 defsymbol (&Qclosed, "closed");
|
|
3379
|
20
|
3380 DEFSUBR (Fprocessp);
|
|
3381 DEFSUBR (Fget_process);
|
|
3382 DEFSUBR (Fget_buffer_process);
|
|
3383 DEFSUBR (Fdelete_process);
|
|
3384 DEFSUBR (Fprocess_status);
|
|
3385 DEFSUBR (Fprocess_exit_status);
|
|
3386 DEFSUBR (Fprocess_id);
|
|
3387 DEFSUBR (Fprocess_name);
|
|
3388 DEFSUBR (Fprocess_tty_name);
|
|
3389 DEFSUBR (Fprocess_command);
|
|
3390 DEFSUBR (Fset_process_buffer);
|
|
3391 DEFSUBR (Fprocess_buffer);
|
|
3392 DEFSUBR (Fprocess_mark);
|
|
3393 DEFSUBR (Fset_process_filter);
|
|
3394 DEFSUBR (Fprocess_filter);
|
|
3395 DEFSUBR (Fset_process_window_size);
|
|
3396 DEFSUBR (Fset_process_sentinel);
|
|
3397 DEFSUBR (Fprocess_sentinel);
|
|
3398 DEFSUBR (Fprocess_kill_without_query);
|
|
3399 DEFSUBR (Fprocess_kill_without_query_p);
|
|
3400 DEFSUBR (Fprocess_list);
|
|
3401 DEFSUBR (Fstart_process_internal);
|
0
|
3402 #ifdef HAVE_SOCKETS
|
20
|
3403 DEFSUBR (Fopen_network_stream_internal);
|
0
|
3404 #endif /* HAVE_SOCKETS */
|
20
|
3405 DEFSUBR (Fprocess_send_region);
|
|
3406 DEFSUBR (Fprocess_send_string);
|
|
3407 DEFSUBR (Finterrupt_process);
|
|
3408 DEFSUBR (Fkill_process);
|
|
3409 DEFSUBR (Fquit_process);
|
|
3410 DEFSUBR (Fstop_process);
|
|
3411 DEFSUBR (Fcontinue_process);
|
|
3412 DEFSUBR (Fprocess_send_eof);
|
|
3413 DEFSUBR (Fsignal_process);
|
|
3414 /* DEFSUBR (Fprocess_connection); */
|
70
|
3415 #ifdef MULE
|
|
3416 DEFSUBR (Fprocess_input_coding_system);
|
|
3417 DEFSUBR (Fprocess_output_coding_system);
|
|
3418 DEFSUBR (Fset_process_input_coding_system);
|
|
3419 DEFSUBR (Fset_process_output_coding_system);
|
120
|
3420 DEFSUBR (Fprocess_coding_system);
|
|
3421 DEFSUBR (Fset_process_coding_system);
|
70
|
3422 #endif /* MULE */
|
0
|
3423 }
|
|
3424
|
|
3425 void
|
|
3426 vars_of_process (void)
|
|
3427 {
|
|
3428 Fprovide (intern ("subprocesses"));
|
|
3429 #ifdef HAVE_SOCKETS
|
|
3430 Fprovide (intern ("network-streams"));
|
|
3431 #endif
|
|
3432 staticpro (&Vprocess_list);
|
|
3433
|
|
3434 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes /*
|
|
3435 *Non-nil means delete processes immediately when they exit.
|
|
3436 nil means don't delete them until `list-processes' is run.
|
|
3437 */ );
|
|
3438
|
|
3439 delete_exited_processes = 1;
|
|
3440
|
|
3441 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type /*
|
|
3442 Control type of device used to communicate with subprocesses.
|
|
3443 Values are nil to use a pipe, or t or `pty' to use a pty.
|
|
3444 The value has no effect if the system has no ptys or if all ptys are busy:
|
|
3445 then a pipe is used in any case.
|
|
3446 The value takes effect when `start-process' is called.
|
|
3447 */ );
|
|
3448 Vprocess_connection_type = Qt;
|
153
|
3449
|
|
3450 #ifdef PROCESS_IO_BLOCKING
|
|
3451 DEFVAR_LISP ("network-stream-blocking-port-list", &network_stream_blocking_port_list /*
|
|
3452 List of port numbers or port names to set a blocking I/O mode with connection.
|
|
3453 Nil value means to set a default(non-blocking) I/O mode.
|
|
3454 The value takes effect when `open-network-stream-internal' is called.
|
|
3455 */ );
|
|
3456 network_stream_blocking_port_list = Qnil;
|
|
3457 #endif /* PROCESS_IO_BLOCKING */
|
0
|
3458 }
|
|
3459
|
|
3460 #endif /* not NO_SUBPROCESSES */
|