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