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