1 /* Asynchronous subprocess control for GNU Emacs.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 96, 98, 1999,
3 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 /* This file is split into two parts by the following preprocessor
27 conditional. The 'then' clause contains all of the support for
28 asynchronous subprocesses. The 'else' clause contains stub
29 versions of some of the asynchronous subprocess routines that are
30 often called elsewhere in Emacs, so we don't have to #ifdef the
31 sections that call them. */
39 #include <sys/types.h> /* some typedefs are used in sys/file.h */
46 #if defined(WINDOWSNT) || defined(UNIX98_PTYS)
49 #endif /* not WINDOWSNT */
51 #ifdef HAVE_SOCKETS /* TCP connection support, if kernel can do it */
52 #include <sys/socket.h>
54 #include <netinet/in.h>
55 #include <arpa/inet.h>
56 #ifdef NEED_NET_ERRNO_H
57 #include <net/errno.h>
58 #endif /* NEED_NET_ERRNO_H */
60 /* Are local (unix) sockets supported? */
61 #if defined (HAVE_SYS_UN_H) && !defined (NO_SOCKETS_IN_FILE_SYSTEM)
62 #if !defined (AF_LOCAL) && defined (AF_UNIX)
63 #define AF_LOCAL AF_UNIX
66 #define HAVE_LOCAL_SOCKETS
70 #endif /* HAVE_SOCKETS */
72 /* TERM is a poor-man's SLIP, used on GNU/Linux. */
77 /* On some systems, e.g. DGUX, inet_addr returns a 'struct in_addr'. */
78 #ifdef HAVE_BROKEN_INET_ADDR
79 #define IN_ADDR struct in_addr
80 #define NUMERIC_ADDR_ERROR (numeric_addr.s_addr == -1)
82 #define IN_ADDR unsigned long
83 #define NUMERIC_ADDR_ERROR (numeric_addr == -1)
86 #if defined(BSD_SYSTEM) || defined(STRIDE)
87 #include <sys/ioctl.h>
88 #if !defined (O_NDELAY) && defined (HAVE_PTYS) && !defined(USG5)
90 #endif /* HAVE_PTYS and no O_NDELAY */
91 #endif /* BSD_SYSTEM || STRIDE */
93 #ifdef BROKEN_O_NONBLOCK
95 #endif /* BROKEN_O_NONBLOCK */
101 /* Can we use SIOCGIFCONF and/or SIOCGIFADDR */
103 #if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_NET_IF_H)
104 /* sys/ioctl.h may have been included already */
106 #include <sys/ioctl.h>
113 #include <sys/sysmacros.h> /* for "minor" */
114 #endif /* not IRIS */
117 #include <sys/wait.h>
129 #include "termhooks.h"
130 #include "termopts.h"
131 #include "commands.h"
132 #include "keyboard.h"
134 #include "blockinput.h"
135 #include "dispextern.h"
136 #include "composite.h"
139 Lisp_Object Qprocessp
;
140 Lisp_Object Qrun
, Qstop
, Qsignal
;
141 Lisp_Object Qopen
, Qclosed
, Qconnect
, Qfailed
, Qlisten
;
142 Lisp_Object Qlocal
, Qdatagram
;
143 Lisp_Object QCname
, QCbuffer
, QChost
, QCservice
, QCtype
;
144 Lisp_Object QClocal
, QCremote
, QCcoding
;
145 Lisp_Object QCserver
, QCnowait
, QCnoquery
, QCstop
;
146 Lisp_Object QCsentinel
, QClog
, QCoptions
, QCplist
;
147 Lisp_Object QCfilter_multibyte
;
148 Lisp_Object Qlast_nonmenu_event
;
149 /* QCfamily is declared and initialized in xfaces.c,
150 QCfilter in keyboard.c. */
151 extern Lisp_Object QCfamily
, QCfilter
;
153 /* Qexit is declared and initialized in eval.c. */
155 /* QCfamily is defined in xfaces.c. */
156 extern Lisp_Object QCfamily
;
157 /* QCfilter is defined in keyboard.c. */
158 extern Lisp_Object QCfilter
;
160 /* a process object is a network connection when its childp field is neither
161 Qt nor Qnil but is instead a property list (KEY VAL ...). */
164 #define NETCONN_P(p) (GC_CONSP (XPROCESS (p)->childp))
165 #define NETCONN1_P(p) (GC_CONSP ((p)->childp))
167 #define NETCONN_P(p) 0
168 #define NETCONN1_P(p) 0
169 #endif /* HAVE_SOCKETS */
171 /* Define first descriptor number available for subprocesses. */
173 #define FIRST_PROC_DESC 1
175 #define FIRST_PROC_DESC 3
178 /* Define SIGCHLD as an alias for SIGCLD. There are many conditionals
181 #if !defined (SIGCHLD) && defined (SIGCLD)
182 #define SIGCHLD SIGCLD
185 #include "syssignal.h"
189 extern void set_waiting_for_input
P_ ((EMACS_TIME
*));
195 extern char *sys_errlist
[];
202 /* t means use pty, nil means use a pipe,
203 maybe other values to come. */
204 static Lisp_Object Vprocess_connection_type
;
208 #include <sys/socket.h>
212 /* These next two vars are non-static since sysdep.c uses them in the
213 emulation of `select'. */
214 /* Number of events of change of status of a process. */
216 /* Number of events for which the user or sentinel has been notified. */
219 /* Define NON_BLOCKING_CONNECT if we can support non-blocking connects. */
221 #ifdef BROKEN_NON_BLOCKING_CONNECT
222 #undef NON_BLOCKING_CONNECT
224 #ifndef NON_BLOCKING_CONNECT
227 #if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX)
228 #if defined (O_NONBLOCK) || defined (O_NDELAY)
229 #if defined (EWOULDBLOCK) || defined (EINPROGRESS)
230 #define NON_BLOCKING_CONNECT
231 #endif /* EWOULDBLOCK || EINPROGRESS */
232 #endif /* O_NONBLOCK || O_NDELAY */
233 #endif /* HAVE_GETPEERNAME || GNU_LINUX */
234 #endif /* HAVE_SELECT */
235 #endif /* HAVE_SOCKETS */
236 #endif /* NON_BLOCKING_CONNECT */
237 #endif /* BROKEN_NON_BLOCKING_CONNECT */
239 /* Define DATAGRAM_SOCKETS if datagrams can be used safely on
240 this system. We need to read full packets, so we need a
241 "non-destructive" select. So we require either native select,
242 or emulation of select using FIONREAD. */
244 #ifdef BROKEN_DATAGRAM_SOCKETS
245 #undef DATAGRAM_SOCKETS
247 #ifndef DATAGRAM_SOCKETS
249 #if defined (HAVE_SELECT) || defined (FIONREAD)
250 #if defined (HAVE_SENDTO) && defined (HAVE_RECVFROM) && defined (EMSGSIZE)
251 #define DATAGRAM_SOCKETS
252 #endif /* HAVE_SENDTO && HAVE_RECVFROM && EMSGSIZE */
253 #endif /* HAVE_SELECT || FIONREAD */
254 #endif /* HAVE_SOCKETS */
255 #endif /* DATAGRAM_SOCKETS */
256 #endif /* BROKEN_DATAGRAM_SOCKETS */
259 #undef NON_BLOCKING_CONNECT
260 #undef DATAGRAM_SOCKETS
263 #if !defined (ADAPTIVE_READ_BUFFERING) && !defined (NO_ADAPTIVE_READ_BUFFERING)
264 #ifdef EMACS_HAS_USECS
265 #define ADAPTIVE_READ_BUFFERING
269 #ifdef ADAPTIVE_READ_BUFFERING
270 #define READ_OUTPUT_DELAY_INCREMENT 10000
271 #define READ_OUTPUT_DELAY_MAX (READ_OUTPUT_DELAY_INCREMENT * 5)
272 #define READ_OUTPUT_DELAY_MAX_MAX (READ_OUTPUT_DELAY_INCREMENT * 7)
274 /* Number of processes which might be delayed. */
276 static int process_output_delay_count
;
278 /* Non-zero if any process has non-nil process_output_skip. */
280 static int process_output_skip
;
282 /* Non-nil means to delay reading process output to improve buffering.
283 A value of t means that delay is reset after each send, any other
284 non-nil value does not reset the delay. */
285 static Lisp_Object Vprocess_adaptive_read_buffering
;
287 #define process_output_delay_count 0
291 #include "sysselect.h"
293 extern int keyboard_bit_set
P_ ((SELECT_TYPE
*));
295 /* If we support a window system, turn on the code to poll periodically
296 to detect C-g. It isn't actually used when doing interrupt input. */
297 #ifdef HAVE_WINDOW_SYSTEM
298 #define POLL_FOR_INPUT
301 /* Mask of bits indicating the descriptors that we wait for input on. */
303 static SELECT_TYPE input_wait_mask
;
305 /* Mask that excludes keyboard input descriptor (s). */
307 static SELECT_TYPE non_keyboard_wait_mask
;
309 /* Mask that excludes process input descriptor (s). */
311 static SELECT_TYPE non_process_wait_mask
;
313 /* Mask of bits indicating the descriptors that we wait for connect to
314 complete on. Once they complete, they are removed from this mask
315 and added to the input_wait_mask and non_keyboard_wait_mask. */
317 static SELECT_TYPE connect_wait_mask
;
319 /* Number of bits set in connect_wait_mask. */
320 static int num_pending_connects
;
322 /* The largest descriptor currently in use for a process object. */
323 static int max_process_desc
;
325 /* The largest descriptor currently in use for keyboard input. */
326 static int max_keyboard_desc
;
328 /* Nonzero means delete a process right away if it exits. */
329 static int delete_exited_processes
;
331 /* Indexed by descriptor, gives the process (if any) for that descriptor */
332 Lisp_Object chan_process
[MAXDESC
];
334 /* Alist of elements (NAME . PROCESS) */
335 Lisp_Object Vprocess_alist
;
337 /* Buffered-ahead input char from process, indexed by channel.
338 -1 means empty (no char is buffered).
339 Used on sys V where the only way to tell if there is any
340 output from the process is to read at least one char.
341 Always -1 on systems that support FIONREAD. */
343 /* Don't make static; need to access externally. */
344 int proc_buffered_char
[MAXDESC
];
346 /* Table of `struct coding-system' for each process. */
347 static struct coding_system
*proc_decode_coding_system
[MAXDESC
];
348 static struct coding_system
*proc_encode_coding_system
[MAXDESC
];
350 #ifdef DATAGRAM_SOCKETS
351 /* Table of `partner address' for datagram sockets. */
352 struct sockaddr_and_len
{
355 } datagram_address
[MAXDESC
];
356 #define DATAGRAM_CHAN_P(chan) (datagram_address[chan].sa != 0)
357 #define DATAGRAM_CONN_P(proc) (PROCESSP (proc) && datagram_address[XINT (XPROCESS (proc)->infd)].sa != 0)
359 #define DATAGRAM_CHAN_P(chan) (0)
360 #define DATAGRAM_CONN_P(proc) (0)
363 static Lisp_Object
get_process ();
364 static void exec_sentinel ();
366 extern EMACS_TIME
timer_check ();
367 extern int timers_run
;
369 /* Maximum number of bytes to send to a pty without an eof. */
370 static int pty_max_bytes
;
372 extern Lisp_Object Vfile_name_coding_system
, Vdefault_file_name_coding_system
;
378 /* The file name of the pty opened by allocate_pty. */
380 static char pty_name
[24];
383 /* Compute the Lisp form of the process status, p->status, from
384 the numeric status that was returned by `wait'. */
386 Lisp_Object
status_convert ();
390 struct Lisp_Process
*p
;
392 union { int i
; WAITTYPE wt
; } u
;
393 u
.i
= XFASTINT (p
->raw_status_low
) + (XFASTINT (p
->raw_status_high
) << 16);
394 p
->status
= status_convert (u
.wt
);
395 p
->raw_status_low
= Qnil
;
396 p
->raw_status_high
= Qnil
;
399 /* Convert a process status word in Unix format to
400 the list that we use internally. */
407 return Fcons (Qstop
, Fcons (make_number (WSTOPSIG (w
)), Qnil
));
408 else if (WIFEXITED (w
))
409 return Fcons (Qexit
, Fcons (make_number (WRETCODE (w
)),
410 WCOREDUMP (w
) ? Qt
: Qnil
));
411 else if (WIFSIGNALED (w
))
412 return Fcons (Qsignal
, Fcons (make_number (WTERMSIG (w
)),
413 WCOREDUMP (w
) ? Qt
: Qnil
));
418 /* Given a status-list, extract the three pieces of information
419 and store them individually through the three pointers. */
422 decode_status (l
, symbol
, code
, coredump
)
440 *code
= XFASTINT (XCAR (tem
));
442 *coredump
= !NILP (tem
);
446 /* Return a string describing a process status list. */
450 struct Lisp_Process
*p
;
452 Lisp_Object status
= p
->status
;
455 Lisp_Object string
, string2
;
457 decode_status (status
, &symbol
, &code
, &coredump
);
459 if (EQ (symbol
, Qsignal
) || EQ (symbol
, Qstop
))
462 synchronize_system_messages_locale ();
463 signame
= strsignal (code
);
466 string
= build_string (signame
);
467 string2
= build_string (coredump
? " (core dumped)\n" : "\n");
468 SSET (string
, 0, DOWNCASE (SREF (string
, 0)));
469 return concat2 (string
, string2
);
471 else if (EQ (symbol
, Qexit
))
474 return build_string (code
== 0 ? "deleted\n" : "connection broken by remote peer\n");
476 return build_string ("finished\n");
477 string
= Fnumber_to_string (make_number (code
));
478 string2
= build_string (coredump
? " (core dumped)\n" : "\n");
479 return concat3 (build_string ("exited abnormally with code "),
482 else if (EQ (symbol
, Qfailed
))
484 string
= Fnumber_to_string (make_number (code
));
485 string2
= build_string ("\n");
486 return concat3 (build_string ("failed with code "),
490 return Fcopy_sequence (Fsymbol_name (symbol
));
495 /* Open an available pty, returning a file descriptor.
496 Return -1 on failure.
497 The file name of the terminal corresponding to the pty
498 is left in the variable pty_name. */
509 for (c
= FIRST_PTY_LETTER
; c
<= 'z'; c
++)
510 for (i
= 0; i
< 16; i
++)
513 struct stat stb
; /* Used in some PTY_OPEN. */
514 #ifdef PTY_NAME_SPRINTF
517 sprintf (pty_name
, "/dev/pty%c%x", c
, i
);
518 #endif /* no PTY_NAME_SPRINTF */
522 #else /* no PTY_OPEN */
525 /* Unusual IRIS code */
526 *ptyv
= emacs_open ("/dev/ptc", O_RDWR
| O_NDELAY
, 0);
529 if (fstat (fd
, &stb
) < 0)
531 # else /* not IRIS */
532 { /* Some systems name their pseudoterminals so that there are gaps in
533 the usual sequence - for example, on HP9000/S700 systems, there
534 are no pseudoterminals with names ending in 'f'. So we wait for
535 three failures in a row before deciding that we've reached the
537 int failed_count
= 0;
539 if (stat (pty_name
, &stb
) < 0)
542 if (failed_count
>= 3)
549 fd
= emacs_open (pty_name
, O_RDWR
| O_NONBLOCK
, 0);
551 fd
= emacs_open (pty_name
, O_RDWR
| O_NDELAY
, 0);
553 # endif /* not IRIS */
555 #endif /* no PTY_OPEN */
559 /* check to make certain that both sides are available
560 this avoids a nasty yet stupid bug in rlogins */
561 #ifdef PTY_TTY_NAME_SPRINTF
564 sprintf (pty_name
, "/dev/tty%c%x", c
, i
);
565 #endif /* no PTY_TTY_NAME_SPRINTF */
567 if (access (pty_name
, 6) != 0)
570 # if !defined(IRIS) && !defined(__sgi)
576 #endif /* not UNIPLUS */
583 #endif /* HAVE_PTYS */
589 register Lisp_Object val
, tem
, name1
;
590 register struct Lisp_Process
*p
;
594 p
= allocate_process ();
596 XSETINT (p
->infd
, -1);
597 XSETINT (p
->outfd
, -1);
598 XSETFASTINT (p
->pid
, 0);
599 XSETFASTINT (p
->tick
, 0);
600 XSETFASTINT (p
->update_tick
, 0);
601 p
->raw_status_low
= Qnil
;
602 p
->raw_status_high
= Qnil
;
604 p
->mark
= Fmake_marker ();
606 #ifdef ADAPTIVE_READ_BUFFERING
607 p
->adaptive_read_buffering
= Qnil
;
608 XSETFASTINT (p
->read_output_delay
, 0);
609 p
->read_output_skip
= Qnil
;
612 /* If name is already in use, modify it until it is unused. */
617 tem
= Fget_process (name1
);
618 if (NILP (tem
)) break;
619 sprintf (suffix
, "<%d>", i
);
620 name1
= concat2 (name
, build_string (suffix
));
624 XSETPROCESS (val
, p
);
625 Vprocess_alist
= Fcons (Fcons (name
, val
), Vprocess_alist
);
630 remove_process (proc
)
631 register Lisp_Object proc
;
633 register Lisp_Object pair
;
635 pair
= Frassq (proc
, Vprocess_alist
);
636 Vprocess_alist
= Fdelq (pair
, Vprocess_alist
);
638 deactivate_process (proc
);
641 /* Setup coding systems of PROCESS. */
644 setup_process_coding_systems (process
)
647 struct Lisp_Process
*p
= XPROCESS (process
);
648 int inch
= XINT (p
->infd
);
649 int outch
= XINT (p
->outfd
);
651 if (inch
< 0 || outch
< 0)
654 if (!proc_decode_coding_system
[inch
])
655 proc_decode_coding_system
[inch
]
656 = (struct coding_system
*) xmalloc (sizeof (struct coding_system
));
657 setup_coding_system (p
->decode_coding_system
,
658 proc_decode_coding_system
[inch
]);
659 if (! NILP (p
->filter
))
661 if (NILP (p
->filter_multibyte
))
662 setup_raw_text_coding_system (proc_decode_coding_system
[inch
]);
664 else if (BUFFERP (p
->buffer
))
666 if (NILP (XBUFFER (p
->buffer
)->enable_multibyte_characters
))
667 setup_raw_text_coding_system (proc_decode_coding_system
[inch
]);
670 if (!proc_encode_coding_system
[outch
])
671 proc_encode_coding_system
[outch
]
672 = (struct coding_system
*) xmalloc (sizeof (struct coding_system
));
673 setup_coding_system (p
->encode_coding_system
,
674 proc_encode_coding_system
[outch
]);
677 DEFUN ("processp", Fprocessp
, Sprocessp
, 1, 1, 0,
678 doc
: /* Return t if OBJECT is a process. */)
682 return PROCESSP (object
) ? Qt
: Qnil
;
685 DEFUN ("get-process", Fget_process
, Sget_process
, 1, 1, 0,
686 doc
: /* Return the process named NAME, or nil if there is none. */)
688 register Lisp_Object name
;
693 return Fcdr (Fassoc (name
, Vprocess_alist
));
696 DEFUN ("get-buffer-process", Fget_buffer_process
, Sget_buffer_process
, 1, 1, 0,
697 doc
: /* Return the (or a) process associated with BUFFER.
698 BUFFER may be a buffer or the name of one. */)
700 register Lisp_Object buffer
;
702 register Lisp_Object buf
, tail
, proc
;
704 if (NILP (buffer
)) return Qnil
;
705 buf
= Fget_buffer (buffer
);
706 if (NILP (buf
)) return Qnil
;
708 for (tail
= Vprocess_alist
; !NILP (tail
); tail
= Fcdr (tail
))
710 proc
= Fcdr (Fcar (tail
));
711 if (PROCESSP (proc
) && EQ (XPROCESS (proc
)->buffer
, buf
))
717 /* This is how commands for the user decode process arguments. It
718 accepts a process, a process name, a buffer, a buffer name, or nil.
719 Buffers denote the first process in the buffer, and nil denotes the
724 register Lisp_Object name
;
726 register Lisp_Object proc
, obj
;
729 obj
= Fget_process (name
);
731 obj
= Fget_buffer (name
);
733 error ("Process %s does not exist", SDATA (name
));
735 else if (NILP (name
))
736 obj
= Fcurrent_buffer ();
740 /* Now obj should be either a buffer object or a process object.
744 proc
= Fget_buffer_process (obj
);
746 error ("Buffer %s has no process", SDATA (XBUFFER (obj
)->name
));
756 DEFUN ("delete-process", Fdelete_process
, Sdelete_process
, 1, 1, 0,
757 doc
: /* Delete PROCESS: kill it and forget about it immediately.
758 PROCESS may be a process, a buffer, the name of a process or buffer, or
759 nil, indicating the current buffer's process. */)
761 register Lisp_Object process
;
763 process
= get_process (process
);
764 XPROCESS (process
)->raw_status_low
= Qnil
;
765 XPROCESS (process
)->raw_status_high
= Qnil
;
766 if (NETCONN_P (process
))
768 XPROCESS (process
)->status
= Fcons (Qexit
, Fcons (make_number (0), Qnil
));
769 XSETINT (XPROCESS (process
)->tick
, ++process_tick
);
772 else if (XINT (XPROCESS (process
)->infd
) >= 0)
774 Fkill_process (process
, Qnil
);
775 /* Do this now, since remove_process will make sigchld_handler do nothing. */
776 XPROCESS (process
)->status
777 = Fcons (Qsignal
, Fcons (make_number (SIGKILL
), Qnil
));
778 XSETINT (XPROCESS (process
)->tick
, ++process_tick
);
781 remove_process (process
);
785 DEFUN ("process-status", Fprocess_status
, Sprocess_status
, 1, 1, 0,
786 doc
: /* Return the status of PROCESS.
787 The returned value is one of the following symbols:
788 run -- for a process that is running.
789 stop -- for a process stopped but continuable.
790 exit -- for a process that has exited.
791 signal -- for a process that has got a fatal signal.
792 open -- for a network stream connection that is open.
793 listen -- for a network stream server that is listening.
794 closed -- for a network stream connection that is closed.
795 connect -- when waiting for a non-blocking connection to complete.
796 failed -- when a non-blocking connection has failed.
797 nil -- if arg is a process name and no such process exists.
798 PROCESS may be a process, a buffer, the name of a process, or
799 nil, indicating the current buffer's process. */)
801 register Lisp_Object process
;
803 register struct Lisp_Process
*p
;
804 register Lisp_Object status
;
806 if (STRINGP (process
))
807 process
= Fget_process (process
);
809 process
= get_process (process
);
814 p
= XPROCESS (process
);
815 if (!NILP (p
->raw_status_low
))
819 status
= XCAR (status
);
822 if (EQ (status
, Qexit
))
824 else if (EQ (p
->command
, Qt
))
826 else if (EQ (status
, Qrun
))
832 DEFUN ("process-exit-status", Fprocess_exit_status
, Sprocess_exit_status
,
834 doc
: /* Return the exit status of PROCESS or the signal number that killed it.
835 If PROCESS has not yet exited or died, return 0. */)
837 register Lisp_Object process
;
839 CHECK_PROCESS (process
);
840 if (!NILP (XPROCESS (process
)->raw_status_low
))
841 update_status (XPROCESS (process
));
842 if (CONSP (XPROCESS (process
)->status
))
843 return XCAR (XCDR (XPROCESS (process
)->status
));
844 return make_number (0);
847 DEFUN ("process-id", Fprocess_id
, Sprocess_id
, 1, 1, 0,
848 doc
: /* Return the process id of PROCESS.
849 This is the pid of the external process which PROCESS uses or talks to.
850 For a network connection, this value is nil. */)
852 register Lisp_Object process
;
854 CHECK_PROCESS (process
);
855 return XPROCESS (process
)->pid
;
858 DEFUN ("process-name", Fprocess_name
, Sprocess_name
, 1, 1, 0,
859 doc
: /* Return the name of PROCESS, as a string.
860 This is the name of the program invoked in PROCESS,
861 possibly modified to make it unique among process names. */)
863 register Lisp_Object process
;
865 CHECK_PROCESS (process
);
866 return XPROCESS (process
)->name
;
869 DEFUN ("process-command", Fprocess_command
, Sprocess_command
, 1, 1, 0,
870 doc
: /* Return the command that was executed to start PROCESS.
871 This is a list of strings, the first string being the program executed
872 and the rest of the strings being the arguments given to it.
873 For a non-child channel, this is nil. */)
875 register Lisp_Object process
;
877 CHECK_PROCESS (process
);
878 return XPROCESS (process
)->command
;
881 DEFUN ("process-tty-name", Fprocess_tty_name
, Sprocess_tty_name
, 1, 1, 0,
882 doc
: /* Return the name of the terminal PROCESS uses, or nil if none.
883 This is the terminal that the process itself reads and writes on,
884 not the name of the pty that Emacs uses to talk with that terminal. */)
886 register Lisp_Object process
;
888 CHECK_PROCESS (process
);
889 return XPROCESS (process
)->tty_name
;
892 DEFUN ("set-process-buffer", Fset_process_buffer
, Sset_process_buffer
,
894 doc
: /* Set buffer associated with PROCESS to BUFFER (a buffer, or nil). */)
896 register Lisp_Object process
, buffer
;
898 struct Lisp_Process
*p
;
900 CHECK_PROCESS (process
);
902 CHECK_BUFFER (buffer
);
903 p
= XPROCESS (process
);
906 p
->childp
= Fplist_put (p
->childp
, QCbuffer
, buffer
);
907 setup_process_coding_systems (process
);
911 DEFUN ("process-buffer", Fprocess_buffer
, Sprocess_buffer
,
913 doc
: /* Return the buffer PROCESS is associated with.
914 Output from PROCESS is inserted in this buffer unless PROCESS has a filter. */)
916 register Lisp_Object process
;
918 CHECK_PROCESS (process
);
919 return XPROCESS (process
)->buffer
;
922 DEFUN ("process-mark", Fprocess_mark
, Sprocess_mark
,
924 doc
: /* Return the marker for the end of the last output from PROCESS. */)
926 register Lisp_Object process
;
928 CHECK_PROCESS (process
);
929 return XPROCESS (process
)->mark
;
932 DEFUN ("set-process-filter", Fset_process_filter
, Sset_process_filter
,
934 doc
: /* Give PROCESS the filter function FILTER; nil means no filter.
935 t means stop accepting output from the process.
937 When a process has a filter, its buffer is not used for output.
938 Instead, each time it does output, the entire string of output is
939 passed to the filter.
941 The filter gets two arguments: the process and the string of output.
942 The string argument is normally a multibyte string, except:
943 - if the process' input coding system is no-conversion or raw-text,
944 it is a unibyte string (the non-converted input), or else
945 - if `default-enable-multibyte-characters' is nil, it is a unibyte
946 string (the result of converting the decoded input multibyte
947 string to unibyte with `string-make-unibyte'). */)
949 register Lisp_Object process
, filter
;
951 struct Lisp_Process
*p
;
953 CHECK_PROCESS (process
);
954 p
= XPROCESS (process
);
956 /* Don't signal an error if the process' input file descriptor
957 is closed. This could make debugging Lisp more difficult,
958 for example when doing something like
960 (setq process (start-process ...))
962 (set-process-filter process ...) */
964 if (XINT (p
->infd
) >= 0)
966 if (EQ (filter
, Qt
) && !EQ (p
->status
, Qlisten
))
968 FD_CLR (XINT (p
->infd
), &input_wait_mask
);
969 FD_CLR (XINT (p
->infd
), &non_keyboard_wait_mask
);
971 else if (EQ (p
->filter
, Qt
)
972 && !EQ (p
->command
, Qt
)) /* Network process not stopped. */
974 FD_SET (XINT (p
->infd
), &input_wait_mask
);
975 FD_SET (XINT (p
->infd
), &non_keyboard_wait_mask
);
981 p
->childp
= Fplist_put (p
->childp
, QCfilter
, filter
);
982 setup_process_coding_systems (process
);
986 DEFUN ("process-filter", Fprocess_filter
, Sprocess_filter
,
988 doc
: /* Returns the filter function of PROCESS; nil if none.
989 See `set-process-filter' for more info on filter functions. */)
991 register Lisp_Object process
;
993 CHECK_PROCESS (process
);
994 return XPROCESS (process
)->filter
;
997 DEFUN ("set-process-sentinel", Fset_process_sentinel
, Sset_process_sentinel
,
999 doc
: /* Give PROCESS the sentinel SENTINEL; nil for none.
1000 The sentinel is called as a function when the process changes state.
1001 It gets two arguments: the process, and a string describing the change. */)
1003 register Lisp_Object process
, sentinel
;
1005 struct Lisp_Process
*p
;
1007 CHECK_PROCESS (process
);
1008 p
= XPROCESS (process
);
1010 p
->sentinel
= sentinel
;
1012 p
->childp
= Fplist_put (p
->childp
, QCsentinel
, sentinel
);
1016 DEFUN ("process-sentinel", Fprocess_sentinel
, Sprocess_sentinel
,
1018 doc
: /* Return the sentinel of PROCESS; nil if none.
1019 See `set-process-sentinel' for more info on sentinels. */)
1021 register Lisp_Object process
;
1023 CHECK_PROCESS (process
);
1024 return XPROCESS (process
)->sentinel
;
1027 DEFUN ("set-process-window-size", Fset_process_window_size
,
1028 Sset_process_window_size
, 3, 3, 0,
1029 doc
: /* Tell PROCESS that it has logical window size HEIGHT and WIDTH. */)
1030 (process
, height
, width
)
1031 register Lisp_Object process
, height
, width
;
1033 CHECK_PROCESS (process
);
1034 CHECK_NATNUM (height
);
1035 CHECK_NATNUM (width
);
1037 if (XINT (XPROCESS (process
)->infd
) < 0
1038 || set_window_size (XINT (XPROCESS (process
)->infd
),
1039 XINT (height
), XINT (width
)) <= 0)
1045 DEFUN ("set-process-inherit-coding-system-flag",
1046 Fset_process_inherit_coding_system_flag
,
1047 Sset_process_inherit_coding_system_flag
, 2, 2, 0,
1048 doc
: /* Determine whether buffer of PROCESS will inherit coding-system.
1049 If the second argument FLAG is non-nil, then the variable
1050 `buffer-file-coding-system' of the buffer associated with PROCESS
1051 will be bound to the value of the coding system used to decode
1054 This is useful when the coding system specified for the process buffer
1055 leaves either the character code conversion or the end-of-line conversion
1056 unspecified, or if the coding system used to decode the process output
1057 is more appropriate for saving the process buffer.
1059 Binding the variable `inherit-process-coding-system' to non-nil before
1060 starting the process is an alternative way of setting the inherit flag
1061 for the process which will run. */)
1063 register Lisp_Object process
, flag
;
1065 CHECK_PROCESS (process
);
1066 XPROCESS (process
)->inherit_coding_system_flag
= flag
;
1070 DEFUN ("process-inherit-coding-system-flag",
1071 Fprocess_inherit_coding_system_flag
, Sprocess_inherit_coding_system_flag
,
1073 doc
: /* Return the value of inherit-coding-system flag for PROCESS.
1074 If this flag is t, `buffer-file-coding-system' of the buffer
1075 associated with PROCESS will inherit the coding system used to decode
1076 the process output. */)
1078 register Lisp_Object process
;
1080 CHECK_PROCESS (process
);
1081 return XPROCESS (process
)->inherit_coding_system_flag
;
1084 DEFUN ("set-process-query-on-exit-flag",
1085 Fset_process_query_on_exit_flag
, Sset_process_query_on_exit_flag
,
1087 doc
: /* Specify if query is needed for PROCESS when Emacs is exited.
1088 If the second argument FLAG is non-nil, Emacs will query the user before
1089 exiting if PROCESS is running. */)
1091 register Lisp_Object process
, flag
;
1093 CHECK_PROCESS (process
);
1094 XPROCESS (process
)->kill_without_query
= Fnull (flag
);
1098 DEFUN ("process-query-on-exit-flag",
1099 Fprocess_query_on_exit_flag
, Sprocess_query_on_exit_flag
,
1101 doc
: /* Return the current value of query-on-exit flag for PROCESS. */)
1103 register Lisp_Object process
;
1105 CHECK_PROCESS (process
);
1106 return Fnull (XPROCESS (process
)->kill_without_query
);
1109 #ifdef DATAGRAM_SOCKETS
1110 Lisp_Object
Fprocess_datagram_address ();
1113 DEFUN ("process-contact", Fprocess_contact
, Sprocess_contact
,
1115 doc
: /* Return the contact info of PROCESS; t for a real child.
1116 For a net connection, the value depends on the optional KEY arg.
1117 If KEY is nil, value is a cons cell of the form (HOST SERVICE),
1118 if KEY is t, the complete contact information for the connection is
1119 returned, else the specific value for the keyword KEY is returned.
1120 See `make-network-process' for a list of keywords. */)
1122 register Lisp_Object process
, key
;
1124 Lisp_Object contact
;
1126 CHECK_PROCESS (process
);
1127 contact
= XPROCESS (process
)->childp
;
1129 #ifdef DATAGRAM_SOCKETS
1130 if (DATAGRAM_CONN_P (process
)
1131 && (EQ (key
, Qt
) || EQ (key
, QCremote
)))
1132 contact
= Fplist_put (contact
, QCremote
,
1133 Fprocess_datagram_address (process
));
1136 if (!NETCONN_P (process
) || EQ (key
, Qt
))
1139 return Fcons (Fplist_get (contact
, QChost
),
1140 Fcons (Fplist_get (contact
, QCservice
), Qnil
));
1141 return Fplist_get (contact
, key
);
1144 DEFUN ("process-plist", Fprocess_plist
, Sprocess_plist
,
1146 doc
: /* Return the plist of PROCESS. */)
1148 register Lisp_Object process
;
1150 CHECK_PROCESS (process
);
1151 return XPROCESS (process
)->plist
;
1154 DEFUN ("set-process-plist", Fset_process_plist
, Sset_process_plist
,
1156 doc
: /* Replace the plist of PROCESS with PLIST. Returns PLIST. */)
1158 register Lisp_Object process
, plist
;
1160 CHECK_PROCESS (process
);
1163 XPROCESS (process
)->plist
= plist
;
1167 #if 0 /* Turned off because we don't currently record this info
1168 in the process. Perhaps add it. */
1169 DEFUN ("process-connection", Fprocess_connection
, Sprocess_connection
, 1, 1, 0,
1170 doc
: /* Return the connection type of PROCESS.
1171 The value is nil for a pipe, t or `pty' for a pty, or `stream' for
1172 a socket connection. */)
1174 Lisp_Object process
;
1176 return XPROCESS (process
)->type
;
1181 DEFUN ("format-network-address", Fformat_network_address
, Sformat_network_address
,
1183 doc
: /* Convert network ADDRESS from internal format to a string.
1184 If optional second argument OMIT-PORT is non-nil, don't include a port
1185 number in the string; in this case, interpret a 4 element vector as an
1186 IP address. Returns nil if format of ADDRESS is invalid. */)
1187 (address
, omit_port
)
1188 Lisp_Object address
, omit_port
;
1193 if (STRINGP (address
)) /* AF_LOCAL */
1196 if (VECTORP (address
)) /* AF_INET */
1198 register struct Lisp_Vector
*p
= XVECTOR (address
);
1199 Lisp_Object args
[6];
1202 if (!NILP (omit_port
) && (p
->size
== 4 || p
->size
== 5))
1204 args
[0] = build_string ("%d.%d.%d.%d");
1207 else if (p
->size
== 5)
1209 args
[0] = build_string ("%d.%d.%d.%d:%d");
1215 for (i
= 0; i
< nargs
; i
++)
1216 args
[i
+1] = p
->contents
[i
];
1217 return Fformat (nargs
+1, args
);
1220 if (CONSP (address
))
1222 Lisp_Object args
[2];
1223 args
[0] = build_string ("<Family %d>");
1224 args
[1] = Fcar (address
);
1225 return Fformat (2, args
);
1234 list_processes_1 (query_only
)
1235 Lisp_Object query_only
;
1237 register Lisp_Object tail
, tem
;
1238 Lisp_Object proc
, minspace
, tem1
;
1239 register struct Lisp_Process
*p
;
1241 int w_proc
, w_buffer
, w_tty
;
1242 Lisp_Object i_status
, i_buffer
, i_tty
, i_command
;
1244 w_proc
= 4; /* Proc */
1245 w_buffer
= 6; /* Buffer */
1246 w_tty
= 0; /* Omit if no ttys */
1248 for (tail
= Vprocess_alist
; !NILP (tail
); tail
= Fcdr (tail
))
1252 proc
= Fcdr (Fcar (tail
));
1253 p
= XPROCESS (proc
);
1254 if (NILP (p
->childp
))
1256 if (!NILP (query_only
) && !NILP (p
->kill_without_query
))
1258 if (STRINGP (p
->name
)
1259 && ( i
= SCHARS (p
->name
), (i
> w_proc
)))
1261 if (!NILP (p
->buffer
))
1263 if (NILP (XBUFFER (p
->buffer
)->name
) && w_buffer
< 8)
1264 w_buffer
= 8; /* (Killed) */
1265 else if ((i
= SCHARS (XBUFFER (p
->buffer
)->name
), (i
> w_buffer
)))
1268 if (STRINGP (p
->tty_name
)
1269 && (i
= SCHARS (p
->tty_name
), (i
> w_tty
)))
1273 XSETFASTINT (i_status
, w_proc
+ 1);
1274 XSETFASTINT (i_buffer
, XFASTINT (i_status
) + 9);
1277 XSETFASTINT (i_tty
, XFASTINT (i_buffer
) + w_buffer
+ 1);
1278 XSETFASTINT (i_command
, XFASTINT (i_buffer
) + w_tty
+ 1);
1281 XSETFASTINT (i_command
, XFASTINT (i_buffer
) + w_buffer
+ 1);
1284 XSETFASTINT (minspace
, 1);
1286 set_buffer_internal (XBUFFER (Vstandard_output
));
1287 Fbuffer_disable_undo (Vstandard_output
);
1289 current_buffer
->truncate_lines
= Qt
;
1291 write_string ("Proc", -1);
1292 Findent_to (i_status
, minspace
); write_string ("Status", -1);
1293 Findent_to (i_buffer
, minspace
); write_string ("Buffer", -1);
1296 Findent_to (i_tty
, minspace
); write_string ("Tty", -1);
1298 Findent_to (i_command
, minspace
); write_string ("Command", -1);
1299 write_string ("\n", -1);
1301 write_string ("----", -1);
1302 Findent_to (i_status
, minspace
); write_string ("------", -1);
1303 Findent_to (i_buffer
, minspace
); write_string ("------", -1);
1306 Findent_to (i_tty
, minspace
); write_string ("---", -1);
1308 Findent_to (i_command
, minspace
); write_string ("-------", -1);
1309 write_string ("\n", -1);
1311 for (tail
= Vprocess_alist
; !NILP (tail
); tail
= Fcdr (tail
))
1315 proc
= Fcdr (Fcar (tail
));
1316 p
= XPROCESS (proc
);
1317 if (NILP (p
->childp
))
1319 if (!NILP (query_only
) && !NILP (p
->kill_without_query
))
1322 Finsert (1, &p
->name
);
1323 Findent_to (i_status
, minspace
);
1325 if (!NILP (p
->raw_status_low
))
1328 if (CONSP (p
->status
))
1329 symbol
= XCAR (p
->status
);
1332 if (EQ (symbol
, Qsignal
))
1335 tem
= Fcar (Fcdr (p
->status
));
1337 if (XINT (tem
) < NSIG
)
1338 write_string (sys_errlist
[XINT (tem
)], -1);
1341 Fprinc (symbol
, Qnil
);
1343 else if (NETCONN1_P (p
))
1345 if (EQ (symbol
, Qexit
))
1346 write_string ("closed", -1);
1347 else if (EQ (p
->command
, Qt
))
1348 write_string ("stopped", -1);
1349 else if (EQ (symbol
, Qrun
))
1350 write_string ("open", -1);
1352 Fprinc (symbol
, Qnil
);
1355 Fprinc (symbol
, Qnil
);
1357 if (EQ (symbol
, Qexit
))
1360 tem
= Fcar (Fcdr (p
->status
));
1363 sprintf (tembuf
, " %d", (int) XFASTINT (tem
));
1364 write_string (tembuf
, -1);
1368 if (EQ (symbol
, Qsignal
) || EQ (symbol
, Qexit
))
1369 remove_process (proc
);
1371 Findent_to (i_buffer
, minspace
);
1372 if (NILP (p
->buffer
))
1373 insert_string ("(none)");
1374 else if (NILP (XBUFFER (p
->buffer
)->name
))
1375 insert_string ("(Killed)");
1377 Finsert (1, &XBUFFER (p
->buffer
)->name
);
1381 Findent_to (i_tty
, minspace
);
1382 if (STRINGP (p
->tty_name
))
1383 Finsert (1, &p
->tty_name
);
1386 Findent_to (i_command
, minspace
);
1388 if (EQ (p
->status
, Qlisten
))
1390 Lisp_Object port
= Fplist_get (p
->childp
, QCservice
);
1391 if (INTEGERP (port
))
1392 port
= Fnumber_to_string (port
);
1394 port
= Fformat_network_address (Fplist_get (p
->childp
, QClocal
), Qnil
);
1395 sprintf (tembuf
, "(network %s server on %s)\n",
1396 (DATAGRAM_CHAN_P (XINT (p
->infd
)) ? "datagram" : "stream"),
1397 (STRINGP (port
) ? (char *)SDATA (port
) : "?"));
1398 insert_string (tembuf
);
1400 else if (NETCONN1_P (p
))
1402 /* For a local socket, there is no host name,
1403 so display service instead. */
1404 Lisp_Object host
= Fplist_get (p
->childp
, QChost
);
1405 if (!STRINGP (host
))
1407 host
= Fplist_get (p
->childp
, QCservice
);
1408 if (INTEGERP (host
))
1409 host
= Fnumber_to_string (host
);
1412 host
= Fformat_network_address (Fplist_get (p
->childp
, QCremote
), Qnil
);
1413 sprintf (tembuf
, "(network %s connection to %s)\n",
1414 (DATAGRAM_CHAN_P (XINT (p
->infd
)) ? "datagram" : "stream"),
1415 (STRINGP (host
) ? (char *)SDATA (host
) : "?"));
1416 insert_string (tembuf
);
1428 insert_string (" ");
1430 insert_string ("\n");
1436 DEFUN ("list-processes", Flist_processes
, Slist_processes
, 0, 1, "P",
1437 doc
: /* Display a list of all processes.
1438 If optional argument QUERY-ONLY is non-nil, only processes with
1439 the query-on-exit flag set will be listed.
1440 Any process listed as exited or signaled is actually eliminated
1441 after the listing is made. */)
1443 Lisp_Object query_only
;
1445 internal_with_output_to_temp_buffer ("*Process List*",
1446 list_processes_1
, query_only
);
1450 DEFUN ("process-list", Fprocess_list
, Sprocess_list
, 0, 0, 0,
1451 doc
: /* Return a list of all processes. */)
1454 return Fmapcar (Qcdr
, Vprocess_alist
);
1457 /* Starting asynchronous inferior processes. */
1459 static Lisp_Object
start_process_unwind ();
1461 DEFUN ("start-process", Fstart_process
, Sstart_process
, 3, MANY
, 0,
1462 doc
: /* Start a program in a subprocess. Return the process object for it.
1463 NAME is name for process. It is modified if necessary to make it unique.
1464 BUFFER is the buffer (or buffer name) to associate with the process.
1465 Process output goes at end of that buffer, unless you specify
1466 an output stream or filter function to handle the output.
1467 BUFFER may be also nil, meaning that this process is not associated
1469 PROGRAM is the program file name. It is searched for in PATH.
1470 Remaining arguments are strings to give program as arguments.
1472 usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1475 register Lisp_Object
*args
;
1477 Lisp_Object buffer
, name
, program
, proc
, current_dir
, tem
;
1479 register unsigned char *new_argv
;
1482 register unsigned char **new_argv
;
1485 int count
= SPECPDL_INDEX ();
1489 buffer
= Fget_buffer_create (buffer
);
1491 /* Make sure that the child will be able to chdir to the current
1492 buffer's current directory, or its unhandled equivalent. We
1493 can't just have the child check for an error when it does the
1494 chdir, since it's in a vfork.
1496 We have to GCPRO around this because Fexpand_file_name and
1497 Funhandled_file_name_directory might call a file name handling
1498 function. The argument list is protected by the caller, so all
1499 we really have to worry about is buffer. */
1501 struct gcpro gcpro1
, gcpro2
;
1503 current_dir
= current_buffer
->directory
;
1505 GCPRO2 (buffer
, current_dir
);
1508 = expand_and_dir_to_file (Funhandled_file_name_directory (current_dir
),
1510 if (NILP (Ffile_accessible_directory_p (current_dir
)))
1511 report_file_error ("Setting current directory",
1512 Fcons (current_buffer
->directory
, Qnil
));
1518 CHECK_STRING (name
);
1522 CHECK_STRING (program
);
1524 proc
= make_process (name
);
1525 /* If an error occurs and we can't start the process, we want to
1526 remove it from the process list. This means that each error
1527 check in create_process doesn't need to call remove_process
1528 itself; it's all taken care of here. */
1529 record_unwind_protect (start_process_unwind
, proc
);
1531 XPROCESS (proc
)->childp
= Qt
;
1532 XPROCESS (proc
)->plist
= Qnil
;
1533 XPROCESS (proc
)->command_channel_p
= Qnil
;
1534 XPROCESS (proc
)->buffer
= buffer
;
1535 XPROCESS (proc
)->sentinel
= Qnil
;
1536 XPROCESS (proc
)->filter
= Qnil
;
1537 XPROCESS (proc
)->filter_multibyte
1538 = buffer_defaults
.enable_multibyte_characters
;
1539 XPROCESS (proc
)->command
= Flist (nargs
- 2, args
+ 2);
1541 #ifdef ADAPTIVE_READ_BUFFERING
1542 XPROCESS (proc
)->adaptive_read_buffering
= Vprocess_adaptive_read_buffering
;
1545 /* Make the process marker point into the process buffer (if any). */
1547 set_marker_both (XPROCESS (proc
)->mark
, buffer
,
1548 BUF_ZV (XBUFFER (buffer
)),
1549 BUF_ZV_BYTE (XBUFFER (buffer
)));
1552 /* Decide coding systems for communicating with the process. Here
1553 we don't setup the structure coding_system nor pay attention to
1554 unibyte mode. They are done in create_process. */
1556 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
1557 Lisp_Object coding_systems
= Qt
;
1558 Lisp_Object val
, *args2
;
1559 struct gcpro gcpro1
, gcpro2
;
1561 val
= Vcoding_system_for_read
;
1564 args2
= (Lisp_Object
*) alloca ((nargs
+ 1) * sizeof *args2
);
1565 args2
[0] = Qstart_process
;
1566 for (i
= 0; i
< nargs
; i
++) args2
[i
+ 1] = args
[i
];
1567 GCPRO2 (proc
, current_dir
);
1568 coding_systems
= Ffind_operation_coding_system (nargs
+ 1, args2
);
1570 if (CONSP (coding_systems
))
1571 val
= XCAR (coding_systems
);
1572 else if (CONSP (Vdefault_process_coding_system
))
1573 val
= XCAR (Vdefault_process_coding_system
);
1575 XPROCESS (proc
)->decode_coding_system
= val
;
1577 val
= Vcoding_system_for_write
;
1580 if (EQ (coding_systems
, Qt
))
1582 args2
= (Lisp_Object
*) alloca ((nargs
+ 1) * sizeof args2
);
1583 args2
[0] = Qstart_process
;
1584 for (i
= 0; i
< nargs
; i
++) args2
[i
+ 1] = args
[i
];
1585 GCPRO2 (proc
, current_dir
);
1586 coding_systems
= Ffind_operation_coding_system (nargs
+ 1, args2
);
1589 if (CONSP (coding_systems
))
1590 val
= XCDR (coding_systems
);
1591 else if (CONSP (Vdefault_process_coding_system
))
1592 val
= XCDR (Vdefault_process_coding_system
);
1594 XPROCESS (proc
)->encode_coding_system
= val
;
1598 /* Make a one member argv with all args concatenated
1599 together separated by a blank. */
1600 len
= SBYTES (program
) + 2;
1601 for (i
= 3; i
< nargs
; i
++)
1605 len
+= SBYTES (tem
) + 1; /* count the blank */
1607 new_argv
= (unsigned char *) alloca (len
);
1608 strcpy (new_argv
, SDATA (program
));
1609 for (i
= 3; i
< nargs
; i
++)
1613 strcat (new_argv
, " ");
1614 strcat (new_argv
, SDATA (tem
));
1616 /* Need to add code here to check for program existence on VMS */
1619 new_argv
= (unsigned char **) alloca ((nargs
- 1) * sizeof (char *));
1621 /* If program file name is not absolute, search our path for it.
1622 Put the name we will really use in TEM. */
1623 if (!IS_DIRECTORY_SEP (SREF (program
, 0))
1624 && !(SCHARS (program
) > 1
1625 && IS_DEVICE_SEP (SREF (program
, 1))))
1627 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
1630 GCPRO4 (name
, program
, buffer
, current_dir
);
1631 openp (Vexec_path
, program
, Vexec_suffixes
, &tem
, make_number (X_OK
));
1634 report_file_error ("Searching for program", Fcons (program
, Qnil
));
1635 tem
= Fexpand_file_name (tem
, Qnil
);
1639 if (!NILP (Ffile_directory_p (program
)))
1640 error ("Specified program for new process is a directory");
1644 /* If program file name starts with /: for quoting a magic name,
1646 if (SBYTES (tem
) > 2 && SREF (tem
, 0) == '/'
1647 && SREF (tem
, 1) == ':')
1648 tem
= Fsubstring (tem
, make_number (2), Qnil
);
1650 /* Encode the file name and put it in NEW_ARGV.
1651 That's where the child will use it to execute the program. */
1652 tem
= ENCODE_FILE (tem
);
1653 new_argv
[0] = SDATA (tem
);
1655 /* Here we encode arguments by the coding system used for sending
1656 data to the process. We don't support using different coding
1657 systems for encoding arguments and for encoding data sent to the
1660 for (i
= 3; i
< nargs
; i
++)
1664 if (STRING_MULTIBYTE (tem
))
1665 tem
= (code_convert_string_norecord
1666 (tem
, XPROCESS (proc
)->encode_coding_system
, 1));
1667 new_argv
[i
- 2] = SDATA (tem
);
1669 new_argv
[i
- 2] = 0;
1670 #endif /* not VMS */
1672 XPROCESS (proc
)->decoding_buf
= make_uninit_string (0);
1673 XPROCESS (proc
)->decoding_carryover
= make_number (0);
1674 XPROCESS (proc
)->encoding_buf
= make_uninit_string (0);
1675 XPROCESS (proc
)->encoding_carryover
= make_number (0);
1677 XPROCESS (proc
)->inherit_coding_system_flag
1678 = (NILP (buffer
) || !inherit_process_coding_system
1681 create_process (proc
, (char **) new_argv
, current_dir
);
1683 return unbind_to (count
, proc
);
1686 /* This function is the unwind_protect form for Fstart_process. If
1687 PROC doesn't have its pid set, then we know someone has signaled
1688 an error and the process wasn't started successfully, so we should
1689 remove it from the process list. */
1691 start_process_unwind (proc
)
1694 if (!PROCESSP (proc
))
1697 /* Was PROC started successfully? */
1698 if (XINT (XPROCESS (proc
)->pid
) <= 0)
1699 remove_process (proc
);
1705 create_process_1 (timer
)
1706 struct atimer
*timer
;
1708 /* Nothing to do. */
1712 #if 0 /* This doesn't work; see the note before sigchld_handler. */
1715 /* Mimic blocking of signals on system V, which doesn't really have it. */
1717 /* Nonzero means we got a SIGCHLD when it was supposed to be blocked. */
1718 int sigchld_deferred
;
1721 create_process_sigchld ()
1723 signal (SIGCHLD
, create_process_sigchld
);
1725 sigchld_deferred
= 1;
1731 #ifndef VMS /* VMS version of this function is in vmsproc.c. */
1733 create_process (process
, new_argv
, current_dir
)
1734 Lisp_Object process
;
1736 Lisp_Object current_dir
;
1738 int pid
, inchannel
, outchannel
;
1740 #ifdef POSIX_SIGNALS
1743 struct sigaction sigint_action
;
1744 struct sigaction sigquit_action
;
1746 struct sigaction sighup_action
;
1748 #else /* !POSIX_SIGNALS */
1751 SIGTYPE (*sigchld
)();
1754 #endif /* !POSIX_SIGNALS */
1755 /* Use volatile to protect variables from being clobbered by longjmp. */
1756 volatile int forkin
, forkout
;
1757 volatile int pty_flag
= 0;
1759 extern char **environ
;
1762 inchannel
= outchannel
= -1;
1765 if (!NILP (Vprocess_connection_type
))
1766 outchannel
= inchannel
= allocate_pty ();
1770 #if ! defined (USG) || defined (USG_SUBTTY_WORKS)
1771 /* On most USG systems it does not work to open the pty's tty here,
1772 then close it and reopen it in the child. */
1774 /* Don't let this terminal become our controlling terminal
1775 (in case we don't have one). */
1776 forkout
= forkin
= emacs_open (pty_name
, O_RDWR
| O_NOCTTY
, 0);
1778 forkout
= forkin
= emacs_open (pty_name
, O_RDWR
, 0);
1781 report_file_error ("Opening pty", Qnil
);
1783 forkin
= forkout
= -1;
1784 #endif /* not USG, or USG_SUBTTY_WORKS */
1788 #endif /* HAVE_PTYS */
1791 if (socketpair (AF_UNIX
, SOCK_STREAM
, 0, sv
) < 0)
1792 report_file_error ("Opening socketpair", Qnil
);
1793 outchannel
= inchannel
= sv
[0];
1794 forkout
= forkin
= sv
[1];
1796 #else /* not SKTPAIR */
1801 report_file_error ("Creating pipe", Qnil
);
1807 emacs_close (inchannel
);
1808 emacs_close (forkout
);
1809 report_file_error ("Creating pipe", Qnil
);
1814 #endif /* not SKTPAIR */
1817 /* Replaced by close_process_descs */
1818 set_exclusive_use (inchannel
);
1819 set_exclusive_use (outchannel
);
1822 /* Stride people say it's a mystery why this is needed
1823 as well as the O_NDELAY, but that it fails without this. */
1824 #if defined (STRIDE) || (defined (pfa) && defined (HAVE_PTYS))
1827 ioctl (inchannel
, FIONBIO
, &one
);
1832 fcntl (inchannel
, F_SETFL
, O_NONBLOCK
);
1833 fcntl (outchannel
, F_SETFL
, O_NONBLOCK
);
1836 fcntl (inchannel
, F_SETFL
, O_NDELAY
);
1837 fcntl (outchannel
, F_SETFL
, O_NDELAY
);
1841 /* Record this as an active process, with its channels.
1842 As a result, child_setup will close Emacs's side of the pipes. */
1843 chan_process
[inchannel
] = process
;
1844 XSETINT (XPROCESS (process
)->infd
, inchannel
);
1845 XSETINT (XPROCESS (process
)->outfd
, outchannel
);
1847 /* Previously we recorded the tty descriptor used in the subprocess.
1848 It was only used for getting the foreground tty process, so now
1849 we just reopen the device (see emacs_get_tty_pgrp) as this is
1850 more portable (see USG_SUBTTY_WORKS above). */
1852 XPROCESS (process
)->pty_flag
= (pty_flag
? Qt
: Qnil
);
1853 XPROCESS (process
)->status
= Qrun
;
1854 setup_process_coding_systems (process
);
1856 /* Delay interrupts until we have a chance to store
1857 the new fork's pid in its process structure */
1858 #ifdef POSIX_SIGNALS
1859 sigemptyset (&blocked
);
1861 sigaddset (&blocked
, SIGCHLD
);
1863 #ifdef HAVE_WORKING_VFORK
1864 /* On many hosts (e.g. Solaris 2.4), if a vforked child calls `signal',
1865 this sets the parent's signal handlers as well as the child's.
1866 So delay all interrupts whose handlers the child might munge,
1867 and record the current handlers so they can be restored later. */
1868 sigaddset (&blocked
, SIGINT
); sigaction (SIGINT
, 0, &sigint_action
);
1869 sigaddset (&blocked
, SIGQUIT
); sigaction (SIGQUIT
, 0, &sigquit_action
);
1871 sigaddset (&blocked
, SIGHUP
); sigaction (SIGHUP
, 0, &sighup_action
);
1873 #endif /* HAVE_WORKING_VFORK */
1874 sigprocmask (SIG_BLOCK
, &blocked
, &procmask
);
1875 #else /* !POSIX_SIGNALS */
1879 #else /* not BSD4_1 */
1880 #if defined (BSD_SYSTEM) || defined (UNIPLUS) || defined (HPUX)
1881 sigsetmask (sigmask (SIGCHLD
));
1882 #else /* ordinary USG */
1884 sigchld_deferred
= 0;
1885 sigchld
= signal (SIGCHLD
, create_process_sigchld
);
1887 #endif /* ordinary USG */
1888 #endif /* not BSD4_1 */
1889 #endif /* SIGCHLD */
1890 #endif /* !POSIX_SIGNALS */
1892 FD_SET (inchannel
, &input_wait_mask
);
1893 FD_SET (inchannel
, &non_keyboard_wait_mask
);
1894 if (inchannel
> max_process_desc
)
1895 max_process_desc
= inchannel
;
1897 /* Until we store the proper pid, enable sigchld_handler
1898 to recognize an unknown pid as standing for this process.
1899 It is very important not to let this `marker' value stay
1900 in the table after this function has returned; if it does
1901 it might cause call-process to hang and subsequent asynchronous
1902 processes to get their return values scrambled. */
1903 XSETINT (XPROCESS (process
)->pid
, -1);
1908 /* child_setup must clobber environ on systems with true vfork.
1909 Protect it from permanent change. */
1910 char **save_environ
= environ
;
1912 current_dir
= ENCODE_FILE (current_dir
);
1917 #endif /* not WINDOWSNT */
1919 int xforkin
= forkin
;
1920 int xforkout
= forkout
;
1922 #if 0 /* This was probably a mistake--it duplicates code later on,
1923 but fails to handle all the cases. */
1924 /* Make sure SIGCHLD is not blocked in the child. */
1925 sigsetmask (SIGEMPTYMASK
);
1928 /* Make the pty be the controlling terminal of the process. */
1930 /* First, disconnect its current controlling terminal. */
1932 /* We tried doing setsid only if pty_flag, but it caused
1933 process_set_signal to fail on SGI when using a pipe. */
1935 /* Make the pty's terminal the controlling terminal. */
1939 /* We ignore the return value
1940 because faith@cs.unc.edu says that is necessary on Linux. */
1941 ioctl (xforkin
, TIOCSCTTY
, 0);
1944 #else /* not HAVE_SETSID */
1946 /* It's very important to call setpgrp here and no time
1947 afterwards. Otherwise, we lose our controlling tty which
1948 is set when we open the pty. */
1951 #endif /* not HAVE_SETSID */
1952 #if defined (HAVE_TERMIOS) && defined (LDISC1)
1953 if (pty_flag
&& xforkin
>= 0)
1956 tcgetattr (xforkin
, &t
);
1958 if (tcsetattr (xforkin
, TCSANOW
, &t
) < 0)
1959 emacs_write (1, "create_process/tcsetattr LDISC1 failed\n", 39);
1962 #if defined (NTTYDISC) && defined (TIOCSETD)
1963 if (pty_flag
&& xforkin
>= 0)
1965 /* Use new line discipline. */
1966 int ldisc
= NTTYDISC
;
1967 ioctl (xforkin
, TIOCSETD
, &ldisc
);
1972 /* In 4.3BSD, the TIOCSPGRP bug has been fixed, and now you
1973 can do TIOCSPGRP only to the process's controlling tty. */
1976 /* I wonder: would just ioctl (0, TIOCNOTTY, 0) work here?
1977 I can't test it since I don't have 4.3. */
1978 int j
= emacs_open ("/dev/tty", O_RDWR
, 0);
1979 ioctl (j
, TIOCNOTTY
, 0);
1982 /* In order to get a controlling terminal on some versions
1983 of BSD, it is necessary to put the process in pgrp 0
1984 before it opens the terminal. */
1992 #endif /* TIOCNOTTY */
1994 #if !defined (RTU) && !defined (UNIPLUS) && !defined (DONT_REOPEN_PTY)
1995 /*** There is a suggestion that this ought to be a
1996 conditional on TIOCSPGRP,
1997 or !(defined (HAVE_SETSID) && defined (TIOCSCTTY)).
1998 Trying the latter gave the wrong results on Debian GNU/Linux 1.1;
1999 that system does seem to need this code, even though
2000 both HAVE_SETSID and TIOCSCTTY are defined. */
2001 /* Now close the pty (if we had it open) and reopen it.
2002 This makes the pty the controlling terminal of the subprocess. */
2005 #ifdef SET_CHILD_PTY_PGRP
2006 int pgrp
= getpid ();
2009 /* I wonder if emacs_close (emacs_open (pty_name, ...))
2012 emacs_close (xforkin
);
2013 xforkout
= xforkin
= emacs_open (pty_name
, O_RDWR
, 0);
2017 emacs_write (1, "Couldn't open the pty terminal ", 31);
2018 emacs_write (1, pty_name
, strlen (pty_name
));
2019 emacs_write (1, "\n", 1);
2023 #ifdef SET_CHILD_PTY_PGRP
2024 ioctl (xforkin
, TIOCSPGRP
, &pgrp
);
2025 ioctl (xforkout
, TIOCSPGRP
, &pgrp
);
2028 #endif /* not UNIPLUS and not RTU and not DONT_REOPEN_PTY */
2030 #ifdef SETUP_SLAVE_PTY
2035 #endif /* SETUP_SLAVE_PTY */
2037 /* On AIX, we've disabled SIGHUP above once we start a child on a pty.
2038 Now reenable it in the child, so it will die when we want it to. */
2040 signal (SIGHUP
, SIG_DFL
);
2042 #endif /* HAVE_PTYS */
2044 signal (SIGINT
, SIG_DFL
);
2045 signal (SIGQUIT
, SIG_DFL
);
2047 /* Stop blocking signals in the child. */
2048 #ifdef POSIX_SIGNALS
2049 sigprocmask (SIG_SETMASK
, &procmask
, 0);
2050 #else /* !POSIX_SIGNALS */
2054 #else /* not BSD4_1 */
2055 #if defined (BSD_SYSTEM) || defined (UNIPLUS) || defined (HPUX)
2056 sigsetmask (SIGEMPTYMASK
);
2057 #else /* ordinary USG */
2059 signal (SIGCHLD
, sigchld
);
2061 #endif /* ordinary USG */
2062 #endif /* not BSD4_1 */
2063 #endif /* SIGCHLD */
2064 #endif /* !POSIX_SIGNALS */
2067 child_setup_tty (xforkout
);
2069 pid
= child_setup (xforkin
, xforkout
, xforkout
,
2070 new_argv
, 1, current_dir
);
2071 #else /* not WINDOWSNT */
2072 child_setup (xforkin
, xforkout
, xforkout
,
2073 new_argv
, 1, current_dir
);
2074 #endif /* not WINDOWSNT */
2076 environ
= save_environ
;
2081 /* This runs in the Emacs process. */
2085 emacs_close (forkin
);
2086 if (forkin
!= forkout
&& forkout
>= 0)
2087 emacs_close (forkout
);
2091 /* vfork succeeded. */
2092 XSETFASTINT (XPROCESS (process
)->pid
, pid
);
2095 register_child (pid
, inchannel
);
2096 #endif /* WINDOWSNT */
2098 /* If the subfork execv fails, and it exits,
2099 this close hangs. I don't know why.
2100 So have an interrupt jar it loose. */
2102 struct atimer
*timer
;
2106 EMACS_SET_SECS_USECS (offset
, 1, 0);
2107 timer
= start_atimer (ATIMER_RELATIVE
, offset
, create_process_1
, 0);
2110 emacs_close (forkin
);
2112 cancel_atimer (timer
);
2116 if (forkin
!= forkout
&& forkout
>= 0)
2117 emacs_close (forkout
);
2121 XPROCESS (process
)->tty_name
= build_string (pty_name
);
2124 XPROCESS (process
)->tty_name
= Qnil
;
2127 /* Restore the signal state whether vfork succeeded or not.
2128 (We will signal an error, below, if it failed.) */
2129 #ifdef POSIX_SIGNALS
2130 #ifdef HAVE_WORKING_VFORK
2131 /* Restore the parent's signal handlers. */
2132 sigaction (SIGINT
, &sigint_action
, 0);
2133 sigaction (SIGQUIT
, &sigquit_action
, 0);
2135 sigaction (SIGHUP
, &sighup_action
, 0);
2137 #endif /* HAVE_WORKING_VFORK */
2138 /* Stop blocking signals in the parent. */
2139 sigprocmask (SIG_SETMASK
, &procmask
, 0);
2140 #else /* !POSIX_SIGNALS */
2144 #else /* not BSD4_1 */
2145 #if defined (BSD_SYSTEM) || defined (UNIPLUS) || defined (HPUX)
2146 sigsetmask (SIGEMPTYMASK
);
2147 #else /* ordinary USG */
2149 signal (SIGCHLD
, sigchld
);
2150 /* Now really handle any of these signals
2151 that came in during this function. */
2152 if (sigchld_deferred
)
2153 kill (getpid (), SIGCHLD
);
2155 #endif /* ordinary USG */
2156 #endif /* not BSD4_1 */
2157 #endif /* SIGCHLD */
2158 #endif /* !POSIX_SIGNALS */
2160 /* Now generate the error if vfork failed. */
2162 report_file_error ("Doing vfork", Qnil
);
2164 #endif /* not VMS */
2169 /* Convert an internal struct sockaddr to a lisp object (vector or string).
2170 The address family of sa is not included in the result. */
2173 conv_sockaddr_to_lisp (sa
, len
)
2174 struct sockaddr
*sa
;
2177 Lisp_Object address
;
2180 register struct Lisp_Vector
*p
;
2182 switch (sa
->sa_family
)
2186 struct sockaddr_in
*sin
= (struct sockaddr_in
*) sa
;
2187 len
= sizeof (sin
->sin_addr
) + 1;
2188 address
= Fmake_vector (make_number (len
), Qnil
);
2189 p
= XVECTOR (address
);
2190 p
->contents
[--len
] = make_number (ntohs (sin
->sin_port
));
2191 cp
= (unsigned char *)&sin
->sin_addr
;
2194 #ifdef HAVE_LOCAL_SOCKETS
2197 struct sockaddr_un
*sockun
= (struct sockaddr_un
*) sa
;
2198 for (i
= 0; i
< sizeof (sockun
->sun_path
); i
++)
2199 if (sockun
->sun_path
[i
] == 0)
2201 return make_unibyte_string (sockun
->sun_path
, i
);
2205 len
-= sizeof (sa
->sa_family
);
2206 address
= Fcons (make_number (sa
->sa_family
),
2207 Fmake_vector (make_number (len
), Qnil
));
2208 p
= XVECTOR (XCDR (address
));
2209 cp
= (unsigned char *) sa
+ sizeof (sa
->sa_family
);
2215 p
->contents
[i
++] = make_number (*cp
++);
2221 /* Get family and required size for sockaddr structure to hold ADDRESS. */
2224 get_lisp_to_sockaddr_size (address
, familyp
)
2225 Lisp_Object address
;
2228 register struct Lisp_Vector
*p
;
2230 if (VECTORP (address
))
2232 p
= XVECTOR (address
);
2236 return sizeof (struct sockaddr_in
);
2239 #ifdef HAVE_LOCAL_SOCKETS
2240 else if (STRINGP (address
))
2242 *familyp
= AF_LOCAL
;
2243 return sizeof (struct sockaddr_un
);
2246 else if (CONSP (address
) && INTEGERP (XCAR (address
)) && VECTORP (XCDR (address
)))
2248 struct sockaddr
*sa
;
2249 *familyp
= XINT (XCAR (address
));
2250 p
= XVECTOR (XCDR (address
));
2251 return p
->size
+ sizeof (sa
->sa_family
);
2256 /* Convert an address object (vector or string) to an internal sockaddr.
2257 Format of address has already been validated by size_lisp_to_sockaddr. */
2260 conv_lisp_to_sockaddr (family
, address
, sa
, len
)
2262 Lisp_Object address
;
2263 struct sockaddr
*sa
;
2266 register struct Lisp_Vector
*p
;
2267 register unsigned char *cp
= NULL
;
2271 sa
->sa_family
= family
;
2273 if (VECTORP (address
))
2275 p
= XVECTOR (address
);
2276 if (family
== AF_INET
)
2278 struct sockaddr_in
*sin
= (struct sockaddr_in
*) sa
;
2279 len
= sizeof (sin
->sin_addr
) + 1;
2280 i
= XINT (p
->contents
[--len
]);
2281 sin
->sin_port
= htons (i
);
2282 cp
= (unsigned char *)&sin
->sin_addr
;
2285 else if (STRINGP (address
))
2287 #ifdef HAVE_LOCAL_SOCKETS
2288 if (family
== AF_LOCAL
)
2290 struct sockaddr_un
*sockun
= (struct sockaddr_un
*) sa
;
2291 cp
= SDATA (address
);
2292 for (i
= 0; i
< sizeof (sockun
->sun_path
) && *cp
; i
++)
2293 sockun
->sun_path
[i
] = *cp
++;
2300 p
= XVECTOR (XCDR (address
));
2301 cp
= (unsigned char *)sa
+ sizeof (sa
->sa_family
);
2304 for (i
= 0; i
< len
; i
++)
2305 if (INTEGERP (p
->contents
[i
]))
2306 *cp
++ = XFASTINT (p
->contents
[i
]) & 0xff;
2309 #ifdef DATAGRAM_SOCKETS
2310 DEFUN ("process-datagram-address", Fprocess_datagram_address
, Sprocess_datagram_address
,
2312 doc
: /* Get the current datagram address associated with PROCESS. */)
2314 Lisp_Object process
;
2318 CHECK_PROCESS (process
);
2320 if (!DATAGRAM_CONN_P (process
))
2323 channel
= XINT (XPROCESS (process
)->infd
);
2324 return conv_sockaddr_to_lisp (datagram_address
[channel
].sa
,
2325 datagram_address
[channel
].len
);
2328 DEFUN ("set-process-datagram-address", Fset_process_datagram_address
, Sset_process_datagram_address
,
2330 doc
: /* Set the datagram address for PROCESS to ADDRESS.
2331 Returns nil upon error setting address, ADDRESS otherwise. */)
2333 Lisp_Object process
, address
;
2338 CHECK_PROCESS (process
);
2340 if (!DATAGRAM_CONN_P (process
))
2343 channel
= XINT (XPROCESS (process
)->infd
);
2345 len
= get_lisp_to_sockaddr_size (address
, &family
);
2346 if (datagram_address
[channel
].len
!= len
)
2348 conv_lisp_to_sockaddr (family
, address
, datagram_address
[channel
].sa
, len
);
2354 static struct socket_options
{
2355 /* The name of this option. Should be lowercase version of option
2356 name without SO_ prefix. */
2358 /* Option level SOL_... */
2360 /* Option number SO_... */
2362 enum { SOPT_UNKNOWN
, SOPT_BOOL
, SOPT_INT
, SOPT_IFNAME
, SOPT_LINGER
} opttype
;
2363 enum { OPIX_NONE
=0, OPIX_MISC
=1, OPIX_REUSEADDR
=2 } optbit
;
2364 } socket_options
[] =
2366 #ifdef SO_BINDTODEVICE
2367 { ":bindtodevice", SOL_SOCKET
, SO_BINDTODEVICE
, SOPT_IFNAME
, OPIX_MISC
},
2370 { ":broadcast", SOL_SOCKET
, SO_BROADCAST
, SOPT_BOOL
, OPIX_MISC
},
2373 { ":dontroute", SOL_SOCKET
, SO_DONTROUTE
, SOPT_BOOL
, OPIX_MISC
},
2376 { ":keepalive", SOL_SOCKET
, SO_KEEPALIVE
, SOPT_BOOL
, OPIX_MISC
},
2379 { ":linger", SOL_SOCKET
, SO_LINGER
, SOPT_LINGER
, OPIX_MISC
},
2382 { ":oobinline", SOL_SOCKET
, SO_OOBINLINE
, SOPT_BOOL
, OPIX_MISC
},
2385 { ":priority", SOL_SOCKET
, SO_PRIORITY
, SOPT_INT
, OPIX_MISC
},
2388 { ":reuseaddr", SOL_SOCKET
, SO_REUSEADDR
, SOPT_BOOL
, OPIX_REUSEADDR
},
2390 { 0, 0, 0, SOPT_UNKNOWN
, OPIX_NONE
}
2393 /* Set option OPT to value VAL on socket S.
2395 Returns (1<<socket_options[OPT].optbit) if option is known, 0 otherwise.
2396 Signals an error if setting a known option fails.
2400 set_socket_option (s
, opt
, val
)
2402 Lisp_Object opt
, val
;
2405 struct socket_options
*sopt
;
2410 name
= (char *) SDATA (SYMBOL_NAME (opt
));
2411 for (sopt
= socket_options
; sopt
->name
; sopt
++)
2412 if (strcmp (name
, sopt
->name
) == 0)
2415 switch (sopt
->opttype
)
2420 optval
= NILP (val
) ? 0 : 1;
2421 ret
= setsockopt (s
, sopt
->optlevel
, sopt
->optnum
,
2422 &optval
, sizeof (optval
));
2430 optval
= XINT (val
);
2432 error ("Bad option value for %s", name
);
2433 ret
= setsockopt (s
, sopt
->optlevel
, sopt
->optnum
,
2434 &optval
, sizeof (optval
));
2438 #ifdef SO_BINDTODEVICE
2441 char devname
[IFNAMSIZ
+1];
2443 /* This is broken, at least in the Linux 2.4 kernel.
2444 To unbind, the arg must be a zero integer, not the empty string.
2445 This should work on all systems. KFS. 2003-09-23. */
2446 bzero (devname
, sizeof devname
);
2449 char *arg
= (char *) SDATA (val
);
2450 int len
= min (strlen (arg
), IFNAMSIZ
);
2451 bcopy (arg
, devname
, len
);
2453 else if (!NILP (val
))
2454 error ("Bad option value for %s", name
);
2455 ret
= setsockopt (s
, sopt
->optlevel
, sopt
->optnum
,
2464 struct linger linger
;
2467 linger
.l_linger
= 0;
2469 linger
.l_linger
= XINT (val
);
2471 linger
.l_onoff
= NILP (val
) ? 0 : 1;
2472 ret
= setsockopt (s
, sopt
->optlevel
, sopt
->optnum
,
2473 &linger
, sizeof (linger
));
2483 report_file_error ("Cannot set network option",
2484 Fcons (opt
, Fcons (val
, Qnil
)));
2485 return (1 << sopt
->optbit
);
2489 DEFUN ("set-network-process-option",
2490 Fset_network_process_option
, Sset_network_process_option
,
2492 doc
: /* For network process PROCESS set option OPTION to value VALUE.
2493 See `make-network-process' for a list of options and values.
2494 If optional fourth arg NO-ERROR is non-nil, don't signal an error if
2495 OPTION is not a supported option, return nil instead; otherwise return t. */)
2496 (process
, option
, value
, no_error
)
2497 Lisp_Object process
, option
, value
;
2498 Lisp_Object no_error
;
2501 struct Lisp_Process
*p
;
2503 CHECK_PROCESS (process
);
2504 p
= XPROCESS (process
);
2505 if (!NETCONN1_P (p
))
2506 error ("Process is not a network process");
2510 error ("Process is not running");
2512 if (set_socket_option (s
, option
, value
))
2514 p
->childp
= Fplist_put (p
->childp
, option
, value
);
2518 if (NILP (no_error
))
2519 error ("Unknown or unsupported option");
2525 /* A version of request_sigio suitable for a record_unwind_protect. */
2528 unwind_request_sigio (dummy
)
2531 if (interrupt_input
)
2536 /* Create a network stream/datagram client/server process. Treated
2537 exactly like a normal process when reading and writing. Primary
2538 differences are in status display and process deletion. A network
2539 connection has no PID; you cannot signal it. All you can do is
2540 stop/continue it and deactivate/close it via delete-process */
2542 DEFUN ("make-network-process", Fmake_network_process
, Smake_network_process
,
2544 doc
: /* Create and return a network server or client process.
2546 In Emacs, network connections are represented by process objects, so
2547 input and output work as for subprocesses and `delete-process' closes
2548 a network connection. However, a network process has no process id,
2549 it cannot be signalled, and the status codes are different from normal
2552 Arguments are specified as keyword/argument pairs. The following
2553 arguments are defined:
2555 :name NAME -- NAME is name for process. It is modified if necessary
2558 :buffer BUFFER -- BUFFER is the buffer (or buffer-name) to associate
2559 with the process. Process output goes at end of that buffer, unless
2560 you specify an output stream or filter function to handle the output.
2561 BUFFER may be also nil, meaning that this process is not associated
2564 :host HOST -- HOST is name of the host to connect to, or its IP
2565 address. The symbol `local' specifies the local host. If specified
2566 for a server process, it must be a valid name or address for the local
2567 host, and only clients connecting to that address will be accepted.
2569 :service SERVICE -- SERVICE is name of the service desired, or an
2570 integer specifying a port number to connect to. If SERVICE is t,
2571 a random port number is selected for the server.
2573 :type TYPE -- TYPE is the type of connection. The default (nil) is a
2574 stream type connection, `datagram' creates a datagram type connection.
2576 :family FAMILY -- FAMILY is the address (and protocol) family for the
2577 service specified by HOST and SERVICE. The default address family is
2578 Inet (or IPv4) for the host and port number specified by HOST and
2579 SERVICE. Other address families supported are:
2580 local -- for a local (i.e. UNIX) address specified by SERVICE.
2582 :local ADDRESS -- ADDRESS is the local address used for the connection.
2583 This parameter is ignored when opening a client process. When specified
2584 for a server process, the FAMILY, HOST and SERVICE args are ignored.
2586 :remote ADDRESS -- ADDRESS is the remote partner's address for the
2587 connection. This parameter is ignored when opening a stream server
2588 process. For a datagram server process, it specifies the initial
2589 setting of the remote datagram address. When specified for a client
2590 process, the FAMILY, HOST, and SERVICE args are ignored.
2592 The format of ADDRESS depends on the address family:
2593 - An IPv4 address is represented as an vector of integers [A B C D P]
2594 corresponding to numeric IP address A.B.C.D and port number P.
2595 - A local address is represented as a string with the address in the
2596 local address space.
2597 - An "unsupported family" address is represented by a cons (F . AV)
2598 where F is the family number and AV is a vector containing the socket
2599 address data with one element per address data byte. Do not rely on
2600 this format in portable code, as it may depend on implementation
2601 defined constants, data sizes, and data structure alignment.
2603 :coding CODING -- If CODING is a symbol, it specifies the coding
2604 system used for both reading and writing for this process. If CODING
2605 is a cons (DECODING . ENCODING), DECODING is used for reading, and
2606 ENCODING is used for writing.
2608 :nowait BOOL -- If BOOL is non-nil for a stream type client process,
2609 return without waiting for the connection to complete; instead, the
2610 sentinel function will be called with second arg matching "open" (if
2611 successful) or "failed" when the connect completes. Default is to use
2612 a blocking connect (i.e. wait) for stream type connections.
2614 :noquery BOOL -- Query the user unless BOOL is non-nil, and process is
2615 running when Emacs is exited.
2617 :stop BOOL -- Start process in the `stopped' state if BOOL non-nil.
2618 In the stopped state, a server process does not accept new
2619 connections, and a client process does not handle incoming traffic.
2620 The stopped state is cleared by `continue-process' and set by
2623 :filter FILTER -- Install FILTER as the process filter.
2625 :filter-multibyte BOOL -- If BOOL is non-nil, strings given to the
2626 process filter are multibyte, otherwise they are unibyte.
2627 If this keyword is not specified, the strings are multibyte iff
2628 `default-enable-multibyte-characters' is non-nil.
2630 :sentinel SENTINEL -- Install SENTINEL as the process sentinel.
2632 :log LOG -- Install LOG as the server process log function. This
2633 function is called when the server accepts a network connection from a
2634 client. The arguments are SERVER, CLIENT, and MESSAGE, where SERVER
2635 is the server process, CLIENT is the new process for the connection,
2636 and MESSAGE is a string.
2638 :plist PLIST -- Install PLIST as the new process' initial plist.
2640 :server QLEN -- if QLEN is non-nil, create a server process for the
2641 specified FAMILY, SERVICE, and connection type (stream or datagram).
2642 If QLEN is an integer, it is used as the max. length of the server's
2643 pending connection queue (also known as the backlog); the default
2644 queue length is 5. Default is to create a client process.
2646 The following network options can be specified for this connection:
2648 :broadcast BOOL -- Allow send and receive of datagram broadcasts.
2649 :dontroute BOOL -- Only send to directly connected hosts.
2650 :keepalive BOOL -- Send keep-alive messages on network stream.
2651 :linger BOOL or TIMEOUT -- Send queued messages before closing.
2652 :oobinline BOOL -- Place out-of-band data in receive data stream.
2653 :priority INT -- Set protocol defined priority for sent packets.
2654 :reuseaddr BOOL -- Allow reusing a recently used local address
2655 (this is allowed by default for a server process).
2656 :bindtodevice NAME -- bind to interface NAME. Using this may require
2657 special privileges on some systems.
2659 Consult the relevant system programmer's manual pages for more
2660 information on using these options.
2663 A server process will listen for and accept connections from clients.
2664 When a client connection is accepted, a new network process is created
2665 for the connection with the following parameters:
2667 - The client's process name is constructed by concatenating the server
2668 process' NAME and a client identification string.
2669 - If the FILTER argument is non-nil, the client process will not get a
2670 separate process buffer; otherwise, the client's process buffer is a newly
2671 created buffer named after the server process' BUFFER name or process
2672 NAME concatenated with the client identification string.
2673 - The connection type and the process filter and sentinel parameters are
2674 inherited from the server process' TYPE, FILTER and SENTINEL.
2675 - The client process' contact info is set according to the client's
2676 addressing information (typically an IP address and a port number).
2677 - The client process' plist is initialized from the server's plist.
2679 Notice that the FILTER and SENTINEL args are never used directly by
2680 the server process. Also, the BUFFER argument is not used directly by
2681 the server process, but via the optional :log function, accepted (and
2682 failed) connections may be logged in the server process' buffer.
2684 The original argument list, modified with the actual connection
2685 information, is available via the `process-contact' function.
2687 usage: (make-network-process &rest ARGS) */)
2693 Lisp_Object contact
;
2694 struct Lisp_Process
*p
;
2695 #ifdef HAVE_GETADDRINFO
2696 struct addrinfo ai
, *res
, *lres
;
2697 struct addrinfo hints
;
2698 char *portstring
, portbuf
[128];
2699 #else /* HAVE_GETADDRINFO */
2700 struct _emacs_addrinfo
2706 struct sockaddr
*ai_addr
;
2707 struct _emacs_addrinfo
*ai_next
;
2709 #endif /* HAVE_GETADDRINFO */
2710 struct sockaddr_in address_in
;
2711 #ifdef HAVE_LOCAL_SOCKETS
2712 struct sockaddr_un address_un
;
2717 int s
= -1, outch
, inch
;
2718 struct gcpro gcpro1
;
2720 int count
= SPECPDL_INDEX ();
2722 Lisp_Object QCaddress
; /* one of QClocal or QCremote */
2724 Lisp_Object name
, buffer
, host
, service
, address
;
2725 Lisp_Object filter
, sentinel
;
2726 int is_non_blocking_client
= 0;
2727 int is_server
= 0, backlog
= 5;
2734 /* Save arguments for process-contact and clone-process. */
2735 contact
= Flist (nargs
, args
);
2739 /* Ensure socket support is loaded if available. */
2740 init_winsock (TRUE
);
2743 /* :type TYPE (nil: stream, datagram */
2744 tem
= Fplist_get (contact
, QCtype
);
2746 socktype
= SOCK_STREAM
;
2747 #ifdef DATAGRAM_SOCKETS
2748 else if (EQ (tem
, Qdatagram
))
2749 socktype
= SOCK_DGRAM
;
2752 error ("Unsupported connection type");
2755 tem
= Fplist_get (contact
, QCserver
);
2758 /* Don't support network sockets when non-blocking mode is
2759 not available, since a blocked Emacs is not useful. */
2760 #if defined(TERM) || (!defined(O_NONBLOCK) && !defined(O_NDELAY))
2761 error ("Network servers not supported");
2765 backlog
= XINT (tem
);
2769 /* Make QCaddress an alias for :local (server) or :remote (client). */
2770 QCaddress
= is_server
? QClocal
: QCremote
;
2773 if (!is_server
&& socktype
== SOCK_STREAM
2774 && (tem
= Fplist_get (contact
, QCnowait
), !NILP (tem
)))
2776 #ifndef NON_BLOCKING_CONNECT
2777 error ("Non-blocking connect not supported");
2779 is_non_blocking_client
= 1;
2783 name
= Fplist_get (contact
, QCname
);
2784 buffer
= Fplist_get (contact
, QCbuffer
);
2785 filter
= Fplist_get (contact
, QCfilter
);
2786 sentinel
= Fplist_get (contact
, QCsentinel
);
2788 CHECK_STRING (name
);
2791 /* Let's handle TERM before things get complicated ... */
2792 host
= Fplist_get (contact
, QChost
);
2793 CHECK_STRING (host
);
2795 service
= Fplist_get (contact
, QCservice
);
2796 if (INTEGERP (service
))
2797 port
= htons ((unsigned short) XINT (service
));
2800 struct servent
*svc_info
;
2801 CHECK_STRING (service
);
2802 svc_info
= getservbyname (SDATA (service
), "tcp");
2804 error ("Unknown service: %s", SDATA (service
));
2805 port
= svc_info
->s_port
;
2808 s
= connect_server (0);
2810 report_file_error ("error creating socket", Fcons (name
, Qnil
));
2811 send_command (s
, C_PORT
, 0, "%s:%d", SDATA (host
), ntohs (port
));
2812 send_command (s
, C_DUMB
, 1, 0);
2814 #else /* not TERM */
2816 /* Initialize addrinfo structure in case we don't use getaddrinfo. */
2817 ai
.ai_socktype
= socktype
;
2822 /* :local ADDRESS or :remote ADDRESS */
2823 address
= Fplist_get (contact
, QCaddress
);
2824 if (!NILP (address
))
2826 host
= service
= Qnil
;
2828 if (!(ai
.ai_addrlen
= get_lisp_to_sockaddr_size (address
, &family
)))
2829 error ("Malformed :address");
2830 ai
.ai_family
= family
;
2831 ai
.ai_addr
= alloca (ai
.ai_addrlen
);
2832 conv_lisp_to_sockaddr (family
, address
, ai
.ai_addr
, ai
.ai_addrlen
);
2836 /* :family FAMILY -- nil (for Inet), local, or integer. */
2837 tem
= Fplist_get (contact
, QCfamily
);
2839 family
= XINT (tem
);
2844 #ifdef HAVE_LOCAL_SOCKETS
2845 else if (EQ (tem
, Qlocal
))
2850 error ("Unknown address family");
2851 ai
.ai_family
= family
;
2853 /* :service SERVICE -- string, integer (port number), or t (random port). */
2854 service
= Fplist_get (contact
, QCservice
);
2856 #ifdef HAVE_LOCAL_SOCKETS
2857 if (family
== AF_LOCAL
)
2859 /* Host is not used. */
2861 CHECK_STRING (service
);
2862 bzero (&address_un
, sizeof address_un
);
2863 address_un
.sun_family
= AF_LOCAL
;
2864 strncpy (address_un
.sun_path
, SDATA (service
), sizeof address_un
.sun_path
);
2865 ai
.ai_addr
= (struct sockaddr
*) &address_un
;
2866 ai
.ai_addrlen
= sizeof address_un
;
2871 /* :host HOST -- hostname, ip address, or 'local for localhost. */
2872 host
= Fplist_get (contact
, QChost
);
2875 if (EQ (host
, Qlocal
))
2876 host
= build_string ("localhost");
2877 CHECK_STRING (host
);
2880 /* Slow down polling to every ten seconds.
2881 Some kernels have a bug which causes retrying connect to fail
2882 after a connect. Polling can interfere with gethostbyname too. */
2883 #ifdef POLL_FOR_INPUT
2884 if (socktype
== SOCK_STREAM
)
2886 record_unwind_protect (unwind_stop_other_atimers
, Qnil
);
2887 bind_polling_period (10);
2891 #ifdef HAVE_GETADDRINFO
2892 /* If we have a host, use getaddrinfo to resolve both host and service.
2893 Otherwise, use getservbyname to lookup the service. */
2897 /* SERVICE can either be a string or int.
2898 Convert to a C string for later use by getaddrinfo. */
2899 if (EQ (service
, Qt
))
2901 else if (INTEGERP (service
))
2903 sprintf (portbuf
, "%ld", (long) XINT (service
));
2904 portstring
= portbuf
;
2908 CHECK_STRING (service
);
2909 portstring
= SDATA (service
);
2914 memset (&hints
, 0, sizeof (hints
));
2916 hints
.ai_family
= NILP (Fplist_member (contact
, QCfamily
)) ? AF_UNSPEC
: family
;
2917 hints
.ai_socktype
= socktype
;
2918 hints
.ai_protocol
= 0;
2919 ret
= getaddrinfo (SDATA (host
), portstring
, &hints
, &res
);
2921 #ifdef HAVE_GAI_STRERROR
2922 error ("%s/%s %s", SDATA (host
), portstring
, gai_strerror(ret
));
2924 error ("%s/%s getaddrinfo error %d", SDATA (host
), portstring
, ret
);
2930 #endif /* HAVE_GETADDRINFO */
2932 /* We end up here if getaddrinfo is not defined, or in case no hostname
2933 has been specified (e.g. for a local server process). */
2935 if (EQ (service
, Qt
))
2937 else if (INTEGERP (service
))
2938 port
= htons ((unsigned short) XINT (service
));
2941 struct servent
*svc_info
;
2942 CHECK_STRING (service
);
2943 svc_info
= getservbyname (SDATA (service
),
2944 (socktype
== SOCK_DGRAM
? "udp" : "tcp"));
2946 error ("Unknown service: %s", SDATA (service
));
2947 port
= svc_info
->s_port
;
2950 bzero (&address_in
, sizeof address_in
);
2951 address_in
.sin_family
= family
;
2952 address_in
.sin_addr
.s_addr
= INADDR_ANY
;
2953 address_in
.sin_port
= port
;
2955 #ifndef HAVE_GETADDRINFO
2958 struct hostent
*host_info_ptr
;
2960 /* gethostbyname may fail with TRY_AGAIN, but we don't honour that,
2961 as it may `hang' Emacs for a very long time. */
2964 host_info_ptr
= gethostbyname (SDATA (host
));
2969 bcopy (host_info_ptr
->h_addr
, (char *) &address_in
.sin_addr
,
2970 host_info_ptr
->h_length
);
2971 family
= host_info_ptr
->h_addrtype
;
2972 address_in
.sin_family
= family
;
2975 /* Attempt to interpret host as numeric inet address */
2977 IN_ADDR numeric_addr
;
2978 numeric_addr
= inet_addr ((char *) SDATA (host
));
2979 if (NUMERIC_ADDR_ERROR
)
2980 error ("Unknown host \"%s\"", SDATA (host
));
2982 bcopy ((char *)&numeric_addr
, (char *) &address_in
.sin_addr
,
2983 sizeof (address_in
.sin_addr
));
2987 #endif /* not HAVE_GETADDRINFO */
2989 ai
.ai_family
= family
;
2990 ai
.ai_addr
= (struct sockaddr
*) &address_in
;
2991 ai
.ai_addrlen
= sizeof address_in
;
2995 /* Kernel bugs (on Ultrix at least) cause lossage (not just EINTR)
2996 when connect is interrupted. So let's not let it get interrupted.
2997 Note we do not turn off polling, because polling is only used
2998 when not interrupt_input, and thus not normally used on the systems
2999 which have this bug. On systems which use polling, there's no way
3000 to quit if polling is turned off. */
3002 && !is_server
&& socktype
== SOCK_STREAM
)
3004 /* Comment from KFS: The original open-network-stream code
3005 didn't unwind protect this, but it seems like the proper
3006 thing to do. In any case, I don't see how it could harm to
3007 do this -- and it makes cleanup (using unbind_to) easier. */
3008 record_unwind_protect (unwind_request_sigio
, Qnil
);
3012 /* Do this in case we never enter the for-loop below. */
3013 count1
= SPECPDL_INDEX ();
3016 for (lres
= res
; lres
; lres
= lres
->ai_next
)
3020 s
= socket (lres
->ai_family
, lres
->ai_socktype
, lres
->ai_protocol
);
3027 #ifdef DATAGRAM_SOCKETS
3028 if (!is_server
&& socktype
== SOCK_DGRAM
)
3030 #endif /* DATAGRAM_SOCKETS */
3032 #ifdef NON_BLOCKING_CONNECT
3033 if (is_non_blocking_client
)
3036 ret
= fcntl (s
, F_SETFL
, O_NONBLOCK
);
3038 ret
= fcntl (s
, F_SETFL
, O_NDELAY
);
3050 /* Make us close S if quit. */
3051 record_unwind_protect (close_file_unwind
, make_number (s
));
3053 /* Parse network options in the arg list.
3054 We simply ignore anything which isn't a known option (including other keywords).
3055 An error is signalled if setting a known option fails. */
3056 for (optn
= optbits
= 0; optn
< nargs
-1; optn
+= 2)
3057 optbits
|= set_socket_option (s
, args
[optn
], args
[optn
+1]);
3061 /* Configure as a server socket. */
3063 /* SO_REUSEADDR = 1 is default for server sockets; must specify
3064 explicit :reuseaddr key to override this. */
3065 #ifdef HAVE_LOCAL_SOCKETS
3066 if (family
!= AF_LOCAL
)
3068 if (!(optbits
& (1 << OPIX_REUSEADDR
)))
3071 if (setsockopt (s
, SOL_SOCKET
, SO_REUSEADDR
, &optval
, sizeof optval
))
3072 report_file_error ("Cannot set reuse option on server socket", Qnil
);
3075 if (bind (s
, lres
->ai_addr
, lres
->ai_addrlen
))
3076 report_file_error ("Cannot bind server socket", Qnil
);
3078 #ifdef HAVE_GETSOCKNAME
3079 if (EQ (service
, Qt
))
3081 struct sockaddr_in sa1
;
3082 int len1
= sizeof (sa1
);
3083 if (getsockname (s
, (struct sockaddr
*)&sa1
, &len1
) == 0)
3085 ((struct sockaddr_in
*)(lres
->ai_addr
))->sin_port
= sa1
.sin_port
;
3086 service
= make_number (ntohs (sa1
.sin_port
));
3087 contact
= Fplist_put (contact
, QCservice
, service
);
3092 if (socktype
== SOCK_STREAM
&& listen (s
, backlog
))
3093 report_file_error ("Cannot listen on server socket", Qnil
);
3103 /* This turns off all alarm-based interrupts; the
3104 bind_polling_period call above doesn't always turn all the
3105 short-interval ones off, especially if interrupt_input is
3108 It'd be nice to be able to control the connect timeout
3109 though. Would non-blocking connect calls be portable?
3111 This used to be conditioned by HAVE_GETADDRINFO. Why? */
3113 turn_on_atimers (0);
3115 ret
= connect (s
, lres
->ai_addr
, lres
->ai_addrlen
);
3118 turn_on_atimers (1);
3120 if (ret
== 0 || xerrno
== EISCONN
)
3122 /* The unwind-protect will be discarded afterwards.
3123 Likewise for immediate_quit. */
3127 #ifdef NON_BLOCKING_CONNECT
3129 if (is_non_blocking_client
&& xerrno
== EINPROGRESS
)
3133 if (is_non_blocking_client
&& xerrno
== EWOULDBLOCK
)
3141 if (xerrno
== EINTR
)
3143 if (xerrno
== EADDRINUSE
&& retry
< 20)
3145 /* A delay here is needed on some FreeBSD systems,
3146 and it is harmless, since this retrying takes time anyway
3147 and should be infrequent. */
3148 Fsleep_for (make_number (1), Qnil
);
3153 /* Discard the unwind protect closing S. */
3154 specpdl_ptr
= specpdl
+ count1
;
3161 #ifdef DATAGRAM_SOCKETS
3162 if (socktype
== SOCK_DGRAM
)
3164 if (datagram_address
[s
].sa
)
3166 datagram_address
[s
].sa
= (struct sockaddr
*) xmalloc (lres
->ai_addrlen
);
3167 datagram_address
[s
].len
= lres
->ai_addrlen
;
3171 bzero (datagram_address
[s
].sa
, lres
->ai_addrlen
);
3172 if (remote
= Fplist_get (contact
, QCremote
), !NILP (remote
))
3175 rlen
= get_lisp_to_sockaddr_size (remote
, &rfamily
);
3176 if (rfamily
== lres
->ai_family
&& rlen
== lres
->ai_addrlen
)
3177 conv_lisp_to_sockaddr (rfamily
, remote
,
3178 datagram_address
[s
].sa
, rlen
);
3182 bcopy (lres
->ai_addr
, datagram_address
[s
].sa
, lres
->ai_addrlen
);
3185 contact
= Fplist_put (contact
, QCaddress
,
3186 conv_sockaddr_to_lisp (lres
->ai_addr
, lres
->ai_addrlen
));
3187 #ifdef HAVE_GETSOCKNAME
3190 struct sockaddr_in sa1
;
3191 int len1
= sizeof (sa1
);
3192 if (getsockname (s
, (struct sockaddr
*)&sa1
, &len1
) == 0)
3193 contact
= Fplist_put (contact
, QClocal
,
3194 conv_sockaddr_to_lisp (&sa1
, len1
));
3199 #ifdef HAVE_GETADDRINFO
3206 /* Discard the unwind protect for closing S, if any. */
3207 specpdl_ptr
= specpdl
+ count1
;
3209 /* Unwind bind_polling_period and request_sigio. */
3210 unbind_to (count
, Qnil
);
3214 /* If non-blocking got this far - and failed - assume non-blocking is
3215 not supported after all. This is probably a wrong assumption, but
3216 the normal blocking calls to open-network-stream handles this error
3218 if (is_non_blocking_client
)
3223 report_file_error ("make server process failed", contact
);
3225 report_file_error ("make client process failed", contact
);
3228 #endif /* not TERM */
3234 buffer
= Fget_buffer_create (buffer
);
3235 proc
= make_process (name
);
3237 chan_process
[inch
] = proc
;
3240 fcntl (inch
, F_SETFL
, O_NONBLOCK
);
3243 fcntl (inch
, F_SETFL
, O_NDELAY
);
3247 p
= XPROCESS (proc
);
3249 p
->childp
= contact
;
3250 p
->plist
= Fcopy_sequence (Fplist_get (contact
, QCplist
));
3253 p
->sentinel
= sentinel
;
3255 p
->filter_multibyte
= buffer_defaults
.enable_multibyte_characters
;
3256 /* Override the above only if :filter-multibyte is specified. */
3257 if (! NILP (Fplist_member (contact
, QCfilter_multibyte
)))
3258 p
->filter_multibyte
= Fplist_get (contact
, QCfilter_multibyte
);
3259 p
->log
= Fplist_get (contact
, QClog
);
3260 if (tem
= Fplist_get (contact
, QCnoquery
), !NILP (tem
))
3261 p
->kill_without_query
= Qt
;
3262 if ((tem
= Fplist_get (contact
, QCstop
), !NILP (tem
)))
3265 XSETINT (p
->infd
, inch
);
3266 XSETINT (p
->outfd
, outch
);
3267 if (is_server
&& socktype
== SOCK_STREAM
)
3268 p
->status
= Qlisten
;
3270 #ifdef NON_BLOCKING_CONNECT
3271 if (is_non_blocking_client
)
3273 /* We may get here if connect did succeed immediately. However,
3274 in that case, we still need to signal this like a non-blocking
3276 p
->status
= Qconnect
;
3277 if (!FD_ISSET (inch
, &connect_wait_mask
))
3279 FD_SET (inch
, &connect_wait_mask
);
3280 num_pending_connects
++;
3285 /* A server may have a client filter setting of Qt, but it must
3286 still listen for incoming connects unless it is stopped. */
3287 if ((!EQ (p
->filter
, Qt
) && !EQ (p
->command
, Qt
))
3288 || (EQ (p
->status
, Qlisten
) && NILP (p
->command
)))
3290 FD_SET (inch
, &input_wait_mask
);
3291 FD_SET (inch
, &non_keyboard_wait_mask
);
3294 if (inch
> max_process_desc
)
3295 max_process_desc
= inch
;
3297 tem
= Fplist_member (contact
, QCcoding
);
3298 if (!NILP (tem
) && (!CONSP (tem
) || !CONSP (XCDR (tem
))))
3299 tem
= Qnil
; /* No error message (too late!). */
3302 /* Setup coding systems for communicating with the network stream. */
3303 struct gcpro gcpro1
;
3304 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
3305 Lisp_Object coding_systems
= Qt
;
3306 Lisp_Object args
[5], val
;
3310 val
= XCAR (XCDR (tem
));
3314 else if (!NILP (Vcoding_system_for_read
))
3315 val
= Vcoding_system_for_read
;
3316 else if ((!NILP (buffer
) && NILP (XBUFFER (buffer
)->enable_multibyte_characters
))
3317 || (NILP (buffer
) && NILP (buffer_defaults
.enable_multibyte_characters
)))
3318 /* We dare not decode end-of-line format by setting VAL to
3319 Qraw_text, because the existing Emacs Lisp libraries
3320 assume that they receive bare code including a sequene of
3325 if (NILP (host
) || NILP (service
))
3326 coding_systems
= Qnil
;
3329 args
[0] = Qopen_network_stream
, args
[1] = name
,
3330 args
[2] = buffer
, args
[3] = host
, args
[4] = service
;
3332 coding_systems
= Ffind_operation_coding_system (5, args
);
3335 if (CONSP (coding_systems
))
3336 val
= XCAR (coding_systems
);
3337 else if (CONSP (Vdefault_process_coding_system
))
3338 val
= XCAR (Vdefault_process_coding_system
);
3342 p
->decode_coding_system
= val
;
3346 val
= XCAR (XCDR (tem
));
3350 else if (!NILP (Vcoding_system_for_write
))
3351 val
= Vcoding_system_for_write
;
3352 else if (NILP (current_buffer
->enable_multibyte_characters
))
3356 if (EQ (coding_systems
, Qt
))
3358 if (NILP (host
) || NILP (service
))
3359 coding_systems
= Qnil
;
3362 args
[0] = Qopen_network_stream
, args
[1] = name
,
3363 args
[2] = buffer
, args
[3] = host
, args
[4] = service
;
3365 coding_systems
= Ffind_operation_coding_system (5, args
);
3369 if (CONSP (coding_systems
))
3370 val
= XCDR (coding_systems
);
3371 else if (CONSP (Vdefault_process_coding_system
))
3372 val
= XCDR (Vdefault_process_coding_system
);
3376 p
->encode_coding_system
= val
;
3378 setup_process_coding_systems (proc
);
3380 p
->decoding_buf
= make_uninit_string (0);
3381 p
->decoding_carryover
= make_number (0);
3382 p
->encoding_buf
= make_uninit_string (0);
3383 p
->encoding_carryover
= make_number (0);
3385 p
->inherit_coding_system_flag
3386 = (!NILP (tem
) || NILP (buffer
) || !inherit_process_coding_system
3392 #endif /* HAVE_SOCKETS */
3395 #if defined(HAVE_SOCKETS) && defined(HAVE_NET_IF_H) && defined(HAVE_SYS_IOCTL_H)
3398 DEFUN ("network-interface-list", Fnetwork_interface_list
, Snetwork_interface_list
, 0, 0, 0,
3399 doc
: /* Return an alist of all network interfaces and their network address.
3400 Each element is a cons, the car of which is a string containing the
3401 interface name, and the cdr is the network address in internal
3402 format; see the description of ADDRESS in `make-network-process'. */)
3405 struct ifconf ifconf
;
3406 struct ifreq
*ifreqs
= NULL
;
3411 s
= socket (AF_INET
, SOCK_STREAM
, 0);
3417 buf_size
= ifaces
* sizeof(ifreqs
[0]);
3418 ifreqs
= (struct ifreq
*)xrealloc(ifreqs
, buf_size
);
3425 ifconf
.ifc_len
= buf_size
;
3426 ifconf
.ifc_req
= ifreqs
;
3427 if (ioctl (s
, SIOCGIFCONF
, &ifconf
))
3433 if (ifconf
.ifc_len
== buf_size
)
3437 ifaces
= ifconf
.ifc_len
/ sizeof (ifreqs
[0]);
3440 while (--ifaces
>= 0)
3442 struct ifreq
*ifq
= &ifreqs
[ifaces
];
3443 char namebuf
[sizeof (ifq
->ifr_name
) + 1];
3444 if (ifq
->ifr_addr
.sa_family
!= AF_INET
)
3446 bcopy (ifq
->ifr_name
, namebuf
, sizeof (ifq
->ifr_name
));
3447 namebuf
[sizeof (ifq
->ifr_name
)] = 0;
3448 res
= Fcons (Fcons (build_string (namebuf
),
3449 conv_sockaddr_to_lisp (&ifq
->ifr_addr
,
3450 sizeof (struct sockaddr
))),
3456 #endif /* SIOCGIFCONF */
3458 #if defined(SIOCGIFADDR) || defined(SIOCGIFHWADDR) || defined(SIOCGIFFLAGS)
3465 static struct ifflag_def ifflag_table
[] = {
3469 #ifdef IFF_BROADCAST
3470 { IFF_BROADCAST
, "broadcast" },
3473 { IFF_DEBUG
, "debug" },
3476 { IFF_LOOPBACK
, "loopback" },
3478 #ifdef IFF_POINTOPOINT
3479 { IFF_POINTOPOINT
, "pointopoint" },
3482 { IFF_RUNNING
, "running" },
3485 { IFF_NOARP
, "noarp" },
3488 { IFF_PROMISC
, "promisc" },
3490 #ifdef IFF_NOTRAILERS
3491 { IFF_NOTRAILERS
, "notrailers" },
3494 { IFF_ALLMULTI
, "allmulti" },
3497 { IFF_MASTER
, "master" },
3500 { IFF_SLAVE
, "slave" },
3502 #ifdef IFF_MULTICAST
3503 { IFF_MULTICAST
, "multicast" },
3506 { IFF_PORTSEL
, "portsel" },
3508 #ifdef IFF_AUTOMEDIA
3509 { IFF_AUTOMEDIA
, "automedia" },
3512 { IFF_DYNAMIC
, "dynamic" },
3517 DEFUN ("network-interface-info", Fnetwork_interface_info
, Snetwork_interface_info
, 1, 1, 0,
3518 doc
: /* Return information about network interface named IFNAME.
3519 The return value is a list (ADDR BCAST NETMASK HWADDR FLAGS),
3520 where ADDR is the layer 3 address, BCAST is the layer 3 broadcast address,
3521 NETMASK is the layer 3 network mask, HWADDR is the layer 2 addres, and
3522 FLAGS is the current flags of the interface. */)
3527 Lisp_Object res
= Qnil
;
3532 CHECK_STRING (ifname
);
3534 bzero (rq
.ifr_name
, sizeof rq
.ifr_name
);
3535 strncpy (rq
.ifr_name
, SDATA (ifname
), sizeof (rq
.ifr_name
));
3537 s
= socket (AF_INET
, SOCK_STREAM
, 0);
3542 #if defined(SIOCGIFFLAGS) && defined(HAVE_STRUCT_IFREQ_IFR_FLAGS)
3543 if (ioctl (s
, SIOCGIFFLAGS
, &rq
) == 0)
3545 int flags
= rq
.ifr_flags
;
3546 struct ifflag_def
*fp
;
3550 for (fp
= ifflag_table
; flags
!= 0 && fp
; fp
++)
3552 if (flags
& fp
->flag_bit
)
3554 elt
= Fcons (intern (fp
->flag_sym
), elt
);
3555 flags
-= fp
->flag_bit
;
3558 for (fnum
= 0; flags
&& fnum
< 32; fnum
++)
3560 if (flags
& (1 << fnum
))
3562 elt
= Fcons (make_number (fnum
), elt
);
3567 res
= Fcons (elt
, res
);
3570 #if defined(SIOCGIFHWADDR) && defined(HAVE_STRUCT_IFREQ_IFR_HWADDR)
3571 if (ioctl (s
, SIOCGIFHWADDR
, &rq
) == 0)
3573 Lisp_Object hwaddr
= Fmake_vector (make_number (6), Qnil
);
3574 register struct Lisp_Vector
*p
= XVECTOR (hwaddr
);
3578 for (n
= 0; n
< 6; n
++)
3579 p
->contents
[n
] = make_number (((unsigned char *)&rq
.ifr_hwaddr
.sa_data
[0])[n
]);
3580 elt
= Fcons (make_number (rq
.ifr_hwaddr
.sa_family
), hwaddr
);
3583 res
= Fcons (elt
, res
);
3586 #if defined(SIOCGIFNETMASK) && defined(ifr_netmask)
3587 if (ioctl (s
, SIOCGIFNETMASK
, &rq
) == 0)
3590 elt
= conv_sockaddr_to_lisp (&rq
.ifr_netmask
, sizeof (rq
.ifr_netmask
));
3593 res
= Fcons (elt
, res
);
3596 #if defined(SIOCGIFBRDADDR) && defined(HAVE_STRUCT_IFREQ_IFR_BROADADDR)
3597 if (ioctl (s
, SIOCGIFBRDADDR
, &rq
) == 0)
3600 elt
= conv_sockaddr_to_lisp (&rq
.ifr_broadaddr
, sizeof (rq
.ifr_broadaddr
));
3603 res
= Fcons (elt
, res
);
3606 #if defined(SIOCGIFADDR) && defined(HAVE_STRUCT_IFREQ_IFR_ADDR)
3607 if (ioctl (s
, SIOCGIFADDR
, &rq
) == 0)
3610 elt
= conv_sockaddr_to_lisp (&rq
.ifr_addr
, sizeof (rq
.ifr_addr
));
3613 res
= Fcons (elt
, res
);
3617 return any
? res
: Qnil
;
3620 #endif /* HAVE_SOCKETS */
3622 /* Turn off input and output for process PROC. */
3625 deactivate_process (proc
)
3628 register int inchannel
, outchannel
;
3629 register struct Lisp_Process
*p
= XPROCESS (proc
);
3631 inchannel
= XINT (p
->infd
);
3632 outchannel
= XINT (p
->outfd
);
3634 #ifdef ADAPTIVE_READ_BUFFERING
3635 if (XINT (p
->read_output_delay
) > 0)
3637 if (--process_output_delay_count
< 0)
3638 process_output_delay_count
= 0;
3639 XSETINT (p
->read_output_delay
, 0);
3640 p
->read_output_skip
= Qnil
;
3646 /* Beware SIGCHLD hereabouts. */
3647 flush_pending_output (inchannel
);
3650 VMS_PROC_STUFF
*get_vms_process_pointer (), *vs
;
3651 sys$
dassgn (outchannel
);
3652 vs
= get_vms_process_pointer (p
->pid
);
3654 give_back_vms_process_stuff (vs
);
3657 emacs_close (inchannel
);
3658 if (outchannel
>= 0 && outchannel
!= inchannel
)
3659 emacs_close (outchannel
);
3662 XSETINT (p
->infd
, -1);
3663 XSETINT (p
->outfd
, -1);
3664 #ifdef DATAGRAM_SOCKETS
3665 if (DATAGRAM_CHAN_P (inchannel
))
3667 xfree (datagram_address
[inchannel
].sa
);
3668 datagram_address
[inchannel
].sa
= 0;
3669 datagram_address
[inchannel
].len
= 0;
3672 chan_process
[inchannel
] = Qnil
;
3673 FD_CLR (inchannel
, &input_wait_mask
);
3674 FD_CLR (inchannel
, &non_keyboard_wait_mask
);
3675 if (FD_ISSET (inchannel
, &connect_wait_mask
))
3677 FD_CLR (inchannel
, &connect_wait_mask
);
3678 if (--num_pending_connects
< 0)
3681 if (inchannel
== max_process_desc
)
3684 /* We just closed the highest-numbered process input descriptor,
3685 so recompute the highest-numbered one now. */
3686 max_process_desc
= 0;
3687 for (i
= 0; i
< MAXDESC
; i
++)
3688 if (!NILP (chan_process
[i
]))
3689 max_process_desc
= i
;
3694 /* Close all descriptors currently in use for communication
3695 with subprocess. This is used in a newly-forked subprocess
3696 to get rid of irrelevant descriptors. */
3699 close_process_descs ()
3703 for (i
= 0; i
< MAXDESC
; i
++)
3705 Lisp_Object process
;
3706 process
= chan_process
[i
];
3707 if (!NILP (process
))
3709 int in
= XINT (XPROCESS (process
)->infd
);
3710 int out
= XINT (XPROCESS (process
)->outfd
);
3713 if (out
>= 0 && in
!= out
)
3720 DEFUN ("accept-process-output", Faccept_process_output
, Saccept_process_output
,
3722 doc
: /* Allow any pending output from subprocesses to be read by Emacs.
3723 It is read into the process' buffers or given to their filter functions.
3724 Non-nil arg PROCESS means do not return until some output has been received
3726 Non-nil second arg TIMEOUT and third arg TIMEOUT-MSECS are number of
3727 seconds and microseconds to wait; return after that much time whether
3728 or not there is input.
3729 If optional fourth arg JUST-THIS-ONE is non-nil, only accept output
3730 from PROCESS, suspending reading output from other processes.
3731 If JUST-THIS-ONE is an integer, don't run any timers either.
3732 Return non-nil iff we received any output before the timeout expired. */)
3733 (process
, timeout
, timeout_msecs
, just_this_one
)
3734 register Lisp_Object process
, timeout
, timeout_msecs
, just_this_one
;
3739 if (! NILP (process
))
3740 CHECK_PROCESS (process
);
3742 just_this_one
= Qnil
;
3744 if (! NILP (timeout_msecs
))
3746 CHECK_NUMBER (timeout_msecs
);
3747 useconds
= XINT (timeout_msecs
);
3748 if (!INTEGERP (timeout
))
3749 XSETINT (timeout
, 0);
3752 int carry
= useconds
/ 1000000;
3754 XSETINT (timeout
, XINT (timeout
) + carry
);
3755 useconds
-= carry
* 1000000;
3757 /* I think this clause is necessary because C doesn't
3758 guarantee a particular rounding direction for negative
3762 XSETINT (timeout
, XINT (timeout
) - 1);
3763 useconds
+= 1000000;
3770 if (! NILP (timeout
))
3772 CHECK_NUMBER (timeout
);
3773 seconds
= XINT (timeout
);
3774 if (seconds
< 0 || (seconds
== 0 && useconds
== 0))
3778 seconds
= NILP (process
) ? -1 : 0;
3781 XSETFASTINT (process
, 0);
3784 (wait_reading_process_input (seconds
, useconds
, process
,
3785 NILP (just_this_one
) ? 0 :
3786 !INTEGERP (just_this_one
) ? -1 : -2)
3790 /* Accept a connection for server process SERVER on CHANNEL. */
3792 static int connect_counter
= 0;
3795 server_accept_connection (server
, channel
)
3799 Lisp_Object proc
, caller
, name
, buffer
;
3800 Lisp_Object contact
, host
, service
;
3801 struct Lisp_Process
*ps
= XPROCESS (server
);
3802 struct Lisp_Process
*p
;
3806 struct sockaddr_in in
;
3807 #ifdef HAVE_LOCAL_SOCKETS
3808 struct sockaddr_un un
;
3811 int len
= sizeof saddr
;
3813 s
= accept (channel
, &saddr
.sa
, &len
);
3822 if (code
== EWOULDBLOCK
)
3826 if (!NILP (ps
->log
))
3827 call3 (ps
->log
, server
, Qnil
,
3828 concat3 (build_string ("accept failed with code"),
3829 Fnumber_to_string (make_number (code
)),
3830 build_string ("\n")));
3836 /* Setup a new process to handle the connection. */
3838 /* Generate a unique identification of the caller, and build contact
3839 information for this process. */
3842 switch (saddr
.sa
.sa_family
)
3846 Lisp_Object args
[5];
3847 unsigned char *ip
= (unsigned char *)&saddr
.in
.sin_addr
.s_addr
;
3848 args
[0] = build_string ("%d.%d.%d.%d");
3849 args
[1] = make_number (*ip
++);
3850 args
[2] = make_number (*ip
++);
3851 args
[3] = make_number (*ip
++);
3852 args
[4] = make_number (*ip
++);
3853 host
= Fformat (5, args
);
3854 service
= make_number (ntohs (saddr
.in
.sin_port
));
3856 args
[0] = build_string (" <%s:%d>");
3859 caller
= Fformat (3, args
);
3863 #ifdef HAVE_LOCAL_SOCKETS
3867 caller
= Fnumber_to_string (make_number (connect_counter
));
3868 caller
= concat3 (build_string (" <*"), caller
, build_string ("*>"));
3872 /* Create a new buffer name for this process if it doesn't have a
3873 filter. The new buffer name is based on the buffer name or
3874 process name of the server process concatenated with the caller
3877 if (!NILP (ps
->filter
) && !EQ (ps
->filter
, Qt
))
3881 buffer
= ps
->buffer
;
3883 buffer
= Fbuffer_name (buffer
);
3888 buffer
= concat2 (buffer
, caller
);
3889 buffer
= Fget_buffer_create (buffer
);
3893 /* Generate a unique name for the new server process. Combine the
3894 server process name with the caller identification. */
3896 name
= concat2 (ps
->name
, caller
);
3897 proc
= make_process (name
);
3899 chan_process
[s
] = proc
;
3902 fcntl (s
, F_SETFL
, O_NONBLOCK
);
3905 fcntl (s
, F_SETFL
, O_NDELAY
);
3909 p
= XPROCESS (proc
);
3911 /* Build new contact information for this setup. */
3912 contact
= Fcopy_sequence (ps
->childp
);
3913 contact
= Fplist_put (contact
, QCserver
, Qnil
);
3914 contact
= Fplist_put (contact
, QChost
, host
);
3915 if (!NILP (service
))
3916 contact
= Fplist_put (contact
, QCservice
, service
);
3917 contact
= Fplist_put (contact
, QCremote
,
3918 conv_sockaddr_to_lisp (&saddr
.sa
, len
));
3919 #ifdef HAVE_GETSOCKNAME
3921 if (getsockname (s
, &saddr
.sa
, &len
) == 0)
3922 contact
= Fplist_put (contact
, QClocal
,
3923 conv_sockaddr_to_lisp (&saddr
.sa
, len
));
3926 p
->childp
= contact
;
3927 p
->plist
= Fcopy_sequence (ps
->plist
);
3930 p
->sentinel
= ps
->sentinel
;
3931 p
->filter
= ps
->filter
;
3934 XSETINT (p
->infd
, s
);
3935 XSETINT (p
->outfd
, s
);
3938 /* Client processes for accepted connections are not stopped initially. */
3939 if (!EQ (p
->filter
, Qt
))
3941 FD_SET (s
, &input_wait_mask
);
3942 FD_SET (s
, &non_keyboard_wait_mask
);
3945 if (s
> max_process_desc
)
3946 max_process_desc
= s
;
3948 /* Setup coding system for new process based on server process.
3949 This seems to be the proper thing to do, as the coding system
3950 of the new process should reflect the settings at the time the
3951 server socket was opened; not the current settings. */
3953 p
->decode_coding_system
= ps
->decode_coding_system
;
3954 p
->encode_coding_system
= ps
->encode_coding_system
;
3955 setup_process_coding_systems (proc
);
3957 p
->decoding_buf
= make_uninit_string (0);
3958 p
->decoding_carryover
= make_number (0);
3959 p
->encoding_buf
= make_uninit_string (0);
3960 p
->encoding_carryover
= make_number (0);
3962 p
->inherit_coding_system_flag
3963 = (NILP (buffer
) ? Qnil
: ps
->inherit_coding_system_flag
);
3965 if (!NILP (ps
->log
))
3966 call3 (ps
->log
, server
, proc
,
3967 concat3 (build_string ("accept from "),
3968 (STRINGP (host
) ? host
: build_string ("-")),
3969 build_string ("\n")));
3971 if (!NILP (p
->sentinel
))
3972 exec_sentinel (proc
,
3973 concat3 (build_string ("open from "),
3974 (STRINGP (host
) ? host
: build_string ("-")),
3975 build_string ("\n")));
3978 /* This variable is different from waiting_for_input in keyboard.c.
3979 It is used to communicate to a lisp process-filter/sentinel (via the
3980 function Fwaiting_for_user_input_p below) whether Emacs was waiting
3981 for user-input when that process-filter was called.
3982 waiting_for_input cannot be used as that is by definition 0 when
3983 lisp code is being evalled.
3984 This is also used in record_asynch_buffer_change.
3985 For that purpose, this must be 0
3986 when not inside wait_reading_process_input. */
3987 static int waiting_for_user_input_p
;
3989 /* This is here so breakpoints can be put on it. */
3991 wait_reading_process_input_1 ()
3995 /* Read and dispose of subprocess output while waiting for timeout to
3996 elapse and/or keyboard input to be available.
3999 timeout in seconds, or
4000 zero for no limit, or
4001 -1 means gobble data immediately available but don't wait for any.
4004 an additional duration to wait, measured in microseconds.
4005 If this is nonzero and time_limit is 0, then the timeout
4006 consists of MICROSECS only.
4008 READ_KBD is a lisp value:
4009 0 to ignore keyboard input, or
4010 1 to return when input is available, or
4011 -1 meaning caller will actually read the input, so don't throw to
4012 the quit handler, or
4013 a cons cell, meaning wait until its car is non-nil
4014 (and gobble terminal input into the buffer if any arrives), or
4015 a process object, meaning wait until something arrives from that
4016 process. The return value is true iff we read some input from
4019 If READ_KBD is a process object, DO_DISPLAY < 0 means handle only
4020 output from that process (suspending output from other processes)
4021 and DO_DISPLAY == -2 specifically means don't run any timers either.
4022 Otherwise, != 0 means redisplay should be done to show subprocess
4023 output that arrives.
4025 If READ_KBD is a pointer to a struct Lisp_Process, then the
4026 function returns true iff we received input from that process
4027 before the timeout elapsed.
4028 Otherwise, return true iff we received input from any process. */
4031 wait_reading_process_input (time_limit
, microsecs
, read_kbd
, do_display
)
4032 int time_limit
, microsecs
;
4033 Lisp_Object read_kbd
;
4036 register int channel
, nfds
;
4037 SELECT_TYPE Available
;
4038 SELECT_TYPE Connecting
;
4039 int check_connect
, check_delay
, no_avail
;
4042 EMACS_TIME timeout
, end_time
;
4043 int wait_channel
= -1;
4044 struct Lisp_Process
*wait_proc
= 0;
4045 int just_wait_proc
= 0;
4046 int got_some_input
= 0;
4047 /* Either nil or a cons cell, the car of which is of interest and
4048 may be changed outside of this routine. */
4049 Lisp_Object wait_for_cell
= Qnil
;
4050 int saved_waiting_for_user_input_p
= waiting_for_user_input_p
;
4052 FD_ZERO (&Available
);
4053 FD_ZERO (&Connecting
);
4055 /* If read_kbd is a process to watch, set wait_proc and wait_channel
4057 if (PROCESSP (read_kbd
))
4059 wait_proc
= XPROCESS (read_kbd
);
4060 wait_channel
= XINT (wait_proc
->infd
);
4061 XSETFASTINT (read_kbd
, 0);
4064 just_wait_proc
= do_display
;
4069 /* If waiting for non-nil in a cell, record where. */
4070 if (CONSP (read_kbd
))
4072 wait_for_cell
= read_kbd
;
4073 XSETFASTINT (read_kbd
, 0);
4076 waiting_for_user_input_p
= XINT (read_kbd
);
4078 /* Since we may need to wait several times,
4079 compute the absolute time to return at. */
4080 if (time_limit
|| microsecs
)
4082 EMACS_GET_TIME (end_time
);
4083 EMACS_SET_SECS_USECS (timeout
, time_limit
, microsecs
);
4084 EMACS_ADD_TIME (end_time
, end_time
, timeout
);
4086 #ifdef POLL_INTERRUPTED_SYS_CALL
4087 /* AlainF 5-Jul-1996
4088 HP-UX 10.10 seem to have problems with signals coming in
4089 Causes "poll: interrupted system call" messages when Emacs is run
4091 Turn off periodic alarms (in case they are in use),
4092 and then turn off any other atimers. */
4094 turn_on_atimers (0);
4095 #endif /* POLL_INTERRUPTED_SYS_CALL */
4099 int timeout_reduced_for_timers
= 0;
4101 /* If calling from keyboard input, do not quit
4102 since we want to return C-g as an input character.
4103 Otherwise, do pending quit if requested. */
4104 if (XINT (read_kbd
) >= 0)
4107 else if (interrupt_input_pending
)
4108 handle_async_input ();
4111 /* Exit now if the cell we're waiting for became non-nil. */
4112 if (! NILP (wait_for_cell
) && ! NILP (XCAR (wait_for_cell
)))
4115 /* Compute time from now till when time limit is up */
4116 /* Exit if already run out */
4117 if (time_limit
== -1)
4119 /* -1 specified for timeout means
4120 gobble output available now
4121 but don't wait at all. */
4123 EMACS_SET_SECS_USECS (timeout
, 0, 0);
4125 else if (time_limit
|| microsecs
)
4127 EMACS_GET_TIME (timeout
);
4128 EMACS_SUB_TIME (timeout
, end_time
, timeout
);
4129 if (EMACS_TIME_NEG_P (timeout
))
4134 EMACS_SET_SECS_USECS (timeout
, 100000, 0);
4137 /* Normally we run timers here.
4138 But not if wait_for_cell; in those cases,
4139 the wait is supposed to be short,
4140 and those callers cannot handle running arbitrary Lisp code here. */
4141 if (NILP (wait_for_cell
)
4142 && just_wait_proc
!= -2)
4144 EMACS_TIME timer_delay
;
4148 int old_timers_run
= timers_run
;
4149 struct buffer
*old_buffer
= current_buffer
;
4151 timer_delay
= timer_check (1);
4153 /* If a timer has run, this might have changed buffers
4154 an alike. Make read_key_sequence aware of that. */
4155 if (timers_run
!= old_timers_run
4156 && old_buffer
!= current_buffer
4157 && waiting_for_user_input_p
== -1)
4158 record_asynch_buffer_change ();
4160 if (timers_run
!= old_timers_run
&& do_display
)
4161 /* We must retry, since a timer may have requeued itself
4162 and that could alter the time_delay. */
4163 redisplay_preserve_echo_area (9);
4167 while (!detect_input_pending ());
4169 /* If there is unread keyboard input, also return. */
4170 if (XINT (read_kbd
) != 0
4171 && requeued_events_pending_p ())
4174 if (! EMACS_TIME_NEG_P (timer_delay
) && time_limit
!= -1)
4176 EMACS_TIME difference
;
4177 EMACS_SUB_TIME (difference
, timer_delay
, timeout
);
4178 if (EMACS_TIME_NEG_P (difference
))
4180 timeout
= timer_delay
;
4181 timeout_reduced_for_timers
= 1;
4184 /* If time_limit is -1, we are not going to wait at all. */
4185 else if (time_limit
!= -1)
4187 /* This is so a breakpoint can be put here. */
4188 wait_reading_process_input_1 ();
4192 /* Cause C-g and alarm signals to take immediate action,
4193 and cause input available signals to zero out timeout.
4195 It is important that we do this before checking for process
4196 activity. If we get a SIGCHLD after the explicit checks for
4197 process activity, timeout is the only way we will know. */
4198 if (XINT (read_kbd
) < 0)
4199 set_waiting_for_input (&timeout
);
4201 /* If status of something has changed, and no input is
4202 available, notify the user of the change right away. After
4203 this explicit check, we'll let the SIGCHLD handler zap
4204 timeout to get our attention. */
4205 if (update_tick
!= process_tick
&& do_display
)
4207 SELECT_TYPE Atemp
, Ctemp
;
4209 Atemp
= input_wait_mask
;
4211 /* On Mac OS X 10.0, the SELECT system call always says input is
4212 present (for reading) at stdin, even when none is. This
4213 causes the call to SELECT below to return 1 and
4214 status_notify not to be called. As a result output of
4215 subprocesses are incorrectly discarded.
4219 Ctemp
= connect_wait_mask
;
4220 EMACS_SET_SECS_USECS (timeout
, 0, 0);
4221 if ((select (max (max_process_desc
, max_keyboard_desc
) + 1,
4223 (num_pending_connects
> 0 ? &Ctemp
: (SELECT_TYPE
*)0),
4224 (SELECT_TYPE
*)0, &timeout
)
4227 /* It's okay for us to do this and then continue with
4228 the loop, since timeout has already been zeroed out. */
4229 clear_waiting_for_input ();
4234 /* Don't wait for output from a non-running process. Just
4235 read whatever data has already been received. */
4236 if (wait_proc
!= 0 && !NILP (wait_proc
->raw_status_low
))
4237 update_status (wait_proc
);
4239 && ! EQ (wait_proc
->status
, Qrun
)
4240 && ! EQ (wait_proc
->status
, Qconnect
))
4242 int nread
, total_nread
= 0;
4244 clear_waiting_for_input ();
4245 XSETPROCESS (proc
, wait_proc
);
4247 /* Read data from the process, until we exhaust it. */
4248 while (XINT (wait_proc
->infd
) >= 0)
4250 nread
= read_process_output (proc
, XINT (wait_proc
->infd
));
4256 total_nread
+= nread
;
4258 else if (nread
== -1 && EIO
== errno
)
4262 else if (nread
== -1 && EAGAIN
== errno
)
4266 else if (nread
== -1 && EWOULDBLOCK
== errno
)
4270 if (total_nread
> 0 && do_display
)
4271 redisplay_preserve_echo_area (10);
4276 /* Wait till there is something to do */
4280 FD_SET (XINT (wait_proc
->infd
), &Available
);
4281 check_connect
= check_delay
= 0;
4283 else if (!NILP (wait_for_cell
))
4285 Available
= non_process_wait_mask
;
4286 check_connect
= check_delay
= 0;
4290 if (! XINT (read_kbd
))
4291 Available
= non_keyboard_wait_mask
;
4293 Available
= input_wait_mask
;
4294 check_connect
= (num_pending_connects
> 0);
4295 check_delay
= wait_channel
>= 0 ? 0 : process_output_delay_count
;
4298 /* If frame size has changed or the window is newly mapped,
4299 redisplay now, before we start to wait. There is a race
4300 condition here; if a SIGIO arrives between now and the select
4301 and indicates that a frame is trashed, the select may block
4302 displaying a trashed screen. */
4303 if (frame_garbaged
&& do_display
)
4305 clear_waiting_for_input ();
4306 redisplay_preserve_echo_area (11);
4307 if (XINT (read_kbd
) < 0)
4308 set_waiting_for_input (&timeout
);
4312 if (XINT (read_kbd
) && detect_input_pending ())
4320 Connecting
= connect_wait_mask
;
4322 #ifdef ADAPTIVE_READ_BUFFERING
4323 if (process_output_skip
&& check_delay
> 0)
4325 int usecs
= EMACS_USECS (timeout
);
4326 if (EMACS_SECS (timeout
) > 0 || usecs
> READ_OUTPUT_DELAY_MAX
)
4327 usecs
= READ_OUTPUT_DELAY_MAX
;
4328 for (channel
= 0; check_delay
> 0 && channel
<= max_process_desc
; channel
++)
4330 proc
= chan_process
[channel
];
4333 if (XINT (XPROCESS (proc
)->read_output_delay
) > 0)
4336 if (NILP (XPROCESS (proc
)->read_output_skip
))
4338 FD_CLR (channel
, &Available
);
4339 XPROCESS (proc
)->read_output_skip
= Qnil
;
4340 if (XINT (XPROCESS (proc
)->read_output_delay
) < usecs
)
4341 usecs
= XINT (XPROCESS (proc
)->read_output_delay
);
4344 EMACS_SET_SECS_USECS (timeout
, 0, usecs
);
4345 process_output_skip
= 0;
4349 nfds
= select (max (max_process_desc
, max_keyboard_desc
) + 1,
4351 (check_connect
? &Connecting
: (SELECT_TYPE
*)0),
4352 (SELECT_TYPE
*)0, &timeout
);
4357 /* Make C-g and alarm signals set flags again */
4358 clear_waiting_for_input ();
4360 /* If we woke up due to SIGWINCH, actually change size now. */
4361 do_pending_window_change (0);
4363 if (time_limit
&& nfds
== 0 && ! timeout_reduced_for_timers
)
4364 /* We wanted the full specified time, so return now. */
4368 if (xerrno
== EINTR
)
4371 /* Ultrix select seems to return ENOMEM when it is
4372 interrupted. Treat it just like EINTR. Bleah. Note
4373 that we want to test for the "ultrix" CPP symbol, not
4374 "__ultrix__"; the latter is only defined under GCC, but
4375 not by DEC's bundled CC. -JimB */
4376 else if (xerrno
== ENOMEM
)
4380 /* This happens for no known reason on ALLIANT.
4381 I am guessing that this is the right response. -- RMS. */
4382 else if (xerrno
== EFAULT
)
4385 else if (xerrno
== EBADF
)
4388 /* AIX doesn't handle PTY closure the same way BSD does. On AIX,
4389 the child's closure of the pts gives the parent a SIGHUP, and
4390 the ptc file descriptor is automatically closed,
4391 yielding EBADF here or at select() call above.
4392 So, SIGHUP is ignored (see def of PTY_TTY_NAME_SPRINTF
4393 in m/ibmrt-aix.h), and here we just ignore the select error.
4394 Cleanup occurs c/o status_notify after SIGCLD. */
4395 no_avail
= 1; /* Cannot depend on values returned */
4401 error ("select error: %s", emacs_strerror (xerrno
));
4406 FD_ZERO (&Available
);
4410 #if defined(sun) && !defined(USG5_4)
4411 if (nfds
> 0 && keyboard_bit_set (&Available
)
4413 /* System sometimes fails to deliver SIGIO.
4415 David J. Mackenzie says that Emacs doesn't compile under
4416 Solaris if this code is enabled, thus the USG5_4 in the CPP
4417 conditional. "I haven't noticed any ill effects so far.
4418 If you find a Solaris expert somewhere, they might know
4420 kill (getpid (), SIGIO
);
4423 #if 0 /* When polling is used, interrupt_input is 0,
4424 so get_input_pending should read the input.
4425 So this should not be needed. */
4426 /* If we are using polling for input,
4427 and we see input available, make it get read now.
4428 Otherwise it might not actually get read for a second.
4429 And on hpux, since we turn off polling in wait_reading_process_input,
4430 it might never get read at all if we don't spend much time
4431 outside of wait_reading_process_input. */
4432 if (XINT (read_kbd
) && interrupt_input
4433 && keyboard_bit_set (&Available
)
4434 && input_polling_used ())
4435 kill (getpid (), SIGALRM
);
4438 /* Check for keyboard input */
4439 /* If there is any, return immediately
4440 to give it higher priority than subprocesses */
4442 if (XINT (read_kbd
) != 0)
4444 int old_timers_run
= timers_run
;
4445 struct buffer
*old_buffer
= current_buffer
;
4448 if (detect_input_pending_run_timers (do_display
))
4450 swallow_events (do_display
);
4451 if (detect_input_pending_run_timers (do_display
))
4455 /* If a timer has run, this might have changed buffers
4456 an alike. Make read_key_sequence aware of that. */
4457 if (timers_run
!= old_timers_run
4458 && waiting_for_user_input_p
== -1
4459 && old_buffer
!= current_buffer
)
4460 record_asynch_buffer_change ();
4466 /* If there is unread keyboard input, also return. */
4467 if (XINT (read_kbd
) != 0
4468 && requeued_events_pending_p ())
4471 /* If we are not checking for keyboard input now,
4472 do process events (but don't run any timers).
4473 This is so that X events will be processed.
4474 Otherwise they may have to wait until polling takes place.
4475 That would causes delays in pasting selections, for example.
4477 (We used to do this only if wait_for_cell.) */
4478 if (XINT (read_kbd
) == 0 && detect_input_pending ())
4480 swallow_events (do_display
);
4481 #if 0 /* Exiting when read_kbd doesn't request that seems wrong, though. */
4482 if (detect_input_pending ())
4487 /* Exit now if the cell we're waiting for became non-nil. */
4488 if (! NILP (wait_for_cell
) && ! NILP (XCAR (wait_for_cell
)))
4492 /* If we think we have keyboard input waiting, but didn't get SIGIO,
4493 go read it. This can happen with X on BSD after logging out.
4494 In that case, there really is no input and no SIGIO,
4495 but select says there is input. */
4497 if (XINT (read_kbd
) && interrupt_input
4498 && keyboard_bit_set (&Available
) && ! noninteractive
)
4499 kill (getpid (), SIGIO
);
4503 got_some_input
|= nfds
> 0;
4505 /* If checking input just got us a size-change event from X,
4506 obey it now if we should. */
4507 if (XINT (read_kbd
) || ! NILP (wait_for_cell
))
4508 do_pending_window_change (0);
4510 /* Check for data from a process. */
4511 if (no_avail
|| nfds
== 0)
4514 /* Really FIRST_PROC_DESC should be 0 on Unix,
4515 but this is safer in the short run. */
4516 for (channel
= 0; channel
<= max_process_desc
; channel
++)
4518 if (FD_ISSET (channel
, &Available
)
4519 && FD_ISSET (channel
, &non_keyboard_wait_mask
))
4523 /* If waiting for this channel, arrange to return as
4524 soon as no more input to be processed. No more
4526 if (wait_channel
== channel
)
4532 proc
= chan_process
[channel
];
4536 /* If this is a server stream socket, accept connection. */
4537 if (EQ (XPROCESS (proc
)->status
, Qlisten
))
4539 server_accept_connection (proc
, channel
);
4543 /* Read data from the process, starting with our
4544 buffered-ahead character if we have one. */
4546 nread
= read_process_output (proc
, channel
);
4549 /* Since read_process_output can run a filter,
4550 which can call accept-process-output,
4551 don't try to read from any other processes
4552 before doing the select again. */
4553 FD_ZERO (&Available
);
4556 redisplay_preserve_echo_area (12);
4559 else if (nread
== -1 && errno
== EWOULDBLOCK
)
4562 /* ISC 4.1 defines both EWOULDBLOCK and O_NONBLOCK,
4563 and Emacs uses O_NONBLOCK, so what we get is EAGAIN. */
4565 else if (nread
== -1 && errno
== EAGAIN
)
4569 else if (nread
== -1 && errno
== EAGAIN
)
4571 /* Note that we cannot distinguish between no input
4572 available now and a closed pipe.
4573 With luck, a closed pipe will be accompanied by
4574 subprocess termination and SIGCHLD. */
4575 else if (nread
== 0 && !NETCONN_P (proc
))
4577 #endif /* O_NDELAY */
4578 #endif /* O_NONBLOCK */
4580 /* On some OSs with ptys, when the process on one end of
4581 a pty exits, the other end gets an error reading with
4582 errno = EIO instead of getting an EOF (0 bytes read).
4583 Therefore, if we get an error reading and errno =
4584 EIO, just continue, because the child process has
4585 exited and should clean itself up soon (e.g. when we
4588 However, it has been known to happen that the SIGCHLD
4589 got lost. So raise the signl again just in case.
4591 else if (nread
== -1 && errno
== EIO
)
4592 kill (getpid (), SIGCHLD
);
4593 #endif /* HAVE_PTYS */
4594 /* If we can detect process termination, don't consider the process
4595 gone just because its pipe is closed. */
4597 else if (nread
== 0 && !NETCONN_P (proc
))
4602 /* Preserve status of processes already terminated. */
4603 XSETINT (XPROCESS (proc
)->tick
, ++process_tick
);
4604 deactivate_process (proc
);
4605 if (!NILP (XPROCESS (proc
)->raw_status_low
))
4606 update_status (XPROCESS (proc
));
4607 if (EQ (XPROCESS (proc
)->status
, Qrun
))
4608 XPROCESS (proc
)->status
4609 = Fcons (Qexit
, Fcons (make_number (256), Qnil
));
4612 #ifdef NON_BLOCKING_CONNECT
4613 if (check_connect
&& FD_ISSET (channel
, &Connecting
)
4614 && FD_ISSET (channel
, &connect_wait_mask
))
4616 struct Lisp_Process
*p
;
4618 FD_CLR (channel
, &connect_wait_mask
);
4619 if (--num_pending_connects
< 0)
4622 proc
= chan_process
[channel
];
4626 p
= XPROCESS (proc
);
4629 /* getsockopt(,,SO_ERROR,,) is said to hang on some systems.
4630 So only use it on systems where it is known to work. */
4632 int xlen
= sizeof(xerrno
);
4633 if (getsockopt(channel
, SOL_SOCKET
, SO_ERROR
, &xerrno
, &xlen
))
4638 struct sockaddr pname
;
4639 int pnamelen
= sizeof(pname
);
4641 /* If connection failed, getpeername will fail. */
4643 if (getpeername(channel
, &pname
, &pnamelen
) < 0)
4645 /* Obtain connect failure code through error slippage. */
4648 if (errno
== ENOTCONN
&& read(channel
, &dummy
, 1) < 0)
4655 XSETINT (p
->tick
, ++process_tick
);
4656 p
->status
= Fcons (Qfailed
, Fcons (make_number (xerrno
), Qnil
));
4657 deactivate_process (proc
);
4662 /* Execute the sentinel here. If we had relied on
4663 status_notify to do it later, it will read input
4664 from the process before calling the sentinel. */
4665 exec_sentinel (proc
, build_string ("open\n"));
4666 if (!EQ (p
->filter
, Qt
) && !EQ (p
->command
, Qt
))
4668 FD_SET (XINT (p
->infd
), &input_wait_mask
);
4669 FD_SET (XINT (p
->infd
), &non_keyboard_wait_mask
);
4673 #endif /* NON_BLOCKING_CONNECT */
4674 } /* end for each file descriptor */
4675 } /* end while exit conditions not met */
4677 waiting_for_user_input_p
= saved_waiting_for_user_input_p
;
4679 /* If calling from keyboard input, do not quit
4680 since we want to return C-g as an input character.
4681 Otherwise, do pending quit if requested. */
4682 if (XINT (read_kbd
) >= 0)
4684 /* Prevent input_pending from remaining set if we quit. */
4685 clear_input_pending ();
4688 #ifdef POLL_INTERRUPTED_SYS_CALL
4689 /* AlainF 5-Jul-1996
4690 HP-UX 10.10 seems to have problems with signals coming in
4691 Causes "poll: interrupted system call" messages when Emacs is run
4693 Turn periodic alarms back on */
4695 #endif /* POLL_INTERRUPTED_SYS_CALL */
4697 return got_some_input
;
4700 /* Given a list (FUNCTION ARGS...), apply FUNCTION to the ARGS. */
4703 read_process_output_call (fun_and_args
)
4704 Lisp_Object fun_and_args
;
4706 return apply1 (XCAR (fun_and_args
), XCDR (fun_and_args
));
4710 read_process_output_error_handler (error
)
4713 cmd_error_internal (error
, "error in process filter: ");
4715 update_echo_area ();
4716 Fsleep_for (make_number (2), Qnil
);
4720 /* Read pending output from the process channel,
4721 starting with our buffered-ahead character if we have one.
4722 Yield number of decoded characters read.
4724 This function reads at most 4096 characters.
4725 If you want to read all available subprocess output,
4726 you must call it repeatedly until it returns zero.
4728 The characters read are decoded according to PROC's coding-system
4732 read_process_output (proc
, channel
)
4734 register int channel
;
4736 register int nbytes
;
4738 register Lisp_Object outstream
;
4739 register struct buffer
*old
= current_buffer
;
4740 register struct Lisp_Process
*p
= XPROCESS (proc
);
4741 register int opoint
;
4742 struct coding_system
*coding
= proc_decode_coding_system
[channel
];
4743 int carryover
= XINT (p
->decoding_carryover
);
4747 VMS_PROC_STUFF
*vs
, *get_vms_process_pointer();
4749 vs
= get_vms_process_pointer (p
->pid
);
4753 return (0); /* Really weird if it does this */
4754 if (!(vs
->iosb
[0] & 1))
4755 return -1; /* I/O error */
4758 error ("Could not get VMS process pointer");
4759 chars
= vs
->inputBuffer
;
4760 nbytes
= clean_vms_buffer (chars
, vs
->iosb
[1]);
4763 start_vms_process_read (vs
); /* Crank up the next read on the process */
4764 return 1; /* Nothing worth printing, say we got 1 */
4768 /* The data carried over in the previous decoding (which are at
4769 the tail of decoding buffer) should be prepended to the new
4770 data read to decode all together. */
4771 chars
= (char *) alloca (nbytes
+ carryover
);
4772 bcopy (SDATA (p
->decoding_buf
), buf
, carryover
);
4773 bcopy (vs
->inputBuffer
, chars
+ carryover
, nbytes
);
4777 chars
= (char *) alloca (carryover
+ readmax
);
4779 /* See the comment above. */
4780 bcopy (SDATA (p
->decoding_buf
), chars
, carryover
);
4782 #ifdef DATAGRAM_SOCKETS
4783 /* We have a working select, so proc_buffered_char is always -1. */
4784 if (DATAGRAM_CHAN_P (channel
))
4786 int len
= datagram_address
[channel
].len
;
4787 nbytes
= recvfrom (channel
, chars
+ carryover
, readmax
,
4788 0, datagram_address
[channel
].sa
, &len
);
4792 if (proc_buffered_char
[channel
] < 0)
4794 nbytes
= emacs_read (channel
, chars
+ carryover
, readmax
);
4795 #ifdef ADAPTIVE_READ_BUFFERING
4796 if (nbytes
> 0 && !NILP (p
->adaptive_read_buffering
))
4798 int delay
= XINT (p
->read_output_delay
);
4801 if (delay
< READ_OUTPUT_DELAY_MAX_MAX
)
4804 process_output_delay_count
++;
4805 delay
+= READ_OUTPUT_DELAY_INCREMENT
* 2;
4808 else if (delay
> 0 && (nbytes
== readmax
))
4810 delay
-= READ_OUTPUT_DELAY_INCREMENT
;
4812 process_output_delay_count
--;
4814 XSETINT (p
->read_output_delay
, delay
);
4817 p
->read_output_skip
= Qt
;
4818 process_output_skip
= 1;
4825 chars
[carryover
] = proc_buffered_char
[channel
];
4826 proc_buffered_char
[channel
] = -1;
4827 nbytes
= emacs_read (channel
, chars
+ carryover
+ 1, readmax
- 1);
4831 nbytes
= nbytes
+ 1;
4833 #endif /* not VMS */
4835 XSETINT (p
->decoding_carryover
, 0);
4837 /* At this point, NBYTES holds number of bytes just received
4838 (including the one in proc_buffered_char[channel]). */
4841 if (nbytes
< 0 || coding
->mode
& CODING_MODE_LAST_BLOCK
)
4843 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
4846 /* Now set NBYTES how many bytes we must decode. */
4847 nbytes
+= carryover
;
4849 /* Read and dispose of the process output. */
4850 outstream
= p
->filter
;
4851 if (!NILP (outstream
))
4853 /* We inhibit quit here instead of just catching it so that
4854 hitting ^G when a filter happens to be running won't screw
4856 int count
= SPECPDL_INDEX ();
4857 Lisp_Object odeactivate
;
4858 Lisp_Object obuffer
, okeymap
;
4860 int outer_running_asynch_code
= running_asynch_code
;
4861 int waiting
= waiting_for_user_input_p
;
4863 /* No need to gcpro these, because all we do with them later
4864 is test them for EQness, and none of them should be a string. */
4865 odeactivate
= Vdeactivate_mark
;
4866 XSETBUFFER (obuffer
, current_buffer
);
4867 okeymap
= current_buffer
->keymap
;
4869 specbind (Qinhibit_quit
, Qt
);
4870 specbind (Qlast_nonmenu_event
, Qt
);
4872 /* In case we get recursively called,
4873 and we already saved the match data nonrecursively,
4874 save the same match data in safely recursive fashion. */
4875 if (outer_running_asynch_code
)
4878 /* Don't clobber the CURRENT match data, either! */
4879 tem
= Fmatch_data (Qnil
, Qnil
);
4880 restore_match_data ();
4881 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
4882 Fset_match_data (tem
);
4885 /* For speed, if a search happens within this code,
4886 save the match data in a special nonrecursive fashion. */
4887 running_asynch_code
= 1;
4889 text
= decode_coding_string (make_unibyte_string (chars
, nbytes
),
4891 Vlast_coding_system_used
= coding
->symbol
;
4892 /* A new coding system might be found. */
4893 if (!EQ (p
->decode_coding_system
, coding
->symbol
))
4895 p
->decode_coding_system
= coding
->symbol
;
4897 /* Don't call setup_coding_system for
4898 proc_decode_coding_system[channel] here. It is done in
4899 detect_coding called via decode_coding above. */
4901 /* If a coding system for encoding is not yet decided, we set
4902 it as the same as coding-system for decoding.
4904 But, before doing that we must check if
4905 proc_encode_coding_system[p->outfd] surely points to a
4906 valid memory because p->outfd will be changed once EOF is
4907 sent to the process. */
4908 if (NILP (p
->encode_coding_system
)
4909 && proc_encode_coding_system
[XINT (p
->outfd
)])
4911 p
->encode_coding_system
= coding
->symbol
;
4912 setup_coding_system (coding
->symbol
,
4913 proc_encode_coding_system
[XINT (p
->outfd
)]);
4917 carryover
= nbytes
- coding
->consumed
;
4918 if (SCHARS (p
->decoding_buf
) < carryover
)
4919 p
->decoding_buf
= make_uninit_string (carryover
);
4920 bcopy (chars
+ coding
->consumed
, SDATA (p
->decoding_buf
),
4922 XSETINT (p
->decoding_carryover
, carryover
);
4923 /* Adjust the multibyteness of TEXT to that of the filter. */
4924 if (NILP (p
->filter_multibyte
) != ! STRING_MULTIBYTE (text
))
4925 text
= (STRING_MULTIBYTE (text
)
4926 ? Fstring_as_unibyte (text
)
4927 : Fstring_to_multibyte (text
));
4928 if (SBYTES (text
) > 0)
4929 internal_condition_case_1 (read_process_output_call
,
4931 Fcons (proc
, Fcons (text
, Qnil
))),
4932 !NILP (Vdebug_on_error
) ? Qnil
: Qerror
,
4933 read_process_output_error_handler
);
4935 /* If we saved the match data nonrecursively, restore it now. */
4936 restore_match_data ();
4937 running_asynch_code
= outer_running_asynch_code
;
4939 /* Handling the process output should not deactivate the mark. */
4940 Vdeactivate_mark
= odeactivate
;
4942 /* Restore waiting_for_user_input_p as it was
4943 when we were called, in case the filter clobbered it. */
4944 waiting_for_user_input_p
= waiting
;
4946 #if 0 /* Call record_asynch_buffer_change unconditionally,
4947 because we might have changed minor modes or other things
4948 that affect key bindings. */
4949 if (! EQ (Fcurrent_buffer (), obuffer
)
4950 || ! EQ (current_buffer
->keymap
, okeymap
))
4952 /* But do it only if the caller is actually going to read events.
4953 Otherwise there's no need to make him wake up, and it could
4954 cause trouble (for example it would make Fsit_for return). */
4955 if (waiting_for_user_input_p
== -1)
4956 record_asynch_buffer_change ();
4959 start_vms_process_read (vs
);
4961 unbind_to (count
, Qnil
);
4965 /* If no filter, write into buffer if it isn't dead. */
4966 if (!NILP (p
->buffer
) && !NILP (XBUFFER (p
->buffer
)->name
))
4968 Lisp_Object old_read_only
;
4969 int old_begv
, old_zv
;
4970 int old_begv_byte
, old_zv_byte
;
4971 Lisp_Object odeactivate
;
4972 int before
, before_byte
;
4977 odeactivate
= Vdeactivate_mark
;
4979 Fset_buffer (p
->buffer
);
4981 opoint_byte
= PT_BYTE
;
4982 old_read_only
= current_buffer
->read_only
;
4985 old_begv_byte
= BEGV_BYTE
;
4986 old_zv_byte
= ZV_BYTE
;
4988 current_buffer
->read_only
= Qnil
;
4990 /* Insert new output into buffer
4991 at the current end-of-output marker,
4992 thus preserving logical ordering of input and output. */
4993 if (XMARKER (p
->mark
)->buffer
)
4994 SET_PT_BOTH (clip_to_bounds (BEGV
, marker_position (p
->mark
), ZV
),
4995 clip_to_bounds (BEGV_BYTE
, marker_byte_position (p
->mark
),
4998 SET_PT_BOTH (ZV
, ZV_BYTE
);
5000 before_byte
= PT_BYTE
;
5002 /* If the output marker is outside of the visible region, save
5003 the restriction and widen. */
5004 if (! (BEGV
<= PT
&& PT
<= ZV
))
5007 text
= decode_coding_string (make_unibyte_string (chars
, nbytes
),
5009 Vlast_coding_system_used
= coding
->symbol
;
5010 /* A new coding system might be found. See the comment in the
5011 similar code in the previous `if' block. */
5012 if (!EQ (p
->decode_coding_system
, coding
->symbol
))
5014 p
->decode_coding_system
= coding
->symbol
;
5015 if (NILP (p
->encode_coding_system
)
5016 && proc_encode_coding_system
[XINT (p
->outfd
)])
5018 p
->encode_coding_system
= coding
->symbol
;
5019 setup_coding_system (coding
->symbol
,
5020 proc_encode_coding_system
[XINT (p
->outfd
)]);
5023 carryover
= nbytes
- coding
->consumed
;
5024 if (SCHARS (p
->decoding_buf
) < carryover
)
5025 p
->decoding_buf
= make_uninit_string (carryover
);
5026 bcopy (chars
+ coding
->consumed
, SDATA (p
->decoding_buf
),
5028 XSETINT (p
->decoding_carryover
, carryover
);
5029 /* Adjust the multibyteness of TEXT to that of the buffer. */
5030 if (NILP (current_buffer
->enable_multibyte_characters
)
5031 != ! STRING_MULTIBYTE (text
))
5032 text
= (STRING_MULTIBYTE (text
)
5033 ? Fstring_as_unibyte (text
)
5034 : Fstring_to_multibyte (text
));
5035 /* Insert before markers in case we are inserting where
5036 the buffer's mark is, and the user's next command is Meta-y. */
5037 insert_from_string_before_markers (text
, 0, 0,
5038 SCHARS (text
), SBYTES (text
), 0);
5040 /* Make sure the process marker's position is valid when the
5041 process buffer is changed in the signal_after_change above.
5042 W3 is known to do that. */
5043 if (BUFFERP (p
->buffer
)
5044 && (b
= XBUFFER (p
->buffer
), b
!= current_buffer
))
5045 set_marker_both (p
->mark
, p
->buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
5047 set_marker_both (p
->mark
, p
->buffer
, PT
, PT_BYTE
);
5049 update_mode_lines
++;
5051 /* Make sure opoint and the old restrictions
5052 float ahead of any new text just as point would. */
5053 if (opoint
>= before
)
5055 opoint
+= PT
- before
;
5056 opoint_byte
+= PT_BYTE
- before_byte
;
5058 if (old_begv
> before
)
5060 old_begv
+= PT
- before
;
5061 old_begv_byte
+= PT_BYTE
- before_byte
;
5063 if (old_zv
>= before
)
5065 old_zv
+= PT
- before
;
5066 old_zv_byte
+= PT_BYTE
- before_byte
;
5069 /* If the restriction isn't what it should be, set it. */
5070 if (old_begv
!= BEGV
|| old_zv
!= ZV
)
5071 Fnarrow_to_region (make_number (old_begv
), make_number (old_zv
));
5073 /* Handling the process output should not deactivate the mark. */
5074 Vdeactivate_mark
= odeactivate
;
5076 current_buffer
->read_only
= old_read_only
;
5077 SET_PT_BOTH (opoint
, opoint_byte
);
5078 set_buffer_internal (old
);
5081 start_vms_process_read (vs
);
5086 DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p
, Swaiting_for_user_input_p
,
5088 doc
: /* Returns non-nil if Emacs is waiting for input from the user.
5089 This is intended for use by asynchronous process output filters and sentinels. */)
5092 return (waiting_for_user_input_p
? Qt
: Qnil
);
5095 /* Sending data to subprocess */
5097 jmp_buf send_process_frame
;
5098 Lisp_Object process_sent_to
;
5101 send_process_trap ()
5107 longjmp (send_process_frame
, 1);
5110 /* Send some data to process PROC.
5111 BUF is the beginning of the data; LEN is the number of characters.
5112 OBJECT is the Lisp object that the data comes from. If OBJECT is
5113 nil or t, it means that the data comes from C string.
5115 If OBJECT is not nil, the data is encoded by PROC's coding-system
5116 for encoding before it is sent.
5118 This function can evaluate Lisp code and can garbage collect. */
5121 send_process (proc
, buf
, len
, object
)
5122 volatile Lisp_Object proc
;
5123 unsigned char *volatile buf
;
5125 volatile Lisp_Object object
;
5127 /* Use volatile to protect variables from being clobbered by longjmp. */
5128 struct Lisp_Process
*p
= XPROCESS (proc
);
5130 struct coding_system
*coding
;
5131 struct gcpro gcpro1
;
5136 VMS_PROC_STUFF
*vs
, *get_vms_process_pointer();
5139 if (! NILP (p
->raw_status_low
))
5141 if (! EQ (p
->status
, Qrun
))
5142 error ("Process %s not running", SDATA (p
->name
));
5143 if (XINT (p
->outfd
) < 0)
5144 error ("Output file descriptor of %s is closed", SDATA (p
->name
));
5146 coding
= proc_encode_coding_system
[XINT (p
->outfd
)];
5147 Vlast_coding_system_used
= coding
->symbol
;
5149 if ((STRINGP (object
) && STRING_MULTIBYTE (object
))
5150 || (BUFFERP (object
)
5151 && !NILP (XBUFFER (object
)->enable_multibyte_characters
))
5154 if (!EQ (coding
->symbol
, p
->encode_coding_system
))
5155 /* The coding system for encoding was changed to raw-text
5156 because we sent a unibyte text previously. Now we are
5157 sending a multibyte text, thus we must encode it by the
5158 original coding system specified for the current process. */
5159 setup_coding_system (p
->encode_coding_system
, coding
);
5160 /* src_multibyte should be set to 1 _after_ a call to
5161 setup_coding_system, since it resets src_multibyte to
5163 coding
->src_multibyte
= 1;
5167 /* For sending a unibyte text, character code conversion should
5168 not take place but EOL conversion should. So, setup raw-text
5169 or one of the subsidiary if we have not yet done it. */
5170 if (coding
->type
!= coding_type_raw_text
)
5172 if (CODING_REQUIRE_FLUSHING (coding
))
5174 /* But, before changing the coding, we must flush out data. */
5175 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
5176 send_process (proc
, "", 0, Qt
);
5178 coding
->src_multibyte
= 0;
5179 setup_raw_text_coding_system (coding
);
5182 coding
->dst_multibyte
= 0;
5184 if (CODING_REQUIRE_ENCODING (coding
))
5186 int require
= encoding_buffer_size (coding
, len
);
5187 int from_byte
= -1, from
= -1, to
= -1;
5189 if (BUFFERP (object
))
5191 from_byte
= BUF_PTR_BYTE_POS (XBUFFER (object
), buf
);
5192 from
= buf_bytepos_to_charpos (XBUFFER (object
), from_byte
);
5193 to
= buf_bytepos_to_charpos (XBUFFER (object
), from_byte
+ len
);
5195 else if (STRINGP (object
))
5197 from_byte
= buf
- SDATA (object
);
5198 from
= string_byte_to_char (object
, from_byte
);
5199 to
= string_byte_to_char (object
, from_byte
+ len
);
5202 if (coding
->composing
!= COMPOSITION_DISABLED
)
5205 coding_save_composition (coding
, from
, to
, object
);
5207 coding
->composing
= COMPOSITION_DISABLED
;
5210 if (SBYTES (p
->encoding_buf
) < require
)
5211 p
->encoding_buf
= make_uninit_string (require
);
5214 buf
= (BUFFERP (object
)
5215 ? BUF_BYTE_ADDRESS (XBUFFER (object
), from_byte
)
5216 : SDATA (object
) + from_byte
);
5218 object
= p
->encoding_buf
;
5219 encode_coding (coding
, (char *) buf
, SDATA (object
),
5220 len
, SBYTES (object
));
5221 len
= coding
->produced
;
5222 buf
= SDATA (object
);
5226 vs
= get_vms_process_pointer (p
->pid
);
5228 error ("Could not find this process: %x", p
->pid
);
5229 else if (write_to_vms_process (vs
, buf
, len
))
5233 if (pty_max_bytes
== 0)
5235 #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON)
5236 pty_max_bytes
= fpathconf (XFASTINT (p
->outfd
), _PC_MAX_CANON
);
5237 if (pty_max_bytes
< 0)
5238 pty_max_bytes
= 250;
5240 pty_max_bytes
= 250;
5242 /* Deduct one, to leave space for the eof. */
5246 /* 2000-09-21: Emacs 20.7, sparc-sun-solaris-2.6, GCC 2.95.2,
5247 CFLAGS="-g -O": The value of the parameter `proc' is clobbered
5248 when returning with longjmp despite being declared volatile. */
5249 if (!setjmp (send_process_frame
))
5251 process_sent_to
= proc
;
5255 SIGTYPE (*old_sigpipe
)();
5257 /* Decide how much data we can send in one batch.
5258 Long lines need to be split into multiple batches. */
5259 if (!NILP (p
->pty_flag
))
5261 /* Starting this at zero is always correct when not the first
5262 iteration because the previous iteration ended by sending C-d.
5263 It may not be correct for the first iteration
5264 if a partial line was sent in a separate send_process call.
5265 If that proves worth handling, we need to save linepos
5266 in the process object. */
5268 unsigned char *ptr
= (unsigned char *) buf
;
5269 unsigned char *end
= (unsigned char *) buf
+ len
;
5271 /* Scan through this text for a line that is too long. */
5272 while (ptr
!= end
&& linepos
< pty_max_bytes
)
5280 /* If we found one, break the line there
5281 and put in a C-d to force the buffer through. */
5285 /* Send this batch, using one or more write calls. */
5288 int outfd
= XINT (p
->outfd
);
5289 old_sigpipe
= (SIGTYPE (*) ()) signal (SIGPIPE
, send_process_trap
);
5290 #ifdef DATAGRAM_SOCKETS
5291 if (DATAGRAM_CHAN_P (outfd
))
5293 rv
= sendto (outfd
, (char *) buf
, this,
5294 0, datagram_address
[outfd
].sa
,
5295 datagram_address
[outfd
].len
);
5296 if (rv
< 0 && errno
== EMSGSIZE
)
5297 report_file_error ("sending datagram", Fcons (proc
, Qnil
));
5302 rv
= emacs_write (outfd
, (char *) buf
, this);
5303 #ifdef ADAPTIVE_READ_BUFFERING
5304 if (XINT (p
->read_output_delay
) > 0
5305 && EQ (p
->adaptive_read_buffering
, Qt
))
5307 XSETFASTINT (p
->read_output_delay
, 0);
5308 process_output_delay_count
--;
5309 p
->read_output_skip
= Qnil
;
5313 signal (SIGPIPE
, old_sigpipe
);
5319 || errno
== EWOULDBLOCK
5325 /* Buffer is full. Wait, accepting input;
5326 that may allow the program
5327 to finish doing output and read more. */
5332 #ifdef BROKEN_PTY_READ_AFTER_EAGAIN
5333 /* A gross hack to work around a bug in FreeBSD.
5334 In the following sequence, read(2) returns
5338 write(2) 954 bytes, get EAGAIN
5339 read(2) 1024 bytes in process_read_output
5340 read(2) 11 bytes in process_read_output
5342 That is, read(2) returns more bytes than have
5343 ever been written successfully. The 1033 bytes
5344 read are the 1022 bytes written successfully
5345 after processing (for example with CRs added if
5346 the terminal is set up that way which it is
5347 here). The same bytes will be seen again in a
5348 later read(2), without the CRs. */
5350 if (errno
== EAGAIN
)
5353 ioctl (XINT (p
->outfd
), TIOCFLUSH
, &flags
);
5355 #endif /* BROKEN_PTY_READ_AFTER_EAGAIN */
5357 /* Running filters might relocate buffers or strings.
5358 Arrange to relocate BUF. */
5359 if (BUFFERP (object
))
5360 offset
= BUF_PTR_BYTE_POS (XBUFFER (object
), buf
);
5361 else if (STRINGP (object
))
5362 offset
= buf
- SDATA (object
);
5364 XSETFASTINT (zero
, 0);
5365 #ifdef EMACS_HAS_USECS
5366 wait_reading_process_input (0, 20000, zero
, 0);
5368 wait_reading_process_input (1, 0, zero
, 0);
5371 if (BUFFERP (object
))
5372 buf
= BUF_BYTE_ADDRESS (XBUFFER (object
), offset
);
5373 else if (STRINGP (object
))
5374 buf
= offset
+ SDATA (object
);
5379 /* This is a real error. */
5380 report_file_error ("writing to process", Fcons (proc
, Qnil
));
5387 /* If we sent just part of the string, put in an EOF
5388 to force it through, before we send the rest. */
5390 Fprocess_send_eof (proc
);
5393 #endif /* not VMS */
5397 proc
= process_sent_to
;
5398 p
= XPROCESS (proc
);
5400 p
->raw_status_low
= Qnil
;
5401 p
->raw_status_high
= Qnil
;
5402 p
->status
= Fcons (Qexit
, Fcons (make_number (256), Qnil
));
5403 XSETINT (p
->tick
, ++process_tick
);
5404 deactivate_process (proc
);
5406 error ("Error writing to process %s; closed it", SDATA (p
->name
));
5408 error ("SIGPIPE raised on process %s; closed it", SDATA (p
->name
));
5415 DEFUN ("process-send-region", Fprocess_send_region
, Sprocess_send_region
,
5417 doc
: /* Send current contents of region as input to PROCESS.
5418 PROCESS may be a process, a buffer, the name of a process or buffer, or
5419 nil, indicating the current buffer's process.
5420 Called from program, takes three arguments, PROCESS, START and END.
5421 If the region is more than 500 characters long,
5422 it is sent in several bunches. This may happen even for shorter regions.
5423 Output from processes can arrive in between bunches. */)
5424 (process
, start
, end
)
5425 Lisp_Object process
, start
, end
;
5430 proc
= get_process (process
);
5431 validate_region (&start
, &end
);
5433 if (XINT (start
) < GPT
&& XINT (end
) > GPT
)
5434 move_gap (XINT (start
));
5436 start1
= CHAR_TO_BYTE (XINT (start
));
5437 end1
= CHAR_TO_BYTE (XINT (end
));
5438 send_process (proc
, BYTE_POS_ADDR (start1
), end1
- start1
,
5439 Fcurrent_buffer ());
5444 DEFUN ("process-send-string", Fprocess_send_string
, Sprocess_send_string
,
5446 doc
: /* Send PROCESS the contents of STRING as input.
5447 PROCESS may be a process, a buffer, the name of a process or buffer, or
5448 nil, indicating the current buffer's process.
5449 If STRING is more than 500 characters long,
5450 it is sent in several bunches. This may happen even for shorter strings.
5451 Output from processes can arrive in between bunches. */)
5453 Lisp_Object process
, string
;
5456 CHECK_STRING (string
);
5457 proc
= get_process (process
);
5458 send_process (proc
, SDATA (string
),
5459 SBYTES (string
), string
);
5463 /* Return the foreground process group for the tty/pty that
5464 the process P uses. */
5466 emacs_get_tty_pgrp (p
)
5467 struct Lisp_Process
*p
;
5472 if (ioctl (XINT (p
->infd
), TIOCGPGRP
, &gid
) == -1 && ! NILP (p
->tty_name
))
5475 /* Some OS:es (Solaris 8/9) does not allow TIOCGPGRP from the
5476 master side. Try the slave side. */
5477 fd
= emacs_open (XSTRING (p
->tty_name
)->data
, O_RDONLY
, 0);
5481 ioctl (fd
, TIOCGPGRP
, &gid
);
5485 #endif /* defined (TIOCGPGRP ) */
5490 DEFUN ("process-running-child-p", Fprocess_running_child_p
,
5491 Sprocess_running_child_p
, 0, 1, 0,
5492 doc
: /* Return t if PROCESS has given the terminal to a child.
5493 If the operating system does not make it possible to find out,
5494 return t unconditionally. */)
5496 Lisp_Object process
;
5498 /* Initialize in case ioctl doesn't exist or gives an error,
5499 in a way that will cause returning t. */
5502 struct Lisp_Process
*p
;
5504 proc
= get_process (process
);
5505 p
= XPROCESS (proc
);
5507 if (!EQ (p
->childp
, Qt
))
5508 error ("Process %s is not a subprocess",
5510 if (XINT (p
->infd
) < 0)
5511 error ("Process %s is not active",
5514 gid
= emacs_get_tty_pgrp (p
);
5516 if (gid
== XFASTINT (p
->pid
))
5521 /* send a signal number SIGNO to PROCESS.
5522 If CURRENT_GROUP is t, that means send to the process group
5523 that currently owns the terminal being used to communicate with PROCESS.
5524 This is used for various commands in shell mode.
5525 If CURRENT_GROUP is lambda, that means send to the process group
5526 that currently owns the terminal, but only if it is NOT the shell itself.
5528 If NOMSG is zero, insert signal-announcements into process's buffers
5531 If we can, we try to signal PROCESS by sending control characters
5532 down the pty. This allows us to signal inferiors who have changed
5533 their uid, for which killpg would return an EPERM error. */
5536 process_send_signal (process
, signo
, current_group
, nomsg
)
5537 Lisp_Object process
;
5539 Lisp_Object current_group
;
5543 register struct Lisp_Process
*p
;
5547 proc
= get_process (process
);
5548 p
= XPROCESS (proc
);
5550 if (!EQ (p
->childp
, Qt
))
5551 error ("Process %s is not a subprocess",
5553 if (XINT (p
->infd
) < 0)
5554 error ("Process %s is not active",
5557 if (NILP (p
->pty_flag
))
5558 current_group
= Qnil
;
5560 /* If we are using pgrps, get a pgrp number and make it negative. */
5561 if (NILP (current_group
))
5562 /* Send the signal to the shell's process group. */
5563 gid
= XFASTINT (p
->pid
);
5566 #ifdef SIGNALS_VIA_CHARACTERS
5567 /* If possible, send signals to the entire pgrp
5568 by sending an input character to it. */
5570 /* TERMIOS is the latest and bestest, and seems most likely to
5571 work. If the system has it, use it. */
5574 cc_t
*sig_char
= NULL
;
5576 tcgetattr (XINT (p
->infd
), &t
);
5581 sig_char
= &t
.c_cc
[VINTR
];
5585 sig_char
= &t
.c_cc
[VQUIT
];
5589 #if defined (VSWTCH) && !defined (PREFER_VSUSP)
5590 sig_char
= &t
.c_cc
[VSWTCH
];
5592 sig_char
= &t
.c_cc
[VSUSP
];
5597 if (sig_char
&& *sig_char
!= CDISABLE
)
5598 send_process (proc
, sig_char
, 1, Qnil
);
5600 #else /* ! HAVE_TERMIOS */
5602 /* On Berkeley descendants, the following IOCTL's retrieve the
5603 current control characters. */
5604 #if defined (TIOCGLTC) && defined (TIOCGETC)
5612 ioctl (XINT (p
->infd
), TIOCGETC
, &c
);
5613 send_process (proc
, &c
.t_intrc
, 1, Qnil
);
5616 ioctl (XINT (p
->infd
), TIOCGETC
, &c
);
5617 send_process (proc
, &c
.t_quitc
, 1, Qnil
);
5621 ioctl (XINT (p
->infd
), TIOCGLTC
, &lc
);
5622 send_process (proc
, &lc
.t_suspc
, 1, Qnil
);
5624 #endif /* ! defined (SIGTSTP) */
5627 #else /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
5629 /* On SYSV descendants, the TCGETA ioctl retrieves the current control
5636 ioctl (XINT (p
->infd
), TCGETA
, &t
);
5637 send_process (proc
, &t
.c_cc
[VINTR
], 1, Qnil
);
5640 ioctl (XINT (p
->infd
), TCGETA
, &t
);
5641 send_process (proc
, &t
.c_cc
[VQUIT
], 1, Qnil
);
5645 ioctl (XINT (p
->infd
), TCGETA
, &t
);
5646 send_process (proc
, &t
.c_cc
[VSWTCH
], 1, Qnil
);
5648 #endif /* ! defined (SIGTSTP) */
5650 #else /* ! defined (TCGETA) */
5651 Your configuration files are messed up
.
5652 /* If your system configuration files define SIGNALS_VIA_CHARACTERS,
5653 you'd better be using one of the alternatives above! */
5654 #endif /* ! defined (TCGETA) */
5655 #endif /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
5656 #endif /* ! defined HAVE_TERMIOS */
5658 /* The code above always returns from the function. */
5659 #endif /* defined (SIGNALS_VIA_CHARACTERS) */
5662 /* Get the current pgrp using the tty itself, if we have that.
5663 Otherwise, use the pty to get the pgrp.
5664 On pfa systems, saka@pfu.fujitsu.co.JP writes:
5665 "TIOCGPGRP symbol defined in sys/ioctl.h at E50.
5666 But, TIOCGPGRP does not work on E50 ;-P works fine on E60"
5667 His patch indicates that if TIOCGPGRP returns an error, then
5668 we should just assume that p->pid is also the process group id. */
5670 gid
= emacs_get_tty_pgrp (p
);
5673 /* If we can't get the information, assume
5674 the shell owns the tty. */
5675 gid
= XFASTINT (p
->pid
);
5677 /* It is not clear whether anything really can set GID to -1.
5678 Perhaps on some system one of those ioctls can or could do so.
5679 Or perhaps this is vestigial. */
5682 #else /* ! defined (TIOCGPGRP ) */
5683 /* Can't select pgrps on this system, so we know that
5684 the child itself heads the pgrp. */
5685 gid
= XFASTINT (p
->pid
);
5686 #endif /* ! defined (TIOCGPGRP ) */
5688 /* If current_group is lambda, and the shell owns the terminal,
5689 don't send any signal. */
5690 if (EQ (current_group
, Qlambda
) && gid
== XFASTINT (p
->pid
))
5698 p
->raw_status_low
= Qnil
;
5699 p
->raw_status_high
= Qnil
;
5701 XSETINT (p
->tick
, ++process_tick
);
5705 #endif /* ! defined (SIGCONT) */
5708 send_process (proc
, "\003", 1, Qnil
); /* ^C */
5713 send_process (proc
, "\031", 1, Qnil
); /* ^Y */
5718 sys$
forcex (&(XFASTINT (p
->pid
)), 0, 1);
5721 flush_pending_output (XINT (p
->infd
));
5725 /* If we don't have process groups, send the signal to the immediate
5726 subprocess. That isn't really right, but it's better than any
5727 obvious alternative. */
5730 kill (XFASTINT (p
->pid
), signo
);
5734 /* gid may be a pid, or minus a pgrp's number */
5736 if (!NILP (current_group
))
5738 if (ioctl (XINT (p
->infd
), TIOCSIGSEND
, signo
) == -1)
5739 EMACS_KILLPG (gid
, signo
);
5743 gid
= - XFASTINT (p
->pid
);
5746 #else /* ! defined (TIOCSIGSEND) */
5747 EMACS_KILLPG (gid
, signo
);
5748 #endif /* ! defined (TIOCSIGSEND) */
5751 DEFUN ("interrupt-process", Finterrupt_process
, Sinterrupt_process
, 0, 2, 0,
5752 doc
: /* Interrupt process PROCESS.
5753 PROCESS may be a process, a buffer, or the name of a process or buffer.
5754 No arg or nil means current buffer's process.
5755 Second arg CURRENT-GROUP non-nil means send signal to
5756 the current process-group of the process's controlling terminal
5757 rather than to the process's own process group.
5758 If the process is a shell, this means interrupt current subjob
5759 rather than the shell.
5761 If CURRENT-GROUP is `lambda', and if the shell owns the terminal,
5762 don't send the signal. */)
5763 (process
, current_group
)
5764 Lisp_Object process
, current_group
;
5766 process_send_signal (process
, SIGINT
, current_group
, 0);
5770 DEFUN ("kill-process", Fkill_process
, Skill_process
, 0, 2, 0,
5771 doc
: /* Kill process PROCESS. May be process or name of one.
5772 See function `interrupt-process' for more details on usage. */)
5773 (process
, current_group
)
5774 Lisp_Object process
, current_group
;
5776 process_send_signal (process
, SIGKILL
, current_group
, 0);
5780 DEFUN ("quit-process", Fquit_process
, Squit_process
, 0, 2, 0,
5781 doc
: /* Send QUIT signal to process PROCESS. May be process or name of one.
5782 See function `interrupt-process' for more details on usage. */)
5783 (process
, current_group
)
5784 Lisp_Object process
, current_group
;
5786 process_send_signal (process
, SIGQUIT
, current_group
, 0);
5790 DEFUN ("stop-process", Fstop_process
, Sstop_process
, 0, 2, 0,
5791 doc
: /* Stop process PROCESS. May be process or name of one.
5792 See function `interrupt-process' for more details on usage.
5793 If PROCESS is a network process, inhibit handling of incoming traffic. */)
5794 (process
, current_group
)
5795 Lisp_Object process
, current_group
;
5798 if (PROCESSP (process
) && NETCONN_P (process
))
5800 struct Lisp_Process
*p
;
5802 p
= XPROCESS (process
);
5803 if (NILP (p
->command
)
5804 && XINT (p
->infd
) >= 0)
5806 FD_CLR (XINT (p
->infd
), &input_wait_mask
);
5807 FD_CLR (XINT (p
->infd
), &non_keyboard_wait_mask
);
5814 error ("no SIGTSTP support");
5816 process_send_signal (process
, SIGTSTP
, current_group
, 0);
5821 DEFUN ("continue-process", Fcontinue_process
, Scontinue_process
, 0, 2, 0,
5822 doc
: /* Continue process PROCESS. May be process or name of one.
5823 See function `interrupt-process' for more details on usage.
5824 If PROCESS is a network process, resume handling of incoming traffic. */)
5825 (process
, current_group
)
5826 Lisp_Object process
, current_group
;
5829 if (PROCESSP (process
) && NETCONN_P (process
))
5831 struct Lisp_Process
*p
;
5833 p
= XPROCESS (process
);
5834 if (EQ (p
->command
, Qt
)
5835 && XINT (p
->infd
) >= 0
5836 && (!EQ (p
->filter
, Qt
) || EQ (p
->status
, Qlisten
)))
5838 FD_SET (XINT (p
->infd
), &input_wait_mask
);
5839 FD_SET (XINT (p
->infd
), &non_keyboard_wait_mask
);
5846 process_send_signal (process
, SIGCONT
, current_group
, 0);
5848 error ("no SIGCONT support");
5853 DEFUN ("signal-process", Fsignal_process
, Ssignal_process
,
5854 2, 2, "sProcess (name or number): \nnSignal code: ",
5855 doc
: /* Send PROCESS the signal with code SIGCODE.
5856 PROCESS may also be an integer specifying the process id of the
5857 process to signal; in this case, the process need not be a child of
5859 SIGCODE may be an integer, or a symbol whose name is a signal name. */)
5861 Lisp_Object process
, sigcode
;
5865 if (INTEGERP (process
))
5871 if (STRINGP (process
))
5874 if (tem
= Fget_process (process
), NILP (tem
))
5876 pid
= Fstring_to_number (process
, make_number (10));
5877 if (XINT (pid
) != 0)
5883 process
= get_process (process
);
5888 CHECK_PROCESS (process
);
5889 pid
= XPROCESS (process
)->pid
;
5890 if (!INTEGERP (pid
) || XINT (pid
) <= 0)
5891 error ("Cannot signal process %s", SDATA (XPROCESS (process
)->name
));
5895 #define handle_signal(NAME, VALUE) \
5896 else if (!strcmp (name, NAME)) \
5897 XSETINT (sigcode, VALUE)
5899 if (INTEGERP (sigcode
))
5903 unsigned char *name
;
5905 CHECK_SYMBOL (sigcode
);
5906 name
= SDATA (SYMBOL_NAME (sigcode
));
5911 handle_signal ("SIGHUP", SIGHUP
);
5914 handle_signal ("SIGINT", SIGINT
);
5917 handle_signal ("SIGQUIT", SIGQUIT
);
5920 handle_signal ("SIGILL", SIGILL
);
5923 handle_signal ("SIGABRT", SIGABRT
);
5926 handle_signal ("SIGEMT", SIGEMT
);
5929 handle_signal ("SIGKILL", SIGKILL
);
5932 handle_signal ("SIGFPE", SIGFPE
);
5935 handle_signal ("SIGBUS", SIGBUS
);
5938 handle_signal ("SIGSEGV", SIGSEGV
);
5941 handle_signal ("SIGSYS", SIGSYS
);
5944 handle_signal ("SIGPIPE", SIGPIPE
);
5947 handle_signal ("SIGALRM", SIGALRM
);
5950 handle_signal ("SIGTERM", SIGTERM
);
5953 handle_signal ("SIGURG", SIGURG
);
5956 handle_signal ("SIGSTOP", SIGSTOP
);
5959 handle_signal ("SIGTSTP", SIGTSTP
);
5962 handle_signal ("SIGCONT", SIGCONT
);
5965 handle_signal ("SIGCHLD", SIGCHLD
);
5968 handle_signal ("SIGTTIN", SIGTTIN
);
5971 handle_signal ("SIGTTOU", SIGTTOU
);
5974 handle_signal ("SIGIO", SIGIO
);
5977 handle_signal ("SIGXCPU", SIGXCPU
);
5980 handle_signal ("SIGXFSZ", SIGXFSZ
);
5983 handle_signal ("SIGVTALRM", SIGVTALRM
);
5986 handle_signal ("SIGPROF", SIGPROF
);
5989 handle_signal ("SIGWINCH", SIGWINCH
);
5992 handle_signal ("SIGINFO", SIGINFO
);
5995 handle_signal ("SIGUSR1", SIGUSR1
);
5998 handle_signal ("SIGUSR2", SIGUSR2
);
6001 error ("Undefined signal name %s", name
);
6004 #undef handle_signal
6006 return make_number (kill (XINT (pid
), XINT (sigcode
)));
6009 DEFUN ("process-send-eof", Fprocess_send_eof
, Sprocess_send_eof
, 0, 1, 0,
6010 doc
: /* Make PROCESS see end-of-file in its input.
6011 EOF comes after any text already sent to it.
6012 PROCESS may be a process, a buffer, the name of a process or buffer, or
6013 nil, indicating the current buffer's process.
6014 If PROCESS is a network connection, or is a process communicating
6015 through a pipe (as opposed to a pty), then you cannot send any more
6016 text to PROCESS after you call this function. */)
6018 Lisp_Object process
;
6021 struct coding_system
*coding
;
6023 if (DATAGRAM_CONN_P (process
))
6026 proc
= get_process (process
);
6027 coding
= proc_encode_coding_system
[XINT (XPROCESS (proc
)->outfd
)];
6029 /* Make sure the process is really alive. */
6030 if (! NILP (XPROCESS (proc
)->raw_status_low
))
6031 update_status (XPROCESS (proc
));
6032 if (! EQ (XPROCESS (proc
)->status
, Qrun
))
6033 error ("Process %s not running", SDATA (XPROCESS (proc
)->name
));
6035 if (CODING_REQUIRE_FLUSHING (coding
))
6037 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
6038 send_process (proc
, "", 0, Qnil
);
6042 send_process (proc
, "\032", 1, Qnil
); /* ^z */
6044 if (!NILP (XPROCESS (proc
)->pty_flag
))
6045 send_process (proc
, "\004", 1, Qnil
);
6048 int old_outfd
, new_outfd
;
6050 #ifdef HAVE_SHUTDOWN
6051 /* If this is a network connection, or socketpair is used
6052 for communication with the subprocess, call shutdown to cause EOF.
6053 (In some old system, shutdown to socketpair doesn't work.
6054 Then we just can't win.) */
6055 if (NILP (XPROCESS (proc
)->pid
)
6056 || XINT (XPROCESS (proc
)->outfd
) == XINT (XPROCESS (proc
)->infd
))
6057 shutdown (XINT (XPROCESS (proc
)->outfd
), 1);
6058 /* In case of socketpair, outfd == infd, so don't close it. */
6059 if (XINT (XPROCESS (proc
)->outfd
) != XINT (XPROCESS (proc
)->infd
))
6060 emacs_close (XINT (XPROCESS (proc
)->outfd
));
6061 #else /* not HAVE_SHUTDOWN */
6062 emacs_close (XINT (XPROCESS (proc
)->outfd
));
6063 #endif /* not HAVE_SHUTDOWN */
6064 new_outfd
= emacs_open (NULL_DEVICE
, O_WRONLY
, 0);
6065 old_outfd
= XINT (XPROCESS (proc
)->outfd
);
6067 if (!proc_encode_coding_system
[new_outfd
])
6068 proc_encode_coding_system
[new_outfd
]
6069 = (struct coding_system
*) xmalloc (sizeof (struct coding_system
));
6070 bcopy (proc_encode_coding_system
[old_outfd
],
6071 proc_encode_coding_system
[new_outfd
],
6072 sizeof (struct coding_system
));
6073 bzero (proc_encode_coding_system
[old_outfd
],
6074 sizeof (struct coding_system
));
6076 XSETINT (XPROCESS (proc
)->outfd
, new_outfd
);
6082 /* Kill all processes associated with `buffer'.
6083 If `buffer' is nil, kill all processes */
6086 kill_buffer_processes (buffer
)
6089 Lisp_Object tail
, proc
;
6091 for (tail
= Vprocess_alist
; GC_CONSP (tail
); tail
= XCDR (tail
))
6093 proc
= XCDR (XCAR (tail
));
6094 if (GC_PROCESSP (proc
)
6095 && (NILP (buffer
) || EQ (XPROCESS (proc
)->buffer
, buffer
)))
6097 if (NETCONN_P (proc
))
6098 Fdelete_process (proc
);
6099 else if (XINT (XPROCESS (proc
)->infd
) >= 0)
6100 process_send_signal (proc
, SIGHUP
, Qnil
, 1);
6105 /* On receipt of a signal that a child status has changed, loop asking
6106 about children with changed statuses until the system says there
6109 All we do is change the status; we do not run sentinels or print
6110 notifications. That is saved for the next time keyboard input is
6111 done, in order to avoid timing errors.
6113 ** WARNING: this can be called during garbage collection.
6114 Therefore, it must not be fooled by the presence of mark bits in
6117 ** USG WARNING: Although it is not obvious from the documentation
6118 in signal(2), on a USG system the SIGCLD handler MUST NOT call
6119 signal() before executing at least one wait(), otherwise the
6120 handler will be called again, resulting in an infinite loop. The
6121 relevant portion of the documentation reads "SIGCLD signals will be
6122 queued and the signal-catching function will be continually
6123 reentered until the queue is empty". Invoking signal() causes the
6124 kernel to reexamine the SIGCLD queue. Fred Fish, UniSoft Systems
6127 ** Malloc WARNING: This should never call malloc either directly or
6128 indirectly; if it does, that is a bug */
6131 sigchld_handler (signo
)
6134 int old_errno
= errno
;
6136 register struct Lisp_Process
*p
;
6137 extern EMACS_TIME
*input_available_clear_time
;
6141 sigheld
|= sigbit (SIGCHLD
);
6153 #endif /* no WUNTRACED */
6154 /* Keep trying to get a status until we get a definitive result. */
6158 pid
= wait3 (&w
, WNOHANG
| WUNTRACED
, 0);
6160 while (pid
< 0 && errno
== EINTR
);
6164 /* PID == 0 means no processes found, PID == -1 means a real
6165 failure. We have done all our job, so return. */
6167 /* USG systems forget handlers when they are used;
6168 must reestablish each time */
6169 #if defined (USG) && !defined (POSIX_SIGNALS)
6170 signal (signo
, sigchld_handler
); /* WARNING - must come after wait3() */
6173 sigheld
&= ~sigbit (SIGCHLD
);
6181 #endif /* no WNOHANG */
6183 /* Find the process that signaled us, and record its status. */
6186 for (tail
= Vprocess_alist
; GC_CONSP (tail
); tail
= XCDR (tail
))
6188 proc
= XCDR (XCAR (tail
));
6189 p
= XPROCESS (proc
);
6190 if (GC_EQ (p
->childp
, Qt
) && XINT (p
->pid
) == pid
)
6195 /* Look for an asynchronous process whose pid hasn't been filled
6198 for (tail
= Vprocess_alist
; GC_CONSP (tail
); tail
= XCDR (tail
))
6200 proc
= XCDR (XCAR (tail
));
6201 p
= XPROCESS (proc
);
6202 if (GC_INTEGERP (p
->pid
) && XINT (p
->pid
) == -1)
6207 /* Change the status of the process that was found. */
6210 union { int i
; WAITTYPE wt
; } u
;
6211 int clear_desc_flag
= 0;
6213 XSETINT (p
->tick
, ++process_tick
);
6215 XSETINT (p
->raw_status_low
, u
.i
& 0xffff);
6216 XSETINT (p
->raw_status_high
, u
.i
>> 16);
6218 /* If process has terminated, stop waiting for its output. */
6219 if ((WIFSIGNALED (w
) || WIFEXITED (w
))
6220 && XINT (p
->infd
) >= 0)
6221 clear_desc_flag
= 1;
6223 /* We use clear_desc_flag to avoid a compiler bug in Microsoft C. */
6224 if (clear_desc_flag
)
6226 FD_CLR (XINT (p
->infd
), &input_wait_mask
);
6227 FD_CLR (XINT (p
->infd
), &non_keyboard_wait_mask
);
6230 /* Tell wait_reading_process_input that it needs to wake up and
6232 if (input_available_clear_time
)
6233 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
6236 /* There was no asynchronous process found for that id. Check
6237 if we have a synchronous process. */
6240 synch_process_alive
= 0;
6242 /* Report the status of the synchronous process. */
6244 synch_process_retcode
= WRETCODE (w
);
6245 else if (WIFSIGNALED (w
))
6246 synch_process_termsig
= WTERMSIG (w
);
6248 /* Tell wait_reading_process_input that it needs to wake up and
6250 if (input_available_clear_time
)
6251 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
6254 /* On some systems, we must return right away.
6255 If any more processes want to signal us, we will
6257 Otherwise (on systems that have WNOHANG), loop around
6258 to use up all the processes that have something to tell us. */
6259 #if (defined WINDOWSNT \
6260 || (defined USG && !defined GNU_LINUX \
6261 && !(defined HPUX && defined WNOHANG)))
6262 #if defined (USG) && ! defined (POSIX_SIGNALS)
6263 signal (signo
, sigchld_handler
);
6267 #endif /* USG, but not HPUX with WNOHANG */
6273 exec_sentinel_unwind (data
)
6276 XPROCESS (XCAR (data
))->sentinel
= XCDR (data
);
6281 exec_sentinel_error_handler (error
)
6284 cmd_error_internal (error
, "error in process sentinel: ");
6286 update_echo_area ();
6287 Fsleep_for (make_number (2), Qnil
);
6292 exec_sentinel (proc
, reason
)
6293 Lisp_Object proc
, reason
;
6295 Lisp_Object sentinel
, obuffer
, odeactivate
, okeymap
;
6296 register struct Lisp_Process
*p
= XPROCESS (proc
);
6297 int count
= SPECPDL_INDEX ();
6298 int outer_running_asynch_code
= running_asynch_code
;
6299 int waiting
= waiting_for_user_input_p
;
6301 /* No need to gcpro these, because all we do with them later
6302 is test them for EQness, and none of them should be a string. */
6303 odeactivate
= Vdeactivate_mark
;
6304 XSETBUFFER (obuffer
, current_buffer
);
6305 okeymap
= current_buffer
->keymap
;
6307 sentinel
= p
->sentinel
;
6308 if (NILP (sentinel
))
6311 /* Zilch the sentinel while it's running, to avoid recursive invocations;
6312 assure that it gets restored no matter how the sentinel exits. */
6314 record_unwind_protect (exec_sentinel_unwind
, Fcons (proc
, sentinel
));
6315 /* Inhibit quit so that random quits don't screw up a running filter. */
6316 specbind (Qinhibit_quit
, Qt
);
6317 specbind (Qlast_nonmenu_event
, Qt
);
6319 /* In case we get recursively called,
6320 and we already saved the match data nonrecursively,
6321 save the same match data in safely recursive fashion. */
6322 if (outer_running_asynch_code
)
6325 tem
= Fmatch_data (Qnil
, Qnil
);
6326 restore_match_data ();
6327 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6328 Fset_match_data (tem
);
6331 /* For speed, if a search happens within this code,
6332 save the match data in a special nonrecursive fashion. */
6333 running_asynch_code
= 1;
6335 internal_condition_case_1 (read_process_output_call
,
6337 Fcons (proc
, Fcons (reason
, Qnil
))),
6338 !NILP (Vdebug_on_error
) ? Qnil
: Qerror
,
6339 exec_sentinel_error_handler
);
6341 /* If we saved the match data nonrecursively, restore it now. */
6342 restore_match_data ();
6343 running_asynch_code
= outer_running_asynch_code
;
6345 Vdeactivate_mark
= odeactivate
;
6347 /* Restore waiting_for_user_input_p as it was
6348 when we were called, in case the filter clobbered it. */
6349 waiting_for_user_input_p
= waiting
;
6352 if (! EQ (Fcurrent_buffer (), obuffer
)
6353 || ! EQ (current_buffer
->keymap
, okeymap
))
6355 /* But do it only if the caller is actually going to read events.
6356 Otherwise there's no need to make him wake up, and it could
6357 cause trouble (for example it would make Fsit_for return). */
6358 if (waiting_for_user_input_p
== -1)
6359 record_asynch_buffer_change ();
6361 unbind_to (count
, Qnil
);
6364 /* Report all recent events of a change in process status
6365 (either run the sentinel or output a message).
6366 This is usually done while Emacs is waiting for keyboard input
6367 but can be done at other times. */
6372 register Lisp_Object proc
, buffer
;
6373 Lisp_Object tail
, msg
;
6374 struct gcpro gcpro1
, gcpro2
;
6378 /* We need to gcpro tail; if read_process_output calls a filter
6379 which deletes a process and removes the cons to which tail points
6380 from Vprocess_alist, and then causes a GC, tail is an unprotected
6384 /* Set this now, so that if new processes are created by sentinels
6385 that we run, we get called again to handle their status changes. */
6386 update_tick
= process_tick
;
6388 for (tail
= Vprocess_alist
; !NILP (tail
); tail
= Fcdr (tail
))
6391 register struct Lisp_Process
*p
;
6393 proc
= Fcdr (Fcar (tail
));
6394 p
= XPROCESS (proc
);
6396 if (XINT (p
->tick
) != XINT (p
->update_tick
))
6398 XSETINT (p
->update_tick
, XINT (p
->tick
));
6400 /* If process is still active, read any output that remains. */
6401 while (! EQ (p
->filter
, Qt
)
6402 && ! EQ (p
->status
, Qconnect
)
6403 && ! EQ (p
->status
, Qlisten
)
6404 && ! EQ (p
->command
, Qt
) /* Network process not stopped. */
6405 && XINT (p
->infd
) >= 0
6406 && read_process_output (proc
, XINT (p
->infd
)) > 0);
6410 /* Get the text to use for the message. */
6411 if (!NILP (p
->raw_status_low
))
6413 msg
= status_message (p
);
6415 /* If process is terminated, deactivate it or delete it. */
6417 if (CONSP (p
->status
))
6418 symbol
= XCAR (p
->status
);
6420 if (EQ (symbol
, Qsignal
) || EQ (symbol
, Qexit
)
6421 || EQ (symbol
, Qclosed
))
6423 if (delete_exited_processes
)
6424 remove_process (proc
);
6426 deactivate_process (proc
);
6429 /* The actions above may have further incremented p->tick.
6430 So set p->update_tick again
6431 so that an error in the sentinel will not cause
6432 this code to be run again. */
6433 XSETINT (p
->update_tick
, XINT (p
->tick
));
6434 /* Now output the message suitably. */
6435 if (!NILP (p
->sentinel
))
6436 exec_sentinel (proc
, msg
);
6437 /* Don't bother with a message in the buffer
6438 when a process becomes runnable. */
6439 else if (!EQ (symbol
, Qrun
) && !NILP (buffer
))
6441 Lisp_Object ro
, tem
;
6442 struct buffer
*old
= current_buffer
;
6443 int opoint
, opoint_byte
;
6444 int before
, before_byte
;
6446 ro
= XBUFFER (buffer
)->read_only
;
6448 /* Avoid error if buffer is deleted
6449 (probably that's why the process is dead, too) */
6450 if (NILP (XBUFFER (buffer
)->name
))
6452 Fset_buffer (buffer
);
6455 opoint_byte
= PT_BYTE
;
6456 /* Insert new output into buffer
6457 at the current end-of-output marker,
6458 thus preserving logical ordering of input and output. */
6459 if (XMARKER (p
->mark
)->buffer
)
6460 Fgoto_char (p
->mark
);
6462 SET_PT_BOTH (ZV
, ZV_BYTE
);
6465 before_byte
= PT_BYTE
;
6467 tem
= current_buffer
->read_only
;
6468 current_buffer
->read_only
= Qnil
;
6469 insert_string ("\nProcess ");
6470 Finsert (1, &p
->name
);
6471 insert_string (" ");
6473 current_buffer
->read_only
= tem
;
6474 set_marker_both (p
->mark
, p
->buffer
, PT
, PT_BYTE
);
6476 if (opoint
>= before
)
6477 SET_PT_BOTH (opoint
+ (PT
- before
),
6478 opoint_byte
+ (PT_BYTE
- before_byte
));
6480 SET_PT_BOTH (opoint
, opoint_byte
);
6482 set_buffer_internal (old
);
6487 update_mode_lines
++; /* in case buffers use %s in mode-line-format */
6488 redisplay_preserve_echo_area (13);
6494 DEFUN ("set-process-coding-system", Fset_process_coding_system
,
6495 Sset_process_coding_system
, 1, 3, 0,
6496 doc
: /* Set coding systems of PROCESS to DECODING and ENCODING.
6497 DECODING will be used to decode subprocess output and ENCODING to
6498 encode subprocess input. */)
6499 (process
, decoding
, encoding
)
6500 register Lisp_Object process
, decoding
, encoding
;
6502 register struct Lisp_Process
*p
;
6504 CHECK_PROCESS (process
);
6505 p
= XPROCESS (process
);
6506 if (XINT (p
->infd
) < 0)
6507 error ("Input file descriptor of %s closed", SDATA (p
->name
));
6508 if (XINT (p
->outfd
) < 0)
6509 error ("Output file descriptor of %s closed", SDATA (p
->name
));
6510 Fcheck_coding_system (decoding
);
6511 Fcheck_coding_system (encoding
);
6513 p
->decode_coding_system
= decoding
;
6514 p
->encode_coding_system
= encoding
;
6515 setup_process_coding_systems (process
);
6520 DEFUN ("process-coding-system",
6521 Fprocess_coding_system
, Sprocess_coding_system
, 1, 1, 0,
6522 doc
: /* Return a cons of coding systems for decoding and encoding of PROCESS. */)
6524 register Lisp_Object process
;
6526 CHECK_PROCESS (process
);
6527 return Fcons (XPROCESS (process
)->decode_coding_system
,
6528 XPROCESS (process
)->encode_coding_system
);
6531 DEFUN ("set-process-filter-multibyte", Fset_process_filter_multibyte
,
6532 Sset_process_filter_multibyte
, 2, 2, 0,
6533 doc
: /* Set multibyteness of the strings given to PROCESS's filter.
6534 If FLAG is non-nil, the filter is given multibyte strings.
6535 If FLAG is nil, the filter is given unibyte strings. In this case,
6536 all character code conversion except for end-of-line conversion is
6539 Lisp_Object process
, flag
;
6541 register struct Lisp_Process
*p
;
6543 CHECK_PROCESS (process
);
6544 p
= XPROCESS (process
);
6545 p
->filter_multibyte
= flag
;
6546 setup_process_coding_systems (process
);
6551 DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p
,
6552 Sprocess_filter_multibyte_p
, 1, 1, 0,
6553 doc
: /* Return t if a multibyte string is given to PROCESS's filter.*/)
6555 Lisp_Object process
;
6557 register struct Lisp_Process
*p
;
6559 CHECK_PROCESS (process
);
6560 p
= XPROCESS (process
);
6562 return (NILP (p
->filter_multibyte
) ? Qnil
: Qt
);
6567 /* The first time this is called, assume keyboard input comes from DESC
6568 instead of from where we used to expect it.
6569 Subsequent calls mean assume input keyboard can come from DESC
6570 in addition to other places. */
6572 static int add_keyboard_wait_descriptor_called_flag
;
6575 add_keyboard_wait_descriptor (desc
)
6578 if (! add_keyboard_wait_descriptor_called_flag
)
6579 FD_CLR (0, &input_wait_mask
);
6580 add_keyboard_wait_descriptor_called_flag
= 1;
6581 FD_SET (desc
, &input_wait_mask
);
6582 FD_SET (desc
, &non_process_wait_mask
);
6583 if (desc
> max_keyboard_desc
)
6584 max_keyboard_desc
= desc
;
6587 /* From now on, do not expect DESC to give keyboard input. */
6590 delete_keyboard_wait_descriptor (desc
)
6594 int lim
= max_keyboard_desc
;
6596 FD_CLR (desc
, &input_wait_mask
);
6597 FD_CLR (desc
, &non_process_wait_mask
);
6599 if (desc
== max_keyboard_desc
)
6600 for (fd
= 0; fd
< lim
; fd
++)
6601 if (FD_ISSET (fd
, &input_wait_mask
)
6602 && !FD_ISSET (fd
, &non_keyboard_wait_mask
))
6603 max_keyboard_desc
= fd
;
6606 /* Return nonzero if *MASK has a bit set
6607 that corresponds to one of the keyboard input descriptors. */
6610 keyboard_bit_set (mask
)
6615 for (fd
= 0; fd
<= max_keyboard_desc
; fd
++)
6616 if (FD_ISSET (fd
, mask
) && FD_ISSET (fd
, &input_wait_mask
)
6617 && !FD_ISSET (fd
, &non_keyboard_wait_mask
))
6630 if (! noninteractive
|| initialized
)
6632 signal (SIGCHLD
, sigchld_handler
);
6635 FD_ZERO (&input_wait_mask
);
6636 FD_ZERO (&non_keyboard_wait_mask
);
6637 FD_ZERO (&non_process_wait_mask
);
6638 max_process_desc
= 0;
6640 #ifdef ADAPTIVE_READ_BUFFERING
6641 process_output_delay_count
= 0;
6642 process_output_skip
= 0;
6645 FD_SET (0, &input_wait_mask
);
6647 Vprocess_alist
= Qnil
;
6648 for (i
= 0; i
< MAXDESC
; i
++)
6650 chan_process
[i
] = Qnil
;
6651 proc_buffered_char
[i
] = -1;
6653 bzero (proc_decode_coding_system
, sizeof proc_decode_coding_system
);
6654 bzero (proc_encode_coding_system
, sizeof proc_encode_coding_system
);
6655 #ifdef DATAGRAM_SOCKETS
6656 bzero (datagram_address
, sizeof datagram_address
);
6661 Lisp_Object subfeatures
= Qnil
;
6662 struct socket_options
*sopt
;
6664 #define ADD_SUBFEATURE(key, val) \
6665 subfeatures = Fcons (Fcons (key, Fcons (val, Qnil)), subfeatures)
6667 #ifdef NON_BLOCKING_CONNECT
6668 ADD_SUBFEATURE (QCnowait
, Qt
);
6670 #ifdef DATAGRAM_SOCKETS
6671 ADD_SUBFEATURE (QCtype
, Qdatagram
);
6673 #ifdef HAVE_LOCAL_SOCKETS
6674 ADD_SUBFEATURE (QCfamily
, Qlocal
);
6676 #ifdef HAVE_GETSOCKNAME
6677 ADD_SUBFEATURE (QCservice
, Qt
);
6679 #if !defined(TERM) && (defined(O_NONBLOCK) || defined(O_NDELAY))
6680 ADD_SUBFEATURE (QCserver
, Qt
);
6683 for (sopt
= socket_options
; sopt
->name
; sopt
++)
6684 subfeatures
= Fcons (intern (sopt
->name
), subfeatures
);
6686 Fprovide (intern ("make-network-process"), subfeatures
);
6688 #endif /* HAVE_SOCKETS */
6694 Qprocessp
= intern ("processp");
6695 staticpro (&Qprocessp
);
6696 Qrun
= intern ("run");
6698 Qstop
= intern ("stop");
6700 Qsignal
= intern ("signal");
6701 staticpro (&Qsignal
);
6703 /* Qexit is already staticpro'd by syms_of_eval; don't staticpro it
6706 Qexit = intern ("exit");
6707 staticpro (&Qexit); */
6709 Qopen
= intern ("open");
6711 Qclosed
= intern ("closed");
6712 staticpro (&Qclosed
);
6713 Qconnect
= intern ("connect");
6714 staticpro (&Qconnect
);
6715 Qfailed
= intern ("failed");
6716 staticpro (&Qfailed
);
6717 Qlisten
= intern ("listen");
6718 staticpro (&Qlisten
);
6719 Qlocal
= intern ("local");
6720 staticpro (&Qlocal
);
6721 Qdatagram
= intern ("datagram");
6722 staticpro (&Qdatagram
);
6724 QCname
= intern (":name");
6725 staticpro (&QCname
);
6726 QCbuffer
= intern (":buffer");
6727 staticpro (&QCbuffer
);
6728 QChost
= intern (":host");
6729 staticpro (&QChost
);
6730 QCservice
= intern (":service");
6731 staticpro (&QCservice
);
6732 QCtype
= intern (":type");
6733 staticpro (&QCtype
);
6734 QClocal
= intern (":local");
6735 staticpro (&QClocal
);
6736 QCremote
= intern (":remote");
6737 staticpro (&QCremote
);
6738 QCcoding
= intern (":coding");
6739 staticpro (&QCcoding
);
6740 QCserver
= intern (":server");
6741 staticpro (&QCserver
);
6742 QCnowait
= intern (":nowait");
6743 staticpro (&QCnowait
);
6744 QCsentinel
= intern (":sentinel");
6745 staticpro (&QCsentinel
);
6746 QClog
= intern (":log");
6748 QCnoquery
= intern (":noquery");
6749 staticpro (&QCnoquery
);
6750 QCstop
= intern (":stop");
6751 staticpro (&QCstop
);
6752 QCoptions
= intern (":options");
6753 staticpro (&QCoptions
);
6754 QCplist
= intern (":plist");
6755 staticpro (&QCplist
);
6756 QCfilter_multibyte
= intern (":filter-multibyte");
6757 staticpro (&QCfilter_multibyte
);
6759 Qlast_nonmenu_event
= intern ("last-nonmenu-event");
6760 staticpro (&Qlast_nonmenu_event
);
6762 staticpro (&Vprocess_alist
);
6764 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes
,
6765 doc
: /* *Non-nil means delete processes immediately when they exit.
6766 nil means don't delete them until `list-processes' is run. */);
6768 delete_exited_processes
= 1;
6770 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type
,
6771 doc
: /* Control type of device used to communicate with subprocesses.
6772 Values are nil to use a pipe, or t or `pty' to use a pty.
6773 The value has no effect if the system has no ptys or if all ptys are busy:
6774 then a pipe is used in any case.
6775 The value takes effect when `start-process' is called. */);
6776 Vprocess_connection_type
= Qt
;
6778 #ifdef ADAPTIVE_READ_BUFFERING
6779 DEFVAR_LISP ("process-adaptive-read-buffering", &Vprocess_adaptive_read_buffering
,
6780 doc
: /* If non-nil, improve receive buffering by delaying after short reads.
6781 On some systems, when Emacs reads the output from a subprocess, the output data
6782 is read in very small blocks, potentially resulting in very poor performance.
6783 This behaviour can be remedied to some extent by setting this variable to a
6784 non-nil value, as it will automatically delay reading from such processes, to
6785 allowing them to produce more output before Emacs tries to read it.
6786 If the value is t, the delay is reset after each write to the process; any other
6787 non-nil value means that the delay is not reset on write.
6788 The variable takes effect when `start-process' is called. */);
6789 Vprocess_adaptive_read_buffering
= Qt
;
6792 defsubr (&Sprocessp
);
6793 defsubr (&Sget_process
);
6794 defsubr (&Sget_buffer_process
);
6795 defsubr (&Sdelete_process
);
6796 defsubr (&Sprocess_status
);
6797 defsubr (&Sprocess_exit_status
);
6798 defsubr (&Sprocess_id
);
6799 defsubr (&Sprocess_name
);
6800 defsubr (&Sprocess_tty_name
);
6801 defsubr (&Sprocess_command
);
6802 defsubr (&Sset_process_buffer
);
6803 defsubr (&Sprocess_buffer
);
6804 defsubr (&Sprocess_mark
);
6805 defsubr (&Sset_process_filter
);
6806 defsubr (&Sprocess_filter
);
6807 defsubr (&Sset_process_sentinel
);
6808 defsubr (&Sprocess_sentinel
);
6809 defsubr (&Sset_process_window_size
);
6810 defsubr (&Sset_process_inherit_coding_system_flag
);
6811 defsubr (&Sprocess_inherit_coding_system_flag
);
6812 defsubr (&Sset_process_query_on_exit_flag
);
6813 defsubr (&Sprocess_query_on_exit_flag
);
6814 defsubr (&Sprocess_contact
);
6815 defsubr (&Sprocess_plist
);
6816 defsubr (&Sset_process_plist
);
6817 defsubr (&Slist_processes
);
6818 defsubr (&Sprocess_list
);
6819 defsubr (&Sstart_process
);
6821 defsubr (&Sset_network_process_option
);
6822 defsubr (&Smake_network_process
);
6823 defsubr (&Sformat_network_address
);
6824 #endif /* HAVE_SOCKETS */
6825 #if defined(HAVE_SOCKETS) && defined(HAVE_NET_IF_H) && defined(HAVE_SYS_IOCTL_H)
6827 defsubr (&Snetwork_interface_list
);
6829 #if defined(SIOCGIFADDR) || defined(SIOCGIFHWADDR) || defined(SIOCGIFFLAGS)
6830 defsubr (&Snetwork_interface_info
);
6832 #endif /* HAVE_SOCKETS ... */
6833 #ifdef DATAGRAM_SOCKETS
6834 defsubr (&Sprocess_datagram_address
);
6835 defsubr (&Sset_process_datagram_address
);
6837 defsubr (&Saccept_process_output
);
6838 defsubr (&Sprocess_send_region
);
6839 defsubr (&Sprocess_send_string
);
6840 defsubr (&Sinterrupt_process
);
6841 defsubr (&Skill_process
);
6842 defsubr (&Squit_process
);
6843 defsubr (&Sstop_process
);
6844 defsubr (&Scontinue_process
);
6845 defsubr (&Sprocess_running_child_p
);
6846 defsubr (&Sprocess_send_eof
);
6847 defsubr (&Ssignal_process
);
6848 defsubr (&Swaiting_for_user_input_p
);
6849 /* defsubr (&Sprocess_connection); */
6850 defsubr (&Sset_process_coding_system
);
6851 defsubr (&Sprocess_coding_system
);
6852 defsubr (&Sset_process_filter_multibyte
);
6853 defsubr (&Sprocess_filter_multibyte_p
);
6857 #else /* not subprocesses */
6859 #include <sys/types.h>
6863 #include "systime.h"
6864 #include "charset.h"
6866 #include "termopts.h"
6867 #include "sysselect.h"
6869 extern int frame_garbaged
;
6871 extern EMACS_TIME
timer_check ();
6872 extern int timers_run
;
6876 /* As described above, except assuming that there are no subprocesses:
6878 Wait for timeout to elapse and/or keyboard input to be available.
6881 timeout in seconds, or
6882 zero for no limit, or
6883 -1 means gobble data immediately available but don't wait for any.
6885 read_kbd is a Lisp_Object:
6886 0 to ignore keyboard input, or
6887 1 to return when input is available, or
6888 -1 means caller will actually read the input, so don't throw to
6890 a cons cell, meaning wait until its car is non-nil
6891 (and gobble terminal input into the buffer if any arrives), or
6892 We know that read_kbd will never be a Lisp_Process, since
6893 `subprocesses' isn't defined.
6895 do_display != 0 means redisplay should be done to show subprocess
6896 output that arrives.
6898 Return true iff we received input from any process. */
6901 wait_reading_process_input (time_limit
, microsecs
, read_kbd
, do_display
)
6902 int time_limit
, microsecs
;
6903 Lisp_Object read_kbd
;
6907 EMACS_TIME end_time
, timeout
;
6908 SELECT_TYPE waitchannels
;
6910 /* Either nil or a cons cell, the car of which is of interest and
6911 may be changed outside of this routine. */
6912 Lisp_Object wait_for_cell
;
6914 wait_for_cell
= Qnil
;
6916 /* If waiting for non-nil in a cell, record where. */
6917 if (CONSP (read_kbd
))
6919 wait_for_cell
= read_kbd
;
6920 XSETFASTINT (read_kbd
, 0);
6923 /* What does time_limit really mean? */
6924 if (time_limit
|| microsecs
)
6926 EMACS_GET_TIME (end_time
);
6927 EMACS_SET_SECS_USECS (timeout
, time_limit
, microsecs
);
6928 EMACS_ADD_TIME (end_time
, end_time
, timeout
);
6931 /* Turn off periodic alarms (in case they are in use)
6932 and then turn off any other atimers,
6933 because the select emulator uses alarms. */
6935 turn_on_atimers (0);
6939 int timeout_reduced_for_timers
= 0;
6941 /* If calling from keyboard input, do not quit
6942 since we want to return C-g as an input character.
6943 Otherwise, do pending quit if requested. */
6944 if (XINT (read_kbd
) >= 0)
6947 /* Exit now if the cell we're waiting for became non-nil. */
6948 if (! NILP (wait_for_cell
) && ! NILP (XCAR (wait_for_cell
)))
6951 /* Compute time from now till when time limit is up */
6952 /* Exit if already run out */
6953 if (time_limit
== -1)
6955 /* -1 specified for timeout means
6956 gobble output available now
6957 but don't wait at all. */
6959 EMACS_SET_SECS_USECS (timeout
, 0, 0);
6961 else if (time_limit
|| microsecs
)
6963 EMACS_GET_TIME (timeout
);
6964 EMACS_SUB_TIME (timeout
, end_time
, timeout
);
6965 if (EMACS_TIME_NEG_P (timeout
))
6970 EMACS_SET_SECS_USECS (timeout
, 100000, 0);
6973 /* If our caller will not immediately handle keyboard events,
6974 run timer events directly.
6975 (Callers that will immediately read keyboard events
6976 call timer_delay on their own.) */
6977 if (NILP (wait_for_cell
))
6979 EMACS_TIME timer_delay
;
6983 int old_timers_run
= timers_run
;
6984 timer_delay
= timer_check (1);
6985 if (timers_run
!= old_timers_run
&& do_display
)
6986 /* We must retry, since a timer may have requeued itself
6987 and that could alter the time delay. */
6988 redisplay_preserve_echo_area (14);
6992 while (!detect_input_pending ());
6994 /* If there is unread keyboard input, also return. */
6995 if (XINT (read_kbd
) != 0
6996 && requeued_events_pending_p ())
6999 if (! EMACS_TIME_NEG_P (timer_delay
) && time_limit
!= -1)
7001 EMACS_TIME difference
;
7002 EMACS_SUB_TIME (difference
, timer_delay
, timeout
);
7003 if (EMACS_TIME_NEG_P (difference
))
7005 timeout
= timer_delay
;
7006 timeout_reduced_for_timers
= 1;
7011 /* Cause C-g and alarm signals to take immediate action,
7012 and cause input available signals to zero out timeout. */
7013 if (XINT (read_kbd
) < 0)
7014 set_waiting_for_input (&timeout
);
7016 /* Wait till there is something to do. */
7018 if (! XINT (read_kbd
) && NILP (wait_for_cell
))
7019 FD_ZERO (&waitchannels
);
7021 FD_SET (0, &waitchannels
);
7023 /* If a frame has been newly mapped and needs updating,
7024 reprocess its display stuff. */
7025 if (frame_garbaged
&& do_display
)
7027 clear_waiting_for_input ();
7028 redisplay_preserve_echo_area (15);
7029 if (XINT (read_kbd
) < 0)
7030 set_waiting_for_input (&timeout
);
7033 if (XINT (read_kbd
) && detect_input_pending ())
7036 FD_ZERO (&waitchannels
);
7039 nfds
= select (1, &waitchannels
, (SELECT_TYPE
*)0, (SELECT_TYPE
*)0,
7044 /* Make C-g and alarm signals set flags again */
7045 clear_waiting_for_input ();
7047 /* If we woke up due to SIGWINCH, actually change size now. */
7048 do_pending_window_change (0);
7050 if (time_limit
&& nfds
== 0 && ! timeout_reduced_for_timers
)
7051 /* We waited the full specified time, so return now. */
7056 /* If the system call was interrupted, then go around the
7058 if (xerrno
== EINTR
)
7059 FD_ZERO (&waitchannels
);
7061 error ("select error: %s", emacs_strerror (xerrno
));
7064 else if (nfds
> 0 && (waitchannels
& 1) && interrupt_input
)
7065 /* System sometimes fails to deliver SIGIO. */
7066 kill (getpid (), SIGIO
);
7069 if (XINT (read_kbd
) && interrupt_input
&& (waitchannels
& 1))
7070 kill (getpid (), SIGIO
);
7073 /* Check for keyboard input */
7075 if ((XINT (read_kbd
) != 0)
7076 && detect_input_pending_run_timers (do_display
))
7078 swallow_events (do_display
);
7079 if (detect_input_pending_run_timers (do_display
))
7083 /* If there is unread keyboard input, also return. */
7084 if (XINT (read_kbd
) != 0
7085 && requeued_events_pending_p ())
7088 /* If wait_for_cell. check for keyboard input
7089 but don't run any timers.
7090 ??? (It seems wrong to me to check for keyboard
7091 input at all when wait_for_cell, but the code
7092 has been this way since July 1994.
7093 Try changing this after version 19.31.) */
7094 if (! NILP (wait_for_cell
)
7095 && detect_input_pending ())
7097 swallow_events (do_display
);
7098 if (detect_input_pending ())
7102 /* Exit now if the cell we're waiting for became non-nil. */
7103 if (! NILP (wait_for_cell
) && ! NILP (XCAR (wait_for_cell
)))
7113 /* Don't confuse make-docfile by having two doc strings for this function.
7114 make-docfile does not pay attention to #if, for good reason! */
7115 DEFUN ("get-buffer-process", Fget_buffer_process
, Sget_buffer_process
, 1, 1, 0,
7118 register Lisp_Object name
;
7123 /* Don't confuse make-docfile by having two doc strings for this function.
7124 make-docfile does not pay attention to #if, for good reason! */
7125 DEFUN ("process-inherit-coding-system-flag",
7126 Fprocess_inherit_coding_system_flag
, Sprocess_inherit_coding_system_flag
,
7130 register Lisp_Object process
;
7132 /* Ignore the argument and return the value of
7133 inherit-process-coding-system. */
7134 return inherit_process_coding_system
? Qt
: Qnil
;
7137 /* Kill all processes associated with `buffer'.
7138 If `buffer' is nil, kill all processes.
7139 Since we have no subprocesses, this does nothing. */
7142 kill_buffer_processes (buffer
)
7155 QCtype
= intern (":type");
7156 staticpro (&QCtype
);
7158 defsubr (&Sget_buffer_process
);
7159 defsubr (&Sprocess_inherit_coding_system_flag
);
7163 #endif /* not subprocesses */
7165 /* arch-tag: 3706c011-7b9a-4117-bd4f-59e7f701a4c4
7166 (do not change this comment) */