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