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