0
|
1 /* Asynchronous subprocess control for XEmacs.
|
|
2 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 1995
|
|
3 Free Software Foundation, Inc.
|
|
4 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
5 Copyright (C) 1995, 1996 Ben Wing.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Mule 2.0, FSF 19.30. */
|
|
25
|
|
26 /* This file has been Mule-ized except for `start-process-internal'
|
|
27 and `open-network-stream-internal'. */
|
|
28
|
|
29 #include <config.h>
|
|
30
|
|
31 #if !defined (NO_SUBPROCESSES)
|
|
32
|
|
33 /* The entire file is within this conditional */
|
|
34
|
|
35 #include "lisp.h"
|
|
36
|
|
37 #include "buffer.h"
|
|
38 #include "commands.h"
|
|
39 #include "events.h"
|
|
40 #include "frame.h"
|
|
41 #include "insdel.h"
|
|
42 #include "lstream.h"
|
|
43 #include "opaque.h"
|
|
44 #include "process.h"
|
|
45 #include "sysdep.h"
|
|
46 #include "window.h"
|
70
|
47 #ifdef MULE
|
|
48 #include "mule-coding.h"
|
|
49 #endif
|
0
|
50
|
|
51 #include <setjmp.h>
|
|
52 #include "sysfile.h"
|
|
53 #include "sysproc.h"
|
|
54 #include "systime.h"
|
|
55 #include "syssignal.h" /* Always include before systty.h */
|
|
56
|
|
57 #include "systty.h"
|
|
58 #include "syswait.h"
|
|
59
|
|
60 /* a process object is a network connection when its pid field a cons
|
|
61 (name of name of port we are connected to . foreign host name) */
|
|
62
|
|
63 /* Valid values of process->status_symbol */
|
|
64 Lisp_Object Qrun, Qstop; /* Qexit from eval.c, Qsignal from data.c. */
|
|
65 /* Qrun => Qopen, Qexit => Qclosed for "network connection" processes */
|
|
66 Lisp_Object Qopen, Qclosed;
|
|
67
|
|
68 /* t means use pty, nil means use a pipe,
|
|
69 maybe other values to come. */
|
|
70 static Lisp_Object Vprocess_connection_type;
|
|
71
|
153
|
72 #ifdef PROCESS_IO_BLOCKING
|
|
73 /* List of port numbers or port names to set a blocking I/O mode.
|
|
74 Nil means set a non-blocking I/O mode [default]. */
|
|
75 static Lisp_Object network_stream_blocking_port_list;
|
|
76 #endif /* PROCESS_IO_BLOCKING */
|
|
77
|
0
|
78 /* FSFmacs says:
|
|
79
|
|
80 These next two vars are non-static since sysdep.c uses them in the
|
|
81 emulation of `select'. */
|
|
82 /* Number of events of change of status of a process. */
|
|
83 static volatile int process_tick;
|
|
84
|
|
85 /* Number of events for which the user or sentinel has been notified. */
|
|
86 static int update_tick;
|
|
87
|
|
88 /* Nonzero means delete a process right away if it exits. */
|
|
89 int delete_exited_processes;
|
|
90
|
|
91 /* Indexed by descriptor, gives the process (if any) for that descriptor */
|
|
92 Lisp_Object descriptor_to_process[MAXDESC];
|
|
93
|
|
94 /* List of process objects. */
|
|
95 Lisp_Object Vprocess_list;
|
|
96
|
|
97 Lisp_Object Qprocessp;
|
|
98
|
|
99 /* Buffered-ahead input char from process, indexed by channel.
|
|
100 -1 means empty (no char is buffered).
|
|
101 Used on sys V where the only way to tell if there is any
|
|
102 output from the process is to read at least one char.
|
|
103 Always -1 on systems that support FIONREAD. */
|
|
104
|
|
105 /* FSFmacs says:
|
|
106 Don't make static; need to access externally. */
|
|
107 static int proc_buffered_char[MAXDESC];
|
|
108
|
|
109 #ifdef HAVE_PTYS
|
|
110 /* The file name of the pty opened by allocate_pty. */
|
|
111
|
|
112 static char pty_name[24];
|
|
113 #endif
|
|
114
|
|
115
|
|
116 /************************************************************************/
|
|
117 /* the process Lisp object */
|
|
118 /************************************************************************/
|
|
119
|
|
120 /*
|
|
121 * Structure records pertinent information about open channels.
|
|
122 * There is one channel associated with each process.
|
|
123 */
|
|
124
|
|
125 struct Lisp_Process
|
|
126 {
|
|
127 struct lcrecord_header header;
|
|
128 /* Name of this process */
|
|
129 Lisp_Object name;
|
|
130 /* List of command arguments that this process was run with */
|
|
131 Lisp_Object command;
|
|
132 /* (funcall FILTER PROC STRING) (if FILTER is non-nil)
|
|
133 to dispose of a bunch of chars from the process all at once */
|
|
134 Lisp_Object filter;
|
|
135 /* (funcall SENTINEL PROCESS) when process state changes */
|
|
136 Lisp_Object sentinel;
|
|
137 /* Buffer that output is going to */
|
|
138 Lisp_Object buffer;
|
|
139 /* Marker set to end of last buffer-inserted output from this process */
|
|
140 Lisp_Object mark;
|
|
141 /* Lisp_Int of subprocess' PID, or a cons of
|
|
142 service/host if this is really a network connection */
|
|
143 Lisp_Object pid;
|
|
144 /* Non-0 if this is really a ToolTalk channel. */
|
|
145 int connected_via_filedesc_p;
|
|
146 #if 0 /* FSFmacs */
|
|
147 /* Perhaps it's cleaner this way, but FSFmacs
|
|
148 provides no way of retrieving this value, so I'll
|
|
149 leave this info with PID. */
|
|
150 /* Non-nil if this is really a child process */
|
|
151 Lisp_Object childp;
|
|
152 #endif
|
|
153
|
|
154 /* Symbol indicating status of process.
|
|
155 This may be a symbol: run, stop, exit, signal */
|
|
156 Lisp_Object status_symbol;
|
|
157
|
|
158
|
|
159 /* Exit code if process has terminated,
|
|
160 signal which stopped/interrupted process
|
|
161 or 0 if process is running */
|
|
162 int exit_code;
|
|
163 /* Number of this process */
|
|
164 /* Non-false if process has exited and "dumped core" on its way down */
|
|
165 char core_dumped;
|
|
166 /* Descriptor by which we read from this process. -1 for dead process */
|
|
167 int infd;
|
|
168 /* Descriptor by which we write to this process. -1 for dead process */
|
|
169 int outfd;
|
|
170 /* Descriptor for the tty which this process is using.
|
|
171 -1 if we didn't record it (on some systems, there's no need). */
|
|
172 int subtty;
|
|
173 /* Name of subprocess terminal. */
|
|
174 Lisp_Object tty_name;
|
|
175 /* Non-false if communicating through a pty. */
|
|
176 char pty_flag;
|
|
177 /* This next field is only actually used #ifdef ENERGIZE */
|
|
178 /* if this flag is not NIL, then filter will do the read on the
|
|
179 channel, rather than having a call to make_string.
|
|
180 This only works if the filter is a subr. */
|
|
181 char filter_does_read;
|
|
182 /* Non-nil means kill silently if Emacs is exited. */
|
|
183 char kill_without_query;
|
|
184 char selected;
|
|
185 /* Event-count of last event in which this process changed status. */
|
|
186 volatile int tick;
|
|
187 /* Event-count of last such event reported. */
|
|
188 int update_tick;
|
|
189 /* streams used in input and output */
|
|
190 Lisp_Object instream;
|
|
191 Lisp_Object outstream;
|
|
192 /* The actual filedesc stream used for output; may be different
|
|
193 than OUTSTREAM under Mule */
|
|
194 Lisp_Object filedesc_stream;
|
|
195 };
|
|
196
|
|
197 static Lisp_Object mark_process (Lisp_Object, void (*) (Lisp_Object));
|
|
198 static void print_process (Lisp_Object, Lisp_Object, int);
|
|
199 static void finalize_process (void *, int);
|
|
200 DEFINE_LRECORD_IMPLEMENTATION ("process", process,
|
|
201 mark_process, print_process, finalize_process,
|
|
202 0, 0, struct Lisp_Process);
|
|
203
|
|
204 static Lisp_Object
|
|
205 mark_process (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
206 {
|
|
207 struct Lisp_Process *proc = XPROCESS (obj);
|
|
208 ((markobj) (proc->name));
|
|
209 ((markobj) (proc->command));
|
|
210 ((markobj) (proc->filter));
|
|
211 ((markobj) (proc->sentinel));
|
|
212 ((markobj) (proc->buffer));
|
|
213 ((markobj) (proc->mark));
|
|
214 ((markobj) (proc->pid));
|
|
215 ((markobj) (proc->tty_name));
|
|
216 ((markobj) (proc->instream));
|
|
217 ((markobj) (proc->outstream));
|
|
218 ((markobj) (proc->filedesc_stream));
|
173
|
219 return proc->status_symbol;
|
0
|
220 }
|
|
221
|
|
222 static void
|
|
223 print_process (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
224 {
|
|
225 struct Lisp_Process *proc = XPROCESS (obj);
|
185
|
226
|
0
|
227 if (print_readably)
|
|
228 error ("printing unreadable object #<process %s>",
|
16
|
229 XSTRING_DATA (proc->name));
|
185
|
230
|
0
|
231 if (!escapeflag)
|
|
232 {
|
|
233 print_internal (proc->name, printcharfun, 0);
|
|
234 }
|
|
235 else
|
|
236 {
|
|
237 int netp = network_connection_p (obj);
|
|
238 write_c_string (((netp) ? GETTEXT ("#<network connection ") :
|
|
239 GETTEXT ("#<process ")), printcharfun);
|
|
240 print_internal (proc->name, printcharfun, 1);
|
|
241 write_c_string (((netp) ? " " : " pid "), printcharfun);
|
|
242 print_internal (proc->pid, printcharfun, 1);
|
|
243 write_c_string (" state:", printcharfun);
|
|
244 print_internal (proc->status_symbol, printcharfun, 1);
|
|
245 write_c_string (">", printcharfun);
|
|
246 }
|
|
247 }
|
|
248
|
|
249 #ifdef HAVE_WINDOW_SYSTEM
|
|
250 extern void debug_process_finalization (struct Lisp_Process *p);
|
|
251 #endif /* HAVE_WINDOW_SYSTEM */
|
|
252
|
|
253 static void
|
|
254 finalize_process (void *header, int for_disksave)
|
|
255 {
|
|
256 if (for_disksave) return; /* hmm, what would this do anyway? */
|
|
257 /* #### this probably needs to be tied into the tty event loop */
|
|
258 /* #### when there is one */
|
|
259 #ifdef HAVE_WINDOW_SYSTEM
|
|
260 {
|
|
261 struct Lisp_Process *p = (struct Lisp_Process *) header;
|
|
262 debug_process_finalization (p);
|
|
263 }
|
|
264 #endif /* HAVE_WINDOW_SYSTEM */
|
|
265 }
|
|
266
|
|
267
|
|
268 /************************************************************************/
|
|
269 /* basic process accessors */
|
|
270 /************************************************************************/
|
|
271
|
|
272 static SIGTYPE
|
|
273 close_safely_handler (int signo)
|
|
274 {
|
|
275 EMACS_REESTABLISH_SIGNAL (signo, close_safely_handler);
|
|
276 SIGRETURN;
|
|
277 }
|
|
278
|
|
279 static void
|
|
280 close_safely (int fd)
|
|
281 {
|
|
282 stop_interrupts ();
|
|
283 signal (SIGALRM, close_safely_handler);
|
|
284 alarm (1);
|
|
285 close (fd);
|
|
286 alarm (0);
|
|
287 start_interrupts ();
|
|
288 }
|
|
289
|
|
290 static void
|
|
291 close_descriptor_pair (int in, int out)
|
|
292 {
|
|
293 if (in >= 0)
|
|
294 close (in);
|
|
295 if (out != in && out >= 0)
|
|
296 close (out);
|
|
297 }
|
|
298
|
|
299 /* Close all descriptors currently in use for communication
|
|
300 with subprocess. This is used in a newly-forked subprocess
|
|
301 to get rid of irrelevant descriptors. */
|
|
302
|
|
303 void
|
|
304 close_process_descs (void)
|
|
305 {
|
|
306 #ifndef WINDOWSNT
|
|
307 int i;
|
|
308 for (i = 0; i < MAXDESC; i++)
|
|
309 {
|
|
310 Lisp_Object process;
|
|
311 process = descriptor_to_process[i];
|
|
312 if (!NILP (process))
|
|
313 {
|
|
314 close_descriptor_pair (XPROCESS (process)->infd,
|
|
315 XPROCESS (process)->outfd);
|
|
316 }
|
|
317 }
|
|
318 #endif
|
|
319 }
|
|
320
|
|
321 void
|
|
322 get_process_file_descriptors (struct Lisp_Process *p, int *infd,
|
|
323 int *outfd)
|
|
324 {
|
|
325 if (! p) abort ();
|
|
326 /* the cast of MAXDESC is needed for some versions of Linux */
|
|
327 assert (p->infd >= -1 && p->infd < ((int) (MAXDESC)));
|
|
328 assert (p->outfd >= -1 && p->outfd < ((int) (MAXDESC)));
|
|
329 *infd = p->infd;
|
|
330 *outfd = p->outfd;
|
|
331 }
|
|
332
|
|
333 struct Lisp_Process *
|
|
334 get_process_from_input_descriptor (int infd)
|
|
335 {
|
|
336 Lisp_Object proc;
|
|
337
|
|
338 if ((infd < 0) || (infd >= ((int) (MAXDESC)))) abort ();
|
|
339 proc = descriptor_to_process[infd];
|
|
340 if (NILP (proc))
|
|
341 return 0;
|
|
342 else
|
|
343 return XPROCESS (proc);
|
|
344 }
|
|
345
|
|
346 int
|
|
347 get_process_selected_p (struct Lisp_Process *p)
|
|
348 {
|
|
349 return p->selected;
|
|
350 }
|
|
351
|
|
352 void
|
|
353 set_process_selected_p (struct Lisp_Process *p, int selected_p)
|
|
354 {
|
|
355 p->selected = !!selected_p;
|
|
356 }
|
|
357
|
|
358 #ifdef HAVE_SOCKETS
|
|
359 int
|
|
360 network_connection_p (Lisp_Object process)
|
|
361 {
|
173
|
362 return GC_CONSP (XPROCESS (process)->pid);
|
0
|
363 }
|
|
364 #endif
|
|
365
|
|
366 int
|
|
367 connected_via_filedesc_p (struct Lisp_Process *p)
|
|
368 {
|
|
369 return p->connected_via_filedesc_p;
|
|
370 }
|
|
371
|
20
|
372 DEFUN ("processp", Fprocessp, 1, 1, 0, /*
|
0
|
373 Return t if OBJECT is a process.
|
20
|
374 */
|
|
375 (obj))
|
0
|
376 {
|
173
|
377 return PROCESSP (obj) ? Qt : Qnil;
|
0
|
378 }
|
|
379
|
20
|
380 DEFUN ("process-list", Fprocess_list, 0, 0, 0, /*
|
0
|
381 Return a list of all processes.
|
20
|
382 */
|
|
383 ())
|
0
|
384 {
|
|
385 return Fcopy_sequence (Vprocess_list);
|
|
386 }
|
|
387
|
20
|
388 DEFUN ("get-process", Fget_process, 1, 1, 0, /*
|
0
|
389 Return the process named NAME, or nil if there is none.
|
20
|
390 */
|
|
391 (name))
|
0
|
392 {
|
|
393 Lisp_Object tail;
|
|
394
|
|
395 if (GC_PROCESSP (name))
|
173
|
396 return name;
|
0
|
397
|
|
398 if (!gc_in_progress)
|
|
399 /* this only gets called during GC when emacs is going away as a result
|
|
400 of a signal or crash. */
|
|
401 CHECK_STRING (name);
|
|
402
|
|
403 for (tail = Vprocess_list; GC_CONSP (tail); tail = XCDR (tail))
|
|
404 {
|
|
405 Lisp_Object proc = XCAR (tail);
|
|
406 QUIT;
|
195
|
407 if (internal_equal (name, XPROCESS (proc)->name, 0))
|
173
|
408 return XCAR (tail);
|
0
|
409 }
|
|
410 return Qnil;
|
|
411 }
|
|
412
|
20
|
413 DEFUN ("get-buffer-process", Fget_buffer_process, 1, 1, 0, /*
|
0
|
414 Return the (or, a) process associated with BUFFER.
|
|
415 BUFFER may be a buffer or the name of one.
|
20
|
416 */
|
|
417 (name))
|
0
|
418 {
|
|
419 Lisp_Object buf, tail, proc;
|
|
420
|
|
421 if (GC_NILP (name)) return Qnil;
|
|
422 buf = Fget_buffer (name);
|
|
423 if (GC_NILP (buf)) return Qnil;
|
|
424
|
|
425 #ifdef ENERGIZE
|
|
426 {
|
|
427 Lisp_Object p = energize_get_buffer_process (buf);
|
|
428 if (!GC_NILP (p)) return p;
|
|
429 }
|
|
430 #endif
|
|
431
|
|
432 for (tail = Vprocess_list; GC_CONSP (tail); tail = XCDR (tail))
|
|
433 {
|
|
434 /* jwz: do not quit here - it isn't necessary, as there is no way for
|
|
435 Vprocess_list to get circular or overwhelmingly long, and this
|
|
436 function is called from layout_mode_element under redisplay. */
|
|
437 /* QUIT; */
|
|
438 proc = XCAR (tail);
|
|
439 if (GC_PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf))
|
|
440 return proc;
|
|
441 }
|
|
442 return Qnil;
|
|
443 }
|
|
444
|
|
445 /* This is how commands for the user decode process arguments. It
|
|
446 accepts a process, a process name, a buffer, a buffer name, or nil.
|
|
447 Buffers denote the first process in the buffer, and nil denotes the
|
|
448 current buffer. */
|
|
449
|
|
450 static Lisp_Object
|
|
451 get_process (Lisp_Object name)
|
|
452 {
|
136
|
453 Lisp_Object proc, obj;
|
0
|
454
|
|
455 #ifdef I18N3
|
|
456 /* #### Look more closely into translating process names. */
|
|
457 #endif
|
|
458
|
|
459 /* This may be called during a GC from process_send_signal() from
|
|
460 kill_buffer_processes() if emacs decides to abort(). */
|
|
461 if (GC_PROCESSP (name))
|
|
462 return name;
|
|
463
|
136
|
464 if (GC_STRINGP (name))
|
|
465 {
|
|
466 obj = Fget_process (name);
|
|
467 if (GC_NILP (obj))
|
|
468 obj = Fget_buffer (name);
|
|
469 if (GC_NILP (obj))
|
|
470 error ("Process %s does not exist", XSTRING_DATA (name));
|
|
471 }
|
|
472 else if (GC_NILP (name))
|
|
473 obj = Fcurrent_buffer ();
|
|
474 else
|
|
475 obj = name;
|
|
476
|
|
477 /* Now obj should be either a buffer object or a process object.
|
|
478 */
|
|
479 if (GC_BUFFERP (obj))
|
|
480 {
|
|
481 proc = Fget_buffer_process (obj);
|
|
482 if (GC_NILP (proc))
|
|
483 error ("Buffer %s has no process", XSTRING_DATA (XBUFFER(obj)->name));
|
|
484 }
|
0
|
485 else
|
|
486 {
|
136
|
487 /* fsf: CHECK_PROCESS (obj, 0); */
|
|
488 proc = obj;
|
0
|
489 }
|
136
|
490 return proc;
|
0
|
491 }
|
|
492
|
20
|
493 DEFUN ("process-id", Fprocess_id, 1, 1, 0, /*
|
0
|
494 Return the process id of PROCESS.
|
|
495 This is the pid of the Unix process which PROCESS uses or talks to.
|
|
496 For a network connection, this value is a cons of
|
|
497 (foreign-network-port . foreign-host-name).
|
20
|
498 */
|
|
499 (proc))
|
0
|
500 {
|
|
501 Lisp_Object pid;
|
|
502 CHECK_PROCESS (proc);
|
|
503
|
|
504 pid = XPROCESS (proc)->pid;
|
|
505 if (network_connection_p (proc))
|
173
|
506 /* return Qnil; */
|
|
507 return Fcons (Fcar (pid), Fcdr (pid));
|
0
|
508 else
|
173
|
509 return pid;
|
0
|
510 }
|
|
511
|
20
|
512 DEFUN ("process-name", Fprocess_name, 1, 1, 0, /*
|
0
|
513 Return the name of PROCESS, as a string.
|
|
514 This is the name of the program invoked in PROCESS,
|
|
515 possibly modified to make it unique among process names.
|
20
|
516 */
|
|
517 (proc))
|
0
|
518 {
|
|
519 CHECK_PROCESS (proc);
|
|
520 return XPROCESS (proc)->name;
|
|
521 }
|
|
522
|
20
|
523 DEFUN ("process-command", Fprocess_command, 1, 1, 0, /*
|
0
|
524 Return the command that was executed to start PROCESS.
|
|
525 This is a list of strings, the first string being the program executed
|
|
526 and the rest of the strings being the arguments given to it.
|
20
|
527 */
|
|
528 (proc))
|
0
|
529 {
|
|
530 CHECK_PROCESS (proc);
|
|
531 return XPROCESS (proc)->command;
|
|
532 }
|
|
533
|
|
534
|
|
535 /************************************************************************/
|
|
536 /* creating a process */
|
|
537 /************************************************************************/
|
|
538
|
|
539 static Lisp_Object
|
|
540 make_process_internal (Lisp_Object name)
|
|
541 {
|
|
542 Lisp_Object val, name1;
|
|
543 int i;
|
185
|
544 struct Lisp_Process *p =
|
|
545 alloc_lcrecord_type (struct Lisp_Process, lrecord_process);
|
0
|
546
|
|
547 /* If name is already in use, modify it until it is unused. */
|
|
548 name1 = name;
|
|
549 for (i = 1; ; i++)
|
|
550 {
|
|
551 char suffix[10];
|
|
552 Lisp_Object tem = Fget_process (name1);
|
185
|
553 if (NILP (tem))
|
0
|
554 break;
|
|
555 sprintf (suffix, "<%d>", i);
|
|
556 name1 = concat2 (name, build_string (suffix));
|
|
557 }
|
|
558 name = name1;
|
|
559 p->name = name;
|
|
560
|
|
561 p->command = Qnil;
|
|
562 p->filter = Qnil;
|
|
563 p->sentinel = Qnil;
|
|
564 p->buffer = Qnil;
|
|
565 p->mark = Fmake_marker ();
|
|
566 p->pid = Qnil;
|
|
567 p->status_symbol = Qrun;
|
|
568 p->connected_via_filedesc_p = 0;
|
|
569 p->exit_code = 0;
|
|
570 p->core_dumped = 0;
|
|
571 p->infd = -1;
|
|
572 p->outfd = -1;
|
|
573 p->subtty = -1;
|
|
574 p->tty_name = Qnil;
|
|
575 p->pty_flag = 0;
|
|
576 p->filter_does_read = 0;
|
|
577 p->kill_without_query = 0;
|
|
578 p->selected = 0;
|
|
579 p->tick = 0;
|
|
580 p->update_tick = 0;
|
|
581 p->instream = Qnil;
|
|
582 p->outstream = Qnil;
|
|
583
|
|
584 XSETPROCESS (val, p);
|
|
585
|
|
586 Vprocess_list = Fcons (val, Vprocess_list);
|
173
|
587 return val;
|
0
|
588 }
|
|
589
|
|
590 #ifdef HAVE_PTYS
|
|
591
|
|
592 /* Open an available pty, returning a file descriptor.
|
|
593 Return -1 on failure.
|
|
594 The file name of the terminal corresponding to the pty
|
|
595 is left in the variable pty_name. */
|
|
596
|
|
597 static int
|
|
598 allocate_pty (void)
|
|
599 {
|
|
600 struct stat stb;
|
|
601 int c, i;
|
|
602 int fd;
|
|
603
|
|
604 /* Some systems name their pseudoterminals so that there are gaps in
|
|
605 the usual sequence - for example, on HP9000/S700 systems, there
|
|
606 are no pseudoterminals with names ending in 'f'. So we wait for
|
|
607 three failures in a row before deciding that we've reached the
|
|
608 end of the ptys. */
|
|
609 int failed_count = 0;
|
|
610
|
|
611 #ifdef PTY_ITERATION
|
|
612 PTY_ITERATION
|
|
613 #else
|
|
614 for (c = FIRST_PTY_LETTER; c <= 'z'; c++)
|
|
615 for (i = 0; i < 16; i++)
|
|
616 #endif
|
|
617 {
|
|
618 #ifdef PTY_NAME_SPRINTF
|
|
619 PTY_NAME_SPRINTF
|
|
620 #else
|
|
621 sprintf (pty_name, "/dev/pty%c%x", c, i);
|
|
622 #endif /* no PTY_NAME_SPRINTF */
|
|
623
|
|
624 #ifdef PTY_OPEN
|
|
625 PTY_OPEN;
|
|
626 #else /* no PTY_OPEN */
|
|
627 #ifdef IRIS
|
|
628 /* Unusual IRIS code */
|
|
629 *ptyv = open ("/dev/ptc", O_RDWR | O_NDELAY, 0);
|
|
630 if (fd < 0)
|
|
631 return -1;
|
|
632 if (fstat (fd, &stb) < 0)
|
|
633 return -1;
|
|
634 #else /* not IRIS */
|
|
635 if (stat (pty_name, &stb) < 0)
|
|
636 {
|
|
637 failed_count++;
|
|
638 if (failed_count >= 3)
|
|
639 return -1;
|
|
640 }
|
|
641 else
|
|
642 failed_count = 0;
|
|
643 #ifdef O_NONBLOCK
|
|
644 fd = open (pty_name, O_RDWR | O_NONBLOCK, 0);
|
|
645 #else
|
|
646 fd = open (pty_name, O_RDWR | O_NDELAY, 0);
|
|
647 #endif
|
|
648 #endif /* not IRIS */
|
|
649 #endif /* no PTY_OPEN */
|
|
650
|
|
651 if (fd >= 0)
|
|
652 {
|
|
653 /* check to make certain that both sides are available
|
|
654 this avoids a nasty yet stupid bug in rlogins */
|
|
655 #ifdef PTY_TTY_NAME_SPRINTF
|
|
656 PTY_TTY_NAME_SPRINTF
|
|
657 #else
|
|
658 sprintf (pty_name, "/dev/tty%c%x", c, i);
|
|
659 #endif /* no PTY_TTY_NAME_SPRINTF */
|
|
660 #ifndef UNIPLUS
|
|
661 if (access (pty_name, 6) != 0)
|
|
662 {
|
|
663 close (fd);
|
|
664 #if !defined(IRIS) && !defined(__sgi)
|
|
665 continue;
|
|
666 #else
|
|
667 return -1;
|
|
668 #endif /* IRIS */
|
|
669 }
|
|
670 #endif /* not UNIPLUS */
|
|
671 setup_pty (fd);
|
|
672 return fd;
|
|
673 }
|
|
674 }
|
|
675 return -1;
|
|
676 }
|
|
677 #endif /* HAVE_PTYS */
|
|
678
|
|
679 static int
|
|
680 create_bidirectional_pipe (int *inchannel, int *outchannel,
|
|
681 volatile int *forkin, volatile int *forkout)
|
|
682 {
|
|
683 int sv[2];
|
|
684
|
|
685 #ifdef SKTPAIR
|
|
686 if (socketpair (AF_UNIX, SOCK_STREAM, 0, sv) < 0)
|
|
687 return -1;
|
|
688 *outchannel = *inchannel = sv[0];
|
|
689 *forkout = *forkin = sv[1];
|
|
690 #else /* not SKTPAIR */
|
|
691 int temp;
|
|
692 temp = pipe (sv);
|
|
693 if (temp < 0) return -1;
|
|
694 *inchannel = sv[0];
|
|
695 *forkout = sv[1];
|
|
696 temp = pipe (sv);
|
|
697 if (temp < 0) return -1;
|
|
698 *outchannel = sv[1];
|
|
699 *forkin = sv[0];
|
|
700 #endif /* not SKTPAIR */
|
|
701 return 0;
|
|
702 }
|
|
703
|
|
704
|
|
705 static Bufbyte
|
|
706 get_eof_char (struct Lisp_Process *p)
|
|
707 {
|
|
708 /* Figure out the eof character for the outfd of the given process.
|
185
|
709 * The following code is similar to that in process_send_signal, and
|
0
|
710 * should probably be merged with that code somehow. */
|
|
711
|
16
|
712 CONST Bufbyte ctrl_d = (Bufbyte) '\004';
|
185
|
713
|
16
|
714 if (!isatty (p->outfd))
|
|
715 return ctrl_d;
|
0
|
716 #ifdef HAVE_TERMIOS
|
16
|
717 {
|
|
718 struct termios t;
|
|
719 tcgetattr (p->outfd, &t);
|
|
720 #if 0
|
|
721 /* What is the following line designed to do??? -mrb */
|
|
722 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VEOF + 1))
|
|
723 return ctrl_d;
|
|
724 else
|
|
725 return (Bufbyte) t.c_cc[VEOF];
|
|
726 #endif
|
|
727 return t.c_cc[VEOF] == CDISABLE ? ctrl_d : (Bufbyte) t.c_cc[VEOF];
|
|
728 }
|
0
|
729 #else /* ! HAVE_TERMIOS */
|
|
730 /* On Berkeley descendants, the following IOCTL's retrieve the
|
|
731 current control characters. */
|
|
732 #if defined (TIOCGETC)
|
16
|
733 {
|
|
734 struct tchars c;
|
|
735 ioctl (p->outfd, TIOCGETC, &c);
|
|
736 return (Bufbyte) c.t_eofc;
|
|
737 }
|
0
|
738 #else /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
|
|
739 /* On SYSV descendants, the TCGETA ioctl retrieves the current control
|
|
740 characters. */
|
|
741 #ifdef TCGETA
|
16
|
742 {
|
|
743 struct termio t;
|
|
744 ioctl (p->outfd, TCGETA, &t);
|
|
745 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VINTR + 1))
|
|
746 return ctrl_d;
|
|
747 else
|
|
748 return (Bufbyte) t.c_cc[VINTR];
|
|
749 }
|
0
|
750 #else /* ! defined (TCGETA) */
|
185
|
751 /* Rather than complain, we'll just guess ^D, which is what
|
0
|
752 * earlier emacsen always used. */
|
16
|
753 return ctrl_d;
|
0
|
754 #endif /* ! defined (TCGETA) */
|
|
755 #endif /* ! defined (TIOCGETC) */
|
|
756 #endif /* ! defined (HAVE_TERMIOS) */
|
|
757 }
|
|
758
|
|
759 static int
|
|
760 get_pty_max_bytes (struct Lisp_Process *p)
|
|
761 {
|
|
762 int pty_max_bytes;
|
|
763
|
|
764 #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON)
|
|
765 pty_max_bytes = fpathconf (p->outfd, _PC_MAX_CANON);
|
|
766 if (pty_max_bytes < 0)
|
|
767 pty_max_bytes = 250;
|
|
768 #else
|
|
769 pty_max_bytes = 250;
|
|
770 #endif
|
|
771 /* Deduct one, to leave space for the eof. */
|
|
772 pty_max_bytes--;
|
|
773
|
|
774 return pty_max_bytes;
|
|
775 }
|
|
776
|
|
777 static void
|
|
778 init_process_fds (struct Lisp_Process *p, int in, int out)
|
|
779 {
|
|
780 p->infd = in;
|
|
781 p->outfd = out;
|
|
782 p->instream = make_filedesc_input_stream (in, 0, -1, 0);
|
|
783 p->outstream = make_filedesc_output_stream (out, 0, -1,
|
|
784 LSTR_BLOCKED_OK
|
|
785 | (p->pty_flag ?
|
|
786 LSTR_PTY_FLUSHING : 0));
|
|
787 p->filedesc_stream = p->outstream;
|
|
788 if (p->pty_flag)
|
|
789 {
|
|
790 Bufbyte eof_char = get_eof_char (p);
|
|
791 int pty_max_bytes = get_pty_max_bytes (p);
|
|
792 filedesc_stream_set_pty_flushing (XLSTREAM (p->outstream),
|
|
793 pty_max_bytes, eof_char);
|
|
794 }
|
70
|
795 #ifdef MULE
|
|
796 p->instream = make_decoding_input_stream
|
|
797 (XLSTREAM (p->instream),
|
120
|
798 Fget_coding_system (Vcoding_system_for_read));
|
70
|
799 Lstream_set_character_mode (XLSTREAM (p->instream));
|
|
800 p->outstream = make_encoding_output_stream
|
|
801 (XLSTREAM (p->outstream),
|
120
|
802 Fget_coding_system (Vcoding_system_for_write));
|
70
|
803 /* CODE_CNTL (&out_state[outchannel]) |= CC_END; !!####
|
|
804 What's going on here? */
|
|
805 #endif /* MULE */
|
0
|
806 }
|
|
807
|
|
808 static void
|
185
|
809 create_process (Lisp_Object process,
|
0
|
810 char **new_argv, CONST char *current_dir)
|
|
811 {
|
|
812 /* This function rewritten by wing@666.com. */
|
|
813
|
|
814 int pid, inchannel, outchannel;
|
|
815 /* Use volatile to protect variables from being clobbered by longjmp. */
|
|
816 volatile int forkin, forkout;
|
|
817 volatile int pty_flag = 0;
|
|
818 char **env;
|
|
819 struct Lisp_Process *p = XPROCESS (process);
|
|
820
|
|
821 env = environ;
|
|
822
|
|
823 inchannel = outchannel = forkin = forkout = -1;
|
|
824
|
|
825 #ifdef HAVE_PTYS
|
|
826 if (!NILP (Vprocess_connection_type))
|
|
827 {
|
|
828 /* find a new pty, open the master side, return the opened
|
|
829 file handle, and store the name of the corresponding slave
|
|
830 side in global variable pty_name. */
|
|
831 outchannel = inchannel = allocate_pty ();
|
|
832 }
|
|
833
|
|
834 if (inchannel >= 0)
|
|
835 {
|
|
836 /* You're "supposed" to now open the slave in the child.
|
|
837 On some systems, we can open it here; this allows for
|
|
838 better error checking. */
|
|
839 #ifndef USG
|
|
840 /* On USG systems it does not work to open the pty's tty here
|
|
841 and then close and reopen it in the child. */
|
|
842 #ifdef O_NOCTTY
|
|
843 /* Don't let this terminal become our controlling terminal
|
|
844 (in case we don't have one). */
|
|
845 forkout = forkin = open (pty_name, O_RDWR | O_NOCTTY, 0);
|
|
846 #else
|
|
847 forkout = forkin = open (pty_name, O_RDWR, 0);
|
|
848 #endif
|
|
849 if (forkin < 0)
|
|
850 goto io_failure;
|
|
851 #endif /* not USG */
|
|
852 p->pty_flag = pty_flag = 1;
|
|
853 }
|
|
854 else
|
|
855 #endif /* HAVE_PTYS */
|
|
856 if (create_bidirectional_pipe (&inchannel, &outchannel,
|
|
857 &forkin, &forkout) < 0)
|
|
858 goto io_failure;
|
|
859
|
|
860 #if 0
|
|
861 /* Replaced by close_process_descs */
|
|
862 set_exclusive_use (inchannel);
|
|
863 set_exclusive_use (outchannel);
|
|
864 #endif
|
|
865
|
|
866 set_descriptor_non_blocking (inchannel);
|
|
867
|
|
868 /* Record this as an active process, with its channels.
|
|
869 As a result, child_setup will close Emacs's side of the pipes. */
|
|
870 descriptor_to_process[inchannel] = process;
|
|
871 init_process_fds (p, inchannel, outchannel);
|
|
872 /* Record the tty descriptor used in the subprocess. */
|
|
873 p->subtty = forkin;
|
|
874 p->status_symbol = Qrun;
|
|
875 p->exit_code = 0;
|
|
876
|
|
877 {
|
|
878 /* child_setup must clobber environ on systems with true vfork.
|
|
879 Protect it from permanent change. */
|
|
880 char **save_environ = environ;
|
|
881
|
|
882 #ifdef EMACS_BTL
|
|
883 /* when performance monitoring is on, turn it off before the vfork(),
|
|
884 as the child has no handler for the signal -- when back in the
|
|
885 parent process, turn it back on if it was really on when you "turned
|
|
886 it off" */
|
|
887 int logging_on = cadillac_stop_logging (); /* #### rename me */
|
|
888 #endif
|
|
889
|
|
890 #ifndef WINDOWSNT
|
167
|
891 pid = fork ();
|
0
|
892 if (pid == 0)
|
|
893 #endif /* not WINDOWSNT */
|
|
894 {
|
|
895 /**** Now we're in the child process ****/
|
|
896 int xforkin = forkin;
|
|
897 int xforkout = forkout;
|
|
898
|
|
899 if (!pty_flag)
|
|
900 EMACS_SEPARATE_PROCESS_GROUP ();
|
|
901 #ifdef HAVE_PTYS
|
|
902 else
|
|
903 {
|
|
904 /* Disconnect the current controlling terminal, pursuant to
|
|
905 making the pty be the controlling terminal of the process.
|
|
906 Also put us in our own process group. */
|
|
907
|
|
908 disconnect_controlling_terminal ();
|
|
909
|
|
910 /* Open the pty connection and make the pty's terminal
|
|
911 our controlling terminal.
|
|
912
|
|
913 On systems with TIOCSCTTY, we just use it to set
|
|
914 the controlling terminal. On other systems, the
|
|
915 first TTY we open becomes the controlling terminal.
|
|
916 So, we end up with four possibilities:
|
|
917
|
|
918 (1) on USG and TIOCSCTTY systems, we open the pty
|
|
919 and use TIOCSCTTY.
|
|
920 (2) on other USG systems, we just open the pty.
|
|
921 (3) on non-USG systems with TIOCSCTTY, we
|
|
922 just use TIOCSCTTY. (On non-USG systems, we
|
|
923 already opened the pty in the parent process.)
|
|
924 (4) on non-USG systems without TIOCSCTTY, we
|
|
925 close the pty and reopen it.
|
|
926
|
|
927 This would be cleaner if we didn't open the pty
|
|
928 in the parent process, but doing it that way
|
|
929 makes it possible to trap error conditions.
|
|
930 It's harder to convey an error from the child
|
|
931 process, and I don't feel like messing with
|
|
932 this now. */
|
|
933
|
|
934 /* There was some weirdo, probably wrong,
|
|
935 conditionalization on RTU and UNIPLUS here.
|
|
936 I deleted it. So sue me. */
|
|
937
|
|
938 /* SunOS has TIOCSCTTY but the close/open method
|
|
939 also works. */
|
|
940
|
|
941 # if defined (USG) || !defined (TIOCSCTTY)
|
|
942 /* Now close the pty (if we had it open) and reopen it.
|
|
943 This makes the pty the controlling terminal of the
|
|
944 subprocess. */
|
|
945 /* I wonder if close (open (pty_name, ...)) would work? */
|
|
946 if (xforkin >= 0)
|
|
947 close (xforkin);
|
|
948 xforkout = xforkin = open (pty_name, O_RDWR, 0);
|
|
949 if (xforkin < 0)
|
|
950 {
|
|
951 write (1, "Couldn't open the pty terminal ", 31);
|
|
952 write (1, pty_name, strlen (pty_name));
|
|
953 write (1, "\n", 1);
|
|
954 _exit (1);
|
|
955 }
|
|
956 # endif /* USG or not TIOCSCTTY */
|
|
957
|
|
958 /* Miscellaneous setup required for some systems.
|
|
959 Must be done before using tc* functions on xforkin.
|
|
960 This guarantees that isatty(xforkin) is true. */
|
185
|
961
|
0
|
962 # ifdef SETUP_SLAVE_PTY
|
|
963 SETUP_SLAVE_PTY;
|
|
964 # endif /* SETUP_SLAVE_PTY */
|
185
|
965
|
0
|
966 # ifdef TIOCSCTTY
|
|
967 /* We ignore the return value
|
|
968 because faith@cs.unc.edu says that is necessary on Linux. */
|
|
969 assert (isatty (xforkin));
|
|
970 ioctl (xforkin, TIOCSCTTY, 0);
|
|
971 # endif /* TIOCSCTTY */
|
|
972
|
|
973 /* Change the line discipline. */
|
|
974
|
|
975 # if defined (HAVE_TERMIOS) && defined (LDISC1)
|
|
976 {
|
|
977 struct termios t;
|
|
978 assert (isatty (xforkin));
|
|
979 tcgetattr (xforkin, &t);
|
|
980 t.c_lflag = LDISC1;
|
|
981 if (tcsetattr (xforkin, TCSANOW, &t) < 0)
|
|
982 perror ("create_process/tcsetattr LDISC1 failed\n");
|
|
983 }
|
|
984 # elif defined (NTTYDISC) && defined (TIOCSETD)
|
|
985 {
|
|
986 /* Use new line discipline. TIOCSETD is accepted and
|
|
987 ignored on Sys5.4 systems with ttcompat. */
|
|
988 int ldisc = NTTYDISC;
|
|
989 assert (isatty (xforkin));
|
|
990 ioctl (xforkin, TIOCSETD, &ldisc);
|
|
991 }
|
|
992 # endif /* TIOCSETD & NTTYDISC */
|
|
993
|
|
994 /* Make our process group be the foreground group
|
|
995 of our new controlling terminal. */
|
|
996
|
|
997 {
|
|
998 int piddly = EMACS_GET_PROCESS_GROUP ();
|
|
999 EMACS_SET_TTY_PROCESS_GROUP (xforkin, &piddly);
|
|
1000 }
|
|
1001
|
|
1002 # ifdef AIX
|
|
1003 /* On AIX, we've disabled SIGHUP above once we start a
|
|
1004 child on a pty. Now reenable it in the child, so it
|
|
1005 will die when we want it to. */
|
|
1006 signal (SIGHUP, SIG_DFL);
|
|
1007 # endif /* AIX */
|
|
1008 }
|
|
1009 #endif /* HAVE_PTYS */
|
|
1010
|
|
1011 signal (SIGINT, SIG_DFL);
|
|
1012 signal (SIGQUIT, SIG_DFL);
|
|
1013
|
100
|
1014 #if !defined(MSDOS) && !defined(WINDOWSNT)
|
0
|
1015 if (pty_flag)
|
|
1016 {
|
|
1017 /* Set up the terminal characteristics of the pty. */
|
|
1018 child_setup_tty (xforkout);
|
|
1019 }
|
|
1020
|
|
1021 #ifdef WINDOWSNT
|
|
1022 pid = child_setup (xforkin, xforkout, xforkout,
|
|
1023 new_argv, current_dir);
|
185
|
1024 #else /* not WINDOWSNT */
|
0
|
1025 child_setup (xforkin, xforkout, xforkout, new_argv, current_dir);
|
|
1026 #endif /* not WINDOWSNT */
|
|
1027 #endif /* not MSDOS */
|
|
1028 }
|
|
1029 #ifdef EMACS_BTL
|
|
1030 else if (logging_on)
|
|
1031 cadillac_start_logging (); /* #### rename me */
|
|
1032 #endif
|
|
1033
|
|
1034 environ = save_environ;
|
|
1035 }
|
|
1036
|
|
1037 if (pid < 0)
|
|
1038 {
|
|
1039 close_descriptor_pair (forkin, forkout);
|
167
|
1040 report_file_error ("Doing fork", Qnil);
|
0
|
1041 }
|
|
1042
|
|
1043 p->pid = make_int (pid);
|
120
|
1044 /* #### dmoore - why is this commented out, otherwise we leave
|
|
1045 subtty = forkin, but then we close forkin just below. */
|
0
|
1046 /* p->subtty = -1; */
|
|
1047
|
|
1048 #ifdef WINDOWSNT
|
|
1049 register_child (pid, inchannel);
|
|
1050 #endif /* WINDOWSNT */
|
|
1051
|
|
1052 /* If the subfork execv fails, and it exits,
|
|
1053 this close hangs. I don't know why.
|
|
1054 So have an interrupt jar it loose. */
|
|
1055 if (forkin >= 0)
|
|
1056 close_safely (forkin);
|
|
1057 if (forkin != forkout && forkout >= 0)
|
|
1058 close (forkout);
|
|
1059
|
|
1060 #ifdef HAVE_PTYS
|
|
1061 if (pty_flag)
|
|
1062 XPROCESS (process)->tty_name = build_string (pty_name);
|
|
1063 else
|
|
1064 #endif
|
|
1065 XPROCESS (process)->tty_name = Qnil;
|
|
1066
|
|
1067 /* Notice that SIGCHLD was not blocked. (This is not possible on
|
|
1068 some systems.) No biggie if SIGCHLD occurs right around the
|
|
1069 time that this call happens, because SIGCHLD() does not actually
|
|
1070 deselect the process (that doesn't occur until the next time
|
|
1071 we're waiting for an event, when status_notify() is called). */
|
|
1072 event_stream_select_process (XPROCESS (process));
|
|
1073
|
|
1074 return;
|
|
1075
|
|
1076 io_failure:
|
|
1077 {
|
|
1078 int temp = errno;
|
|
1079 close_descriptor_pair (forkin, forkout);
|
|
1080 close_descriptor_pair (inchannel, outchannel);
|
|
1081 errno = temp;
|
|
1082 report_file_error ("Opening pty or pipe", Qnil);
|
|
1083 }
|
|
1084 }
|
|
1085
|
|
1086 /* This function is the unwind_protect form for Fstart_process_internal. If
|
|
1087 PROC doesn't have its pid set, then we know someone has signalled
|
|
1088 an error and the process wasn't started successfully, so we should
|
|
1089 remove it from the process list. */
|
|
1090 static void remove_process (Lisp_Object proc);
|
|
1091 static Lisp_Object
|
|
1092 start_process_unwind (Lisp_Object proc)
|
|
1093 {
|
|
1094 /* Was PROC started successfully? */
|
|
1095 if (EQ (XPROCESS (proc)->pid, Qnil))
|
|
1096 remove_process (proc);
|
|
1097 return Qnil;
|
|
1098 }
|
|
1099
|
20
|
1100 DEFUN ("start-process-internal", Fstart_process_internal, 3, MANY, 0, /*
|
0
|
1101 Start a program in a subprocess. Return the process object for it.
|
|
1102 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS
|
|
1103 NAME is name for process. It is modified if necessary to make it unique.
|
|
1104 BUFFER is the buffer or (buffer-name) to associate with the process.
|
|
1105 Process output goes at end of that buffer, unless you specify
|
|
1106 an output stream or filter function to handle the output.
|
|
1107 BUFFER may be also nil, meaning that this process is not associated
|
|
1108 with any buffer
|
|
1109 Third arg is program file name. It is searched for as in the shell.
|
|
1110 Remaining arguments are strings to give program as arguments.
|
|
1111 INCODE and OUTCODE specify the coding-system objects used in input/output
|
|
1112 from/to the process.
|
20
|
1113 */
|
|
1114 (int nargs, Lisp_Object *args))
|
0
|
1115 {
|
120
|
1116 /* This function can call lisp */
|
0
|
1117 /* !!#### This function has not been Mule-ized */
|
|
1118 Lisp_Object buffer, name, program, proc, current_dir;
|
|
1119 Lisp_Object tem;
|
|
1120 int speccount = specpdl_depth ();
|
120
|
1121 struct gcpro gcpro1, gcpro2, gcpro3;
|
0
|
1122 char **new_argv;
|
|
1123 int i;
|
|
1124
|
120
|
1125 name = args[0];
|
0
|
1126 buffer = args[1];
|
120
|
1127 program = args[2];
|
|
1128 current_dir = Qnil;
|
|
1129
|
|
1130 /* Protect against various file handlers doing GCs below. */
|
|
1131 GCPRO3 (buffer, program, current_dir);
|
|
1132
|
0
|
1133 if (!NILP (buffer))
|
|
1134 buffer = Fget_buffer_create (buffer);
|
|
1135
|
120
|
1136 CHECK_STRING (name);
|
|
1137 CHECK_STRING (program);
|
0
|
1138
|
|
1139 /* Make sure that the child will be able to chdir to the current
|
|
1140 buffer's current directory, or its unhandled equivalent. We
|
|
1141 can't just have the child check for an error when it does the
|
|
1142 chdir, since it's in a vfork.
|
|
1143
|
120
|
1144 Note: these assignments and calls are like this in order to insure
|
|
1145 "caller protects args" GC semantics. */
|
|
1146 current_dir = current_buffer->directory;
|
|
1147 current_dir = Funhandled_file_name_directory (current_dir);
|
|
1148 current_dir = expand_and_dir_to_file (current_dir, Qnil);
|
|
1149
|
0
|
1150 #if 0 /* This loser breaks ange-ftp */
|
120
|
1151 /* dmoore - if you re-enable this code, you have to gcprotect
|
|
1152 current_buffer through the above calls. */
|
|
1153 if (NILP (Ffile_accessible_directory_p (current_dir)))
|
|
1154 report_file_error ("Setting current directory",
|
|
1155 list1 (current_buffer->directory));
|
0
|
1156 #endif /* 0 */
|
|
1157
|
|
1158 /* If program file name is not absolute, search our path for it */
|
82
|
1159 if (!IS_DIRECTORY_SEP (XSTRING_BYTE (program, 0))
|
16
|
1160 && !(XSTRING_LENGTH (program) > 1
|
82
|
1161 && IS_DEVICE_SEP (XSTRING_BYTE (program, 1))))
|
0
|
1162 {
|
120
|
1163 struct gcpro ngcpro1;
|
70
|
1164
|
0
|
1165 tem = Qnil;
|
120
|
1166 NGCPRO1 (tem);
|
0
|
1167 locate_file (Vexec_path, program, EXEC_SUFFIXES, &tem,
|
|
1168 X_OK);
|
|
1169 if (NILP (tem))
|
|
1170 report_file_error ("Searching for program", list1 (program));
|
120
|
1171 program = Fexpand_file_name (tem, Qnil);
|
|
1172 NUNGCPRO;
|
0
|
1173 }
|
|
1174 else
|
|
1175 {
|
|
1176 if (!NILP (Ffile_directory_p (program)))
|
|
1177 error ("Specified program for new process is a directory");
|
|
1178 }
|
|
1179
|
120
|
1180 /* Nothing below here GCs so our string pointers shouldn't move. */
|
185
|
1181 new_argv = alloca_array (char *, nargs - 1);
|
120
|
1182 new_argv[0] = (char *) XSTRING_DATA (program);
|
0
|
1183 for (i = 3; i < nargs; i++)
|
|
1184 {
|
|
1185 tem = args[i];
|
|
1186 CHECK_STRING (tem);
|
16
|
1187 new_argv[i - 2] = (char *) XSTRING_DATA (tem);
|
0
|
1188 }
|
|
1189 new_argv[i - 2] = 0;
|
|
1190
|
|
1191 proc = make_process_internal (name);
|
|
1192
|
|
1193 XPROCESS (proc)->buffer = buffer;
|
|
1194 XPROCESS (proc)->command = Flist (nargs - 2,
|
|
1195 args + 2);
|
|
1196
|
|
1197 /* Make the process marker point into the process buffer (if any). */
|
|
1198 if (!NILP (buffer))
|
|
1199 Fset_marker (XPROCESS (proc)->mark,
|
|
1200 make_int (BUF_ZV (XBUFFER (buffer))), buffer);
|
|
1201
|
|
1202 /* If an error occurs and we can't start the process, we want to
|
|
1203 remove it from the process list. This means that each error
|
|
1204 check in create_process doesn't need to call remove_process
|
|
1205 itself; it's all taken care of here. */
|
|
1206 record_unwind_protect (start_process_unwind, proc);
|
|
1207
|
16
|
1208 create_process (proc, new_argv, (char *) XSTRING_DATA (current_dir));
|
0
|
1209
|
120
|
1210 UNGCPRO;
|
0
|
1211 return unbind_to (speccount, proc);
|
|
1212 }
|
|
1213
|
|
1214
|
|
1215 /* connect to an existing file descriptor. This is very similar to
|
|
1216 open-network-stream except that it assumes that the connection has
|
|
1217 already been initialized. It is currently used for ToolTalk
|
|
1218 communication. */
|
|
1219
|
|
1220 /* This function used to be visible on the Lisp level, but there is no
|
|
1221 real point in doing that. Here is the doc string:
|
|
1222
|
|
1223 "Connect to an existing file descriptor.\n\
|
|
1224 Returns a subprocess-object to represent the connection.\n\
|
|
1225 Input and output work as for subprocesses; `delete-process' closes it.\n\
|
|
1226 Args are NAME BUFFER INFD OUTFD.\n\
|
|
1227 NAME is name for process. It is modified if necessary to make it unique.\n\
|
|
1228 BUFFER is the buffer (or buffer-name) to associate with the process.\n\
|
|
1229 Process output goes at end of that buffer, unless you specify\n\
|
|
1230 an output stream or filter function to handle the output.\n\
|
|
1231 BUFFER may be also nil, meaning that this process is not associated\n\
|
|
1232 with any buffer\n\
|
|
1233 INFD and OUTFD specify the file descriptors to use for input and\n\
|
|
1234 output, respectively."
|
|
1235 */
|
|
1236
|
|
1237 Lisp_Object
|
|
1238 connect_to_file_descriptor (Lisp_Object name, Lisp_Object buffer,
|
|
1239 Lisp_Object infd, Lisp_Object outfd)
|
|
1240 {
|
|
1241 /* This function can GC */
|
|
1242 Lisp_Object proc;
|
|
1243 int inch;
|
|
1244
|
|
1245 CHECK_STRING (name);
|
|
1246 CHECK_INT (infd);
|
|
1247 CHECK_INT (outfd);
|
|
1248
|
|
1249 inch = XINT (infd);
|
|
1250 if (!NILP (descriptor_to_process[inch]))
|
|
1251 error ("There is already a process connected to fd %d", inch);
|
|
1252 if (!NILP (buffer))
|
|
1253 buffer = Fget_buffer_create (buffer);
|
|
1254 proc = make_process_internal (name);
|
|
1255
|
|
1256 descriptor_to_process[inch] = proc;
|
|
1257
|
|
1258 XPROCESS (proc)->pid = Fcons (infd, name);
|
|
1259 XPROCESS (proc)->buffer = buffer;
|
|
1260 init_process_fds (XPROCESS (proc), inch, XINT (outfd));
|
|
1261 XPROCESS (proc)->connected_via_filedesc_p = 1;
|
|
1262
|
|
1263 event_stream_select_process (XPROCESS (proc));
|
|
1264
|
|
1265 return proc;
|
|
1266 }
|
|
1267
|
|
1268
|
|
1269 #ifdef HAVE_SOCKETS
|
|
1270
|
|
1271 static int
|
|
1272 get_internet_address (Lisp_Object host, struct sockaddr_in *address,
|
|
1273 Error_behavior errb)
|
|
1274 {
|
173
|
1275 struct hostent *host_info_ptr = NULL;
|
108
|
1276 #ifdef TRY_AGAIN
|
|
1277 int count = 0;
|
|
1278 #endif
|
0
|
1279
|
|
1280 #ifndef HAVE_TERM
|
|
1281 memset (address, 0, sizeof (*address));
|
|
1282
|
|
1283 while (1)
|
|
1284 {
|
|
1285 #ifdef TRY_AGAIN
|
108
|
1286 if (count++ > 10) break;
|
0
|
1287 h_errno = 0;
|
|
1288 #endif
|
|
1289 /* Some systems can't handle SIGIO/SIGALARM in gethostbyname. */
|
|
1290 slow_down_interrupts ();
|
16
|
1291 host_info_ptr = gethostbyname ((char *) XSTRING_DATA (host));
|
0
|
1292 speed_up_interrupts ();
|
|
1293 #ifdef TRY_AGAIN
|
|
1294 if (! (host_info_ptr == 0 && h_errno == TRY_AGAIN))
|
|
1295 #endif
|
|
1296 break;
|
|
1297 Fsleep_for (make_int (1));
|
|
1298 }
|
|
1299 if (host_info_ptr)
|
|
1300 {
|
|
1301 address->sin_family = host_info_ptr->h_addrtype;
|
|
1302 memcpy (&address->sin_addr, host_info_ptr->h_addr, host_info_ptr->h_length);
|
|
1303 }
|
|
1304 else
|
|
1305 {
|
|
1306 IN_ADDR numeric_addr;
|
|
1307 /* Attempt to interpret host as numeric inet address */
|
16
|
1308 numeric_addr = inet_addr ((char *) XSTRING_DATA (host));
|
0
|
1309 if (NUMERIC_ADDR_ERROR)
|
|
1310 {
|
|
1311 maybe_error (Qprocess, errb,
|
16
|
1312 "Unknown host \"%s\"", XSTRING_DATA (host));
|
0
|
1313 return 0;
|
|
1314 }
|
|
1315
|
|
1316 /* There was some broken code here that called strlen() here
|
|
1317 on (char *) &numeric_addr and even sometimes accessed
|
|
1318 uninitialized data. */
|
|
1319 address->sin_family = AF_INET;
|
|
1320 * (IN_ADDR *) &address->sin_addr = numeric_addr;
|
|
1321 }
|
|
1322
|
|
1323 return 1;
|
|
1324 }
|
|
1325
|
|
1326 /* open a TCP network connection to a given HOST/SERVICE. Treated
|
|
1327 exactly like a normal process when reading and writing. Only
|
|
1328 differences are in status display and process deletion. A network
|
|
1329 connection has no PID; you cannot signal it. All you can do is
|
|
1330 deactivate and close it via delete-process */
|
|
1331
|
20
|
1332 DEFUN ("open-network-stream-internal", Fopen_network_stream_internal, 4, 4, 0, /*
|
0
|
1333 Open a TCP connection for a service to a host.
|
|
1334 Returns a subprocess-object to represent the connection.
|
|
1335 Input and output work as for subprocesses; `delete-process' closes it.
|
70
|
1336
|
0
|
1337 NAME is name for process. It is modified if necessary to make it unique.
|
|
1338 BUFFER is the buffer (or buffer-name) to associate with the process.
|
|
1339 Process output goes at end of that buffer, unless you specify
|
|
1340 an output stream or filter function to handle the output.
|
70
|
1341 BUFFER may also be nil, meaning that this process is not associated
|
|
1342 with any buffer.
|
0
|
1343 Third arg is name of the host to connect to, or its IP address.
|
|
1344 Fourth arg SERVICE is name of the service desired, or an integer
|
|
1345 specifying a port number to connect to.
|
20
|
1346 */
|
|
1347 (name, buffer, host, service))
|
0
|
1348 {
|
|
1349 /* !!#### This function has not been Mule-ized */
|
|
1350 /* This function can GC */
|
|
1351 Lisp_Object proc;
|
|
1352 struct sockaddr_in address;
|
|
1353 int s, outch, inch;
|
169
|
1354 volatile int port;
|
0
|
1355 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
16
|
1356 volatile int retry = 0;
|
0
|
1357 int retval;
|
|
1358
|
|
1359 GCPRO4 (name, buffer, host, service);
|
|
1360 CHECK_STRING (name);
|
|
1361 CHECK_STRING (host);
|
|
1362 if (INTP (service))
|
|
1363 port = htons ((unsigned short) XINT (service));
|
|
1364 else
|
|
1365 {
|
|
1366 struct servent *svc_info;
|
|
1367 CHECK_STRING (service);
|
16
|
1368 svc_info = getservbyname ((char *) XSTRING_DATA (service), "tcp");
|
0
|
1369 if (svc_info == 0)
|
|
1370 #ifdef WIN32
|
|
1371 error ("Unknown service \"%s\" (%d)",
|
16
|
1372 XSTRING_DATA (service), WSAGetLastError ());
|
0
|
1373 #else
|
16
|
1374 error ("Unknown service \"%s\"", XSTRING_DATA (service));
|
0
|
1375 #endif
|
|
1376 port = svc_info->s_port;
|
|
1377 }
|
|
1378
|
|
1379 get_internet_address (host, &address, ERROR_ME);
|
|
1380 address.sin_port = port;
|
|
1381
|
|
1382 s = socket (address.sin_family, SOCK_STREAM, 0);
|
185
|
1383 if (s < 0)
|
0
|
1384 report_file_error ("error creating socket", list1 (name));
|
|
1385
|
|
1386 /* Turn off interrupts here -- see comments below. There used to
|
|
1387 be code which called bind_polling_period() to slow the polling
|
|
1388 period down rather than turn it off, but that seems rather
|
|
1389 bogus to me. Best thing here is to use a non-blocking connect
|
|
1390 or something, to check for QUIT. */
|
|
1391
|
|
1392 /* Comments that are not quite valid: */
|
|
1393
|
|
1394 /* Kernel bugs (on Ultrix at least) cause lossage (not just EINTR)
|
|
1395 when connect is interrupted. So let's not let it get interrupted.
|
|
1396 Note we do not turn off polling, because polling is only used
|
|
1397 when not interrupt_input, and thus not normally used on the systems
|
|
1398 which have this bug. On systems which use polling, there's no way
|
|
1399 to quit if polling is turned off. */
|
|
1400
|
|
1401 /* Slow down polling. Some kernels have a bug which causes retrying
|
|
1402 connect to fail after a connect. */
|
|
1403
|
|
1404 slow_down_interrupts ();
|
|
1405
|
|
1406 loop:
|
|
1407
|
|
1408 /* A system call interrupted with a SIGALRM or SIGIO comes back
|
|
1409 here, with can_break_system_calls reset to 0. */
|
|
1410 SETJMP (break_system_call_jump);
|
|
1411 if (QUITP)
|
|
1412 {
|
|
1413 speed_up_interrupts ();
|
|
1414 REALLY_QUIT;
|
|
1415 /* In case something really weird happens ... */
|
|
1416 slow_down_interrupts ();
|
|
1417 }
|
|
1418
|
|
1419 /* Break out of connect with a signal (it isn't otherwise possible).
|
|
1420 Thus you don't get screwed with a hung network. */
|
|
1421 can_break_system_calls = 1;
|
|
1422 retval = connect (s, (struct sockaddr *) &address, sizeof (address));
|
|
1423 can_break_system_calls = 0;
|
|
1424 if (retval == -1 && errno != EISCONN)
|
|
1425 {
|
|
1426 int xerrno = errno;
|
|
1427 if (errno == EINTR)
|
|
1428 goto loop;
|
|
1429 if (errno == EADDRINUSE && retry < 20)
|
|
1430 {
|
|
1431 /* A delay here is needed on some FreeBSD systems,
|
|
1432 and it is harmless, since this retrying takes time anyway
|
104
|
1433 and should be infrequent.
|
|
1434 `sleep-for' allowed for quitting this loop with interrupts
|
|
1435 slowed down so it can't be used here. Async timers should
|
|
1436 already be disabled at this point so we can use `sleep'. */
|
|
1437 sleep (1);
|
0
|
1438 retry++;
|
|
1439 goto loop;
|
|
1440 }
|
|
1441
|
|
1442 close (s);
|
|
1443
|
|
1444 speed_up_interrupts ();
|
|
1445
|
|
1446 errno = xerrno;
|
|
1447 report_file_error ("connection failed", list2 (host, name));
|
|
1448 }
|
|
1449
|
|
1450 speed_up_interrupts ();
|
|
1451
|
|
1452 #else /* HAVE_TERM */
|
|
1453 s = connect_server (0);
|
|
1454 if (s < 0)
|
|
1455 report_file_error ("error creating socket", Fcons (name, Qnil));
|
16
|
1456 send_command (s, C_PORT, 0, "%s:%d", XSTRING_DATA (host), ntohs (port));
|
0
|
1457 send_command (s, C_DUMB, 1, 0);
|
|
1458 #endif /* HAVE_TERM */
|
|
1459
|
|
1460 inch = s;
|
|
1461 outch = dup (s);
|
|
1462 if (outch < 0)
|
|
1463 {
|
|
1464 close (s); /* this used to be leaked; from Kyle Jones */
|
|
1465 report_file_error ("error duplicating socket", list1 (name));
|
|
1466 }
|
|
1467
|
|
1468 if (!NILP (buffer))
|
|
1469 buffer = Fget_buffer_create (buffer);
|
|
1470 proc = make_process_internal (name);
|
|
1471
|
|
1472 descriptor_to_process[inch] = proc;
|
|
1473
|
153
|
1474 #ifdef PROCESS_IO_BLOCKING
|
|
1475 {
|
|
1476 Lisp_Object tail;
|
|
1477
|
|
1478 for (tail = network_stream_blocking_port_list; CONSP (tail); tail = XCDR (tail))
|
|
1479 {
|
|
1480 Lisp_Object tail_port = XCAR (tail);
|
|
1481
|
|
1482 if (STRINGP (tail_port))
|
|
1483 {
|
|
1484 struct servent *svc_info;
|
|
1485 CHECK_STRING (tail_port);
|
|
1486 svc_info = getservbyname ((char *) XSTRING_DATA (tail_port), "tcp");
|
|
1487 if ((svc_info != 0) && (svc_info->s_port == port))
|
|
1488 break;
|
|
1489 else
|
|
1490 continue;
|
|
1491 }
|
|
1492 else if ((INTP (tail_port)) && (htons ((unsigned short) XINT (tail_port)) == port))
|
|
1493 break;
|
|
1494 }
|
|
1495
|
|
1496 if (!CONSP (tail))
|
|
1497 {
|
|
1498 #endif /* PROCESS_IO_BLOCKING */
|
0
|
1499 set_descriptor_non_blocking (inch);
|
153
|
1500 #ifdef PROCESS_IO_BLOCKING
|
|
1501 }
|
|
1502 }
|
|
1503 #endif /* PROCESS_IO_BLOCKING */
|
0
|
1504
|
|
1505 XPROCESS (proc)->pid = Fcons (service, host);
|
|
1506 XPROCESS (proc)->buffer = buffer;
|
|
1507 init_process_fds (XPROCESS (proc), inch, outch);
|
|
1508 XPROCESS (proc)->connected_via_filedesc_p = 0;
|
|
1509
|
|
1510 event_stream_select_process (XPROCESS (proc));
|
|
1511
|
|
1512 UNGCPRO;
|
|
1513 return proc;
|
|
1514 }
|
|
1515
|
|
1516 #endif /* HAVE_SOCKETS */
|
|
1517
|
|
1518 Lisp_Object
|
|
1519 canonicalize_host_name (Lisp_Object host)
|
|
1520 {
|
|
1521 #ifdef HAVE_SOCKETS
|
|
1522 /* #### for HAVE_TERM, you probably have to do something else. */
|
|
1523 struct sockaddr_in address;
|
|
1524
|
|
1525 if (!get_internet_address (host, &address, ERROR_ME_NOT))
|
|
1526 return host;
|
|
1527
|
|
1528 if (address.sin_family == AF_INET)
|
|
1529 return build_string (inet_ntoa (address.sin_addr));
|
|
1530 else
|
|
1531 /* #### any clue what to do here? */
|
|
1532 return host;
|
|
1533 #else
|
|
1534 return host;
|
|
1535 #endif
|
|
1536 }
|
|
1537
|
|
1538
|
20
|
1539 DEFUN ("set-process-window-size", Fset_process_window_size, 3, 3, 0, /*
|
0
|
1540 Tell PROCESS that it has logical window size HEIGHT and WIDTH.
|
20
|
1541 */
|
|
1542 (proc, height, width))
|
0
|
1543 {
|
|
1544 CHECK_PROCESS (proc);
|
|
1545 CHECK_NATNUM (height);
|
|
1546 CHECK_NATNUM (width);
|
|
1547 if (set_window_size (XPROCESS (proc)->infd, XINT (height), XINT (width))
|
|
1548 <= 0)
|
|
1549 return Qnil;
|
|
1550 else
|
|
1551 return Qt;
|
|
1552 }
|
|
1553
|
|
1554
|
|
1555 /************************************************************************/
|
|
1556 /* Process I/O */
|
|
1557 /************************************************************************/
|
|
1558
|
|
1559 /* (Faccept_process_output is now in event-stream.c) */
|
|
1560
|
|
1561 /* Some FSFmacs error handlers here. We handle this
|
|
1562 in call2_trapping_errors(). */
|
|
1563
|
|
1564 /* Read pending output from the process channel,
|
|
1565 starting with our buffered-ahead character if we have one.
|
|
1566 Yield number of characters read.
|
|
1567
|
|
1568 This function reads at most 1024 bytes.
|
|
1569 If you want to read all available subprocess output,
|
|
1570 you must call it repeatedly until it returns zero. */
|
|
1571
|
|
1572 Charcount
|
|
1573 read_process_output (Lisp_Object proc)
|
|
1574 {
|
|
1575 /* This function can GC */
|
|
1576 Bytecount nbytes, nchars;
|
|
1577 Bufbyte chars[1024];
|
|
1578 Lisp_Object outstream;
|
|
1579 struct Lisp_Process *p = XPROCESS (proc);
|
|
1580
|
|
1581 /* If there is a lot of output from the subprocess, the loop in
|
|
1582 execute_internal_event() might call read_process_output() more
|
|
1583 than once. If the filter that was executed from one of these
|
|
1584 calls set the filter to t, we have to stop now. Return -1 rather
|
|
1585 than 0 so execute_internal_event() doesn't close the process.
|
|
1586 Really, the loop in execute_internal_event() should check itself
|
|
1587 for a process-filter change, like in status_notify(); but the
|
|
1588 struct Lisp_Process is not exported outside of this file. */
|
|
1589 if (p->infd < 0)
|
|
1590 return -1; /* already closed */
|
|
1591
|
|
1592 if (!NILP (p->filter) && (p->filter_does_read))
|
|
1593 {
|
|
1594 Lisp_Object filter_result;
|
|
1595
|
|
1596 /* Some weird FSFmacs crap here with
|
|
1597 Vdeactivate_mark and current_buffer->keymap */
|
|
1598 running_asynch_code = 1;
|
|
1599 filter_result = call2_trapping_errors ("Error in process filter",
|
|
1600 p->filter, proc, Qnil);
|
|
1601 running_asynch_code = 0;
|
|
1602 restore_match_data ();
|
|
1603 CHECK_INT (filter_result);
|
|
1604 return XINT (filter_result);
|
|
1605 }
|
|
1606
|
|
1607 #if 0 /* FSFmacs */
|
|
1608 /* #### equivalent code from FSFmacs. Would need some porting
|
|
1609 for Windows NT. */
|
|
1610 if (proc_buffered_char[channel] < 0)
|
|
1611 #ifdef WINDOWSNT
|
|
1612 nchars = read_child_output (channel, chars, sizeof (chars));
|
|
1613 #else
|
|
1614 nchars = read (channel, chars, sizeof chars);
|
|
1615 #endif
|
|
1616 else
|
|
1617 {
|
|
1618 chars[0] = proc_buffered_char[channel];
|
|
1619 proc_buffered_char[channel] = -1;
|
|
1620 #ifdef WINDOWSNT
|
|
1621 nchars = read_child_output (channel, chars + 1, sizeof (chars) - 1);
|
|
1622 #else
|
|
1623 nchars = read (channel, chars + 1, sizeof chars - 1);
|
|
1624 #endif
|
|
1625 if (nchars < 0)
|
|
1626 nchars = 1;
|
|
1627 else
|
|
1628 nchars = nchars + 1;
|
|
1629 }
|
|
1630 #endif /* FSFmacs */
|
|
1631
|
|
1632 nbytes = Lstream_read (XLSTREAM (p->instream), chars, sizeof (chars));
|
|
1633 if (nbytes <= 0) return nbytes;
|
|
1634
|
|
1635 nchars = bytecount_to_charcount (chars, nbytes);
|
|
1636 outstream = p->filter;
|
|
1637 if (!NILP (outstream))
|
|
1638 {
|
|
1639 /* We used to bind inhibit-quit to t here, but
|
|
1640 call2_trapping_errors() does that for us. */
|
|
1641 running_asynch_code = 1;
|
|
1642 call2_trapping_errors ("Error in process filter",
|
|
1643 outstream, proc, make_string (chars, nbytes));
|
|
1644 running_asynch_code = 0;
|
|
1645 restore_match_data ();
|
173
|
1646 return nchars;
|
0
|
1647 }
|
|
1648
|
|
1649 /* If no filter, write into buffer if it isn't dead. */
|
|
1650 if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer)))
|
|
1651 {
|
|
1652 Lisp_Object old_read_only = Qnil;
|
|
1653 Bufpos old_point;
|
|
1654 Bufpos old_begv;
|
|
1655 Bufpos old_zv;
|
|
1656 int old_zmacs_region_stays = zmacs_region_stays;
|
|
1657 struct gcpro gcpro1, gcpro2;
|
|
1658 struct buffer *buf = XBUFFER (p->buffer);
|
|
1659
|
|
1660 GCPRO2 (proc, old_read_only);
|
|
1661
|
|
1662 old_point = BUF_PT (buf);
|
|
1663 old_begv = BUF_BEGV (buf);
|
|
1664 old_zv = BUF_ZV (buf);
|
|
1665 old_read_only = buf->read_only;
|
|
1666 buf->read_only = Qnil;
|
|
1667
|
|
1668 /* Insert new output into buffer
|
|
1669 at the current end-of-output marker,
|
|
1670 thus preserving logical ordering of input and output. */
|
|
1671 if (XMARKER (p->mark)->buffer)
|
|
1672 BUF_SET_PT (buf,
|
|
1673 bufpos_clip_to_bounds (old_begv, marker_position (p->mark),
|
|
1674 old_zv));
|
|
1675 else
|
|
1676 BUF_SET_PT (buf, old_zv);
|
|
1677
|
|
1678 /* If the output marker is outside of the visible region, save
|
|
1679 the restriction and widen. */
|
|
1680 if (! (BUF_BEGV (buf) <= BUF_PT (buf) &&
|
|
1681 BUF_PT (buf) <= BUF_ZV (buf)))
|
|
1682 Fwiden (p->buffer);
|
|
1683
|
|
1684 /* Make sure opoint floats ahead of any new text, just as point
|
|
1685 would. */
|
|
1686 if (BUF_PT (buf) <= old_point)
|
|
1687 old_point += nchars;
|
|
1688
|
|
1689 /* Insert after old_begv, but before old_zv. */
|
|
1690 if (BUF_PT (buf) < old_begv)
|
|
1691 old_begv += nchars;
|
|
1692 if (BUF_PT (buf) <= old_zv)
|
|
1693 old_zv += nchars;
|
|
1694
|
|
1695 #if 0
|
|
1696 /* This screws up intial display of the window. jla */
|
|
1697
|
|
1698 /* Insert before markers in case we are inserting where
|
|
1699 the buffer's mark is, and the user's next command is Meta-y. */
|
|
1700 buffer_insert_raw_string_1 (buf, -1, chars,
|
|
1701 nbytes, INSDEL_BEFORE_MARKERS);
|
|
1702 #else
|
|
1703 buffer_insert_raw_string (buf, chars, nbytes);
|
|
1704 #endif
|
|
1705
|
|
1706 Fset_marker (p->mark, make_int (BUF_PT (buf)), p->buffer);
|
|
1707
|
|
1708 MARK_MODELINE_CHANGED;
|
|
1709
|
|
1710 /* If the restriction isn't what it should be, set it. */
|
|
1711 if (old_begv != BUF_BEGV (buf) || old_zv != BUF_ZV (buf))
|
161
|
1712 {
|
|
1713 Fwiden(p->buffer);
|
|
1714 old_begv = bufpos_clip_to_bounds (BUF_BEG (buf),
|
|
1715 old_begv,
|
|
1716 BUF_Z (buf));
|
|
1717 old_zv = bufpos_clip_to_bounds (BUF_BEG (buf),
|
|
1718 old_zv,
|
|
1719 BUF_Z (buf));
|
|
1720 Fnarrow_to_region (make_int (old_begv), make_int (old_zv),
|
|
1721 p->buffer);
|
|
1722 }
|
0
|
1723
|
|
1724 /* Handling the process output should not deactivate the mark. */
|
|
1725 zmacs_region_stays = old_zmacs_region_stays;
|
|
1726 buf->read_only = old_read_only;
|
161
|
1727 old_point = bufpos_clip_to_bounds (BUF_BEGV (buf),
|
|
1728 old_point,
|
|
1729 BUF_ZV (buf));
|
0
|
1730 BUF_SET_PT (buf, old_point);
|
|
1731
|
|
1732 UNGCPRO;
|
|
1733 }
|
173
|
1734 return nchars;
|
0
|
1735 }
|
|
1736
|
|
1737 /* Sending data to subprocess */
|
|
1738
|
|
1739 static JMP_BUF send_process_frame;
|
|
1740
|
|
1741 static SIGTYPE
|
|
1742 send_process_trap (int signum)
|
|
1743 {
|
|
1744 EMACS_REESTABLISH_SIGNAL (signum, send_process_trap);
|
|
1745 EMACS_UNBLOCK_SIGNAL (signum);
|
|
1746 LONGJMP (send_process_frame, 1);
|
|
1747 }
|
|
1748
|
|
1749 /* send some data to process PROC. If NONRELOCATABLE is non-NULL, it
|
|
1750 specifies the address of the data. Otherwise, the data comes from the
|
|
1751 object RELOCATABLE (either a string or a buffer). START and LEN
|
|
1752 specify the offset and length of the data to send.
|
|
1753
|
|
1754 Note that START and LEN are in Bufpos's if RELOCATABLE is a buffer,
|
|
1755 and in Bytecounts otherwise. */
|
|
1756
|
|
1757 static void
|
|
1758 send_process (volatile Lisp_Object proc,
|
|
1759 Lisp_Object relocatable, CONST Bufbyte *nonrelocatable,
|
|
1760 int start, int len)
|
|
1761 {
|
|
1762 /* This function can GC */
|
|
1763 /* Use volatile to protect variables from being clobbered by longjmp. */
|
|
1764 struct gcpro gcpro1, gcpro2;
|
16
|
1765 SIGTYPE (*volatile old_sigpipe) (int) = 0;
|
0
|
1766 Lisp_Object lstream = Qnil;
|
|
1767 volatile struct Lisp_Process *p = XPROCESS (proc);
|
|
1768 #if defined (NO_UNION_TYPE) /* || !defined (__GNUC__) GCC bug only??? */
|
|
1769 /* #### ugh! There must be a better solution. */
|
|
1770 Lisp_Object defeat_volatile_kludge = (Lisp_Object) proc;
|
|
1771 #else
|
|
1772 Lisp_Object defeat_volatile_kludge = proc;
|
|
1773 #endif
|
|
1774
|
|
1775 GCPRO2 (defeat_volatile_kludge, lstream);
|
|
1776
|
|
1777 if (p->outfd < 0)
|
|
1778 signal_simple_error ("Process not open for writing", proc);
|
|
1779
|
|
1780 if (nonrelocatable)
|
|
1781 lstream =
|
|
1782 make_fixed_buffer_input_stream (nonrelocatable + start, len);
|
|
1783 else if (GC_BUFFERP (relocatable))
|
|
1784 lstream = make_lisp_buffer_input_stream (XBUFFER (relocatable),
|
|
1785 start, start + len, 0);
|
|
1786 else
|
|
1787 lstream = make_lisp_string_input_stream (relocatable, start, len);
|
|
1788
|
|
1789 if (!SETJMP (send_process_frame))
|
|
1790 {
|
|
1791 /* use a reasonable-sized buffer (somewhere around the size of the
|
|
1792 stream buffer) so as to avoid inundating the stream with blocked
|
|
1793 data. */
|
|
1794 Bufbyte chunkbuf[512];
|
|
1795 Bytecount chunklen;
|
|
1796
|
|
1797 while (1)
|
|
1798 {
|
|
1799 int writeret;
|
|
1800
|
|
1801 chunklen = Lstream_read (XLSTREAM (lstream), chunkbuf, 512);
|
|
1802 if (chunklen <= 0)
|
|
1803 break; /* perhaps should abort() if < 0?
|
|
1804 This should never happen. */
|
|
1805 old_sigpipe =
|
|
1806 (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
|
|
1807 /* Lstream_write() will never successfully write less than
|
|
1808 the amount sent in. In the worst case, it just buffers
|
|
1809 the unwritten data. */
|
|
1810 writeret = Lstream_write (XLSTREAM (p->outstream), chunkbuf,
|
|
1811 chunklen);
|
|
1812 signal (SIGPIPE, old_sigpipe);
|
|
1813 if (writeret < 0)
|
|
1814 /* This is a real error. Blocking errors are handled
|
|
1815 specially inside of the filedesc stream. */
|
|
1816 report_file_error ("writing to process",
|
|
1817 list1 (proc));
|
|
1818 while (filedesc_stream_was_blocked (XLSTREAM (p->filedesc_stream)))
|
|
1819 {
|
185
|
1820 /* Buffer is full. Wait, accepting input;
|
0
|
1821 that may allow the program
|
|
1822 to finish doing output and read more. */
|
|
1823 Faccept_process_output (Qnil, make_int (1), Qnil);
|
|
1824 old_sigpipe =
|
|
1825 (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
|
|
1826 Lstream_flush (XLSTREAM (p->filedesc_stream));
|
|
1827 signal (SIGPIPE, old_sigpipe);
|
|
1828 }
|
|
1829 }
|
|
1830 }
|
|
1831 else
|
|
1832 { /* We got here from a longjmp() from the SIGPIPE handler */
|
|
1833 signal (SIGPIPE, old_sigpipe);
|
|
1834 p->status_symbol = Qexit;
|
|
1835 p->exit_code = 256; /* #### SIGPIPE ??? */
|
|
1836 p->core_dumped = 0;
|
|
1837 p->tick++;
|
|
1838 process_tick++;
|
|
1839 deactivate_process (proc);
|
|
1840 error ("SIGPIPE raised on process %s; closed it",
|
70
|
1841 XSTRING_DATA (p->name));
|
0
|
1842 }
|
207
|
1843 old_sigpipe = (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
|
0
|
1844 Lstream_flush (XLSTREAM (p->outstream));
|
207
|
1845 signal (SIGPIPE, old_sigpipe);
|
0
|
1846 UNGCPRO;
|
185
|
1847 Lstream_delete (XLSTREAM (lstream));
|
0
|
1848 }
|
|
1849
|
20
|
1850 DEFUN ("process-tty-name", Fprocess_tty_name, 1, 1, 0, /*
|
0
|
1851 Return the name of the terminal PROCESS uses, or nil if none.
|
|
1852 This is the terminal that the process itself reads and writes on,
|
|
1853 not the name of the pty that Emacs uses to talk with that terminal.
|
20
|
1854 */
|
|
1855 (proc))
|
0
|
1856 {
|
|
1857 CHECK_PROCESS (proc);
|
|
1858 return XPROCESS (proc)->tty_name;
|
|
1859 }
|
|
1860
|
20
|
1861 DEFUN ("set-process-buffer", Fset_process_buffer, 2, 2, 0, /*
|
0
|
1862 Set buffer associated with PROCESS to BUFFER (a buffer, or nil).
|
20
|
1863 */
|
|
1864 (proc, buffer))
|
0
|
1865 {
|
|
1866 CHECK_PROCESS (proc);
|
|
1867 if (!NILP (buffer))
|
|
1868 CHECK_BUFFER (buffer);
|
|
1869 XPROCESS (proc)->buffer = buffer;
|
|
1870 return buffer;
|
|
1871 }
|
|
1872
|
20
|
1873 DEFUN ("process-buffer", Fprocess_buffer, 1, 1, 0, /*
|
0
|
1874 Return the buffer PROCESS is associated with.
|
|
1875 Output from PROCESS is inserted in this buffer
|
|
1876 unless PROCESS has a filter.
|
20
|
1877 */
|
|
1878 (proc))
|
0
|
1879 {
|
|
1880 CHECK_PROCESS (proc);
|
|
1881 return XPROCESS (proc)->buffer;
|
|
1882 }
|
|
1883
|
20
|
1884 DEFUN ("process-mark", Fprocess_mark, 1, 1, 0, /*
|
0
|
1885 Return the marker for the end of the last output from PROCESS.
|
20
|
1886 */
|
|
1887 (proc))
|
0
|
1888 {
|
|
1889 CHECK_PROCESS (proc);
|
|
1890 #ifdef ENERGIZE
|
|
1891 if (EQ (proc, Venergize_process)) /* per buffer rather than per process */
|
|
1892 return Fenergize_user_input_buffer_mark (Qnil); /* ## current_buffer ok? */
|
|
1893 #endif
|
|
1894 return XPROCESS (proc)->mark;
|
|
1895 }
|
|
1896
|
|
1897 void
|
|
1898 set_process_filter (Lisp_Object proc, Lisp_Object filter, int filter_does_read)
|
|
1899 {
|
|
1900 CHECK_PROCESS (proc);
|
|
1901 if (PROCESS_LIVE_P (proc))
|
|
1902 if (EQ (filter, Qt))
|
|
1903 event_stream_unselect_process (XPROCESS (proc));
|
|
1904 else
|
|
1905 event_stream_select_process (XPROCESS (proc));
|
|
1906
|
|
1907 XPROCESS (proc)->filter = filter;
|
|
1908 XPROCESS (proc)->filter_does_read = filter_does_read;
|
|
1909 }
|
|
1910
|
20
|
1911 DEFUN ("set-process-filter", Fset_process_filter, 2, 2, 0, /*
|
0
|
1912 Give PROCESS the filter function FILTER; nil means no filter.
|
|
1913 t means stop accepting output from the process.
|
|
1914 When a process has a filter, each time it does output
|
|
1915 the entire string of output is passed to the filter.
|
|
1916 The filter gets two arguments: the process and the string of output.
|
|
1917 If the process has a filter, its buffer is not used for output.
|
20
|
1918 */
|
|
1919 (proc, filter))
|
0
|
1920 {
|
|
1921 set_process_filter (proc, filter, 0);
|
|
1922 return filter;
|
|
1923 }
|
|
1924
|
20
|
1925 DEFUN ("process-filter", Fprocess_filter, 1, 1, 0, /*
|
0
|
1926 Return the filter function of PROCESS; nil if none.
|
|
1927 See `set-process-filter' for more info on filter functions.
|
20
|
1928 */
|
|
1929 (proc))
|
0
|
1930 {
|
|
1931 CHECK_PROCESS (proc);
|
|
1932 return XPROCESS (proc)->filter;
|
|
1933 }
|
|
1934
|
20
|
1935 DEFUN ("process-send-region", Fprocess_send_region, 3, 3, 0, /*
|
0
|
1936 Send current contents of region as input to PROCESS.
|
|
1937 PROCESS may be a process name or an actual process.
|
|
1938 Called from program, takes three arguments, PROCESS, START and END.
|
|
1939 If the region is more than 500 or so characters long,
|
|
1940 it is sent in several bunches. This may happen even for shorter regions.
|
|
1941 Output from processes can arrive in between bunches.
|
20
|
1942 */
|
|
1943 (process, start, end))
|
0
|
1944 {
|
|
1945 /* This function can GC */
|
|
1946 Lisp_Object proc = get_process (process);
|
|
1947 Bufpos st, en;
|
|
1948
|
|
1949 get_buffer_range_char (current_buffer, start, end, &st, &en, 0);
|
|
1950
|
|
1951 send_process (proc, Fcurrent_buffer (), 0,
|
|
1952 st, en - st);
|
173
|
1953 return Qnil;
|
0
|
1954 }
|
|
1955
|
20
|
1956 DEFUN ("process-send-string", Fprocess_send_string, 2, 4, 0, /*
|
0
|
1957 Send PROCESS the contents of STRING as input.
|
|
1958 PROCESS may be a process name or an actual process.
|
|
1959 Optional arguments FROM and TO specify part of STRING, see `substring'.
|
|
1960 If STRING is more than 500 or so characters long,
|
|
1961 it is sent in several bunches. This may happen even for shorter strings.
|
|
1962 Output from processes can arrive in between bunches.
|
20
|
1963 */
|
|
1964 (process, string, from, to))
|
0
|
1965 {
|
|
1966 /* This function can GC */
|
|
1967 Lisp_Object proc;
|
|
1968 Bytecount len;
|
|
1969 Bytecount bfr, bto;
|
|
1970
|
|
1971 proc = get_process (process);
|
|
1972 CHECK_STRING (string);
|
|
1973 get_string_range_byte (string, from, to, &bfr, &bto,
|
|
1974 GB_HISTORICAL_STRING_BEHAVIOR);
|
|
1975 len = bto - bfr;
|
|
1976
|
|
1977 send_process (proc, string, 0, bfr, len);
|
173
|
1978 return Qnil;
|
0
|
1979 }
|
|
1980
|
70
|
1981 #ifdef MULE
|
|
1982
|
|
1983 DEFUN ("process-input-coding-system", Fprocess_input_coding_system, 1, 1, 0, /*
|
|
1984 Return PROCESS's input coding system.
|
|
1985 */
|
|
1986 (process))
|
|
1987 {
|
|
1988 process = get_process (process);
|
|
1989 return decoding_stream_coding_system (XLSTREAM ( XPROCESS (process)->instream) );
|
|
1990 }
|
|
1991
|
|
1992 DEFUN ("process-output-coding-system", Fprocess_output_coding_system, 1, 1, 0, /*
|
|
1993 Return PROCESS's output coding system.
|
|
1994 */
|
|
1995 (process))
|
|
1996 {
|
|
1997 process = get_process (process);
|
|
1998 return encoding_stream_coding_system (XLSTREAM (XPROCESS (process)->outstream));
|
|
1999 }
|
|
2000
|
120
|
2001 DEFUN ("process-coding-system", Fprocess_coding_system, 1, 1, 0, /*
|
|
2002 Return a pair of coding-system for decoding and encoding of PROCESS.
|
|
2003 */
|
|
2004 (process))
|
|
2005 {
|
|
2006 process = get_process (process);
|
175
|
2007 return Fcons (decoding_stream_coding_system
|
|
2008 (XLSTREAM (XPROCESS (process)->instream)),
|
|
2009 encoding_stream_coding_system
|
|
2010 (XLSTREAM (XPROCESS (process)->outstream)));
|
120
|
2011 }
|
|
2012
|
70
|
2013 DEFUN ("set-process-input-coding-system",
|
|
2014 Fset_process_input_coding_system, 2, 2, 0, /*
|
|
2015 Set PROCESS's input coding system to CODESYS.
|
|
2016 */
|
|
2017 (process, codesys))
|
|
2018 {
|
|
2019 codesys = Fget_coding_system (codesys);
|
|
2020 process = get_process (process);
|
|
2021 set_decoding_stream_coding_system ( XLSTREAM ( XPROCESS (process)->instream ), codesys);
|
|
2022 return Qnil;
|
|
2023 }
|
|
2024
|
|
2025 DEFUN ("set-process-output-coding-system",
|
|
2026 Fset_process_output_coding_system, 2, 2, 0, /*
|
|
2027 Set PROCESS's output coding system to CODESYS.
|
|
2028 */
|
|
2029 (process, codesys))
|
|
2030 {
|
|
2031 codesys = Fget_coding_system (codesys);
|
|
2032 process = get_process (process);
|
|
2033 set_encoding_stream_coding_system
|
|
2034 ( XLSTREAM ( XPROCESS (process)->outstream), codesys);
|
|
2035 return Qnil;
|
|
2036 }
|
|
2037
|
120
|
2038 DEFUN ("set-process-coding-system",
|
|
2039 Fset_process_coding_system, 1, 3, 0, /*
|
|
2040 Set coding-systems of PROCESS to DECODING and ENCODING.
|
|
2041 */
|
|
2042 (process, decoding, encoding))
|
|
2043 {
|
|
2044 if(!NILP(decoding)){
|
|
2045 Fset_process_input_coding_system(process, decoding);
|
|
2046 }
|
|
2047 if(!NILP(encoding)){
|
|
2048 Fset_process_output_coding_system(process, encoding);
|
|
2049 }
|
|
2050 return Qnil;
|
|
2051 }
|
|
2052
|
70
|
2053 #endif /* MULE */
|
|
2054
|
0
|
2055
|
|
2056 /************************************************************************/
|
|
2057 /* process status */
|
|
2058 /************************************************************************/
|
|
2059
|
|
2060 /* Some FSFmacs error handlers here. We handle this
|
|
2061 in call2_trapping_errors(). */
|
|
2062
|
|
2063 static Lisp_Object
|
|
2064 exec_sentinel_unwind (Lisp_Object datum)
|
|
2065 {
|
|
2066 struct Lisp_Cons *d = XCONS (datum);
|
|
2067 XPROCESS (d->car)->sentinel = d->cdr;
|
|
2068 free_cons (d);
|
|
2069 return Qnil;
|
|
2070 }
|
|
2071
|
|
2072 static void
|
|
2073 exec_sentinel (Lisp_Object proc, Lisp_Object reason)
|
|
2074 {
|
|
2075 /* This function can GC */
|
175
|
2076 int speccount = specpdl_depth ();
|
0
|
2077 struct Lisp_Process *p = XPROCESS (proc);
|
175
|
2078 Lisp_Object sentinel = p->sentinel;
|
|
2079
|
0
|
2080 if (NILP (sentinel))
|
|
2081 return;
|
|
2082
|
|
2083 /* Some weird FSFmacs crap here with
|
|
2084 Vdeactivate_mark and current_buffer->keymap */
|
|
2085
|
|
2086 /* Zilch the sentinel while it's running, to avoid recursive invocations;
|
|
2087 assure that it gets restored no matter how the sentinel exits. */
|
|
2088 p->sentinel = Qnil;
|
|
2089 record_unwind_protect (exec_sentinel_unwind, noseeum_cons (proc, sentinel));
|
|
2090 /* We used to bind inhibit-quit to t here, but call2_trapping_errors()
|
|
2091 does that for us. */
|
|
2092 running_asynch_code = 1;
|
175
|
2093 call2_trapping_errors ("Error in process sentinel", sentinel, proc, reason);
|
0
|
2094 running_asynch_code = 0;
|
|
2095 restore_match_data ();
|
|
2096 unbind_to (speccount, Qnil);
|
|
2097 }
|
|
2098
|
20
|
2099 DEFUN ("set-process-sentinel", Fset_process_sentinel, 2, 2, 0, /*
|
0
|
2100 Give PROCESS the sentinel SENTINEL; nil for none.
|
|
2101 The sentinel is called as a function when the process changes state.
|
|
2102 It gets two arguments: the process, and a string describing the change.
|
20
|
2103 */
|
|
2104 (proc, sentinel))
|
0
|
2105 {
|
|
2106 CHECK_PROCESS (proc);
|
|
2107 XPROCESS (proc)->sentinel = sentinel;
|
|
2108 return sentinel;
|
|
2109 }
|
|
2110
|
20
|
2111 DEFUN ("process-sentinel", Fprocess_sentinel, 1, 1, 0, /*
|
0
|
2112 Return the sentinel of PROCESS; nil if none.
|
|
2113 See `set-process-sentinel' for more info on sentinels.
|
20
|
2114 */
|
|
2115 (proc))
|
0
|
2116 {
|
|
2117 CHECK_PROCESS (proc);
|
|
2118 return XPROCESS (proc)->sentinel;
|
|
2119 }
|
|
2120
|
|
2121
|
|
2122 CONST char *
|
|
2123 signal_name (int signum)
|
|
2124 {
|
|
2125 if (signum >= 0 && signum < NSIG)
|
173
|
2126 return (CONST char *) sys_siglist[signum];
|
209
|
2127
|
173
|
2128 return (CONST char *) GETTEXT ("unknown signal");
|
0
|
2129 }
|
|
2130
|
|
2131 /* Compute the Lisp form of the process status from
|
|
2132 the numeric status that was returned by `wait'. */
|
|
2133
|
|
2134 static void
|
155
|
2135 update_status_from_wait_code (struct Lisp_Process *p, int *w_fmh)
|
0
|
2136 {
|
|
2137 /* C compiler lossage when attempting to pass w directly */
|
155
|
2138 int w = *w_fmh;
|
0
|
2139
|
|
2140 if (WIFSTOPPED (w))
|
|
2141 {
|
|
2142 p->status_symbol = Qstop;
|
|
2143 p->exit_code = WSTOPSIG (w);
|
|
2144 p->core_dumped = 0;
|
|
2145 }
|
|
2146 else if (WIFEXITED (w))
|
|
2147 {
|
|
2148 p->status_symbol = Qexit;
|
155
|
2149 p->exit_code = WEXITSTATUS (w);
|
|
2150 p->core_dumped = 0;
|
0
|
2151 }
|
|
2152 else if (WIFSIGNALED (w))
|
|
2153 {
|
|
2154 p->status_symbol = Qsignal;
|
155
|
2155 p->exit_code = WTERMSIG (w);
|
|
2156 p->core_dumped = WCOREDUMP (w);
|
0
|
2157 }
|
|
2158 else
|
|
2159 {
|
|
2160 p->status_symbol = Qrun;
|
|
2161 p->exit_code = 0;
|
|
2162 }
|
|
2163 }
|
|
2164
|
|
2165 void
|
|
2166 update_process_status (Lisp_Object p,
|
|
2167 Lisp_Object status_symbol,
|
|
2168 int exit_code,
|
|
2169 int core_dumped)
|
|
2170 {
|
|
2171 XPROCESS (p)->tick++;
|
|
2172 process_tick++;
|
|
2173 XPROCESS (p)->status_symbol = status_symbol;
|
|
2174 XPROCESS (p)->exit_code = exit_code;
|
|
2175 XPROCESS (p)->core_dumped = core_dumped;
|
|
2176 }
|
|
2177
|
|
2178 #ifdef SIGCHLD
|
|
2179
|
|
2180 #define MAX_EXITED_PROCESSES 1000
|
|
2181 static volatile pid_t exited_processes[MAX_EXITED_PROCESSES];
|
155
|
2182 static volatile int exited_processes_status[MAX_EXITED_PROCESSES];
|
0
|
2183 static volatile int exited_processes_index;
|
|
2184
|
|
2185 static volatile int sigchld_happened;
|
|
2186
|
|
2187 /* For any processes that have changed status and are recorded
|
|
2188 and such, update the corresponding struct Lisp_Process.
|
|
2189 We separate this from record_exited_processes() so that
|
|
2190 we never have to call this function from within a signal
|
|
2191 handler. We block SIGCHLD in case record_exited_processes()
|
|
2192 is called from a signal handler. */
|
|
2193
|
|
2194 static void
|
|
2195 reap_exited_processes (void)
|
|
2196 {
|
|
2197 int i;
|
|
2198 struct Lisp_Process *p;
|
|
2199
|
114
|
2200 if (exited_processes_index <= 0)
|
|
2201 {
|
|
2202 return;
|
|
2203 }
|
|
2204
|
100
|
2205 #ifdef EMACS_BLOCK_SIGNAL
|
0
|
2206 EMACS_BLOCK_SIGNAL (SIGCHLD);
|
100
|
2207 #endif
|
0
|
2208 for (i = 0; i < exited_processes_index; i++)
|
|
2209 {
|
|
2210 int pid = exited_processes[i];
|
155
|
2211 int w = exited_processes_status[i];
|
0
|
2212
|
|
2213 /* Find the process that signaled us, and record its status. */
|
|
2214
|
|
2215 p = 0;
|
|
2216 {
|
|
2217 Lisp_Object tail;
|
|
2218 LIST_LOOP (tail, Vprocess_list)
|
|
2219 {
|
|
2220 Lisp_Object proc = XCAR (tail);
|
|
2221 p = XPROCESS (proc);
|
|
2222 if (INTP (p->pid) && XINT (p->pid) == pid)
|
|
2223 break;
|
|
2224 p = 0;
|
|
2225 }
|
|
2226 }
|
|
2227
|
|
2228 if (p)
|
|
2229 {
|
|
2230 /* Change the status of the process that was found. */
|
|
2231 p->tick++;
|
|
2232 process_tick++;
|
|
2233 update_status_from_wait_code (p, &w);
|
185
|
2234
|
0
|
2235 /* If process has terminated, stop waiting for its output. */
|
|
2236 if (WIFSIGNALED (w) || WIFEXITED (w))
|
|
2237 {
|
|
2238 if (p->infd >= 0)
|
|
2239 {
|
|
2240 /* We can't just call event_stream->unselect_process_cb (p)
|
|
2241 here, because that calls XtRemoveInput, which is not
|
|
2242 necessarily reentrant, so we can't call this at interrupt
|
|
2243 level.
|
|
2244 */
|
|
2245 }
|
|
2246 }
|
|
2247 }
|
|
2248 else
|
|
2249 {
|
|
2250 /* There was no asynchronous process found for that id. Check
|
|
2251 if we have a synchronous process. Only set sync process status
|
|
2252 if there is one, so we work OK with the waitpid() call in
|
|
2253 wait_for_termination(). */
|
|
2254 if (synch_process_alive != 0)
|
|
2255 { /* Set the global sync process status variables. */
|
|
2256 synch_process_alive = 0;
|
|
2257
|
|
2258 /* Report the status of the synchronous process. */
|
|
2259 if (WIFEXITED (w))
|
155
|
2260 synch_process_retcode = WEXITSTATUS (w);
|
0
|
2261 else if (WIFSIGNALED (w))
|
|
2262 synch_process_death = signal_name (WTERMSIG (w));
|
|
2263 }
|
|
2264 }
|
|
2265 }
|
|
2266
|
|
2267 exited_processes_index = 0;
|
185
|
2268
|
0
|
2269 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
|
|
2270 }
|
|
2271
|
|
2272 /* On receipt of a signal that a child status has changed,
|
|
2273 loop asking about children with changed statuses until
|
|
2274 the system says there are no more. All we do is record
|
|
2275 the processes and wait status.
|
|
2276
|
|
2277 This function could be called from within the SIGCHLD
|
|
2278 handler, so it must be completely reentrant. When
|
|
2279 not called from a SIGCHLD handler, BLOCK_SIGCHLD should
|
|
2280 be non-zero so that SIGCHLD is blocked while this
|
|
2281 function is running. (This is necessary so avoid
|
|
2282 race conditions with the SIGCHLD_HAPPENED flag). */
|
|
2283
|
|
2284 static void
|
|
2285 record_exited_processes (int block_sigchld)
|
|
2286 {
|
114
|
2287 if (!sigchld_happened)
|
|
2288 {
|
|
2289 return;
|
|
2290 }
|
|
2291
|
102
|
2292 #ifdef EMACS_BLOCK_SIGNAL
|
0
|
2293 if (block_sigchld)
|
|
2294 EMACS_BLOCK_SIGNAL (SIGCHLD);
|
100
|
2295 #endif
|
0
|
2296
|
|
2297 while (sigchld_happened)
|
|
2298 {
|
|
2299 int pid;
|
155
|
2300 int w;
|
185
|
2301
|
0
|
2302 /* Keep trying to get a status until we get a definitive result. */
|
185
|
2303 do
|
0
|
2304 {
|
|
2305 errno = 0;
|
|
2306 #ifdef WNOHANG
|
|
2307 # ifndef WUNTRACED
|
|
2308 # define WUNTRACED 0
|
|
2309 # endif /* not WUNTRACED */
|
|
2310 # ifdef HAVE_WAITPID
|
|
2311 pid = waitpid ((pid_t) -1, &w, WNOHANG | WUNTRACED);
|
|
2312 # else
|
|
2313 pid = wait3 (&w, WNOHANG | WUNTRACED, 0);
|
|
2314 # endif
|
|
2315 #else /* not WNOHANG */
|
|
2316 pid = wait (&w);
|
|
2317 #endif /* not WNOHANG */
|
|
2318 }
|
|
2319 while (pid <= 0 && errno == EINTR);
|
185
|
2320
|
0
|
2321 if (pid <= 0)
|
|
2322 break;
|
185
|
2323
|
0
|
2324 if (exited_processes_index < MAX_EXITED_PROCESSES)
|
|
2325 {
|
|
2326 exited_processes[exited_processes_index] = pid;
|
|
2327 exited_processes_status[exited_processes_index] = w;
|
|
2328 exited_processes_index++;
|
|
2329 }
|
185
|
2330
|
0
|
2331 /* On systems with WNOHANG, we just ignore the number
|
|
2332 of times that SIGCHLD was signalled, and keep looping
|
|
2333 until there are no more processes to wait on. If we
|
|
2334 don't have WNOHANG, we have to rely on the count in
|
|
2335 SIGCHLD_HAPPENED. */
|
|
2336 #ifndef WNOHANG
|
|
2337 sigchld_happened--;
|
|
2338 #endif /* not WNOHANG */
|
|
2339 }
|
|
2340
|
|
2341 sigchld_happened = 0;
|
|
2342
|
|
2343 if (block_sigchld)
|
|
2344 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
|
|
2345 }
|
|
2346
|
|
2347 /** USG WARNING: Although it is not obvious from the documentation
|
|
2348 in signal(2), on a USG system the SIGCLD handler MUST NOT call
|
|
2349 signal() before executing at least one wait(), otherwise the handler
|
|
2350 will be called again, resulting in an infinite loop. The relevant
|
|
2351 portion of the documentation reads "SIGCLD signals will be queued
|
|
2352 and the signal-catching function will be continually reentered until
|
|
2353 the queue is empty". Invoking signal() causes the kernel to reexamine
|
|
2354 the SIGCLD queue. Fred Fish, UniSoft Systems Inc.
|
185
|
2355
|
0
|
2356 (Note that now this only applies in SYS V Release 2 and before.
|
|
2357 On SYS V Release 3, we use sigset() to set the signal handler for
|
|
2358 the first time, and so we don't have to reestablish the signal handler
|
|
2359 in the handler below. On SYS V Release 4, we don't get this weirdo
|
|
2360 behavior when we use sigaction(), which we do use.) */
|
|
2361
|
|
2362 static SIGTYPE
|
|
2363 sigchld_handler (int signo)
|
|
2364 {
|
|
2365 #ifdef OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
|
|
2366 int old_errno = errno;
|
|
2367
|
|
2368 sigchld_happened++;
|
|
2369 record_exited_processes (0);
|
|
2370 errno = old_errno;
|
|
2371 #else
|
|
2372 sigchld_happened++;
|
|
2373 #endif
|
|
2374 signal_fake_event ();
|
|
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);
|
|
3059 XPROCESS (proc)->outfd = open (NULL_DEVICE, O_WRONLY, 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;
|
|
3237 proc_buffered_char[i] = -1;
|
|
3238 }
|
|
3239 }
|
149
|
3240
|
0
|
3241 #if 0
|
|
3242
|
149
|
3243 xxDEFUN ("process-connection", Fprocess_connection, 0, 1, 0, /*
|
0
|
3244 Return the connection type of `PROCESS'. This can be nil (pipe),
|
|
3245 t or pty (pty) or stream (socket connection).
|
149
|
3246 */
|
|
3247 (process))
|
0
|
3248 {
|
|
3249 return XPROCESS (process)->type;
|
|
3250 }
|
|
3251
|
|
3252 #endif /* 0 */
|
|
3253
|
|
3254 void
|
|
3255 syms_of_process (void)
|
|
3256 {
|
|
3257 defsymbol (&Qprocessp, "processp");
|
|
3258 defsymbol (&Qrun, "run");
|
|
3259 defsymbol (&Qstop, "stop");
|
|
3260 defsymbol (&Qsignal, "signal");
|
|
3261 /* Qexit is already defined by syms_of_eval
|
185
|
3262 * defsymbol (&Qexit, "exit");
|
0
|
3263 */
|
|
3264 defsymbol (&Qopen, "open");
|
|
3265 defsymbol (&Qclosed, "closed");
|
|
3266
|
20
|
3267 DEFSUBR (Fprocessp);
|
|
3268 DEFSUBR (Fget_process);
|
|
3269 DEFSUBR (Fget_buffer_process);
|
|
3270 DEFSUBR (Fdelete_process);
|
|
3271 DEFSUBR (Fprocess_status);
|
|
3272 DEFSUBR (Fprocess_exit_status);
|
|
3273 DEFSUBR (Fprocess_id);
|
|
3274 DEFSUBR (Fprocess_name);
|
|
3275 DEFSUBR (Fprocess_tty_name);
|
|
3276 DEFSUBR (Fprocess_command);
|
|
3277 DEFSUBR (Fset_process_buffer);
|
|
3278 DEFSUBR (Fprocess_buffer);
|
|
3279 DEFSUBR (Fprocess_mark);
|
|
3280 DEFSUBR (Fset_process_filter);
|
|
3281 DEFSUBR (Fprocess_filter);
|
|
3282 DEFSUBR (Fset_process_window_size);
|
|
3283 DEFSUBR (Fset_process_sentinel);
|
|
3284 DEFSUBR (Fprocess_sentinel);
|
|
3285 DEFSUBR (Fprocess_kill_without_query);
|
|
3286 DEFSUBR (Fprocess_kill_without_query_p);
|
|
3287 DEFSUBR (Fprocess_list);
|
|
3288 DEFSUBR (Fstart_process_internal);
|
0
|
3289 #ifdef HAVE_SOCKETS
|
20
|
3290 DEFSUBR (Fopen_network_stream_internal);
|
0
|
3291 #endif /* HAVE_SOCKETS */
|
20
|
3292 DEFSUBR (Fprocess_send_region);
|
|
3293 DEFSUBR (Fprocess_send_string);
|
|
3294 DEFSUBR (Finterrupt_process);
|
|
3295 DEFSUBR (Fkill_process);
|
|
3296 DEFSUBR (Fquit_process);
|
|
3297 DEFSUBR (Fstop_process);
|
|
3298 DEFSUBR (Fcontinue_process);
|
|
3299 DEFSUBR (Fprocess_send_eof);
|
|
3300 DEFSUBR (Fsignal_process);
|
|
3301 /* DEFSUBR (Fprocess_connection); */
|
70
|
3302 #ifdef MULE
|
|
3303 DEFSUBR (Fprocess_input_coding_system);
|
|
3304 DEFSUBR (Fprocess_output_coding_system);
|
|
3305 DEFSUBR (Fset_process_input_coding_system);
|
|
3306 DEFSUBR (Fset_process_output_coding_system);
|
120
|
3307 DEFSUBR (Fprocess_coding_system);
|
|
3308 DEFSUBR (Fset_process_coding_system);
|
70
|
3309 #endif /* MULE */
|
0
|
3310 }
|
|
3311
|
|
3312 void
|
|
3313 vars_of_process (void)
|
|
3314 {
|
|
3315 Fprovide (intern ("subprocesses"));
|
|
3316 #ifdef HAVE_SOCKETS
|
|
3317 Fprovide (intern ("network-streams"));
|
|
3318 #endif
|
|
3319 staticpro (&Vprocess_list);
|
|
3320
|
|
3321 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes /*
|
|
3322 *Non-nil means delete processes immediately when they exit.
|
|
3323 nil means don't delete them until `list-processes' is run.
|
|
3324 */ );
|
|
3325
|
|
3326 delete_exited_processes = 1;
|
|
3327
|
|
3328 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type /*
|
|
3329 Control type of device used to communicate with subprocesses.
|
|
3330 Values are nil to use a pipe, or t or `pty' to use a pty.
|
|
3331 The value has no effect if the system has no ptys or if all ptys are busy:
|
|
3332 then a pipe is used in any case.
|
|
3333 The value takes effect when `start-process' is called.
|
|
3334 */ );
|
|
3335 Vprocess_connection_type = Qt;
|
153
|
3336
|
|
3337 #ifdef PROCESS_IO_BLOCKING
|
|
3338 DEFVAR_LISP ("network-stream-blocking-port-list", &network_stream_blocking_port_list /*
|
|
3339 List of port numbers or port names to set a blocking I/O mode with connection.
|
|
3340 Nil value means to set a default(non-blocking) I/O mode.
|
|
3341 The value takes effect when `open-network-stream-internal' is called.
|
|
3342 */ );
|
|
3343 network_stream_blocking_port_list = Qnil;
|
|
3344 #endif /* PROCESS_IO_BLOCKING */
|
0
|
3345 }
|
|
3346
|
|
3347 #endif /* not NO_SUBPROCESSES */
|