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