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