XEmacs 21.2.5
[chise/xemacs-chise.git.1] / src / process.c
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 /* This file has been Mule-ized except for `start-process-internal',
25    `open-network-stream-internal' and `open-multicast-group-internal'. */
26
27 /* This file has been split into process.c and process-unix.c by
28    Kirill M. Katsnelson <kkm@kis.ru>, so please bash him and not
29    the original author(s) */
30
31 #include <config.h>
32
33 #if !defined (NO_SUBPROCESSES)
34
35 /* The entire file is within this conditional */
36
37 #include "lisp.h"
38
39 #include "buffer.h"
40 #include "commands.h"
41 #include "events.h"
42 #include "frame.h"
43 #include "hash.h"
44 #include "insdel.h"
45 #include "lstream.h"
46 #include "opaque.h"
47 #include "process.h"
48 #include "procimpl.h"
49 #include "window.h"
50 #ifdef FILE_CODING
51 #include "file-coding.h"
52 #endif
53
54 #include "sysfile.h"
55 #include "sysproc.h"
56 #include "systime.h"
57 #include "syssignal.h" /* Always include before systty.h */
58 #include "systty.h"
59 #include "syswait.h"
60
61 Lisp_Object Qprocessp;
62
63 /* Process methods */
64 struct process_methods the_process_methods;
65
66 /* a process object is a network connection when its pid field a cons
67    (name of name of port we are connected to . foreign host name) */
68
69 /* Valid values of process->status_symbol */
70 Lisp_Object Qrun, Qstop;
71 /* Qrun => Qopen, Qexit => Qclosed for "network connection" processes */
72 Lisp_Object Qopen, Qclosed;
73 /* Protocol families */
74 Lisp_Object Qtcpip;
75
76 #ifdef HAVE_MULTICAST
77 Lisp_Object Qmulticast; /* Will be used for occasional warnings */
78 #endif
79
80 /* t means use pty, nil means use a pipe,
81    maybe other values to come.  */
82 Lisp_Object Vprocess_connection_type;
83
84 /* Read comments to DEFVAR of this */
85 int windowed_process_io;
86
87 #ifdef PROCESS_IO_BLOCKING
88 /* List of port numbers or port names to set a blocking I/O mode.
89    Nil means set a non-blocking I/O mode [default]. */
90 Lisp_Object network_stream_blocking_port_list;
91 #endif  /* PROCESS_IO_BLOCKING */
92
93 /* Number of events of change of status of a process.  */
94 volatile int process_tick;
95
96 /* Number of events for which the user or sentinel has been notified.  */
97 static int update_tick;
98
99 /* Nonzero means delete a process right away if it exits.  */
100 int delete_exited_processes;
101
102 /* Hash table which maps USIDs as returned by create_stream_pair_cb to
103    process objects. Processes are not GC-protected through this! */
104 struct hash_table *usid_to_process;
105
106 /* List of process objects. */
107 Lisp_Object Vprocess_list;
108
109 \f
110
111 static Lisp_Object
112 mark_process (Lisp_Object obj, void (*markobj) (Lisp_Object))
113 {
114   struct Lisp_Process *proc = XPROCESS (obj);
115   MAYBE_PROCMETH (mark_process_data, (proc, markobj));
116   markobj (proc->name);
117   markobj (proc->command);
118   markobj (proc->filter);
119   markobj (proc->sentinel);
120   markobj (proc->buffer);
121   markobj (proc->mark);
122   markobj (proc->pid);
123   markobj (proc->pipe_instream);
124   markobj (proc->pipe_outstream);
125 #ifdef FILE_CODING
126   markobj (proc->coding_instream);
127   markobj (proc->coding_outstream);
128 #endif
129   return proc->status_symbol;
130 }
131
132 static void
133 print_process (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
134 {
135   struct Lisp_Process *proc = XPROCESS (obj);
136
137   if (print_readably)
138     error ("printing unreadable object #<process %s>",
139            XSTRING_DATA (proc->name));
140
141   if (!escapeflag)
142     {
143       print_internal (proc->name, printcharfun, 0);
144     }
145   else
146     {
147       int netp = network_connection_p (obj);
148       write_c_string (((netp) ? GETTEXT ("#<network connection ") :
149                        GETTEXT ("#<process ")), printcharfun);
150       print_internal (proc->name, printcharfun, 1);
151       write_c_string (((netp) ? " " : " pid "), printcharfun);
152       print_internal (proc->pid, printcharfun, 1);
153       write_c_string (" state:", printcharfun);
154       print_internal (proc->status_symbol, printcharfun, 1);
155       MAYBE_PROCMETH (print_process_data, (proc, printcharfun));
156       write_c_string (">", printcharfun);
157     }
158 }
159
160 #ifdef HAVE_WINDOW_SYSTEM
161 extern void debug_process_finalization (struct Lisp_Process *p);
162 #endif /* HAVE_WINDOW_SYSTEM */
163
164 static void
165 finalize_process (void *header, int for_disksave)
166 {
167   /* #### this probably needs to be tied into the tty event loop */
168   /* #### when there is one */
169   struct Lisp_Process *p = (struct Lisp_Process *) header;
170 #ifdef HAVE_WINDOW_SYSTEM
171   if (!for_disksave)
172     {
173       debug_process_finalization (p);
174     }
175 #endif /* HAVE_WINDOW_SYSTEM */
176
177   if (p->process_data)
178     {
179       MAYBE_PROCMETH (finalize_process_data, (p, for_disksave));
180       if (!for_disksave)
181         xfree (p->process_data);
182     }
183 }
184
185 DEFINE_LRECORD_IMPLEMENTATION ("process", process,
186                                mark_process, print_process, finalize_process,
187                                0, 0, struct Lisp_Process);
188 \f
189 /************************************************************************/
190 /*                       basic process accessors                        */
191 /************************************************************************/
192
193 /* Under FILE_CODING, this function returns low-level streams, connected
194    directly to the child process, rather than en/decoding FILE_CODING
195    streams */
196 void
197 get_process_streams (struct Lisp_Process *p,
198                      Lisp_Object *instr, Lisp_Object *outstr)
199 {
200   assert (p);
201   assert (NILP (p->pipe_instream) || LSTREAMP(p->pipe_instream));
202   assert (NILP (p->pipe_outstream) || LSTREAMP(p->pipe_outstream));
203   *instr = p->pipe_instream;
204   *outstr = p->pipe_outstream;
205 }
206
207 struct Lisp_Process *
208 get_process_from_usid (USID usid)
209 {
210   CONST void *vval;
211
212   assert (usid != USID_ERROR && usid != USID_DONTHASH);
213
214   if (gethash ((CONST void*)usid, usid_to_process, &vval))
215     {
216       Lisp_Object proc;
217       CVOID_TO_LISP (proc, vval);
218       return XPROCESS (proc);
219     }
220   else
221     return 0;
222 }
223
224 int
225 get_process_selected_p (struct Lisp_Process *p)
226 {
227   return p->selected;
228 }
229
230 void
231 set_process_selected_p (struct Lisp_Process *p, int selected_p)
232 {
233   p->selected = !!selected_p;
234 }
235
236 int
237 connected_via_filedesc_p (struct Lisp_Process *p)
238 {
239   return MAYBE_INT_PROCMETH (tooltalk_connection_p, (p));
240 }
241
242 #ifdef HAVE_SOCKETS
243 int
244 network_connection_p (Lisp_Object process)
245 {
246   return GC_CONSP (XPROCESS (process)->pid);
247 }
248 #endif
249
250 DEFUN ("processp", Fprocessp, 1, 1, 0, /*
251 Return t if OBJECT is a process.
252 */
253        (obj))
254 {
255   return PROCESSP (obj) ? Qt : Qnil;
256 }
257
258 DEFUN ("process-list", Fprocess_list, 0, 0, 0, /*
259 Return a list of all processes.
260 */
261        ())
262 {
263   return Fcopy_sequence (Vprocess_list);
264 }
265
266 DEFUN ("get-process", Fget_process, 1, 1, 0, /*
267 Return the process named NAME, or nil if there is none.
268 */
269        (name))
270 {
271   Lisp_Object tail;
272
273   if (GC_PROCESSP (name))
274     return name;
275
276   if (!gc_in_progress)
277     /* this only gets called during GC when emacs is going away as a result
278        of a signal or crash. */
279     CHECK_STRING (name);
280
281   for (tail = Vprocess_list; GC_CONSP (tail); tail = XCDR (tail))
282     {
283       Lisp_Object proc = XCAR (tail);
284       QUIT;
285       if (internal_equal (name, XPROCESS (proc)->name, 0))
286         return XCAR (tail);
287     }
288   return Qnil;
289 }
290
291 DEFUN ("get-buffer-process", Fget_buffer_process, 1, 1, 0, /*
292 Return the (or, a) process associated with BUFFER.
293 BUFFER may be a buffer or the name of one.
294 */
295        (name))
296 {
297   Lisp_Object buf, tail, proc;
298
299   if (GC_NILP (name)) return Qnil;
300   buf = Fget_buffer (name);
301   if (GC_NILP (buf)) return Qnil;
302
303   for (tail = Vprocess_list; GC_CONSP (tail); tail = XCDR (tail))
304     {
305       /* jwz: do not quit here - it isn't necessary, as there is no way for
306          Vprocess_list to get circular or overwhelmingly long, and this
307          function is called from layout_mode_element under redisplay. */
308       /* QUIT; */
309       proc = XCAR (tail);
310       if (GC_PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf))
311         return proc;
312     }
313   return Qnil;
314 }
315
316 /* This is how commands for the user decode process arguments.  It
317    accepts a process, a process name, a buffer, a buffer name, or nil.
318    Buffers denote the first process in the buffer, and nil denotes the
319    current buffer.  */
320
321 static Lisp_Object
322 get_process (Lisp_Object name)
323 {
324   Lisp_Object proc, obj;
325
326 #ifdef I18N3
327   /* #### Look more closely into translating process names. */
328 #endif
329
330   /* This may be called during a GC from process_send_signal() from
331      kill_buffer_processes() if emacs decides to abort(). */
332   if (GC_PROCESSP (name))
333     return name;
334
335   if (GC_STRINGP (name))
336     {
337       obj = Fget_process (name);
338       if (GC_NILP (obj))
339         obj = Fget_buffer (name);
340       if (GC_NILP (obj))
341         error ("Process %s does not exist", XSTRING_DATA (name));
342     }
343   else if (GC_NILP (name))
344     obj = Fcurrent_buffer ();
345   else
346     obj = name;
347
348   /* Now obj should be either a buffer object or a process object.
349    */
350   if (GC_BUFFERP (obj))
351     {
352       proc = Fget_buffer_process (obj);
353       if (GC_NILP (proc))
354         error ("Buffer %s has no process", XSTRING_DATA (XBUFFER(obj)->name));
355     }
356   else
357     {
358       /* #### This was commented out. Although, simple
359          (kill-process 7 "qqq") resulted in a fatal error. - kkm */
360       CHECK_PROCESS (obj);
361       proc = obj;
362     }
363   return proc;
364 }
365
366 DEFUN ("process-id", Fprocess_id, 1, 1, 0, /*
367 Return the process id of PROCESS.
368 This is the pid of the Unix process which PROCESS uses or talks to.
369 For a network connection, this value is a cons of
370  (foreign-network-port . foreign-host-name).
371 */
372        (proc))
373 {
374   Lisp_Object pid;
375   CHECK_PROCESS (proc);
376
377   pid = XPROCESS (proc)->pid;
378   if (network_connection_p (proc))
379     /* return Qnil; */
380     return Fcons (Fcar (pid), Fcdr (pid));
381   else
382     return pid;
383 }
384
385 DEFUN ("process-name", Fprocess_name, 1, 1, 0, /*
386 Return the name of PROCESS, as a string.
387 This is the name of the program invoked in PROCESS,
388 possibly modified to make it unique among process names.
389 */
390        (proc))
391 {
392   CHECK_PROCESS (proc);
393   return XPROCESS (proc)->name;
394 }
395
396 DEFUN ("process-command", Fprocess_command, 1, 1, 0, /*
397 Return the command that was executed to start PROCESS.
398 This is a list of strings, the first string being the program executed
399 and the rest of the strings being the arguments given to it.
400 */
401        (proc))
402 {
403   CHECK_PROCESS (proc);
404   return XPROCESS (proc)->command;
405 }
406
407 \f
408 /************************************************************************/
409 /*                          creating a process                          */
410 /************************************************************************/
411
412 Lisp_Object
413 make_process_internal (Lisp_Object name)
414 {
415   Lisp_Object val, name1;
416   int i;
417   struct Lisp_Process *p =
418     alloc_lcrecord_type (struct Lisp_Process, lrecord_process);
419
420   /* If name is already in use, modify it until it is unused.  */
421   name1 = name;
422   for (i = 1; ; i++)
423     {
424       char suffix[10];
425       Lisp_Object tem = Fget_process (name1);
426       if (NILP (tem))
427         break;
428       sprintf (suffix, "<%d>", i);
429       name1 = concat2 (name, build_string (suffix));
430     }
431   name = name1;
432   p->name = name;
433
434   p->command  = Qnil;
435   p->filter   = Qnil;
436   p->sentinel = Qnil;
437   p->buffer   = Qnil;
438   p->mark = Fmake_marker ();
439   p->pid = Qnil;
440   p->status_symbol = Qrun;
441   p->exit_code = 0;
442   p->core_dumped = 0;
443   p->filter_does_read = 0;
444   p->kill_without_query = 0;
445   p->selected = 0;
446   p->tick = 0;
447   p->update_tick = 0;
448   p->pipe_instream  = Qnil;
449   p->pipe_outstream = Qnil;
450 #ifdef FILE_CODING
451   p->coding_instream  = Qnil;
452   p->coding_outstream = Qnil;
453 #endif
454
455   p->process_data = 0;
456   MAYBE_PROCMETH (alloc_process_data, (p));
457
458   XSETPROCESS (val, p);
459
460   Vprocess_list = Fcons (val, Vprocess_list);
461   return val;
462 }
463
464 void
465 init_process_io_handles (struct Lisp_Process *p, void* in, void* out, int flags)
466 {
467   USID usid = event_stream_create_stream_pair (in, out,
468                                                &p->pipe_instream, &p->pipe_outstream,
469                                                flags);
470
471   if (usid == USID_ERROR)
472     report_file_error ("Setting up communication with subprocess", Qnil);
473
474   if (usid != USID_DONTHASH)
475     {
476       Lisp_Object proc = Qnil;
477       XSETPROCESS (proc, p);
478       puthash ((CONST void*)usid, LISP_TO_VOID (proc), usid_to_process);
479     }
480
481   MAYBE_PROCMETH (init_process_io_handles, (p, in, out, flags));
482
483 #ifdef FILE_CODING
484   p->coding_instream = make_decoding_input_stream
485     (XLSTREAM (p->pipe_instream),
486      Fget_coding_system (Vcoding_system_for_read));
487   Lstream_set_character_mode (XLSTREAM (p->coding_instream));
488   p->coding_outstream = make_encoding_output_stream
489     (XLSTREAM (p->pipe_outstream),
490      Fget_coding_system (Vcoding_system_for_write));
491   /* CODE_CNTL (&out_state[outchannel]) |= CC_END; !!####
492      What's going on here? */
493 #endif /* FILE_CODING */
494 }
495
496 static void
497 create_process (Lisp_Object process, Lisp_Object *argv, int nargv,
498                 Lisp_Object program, Lisp_Object cur_dir)
499 {
500   struct Lisp_Process *p = XPROCESS (process);
501   int pid;
502
503   /* *_create_process may change status_symbol, if the process
504      is a kind of "fire-and-forget" (no I/O, unwaitable) */
505   p->status_symbol = Qrun;
506   p->exit_code = 0;
507
508   pid = PROCMETH (create_process, (p, argv, nargv, program, cur_dir));
509
510   p->pid = make_int (pid);
511   if (!NILP(p->pipe_instream))
512     event_stream_select_process (p);
513 }
514
515 /* This function is the unwind_protect form for Fstart_process_internal.  If
516    PROC doesn't have its pid set, then we know someone has signalled
517    an error and the process wasn't started successfully, so we should
518    remove it from the process list.  */
519 static void remove_process (Lisp_Object proc);
520 static Lisp_Object
521 start_process_unwind (Lisp_Object proc)
522 {
523   /* Was PROC started successfully?  */
524   if (EQ (XPROCESS (proc)->pid, Qnil))
525     remove_process (proc);
526   return Qnil;
527 }
528
529 DEFUN ("start-process-internal", Fstart_process_internal, 3, MANY, 0, /*
530 Start a program in a subprocess.  Return the process object for it.
531 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS
532 NAME is name for process.  It is modified if necessary to make it unique.
533 BUFFER is the buffer or (buffer-name) to associate with the process.
534  Process output goes at end of that buffer, unless you specify
535  an output stream or filter function to handle the output.
536  BUFFER may be also nil, meaning that this process is not associated
537  with any buffer
538 Third arg is program file name.  It is searched for as in the shell.
539 Remaining arguments are strings to give program as arguments.
540 INCODE and OUTCODE specify the coding-system objects used in input/output
541  from/to the process.
542 */
543        (int nargs, Lisp_Object *args))
544 {
545   /* This function can call lisp */
546   /* !!#### This function has not been Mule-ized */
547   Lisp_Object buffer, name, program, proc, current_dir;
548   Lisp_Object tem;
549   int speccount = specpdl_depth ();
550   struct gcpro gcpro1, gcpro2, gcpro3;
551
552   name = args[0];
553   buffer = args[1];
554   program = args[2];
555   current_dir = Qnil;
556
557   /* Protect against various file handlers doing GCs below. */
558   GCPRO3 (buffer, program, current_dir);
559
560   if (!NILP (buffer))
561     buffer = Fget_buffer_create (buffer);
562
563   CHECK_STRING (name);
564   CHECK_STRING (program);
565
566   /* Make sure that the child will be able to chdir to the current
567      buffer's current directory, or its unhandled equivalent.  We
568      can't just have the child check for an error when it does the
569      chdir, since it's in a vfork.
570
571      Note: these assignments and calls are like this in order to insure
572      "caller protects args" GC semantics. */
573   current_dir = current_buffer->directory;
574   current_dir = Funhandled_file_name_directory (current_dir);
575   current_dir = expand_and_dir_to_file (current_dir, Qnil);
576
577 #if 0   /* This loser breaks ange-ftp */
578   /* dmoore - if you re-enable this code, you have to gcprotect
579      current_buffer through the above calls. */
580   if (NILP (Ffile_accessible_directory_p (current_dir)))
581     report_file_error ("Setting current directory",
582                        list1 (current_buffer->directory));
583 #endif /* 0 */
584
585   /* If program file name is not absolute, search our path for it */
586   if (!IS_DIRECTORY_SEP (XSTRING_BYTE (program, 0))
587       && !(XSTRING_LENGTH (program) > 1
588            && IS_DEVICE_SEP (XSTRING_BYTE (program, 1))))
589     {
590       struct gcpro ngcpro1;
591
592       tem = Qnil;
593       NGCPRO1 (tem);
594       locate_file (Vexec_path, program, EXEC_SUFFIXES, &tem,
595                    X_OK);
596       if (NILP (tem))
597         report_file_error ("Searching for program", list1 (program));
598       program = Fexpand_file_name (tem, Qnil);
599       NUNGCPRO;
600     }
601   else
602     {
603       if (!NILP (Ffile_directory_p (program)))
604         error ("Specified program for new process is a directory");
605     }
606
607   proc = make_process_internal (name);
608
609   XPROCESS (proc)->buffer = buffer;
610   XPROCESS (proc)->command = Flist (nargs - 2,
611                                     args + 2);
612
613   /* Make the process marker point into the process buffer (if any).  */
614   if (!NILP (buffer))
615     Fset_marker (XPROCESS (proc)->mark,
616                  make_int (BUF_ZV (XBUFFER (buffer))), buffer);
617
618   /* If an error occurs and we can't start the process, we want to
619      remove it from the process list.  This means that each error
620      check in create_process doesn't need to call remove_process
621      itself; it's all taken care of here.  */
622   record_unwind_protect (start_process_unwind, proc);
623
624   create_process (proc, args + 3, nargs - 3, program, current_dir);
625
626   UNGCPRO;
627   return unbind_to (speccount, proc);
628 }
629
630 \f
631 #ifdef HAVE_SOCKETS
632
633
634 /* #### The network support is fairly synthetical. What we actually
635    need is a single function, which supports all datagram, stream and
636    packet stream connections, arbitrary protocol families should they
637    be supported by the target system, multicast groups, in both data
638    and control rooted/nonrooted flavors, service quality etc whatever
639    is supported by the underlying network.
640
641    It must accept a property list describing the connection. The current
642    functions must then go to lisp and provide a suitable list for the
643    generalized connection function.
644
645    Both UNIX and Win32 support BSD sockets, and there are many extensions
646    available (Sockets 2 spec).
647
648    A todo is define a consistent set of properties abstracting a
649    network connection.   -kkm
650 */
651
652
653 /* open a TCP network connection to a given HOST/SERVICE.  Treated
654    exactly like a normal process when reading and writing.  Only
655    differences are in status display and process deletion.  A network
656    connection has no PID; you cannot signal it.  All you can do is
657    deactivate and close it via delete-process */
658
659 DEFUN ("open-network-stream-internal", Fopen_network_stream_internal, 4, 5, 0, /*
660 Open a TCP connection for a service to a host.
661 Returns a subprocess-object to represent the connection.
662 Input and output work as for subprocesses; `delete-process' closes it.
663
664 NAME is name for process.  It is modified if necessary to make it unique.
665 BUFFER is the buffer (or buffer-name) to associate with the process.
666  Process output goes at end of that buffer, unless you specify
667  an output stream or filter function to handle the output.
668  BUFFER may also be nil, meaning that this process is not associated
669  with any buffer.
670 Third arg is name of the host to connect to, or its IP address.
671 Fourth arg SERVICE is name of the service desired, or an integer
672  specifying a port number to connect to.
673 Fifth argument FAMILY is a protocol family. When omitted, 'tcp/ip
674 \(Internet protocol family TCP/IP) is assumed.
675 */
676        (name, buffer, host, service, family))
677 {
678   /* !!#### This function has not been Mule-ized */
679   /* This function can GC */
680   Lisp_Object proc = Qnil;
681   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, ngcpro1;
682   void *inch, *outch;
683
684   GCPRO5 (name, buffer, host, service, family);
685   CHECK_STRING (name);
686
687   if (NILP(family))
688     family = Qtcpip;
689   else
690     CHECK_SYMBOL (family);
691
692   /* Since this code is inside HAVE_SOCKETS, existence of
693      open_network_stream is mandatory */
694   PROCMETH (open_network_stream, (name, host, service, family,
695                                   &inch, &outch));
696
697   if (!NILP (buffer))
698     buffer = Fget_buffer_create (buffer);
699   proc = make_process_internal (name);
700   NGCPRO1 (proc);
701
702   XPROCESS (proc)->pid = Fcons (service, host);
703   XPROCESS (proc)->buffer = buffer;
704   init_process_io_handles (XPROCESS (proc), (void*)inch, (void*)outch,
705                            STREAM_NETWORK_CONNECTION);
706
707   event_stream_select_process (XPROCESS (proc));
708
709   UNGCPRO;
710   NUNGCPRO;
711   return proc;
712 }
713
714 #ifdef HAVE_MULTICAST
715
716 DEFUN ("open-multicast-group-internal", Fopen_multicast_group_internal, 5, 5, 0, /*
717 Open a multicast connection on the specified dest/port/ttl.
718 Returns a subprocess-object to represent the connection.
719 Input and output work as for subprocesses; `delete-process' closes it.
720
721 NAME is name for process.  It is modified if necessary to make it unique.
722 BUFFER is the buffer (or buffer-name) to associate with the process.
723  Process output goes at end of that buffer, unless you specify
724  an output stream or filter function to handle the output.
725  BUFFER may also be nil, meaning that this process is not associated
726  with any buffer.
727 Third, fourth and fifth args are the multicast destination group, port and ttl.
728  dest must be an internet address between 224.0.0.0 and 239.255.255.255
729  port is a communication port like in traditional unicast
730  ttl is the time-to-live (15 for site, 63 for region and 127 for world)
731 */
732        (name, buffer, dest, port, ttl))
733 {
734   /* !!#### This function has not been Mule-ized */
735   /* This function can GC */
736   Lisp_Object proc = Qnil;
737   struct gcpro gcpro1;
738   void *inch, *outch;
739
740   CHECK_STRING (name);
741
742   /* Since this code is inside HAVE_MULTICAST, existence of
743      open_network_stream is mandatory */
744   PROCMETH (open_multicast_group, (name, dest, port, ttl,
745                                    &inch, &outch));
746
747   if (!NILP (buffer))
748     buffer = Fget_buffer_create (buffer);
749
750   proc = make_process_internal (name);
751   GCPRO1 (proc);
752
753   XPROCESS (proc)->pid = Fcons (port, dest);
754   XPROCESS (proc)->buffer = buffer;
755   init_process_io_handles (XPROCESS (proc), (void*)inch, (void*)outch,
756                            STREAM_NETWORK_CONNECTION);
757
758   event_stream_select_process (XPROCESS (proc));
759
760   UNGCPRO;
761   return proc;
762 }
763 #endif /* HAVE_MULTICAST */
764
765 #endif  /* HAVE_SOCKETS */
766
767 Lisp_Object
768 canonicalize_host_name (Lisp_Object host)
769 {
770   return PROCMETH_OR_GIVEN (canonicalize_host_name, (host), host);
771 }
772
773 \f
774 DEFUN ("set-process-window-size", Fset_process_window_size, 3, 3, 0, /*
775 Tell PROCESS that it has logical window size HEIGHT and WIDTH.
776 */
777        (proc, height, width))
778 {
779   CHECK_PROCESS (proc);
780   CHECK_NATNUM (height);
781   CHECK_NATNUM (width);
782   return
783     MAYBE_INT_PROCMETH (set_window_size, (XPROCESS (proc), XINT (height), XINT (width))) <= 0
784     ? Qnil : Qt;
785 }
786
787 \f
788 /************************************************************************/
789 /*                              Process I/O                             */
790 /************************************************************************/
791
792 /* Read pending output from the process channel,
793    starting with our buffered-ahead character if we have one.
794    Yield number of characters read.
795
796    This function reads at most 1024 bytes.
797    If you want to read all available subprocess output,
798    you must call it repeatedly until it returns zero.  */
799
800 Charcount
801 read_process_output (Lisp_Object proc)
802 {
803   /* This function can GC */
804   Bytecount nbytes, nchars;
805   Bufbyte chars[1024];
806   Lisp_Object outstream;
807   struct Lisp_Process *p = XPROCESS (proc);
808
809   /* If there is a lot of output from the subprocess, the loop in
810      execute_internal_event() might call read_process_output() more
811      than once.  If the filter that was executed from one of these
812      calls set the filter to t, we have to stop now.  Return -1 rather
813      than 0 so execute_internal_event() doesn't close the process.
814      Really, the loop in execute_internal_event() should check itself
815      for a process-filter change, like in status_notify(); but the
816      struct Lisp_Process is not exported outside of this file. */
817   if (NILP(p->pipe_instream))
818     return -1; /* already closed */
819
820   if (!NILP (p->filter) && (p->filter_does_read))
821     {
822       Lisp_Object filter_result;
823
824       /* Some weird FSFmacs crap here with
825          Vdeactivate_mark and current_buffer->keymap */
826       running_asynch_code = 1;
827       filter_result = call2_trapping_errors ("Error in process filter",
828                                              p->filter, proc, Qnil);
829       running_asynch_code = 0;
830       restore_match_data ();
831       CHECK_INT (filter_result);
832       return XINT (filter_result);
833     }
834
835   nbytes = Lstream_read (XLSTREAM (DATA_INSTREAM(p)), chars, sizeof (chars));
836   if (nbytes <= 0) return nbytes;
837
838   nchars = bytecount_to_charcount (chars, nbytes);
839   outstream = p->filter;
840   if (!NILP (outstream))
841     {
842       /* We used to bind inhibit-quit to t here, but
843          call2_trapping_errors() does that for us. */
844       running_asynch_code = 1;
845       call2_trapping_errors ("Error in process filter",
846                              outstream, proc, make_string (chars, nbytes));
847       running_asynch_code = 0;
848       restore_match_data ();
849       return nchars;
850     }
851
852   /* If no filter, write into buffer if it isn't dead.  */
853   if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer)))
854     {
855       Lisp_Object old_read_only = Qnil;
856       Bufpos old_point;
857       Bufpos old_begv;
858       Bufpos old_zv;
859       int old_zmacs_region_stays = zmacs_region_stays;
860       struct gcpro gcpro1, gcpro2;
861       struct buffer *buf = XBUFFER (p->buffer);
862
863       GCPRO2 (proc, old_read_only);
864
865       old_point = BUF_PT (buf);
866       old_begv = BUF_BEGV (buf);
867       old_zv = BUF_ZV (buf);
868       old_read_only = buf->read_only;
869       buf->read_only = Qnil;
870
871       /* Insert new output into buffer
872          at the current end-of-output marker,
873          thus preserving logical ordering of input and output.  */
874       if (XMARKER (p->mark)->buffer)
875         BUF_SET_PT (buf,
876                     bufpos_clip_to_bounds (old_begv, marker_position (p->mark),
877                                            old_zv));
878       else
879         BUF_SET_PT (buf, old_zv);
880
881       /* If the output marker is outside of the visible region, save
882          the restriction and widen.  */
883       if (! (BUF_BEGV (buf) <= BUF_PT (buf) &&
884              BUF_PT (buf) <= BUF_ZV (buf)))
885         Fwiden (p->buffer);
886
887       /* Make sure opoint floats ahead of any new text, just as point
888          would.  */
889       if (BUF_PT (buf) <= old_point)
890         old_point += nchars;
891
892       /* Insert after old_begv, but before old_zv.  */
893       if (BUF_PT (buf) < old_begv)
894         old_begv += nchars;
895       if (BUF_PT (buf) <= old_zv)
896         old_zv += nchars;
897
898 #if 0
899       /* This screws up initial display of the window.  jla */
900
901       /* Insert before markers in case we are inserting where
902          the buffer's mark is, and the user's next command is Meta-y.  */
903       buffer_insert_raw_string_1 (buf, -1, chars,
904                                   nbytes, INSDEL_BEFORE_MARKERS);
905 #else
906       buffer_insert_raw_string (buf, chars, nbytes);
907 #endif
908
909       Fset_marker (p->mark, make_int (BUF_PT (buf)), p->buffer);
910
911       MARK_MODELINE_CHANGED;
912
913       /* If the restriction isn't what it should be, set it.  */
914       if (old_begv != BUF_BEGV (buf) || old_zv != BUF_ZV (buf))
915         {
916           Fwiden(p->buffer);
917           old_begv = bufpos_clip_to_bounds (BUF_BEG (buf),
918                                             old_begv,
919                                             BUF_Z (buf));
920           old_zv = bufpos_clip_to_bounds (BUF_BEG (buf),
921                                           old_zv,
922                                           BUF_Z (buf));
923           Fnarrow_to_region (make_int (old_begv), make_int (old_zv),
924                              p->buffer);
925         }
926
927       /* Handling the process output should not deactivate the mark.  */
928       zmacs_region_stays = old_zmacs_region_stays;
929       buf->read_only = old_read_only;
930       old_point = bufpos_clip_to_bounds (BUF_BEGV (buf),
931                                          old_point,
932                                          BUF_ZV (buf));
933       BUF_SET_PT (buf, old_point);
934
935       UNGCPRO;
936     }
937   return nchars;
938 }
939 \f
940 /* Sending data to subprocess */
941
942 /* send some data to process PROC.  If NONRELOCATABLE is non-NULL, it
943    specifies the address of the data.  Otherwise, the data comes from the
944    object RELOCATABLE (either a string or a buffer).  START and LEN
945    specify the offset and length of the data to send.
946
947    Note that START and LEN are in Bufpos's if RELOCATABLE is a buffer,
948    and in Bytecounts otherwise. */
949
950 void
951 send_process (Lisp_Object proc,
952               Lisp_Object relocatable, CONST Bufbyte *nonrelocatable,
953               int start, int len)
954 {
955   /* This function can GC */
956   struct gcpro gcpro1, gcpro2;
957   Lisp_Object lstream = Qnil;
958
959   GCPRO2 (proc, lstream);
960
961   if (NILP (DATA_OUTSTREAM (XPROCESS (proc))))
962     signal_simple_error ("Process not open for writing", proc);
963
964   if (nonrelocatable)
965     lstream =
966       make_fixed_buffer_input_stream (nonrelocatable + start, len);
967   else if (GC_BUFFERP (relocatable))
968     lstream = make_lisp_buffer_input_stream (XBUFFER (relocatable),
969                                              start, start + len, 0);
970   else
971     lstream = make_lisp_string_input_stream (relocatable, start, len);
972
973   PROCMETH (send_process, (proc, XLSTREAM (lstream)));
974
975   UNGCPRO;
976   Lstream_delete (XLSTREAM (lstream));
977 }
978
979 DEFUN ("process-tty-name", Fprocess_tty_name, 1, 1, 0, /*
980 Return the name of the terminal PROCESS uses, or nil if none.
981 This is the terminal that the process itself reads and writes on,
982 not the name of the pty that Emacs uses to talk with that terminal.
983 */
984        (proc))
985 {
986   CHECK_PROCESS (proc);
987   return MAYBE_LISP_PROCMETH (get_tty_name, (XPROCESS (proc)));
988 }
989
990 DEFUN ("set-process-buffer", Fset_process_buffer, 2, 2, 0, /*
991 Set buffer associated with PROCESS to BUFFER (a buffer, or nil).
992 */
993        (proc, buffer))
994 {
995   CHECK_PROCESS (proc);
996   if (!NILP (buffer))
997     CHECK_BUFFER (buffer);
998   XPROCESS (proc)->buffer = buffer;
999   return buffer;
1000 }
1001
1002 DEFUN ("process-buffer", Fprocess_buffer, 1, 1, 0, /*
1003 Return the buffer PROCESS is associated with.
1004 Output from PROCESS is inserted in this buffer
1005 unless PROCESS has a filter.
1006 */
1007        (proc))
1008 {
1009   CHECK_PROCESS (proc);
1010   return XPROCESS (proc)->buffer;
1011 }
1012
1013 DEFUN ("process-mark", Fprocess_mark, 1, 1, 0, /*
1014 Return the marker for the end of the last output from PROCESS.
1015 */
1016        (proc))
1017 {
1018   CHECK_PROCESS (proc);
1019   return XPROCESS (proc)->mark;
1020 }
1021
1022 void
1023 set_process_filter (Lisp_Object proc, Lisp_Object filter, int filter_does_read)
1024 {
1025   CHECK_PROCESS (proc);
1026   if (PROCESS_LIVE_P (proc)) {
1027     if (EQ (filter, Qt))
1028       event_stream_unselect_process (XPROCESS (proc));
1029     else
1030       event_stream_select_process (XPROCESS (proc));
1031   }
1032
1033   XPROCESS (proc)->filter = filter;
1034   XPROCESS (proc)->filter_does_read = filter_does_read;
1035 }
1036
1037 DEFUN ("set-process-filter", Fset_process_filter, 2, 2, 0, /*
1038 Give PROCESS the filter function FILTER; nil means no filter.
1039 t means stop accepting output from the process.
1040 When a process has a filter, each time it does output
1041 the entire string of output is passed to the filter.
1042 The filter gets two arguments: the process and the string of output.
1043 If the process has a filter, its buffer is not used for output.
1044 */
1045        (proc, filter))
1046 {
1047   set_process_filter (proc, filter, 0);
1048   return filter;
1049 }
1050
1051 DEFUN ("process-filter", Fprocess_filter, 1, 1, 0, /*
1052 Return the filter function of PROCESS; nil if none.
1053 See `set-process-filter' for more info on filter functions.
1054 */
1055        (proc))
1056 {
1057   CHECK_PROCESS (proc);
1058   return XPROCESS (proc)->filter;
1059 }
1060
1061 DEFUN ("process-send-region", Fprocess_send_region, 3, 3, 0, /*
1062 Send current contents of region as input to PROCESS.
1063 PROCESS may be a process name or an actual process.
1064 Called from program, takes three arguments, PROCESS, START and END.
1065 If the region is more than 500 or so characters long,
1066 it is sent in several bunches.  This may happen even for shorter regions.
1067 Output from processes can arrive in between bunches.
1068 */
1069        (process, start, end))
1070 {
1071   /* This function can GC */
1072   Lisp_Object proc = get_process (process);
1073   Bufpos st, en;
1074
1075   get_buffer_range_char (current_buffer, start, end, &st, &en, 0);
1076
1077   send_process (proc, Fcurrent_buffer (), 0,
1078                 st, en - st);
1079   return Qnil;
1080 }
1081
1082 DEFUN ("process-send-string", Fprocess_send_string, 2, 4, 0, /*
1083 Send PROCESS the contents of STRING as input.
1084 PROCESS may be a process name or an actual process.
1085 Optional arguments FROM and TO specify part of STRING, see `substring'.
1086 If STRING is more than 500 or so characters long,
1087 it is sent in several bunches.  This may happen even for shorter strings.
1088 Output from processes can arrive in between bunches.
1089 */
1090        (process, string, from, to))
1091 {
1092   /* This function can GC */
1093   Lisp_Object proc;
1094   Bytecount len;
1095   Bytecount bfr, bto;
1096
1097   proc = get_process (process);
1098   CHECK_STRING (string);
1099   get_string_range_byte (string, from, to, &bfr, &bto,
1100                          GB_HISTORICAL_STRING_BEHAVIOR);
1101   len = bto - bfr;
1102
1103   send_process (proc, string, 0, bfr, len);
1104   return Qnil;
1105 }
1106
1107 #ifdef FILE_CODING
1108
1109 DEFUN ("process-input-coding-system", Fprocess_input_coding_system, 1, 1, 0, /*
1110 Return PROCESS's input coding system.
1111 */
1112        (process))
1113 {
1114   process = get_process (process);
1115   return decoding_stream_coding_system (XLSTREAM (XPROCESS (process)->coding_instream) );
1116 }
1117
1118 DEFUN ("process-output-coding-system", Fprocess_output_coding_system, 1, 1, 0, /*
1119 Return PROCESS's output coding system.
1120 */
1121        (process))
1122 {
1123   process = get_process (process);
1124   return encoding_stream_coding_system (XLSTREAM (XPROCESS (process)->coding_outstream));
1125 }
1126
1127 DEFUN ("process-coding-system", Fprocess_coding_system, 1, 1, 0, /*
1128 Return a pair of coding-system for decoding and encoding of PROCESS.
1129 */
1130        (process))
1131 {
1132   process = get_process (process);
1133   return Fcons (decoding_stream_coding_system
1134                 (XLSTREAM (XPROCESS (process)->coding_instream)),
1135                 encoding_stream_coding_system
1136                 (XLSTREAM (XPROCESS (process)->coding_outstream)));
1137 }
1138
1139 DEFUN ("set-process-input-coding-system", Fset_process_input_coding_system,
1140        2, 2, 0, /*
1141 Set PROCESS's input coding system to CODESYS.
1142 */
1143        (process, codesys))
1144 {
1145   codesys = Fget_coding_system (codesys);
1146   process = get_process (process);
1147   set_decoding_stream_coding_system
1148     (XLSTREAM (XPROCESS (process)->coding_instream), codesys);
1149   return Qnil;
1150 }
1151
1152 DEFUN ("set-process-output-coding-system", Fset_process_output_coding_system,
1153        2, 2, 0, /*
1154 Set PROCESS's output coding system to CODESYS.
1155 */
1156        (process, codesys))
1157 {
1158   codesys = Fget_coding_system (codesys);
1159   process = get_process (process);
1160   set_encoding_stream_coding_system
1161     (XLSTREAM (XPROCESS (process)->coding_outstream), codesys);
1162   return Qnil;
1163 }
1164
1165 DEFUN ("set-process-coding-system", Fset_process_coding_system,
1166        1, 3, 0, /*
1167 Set coding-systems of PROCESS to DECODING and ENCODING.
1168 */
1169        (process, decoding, encoding))
1170 {
1171   if (!NILP (decoding))
1172     Fset_process_input_coding_system (process, decoding);
1173
1174   if (!NILP (encoding))
1175     Fset_process_output_coding_system (process, encoding);
1176
1177   return Qnil;
1178 }
1179
1180 #endif /* FILE_CODING */
1181 \f
1182 /************************************************************************/
1183 /*                             process status                           */
1184 /************************************************************************/
1185
1186 static Lisp_Object
1187 exec_sentinel_unwind (Lisp_Object datum)
1188 {
1189   struct Lisp_Cons *d = XCONS (datum);
1190   XPROCESS (d->car)->sentinel = d->cdr;
1191   free_cons (d);
1192   return Qnil;
1193 }
1194
1195 static void
1196 exec_sentinel (Lisp_Object proc, Lisp_Object reason)
1197 {
1198   /* This function can GC */
1199   int speccount = specpdl_depth ();
1200   struct Lisp_Process *p = XPROCESS (proc);
1201   Lisp_Object sentinel = p->sentinel;
1202
1203   if (NILP (sentinel))
1204     return;
1205
1206   /* Some weird FSFmacs crap here with
1207      Vdeactivate_mark and current_buffer->keymap */
1208
1209   /* Zilch the sentinel while it's running, to avoid recursive invocations;
1210      assure that it gets restored no matter how the sentinel exits.  */
1211   p->sentinel = Qnil;
1212   record_unwind_protect (exec_sentinel_unwind, noseeum_cons (proc, sentinel));
1213   /* We used to bind inhibit-quit to t here, but call2_trapping_errors()
1214      does that for us. */
1215   running_asynch_code = 1;
1216   call2_trapping_errors ("Error in process sentinel", sentinel, proc, reason);
1217   running_asynch_code = 0;
1218   restore_match_data ();
1219   unbind_to (speccount, Qnil);
1220 }
1221
1222 DEFUN ("set-process-sentinel", Fset_process_sentinel, 2, 2, 0, /*
1223 Give PROCESS the sentinel SENTINEL; nil for none.
1224 The sentinel is called as a function when the process changes state.
1225 It gets two arguments: the process, and a string describing the change.
1226 */
1227        (proc, sentinel))
1228 {
1229   CHECK_PROCESS (proc);
1230   XPROCESS (proc)->sentinel = sentinel;
1231   return sentinel;
1232 }
1233
1234 DEFUN ("process-sentinel", Fprocess_sentinel, 1, 1, 0, /*
1235 Return the sentinel of PROCESS; nil if none.
1236 See `set-process-sentinel' for more info on sentinels.
1237 */
1238        (proc))
1239 {
1240   CHECK_PROCESS (proc);
1241   return XPROCESS (proc)->sentinel;
1242 }
1243
1244 \f
1245 CONST char *
1246 signal_name (int signum)
1247 {
1248   if (signum >= 0 && signum < NSIG)
1249     return (CONST char *) sys_siglist[signum];
1250
1251   return (CONST char *) GETTEXT ("unknown signal");
1252 }
1253
1254 void
1255 update_process_status (Lisp_Object p,
1256                        Lisp_Object status_symbol,
1257                        int exit_code,
1258                        int core_dumped)
1259 {
1260   XPROCESS (p)->tick++;
1261   process_tick++;
1262   XPROCESS (p)->status_symbol = status_symbol;
1263   XPROCESS (p)->exit_code = exit_code;
1264   XPROCESS (p)->core_dumped = core_dumped;
1265 }
1266
1267 /* Return a string describing a process status list.  */
1268
1269 static Lisp_Object
1270 status_message (struct Lisp_Process *p)
1271 {
1272   Lisp_Object symbol = p->status_symbol;
1273   int code = p->exit_code;
1274   int coredump = p->core_dumped;
1275   Lisp_Object string, string2;
1276
1277   if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
1278     {
1279       string = build_string (signal_name (code));
1280       if (coredump)
1281         string2 = build_translated_string (" (core dumped)\n");
1282       else
1283         string2 = build_string ("\n");
1284       set_string_char (XSTRING (string), 0,
1285                        DOWNCASE (current_buffer,
1286                                  string_char (XSTRING (string), 0)));
1287       return concat2 (string, string2);
1288     }
1289   else if (EQ (symbol, Qexit))
1290     {
1291       if (code == 0)
1292         return build_translated_string ("finished\n");
1293       string = Fnumber_to_string (make_int (code));
1294       if (coredump)
1295         string2 = build_translated_string (" (core dumped)\n");
1296       else
1297         string2 = build_string ("\n");
1298       return concat2 (build_translated_string ("exited abnormally with code "),
1299                       concat2 (string, string2));
1300     }
1301   else
1302     return Fcopy_sequence (Fsymbol_name (symbol));
1303 }
1304
1305 /* Tell status_notify() to check for terminated processes.  We do this
1306    because on some systems we sometimes miss SIGCHLD calls. (Not sure
1307    why.) */
1308
1309 void
1310 kick_status_notify (void)
1311 {
1312   process_tick++;
1313 }
1314
1315
1316 /* Report all recent events of a change in process status
1317    (either run the sentinel or output a message).
1318    This is done while Emacs is waiting for keyboard input.  */
1319
1320 void
1321 status_notify (void)
1322 {
1323   /* This function can GC */
1324   Lisp_Object tail = Qnil;
1325   Lisp_Object symbol = Qnil;
1326   Lisp_Object msg = Qnil;
1327   struct gcpro gcpro1, gcpro2, gcpro3;
1328   /* process_tick is volatile, so we have to remember it now.
1329      Otherwise, we get a race condition is SIGCHLD happens during
1330      this function.
1331
1332      (Actually, this is not the case anymore.  The code to
1333      update the process structures has been moved out of the
1334      SIGCHLD handler.  But for the moment I'm leaving this
1335      stuff in -- it can't hurt.) */
1336   int temp_process_tick;
1337
1338   MAYBE_PROCMETH (reap_exited_processes, ());
1339
1340   temp_process_tick = process_tick;
1341
1342   if (update_tick == temp_process_tick)
1343     return;
1344
1345   /* We need to gcpro tail; if read_process_output calls a filter
1346      which deletes a process and removes the cons to which tail points
1347      from Vprocess_alist, and then causes a GC, tail is an unprotected
1348      reference.  */
1349   GCPRO3 (tail, symbol, msg);
1350
1351   for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
1352     {
1353       Lisp_Object proc = XCAR (tail);
1354       struct Lisp_Process *p = XPROCESS (proc);
1355       /* p->tick is also volatile.  Same thing as above applies. */
1356       int this_process_tick;
1357
1358       /* #### extra check for terminated processes, in case a SIGCHLD
1359          got missed (this seems to happen sometimes, I'm not sure why).
1360        */
1361       if (INTP (p->pid))
1362         MAYBE_PROCMETH (update_status_if_terminated, (p));
1363
1364       this_process_tick = p->tick;
1365       if (this_process_tick != p->update_tick)
1366         {
1367           p->update_tick = this_process_tick;
1368
1369           /* If process is still active, read any output that remains.  */
1370           while (!EQ (p->filter, Qt)
1371                  && read_process_output (proc) > 0)
1372             ;
1373
1374           /* Get the text to use for the message.  */
1375           msg = status_message (p);
1376
1377           /* If process is terminated, deactivate it or delete it.  */
1378           symbol = p->status_symbol;
1379
1380           if (EQ (symbol, Qsignal)
1381               || EQ (symbol, Qexit))
1382             {
1383               if (delete_exited_processes)
1384                 remove_process (proc);
1385               else
1386                 deactivate_process (proc);
1387             }
1388
1389           /* Now output the message suitably.  */
1390           if (!NILP (p->sentinel))
1391             exec_sentinel (proc, msg);
1392           /* Don't bother with a message in the buffer
1393              when a process becomes runnable.  */
1394           else if (!EQ (symbol, Qrun) && !NILP (p->buffer))
1395             {
1396               Lisp_Object old_read_only = Qnil;
1397               Lisp_Object old = Fcurrent_buffer ();
1398               Bufpos opoint;
1399               struct gcpro ngcpro1, ngcpro2;
1400
1401               /* Avoid error if buffer is deleted
1402                  (probably that's why the process is dead, too) */
1403               if (!BUFFER_LIVE_P (XBUFFER (p->buffer)))
1404                 continue;
1405
1406               NGCPRO2 (old, old_read_only);
1407               Fset_buffer (p->buffer);
1408               opoint = BUF_PT (current_buffer);
1409               /* Insert new output into buffer
1410                  at the current end-of-output marker,
1411                  thus preserving logical ordering of input and output.  */
1412               if (XMARKER (p->mark)->buffer)
1413                 BUF_SET_PT (current_buffer, marker_position (p->mark));
1414               else
1415                 BUF_SET_PT (current_buffer, BUF_ZV (current_buffer));
1416               if (BUF_PT (current_buffer) <= opoint)
1417                 opoint += (string_char_length (XSTRING (msg))
1418                            + string_char_length (XSTRING (p->name))
1419                            + 10);
1420
1421               old_read_only = current_buffer->read_only;
1422               current_buffer->read_only = Qnil;
1423               buffer_insert_c_string (current_buffer, "\nProcess ");
1424               Finsert (1, &p->name);
1425               buffer_insert_c_string (current_buffer, " ");
1426               Finsert (1, &msg);
1427               current_buffer->read_only = old_read_only;
1428               Fset_marker (p->mark, make_int (BUF_PT (current_buffer)),
1429                            p->buffer);
1430
1431               opoint = bufpos_clip_to_bounds(BUF_BEGV (XBUFFER (p->buffer)),
1432                                              opoint,
1433                                              BUF_ZV (XBUFFER (p->buffer)));
1434               BUF_SET_PT (current_buffer, opoint);
1435               Fset_buffer (old);
1436               NUNGCPRO;
1437             }
1438         }
1439     } /* end for */
1440
1441   /* in case buffers use %s in modeline-format */
1442   MARK_MODELINE_CHANGED;
1443   redisplay ();
1444
1445   update_tick = temp_process_tick;
1446
1447   UNGCPRO;
1448 }
1449
1450 DEFUN ("process-status", Fprocess_status, 1, 1, 0, /*
1451 Return the status of PROCESS.
1452 This is a symbol, one of these:
1453
1454 run    -- for a process that is running.
1455 stop   -- for a process stopped but continuable.
1456 exit   -- for a process that has exited.
1457 signal -- for a process that has got a fatal signal.
1458 open   -- for a network stream connection that is open.
1459 closed -- for a network stream connection that is closed.
1460 nil    -- if arg is a process name and no such process exists.
1461
1462 PROCESS may be a process, a buffer, the name of a process or buffer, or
1463 nil, indicating the current buffer's process.
1464 */
1465        (proc))
1466 {
1467   Lisp_Object status_symbol;
1468
1469   if (STRINGP (proc))
1470     proc = Fget_process (proc);
1471   else
1472     proc = get_process (proc);
1473
1474   if (NILP (proc))
1475     return Qnil;
1476
1477   status_symbol = XPROCESS (proc)->status_symbol;
1478   if (network_connection_p (proc))
1479     {
1480       if (EQ (status_symbol, Qrun))
1481         status_symbol = Qopen;
1482       else if (EQ (status_symbol, Qexit))
1483         status_symbol = Qclosed;
1484     }
1485   return status_symbol;
1486 }
1487
1488 DEFUN ("process-exit-status", Fprocess_exit_status, 1, 1, 0, /*
1489 Return the exit status of PROCESS or the signal number that killed it.
1490 If PROCESS has not yet exited or died, return 0.
1491 */
1492        (proc))
1493 {
1494   CHECK_PROCESS (proc);
1495   return make_int (XPROCESS (proc)->exit_code);
1496 }
1497
1498 \f
1499
1500 /* send a signal number SIGNO to PROCESS.
1501    CURRENT_GROUP means send to the process group that currently owns
1502    the terminal being used to communicate with PROCESS.
1503    This is used for various commands in shell mode.
1504    If NOMSG is zero, insert signal-announcements into process's buffers
1505    right away.
1506
1507    If we can, we try to signal PROCESS by sending control characters
1508    down the pty.  This allows us to signal inferiors who have changed
1509    their uid, for which killpg would return an EPERM error.  */
1510
1511 static void
1512 process_send_signal (Lisp_Object process, int signo,
1513                      int current_group, int nomsg)
1514 {
1515   /* This function can GC */
1516   Lisp_Object proc = get_process (process);
1517
1518   if (network_connection_p (proc))
1519     error ("Network connection %s is not a subprocess",
1520            XSTRING_DATA (XPROCESS(proc)->name));
1521   if (!PROCESS_LIVE_P (proc))
1522     error ("Process %s is not active",
1523            XSTRING_DATA (XPROCESS(proc)->name));
1524
1525   MAYBE_PROCMETH (kill_child_process, (proc, signo, current_group, nomsg));
1526 }
1527
1528 DEFUN ("interrupt-process", Finterrupt_process, 0, 2, 0, /*
1529 Interrupt process PROCESS.  May be process or name of one.
1530 Nil or no arg means current buffer's process.
1531 Second arg CURRENT-GROUP non-nil means send signal to
1532 the current process-group of the process's controlling terminal
1533 rather than to the process's own process group.
1534 If the process is a shell, this means interrupt current subjob
1535 rather than the shell.
1536 */
1537        (process, current_group))
1538 {
1539   /* This function can GC */
1540   process_send_signal (process, SIGINT, !NILP (current_group), 0);
1541   return process;
1542 }
1543
1544 DEFUN ("kill-process", Fkill_process, 0, 2, 0, /*
1545 Kill process PROCESS.  May be process or name of one.
1546 See function `interrupt-process' for more details on usage.
1547 */
1548        (process, current_group))
1549 {
1550   /* This function can GC */
1551 #ifdef SIGKILL
1552   process_send_signal (process, SIGKILL, !NILP (current_group), 0);
1553 #else
1554   error ("kill-process: Not supported on this system");
1555 #endif
1556   return process;
1557 }
1558
1559 DEFUN ("quit-process", Fquit_process, 0, 2, 0, /*
1560 Send QUIT signal to process PROCESS.  May be process or name of one.
1561 See function `interrupt-process' for more details on usage.
1562 */
1563        (process, current_group))
1564 {
1565   /* This function can GC */
1566 #ifdef SIGQUIT
1567   process_send_signal (process, SIGQUIT, !NILP (current_group), 0);
1568 #else
1569   error ("quit-process: Not supported on this system");
1570 #endif
1571   return process;
1572 }
1573
1574 DEFUN ("stop-process", Fstop_process, 0, 2, 0, /*
1575 Stop process PROCESS.  May be process or name of one.
1576 See function `interrupt-process' for more details on usage.
1577 */
1578        (process, current_group))
1579 {
1580   /* This function can GC */
1581 #ifdef SIGTSTP
1582   process_send_signal (process, SIGTSTP, !NILP (current_group), 0);
1583 #else
1584   error ("stop-process: Not supported on this system");
1585 #endif
1586   return process;
1587 }
1588
1589 DEFUN ("continue-process", Fcontinue_process, 0, 2, 0, /*
1590 Continue process PROCESS.  May be process or name of one.
1591 See function `interrupt-process' for more details on usage.
1592 */
1593        (process, current_group))
1594 {
1595   /* This function can GC */
1596 #ifdef SIGCONT
1597   process_send_signal (process, SIGCONT, !NILP (current_group), 0);
1598 #else
1599   error ("continue-process: Not supported on this system");
1600 #endif
1601   return process;
1602 }
1603
1604 DEFUN ("signal-process", Fsignal_process, 2, 2,
1605        "nProcess number: \nnSignal code: ", /*
1606 Send the process with process id PID the signal with code SIGCODE.
1607 PID must be an integer.  The process need not be a child of this Emacs.
1608 SIGCODE may be an integer, or a symbol whose name is a signal name.
1609 */
1610        (pid, sigcode))
1611 {
1612   CHECK_INT (pid);
1613
1614   if (INTP (sigcode))
1615     ;
1616   else
1617     {
1618       Bufbyte *name;
1619
1620       CHECK_SYMBOL (sigcode);
1621       name = string_data (XSYMBOL (sigcode)->name);
1622
1623 #define handle_signal(signal)                           \
1624   else if (!strcmp ((CONST char *) name, #signal))      \
1625     XSETINT (sigcode, signal)
1626
1627       if (0)
1628         ;
1629       handle_signal (SIGINT);  /* ANSI */
1630       handle_signal (SIGILL);  /* ANSI */
1631       handle_signal (SIGABRT); /* ANSI */
1632       handle_signal (SIGFPE);  /* ANSI */
1633       handle_signal (SIGSEGV); /* ANSI */
1634       handle_signal (SIGTERM); /* ANSI */
1635
1636 #ifdef SIGHUP
1637       handle_signal (SIGHUP);  /* POSIX */
1638 #endif
1639 #ifdef SIGQUIT
1640       handle_signal (SIGQUIT); /* POSIX */
1641 #endif
1642 #ifdef SIGTRAP
1643       handle_signal (SIGTRAP); /* POSIX */
1644 #endif
1645 #ifdef SIGKILL
1646       handle_signal (SIGKILL); /* POSIX */
1647 #endif
1648 #ifdef SIGUSR1
1649       handle_signal (SIGUSR1); /* POSIX */
1650 #endif
1651 #ifdef SIGUSR2
1652       handle_signal (SIGUSR2); /* POSIX */
1653 #endif
1654 #ifdef SIGPIPE
1655       handle_signal (SIGPIPE); /* POSIX */
1656 #endif
1657 #ifdef SIGALRM
1658       handle_signal (SIGALRM); /* POSIX */
1659 #endif
1660 #ifdef SIGCHLD
1661       handle_signal (SIGCHLD); /* POSIX */
1662 #endif
1663 #ifdef SIGCONT
1664       handle_signal (SIGCONT); /* POSIX */
1665 #endif
1666 #ifdef SIGSTOP
1667       handle_signal (SIGSTOP); /* POSIX */
1668 #endif
1669 #ifdef SIGTSTP
1670       handle_signal (SIGTSTP); /* POSIX */
1671 #endif
1672 #ifdef SIGTTIN
1673       handle_signal (SIGTTIN); /* POSIX */
1674 #endif
1675 #ifdef SIGTTOU
1676       handle_signal (SIGTTOU); /* POSIX */
1677 #endif
1678
1679 #ifdef SIGBUS
1680       handle_signal (SIGBUS);  /* XPG5 */
1681 #endif
1682 #ifdef SIGPOLL
1683       handle_signal (SIGPOLL); /* XPG5 */
1684 #endif
1685 #ifdef SIGPROF
1686       handle_signal (SIGPROF); /* XPG5 */
1687 #endif
1688 #ifdef SIGSYS
1689       handle_signal (SIGSYS);  /* XPG5 */
1690 #endif
1691 #ifdef SIGURG
1692       handle_signal (SIGURG);  /* XPG5 */
1693 #endif
1694 #ifdef SIGXCPU
1695       handle_signal (SIGXCPU); /* XPG5 */
1696 #endif
1697 #ifdef SIGXFSZ
1698       handle_signal (SIGXFSZ); /* XPG5 */
1699 #endif
1700 #ifdef SIGVTALRM
1701       handle_signal (SIGVTALRM); /* XPG5 */
1702 #endif
1703
1704 #ifdef SIGIO
1705       handle_signal (SIGIO); /* BSD 4.2 */
1706 #endif
1707 #ifdef SIGWINCH
1708       handle_signal (SIGWINCH); /* BSD 4.3 */
1709 #endif
1710
1711 #ifdef SIGEMT
1712       handle_signal (SIGEMT);
1713 #endif
1714 #ifdef SIGINFO
1715       handle_signal (SIGINFO);
1716 #endif
1717 #ifdef SIGHWE
1718       handle_signal (SIGHWE);
1719 #endif
1720 #ifdef SIGPRE
1721       handle_signal (SIGPRE);
1722 #endif
1723 #ifdef SIGUME
1724       handle_signal (SIGUME);
1725 #endif
1726 #ifdef SIGDLK
1727       handle_signal (SIGDLK);
1728 #endif
1729 #ifdef SIGCPULIM
1730       handle_signal (SIGCPULIM);
1731 #endif
1732 #ifdef SIGIOT
1733       handle_signal (SIGIOT);
1734 #endif
1735 #ifdef SIGLOST
1736       handle_signal (SIGLOST);
1737 #endif
1738 #ifdef SIGSTKFLT
1739       handle_signal (SIGSTKFLT);
1740 #endif
1741 #ifdef SIGUNUSED
1742       handle_signal (SIGUNUSED);
1743 #endif
1744 #ifdef SIGDANGER
1745       handle_signal (SIGDANGER); /* AIX */
1746 #endif
1747 #ifdef SIGMSG
1748       handle_signal (SIGMSG);
1749 #endif
1750 #ifdef SIGSOUND
1751       handle_signal (SIGSOUND);
1752 #endif
1753 #ifdef SIGRETRACT
1754       handle_signal (SIGRETRACT);
1755 #endif
1756 #ifdef SIGGRANT
1757       handle_signal (SIGGRANT);
1758 #endif
1759 #ifdef SIGPWR
1760       handle_signal (SIGPWR);
1761 #endif
1762       else
1763         error ("Undefined signal name %s", name);
1764     }
1765
1766 #undef handle_signal
1767
1768   return make_int (PROCMETH_OR_GIVEN (kill_process_by_pid,
1769                                       (XINT (pid), XINT (sigcode)), -1));
1770 }
1771
1772 DEFUN ("process-send-eof", Fprocess_send_eof, 0, 1, 0, /*
1773 Make PROCESS see end-of-file in its input.
1774 PROCESS may be a process, a buffer, the name of a process or buffer, or
1775 nil, indicating the current buffer's process.
1776 If PROCESS is a network connection, or is a process communicating
1777 through a pipe (as opposed to a pty), then you cannot send any more
1778 text to PROCESS after you call this function.
1779 */
1780        (process))
1781 {
1782   /* This function can GC */
1783   Lisp_Object proc = get_process (process);
1784
1785   /* Make sure the process is really alive.  */
1786   if (! EQ (XPROCESS (proc)->status_symbol, Qrun))
1787     error ("Process %s not running", XSTRING_DATA (XPROCESS (proc)->name));
1788
1789   if (!MAYBE_INT_PROCMETH (process_send_eof, (proc)))
1790     {
1791       if (!NILP (DATA_OUTSTREAM (XPROCESS (proc))))
1792         {
1793           Lstream_close (XLSTREAM (DATA_OUTSTREAM (XPROCESS (proc))));
1794           event_stream_delete_stream_pair (Qnil, XPROCESS (proc)->pipe_outstream);
1795           XPROCESS (proc)->pipe_outstream = Qnil;
1796 #ifdef FILE_CODING
1797           XPROCESS (proc)->coding_outstream = Qnil;
1798 #endif
1799         }
1800     }
1801
1802   return process;
1803 }
1804
1805 \f
1806 /************************************************************************/
1807 /*                          deleting a process                          */
1808 /************************************************************************/
1809
1810 void
1811 deactivate_process (Lisp_Object proc)
1812 {
1813   struct Lisp_Process *p = XPROCESS (proc);
1814   USID usid;
1815
1816   /* It's possible that we got as far in the process-creation
1817      process as creating the descriptors but didn't get so
1818      far as selecting the process for input.  In this
1819      case, p->pid is nil: p->pid is set at the same time that
1820      the process is selected for input. */
1821   /* #### The comment does not look correct. event_stream_unselect_process
1822      is guarded by process->selected, so this is not a problem. - kkm*/
1823   /* Must call this before setting the streams to nil */
1824   event_stream_unselect_process (p);
1825
1826   if (!NILP (DATA_OUTSTREAM (p)))
1827     Lstream_close (XLSTREAM (DATA_OUTSTREAM (p)));
1828   if (!NILP (DATA_INSTREAM (p)))
1829     Lstream_close (XLSTREAM (DATA_INSTREAM (p)));
1830
1831   /* Provide minimal implementation for deactivate_process
1832      if there's no process-specific one */
1833   if (HAS_PROCMETH_P (deactivate_process))
1834     usid = PROCMETH (deactivate_process, (p));
1835   else
1836     usid = event_stream_delete_stream_pair (p->pipe_instream,
1837                                             p->pipe_outstream);
1838
1839   if (usid != USID_DONTHASH)
1840     remhash ((CONST void*)usid, usid_to_process);
1841
1842   p->pipe_instream = Qnil;
1843   p->pipe_outstream = Qnil;
1844 #ifdef FILE_CODING
1845   p->coding_instream = Qnil;
1846   p->coding_outstream = Qnil;
1847 #endif
1848 }
1849
1850 static void
1851 remove_process (Lisp_Object proc)
1852 {
1853   Vprocess_list = delq_no_quit (proc, Vprocess_list);
1854   Fset_marker (XPROCESS (proc)->mark, Qnil, Qnil);
1855
1856   deactivate_process (proc);
1857 }
1858
1859 DEFUN ("delete-process", Fdelete_process, 1, 1, 0, /*
1860 Delete PROCESS: kill it and forget about it immediately.
1861 PROCESS may be a process or the name of one, or a buffer name.
1862 */
1863        (proc))
1864 {
1865   /* This function can GC */
1866   struct Lisp_Process *p;
1867   proc = get_process (proc);
1868   p = XPROCESS (proc);
1869   if (network_connection_p (proc))
1870     {
1871       p->status_symbol = Qexit;
1872       p->exit_code = 0;
1873       p->core_dumped = 0;
1874       p->tick++;
1875       process_tick++;
1876     }
1877   else if (!NILP(p->pipe_instream))
1878     {
1879       Fkill_process (proc, Qnil);
1880       /* Do this now, since remove_process will make sigchld_handler do nothing.  */
1881       p->status_symbol = Qsignal;
1882       p->exit_code = SIGKILL;
1883       p->core_dumped = 0;
1884       p->tick++;
1885       process_tick++;
1886       status_notify ();
1887     }
1888   remove_process (proc);
1889   return Qnil;
1890 }
1891
1892 /* Kill all processes associated with `buffer'.
1893  If `buffer' is nil, kill all processes  */
1894
1895 void
1896 kill_buffer_processes (Lisp_Object buffer)
1897 {
1898   Lisp_Object tail;
1899
1900   for (tail = Vprocess_list; GC_CONSP (tail);
1901        tail = XCDR (tail))
1902     {
1903       Lisp_Object proc = XCAR (tail);
1904       if (GC_PROCESSP (proc)
1905           && (GC_NILP (buffer) || GC_EQ (XPROCESS (proc)->buffer, buffer)))
1906         {
1907           if (network_connection_p (proc))
1908             Fdelete_process (proc);
1909           else if (!NILP (XPROCESS (proc)->pipe_instream))
1910             process_send_signal (proc, SIGHUP, 0, 1);
1911         }
1912     }
1913 }
1914
1915 DEFUN ("process-kill-without-query", Fprocess_kill_without_query, 1, 2, 0, /*
1916 Say no query needed if PROCESS is running when Emacs is exited.
1917 Optional second argument if non-nil says to require a query.
1918 Value is t if a query was formerly required.
1919 */
1920        (proc, require_query_p))
1921 {
1922   int tem;
1923
1924   CHECK_PROCESS (proc);
1925   tem = XPROCESS (proc)->kill_without_query;
1926   XPROCESS (proc)->kill_without_query = NILP (require_query_p);
1927
1928   return tem ? Qnil : Qt;
1929 }
1930
1931 DEFUN ("process-kill-without-query-p", Fprocess_kill_without_query_p, 1, 1, 0, /*
1932 Whether PROC will be killed without query if running when emacs is exited.
1933 */
1934        (proc))
1935 {
1936   CHECK_PROCESS (proc);
1937   return XPROCESS (proc)->kill_without_query ? Qt : Qnil;
1938 }
1939
1940 \f
1941 /* This is not named init_process in order to avoid a conflict with NS 3.3 */
1942 void
1943 init_xemacs_process (void)
1944 {
1945   MAYBE_PROCMETH (init_process, ());
1946
1947   Vprocess_list = Qnil;
1948
1949   if (usid_to_process)
1950     clrhash (usid_to_process);
1951   else
1952     usid_to_process = make_hash_table (32);
1953 }
1954
1955 #if 0
1956
1957 xxDEFUN ("process-connection", Fprocess_connection, 0, 1, 0, /*
1958 Return the connection type of `PROCESS'.  This can be nil (pipe),
1959 t or pty (pty) or stream (socket connection).
1960 */
1961          (process))
1962 {
1963   return XPROCESS (process)->type;
1964 }
1965
1966 #endif /* 0 */
1967
1968 void
1969 syms_of_process (void)
1970 {
1971   defsymbol (&Qprocessp, "processp");
1972   defsymbol (&Qrun, "run");
1973   defsymbol (&Qstop, "stop");
1974   defsymbol (&Qopen, "open");
1975   defsymbol (&Qclosed, "closed");
1976
1977   defsymbol (&Qtcpip, "tcp/ip");
1978
1979 #ifdef HAVE_MULTICAST
1980   defsymbol(&Qmulticast, "multicast"); /* Used for occasional warnings */
1981 #endif
1982
1983   DEFSUBR (Fprocessp);
1984   DEFSUBR (Fget_process);
1985   DEFSUBR (Fget_buffer_process);
1986   DEFSUBR (Fdelete_process);
1987   DEFSUBR (Fprocess_status);
1988   DEFSUBR (Fprocess_exit_status);
1989   DEFSUBR (Fprocess_id);
1990   DEFSUBR (Fprocess_name);
1991   DEFSUBR (Fprocess_tty_name);
1992   DEFSUBR (Fprocess_command);
1993   DEFSUBR (Fset_process_buffer);
1994   DEFSUBR (Fprocess_buffer);
1995   DEFSUBR (Fprocess_mark);
1996   DEFSUBR (Fset_process_filter);
1997   DEFSUBR (Fprocess_filter);
1998   DEFSUBR (Fset_process_window_size);
1999   DEFSUBR (Fset_process_sentinel);
2000   DEFSUBR (Fprocess_sentinel);
2001   DEFSUBR (Fprocess_kill_without_query);
2002   DEFSUBR (Fprocess_kill_without_query_p);
2003   DEFSUBR (Fprocess_list);
2004   DEFSUBR (Fstart_process_internal);
2005 #ifdef HAVE_SOCKETS
2006   DEFSUBR (Fopen_network_stream_internal);
2007 #ifdef HAVE_MULTICAST
2008   DEFSUBR (Fopen_multicast_group_internal);
2009 #endif /* HAVE_MULTICAST */
2010 #endif /* HAVE_SOCKETS */
2011   DEFSUBR (Fprocess_send_region);
2012   DEFSUBR (Fprocess_send_string);
2013   DEFSUBR (Finterrupt_process);
2014   DEFSUBR (Fkill_process);
2015   DEFSUBR (Fquit_process);
2016   DEFSUBR (Fstop_process);
2017   DEFSUBR (Fcontinue_process);
2018   DEFSUBR (Fprocess_send_eof);
2019   DEFSUBR (Fsignal_process);
2020 /*  DEFSUBR (Fprocess_connection); */
2021 #ifdef FILE_CODING
2022   DEFSUBR (Fprocess_input_coding_system);
2023   DEFSUBR (Fprocess_output_coding_system);
2024   DEFSUBR (Fset_process_input_coding_system);
2025   DEFSUBR (Fset_process_output_coding_system);
2026   DEFSUBR (Fprocess_coding_system);
2027   DEFSUBR (Fset_process_coding_system);
2028 #endif /* FILE_CODING */
2029 }
2030
2031 void
2032 vars_of_process (void)
2033 {
2034   Fprovide (intern ("subprocesses"));
2035 #ifdef HAVE_SOCKETS
2036   Fprovide (intern ("network-streams"));
2037 #ifdef HAVE_MULTICAST
2038   Fprovide (intern ("multicast"));
2039 #endif /* HAVE_MULTICAST */
2040 #endif /* HAVE_SOCKETS */
2041   staticpro (&Vprocess_list);
2042
2043   DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes /*
2044 *Non-nil means delete processes immediately when they exit.
2045 nil means don't delete them until `list-processes' is run.
2046 */ );
2047
2048   delete_exited_processes = 1;
2049
2050   DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type /*
2051 Control type of device used to communicate with subprocesses.
2052 Values are nil to use a pipe, or t or `pty' to use a pty.
2053 The value has no effect if the system has no ptys or if all ptys are busy:
2054 then a pipe is used in any case.
2055 The value takes effect when `start-process' is called.
2056 */ );
2057   Vprocess_connection_type = Qt;
2058
2059   DEFVAR_BOOL ("windowed-process-io", &windowed_process_io /*
2060 Enables input/output on standard handles of a windowed process.
2061 When this variable is nil (the default), XEmacs does not attempt to read
2062 standard output handle of a windowed process. Instead, the process is
2063 immediately marked as exited immediately upon successful launching. This is
2064 done because normal windowed processes do not use standard I/O, as they are
2065 not connected to any console.
2066
2067 When launching a specially crafted windowed process, which expects to be
2068 launched by XEmacs, or by other program which pipes its standard input and
2069 output, this variable must be set to non-nil, in which case XEmacs will
2070 treat this process just like a console process.
2071
2072 NOTE: You should never set this variable, only bind it.
2073
2074 Only Windows processes can be "windowed" or "console". This variable has no
2075 effect on UNIX processes, because all UNIX processes are "console".
2076 */ );
2077   windowed_process_io = 0;
2078
2079 #ifdef PROCESS_IO_BLOCKING
2080   DEFVAR_LISP ("network-stream-blocking-port-list", &network_stream_blocking_port_list /*
2081 List of port numbers or port names to set a blocking I/O mode with connection.
2082 Nil value means to set a default(non-blocking) I/O mode.
2083 The value takes effect when `open-network-stream-internal' is called.
2084 */ );
2085   network_stream_blocking_port_list = Qnil;
2086 #endif  /* PROCESS_IO_BLOCKING */
2087 }
2088
2089 #endif /* not NO_SUBPROCESSES */