1 /* Asynchronous subprocess control for GNU Emacs.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1996, 1998, 1999, 2001, 2002, 2003, 2004,
4 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
25 /* This file is split into two parts by the following preprocessor
26 conditional. The 'then' clause contains all of the support for
27 asynchronous subprocesses. The 'else' clause contains stub
28 versions of some of the asynchronous subprocess routines that are
29 often called elsewhere in Emacs, so we don't have to #ifdef the
30 sections that call them. */
38 #include <sys/types.h> /* some typedefs are used in sys/file.h */
41 #ifdef HAVE_INTTYPES_H
53 #ifdef HAVE_SOCKETS /* TCP connection support, if kernel can do it */
54 #include <sys/socket.h>
56 #include <netinet/in.h>
57 #include <arpa/inet.h>
59 /* Are local (unix) sockets supported? */
60 #if defined (HAVE_SYS_UN_H)
61 #if !defined (AF_LOCAL) && defined (AF_UNIX)
62 #define AF_LOCAL AF_UNIX
65 #define HAVE_LOCAL_SOCKETS
69 #endif /* HAVE_SOCKETS */
71 #if defined(BSD_SYSTEM)
72 #include <sys/ioctl.h>
73 #if !defined (O_NDELAY) && defined (HAVE_PTYS) && !defined(USG5)
75 #endif /* HAVE_PTYS and no O_NDELAY */
76 #endif /* BSD_SYSTEM */
82 /* Can we use SIOCGIFCONF and/or SIOCGIFADDR */
84 #if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_NET_IF_H)
85 /* sys/ioctl.h may have been included already */
87 #include <sys/ioctl.h>
98 #include <netinet/in.h>
99 #include <arpa/nameser.h>
109 #include "character.h"
113 #include "termhooks.h"
114 #include "termopts.h"
115 #include "commands.h"
116 #include "keyboard.h"
117 #include "blockinput.h"
118 #include "dispextern.h"
119 #include "composite.h"
122 Lisp_Object Qprocessp
;
123 Lisp_Object Qrun
, Qstop
, Qsignal
;
124 Lisp_Object Qopen
, Qclosed
, Qconnect
, Qfailed
, Qlisten
;
125 Lisp_Object Qlocal
, Qipv4
, Qdatagram
;
126 Lisp_Object Qreal
, Qnetwork
, Qserial
;
130 Lisp_Object QCport
, QCspeed
, QCprocess
;
131 Lisp_Object QCbytesize
, QCstopbits
, QCparity
, Qodd
, Qeven
;
132 Lisp_Object QCflowcontrol
, Qhw
, Qsw
, QCsummary
;
133 Lisp_Object QCname
, QCbuffer
, QChost
, QCservice
, QCtype
;
134 Lisp_Object QClocal
, QCremote
, QCcoding
;
135 Lisp_Object QCserver
, QCnowait
, QCnoquery
, QCstop
;
136 Lisp_Object QCsentinel
, QClog
, QCoptions
, QCplist
;
137 Lisp_Object Qlast_nonmenu_event
;
138 /* QCfamily is declared and initialized in xfaces.c,
139 QCfilter in keyboard.c. */
140 extern Lisp_Object QCfamily
, QCfilter
;
142 /* Qexit is declared and initialized in eval.c. */
144 /* QCfamily is defined in xfaces.c. */
145 extern Lisp_Object QCfamily
;
146 /* QCfilter is defined in keyboard.c. */
147 extern Lisp_Object QCfilter
;
149 Lisp_Object Qeuid
, Qegid
, Qcomm
, Qstate
, Qppid
, Qpgrp
, Qsess
, Qttname
, Qtpgid
;
150 Lisp_Object Qminflt
, Qmajflt
, Qcminflt
, Qcmajflt
, Qutime
, Qstime
, Qcstime
;
151 Lisp_Object Qcutime
, Qpri
, Qnice
, Qthcount
, Qstart
, Qvsize
, Qrss
, Qargs
;
152 Lisp_Object Quser
, Qgroup
, Qetime
, Qpcpu
, Qpmem
, Qtime
, Qctime
;
155 #define NETCONN_P(p) (EQ (XPROCESS (p)->type, Qnetwork))
156 #define NETCONN1_P(p) (EQ ((p)->type, Qnetwork))
157 #define SERIALCONN_P(p) (EQ (XPROCESS (p)->type, Qserial))
158 #define SERIALCONN1_P(p) (EQ ((p)->type, Qserial))
160 #define NETCONN_P(p) 0
161 #define NETCONN1_P(p) 0
162 #define SERIALCONN_P(p) 0
163 #define SERIALCONN1_P(p) 0
164 #endif /* HAVE_SOCKETS */
166 /* Define first descriptor number available for subprocesses. */
167 #define FIRST_PROC_DESC 3
169 /* Define SIGCHLD as an alias for SIGCLD. There are many conditionals
172 #if !defined (SIGCHLD) && defined (SIGCLD)
173 #define SIGCHLD SIGCLD
176 #include "syssignal.h"
180 extern char *get_operating_system_release ();
182 /* Serial processes require termios or Windows. */
183 #if defined (HAVE_TERMIOS) || defined (WINDOWSNT)
188 /* From sysdep.c or w32.c */
189 extern int serial_open (char *port
);
190 extern void serial_configure (struct Lisp_Process
*p
, Lisp_Object contact
);
201 /* t means use pty, nil means use a pipe,
202 maybe other values to come. */
203 static Lisp_Object Vprocess_connection_type
;
205 /* These next two vars are non-static since sysdep.c uses them in the
206 emulation of `select'. */
207 /* Number of events of change of status of a process. */
209 /* Number of events for which the user or sentinel has been notified. */
212 /* Define NON_BLOCKING_CONNECT if we can support non-blocking connects. */
214 #ifdef BROKEN_NON_BLOCKING_CONNECT
215 #undef NON_BLOCKING_CONNECT
217 #ifndef NON_BLOCKING_CONNECT
220 #if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX)
221 #if defined (O_NONBLOCK) || defined (O_NDELAY)
222 #if defined (EWOULDBLOCK) || defined (EINPROGRESS)
223 #define NON_BLOCKING_CONNECT
224 #endif /* EWOULDBLOCK || EINPROGRESS */
225 #endif /* O_NONBLOCK || O_NDELAY */
226 #endif /* HAVE_GETPEERNAME || GNU_LINUX */
227 #endif /* HAVE_SELECT */
228 #endif /* HAVE_SOCKETS */
229 #endif /* NON_BLOCKING_CONNECT */
230 #endif /* BROKEN_NON_BLOCKING_CONNECT */
232 /* Define DATAGRAM_SOCKETS if datagrams can be used safely on
233 this system. We need to read full packets, so we need a
234 "non-destructive" select. So we require either native select,
235 or emulation of select using FIONREAD. */
237 #ifdef BROKEN_DATAGRAM_SOCKETS
238 #undef DATAGRAM_SOCKETS
240 #ifndef DATAGRAM_SOCKETS
242 #if defined (HAVE_SELECT) || defined (FIONREAD)
243 #if defined (HAVE_SENDTO) && defined (HAVE_RECVFROM) && defined (EMSGSIZE)
244 #define DATAGRAM_SOCKETS
245 #endif /* HAVE_SENDTO && HAVE_RECVFROM && EMSGSIZE */
246 #endif /* HAVE_SELECT || FIONREAD */
247 #endif /* HAVE_SOCKETS */
248 #endif /* DATAGRAM_SOCKETS */
249 #endif /* BROKEN_DATAGRAM_SOCKETS */
251 #if !defined (ADAPTIVE_READ_BUFFERING) && !defined (NO_ADAPTIVE_READ_BUFFERING)
252 #ifdef EMACS_HAS_USECS
253 #define ADAPTIVE_READ_BUFFERING
257 #ifdef ADAPTIVE_READ_BUFFERING
258 #define READ_OUTPUT_DELAY_INCREMENT 10000
259 #define READ_OUTPUT_DELAY_MAX (READ_OUTPUT_DELAY_INCREMENT * 5)
260 #define READ_OUTPUT_DELAY_MAX_MAX (READ_OUTPUT_DELAY_INCREMENT * 7)
262 /* Number of processes which have a non-zero read_output_delay,
263 and therefore might be delayed for adaptive read buffering. */
265 static int process_output_delay_count
;
267 /* Non-zero if any process has non-nil read_output_skip. */
269 static int process_output_skip
;
271 /* Non-nil means to delay reading process output to improve buffering.
272 A value of t means that delay is reset after each send, any other
273 non-nil value does not reset the delay. A value of nil disables
274 adaptive read buffering completely. */
275 static Lisp_Object Vprocess_adaptive_read_buffering
;
277 #define process_output_delay_count 0
281 #include "sysselect.h"
283 static int keyboard_bit_set
P_ ((SELECT_TYPE
*));
284 static void deactivate_process
P_ ((Lisp_Object
));
285 static void status_notify
P_ ((struct Lisp_Process
*));
286 static int read_process_output
P_ ((Lisp_Object
, int));
288 /* If we support a window system, turn on the code to poll periodically
289 to detect C-g. It isn't actually used when doing interrupt input. */
290 #ifdef HAVE_WINDOW_SYSTEM
291 #define POLL_FOR_INPUT
294 static Lisp_Object
get_process ();
295 static void exec_sentinel ();
297 extern EMACS_TIME
timer_check ();
298 extern int timers_run
;
300 /* Mask of bits indicating the descriptors that we wait for input on. */
302 static SELECT_TYPE input_wait_mask
;
304 /* Mask that excludes keyboard input descriptor(s). */
306 static SELECT_TYPE non_keyboard_wait_mask
;
308 /* Mask that excludes process input descriptor(s). */
310 static SELECT_TYPE non_process_wait_mask
;
312 /* Mask for the gpm mouse input descriptor. */
314 static SELECT_TYPE gpm_wait_mask
;
316 #ifdef NON_BLOCKING_CONNECT
317 /* Mask of bits indicating the descriptors that we wait for connect to
318 complete on. Once they complete, they are removed from this mask
319 and added to the input_wait_mask and non_keyboard_wait_mask. */
321 static SELECT_TYPE connect_wait_mask
;
323 /* Number of bits set in connect_wait_mask. */
324 static int num_pending_connects
;
326 #define IF_NON_BLOCKING_CONNECT(s) s
328 #define IF_NON_BLOCKING_CONNECT(s)
331 /* The largest descriptor currently in use for a process object. */
332 static int max_process_desc
;
334 /* The largest descriptor currently in use for keyboard input. */
335 static int max_keyboard_desc
;
337 /* The largest descriptor currently in use for gpm mouse input. */
338 static int max_gpm_desc
;
340 /* Nonzero means delete a process right away if it exits. */
341 static int delete_exited_processes
;
343 /* Indexed by descriptor, gives the process (if any) for that descriptor */
344 Lisp_Object chan_process
[MAXDESC
];
346 /* Alist of elements (NAME . PROCESS) */
347 Lisp_Object Vprocess_alist
;
349 /* Buffered-ahead input char from process, indexed by channel.
350 -1 means empty (no char is buffered).
351 Used on sys V where the only way to tell if there is any
352 output from the process is to read at least one char.
353 Always -1 on systems that support FIONREAD. */
355 /* Don't make static; need to access externally. */
356 int proc_buffered_char
[MAXDESC
];
358 /* Table of `struct coding-system' for each process. */
359 static struct coding_system
*proc_decode_coding_system
[MAXDESC
];
360 static struct coding_system
*proc_encode_coding_system
[MAXDESC
];
362 #ifdef DATAGRAM_SOCKETS
363 /* Table of `partner address' for datagram sockets. */
364 struct sockaddr_and_len
{
367 } datagram_address
[MAXDESC
];
368 #define DATAGRAM_CHAN_P(chan) (datagram_address[chan].sa != 0)
369 #define DATAGRAM_CONN_P(proc) (PROCESSP (proc) && datagram_address[XPROCESS (proc)->infd].sa != 0)
371 #define DATAGRAM_CHAN_P(chan) (0)
372 #define DATAGRAM_CONN_P(proc) (0)
375 /* Maximum number of bytes to send to a pty without an eof. */
376 static int pty_max_bytes
;
378 /* Nonzero means don't run process sentinels. This is used
380 int inhibit_sentinels
;
386 /* The file name of the pty opened by allocate_pty. */
388 static char pty_name
[24];
391 /* Compute the Lisp form of the process status, p->status, from
392 the numeric status that was returned by `wait'. */
394 static Lisp_Object
status_convert (int);
398 struct Lisp_Process
*p
;
400 eassert (p
->raw_status_new
);
401 p
->status
= status_convert (p
->raw_status
);
402 p
->raw_status_new
= 0;
405 /* Convert a process status word in Unix format to
406 the list that we use internally. */
409 status_convert (int w
)
412 return Fcons (Qstop
, Fcons (make_number (WSTOPSIG (w
)), Qnil
));
413 else if (WIFEXITED (w
))
414 return Fcons (Qexit
, Fcons (make_number (WRETCODE (w
)),
415 WCOREDUMP (w
) ? Qt
: Qnil
));
416 else if (WIFSIGNALED (w
))
417 return Fcons (Qsignal
, Fcons (make_number (WTERMSIG (w
)),
418 WCOREDUMP (w
) ? Qt
: Qnil
));
423 /* Given a status-list, extract the three pieces of information
424 and store them individually through the three pointers. */
427 decode_status (l
, symbol
, code
, coredump
)
445 *code
= XFASTINT (XCAR (tem
));
447 *coredump
= !NILP (tem
);
451 /* Return a string describing a process status list. */
455 struct Lisp_Process
*p
;
457 Lisp_Object status
= p
->status
;
460 Lisp_Object string
, string2
;
462 decode_status (status
, &symbol
, &code
, &coredump
);
464 if (EQ (symbol
, Qsignal
) || EQ (symbol
, Qstop
))
467 synchronize_system_messages_locale ();
468 signame
= strsignal (code
);
471 string
= build_string (signame
);
472 string2
= build_string (coredump
? " (core dumped)\n" : "\n");
473 SSET (string
, 0, DOWNCASE (SREF (string
, 0)));
474 return concat2 (string
, string2
);
476 else if (EQ (symbol
, Qexit
))
479 return build_string (code
== 0 ? "deleted\n" : "connection broken by remote peer\n");
481 return build_string ("finished\n");
482 string
= Fnumber_to_string (make_number (code
));
483 string2
= build_string (coredump
? " (core dumped)\n" : "\n");
484 return concat3 (build_string ("exited abnormally with code "),
487 else if (EQ (symbol
, Qfailed
))
489 string
= Fnumber_to_string (make_number (code
));
490 string2
= build_string ("\n");
491 return concat3 (build_string ("failed with code "),
495 return Fcopy_sequence (Fsymbol_name (symbol
));
500 /* Open an available pty, returning a file descriptor.
501 Return -1 on failure.
502 The file name of the terminal corresponding to the pty
503 is left in the variable pty_name. */
514 for (c
= FIRST_PTY_LETTER
; c
<= 'z'; c
++)
515 for (i
= 0; i
< 16; i
++)
518 struct stat stb
; /* Used in some PTY_OPEN. */
519 #ifdef PTY_NAME_SPRINTF
522 sprintf (pty_name
, "/dev/pty%c%x", c
, i
);
523 #endif /* no PTY_NAME_SPRINTF */
527 #else /* no PTY_OPEN */
529 { /* Some systems name their pseudoterminals so that there are gaps in
530 the usual sequence - for example, on HP9000/S700 systems, there
531 are no pseudoterminals with names ending in 'f'. So we wait for
532 three failures in a row before deciding that we've reached the
534 int failed_count
= 0;
536 if (stat (pty_name
, &stb
) < 0)
539 if (failed_count
>= 3)
546 fd
= emacs_open (pty_name
, O_RDWR
| O_NONBLOCK
, 0);
548 fd
= emacs_open (pty_name
, O_RDWR
| O_NDELAY
, 0);
551 #endif /* no PTY_OPEN */
555 /* check to make certain that both sides are available
556 this avoids a nasty yet stupid bug in rlogins */
557 #ifdef PTY_TTY_NAME_SPRINTF
560 sprintf (pty_name
, "/dev/tty%c%x", c
, i
);
561 #endif /* no PTY_TTY_NAME_SPRINTF */
562 if (access (pty_name
, 6) != 0)
577 #endif /* HAVE_PTYS */
583 register Lisp_Object val
, tem
, name1
;
584 register struct Lisp_Process
*p
;
588 p
= allocate_process ();
596 p
->raw_status_new
= 0;
598 p
->mark
= Fmake_marker ();
599 p
->kill_without_query
= 0;
601 #ifdef ADAPTIVE_READ_BUFFERING
602 p
->adaptive_read_buffering
= 0;
603 p
->read_output_delay
= 0;
604 p
->read_output_skip
= 0;
607 /* If name is already in use, modify it until it is unused. */
612 tem
= Fget_process (name1
);
613 if (NILP (tem
)) break;
614 sprintf (suffix
, "<%d>", i
);
615 name1
= concat2 (name
, build_string (suffix
));
619 XSETPROCESS (val
, p
);
620 Vprocess_alist
= Fcons (Fcons (name
, val
), Vprocess_alist
);
625 remove_process (proc
)
626 register Lisp_Object proc
;
628 register Lisp_Object pair
;
630 pair
= Frassq (proc
, Vprocess_alist
);
631 Vprocess_alist
= Fdelq (pair
, Vprocess_alist
);
633 deactivate_process (proc
);
636 /* Setup coding systems of PROCESS. */
639 setup_process_coding_systems (process
)
642 struct Lisp_Process
*p
= XPROCESS (process
);
644 int outch
= p
->outfd
;
645 Lisp_Object coding_system
;
647 if (inch
< 0 || outch
< 0)
650 if (!proc_decode_coding_system
[inch
])
651 proc_decode_coding_system
[inch
]
652 = (struct coding_system
*) xmalloc (sizeof (struct coding_system
));
653 coding_system
= p
->decode_coding_system
;
654 if (! NILP (p
->filter
))
656 else if (BUFFERP (p
->buffer
))
658 if (NILP (XBUFFER (p
->buffer
)->enable_multibyte_characters
))
659 coding_system
= raw_text_coding_system (coding_system
);
661 setup_coding_system (coding_system
, proc_decode_coding_system
[inch
]);
663 if (!proc_encode_coding_system
[outch
])
664 proc_encode_coding_system
[outch
]
665 = (struct coding_system
*) xmalloc (sizeof (struct coding_system
));
666 setup_coding_system (p
->encode_coding_system
,
667 proc_encode_coding_system
[outch
]);
670 DEFUN ("processp", Fprocessp
, Sprocessp
, 1, 1, 0,
671 doc
: /* Return t if OBJECT is a process. */)
675 return PROCESSP (object
) ? Qt
: Qnil
;
678 DEFUN ("get-process", Fget_process
, Sget_process
, 1, 1, 0,
679 doc
: /* Return the process named NAME, or nil if there is none. */)
681 register Lisp_Object name
;
686 return Fcdr (Fassoc (name
, Vprocess_alist
));
689 DEFUN ("get-buffer-process", Fget_buffer_process
, Sget_buffer_process
, 1, 1, 0,
690 doc
: /* Return the (or a) process associated with BUFFER.
691 BUFFER may be a buffer or the name of one. */)
693 register Lisp_Object buffer
;
695 register Lisp_Object buf
, tail
, proc
;
697 if (NILP (buffer
)) return Qnil
;
698 buf
= Fget_buffer (buffer
);
699 if (NILP (buf
)) return Qnil
;
701 for (tail
= Vprocess_alist
; CONSP (tail
); tail
= XCDR (tail
))
703 proc
= Fcdr (XCAR (tail
));
704 if (PROCESSP (proc
) && EQ (XPROCESS (proc
)->buffer
, buf
))
710 /* This is how commands for the user decode process arguments. It
711 accepts a process, a process name, a buffer, a buffer name, or nil.
712 Buffers denote the first process in the buffer, and nil denotes the
717 register Lisp_Object name
;
719 register Lisp_Object proc
, obj
;
722 obj
= Fget_process (name
);
724 obj
= Fget_buffer (name
);
726 error ("Process %s does not exist", SDATA (name
));
728 else if (NILP (name
))
729 obj
= Fcurrent_buffer ();
733 /* Now obj should be either a buffer object or a process object.
737 proc
= Fget_buffer_process (obj
);
739 error ("Buffer %s has no process", SDATA (XBUFFER (obj
)->name
));
751 /* Fdelete_process promises to immediately forget about the process, but in
752 reality, Emacs needs to remember those processes until they have been
753 treated by sigchld_handler; otherwise this handler would consider the
754 process as being synchronous and say that the synchronous process is
756 static Lisp_Object deleted_pid_list
;
759 DEFUN ("delete-process", Fdelete_process
, Sdelete_process
, 1, 1, 0,
760 doc
: /* Delete PROCESS: kill it and forget about it immediately.
761 PROCESS may be a process, a buffer, the name of a process or buffer, or
762 nil, indicating the current buffer's process. */)
764 register Lisp_Object process
;
766 register struct Lisp_Process
*p
;
768 process
= get_process (process
);
769 p
= XPROCESS (process
);
771 p
->raw_status_new
= 0;
772 if (NETCONN1_P (p
) || SERIALCONN1_P (p
))
774 p
->status
= Fcons (Qexit
, Fcons (make_number (0), Qnil
));
775 p
->tick
= ++process_tick
;
778 else if (p
->infd
>= 0)
782 /* Assignment to EMACS_INT stops GCC whining about limited range
784 EMACS_INT pid
= p
->pid
;
786 /* No problem storing the pid here, as it is still in Vprocess_alist. */
787 deleted_pid_list
= Fcons (make_fixnum_or_float (pid
),
788 /* GC treated elements set to nil. */
789 Fdelq (Qnil
, deleted_pid_list
));
790 /* If the process has already signaled, remove it from the list. */
791 if (p
->raw_status_new
)
794 if (CONSP (p
->status
))
795 symbol
= XCAR (p
->status
);
796 if (EQ (symbol
, Qsignal
) || EQ (symbol
, Qexit
))
798 = Fdelete (make_fixnum_or_float (pid
), deleted_pid_list
);
802 Fkill_process (process
, Qnil
);
803 /* Do this now, since remove_process will make sigchld_handler do nothing. */
805 = Fcons (Qsignal
, Fcons (make_number (SIGKILL
), Qnil
));
806 p
->tick
= ++process_tick
;
810 remove_process (process
);
814 DEFUN ("process-status", Fprocess_status
, Sprocess_status
, 1, 1, 0,
815 doc
: /* Return the status of PROCESS.
816 The returned value is one of the following symbols:
817 run -- for a process that is running.
818 stop -- for a process stopped but continuable.
819 exit -- for a process that has exited.
820 signal -- for a process that has got a fatal signal.
821 open -- for a network stream connection that is open.
822 listen -- for a network stream server that is listening.
823 closed -- for a network stream connection that is closed.
824 connect -- when waiting for a non-blocking connection to complete.
825 failed -- when a non-blocking connection has failed.
826 nil -- if arg is a process name and no such process exists.
827 PROCESS may be a process, a buffer, the name of a process, or
828 nil, indicating the current buffer's process. */)
830 register Lisp_Object process
;
832 register struct Lisp_Process
*p
;
833 register Lisp_Object status
;
835 if (STRINGP (process
))
836 process
= Fget_process (process
);
838 process
= get_process (process
);
843 p
= XPROCESS (process
);
844 if (p
->raw_status_new
)
848 status
= XCAR (status
);
849 if (NETCONN1_P (p
) || SERIALCONN1_P (p
))
851 if (EQ (status
, Qexit
))
853 else if (EQ (p
->command
, Qt
))
855 else if (EQ (status
, Qrun
))
861 DEFUN ("process-exit-status", Fprocess_exit_status
, Sprocess_exit_status
,
863 doc
: /* Return the exit status of PROCESS or the signal number that killed it.
864 If PROCESS has not yet exited or died, return 0. */)
866 register Lisp_Object process
;
868 CHECK_PROCESS (process
);
869 if (XPROCESS (process
)->raw_status_new
)
870 update_status (XPROCESS (process
));
871 if (CONSP (XPROCESS (process
)->status
))
872 return XCAR (XCDR (XPROCESS (process
)->status
));
873 return make_number (0);
876 DEFUN ("process-id", Fprocess_id
, Sprocess_id
, 1, 1, 0,
877 doc
: /* Return the process id of PROCESS.
878 This is the pid of the external process which PROCESS uses or talks to.
879 For a network connection, this value is nil. */)
881 register Lisp_Object process
;
883 /* Assignment to EMACS_INT stops GCC whining about limited range of
887 CHECK_PROCESS (process
);
888 pid
= XPROCESS (process
)->pid
;
889 return (pid
? make_fixnum_or_float (pid
) : Qnil
);
892 DEFUN ("process-name", Fprocess_name
, Sprocess_name
, 1, 1, 0,
893 doc
: /* Return the name of PROCESS, as a string.
894 This is the name of the program invoked in PROCESS,
895 possibly modified to make it unique among process names. */)
897 register Lisp_Object process
;
899 CHECK_PROCESS (process
);
900 return XPROCESS (process
)->name
;
903 DEFUN ("process-command", Fprocess_command
, Sprocess_command
, 1, 1, 0,
904 doc
: /* Return the command that was executed to start PROCESS.
905 This is a list of strings, the first string being the program executed
906 and the rest of the strings being the arguments given to it.
907 For a network or serial process, this is nil (process is running) or t
908 \(process is stopped). */)
910 register Lisp_Object process
;
912 CHECK_PROCESS (process
);
913 return XPROCESS (process
)->command
;
916 DEFUN ("process-tty-name", Fprocess_tty_name
, Sprocess_tty_name
, 1, 1, 0,
917 doc
: /* Return the name of the terminal PROCESS uses, or nil if none.
918 This is the terminal that the process itself reads and writes on,
919 not the name of the pty that Emacs uses to talk with that terminal. */)
921 register Lisp_Object process
;
923 CHECK_PROCESS (process
);
924 return XPROCESS (process
)->tty_name
;
927 DEFUN ("set-process-buffer", Fset_process_buffer
, Sset_process_buffer
,
929 doc
: /* Set buffer associated with PROCESS to BUFFER (a buffer, or nil). */)
931 register Lisp_Object process
, buffer
;
933 struct Lisp_Process
*p
;
935 CHECK_PROCESS (process
);
937 CHECK_BUFFER (buffer
);
938 p
= XPROCESS (process
);
940 if (NETCONN1_P (p
) || SERIALCONN1_P (p
))
941 p
->childp
= Fplist_put (p
->childp
, QCbuffer
, buffer
);
942 setup_process_coding_systems (process
);
946 DEFUN ("process-buffer", Fprocess_buffer
, Sprocess_buffer
,
948 doc
: /* Return the buffer PROCESS is associated with.
949 Output from PROCESS is inserted in this buffer unless PROCESS has a filter. */)
951 register Lisp_Object process
;
953 CHECK_PROCESS (process
);
954 return XPROCESS (process
)->buffer
;
957 DEFUN ("process-mark", Fprocess_mark
, Sprocess_mark
,
959 doc
: /* Return the marker for the end of the last output from PROCESS. */)
961 register Lisp_Object process
;
963 CHECK_PROCESS (process
);
964 return XPROCESS (process
)->mark
;
967 DEFUN ("set-process-filter", Fset_process_filter
, Sset_process_filter
,
969 doc
: /* Give PROCESS the filter function FILTER; nil means no filter.
970 A value of t means stop accepting output from the process.
972 When a process has a filter, its buffer is not used for output.
973 Instead, each time it does output, the entire string of output is
974 passed to the filter.
976 The filter gets two arguments: the process and the string of output.
977 The string argument is normally a multibyte string, except:
978 - if the process' input coding system is no-conversion or raw-text,
979 it is a unibyte string (the non-converted input), or else
980 - if `default-enable-multibyte-characters' is nil, it is a unibyte
981 string (the result of converting the decoded input multibyte
982 string to unibyte with `string-make-unibyte'). */)
984 register Lisp_Object process
, filter
;
986 struct Lisp_Process
*p
;
988 CHECK_PROCESS (process
);
989 p
= XPROCESS (process
);
991 /* Don't signal an error if the process' input file descriptor
992 is closed. This could make debugging Lisp more difficult,
993 for example when doing something like
995 (setq process (start-process ...))
997 (set-process-filter process ...) */
1001 if (EQ (filter
, Qt
) && !EQ (p
->status
, Qlisten
))
1003 FD_CLR (p
->infd
, &input_wait_mask
);
1004 FD_CLR (p
->infd
, &non_keyboard_wait_mask
);
1006 else if (EQ (p
->filter
, Qt
)
1007 /* Network or serial process not stopped: */
1008 && !EQ (p
->command
, Qt
))
1010 FD_SET (p
->infd
, &input_wait_mask
);
1011 FD_SET (p
->infd
, &non_keyboard_wait_mask
);
1016 if (NETCONN1_P (p
) || SERIALCONN1_P (p
))
1017 p
->childp
= Fplist_put (p
->childp
, QCfilter
, filter
);
1018 setup_process_coding_systems (process
);
1022 DEFUN ("process-filter", Fprocess_filter
, Sprocess_filter
,
1024 doc
: /* Returns the filter function of PROCESS; nil if none.
1025 See `set-process-filter' for more info on filter functions. */)
1027 register Lisp_Object process
;
1029 CHECK_PROCESS (process
);
1030 return XPROCESS (process
)->filter
;
1033 DEFUN ("set-process-sentinel", Fset_process_sentinel
, Sset_process_sentinel
,
1035 doc
: /* Give PROCESS the sentinel SENTINEL; nil for none.
1036 The sentinel is called as a function when the process changes state.
1037 It gets two arguments: the process, and a string describing the change. */)
1039 register Lisp_Object process
, sentinel
;
1041 struct Lisp_Process
*p
;
1043 CHECK_PROCESS (process
);
1044 p
= XPROCESS (process
);
1046 p
->sentinel
= sentinel
;
1047 if (NETCONN1_P (p
) || SERIALCONN1_P (p
))
1048 p
->childp
= Fplist_put (p
->childp
, QCsentinel
, sentinel
);
1052 DEFUN ("process-sentinel", Fprocess_sentinel
, Sprocess_sentinel
,
1054 doc
: /* Return the sentinel of PROCESS; nil if none.
1055 See `set-process-sentinel' for more info on sentinels. */)
1057 register Lisp_Object process
;
1059 CHECK_PROCESS (process
);
1060 return XPROCESS (process
)->sentinel
;
1063 DEFUN ("set-process-window-size", Fset_process_window_size
,
1064 Sset_process_window_size
, 3, 3, 0,
1065 doc
: /* Tell PROCESS that it has logical window size HEIGHT and WIDTH. */)
1066 (process
, height
, width
)
1067 register Lisp_Object process
, height
, width
;
1069 CHECK_PROCESS (process
);
1070 CHECK_NATNUM (height
);
1071 CHECK_NATNUM (width
);
1073 if (XPROCESS (process
)->infd
< 0
1074 || set_window_size (XPROCESS (process
)->infd
,
1075 XINT (height
), XINT (width
)) <= 0)
1081 DEFUN ("set-process-inherit-coding-system-flag",
1082 Fset_process_inherit_coding_system_flag
,
1083 Sset_process_inherit_coding_system_flag
, 2, 2, 0,
1084 doc
: /* Determine whether buffer of PROCESS will inherit coding-system.
1085 If the second argument FLAG is non-nil, then the variable
1086 `buffer-file-coding-system' of the buffer associated with PROCESS
1087 will be bound to the value of the coding system used to decode
1090 This is useful when the coding system specified for the process buffer
1091 leaves either the character code conversion or the end-of-line conversion
1092 unspecified, or if the coding system used to decode the process output
1093 is more appropriate for saving the process buffer.
1095 Binding the variable `inherit-process-coding-system' to non-nil before
1096 starting the process is an alternative way of setting the inherit flag
1097 for the process which will run. */)
1099 register Lisp_Object process
, flag
;
1101 CHECK_PROCESS (process
);
1102 XPROCESS (process
)->inherit_coding_system_flag
= !NILP (flag
);
1106 DEFUN ("process-inherit-coding-system-flag",
1107 Fprocess_inherit_coding_system_flag
, Sprocess_inherit_coding_system_flag
,
1109 doc
: /* Return the value of inherit-coding-system flag for PROCESS.
1110 If this flag is t, `buffer-file-coding-system' of the buffer
1111 associated with PROCESS will inherit the coding system used to decode
1112 the process output. */)
1114 register Lisp_Object process
;
1116 CHECK_PROCESS (process
);
1117 return XPROCESS (process
)->inherit_coding_system_flag
? Qt
: Qnil
;
1120 DEFUN ("set-process-query-on-exit-flag",
1121 Fset_process_query_on_exit_flag
, Sset_process_query_on_exit_flag
,
1123 doc
: /* Specify if query is needed for PROCESS when Emacs is exited.
1124 If the second argument FLAG is non-nil, Emacs will query the user before
1125 exiting if PROCESS is running. */)
1127 register Lisp_Object process
, flag
;
1129 CHECK_PROCESS (process
);
1130 XPROCESS (process
)->kill_without_query
= NILP (flag
);
1134 DEFUN ("process-query-on-exit-flag",
1135 Fprocess_query_on_exit_flag
, Sprocess_query_on_exit_flag
,
1137 doc
: /* Return the current value of query-on-exit flag for PROCESS. */)
1139 register Lisp_Object process
;
1141 CHECK_PROCESS (process
);
1142 return (XPROCESS (process
)->kill_without_query
? Qnil
: Qt
);
1145 #ifdef DATAGRAM_SOCKETS
1146 Lisp_Object
Fprocess_datagram_address ();
1149 DEFUN ("process-contact", Fprocess_contact
, Sprocess_contact
,
1151 doc
: /* Return the contact info of PROCESS; t for a real child.
1152 For a network or serial connection, the value depends on the optional
1153 KEY arg. If KEY is nil, value is a cons cell of the form (HOST
1154 SERVICE) for a network connection or (PORT SPEED) for a serial
1155 connection. If KEY is t, the complete contact information for the
1156 connection is returned, else the specific value for the keyword KEY is
1157 returned. See `make-network-process' or `make-serial-process' for a
1158 list of keywords. */)
1160 register Lisp_Object process
, key
;
1162 Lisp_Object contact
;
1164 CHECK_PROCESS (process
);
1165 contact
= XPROCESS (process
)->childp
;
1167 #ifdef DATAGRAM_SOCKETS
1168 if (DATAGRAM_CONN_P (process
)
1169 && (EQ (key
, Qt
) || EQ (key
, QCremote
)))
1170 contact
= Fplist_put (contact
, QCremote
,
1171 Fprocess_datagram_address (process
));
1174 if ((!NETCONN_P (process
) && !SERIALCONN_P (process
)) || EQ (key
, Qt
))
1176 if (NILP (key
) && NETCONN_P (process
))
1177 return Fcons (Fplist_get (contact
, QChost
),
1178 Fcons (Fplist_get (contact
, QCservice
), Qnil
));
1179 if (NILP (key
) && SERIALCONN_P (process
))
1180 return Fcons (Fplist_get (contact
, QCport
),
1181 Fcons (Fplist_get (contact
, QCspeed
), Qnil
));
1182 return Fplist_get (contact
, key
);
1185 DEFUN ("process-plist", Fprocess_plist
, Sprocess_plist
,
1187 doc
: /* Return the plist of PROCESS. */)
1189 register Lisp_Object process
;
1191 CHECK_PROCESS (process
);
1192 return XPROCESS (process
)->plist
;
1195 DEFUN ("set-process-plist", Fset_process_plist
, Sset_process_plist
,
1197 doc
: /* Replace the plist of PROCESS with PLIST. Returns PLIST. */)
1199 register Lisp_Object process
, plist
;
1201 CHECK_PROCESS (process
);
1204 XPROCESS (process
)->plist
= plist
;
1208 #if 0 /* Turned off because we don't currently record this info
1209 in the process. Perhaps add it. */
1210 DEFUN ("process-connection", Fprocess_connection
, Sprocess_connection
, 1, 1, 0,
1211 doc
: /* Return the connection type of PROCESS.
1212 The value is nil for a pipe, t or `pty' for a pty, or `stream' for
1213 a socket connection. */)
1215 Lisp_Object process
;
1217 return XPROCESS (process
)->type
;
1221 DEFUN ("process-type", Fprocess_type
, Sprocess_type
, 1, 1, 0,
1222 doc
: /* Return the connection type of PROCESS.
1223 The value is either the symbol `real', `network', or `serial'.
1224 PROCESS may be a process, a buffer, the name of a process or buffer, or
1225 nil, indicating the current buffer's process. */)
1227 Lisp_Object process
;
1230 proc
= get_process (process
);
1231 return XPROCESS (proc
)->type
;
1235 DEFUN ("format-network-address", Fformat_network_address
, Sformat_network_address
,
1237 doc
: /* Convert network ADDRESS from internal format to a string.
1238 A 4 or 5 element vector represents an IPv4 address (with port number).
1239 An 8 or 9 element vector represents an IPv6 address (with port number).
1240 If optional second argument OMIT-PORT is non-nil, don't include a port
1241 number in the string, even when present in ADDRESS.
1242 Returns nil if format of ADDRESS is invalid. */)
1243 (address
, omit_port
)
1244 Lisp_Object address
, omit_port
;
1249 if (STRINGP (address
)) /* AF_LOCAL */
1252 if (VECTORP (address
)) /* AF_INET or AF_INET6 */
1254 register struct Lisp_Vector
*p
= XVECTOR (address
);
1255 Lisp_Object args
[10];
1258 if (p
->size
== 4 || (p
->size
== 5 && !NILP (omit_port
)))
1260 args
[0] = build_string ("%d.%d.%d.%d");
1263 else if (p
->size
== 5)
1265 args
[0] = build_string ("%d.%d.%d.%d:%d");
1268 else if (p
->size
== 8 || (p
->size
== 9 && !NILP (omit_port
)))
1270 args
[0] = build_string ("%x:%x:%x:%x:%x:%x:%x:%x");
1273 else if (p
->size
== 9)
1275 args
[0] = build_string ("[%x:%x:%x:%x:%x:%x:%x:%x]:%d");
1281 for (i
= 0; i
< nargs
; i
++)
1283 EMACS_INT element
= XINT (p
->contents
[i
]);
1285 if (element
< 0 || element
> 65535)
1288 if (nargs
<= 5 /* IPv4 */
1289 && i
< 4 /* host, not port */
1293 args
[i
+1] = p
->contents
[i
];
1296 return Fformat (nargs
+1, args
);
1299 if (CONSP (address
))
1301 Lisp_Object args
[2];
1302 args
[0] = build_string ("<Family %d>");
1303 args
[1] = Fcar (address
);
1304 return Fformat (2, args
);
1312 list_processes_1 (query_only
)
1313 Lisp_Object query_only
;
1315 register Lisp_Object tail
, tem
;
1316 Lisp_Object proc
, minspace
, tem1
;
1317 register struct Lisp_Process
*p
;
1319 int w_proc
, w_buffer
, w_tty
;
1321 Lisp_Object i_status
, i_buffer
, i_tty
, i_command
;
1323 w_proc
= 4; /* Proc */
1324 w_buffer
= 6; /* Buffer */
1325 w_tty
= 0; /* Omit if no ttys */
1327 for (tail
= Vprocess_alist
; CONSP (tail
); tail
= XCDR (tail
))
1331 proc
= Fcdr (XCAR (tail
));
1332 p
= XPROCESS (proc
);
1335 if (!NILP (query_only
) && p
->kill_without_query
)
1337 if (STRINGP (p
->name
)
1338 && ( i
= SCHARS (p
->name
), (i
> w_proc
)))
1340 if (!NILP (p
->buffer
))
1342 if (NILP (XBUFFER (p
->buffer
)->name
))
1345 w_buffer
= 8; /* (Killed) */
1347 else if ((i
= SCHARS (XBUFFER (p
->buffer
)->name
), (i
> w_buffer
)))
1350 if (STRINGP (p
->tty_name
)
1351 && (i
= SCHARS (p
->tty_name
), (i
> w_tty
)))
1355 XSETFASTINT (i_status
, w_proc
+ 1);
1356 XSETFASTINT (i_buffer
, XFASTINT (i_status
) + 9);
1359 XSETFASTINT (i_tty
, XFASTINT (i_buffer
) + w_buffer
+ 1);
1360 XSETFASTINT (i_command
, XFASTINT (i_tty
) + w_tty
+ 1);
1365 XSETFASTINT (i_command
, XFASTINT (i_buffer
) + w_buffer
+ 1);
1368 XSETFASTINT (minspace
, 1);
1370 set_buffer_internal (XBUFFER (Vstandard_output
));
1371 current_buffer
->undo_list
= Qt
;
1373 current_buffer
->truncate_lines
= Qt
;
1375 write_string ("Proc", -1);
1376 Findent_to (i_status
, minspace
); write_string ("Status", -1);
1377 Findent_to (i_buffer
, minspace
); write_string ("Buffer", -1);
1380 Findent_to (i_tty
, minspace
); write_string ("Tty", -1);
1382 Findent_to (i_command
, minspace
); write_string ("Command", -1);
1383 write_string ("\n", -1);
1385 write_string ("----", -1);
1386 Findent_to (i_status
, minspace
); write_string ("------", -1);
1387 Findent_to (i_buffer
, minspace
); write_string ("------", -1);
1390 Findent_to (i_tty
, minspace
); write_string ("---", -1);
1392 Findent_to (i_command
, minspace
); write_string ("-------", -1);
1393 write_string ("\n", -1);
1395 for (tail
= Vprocess_alist
; CONSP (tail
); tail
= XCDR (tail
))
1399 proc
= Fcdr (XCAR (tail
));
1400 p
= XPROCESS (proc
);
1403 if (!NILP (query_only
) && p
->kill_without_query
)
1406 Finsert (1, &p
->name
);
1407 Findent_to (i_status
, minspace
);
1409 if (p
->raw_status_new
)
1412 if (CONSP (p
->status
))
1413 symbol
= XCAR (p
->status
);
1415 if (EQ (symbol
, Qsignal
))
1418 tem
= Fcar (Fcdr (p
->status
));
1419 Fprinc (symbol
, Qnil
);
1421 else if (NETCONN1_P (p
) || SERIALCONN1_P (p
))
1423 if (EQ (symbol
, Qexit
))
1424 write_string ("closed", -1);
1425 else if (EQ (p
->command
, Qt
))
1426 write_string ("stopped", -1);
1427 else if (EQ (symbol
, Qrun
))
1428 write_string ("open", -1);
1430 Fprinc (symbol
, Qnil
);
1432 else if (SERIALCONN1_P (p
))
1434 write_string ("running", -1);
1437 Fprinc (symbol
, Qnil
);
1439 if (EQ (symbol
, Qexit
))
1442 tem
= Fcar (Fcdr (p
->status
));
1445 sprintf (tembuf
, " %d", (int) XFASTINT (tem
));
1446 write_string (tembuf
, -1);
1450 if (EQ (symbol
, Qsignal
) || EQ (symbol
, Qexit
) || EQ (symbol
, Qclosed
))
1453 Findent_to (i_buffer
, minspace
);
1454 if (NILP (p
->buffer
))
1455 insert_string ("(none)");
1456 else if (NILP (XBUFFER (p
->buffer
)->name
))
1457 insert_string ("(Killed)");
1459 Finsert (1, &XBUFFER (p
->buffer
)->name
);
1463 Findent_to (i_tty
, minspace
);
1464 if (STRINGP (p
->tty_name
))
1465 Finsert (1, &p
->tty_name
);
1468 Findent_to (i_command
, minspace
);
1470 if (EQ (p
->status
, Qlisten
))
1472 Lisp_Object port
= Fplist_get (p
->childp
, QCservice
);
1473 if (INTEGERP (port
))
1474 port
= Fnumber_to_string (port
);
1476 port
= Fformat_network_address (Fplist_get (p
->childp
, QClocal
), Qnil
);
1477 sprintf (tembuf
, "(network %s server on %s)\n",
1478 (DATAGRAM_CHAN_P (p
->infd
) ? "datagram" : "stream"),
1479 (STRINGP (port
) ? (char *)SDATA (port
) : "?"));
1480 insert_string (tembuf
);
1482 else if (NETCONN1_P (p
))
1484 /* For a local socket, there is no host name,
1485 so display service instead. */
1486 Lisp_Object host
= Fplist_get (p
->childp
, QChost
);
1487 if (!STRINGP (host
))
1489 host
= Fplist_get (p
->childp
, QCservice
);
1490 if (INTEGERP (host
))
1491 host
= Fnumber_to_string (host
);
1494 host
= Fformat_network_address (Fplist_get (p
->childp
, QCremote
), Qnil
);
1495 sprintf (tembuf
, "(network %s connection to %s)\n",
1496 (DATAGRAM_CHAN_P (p
->infd
) ? "datagram" : "stream"),
1497 (STRINGP (host
) ? (char *)SDATA (host
) : "?"));
1498 insert_string (tembuf
);
1500 else if (SERIALCONN1_P (p
))
1502 Lisp_Object port
= Fplist_get (p
->childp
, QCport
);
1503 Lisp_Object speed
= Fplist_get (p
->childp
, QCspeed
);
1504 insert_string ("(serial port ");
1506 insert_string (SDATA (port
));
1508 insert_string ("?");
1509 if (INTEGERP (speed
))
1511 sprintf (tembuf
, " at %d b/s", XINT (speed
));
1512 insert_string (tembuf
);
1514 insert_string (")\n");
1526 insert_string (" ");
1528 insert_string ("\n");
1532 status_notify (NULL
);
1536 DEFUN ("list-processes", Flist_processes
, Slist_processes
, 0, 1, "P",
1537 doc
: /* Display a list of all processes.
1538 If optional argument QUERY-ONLY is non-nil, only processes with
1539 the query-on-exit flag set will be listed.
1540 Any process listed as exited or signaled is actually eliminated
1541 after the listing is made. */)
1543 Lisp_Object query_only
;
1545 internal_with_output_to_temp_buffer ("*Process List*",
1546 list_processes_1
, query_only
);
1550 DEFUN ("process-list", Fprocess_list
, Sprocess_list
, 0, 0, 0,
1551 doc
: /* Return a list of all processes. */)
1554 return Fmapcar (Qcdr
, Vprocess_alist
);
1557 /* Starting asynchronous inferior processes. */
1559 static Lisp_Object
start_process_unwind ();
1561 DEFUN ("start-process", Fstart_process
, Sstart_process
, 3, MANY
, 0,
1562 doc
: /* Start a program in a subprocess. Return the process object for it.
1563 NAME is name for process. It is modified if necessary to make it unique.
1564 BUFFER is the buffer (or buffer name) to associate with the process.
1566 Process output (both standard output and standard error streams) goes
1567 at end of BUFFER, unless you specify an output stream or filter
1568 function to handle the output. BUFFER may also be nil, meaning that
1569 this process is not associated with any buffer.
1571 PROGRAM is the program file name. It is searched for in PATH.
1572 Remaining arguments are strings to give program as arguments.
1574 If you want to separate standard output from standard error, invoke
1575 the command through a shell and redirect one of them using the shell
1578 usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1581 register Lisp_Object
*args
;
1583 Lisp_Object buffer
, name
, program
, proc
, current_dir
, tem
;
1584 register unsigned char **new_argv
;
1586 int count
= SPECPDL_INDEX ();
1590 buffer
= Fget_buffer_create (buffer
);
1592 /* Make sure that the child will be able to chdir to the current
1593 buffer's current directory, or its unhandled equivalent. We
1594 can't just have the child check for an error when it does the
1595 chdir, since it's in a vfork.
1597 We have to GCPRO around this because Fexpand_file_name and
1598 Funhandled_file_name_directory might call a file name handling
1599 function. The argument list is protected by the caller, so all
1600 we really have to worry about is buffer. */
1602 struct gcpro gcpro1
, gcpro2
;
1604 current_dir
= current_buffer
->directory
;
1606 GCPRO2 (buffer
, current_dir
);
1608 current_dir
= Funhandled_file_name_directory (current_dir
);
1609 if (NILP (current_dir
))
1610 /* If the file name handler says that current_dir is unreachable, use
1611 a sensible default. */
1612 current_dir
= build_string ("~/");
1613 current_dir
= expand_and_dir_to_file (current_dir
, Qnil
);
1614 if (NILP (Ffile_accessible_directory_p (current_dir
)))
1615 report_file_error ("Setting current directory",
1616 Fcons (current_buffer
->directory
, Qnil
));
1622 CHECK_STRING (name
);
1626 CHECK_STRING (program
);
1628 proc
= make_process (name
);
1629 /* If an error occurs and we can't start the process, we want to
1630 remove it from the process list. This means that each error
1631 check in create_process doesn't need to call remove_process
1632 itself; it's all taken care of here. */
1633 record_unwind_protect (start_process_unwind
, proc
);
1635 XPROCESS (proc
)->childp
= Qt
;
1636 XPROCESS (proc
)->plist
= Qnil
;
1637 XPROCESS (proc
)->type
= Qreal
;
1638 XPROCESS (proc
)->buffer
= buffer
;
1639 XPROCESS (proc
)->sentinel
= Qnil
;
1640 XPROCESS (proc
)->filter
= Qnil
;
1641 XPROCESS (proc
)->command
= Flist (nargs
- 2, args
+ 2);
1643 #ifdef ADAPTIVE_READ_BUFFERING
1644 XPROCESS (proc
)->adaptive_read_buffering
1645 = (NILP (Vprocess_adaptive_read_buffering
) ? 0
1646 : EQ (Vprocess_adaptive_read_buffering
, Qt
) ? 1 : 2);
1649 /* Make the process marker point into the process buffer (if any). */
1650 if (BUFFERP (buffer
))
1651 set_marker_both (XPROCESS (proc
)->mark
, buffer
,
1652 BUF_ZV (XBUFFER (buffer
)),
1653 BUF_ZV_BYTE (XBUFFER (buffer
)));
1656 /* Decide coding systems for communicating with the process. Here
1657 we don't setup the structure coding_system nor pay attention to
1658 unibyte mode. They are done in create_process. */
1660 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
1661 Lisp_Object coding_systems
= Qt
;
1662 Lisp_Object val
, *args2
;
1663 struct gcpro gcpro1
, gcpro2
;
1665 val
= Vcoding_system_for_read
;
1668 args2
= (Lisp_Object
*) alloca ((nargs
+ 1) * sizeof *args2
);
1669 args2
[0] = Qstart_process
;
1670 for (i
= 0; i
< nargs
; i
++) args2
[i
+ 1] = args
[i
];
1671 GCPRO2 (proc
, current_dir
);
1672 coding_systems
= Ffind_operation_coding_system (nargs
+ 1, args2
);
1674 if (CONSP (coding_systems
))
1675 val
= XCAR (coding_systems
);
1676 else if (CONSP (Vdefault_process_coding_system
))
1677 val
= XCAR (Vdefault_process_coding_system
);
1679 XPROCESS (proc
)->decode_coding_system
= val
;
1681 val
= Vcoding_system_for_write
;
1684 if (EQ (coding_systems
, Qt
))
1686 args2
= (Lisp_Object
*) alloca ((nargs
+ 1) * sizeof args2
);
1687 args2
[0] = Qstart_process
;
1688 for (i
= 0; i
< nargs
; i
++) args2
[i
+ 1] = args
[i
];
1689 GCPRO2 (proc
, current_dir
);
1690 coding_systems
= Ffind_operation_coding_system (nargs
+ 1, args2
);
1693 if (CONSP (coding_systems
))
1694 val
= XCDR (coding_systems
);
1695 else if (CONSP (Vdefault_process_coding_system
))
1696 val
= XCDR (Vdefault_process_coding_system
);
1698 XPROCESS (proc
)->encode_coding_system
= val
;
1701 /* If program file name is not absolute, search our path for it.
1702 Put the name we will really use in TEM. */
1703 if (!IS_DIRECTORY_SEP (SREF (program
, 0))
1704 && !(SCHARS (program
) > 1
1705 && IS_DEVICE_SEP (SREF (program
, 1))))
1707 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
1710 GCPRO4 (name
, program
, buffer
, current_dir
);
1711 openp (Vexec_path
, program
, Vexec_suffixes
, &tem
, make_number (X_OK
));
1714 report_file_error ("Searching for program", Fcons (program
, Qnil
));
1715 tem
= Fexpand_file_name (tem
, Qnil
);
1719 if (!NILP (Ffile_directory_p (program
)))
1720 error ("Specified program for new process is a directory");
1724 /* If program file name starts with /: for quoting a magic name,
1726 if (SBYTES (tem
) > 2 && SREF (tem
, 0) == '/'
1727 && SREF (tem
, 1) == ':')
1728 tem
= Fsubstring (tem
, make_number (2), Qnil
);
1731 struct gcpro gcpro1
;
1734 /* Encode the file name and put it in NEW_ARGV.
1735 That's where the child will use it to execute the program. */
1736 tem
= Fcons (ENCODE_FILE (tem
), Qnil
);
1738 /* Here we encode arguments by the coding system used for sending
1739 data to the process. We don't support using different coding
1740 systems for encoding arguments and for encoding data sent to the
1743 for (i
= 3; i
< nargs
; i
++)
1745 tem
= Fcons (args
[i
], tem
);
1746 CHECK_STRING (XCAR (tem
));
1747 if (STRING_MULTIBYTE (XCAR (tem
)))
1749 code_convert_string_norecord
1750 (XCAR (tem
), XPROCESS (proc
)->encode_coding_system
, 1));
1756 /* Now that everything is encoded we can collect the strings into
1758 new_argv
= (unsigned char **) alloca ((nargs
- 1) * sizeof (char *));
1759 new_argv
[nargs
- 2] = 0;
1761 for (i
= nargs
- 3; i
>= 0; i
--)
1763 new_argv
[i
] = SDATA (XCAR (tem
));
1767 XPROCESS (proc
)->decoding_buf
= make_uninit_string (0);
1768 XPROCESS (proc
)->decoding_carryover
= 0;
1769 XPROCESS (proc
)->encoding_buf
= make_uninit_string (0);
1771 XPROCESS (proc
)->inherit_coding_system_flag
1772 = !(NILP (buffer
) || !inherit_process_coding_system
);
1774 create_process (proc
, (char **) new_argv
, current_dir
);
1776 return unbind_to (count
, proc
);
1779 /* This function is the unwind_protect form for Fstart_process. If
1780 PROC doesn't have its pid set, then we know someone has signaled
1781 an error and the process wasn't started successfully, so we should
1782 remove it from the process list. */
1784 start_process_unwind (proc
)
1787 if (!PROCESSP (proc
))
1790 /* Was PROC started successfully? */
1791 if (XPROCESS (proc
)->pid
<= 0)
1792 remove_process (proc
);
1798 create_process_1 (timer
)
1799 struct atimer
*timer
;
1801 /* Nothing to do. */
1805 #if 0 /* This doesn't work; see the note before sigchld_handler. */
1808 /* Mimic blocking of signals on system V, which doesn't really have it. */
1810 /* Nonzero means we got a SIGCHLD when it was supposed to be blocked. */
1811 int sigchld_deferred
;
1814 create_process_sigchld ()
1816 signal (SIGCHLD
, create_process_sigchld
);
1818 sigchld_deferred
= 1;
1825 create_process (process
, new_argv
, current_dir
)
1826 Lisp_Object process
;
1828 Lisp_Object current_dir
;
1830 int inchannel
, outchannel
;
1833 #if !defined (WINDOWSNT) && defined (FD_CLOEXEC)
1834 int wait_child_setup
[2];
1836 #ifdef POSIX_SIGNALS
1839 struct sigaction sigint_action
;
1840 struct sigaction sigquit_action
;
1842 struct sigaction sighup_action
;
1844 #else /* !POSIX_SIGNALS */
1847 SIGTYPE (*sigchld
)();
1850 #endif /* !POSIX_SIGNALS */
1851 /* Use volatile to protect variables from being clobbered by longjmp. */
1852 volatile int forkin
, forkout
;
1853 volatile int pty_flag
= 0;
1855 extern char **environ
;
1858 inchannel
= outchannel
= -1;
1861 if (!NILP (Vprocess_connection_type
))
1862 outchannel
= inchannel
= allocate_pty ();
1866 #if ! defined (USG) || defined (USG_SUBTTY_WORKS)
1867 /* On most USG systems it does not work to open the pty's tty here,
1868 then close it and reopen it in the child. */
1870 /* Don't let this terminal become our controlling terminal
1871 (in case we don't have one). */
1872 forkout
= forkin
= emacs_open (pty_name
, O_RDWR
| O_NOCTTY
, 0);
1874 forkout
= forkin
= emacs_open (pty_name
, O_RDWR
, 0);
1877 report_file_error ("Opening pty", Qnil
);
1879 forkin
= forkout
= -1;
1880 #endif /* not USG, or USG_SUBTTY_WORKS */
1884 #endif /* HAVE_PTYS */
1889 report_file_error ("Creating pipe", Qnil
);
1895 emacs_close (inchannel
);
1896 emacs_close (forkout
);
1897 report_file_error ("Creating pipe", Qnil
);
1903 #if !defined (WINDOWSNT) && defined (FD_CLOEXEC)
1907 tem
= pipe (wait_child_setup
);
1909 report_file_error ("Creating pipe", Qnil
);
1910 tem
= fcntl (wait_child_setup
[1], F_GETFD
, 0);
1912 tem
= fcntl (wait_child_setup
[1], F_SETFD
, tem
| FD_CLOEXEC
);
1915 emacs_close (wait_child_setup
[0]);
1916 emacs_close (wait_child_setup
[1]);
1917 report_file_error ("Setting file descriptor flags", Qnil
);
1923 /* Replaced by close_process_descs */
1924 set_exclusive_use (inchannel
);
1925 set_exclusive_use (outchannel
);
1929 fcntl (inchannel
, F_SETFL
, O_NONBLOCK
);
1930 fcntl (outchannel
, F_SETFL
, O_NONBLOCK
);
1933 fcntl (inchannel
, F_SETFL
, O_NDELAY
);
1934 fcntl (outchannel
, F_SETFL
, O_NDELAY
);
1938 /* Record this as an active process, with its channels.
1939 As a result, child_setup will close Emacs's side of the pipes. */
1940 chan_process
[inchannel
] = process
;
1941 XPROCESS (process
)->infd
= inchannel
;
1942 XPROCESS (process
)->outfd
= outchannel
;
1944 /* Previously we recorded the tty descriptor used in the subprocess.
1945 It was only used for getting the foreground tty process, so now
1946 we just reopen the device (see emacs_get_tty_pgrp) as this is
1947 more portable (see USG_SUBTTY_WORKS above). */
1949 XPROCESS (process
)->pty_flag
= pty_flag
;
1950 XPROCESS (process
)->status
= Qrun
;
1951 setup_process_coding_systems (process
);
1953 /* Delay interrupts until we have a chance to store
1954 the new fork's pid in its process structure */
1955 #ifdef POSIX_SIGNALS
1956 sigemptyset (&blocked
);
1958 sigaddset (&blocked
, SIGCHLD
);
1960 #ifdef HAVE_WORKING_VFORK
1961 /* On many hosts (e.g. Solaris 2.4), if a vforked child calls `signal',
1962 this sets the parent's signal handlers as well as the child's.
1963 So delay all interrupts whose handlers the child might munge,
1964 and record the current handlers so they can be restored later. */
1965 sigaddset (&blocked
, SIGINT
); sigaction (SIGINT
, 0, &sigint_action
);
1966 sigaddset (&blocked
, SIGQUIT
); sigaction (SIGQUIT
, 0, &sigquit_action
);
1968 sigaddset (&blocked
, SIGHUP
); sigaction (SIGHUP
, 0, &sighup_action
);
1970 #endif /* HAVE_WORKING_VFORK */
1971 sigprocmask (SIG_BLOCK
, &blocked
, &procmask
);
1972 #else /* !POSIX_SIGNALS */
1974 #if defined (BSD_SYSTEM) || defined (HPUX)
1975 sigsetmask (sigmask (SIGCHLD
));
1976 #else /* ordinary USG */
1978 sigchld_deferred
= 0;
1979 sigchld
= signal (SIGCHLD
, create_process_sigchld
);
1981 #endif /* ordinary USG */
1982 #endif /* SIGCHLD */
1983 #endif /* !POSIX_SIGNALS */
1985 FD_SET (inchannel
, &input_wait_mask
);
1986 FD_SET (inchannel
, &non_keyboard_wait_mask
);
1987 if (inchannel
> max_process_desc
)
1988 max_process_desc
= inchannel
;
1990 /* Until we store the proper pid, enable sigchld_handler
1991 to recognize an unknown pid as standing for this process.
1992 It is very important not to let this `marker' value stay
1993 in the table after this function has returned; if it does
1994 it might cause call-process to hang and subsequent asynchronous
1995 processes to get their return values scrambled. */
1996 XPROCESS (process
)->pid
= -1;
2001 /* child_setup must clobber environ on systems with true vfork.
2002 Protect it from permanent change. */
2003 char **save_environ
= environ
;
2005 current_dir
= ENCODE_FILE (current_dir
);
2010 #endif /* not WINDOWSNT */
2012 int xforkin
= forkin
;
2013 int xforkout
= forkout
;
2015 #if 0 /* This was probably a mistake--it duplicates code later on,
2016 but fails to handle all the cases. */
2017 /* Make sure SIGCHLD is not blocked in the child. */
2018 sigsetmask (SIGEMPTYMASK
);
2021 /* Make the pty be the controlling terminal of the process. */
2023 /* First, disconnect its current controlling terminal. */
2025 /* We tried doing setsid only if pty_flag, but it caused
2026 process_set_signal to fail on SGI when using a pipe. */
2028 /* Make the pty's terminal the controlling terminal. */
2032 /* We ignore the return value
2033 because faith@cs.unc.edu says that is necessary on Linux. */
2034 ioctl (xforkin
, TIOCSCTTY
, 0);
2037 #else /* not HAVE_SETSID */
2039 /* It's very important to call setpgrp here and no time
2040 afterwards. Otherwise, we lose our controlling tty which
2041 is set when we open the pty. */
2044 #endif /* not HAVE_SETSID */
2045 #if defined (HAVE_TERMIOS) && defined (LDISC1)
2046 if (pty_flag
&& xforkin
>= 0)
2049 tcgetattr (xforkin
, &t
);
2051 if (tcsetattr (xforkin
, TCSANOW
, &t
) < 0)
2052 emacs_write (1, "create_process/tcsetattr LDISC1 failed\n", 39);
2055 #if defined (NTTYDISC) && defined (TIOCSETD)
2056 if (pty_flag
&& xforkin
>= 0)
2058 /* Use new line discipline. */
2059 int ldisc
= NTTYDISC
;
2060 ioctl (xforkin
, TIOCSETD
, &ldisc
);
2065 /* In 4.3BSD, the TIOCSPGRP bug has been fixed, and now you
2066 can do TIOCSPGRP only to the process's controlling tty. */
2069 /* I wonder: would just ioctl (0, TIOCNOTTY, 0) work here?
2070 I can't test it since I don't have 4.3. */
2071 int j
= emacs_open ("/dev/tty", O_RDWR
, 0);
2072 ioctl (j
, TIOCNOTTY
, 0);
2075 /* In order to get a controlling terminal on some versions
2076 of BSD, it is necessary to put the process in pgrp 0
2077 before it opens the terminal. */
2085 #endif /* TIOCNOTTY */
2087 #if !defined (DONT_REOPEN_PTY)
2088 /*** There is a suggestion that this ought to be a
2089 conditional on TIOCSPGRP,
2090 or !(defined (HAVE_SETSID) && defined (TIOCSCTTY)).
2091 Trying the latter gave the wrong results on Debian GNU/Linux 1.1;
2092 that system does seem to need this code, even though
2093 both HAVE_SETSID and TIOCSCTTY are defined. */
2094 /* Now close the pty (if we had it open) and reopen it.
2095 This makes the pty the controlling terminal of the subprocess. */
2099 /* I wonder if emacs_close (emacs_open (pty_name, ...))
2102 emacs_close (xforkin
);
2103 xforkout
= xforkin
= emacs_open (pty_name
, O_RDWR
, 0);
2107 emacs_write (1, "Couldn't open the pty terminal ", 31);
2108 emacs_write (1, pty_name
, strlen (pty_name
));
2109 emacs_write (1, "\n", 1);
2114 #endif /* not DONT_REOPEN_PTY */
2116 #ifdef SETUP_SLAVE_PTY
2121 #endif /* SETUP_SLAVE_PTY */
2123 /* On AIX, we've disabled SIGHUP above once we start a child on a pty.
2124 Now reenable it in the child, so it will die when we want it to. */
2126 signal (SIGHUP
, SIG_DFL
);
2128 #endif /* HAVE_PTYS */
2130 signal (SIGINT
, SIG_DFL
);
2131 signal (SIGQUIT
, SIG_DFL
);
2133 /* Stop blocking signals in the child. */
2134 #ifdef POSIX_SIGNALS
2135 sigprocmask (SIG_SETMASK
, &procmask
, 0);
2136 #else /* !POSIX_SIGNALS */
2138 #if defined (BSD_SYSTEM) || defined (HPUX)
2139 sigsetmask (SIGEMPTYMASK
);
2140 #else /* ordinary USG */
2142 signal (SIGCHLD
, sigchld
);
2144 #endif /* ordinary USG */
2145 #endif /* SIGCHLD */
2146 #endif /* !POSIX_SIGNALS */
2149 child_setup_tty (xforkout
);
2151 pid
= child_setup (xforkin
, xforkout
, xforkout
,
2152 new_argv
, 1, current_dir
);
2153 #else /* not WINDOWSNT */
2155 emacs_close (wait_child_setup
[0]);
2157 child_setup (xforkin
, xforkout
, xforkout
,
2158 new_argv
, 1, current_dir
);
2159 #endif /* not WINDOWSNT */
2161 environ
= save_environ
;
2166 /* This runs in the Emacs process. */
2170 emacs_close (forkin
);
2171 if (forkin
!= forkout
&& forkout
>= 0)
2172 emacs_close (forkout
);
2176 /* vfork succeeded. */
2177 XPROCESS (process
)->pid
= pid
;
2180 register_child (pid
, inchannel
);
2181 #endif /* WINDOWSNT */
2183 /* If the subfork execv fails, and it exits,
2184 this close hangs. I don't know why.
2185 So have an interrupt jar it loose. */
2187 struct atimer
*timer
;
2191 EMACS_SET_SECS_USECS (offset
, 1, 0);
2192 timer
= start_atimer (ATIMER_RELATIVE
, offset
, create_process_1
, 0);
2195 emacs_close (forkin
);
2197 cancel_atimer (timer
);
2201 if (forkin
!= forkout
&& forkout
>= 0)
2202 emacs_close (forkout
);
2206 XPROCESS (process
)->tty_name
= build_string (pty_name
);
2209 XPROCESS (process
)->tty_name
= Qnil
;
2211 #if !defined (WINDOWSNT) && defined (FD_CLOEXEC)
2212 /* Wait for child_setup to complete in case that vfork is
2213 actually defined as fork. The descriptor wait_child_setup[1]
2214 of a pipe is closed at the child side either by close-on-exec
2215 on successful execvp or the _exit call in child_setup. */
2219 emacs_close (wait_child_setup
[1]);
2220 emacs_read (wait_child_setup
[0], &dummy
, 1);
2221 emacs_close (wait_child_setup
[0]);
2226 /* Restore the signal state whether vfork succeeded or not.
2227 (We will signal an error, below, if it failed.) */
2228 #ifdef POSIX_SIGNALS
2229 #ifdef HAVE_WORKING_VFORK
2230 /* Restore the parent's signal handlers. */
2231 sigaction (SIGINT
, &sigint_action
, 0);
2232 sigaction (SIGQUIT
, &sigquit_action
, 0);
2234 sigaction (SIGHUP
, &sighup_action
, 0);
2236 #endif /* HAVE_WORKING_VFORK */
2237 /* Stop blocking signals in the parent. */
2238 sigprocmask (SIG_SETMASK
, &procmask
, 0);
2239 #else /* !POSIX_SIGNALS */
2241 #if defined (BSD_SYSTEM) || defined (HPUX)
2242 sigsetmask (SIGEMPTYMASK
);
2243 #else /* ordinary USG */
2245 signal (SIGCHLD
, sigchld
);
2246 /* Now really handle any of these signals
2247 that came in during this function. */
2248 if (sigchld_deferred
)
2249 kill (getpid (), SIGCHLD
);
2251 #endif /* ordinary USG */
2252 #endif /* SIGCHLD */
2253 #endif /* !POSIX_SIGNALS */
2255 /* Now generate the error if vfork failed. */
2257 report_file_error ("Doing vfork", Qnil
);
2263 /* Convert an internal struct sockaddr to a lisp object (vector or string).
2264 The address family of sa is not included in the result. */
2267 conv_sockaddr_to_lisp (sa
, len
)
2268 struct sockaddr
*sa
;
2271 Lisp_Object address
;
2274 register struct Lisp_Vector
*p
;
2276 /* Workaround for a bug in getsockname on BSD: Names bound to
2277 sockets in the UNIX domain are inaccessible; getsockname returns
2278 a zero length name. */
2279 if (len
< OFFSETOF (struct sockaddr
, sa_family
) + sizeof (sa
->sa_family
))
2280 return empty_unibyte_string
;
2282 switch (sa
->sa_family
)
2286 struct sockaddr_in
*sin
= (struct sockaddr_in
*) sa
;
2287 len
= sizeof (sin
->sin_addr
) + 1;
2288 address
= Fmake_vector (make_number (len
), Qnil
);
2289 p
= XVECTOR (address
);
2290 p
->contents
[--len
] = make_number (ntohs (sin
->sin_port
));
2291 cp
= (unsigned char *) &sin
->sin_addr
;
2297 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*) sa
;
2298 uint16_t *ip6
= (uint16_t *) &sin6
->sin6_addr
;
2299 len
= sizeof (sin6
->sin6_addr
)/2 + 1;
2300 address
= Fmake_vector (make_number (len
), Qnil
);
2301 p
= XVECTOR (address
);
2302 p
->contents
[--len
] = make_number (ntohs (sin6
->sin6_port
));
2303 for (i
= 0; i
< len
; i
++)
2304 p
->contents
[i
] = make_number (ntohs (ip6
[i
]));
2308 #ifdef HAVE_LOCAL_SOCKETS
2311 struct sockaddr_un
*sockun
= (struct sockaddr_un
*) sa
;
2312 for (i
= 0; i
< sizeof (sockun
->sun_path
); i
++)
2313 if (sockun
->sun_path
[i
] == 0)
2315 return make_unibyte_string (sockun
->sun_path
, i
);
2319 len
-= OFFSETOF (struct sockaddr
, sa_family
) + sizeof (sa
->sa_family
);
2320 address
= Fcons (make_number (sa
->sa_family
),
2321 Fmake_vector (make_number (len
), Qnil
));
2322 p
= XVECTOR (XCDR (address
));
2323 cp
= (unsigned char *) &sa
->sa_family
+ sizeof (sa
->sa_family
);
2329 p
->contents
[i
++] = make_number (*cp
++);
2335 /* Get family and required size for sockaddr structure to hold ADDRESS. */
2338 get_lisp_to_sockaddr_size (address
, familyp
)
2339 Lisp_Object address
;
2342 register struct Lisp_Vector
*p
;
2344 if (VECTORP (address
))
2346 p
= XVECTOR (address
);
2350 return sizeof (struct sockaddr_in
);
2353 else if (p
->size
== 9)
2355 *familyp
= AF_INET6
;
2356 return sizeof (struct sockaddr_in6
);
2360 #ifdef HAVE_LOCAL_SOCKETS
2361 else if (STRINGP (address
))
2363 *familyp
= AF_LOCAL
;
2364 return sizeof (struct sockaddr_un
);
2367 else if (CONSP (address
) && INTEGERP (XCAR (address
)) && VECTORP (XCDR (address
)))
2369 struct sockaddr
*sa
;
2370 *familyp
= XINT (XCAR (address
));
2371 p
= XVECTOR (XCDR (address
));
2372 return p
->size
+ sizeof (sa
->sa_family
);
2377 /* Convert an address object (vector or string) to an internal sockaddr.
2379 The address format has been basically validated by
2380 get_lisp_to_sockaddr_size, but this does not mean FAMILY is valid;
2381 it could have come from user data. So if FAMILY is not valid,
2382 we return after zeroing *SA. */
2385 conv_lisp_to_sockaddr (family
, address
, sa
, len
)
2387 Lisp_Object address
;
2388 struct sockaddr
*sa
;
2391 register struct Lisp_Vector
*p
;
2392 register unsigned char *cp
= NULL
;
2397 if (VECTORP (address
))
2399 p
= XVECTOR (address
);
2400 if (family
== AF_INET
)
2402 struct sockaddr_in
*sin
= (struct sockaddr_in
*) sa
;
2403 len
= sizeof (sin
->sin_addr
) + 1;
2404 i
= XINT (p
->contents
[--len
]);
2405 sin
->sin_port
= htons (i
);
2406 cp
= (unsigned char *)&sin
->sin_addr
;
2407 sa
->sa_family
= family
;
2410 else if (family
== AF_INET6
)
2412 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*) sa
;
2413 uint16_t *ip6
= (uint16_t *)&sin6
->sin6_addr
;
2414 len
= sizeof (sin6
->sin6_addr
) + 1;
2415 i
= XINT (p
->contents
[--len
]);
2416 sin6
->sin6_port
= htons (i
);
2417 for (i
= 0; i
< len
; i
++)
2418 if (INTEGERP (p
->contents
[i
]))
2420 int j
= XFASTINT (p
->contents
[i
]) & 0xffff;
2423 sa
->sa_family
= family
;
2428 else if (STRINGP (address
))
2430 #ifdef HAVE_LOCAL_SOCKETS
2431 if (family
== AF_LOCAL
)
2433 struct sockaddr_un
*sockun
= (struct sockaddr_un
*) sa
;
2434 cp
= SDATA (address
);
2435 for (i
= 0; i
< sizeof (sockun
->sun_path
) && *cp
; i
++)
2436 sockun
->sun_path
[i
] = *cp
++;
2437 sa
->sa_family
= family
;
2444 p
= XVECTOR (XCDR (address
));
2445 cp
= (unsigned char *)sa
+ sizeof (sa
->sa_family
);
2448 for (i
= 0; i
< len
; i
++)
2449 if (INTEGERP (p
->contents
[i
]))
2450 *cp
++ = XFASTINT (p
->contents
[i
]) & 0xff;
2453 #ifdef DATAGRAM_SOCKETS
2454 DEFUN ("process-datagram-address", Fprocess_datagram_address
, Sprocess_datagram_address
,
2456 doc
: /* Get the current datagram address associated with PROCESS. */)
2458 Lisp_Object process
;
2462 CHECK_PROCESS (process
);
2464 if (!DATAGRAM_CONN_P (process
))
2467 channel
= XPROCESS (process
)->infd
;
2468 return conv_sockaddr_to_lisp (datagram_address
[channel
].sa
,
2469 datagram_address
[channel
].len
);
2472 DEFUN ("set-process-datagram-address", Fset_process_datagram_address
, Sset_process_datagram_address
,
2474 doc
: /* Set the datagram address for PROCESS to ADDRESS.
2475 Returns nil upon error setting address, ADDRESS otherwise. */)
2477 Lisp_Object process
, address
;
2482 CHECK_PROCESS (process
);
2484 if (!DATAGRAM_CONN_P (process
))
2487 channel
= XPROCESS (process
)->infd
;
2489 len
= get_lisp_to_sockaddr_size (address
, &family
);
2490 if (datagram_address
[channel
].len
!= len
)
2492 conv_lisp_to_sockaddr (family
, address
, datagram_address
[channel
].sa
, len
);
2498 static struct socket_options
{
2499 /* The name of this option. Should be lowercase version of option
2500 name without SO_ prefix. */
2502 /* Option level SOL_... */
2504 /* Option number SO_... */
2506 enum { SOPT_UNKNOWN
, SOPT_BOOL
, SOPT_INT
, SOPT_IFNAME
, SOPT_LINGER
} opttype
;
2507 enum { OPIX_NONE
=0, OPIX_MISC
=1, OPIX_REUSEADDR
=2 } optbit
;
2508 } socket_options
[] =
2510 #ifdef SO_BINDTODEVICE
2511 { ":bindtodevice", SOL_SOCKET
, SO_BINDTODEVICE
, SOPT_IFNAME
, OPIX_MISC
},
2514 { ":broadcast", SOL_SOCKET
, SO_BROADCAST
, SOPT_BOOL
, OPIX_MISC
},
2517 { ":dontroute", SOL_SOCKET
, SO_DONTROUTE
, SOPT_BOOL
, OPIX_MISC
},
2520 { ":keepalive", SOL_SOCKET
, SO_KEEPALIVE
, SOPT_BOOL
, OPIX_MISC
},
2523 { ":linger", SOL_SOCKET
, SO_LINGER
, SOPT_LINGER
, OPIX_MISC
},
2526 { ":oobinline", SOL_SOCKET
, SO_OOBINLINE
, SOPT_BOOL
, OPIX_MISC
},
2529 { ":priority", SOL_SOCKET
, SO_PRIORITY
, SOPT_INT
, OPIX_MISC
},
2532 { ":reuseaddr", SOL_SOCKET
, SO_REUSEADDR
, SOPT_BOOL
, OPIX_REUSEADDR
},
2534 { 0, 0, 0, SOPT_UNKNOWN
, OPIX_NONE
}
2537 /* Set option OPT to value VAL on socket S.
2539 Returns (1<<socket_options[OPT].optbit) if option is known, 0 otherwise.
2540 Signals an error if setting a known option fails.
2544 set_socket_option (s
, opt
, val
)
2546 Lisp_Object opt
, val
;
2549 struct socket_options
*sopt
;
2554 name
= (char *) SDATA (SYMBOL_NAME (opt
));
2555 for (sopt
= socket_options
; sopt
->name
; sopt
++)
2556 if (strcmp (name
, sopt
->name
) == 0)
2559 switch (sopt
->opttype
)
2564 optval
= NILP (val
) ? 0 : 1;
2565 ret
= setsockopt (s
, sopt
->optlevel
, sopt
->optnum
,
2566 &optval
, sizeof (optval
));
2574 optval
= XINT (val
);
2576 error ("Bad option value for %s", name
);
2577 ret
= setsockopt (s
, sopt
->optlevel
, sopt
->optnum
,
2578 &optval
, sizeof (optval
));
2582 #ifdef SO_BINDTODEVICE
2585 char devname
[IFNAMSIZ
+1];
2587 /* This is broken, at least in the Linux 2.4 kernel.
2588 To unbind, the arg must be a zero integer, not the empty string.
2589 This should work on all systems. KFS. 2003-09-23. */
2590 bzero (devname
, sizeof devname
);
2593 char *arg
= (char *) SDATA (val
);
2594 int len
= min (strlen (arg
), IFNAMSIZ
);
2595 bcopy (arg
, devname
, len
);
2597 else if (!NILP (val
))
2598 error ("Bad option value for %s", name
);
2599 ret
= setsockopt (s
, sopt
->optlevel
, sopt
->optnum
,
2608 struct linger linger
;
2611 linger
.l_linger
= 0;
2613 linger
.l_linger
= XINT (val
);
2615 linger
.l_onoff
= NILP (val
) ? 0 : 1;
2616 ret
= setsockopt (s
, sopt
->optlevel
, sopt
->optnum
,
2617 &linger
, sizeof (linger
));
2627 report_file_error ("Cannot set network option",
2628 Fcons (opt
, Fcons (val
, Qnil
)));
2629 return (1 << sopt
->optbit
);
2633 DEFUN ("set-network-process-option",
2634 Fset_network_process_option
, Sset_network_process_option
,
2636 doc
: /* For network process PROCESS set option OPTION to value VALUE.
2637 See `make-network-process' for a list of options and values.
2638 If optional fourth arg NO-ERROR is non-nil, don't signal an error if
2639 OPTION is not a supported option, return nil instead; otherwise return t. */)
2640 (process
, option
, value
, no_error
)
2641 Lisp_Object process
, option
, value
;
2642 Lisp_Object no_error
;
2645 struct Lisp_Process
*p
;
2647 CHECK_PROCESS (process
);
2648 p
= XPROCESS (process
);
2649 if (!NETCONN1_P (p
))
2650 error ("Process is not a network process");
2654 error ("Process is not running");
2656 if (set_socket_option (s
, option
, value
))
2658 p
->childp
= Fplist_put (p
->childp
, option
, value
);
2662 if (NILP (no_error
))
2663 error ("Unknown or unsupported option");
2670 DEFUN ("serial-process-configure",
2671 Fserial_process_configure
,
2672 Sserial_process_configure
,
2674 doc
: /* Configure speed, bytesize, etc. of a serial process.
2676 Arguments are specified as keyword/argument pairs. Attributes that
2677 are not given are re-initialized from the process's current
2678 configuration (available via the function `process-contact') or set to
2679 reasonable default values. The following arguments are defined:
2685 -- Any of these arguments can be given to identify the process that is
2686 to be configured. If none of these arguments is given, the current
2687 buffer's process is used.
2689 :speed SPEED -- SPEED is the speed of the serial port in bits per
2690 second, also called baud rate. Any value can be given for SPEED, but
2691 most serial ports work only at a few defined values between 1200 and
2692 115200, with 9600 being the most common value. If SPEED is nil, the
2693 serial port is not configured any further, i.e., all other arguments
2694 are ignored. This may be useful for special serial ports such as
2695 Bluetooth-to-serial converters which can only be configured through AT
2696 commands. A value of nil for SPEED can be used only when passed
2697 through `make-serial-process' or `serial-term'.
2699 :bytesize BYTESIZE -- BYTESIZE is the number of bits per byte, which
2700 can be 7 or 8. If BYTESIZE is not given or nil, a value of 8 is used.
2702 :parity PARITY -- PARITY can be nil (don't use parity), the symbol
2703 `odd' (use odd parity), or the symbol `even' (use even parity). If
2704 PARITY is not given, no parity is used.
2706 :stopbits STOPBITS -- STOPBITS is the number of stopbits used to
2707 terminate a byte transmission. STOPBITS can be 1 or 2. If STOPBITS
2708 is not given or nil, 1 stopbit is used.
2710 :flowcontrol FLOWCONTROL -- FLOWCONTROL determines the type of
2711 flowcontrol to be used, which is either nil (don't use flowcontrol),
2712 the symbol `hw' (use RTS/CTS hardware flowcontrol), or the symbol `sw'
2713 \(use XON/XOFF software flowcontrol). If FLOWCONTROL is not given, no
2714 flowcontrol is used.
2716 `serial-process-configure' is called by `make-serial-process' for the
2717 initial configuration of the serial port.
2721 \(serial-process-configure :process "/dev/ttyS0" :speed 1200)
2723 \(serial-process-configure
2724 :buffer "COM1" :stopbits 1 :parity 'odd :flowcontrol 'hw)
2726 \(serial-process-configure :port "\\\\.\\COM13" :bytesize 7)
2728 usage: (serial-process-configure &rest ARGS) */)
2733 struct Lisp_Process
*p
;
2734 Lisp_Object contact
= Qnil
;
2735 Lisp_Object proc
= Qnil
;
2736 struct gcpro gcpro1
;
2738 contact
= Flist (nargs
, args
);
2741 proc
= Fplist_get (contact
, QCprocess
);
2743 proc
= Fplist_get (contact
, QCname
);
2745 proc
= Fplist_get (contact
, QCbuffer
);
2747 proc
= Fplist_get (contact
, QCport
);
2748 proc
= get_process (proc
);
2749 p
= XPROCESS (proc
);
2750 if (!EQ (p
->type
, Qserial
))
2751 error ("Not a serial process");
2753 if (NILP (Fplist_get (p
->childp
, QCspeed
)))
2759 serial_configure (p
, contact
);
2765 /* Used by make-serial-process to recover from errors. */
2766 Lisp_Object
make_serial_process_unwind (Lisp_Object proc
)
2768 if (!PROCESSP (proc
))
2770 remove_process (proc
);
2774 DEFUN ("make-serial-process", Fmake_serial_process
, Smake_serial_process
,
2776 doc
: /* Create and return a serial port process.
2778 In Emacs, serial port connections are represented by process objects,
2779 so input and output work as for subprocesses, and `delete-process'
2780 closes a serial port connection. However, a serial process has no
2781 process id, it cannot be signaled, and the status codes are different
2782 from normal processes.
2784 `make-serial-process' creates a process and a buffer, on which you
2785 probably want to use `process-send-string'. Try \\[serial-term] for
2786 an interactive terminal. See below for examples.
2788 Arguments are specified as keyword/argument pairs. The following
2789 arguments are defined:
2791 :port PORT -- (mandatory) PORT is the path or name of the serial port.
2792 For example, this could be "/dev/ttyS0" on Unix. On Windows, this
2793 could be "COM1", or "\\\\.\\COM10" for ports higher than COM9 (double
2794 the backslashes in strings).
2796 :speed SPEED -- (mandatory) is handled by `serial-process-configure',
2797 which is called by `make-serial-process'.
2799 :name NAME -- NAME is the name of the process. If NAME is not given,
2800 the value of PORT is used.
2802 :buffer BUFFER -- BUFFER is the buffer (or buffer-name) to associate
2803 with the process. Process output goes at the end of that buffer,
2804 unless you specify an output stream or filter function to handle the
2805 output. If BUFFER is not given, the value of NAME is used.
2807 :coding CODING -- If CODING is a symbol, it specifies the coding
2808 system used for both reading and writing for this process. If CODING
2809 is a cons (DECODING . ENCODING), DECODING is used for reading, and
2810 ENCODING is used for writing.
2812 :noquery BOOL -- When exiting Emacs, query the user if BOOL is nil and
2813 the process is running. If BOOL is not given, query before exiting.
2815 :stop BOOL -- Start process in the `stopped' state if BOOL is non-nil.
2816 In the stopped state, a serial process does not accept incoming data,
2817 but you can send outgoing data. The stopped state is cleared by
2818 `continue-process' and set by `stop-process'.
2820 :filter FILTER -- Install FILTER as the process filter.
2822 :sentinel SENTINEL -- Install SENTINEL as the process sentinel.
2824 :plist PLIST -- Install PLIST as the initial plist of the process.
2831 -- These arguments are handled by `serial-process-configure', which is
2832 called by `make-serial-process'.
2834 The original argument list, possibly modified by later configuration,
2835 is available via the function `process-contact'.
2839 \(make-serial-process :port "/dev/ttyS0" :speed 9600)
2841 \(make-serial-process :port "COM1" :speed 115200 :stopbits 2)
2843 \(make-serial-process :port "\\\\.\\COM13" :speed 1200 :bytesize 7 :parity 'odd)
2845 \(make-serial-process :port "/dev/tty.BlueConsole-SPP-1" :speed nil)
2847 usage: (make-serial-process &rest ARGS) */)
2853 Lisp_Object proc
, contact
, port
;
2854 struct Lisp_Process
*p
;
2855 struct gcpro gcpro1
;
2856 Lisp_Object name
, buffer
;
2857 Lisp_Object tem
, val
;
2858 int specpdl_count
= -1;
2863 contact
= Flist (nargs
, args
);
2866 port
= Fplist_get (contact
, QCport
);
2868 error ("No port specified");
2869 CHECK_STRING (port
);
2871 if (NILP (Fplist_member (contact
, QCspeed
)))
2872 error (":speed not specified");
2873 if (!NILP (Fplist_get (contact
, QCspeed
)))
2874 CHECK_NUMBER (Fplist_get (contact
, QCspeed
));
2876 name
= Fplist_get (contact
, QCname
);
2879 CHECK_STRING (name
);
2880 proc
= make_process (name
);
2881 specpdl_count
= SPECPDL_INDEX ();
2882 record_unwind_protect (make_serial_process_unwind
, proc
);
2883 p
= XPROCESS (proc
);
2885 fd
= serial_open ((char*) SDATA (port
));
2888 if (fd
> max_process_desc
)
2889 max_process_desc
= fd
;
2890 chan_process
[fd
] = proc
;
2892 buffer
= Fplist_get (contact
, QCbuffer
);
2895 buffer
= Fget_buffer_create (buffer
);
2898 p
->childp
= contact
;
2899 p
->plist
= Fcopy_sequence (Fplist_get (contact
, QCplist
));
2901 p
->sentinel
= Fplist_get (contact
, QCsentinel
);
2902 p
->filter
= Fplist_get (contact
, QCfilter
);
2904 if (tem
= Fplist_get (contact
, QCnoquery
), !NILP (tem
))
2905 p
->kill_without_query
= 1;
2906 if (tem
= Fplist_get (contact
, QCstop
), !NILP (tem
))
2910 if (!EQ (p
->command
, Qt
))
2912 FD_SET (fd
, &input_wait_mask
);
2913 FD_SET (fd
, &non_keyboard_wait_mask
);
2916 if (BUFFERP (buffer
))
2918 set_marker_both (p
->mark
, buffer
,
2919 BUF_ZV (XBUFFER (buffer
)),
2920 BUF_ZV_BYTE (XBUFFER (buffer
)));
2923 tem
= Fplist_member (contact
, QCcoding
);
2924 if (!NILP (tem
) && (!CONSP (tem
) || !CONSP (XCDR (tem
))))
2930 val
= XCAR (XCDR (tem
));
2934 else if (!NILP (Vcoding_system_for_read
))
2935 val
= Vcoding_system_for_read
;
2936 else if ((!NILP (buffer
) && NILP (XBUFFER (buffer
)->enable_multibyte_characters
))
2937 || (NILP (buffer
) && NILP (buffer_defaults
.enable_multibyte_characters
)))
2939 p
->decode_coding_system
= val
;
2944 val
= XCAR (XCDR (tem
));
2948 else if (!NILP (Vcoding_system_for_write
))
2949 val
= Vcoding_system_for_write
;
2950 else if ((!NILP (buffer
) && NILP (XBUFFER (buffer
)->enable_multibyte_characters
))
2951 || (NILP (buffer
) && NILP (buffer_defaults
.enable_multibyte_characters
)))
2953 p
->encode_coding_system
= val
;
2955 setup_process_coding_systems (proc
);
2956 p
->decoding_buf
= make_uninit_string (0);
2957 p
->decoding_carryover
= 0;
2958 p
->encoding_buf
= make_uninit_string (0);
2959 p
->inherit_coding_system_flag
2960 = !(!NILP (tem
) || NILP (buffer
) || !inherit_process_coding_system
);
2962 Fserial_process_configure(nargs
, args
);
2964 specpdl_ptr
= specpdl
+ specpdl_count
;
2969 #endif /* HAVE_SERIAL */
2971 /* Create a network stream/datagram client/server process. Treated
2972 exactly like a normal process when reading and writing. Primary
2973 differences are in status display and process deletion. A network
2974 connection has no PID; you cannot signal it. All you can do is
2975 stop/continue it and deactivate/close it via delete-process */
2977 DEFUN ("make-network-process", Fmake_network_process
, Smake_network_process
,
2979 doc
: /* Create and return a network server or client process.
2981 In Emacs, network connections are represented by process objects, so
2982 input and output work as for subprocesses and `delete-process' closes
2983 a network connection. However, a network process has no process id,
2984 it cannot be signaled, and the status codes are different from normal
2987 Arguments are specified as keyword/argument pairs. The following
2988 arguments are defined:
2990 :name NAME -- NAME is name for process. It is modified if necessary
2993 :buffer BUFFER -- BUFFER is the buffer (or buffer-name) to associate
2994 with the process. Process output goes at end of that buffer, unless
2995 you specify an output stream or filter function to handle the output.
2996 BUFFER may be also nil, meaning that this process is not associated
2999 :host HOST -- HOST is name of the host to connect to, or its IP
3000 address. The symbol `local' specifies the local host. If specified
3001 for a server process, it must be a valid name or address for the local
3002 host, and only clients connecting to that address will be accepted.
3004 :service SERVICE -- SERVICE is name of the service desired, or an
3005 integer specifying a port number to connect to. If SERVICE is t,
3006 a random port number is selected for the server. (If Emacs was
3007 compiled with getaddrinfo, a port number can also be specified as a
3008 string, e.g. "80", as well as an integer. This is not portable.)
3010 :type TYPE -- TYPE is the type of connection. The default (nil) is a
3011 stream type connection, `datagram' creates a datagram type connection.
3013 :family FAMILY -- FAMILY is the address (and protocol) family for the
3014 service specified by HOST and SERVICE. The default (nil) is to use
3015 whatever address family (IPv4 or IPv6) that is defined for the host
3016 and port number specified by HOST and SERVICE. Other address families
3018 local -- for a local (i.e. UNIX) address specified by SERVICE.
3019 ipv4 -- use IPv4 address family only.
3020 ipv6 -- use IPv6 address family only.
3022 :local ADDRESS -- ADDRESS is the local address used for the connection.
3023 This parameter is ignored when opening a client process. When specified
3024 for a server process, the FAMILY, HOST and SERVICE args are ignored.
3026 :remote ADDRESS -- ADDRESS is the remote partner's address for the
3027 connection. This parameter is ignored when opening a stream server
3028 process. For a datagram server process, it specifies the initial
3029 setting of the remote datagram address. When specified for a client
3030 process, the FAMILY, HOST, and SERVICE args are ignored.
3032 The format of ADDRESS depends on the address family:
3033 - An IPv4 address is represented as an vector of integers [A B C D P]
3034 corresponding to numeric IP address A.B.C.D and port number P.
3035 - A local address is represented as a string with the address in the
3036 local address space.
3037 - An "unsupported family" address is represented by a cons (F . AV)
3038 where F is the family number and AV is a vector containing the socket
3039 address data with one element per address data byte. Do not rely on
3040 this format in portable code, as it may depend on implementation
3041 defined constants, data sizes, and data structure alignment.
3043 :coding CODING -- If CODING is a symbol, it specifies the coding
3044 system used for both reading and writing for this process. If CODING
3045 is a cons (DECODING . ENCODING), DECODING is used for reading, and
3046 ENCODING is used for writing.
3048 :nowait BOOL -- If BOOL is non-nil for a stream type client process,
3049 return without waiting for the connection to complete; instead, the
3050 sentinel function will be called with second arg matching "open" (if
3051 successful) or "failed" when the connect completes. Default is to use
3052 a blocking connect (i.e. wait) for stream type connections.
3054 :noquery BOOL -- Query the user unless BOOL is non-nil, and process is
3055 running when Emacs is exited.
3057 :stop BOOL -- Start process in the `stopped' state if BOOL non-nil.
3058 In the stopped state, a server process does not accept new
3059 connections, and a client process does not handle incoming traffic.
3060 The stopped state is cleared by `continue-process' and set by
3063 :filter FILTER -- Install FILTER as the process filter.
3065 :filter-multibyte BOOL -- If BOOL is non-nil, strings given to the
3066 process filter are multibyte, otherwise they are unibyte.
3067 If this keyword is not specified, the strings are multibyte if
3068 `default-enable-multibyte-characters' is non-nil.
3070 :sentinel SENTINEL -- Install SENTINEL as the process sentinel.
3072 :log LOG -- Install LOG as the server process log function. This
3073 function is called when the server accepts a network connection from a
3074 client. The arguments are SERVER, CLIENT, and MESSAGE, where SERVER
3075 is the server process, CLIENT is the new process for the connection,
3076 and MESSAGE is a string.
3078 :plist PLIST -- Install PLIST as the new process' initial plist.
3080 :server QLEN -- if QLEN is non-nil, create a server process for the
3081 specified FAMILY, SERVICE, and connection type (stream or datagram).
3082 If QLEN is an integer, it is used as the max. length of the server's
3083 pending connection queue (also known as the backlog); the default
3084 queue length is 5. Default is to create a client process.
3086 The following network options can be specified for this connection:
3088 :broadcast BOOL -- Allow send and receive of datagram broadcasts.
3089 :dontroute BOOL -- Only send to directly connected hosts.
3090 :keepalive BOOL -- Send keep-alive messages on network stream.
3091 :linger BOOL or TIMEOUT -- Send queued messages before closing.
3092 :oobinline BOOL -- Place out-of-band data in receive data stream.
3093 :priority INT -- Set protocol defined priority for sent packets.
3094 :reuseaddr BOOL -- Allow reusing a recently used local address
3095 (this is allowed by default for a server process).
3096 :bindtodevice NAME -- bind to interface NAME. Using this may require
3097 special privileges on some systems.
3099 Consult the relevant system programmer's manual pages for more
3100 information on using these options.
3103 A server process will listen for and accept connections from clients.
3104 When a client connection is accepted, a new network process is created
3105 for the connection with the following parameters:
3107 - The client's process name is constructed by concatenating the server
3108 process' NAME and a client identification string.
3109 - If the FILTER argument is non-nil, the client process will not get a
3110 separate process buffer; otherwise, the client's process buffer is a newly
3111 created buffer named after the server process' BUFFER name or process
3112 NAME concatenated with the client identification string.
3113 - The connection type and the process filter and sentinel parameters are
3114 inherited from the server process' TYPE, FILTER and SENTINEL.
3115 - The client process' contact info is set according to the client's
3116 addressing information (typically an IP address and a port number).
3117 - The client process' plist is initialized from the server's plist.
3119 Notice that the FILTER and SENTINEL args are never used directly by
3120 the server process. Also, the BUFFER argument is not used directly by
3121 the server process, but via the optional :log function, accepted (and
3122 failed) connections may be logged in the server process' buffer.
3124 The original argument list, modified with the actual connection
3125 information, is available via the `process-contact' function.
3127 usage: (make-network-process &rest ARGS) */)
3133 Lisp_Object contact
;
3134 struct Lisp_Process
*p
;
3135 #ifdef HAVE_GETADDRINFO
3136 struct addrinfo ai
, *res
, *lres
;
3137 struct addrinfo hints
;
3138 char *portstring
, portbuf
[128];
3139 #else /* HAVE_GETADDRINFO */
3140 struct _emacs_addrinfo
3146 struct sockaddr
*ai_addr
;
3147 struct _emacs_addrinfo
*ai_next
;
3149 #endif /* HAVE_GETADDRINFO */
3150 struct sockaddr_in address_in
;
3151 #ifdef HAVE_LOCAL_SOCKETS
3152 struct sockaddr_un address_un
;
3157 int s
= -1, outch
, inch
;
3158 struct gcpro gcpro1
;
3159 int count
= SPECPDL_INDEX ();
3161 Lisp_Object QCaddress
; /* one of QClocal or QCremote */
3163 Lisp_Object name
, buffer
, host
, service
, address
;
3164 Lisp_Object filter
, sentinel
;
3165 int is_non_blocking_client
= 0;
3166 int is_server
= 0, backlog
= 5;
3173 /* Save arguments for process-contact and clone-process. */
3174 contact
= Flist (nargs
, args
);
3178 /* Ensure socket support is loaded if available. */
3179 init_winsock (TRUE
);
3182 /* :type TYPE (nil: stream, datagram */
3183 tem
= Fplist_get (contact
, QCtype
);
3185 socktype
= SOCK_STREAM
;
3186 #ifdef DATAGRAM_SOCKETS
3187 else if (EQ (tem
, Qdatagram
))
3188 socktype
= SOCK_DGRAM
;
3191 error ("Unsupported connection type");
3194 tem
= Fplist_get (contact
, QCserver
);
3197 /* Don't support network sockets when non-blocking mode is
3198 not available, since a blocked Emacs is not useful. */
3199 #if !defined(O_NONBLOCK) && !defined(O_NDELAY)
3200 error ("Network servers not supported");
3204 backlog
= XINT (tem
);
3208 /* Make QCaddress an alias for :local (server) or :remote (client). */
3209 QCaddress
= is_server
? QClocal
: QCremote
;
3212 if (!is_server
&& socktype
== SOCK_STREAM
3213 && (tem
= Fplist_get (contact
, QCnowait
), !NILP (tem
)))
3215 #ifndef NON_BLOCKING_CONNECT
3216 error ("Non-blocking connect not supported");
3218 is_non_blocking_client
= 1;
3222 name
= Fplist_get (contact
, QCname
);
3223 buffer
= Fplist_get (contact
, QCbuffer
);
3224 filter
= Fplist_get (contact
, QCfilter
);
3225 sentinel
= Fplist_get (contact
, QCsentinel
);
3227 CHECK_STRING (name
);
3229 /* Initialize addrinfo structure in case we don't use getaddrinfo. */
3230 ai
.ai_socktype
= socktype
;
3235 /* :local ADDRESS or :remote ADDRESS */
3236 address
= Fplist_get (contact
, QCaddress
);
3237 if (!NILP (address
))
3239 host
= service
= Qnil
;
3241 if (!(ai
.ai_addrlen
= get_lisp_to_sockaddr_size (address
, &family
)))
3242 error ("Malformed :address");
3243 ai
.ai_family
= family
;
3244 ai
.ai_addr
= alloca (ai
.ai_addrlen
);
3245 conv_lisp_to_sockaddr (family
, address
, ai
.ai_addr
, ai
.ai_addrlen
);
3249 /* :family FAMILY -- nil (for Inet), local, or integer. */
3250 tem
= Fplist_get (contact
, QCfamily
);
3253 #if defined(HAVE_GETADDRINFO) && defined(AF_INET6)
3259 #ifdef HAVE_LOCAL_SOCKETS
3260 else if (EQ (tem
, Qlocal
))
3264 else if (EQ (tem
, Qipv6
))
3267 else if (EQ (tem
, Qipv4
))
3269 else if (INTEGERP (tem
))
3270 family
= XINT (tem
);
3272 error ("Unknown address family");
3274 ai
.ai_family
= family
;
3276 /* :service SERVICE -- string, integer (port number), or t (random port). */
3277 service
= Fplist_get (contact
, QCservice
);
3279 #ifdef HAVE_LOCAL_SOCKETS
3280 if (family
== AF_LOCAL
)
3282 /* Host is not used. */
3284 CHECK_STRING (service
);
3285 bzero (&address_un
, sizeof address_un
);
3286 address_un
.sun_family
= AF_LOCAL
;
3287 strncpy (address_un
.sun_path
, SDATA (service
), sizeof address_un
.sun_path
);
3288 ai
.ai_addr
= (struct sockaddr
*) &address_un
;
3289 ai
.ai_addrlen
= sizeof address_un
;
3294 /* :host HOST -- hostname, ip address, or 'local for localhost. */
3295 host
= Fplist_get (contact
, QChost
);
3298 if (EQ (host
, Qlocal
))
3299 host
= build_string ("localhost");
3300 CHECK_STRING (host
);
3303 /* Slow down polling to every ten seconds.
3304 Some kernels have a bug which causes retrying connect to fail
3305 after a connect. Polling can interfere with gethostbyname too. */
3306 #ifdef POLL_FOR_INPUT
3307 if (socktype
== SOCK_STREAM
)
3309 record_unwind_protect (unwind_stop_other_atimers
, Qnil
);
3310 bind_polling_period (10);
3314 #ifdef HAVE_GETADDRINFO
3315 /* If we have a host, use getaddrinfo to resolve both host and service.
3316 Otherwise, use getservbyname to lookup the service. */
3320 /* SERVICE can either be a string or int.
3321 Convert to a C string for later use by getaddrinfo. */
3322 if (EQ (service
, Qt
))
3324 else if (INTEGERP (service
))
3326 sprintf (portbuf
, "%ld", (long) XINT (service
));
3327 portstring
= portbuf
;
3331 CHECK_STRING (service
);
3332 portstring
= SDATA (service
);
3337 memset (&hints
, 0, sizeof (hints
));
3339 hints
.ai_family
= family
;
3340 hints
.ai_socktype
= socktype
;
3341 hints
.ai_protocol
= 0;
3343 #ifdef HAVE_RES_INIT
3347 ret
= getaddrinfo (SDATA (host
), portstring
, &hints
, &res
);
3349 #ifdef HAVE_GAI_STRERROR
3350 error ("%s/%s %s", SDATA (host
), portstring
, gai_strerror(ret
));
3352 error ("%s/%s getaddrinfo error %d", SDATA (host
), portstring
, ret
);
3358 #endif /* HAVE_GETADDRINFO */
3360 /* We end up here if getaddrinfo is not defined, or in case no hostname
3361 has been specified (e.g. for a local server process). */
3363 if (EQ (service
, Qt
))
3365 else if (INTEGERP (service
))
3366 port
= htons ((unsigned short) XINT (service
));
3369 struct servent
*svc_info
;
3370 CHECK_STRING (service
);
3371 svc_info
= getservbyname (SDATA (service
),
3372 (socktype
== SOCK_DGRAM
? "udp" : "tcp"));
3374 error ("Unknown service: %s", SDATA (service
));
3375 port
= svc_info
->s_port
;
3378 bzero (&address_in
, sizeof address_in
);
3379 address_in
.sin_family
= family
;
3380 address_in
.sin_addr
.s_addr
= INADDR_ANY
;
3381 address_in
.sin_port
= port
;
3383 #ifndef HAVE_GETADDRINFO
3386 struct hostent
*host_info_ptr
;
3388 /* gethostbyname may fail with TRY_AGAIN, but we don't honour that,
3389 as it may `hang' Emacs for a very long time. */
3393 #ifdef HAVE_RES_INIT
3397 host_info_ptr
= gethostbyname (SDATA (host
));
3402 bcopy (host_info_ptr
->h_addr
, (char *) &address_in
.sin_addr
,
3403 host_info_ptr
->h_length
);
3404 family
= host_info_ptr
->h_addrtype
;
3405 address_in
.sin_family
= family
;
3408 /* Attempt to interpret host as numeric inet address */
3410 unsigned long numeric_addr
;
3411 numeric_addr
= inet_addr ((char *) SDATA (host
));
3412 if (numeric_addr
== -1)
3413 error ("Unknown host \"%s\"", SDATA (host
));
3415 bcopy ((char *)&numeric_addr
, (char *) &address_in
.sin_addr
,
3416 sizeof (address_in
.sin_addr
));
3420 #endif /* not HAVE_GETADDRINFO */
3422 ai
.ai_family
= family
;
3423 ai
.ai_addr
= (struct sockaddr
*) &address_in
;
3424 ai
.ai_addrlen
= sizeof address_in
;
3428 /* Do this in case we never enter the for-loop below. */
3429 count1
= SPECPDL_INDEX ();
3432 for (lres
= res
; lres
; lres
= lres
->ai_next
)
3438 s
= socket (lres
->ai_family
, lres
->ai_socktype
, lres
->ai_protocol
);
3445 #ifdef DATAGRAM_SOCKETS
3446 if (!is_server
&& socktype
== SOCK_DGRAM
)
3448 #endif /* DATAGRAM_SOCKETS */
3450 #ifdef NON_BLOCKING_CONNECT
3451 if (is_non_blocking_client
)
3454 ret
= fcntl (s
, F_SETFL
, O_NONBLOCK
);
3456 ret
= fcntl (s
, F_SETFL
, O_NDELAY
);
3468 /* Make us close S if quit. */
3469 record_unwind_protect (close_file_unwind
, make_number (s
));
3471 /* Parse network options in the arg list.
3472 We simply ignore anything which isn't a known option (including other keywords).
3473 An error is signaled if setting a known option fails. */
3474 for (optn
= optbits
= 0; optn
< nargs
-1; optn
+= 2)
3475 optbits
|= set_socket_option (s
, args
[optn
], args
[optn
+1]);
3479 /* Configure as a server socket. */
3481 /* SO_REUSEADDR = 1 is default for server sockets; must specify
3482 explicit :reuseaddr key to override this. */
3483 #ifdef HAVE_LOCAL_SOCKETS
3484 if (family
!= AF_LOCAL
)
3486 if (!(optbits
& (1 << OPIX_REUSEADDR
)))
3489 if (setsockopt (s
, SOL_SOCKET
, SO_REUSEADDR
, &optval
, sizeof optval
))
3490 report_file_error ("Cannot set reuse option on server socket", Qnil
);
3493 if (bind (s
, lres
->ai_addr
, lres
->ai_addrlen
))
3494 report_file_error ("Cannot bind server socket", Qnil
);
3496 #ifdef HAVE_GETSOCKNAME
3497 if (EQ (service
, Qt
))
3499 struct sockaddr_in sa1
;
3500 int len1
= sizeof (sa1
);
3501 if (getsockname (s
, (struct sockaddr
*)&sa1
, &len1
) == 0)
3503 ((struct sockaddr_in
*)(lres
->ai_addr
))->sin_port
= sa1
.sin_port
;
3504 service
= make_number (ntohs (sa1
.sin_port
));
3505 contact
= Fplist_put (contact
, QCservice
, service
);
3510 if (socktype
== SOCK_STREAM
&& listen (s
, backlog
))
3511 report_file_error ("Cannot listen on server socket", Qnil
);
3519 /* This turns off all alarm-based interrupts; the
3520 bind_polling_period call above doesn't always turn all the
3521 short-interval ones off, especially if interrupt_input is
3524 It'd be nice to be able to control the connect timeout
3525 though. Would non-blocking connect calls be portable?
3527 This used to be conditioned by HAVE_GETADDRINFO. Why? */
3529 turn_on_atimers (0);
3531 ret
= connect (s
, lres
->ai_addr
, lres
->ai_addrlen
);
3534 turn_on_atimers (1);
3536 if (ret
== 0 || xerrno
== EISCONN
)
3538 /* The unwind-protect will be discarded afterwards.
3539 Likewise for immediate_quit. */
3543 #ifdef NON_BLOCKING_CONNECT
3545 if (is_non_blocking_client
&& xerrno
== EINPROGRESS
)
3549 if (is_non_blocking_client
&& xerrno
== EWOULDBLOCK
)
3557 /* Discard the unwind protect closing S. */
3558 specpdl_ptr
= specpdl
+ count1
;
3562 if (xerrno
== EINTR
)
3568 #ifdef DATAGRAM_SOCKETS
3569 if (socktype
== SOCK_DGRAM
)
3571 if (datagram_address
[s
].sa
)
3573 datagram_address
[s
].sa
= (struct sockaddr
*) xmalloc (lres
->ai_addrlen
);
3574 datagram_address
[s
].len
= lres
->ai_addrlen
;
3578 bzero (datagram_address
[s
].sa
, lres
->ai_addrlen
);
3579 if (remote
= Fplist_get (contact
, QCremote
), !NILP (remote
))
3582 rlen
= get_lisp_to_sockaddr_size (remote
, &rfamily
);
3583 if (rfamily
== lres
->ai_family
&& rlen
== lres
->ai_addrlen
)
3584 conv_lisp_to_sockaddr (rfamily
, remote
,
3585 datagram_address
[s
].sa
, rlen
);
3589 bcopy (lres
->ai_addr
, datagram_address
[s
].sa
, lres
->ai_addrlen
);
3592 contact
= Fplist_put (contact
, QCaddress
,
3593 conv_sockaddr_to_lisp (lres
->ai_addr
, lres
->ai_addrlen
));
3594 #ifdef HAVE_GETSOCKNAME
3597 struct sockaddr_in sa1
;
3598 int len1
= sizeof (sa1
);
3599 if (getsockname (s
, (struct sockaddr
*)&sa1
, &len1
) == 0)
3600 contact
= Fplist_put (contact
, QClocal
,
3601 conv_sockaddr_to_lisp (&sa1
, len1
));
3608 #ifdef HAVE_GETADDRINFO
3617 /* Discard the unwind protect for closing S, if any. */
3618 specpdl_ptr
= specpdl
+ count1
;
3620 /* Unwind bind_polling_period and request_sigio. */
3621 unbind_to (count
, Qnil
);
3625 /* If non-blocking got this far - and failed - assume non-blocking is
3626 not supported after all. This is probably a wrong assumption, but
3627 the normal blocking calls to open-network-stream handles this error
3629 if (is_non_blocking_client
)
3634 report_file_error ("make server process failed", contact
);
3636 report_file_error ("make client process failed", contact
);
3643 buffer
= Fget_buffer_create (buffer
);
3644 proc
= make_process (name
);
3646 chan_process
[inch
] = proc
;
3649 fcntl (inch
, F_SETFL
, O_NONBLOCK
);
3652 fcntl (inch
, F_SETFL
, O_NDELAY
);
3656 p
= XPROCESS (proc
);
3658 p
->childp
= contact
;
3659 p
->plist
= Fcopy_sequence (Fplist_get (contact
, QCplist
));
3663 p
->sentinel
= sentinel
;
3665 p
->log
= Fplist_get (contact
, QClog
);
3666 if (tem
= Fplist_get (contact
, QCnoquery
), !NILP (tem
))
3667 p
->kill_without_query
= 1;
3668 if ((tem
= Fplist_get (contact
, QCstop
), !NILP (tem
)))
3673 if (is_server
&& socktype
== SOCK_STREAM
)
3674 p
->status
= Qlisten
;
3676 /* Make the process marker point into the process buffer (if any). */
3677 if (BUFFERP (buffer
))
3678 set_marker_both (p
->mark
, buffer
,
3679 BUF_ZV (XBUFFER (buffer
)),
3680 BUF_ZV_BYTE (XBUFFER (buffer
)));
3682 #ifdef NON_BLOCKING_CONNECT
3683 if (is_non_blocking_client
)
3685 /* We may get here if connect did succeed immediately. However,
3686 in that case, we still need to signal this like a non-blocking
3688 p
->status
= Qconnect
;
3689 if (!FD_ISSET (inch
, &connect_wait_mask
))
3691 FD_SET (inch
, &connect_wait_mask
);
3692 num_pending_connects
++;
3697 /* A server may have a client filter setting of Qt, but it must
3698 still listen for incoming connects unless it is stopped. */
3699 if ((!EQ (p
->filter
, Qt
) && !EQ (p
->command
, Qt
))
3700 || (EQ (p
->status
, Qlisten
) && NILP (p
->command
)))
3702 FD_SET (inch
, &input_wait_mask
);
3703 FD_SET (inch
, &non_keyboard_wait_mask
);
3706 if (inch
> max_process_desc
)
3707 max_process_desc
= inch
;
3709 tem
= Fplist_member (contact
, QCcoding
);
3710 if (!NILP (tem
) && (!CONSP (tem
) || !CONSP (XCDR (tem
))))
3711 tem
= Qnil
; /* No error message (too late!). */
3714 /* Setup coding systems for communicating with the network stream. */
3715 struct gcpro gcpro1
;
3716 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
3717 Lisp_Object coding_systems
= Qt
;
3718 Lisp_Object args
[5], val
;
3722 val
= XCAR (XCDR (tem
));
3726 else if (!NILP (Vcoding_system_for_read
))
3727 val
= Vcoding_system_for_read
;
3728 else if ((!NILP (buffer
) && NILP (XBUFFER (buffer
)->enable_multibyte_characters
))
3729 || (NILP (buffer
) && NILP (buffer_defaults
.enable_multibyte_characters
)))
3730 /* We dare not decode end-of-line format by setting VAL to
3731 Qraw_text, because the existing Emacs Lisp libraries
3732 assume that they receive bare code including a sequene of
3737 if (NILP (host
) || NILP (service
))
3738 coding_systems
= Qnil
;
3741 args
[0] = Qopen_network_stream
, args
[1] = name
,
3742 args
[2] = buffer
, args
[3] = host
, args
[4] = service
;
3744 coding_systems
= Ffind_operation_coding_system (5, args
);
3747 if (CONSP (coding_systems
))
3748 val
= XCAR (coding_systems
);
3749 else if (CONSP (Vdefault_process_coding_system
))
3750 val
= XCAR (Vdefault_process_coding_system
);
3754 p
->decode_coding_system
= val
;
3758 val
= XCAR (XCDR (tem
));
3762 else if (!NILP (Vcoding_system_for_write
))
3763 val
= Vcoding_system_for_write
;
3764 else if (NILP (current_buffer
->enable_multibyte_characters
))
3768 if (EQ (coding_systems
, Qt
))
3770 if (NILP (host
) || NILP (service
))
3771 coding_systems
= Qnil
;
3774 args
[0] = Qopen_network_stream
, args
[1] = name
,
3775 args
[2] = buffer
, args
[3] = host
, args
[4] = service
;
3777 coding_systems
= Ffind_operation_coding_system (5, args
);
3781 if (CONSP (coding_systems
))
3782 val
= XCDR (coding_systems
);
3783 else if (CONSP (Vdefault_process_coding_system
))
3784 val
= XCDR (Vdefault_process_coding_system
);
3788 p
->encode_coding_system
= val
;
3790 setup_process_coding_systems (proc
);
3792 p
->decoding_buf
= make_uninit_string (0);
3793 p
->decoding_carryover
= 0;
3794 p
->encoding_buf
= make_uninit_string (0);
3796 p
->inherit_coding_system_flag
3797 = !(!NILP (tem
) || NILP (buffer
) || !inherit_process_coding_system
);
3802 #endif /* HAVE_SOCKETS */
3805 #if defined(HAVE_SOCKETS) && defined(HAVE_NET_IF_H) && defined(HAVE_SYS_IOCTL_H)
3808 DEFUN ("network-interface-list", Fnetwork_interface_list
, Snetwork_interface_list
, 0, 0, 0,
3809 doc
: /* Return an alist of all network interfaces and their network address.
3810 Each element is a cons, the car of which is a string containing the
3811 interface name, and the cdr is the network address in internal
3812 format; see the description of ADDRESS in `make-network-process'. */)
3815 struct ifconf ifconf
;
3816 struct ifreq
*ifreqs
= NULL
;
3821 s
= socket (AF_INET
, SOCK_STREAM
, 0);
3827 buf_size
= ifaces
* sizeof(ifreqs
[0]);
3828 ifreqs
= (struct ifreq
*)xrealloc(ifreqs
, buf_size
);
3835 ifconf
.ifc_len
= buf_size
;
3836 ifconf
.ifc_req
= ifreqs
;
3837 if (ioctl (s
, SIOCGIFCONF
, &ifconf
))
3843 if (ifconf
.ifc_len
== buf_size
)
3847 ifaces
= ifconf
.ifc_len
/ sizeof (ifreqs
[0]);
3850 while (--ifaces
>= 0)
3852 struct ifreq
*ifq
= &ifreqs
[ifaces
];
3853 char namebuf
[sizeof (ifq
->ifr_name
) + 1];
3854 if (ifq
->ifr_addr
.sa_family
!= AF_INET
)
3856 bcopy (ifq
->ifr_name
, namebuf
, sizeof (ifq
->ifr_name
));
3857 namebuf
[sizeof (ifq
->ifr_name
)] = 0;
3858 res
= Fcons (Fcons (build_string (namebuf
),
3859 conv_sockaddr_to_lisp (&ifq
->ifr_addr
,
3860 sizeof (struct sockaddr
))),
3866 #endif /* SIOCGIFCONF */
3868 #if defined(SIOCGIFADDR) || defined(SIOCGIFHWADDR) || defined(SIOCGIFFLAGS)
3875 static struct ifflag_def ifflag_table
[] = {
3879 #ifdef IFF_BROADCAST
3880 { IFF_BROADCAST
, "broadcast" },
3883 { IFF_DEBUG
, "debug" },
3886 { IFF_LOOPBACK
, "loopback" },
3888 #ifdef IFF_POINTOPOINT
3889 { IFF_POINTOPOINT
, "pointopoint" },
3892 { IFF_RUNNING
, "running" },
3895 { IFF_NOARP
, "noarp" },
3898 { IFF_PROMISC
, "promisc" },
3900 #ifdef IFF_NOTRAILERS
3901 { IFF_NOTRAILERS
, "notrailers" },
3904 { IFF_ALLMULTI
, "allmulti" },
3907 { IFF_MASTER
, "master" },
3910 { IFF_SLAVE
, "slave" },
3912 #ifdef IFF_MULTICAST
3913 { IFF_MULTICAST
, "multicast" },
3916 { IFF_PORTSEL
, "portsel" },
3918 #ifdef IFF_AUTOMEDIA
3919 { IFF_AUTOMEDIA
, "automedia" },
3922 { IFF_DYNAMIC
, "dynamic" },
3925 { IFF_OACTIVE
, "oactive" }, /* OpenBSD: transmission in progress */
3928 { IFF_SIMPLEX
, "simplex" }, /* OpenBSD: can't hear own transmissions */
3931 { IFF_LINK0
, "link0" }, /* OpenBSD: per link layer defined bit */
3934 { IFF_LINK1
, "link1" }, /* OpenBSD: per link layer defined bit */
3937 { IFF_LINK2
, "link2" }, /* OpenBSD: per link layer defined bit */
3942 DEFUN ("network-interface-info", Fnetwork_interface_info
, Snetwork_interface_info
, 1, 1, 0,
3943 doc
: /* Return information about network interface named IFNAME.
3944 The return value is a list (ADDR BCAST NETMASK HWADDR FLAGS),
3945 where ADDR is the layer 3 address, BCAST is the layer 3 broadcast address,
3946 NETMASK is the layer 3 network mask, HWADDR is the layer 2 addres, and
3947 FLAGS is the current flags of the interface. */)
3952 Lisp_Object res
= Qnil
;
3957 CHECK_STRING (ifname
);
3959 bzero (rq
.ifr_name
, sizeof rq
.ifr_name
);
3960 strncpy (rq
.ifr_name
, SDATA (ifname
), sizeof (rq
.ifr_name
));
3962 s
= socket (AF_INET
, SOCK_STREAM
, 0);
3967 #if defined(SIOCGIFFLAGS) && defined(HAVE_STRUCT_IFREQ_IFR_FLAGS)
3968 if (ioctl (s
, SIOCGIFFLAGS
, &rq
) == 0)
3970 int flags
= rq
.ifr_flags
;
3971 struct ifflag_def
*fp
;
3975 for (fp
= ifflag_table
; flags
!= 0 && fp
->flag_sym
; fp
++)
3977 if (flags
& fp
->flag_bit
)
3979 elt
= Fcons (intern (fp
->flag_sym
), elt
);
3980 flags
-= fp
->flag_bit
;
3983 for (fnum
= 0; flags
&& fnum
< 32; fnum
++)
3985 if (flags
& (1 << fnum
))
3987 elt
= Fcons (make_number (fnum
), elt
);
3992 res
= Fcons (elt
, res
);
3995 #if defined(SIOCGIFHWADDR) && defined(HAVE_STRUCT_IFREQ_IFR_HWADDR)
3996 if (ioctl (s
, SIOCGIFHWADDR
, &rq
) == 0)
3998 Lisp_Object hwaddr
= Fmake_vector (make_number (6), Qnil
);
3999 register struct Lisp_Vector
*p
= XVECTOR (hwaddr
);
4003 for (n
= 0; n
< 6; n
++)
4004 p
->contents
[n
] = make_number (((unsigned char *)&rq
.ifr_hwaddr
.sa_data
[0])[n
]);
4005 elt
= Fcons (make_number (rq
.ifr_hwaddr
.sa_family
), hwaddr
);
4008 res
= Fcons (elt
, res
);
4011 #if defined(SIOCGIFNETMASK) && (defined(HAVE_STRUCT_IFREQ_IFR_NETMASK) || defined(HAVE_STRUCT_IFREQ_IFR_ADDR))
4012 if (ioctl (s
, SIOCGIFNETMASK
, &rq
) == 0)
4015 #ifdef HAVE_STRUCT_IFREQ_IFR_NETMASK
4016 elt
= conv_sockaddr_to_lisp (&rq
.ifr_netmask
, sizeof (rq
.ifr_netmask
));
4018 elt
= conv_sockaddr_to_lisp (&rq
.ifr_addr
, sizeof (rq
.ifr_addr
));
4022 res
= Fcons (elt
, res
);
4025 #if defined(SIOCGIFBRDADDR) && defined(HAVE_STRUCT_IFREQ_IFR_BROADADDR)
4026 if (ioctl (s
, SIOCGIFBRDADDR
, &rq
) == 0)
4029 elt
= conv_sockaddr_to_lisp (&rq
.ifr_broadaddr
, sizeof (rq
.ifr_broadaddr
));
4032 res
= Fcons (elt
, res
);
4035 #if defined(SIOCGIFADDR) && defined(HAVE_STRUCT_IFREQ_IFR_ADDR)
4036 if (ioctl (s
, SIOCGIFADDR
, &rq
) == 0)
4039 elt
= conv_sockaddr_to_lisp (&rq
.ifr_addr
, sizeof (rq
.ifr_addr
));
4042 res
= Fcons (elt
, res
);
4046 return any
? res
: Qnil
;
4049 #endif /* HAVE_SOCKETS */
4051 /* Turn off input and output for process PROC. */
4054 deactivate_process (proc
)
4057 register int inchannel
, outchannel
;
4058 register struct Lisp_Process
*p
= XPROCESS (proc
);
4060 inchannel
= p
->infd
;
4061 outchannel
= p
->outfd
;
4063 #ifdef ADAPTIVE_READ_BUFFERING
4064 if (p
->read_output_delay
> 0)
4066 if (--process_output_delay_count
< 0)
4067 process_output_delay_count
= 0;
4068 p
->read_output_delay
= 0;
4069 p
->read_output_skip
= 0;
4075 /* Beware SIGCHLD hereabouts. */
4076 flush_pending_output (inchannel
);
4077 emacs_close (inchannel
);
4078 if (outchannel
>= 0 && outchannel
!= inchannel
)
4079 emacs_close (outchannel
);
4083 #ifdef DATAGRAM_SOCKETS
4084 if (DATAGRAM_CHAN_P (inchannel
))
4086 xfree (datagram_address
[inchannel
].sa
);
4087 datagram_address
[inchannel
].sa
= 0;
4088 datagram_address
[inchannel
].len
= 0;
4091 chan_process
[inchannel
] = Qnil
;
4092 FD_CLR (inchannel
, &input_wait_mask
);
4093 FD_CLR (inchannel
, &non_keyboard_wait_mask
);
4094 #ifdef NON_BLOCKING_CONNECT
4095 if (FD_ISSET (inchannel
, &connect_wait_mask
))
4097 FD_CLR (inchannel
, &connect_wait_mask
);
4098 if (--num_pending_connects
< 0)
4102 if (inchannel
== max_process_desc
)
4105 /* We just closed the highest-numbered process input descriptor,
4106 so recompute the highest-numbered one now. */
4107 max_process_desc
= 0;
4108 for (i
= 0; i
< MAXDESC
; i
++)
4109 if (!NILP (chan_process
[i
]))
4110 max_process_desc
= i
;
4115 /* Close all descriptors currently in use for communication
4116 with subprocess. This is used in a newly-forked subprocess
4117 to get rid of irrelevant descriptors. */
4120 close_process_descs ()
4124 for (i
= 0; i
< MAXDESC
; i
++)
4126 Lisp_Object process
;
4127 process
= chan_process
[i
];
4128 if (!NILP (process
))
4130 int in
= XPROCESS (process
)->infd
;
4131 int out
= XPROCESS (process
)->outfd
;
4134 if (out
>= 0 && in
!= out
)
4141 DEFUN ("accept-process-output", Faccept_process_output
, Saccept_process_output
,
4143 doc
: /* Allow any pending output from subprocesses to be read by Emacs.
4144 It is read into the process' buffers or given to their filter functions.
4145 Non-nil arg PROCESS means do not return until some output has been received
4148 Non-nil second arg SECONDS and third arg MILLISEC are number of seconds
4149 and milliseconds to wait; return after that much time whether or not
4150 there is any subprocess output. If SECONDS is a floating point number,
4151 it specifies a fractional number of seconds to wait.
4152 The MILLISEC argument is obsolete and should be avoided.
4154 If optional fourth arg JUST-THIS-ONE is non-nil, only accept output
4155 from PROCESS, suspending reading output from other processes.
4156 If JUST-THIS-ONE is an integer, don't run any timers either.
4157 Return non-nil if we received any output before the timeout expired. */)
4158 (process
, seconds
, millisec
, just_this_one
)
4159 register Lisp_Object process
, seconds
, millisec
, just_this_one
;
4161 int secs
, usecs
= 0;
4163 if (! NILP (process
))
4164 CHECK_PROCESS (process
);
4166 just_this_one
= Qnil
;
4168 if (!NILP (millisec
))
4169 { /* Obsolete calling convention using integers rather than floats. */
4170 CHECK_NUMBER (millisec
);
4172 seconds
= make_float (XINT (millisec
) / 1000.0);
4175 CHECK_NUMBER (seconds
);
4176 seconds
= make_float (XINT (millisec
) / 1000.0 + XINT (seconds
));
4180 if (!NILP (seconds
))
4182 if (INTEGERP (seconds
))
4183 secs
= XINT (seconds
);
4184 else if (FLOATP (seconds
))
4186 double timeout
= XFLOAT_DATA (seconds
);
4187 secs
= (int) timeout
;
4188 usecs
= (int) ((timeout
- (double) secs
) * 1000000);
4191 wrong_type_argument (Qnumberp
, seconds
);
4193 if (secs
< 0 || (secs
== 0 && usecs
== 0))
4194 secs
= -1, usecs
= 0;
4197 secs
= NILP (process
) ? -1 : 0;
4200 (wait_reading_process_output (secs
, usecs
, 0, 0,
4202 !NILP (process
) ? XPROCESS (process
) : NULL
,
4203 NILP (just_this_one
) ? 0 :
4204 !INTEGERP (just_this_one
) ? 1 : -1)
4208 /* Accept a connection for server process SERVER on CHANNEL. */
4210 static int connect_counter
= 0;
4213 server_accept_connection (server
, channel
)
4217 Lisp_Object proc
, caller
, name
, buffer
;
4218 Lisp_Object contact
, host
, service
;
4219 struct Lisp_Process
*ps
= XPROCESS (server
);
4220 struct Lisp_Process
*p
;
4224 struct sockaddr_in in
;
4226 struct sockaddr_in6 in6
;
4228 #ifdef HAVE_LOCAL_SOCKETS
4229 struct sockaddr_un un
;
4232 int len
= sizeof saddr
;
4234 s
= accept (channel
, &saddr
.sa
, &len
);
4243 if (code
== EWOULDBLOCK
)
4247 if (!NILP (ps
->log
))
4248 call3 (ps
->log
, server
, Qnil
,
4249 concat3 (build_string ("accept failed with code"),
4250 Fnumber_to_string (make_number (code
)),
4251 build_string ("\n")));
4257 /* Setup a new process to handle the connection. */
4259 /* Generate a unique identification of the caller, and build contact
4260 information for this process. */
4263 switch (saddr
.sa
.sa_family
)
4267 Lisp_Object args
[5];
4268 unsigned char *ip
= (unsigned char *)&saddr
.in
.sin_addr
.s_addr
;
4269 args
[0] = build_string ("%d.%d.%d.%d");
4270 args
[1] = make_number (*ip
++);
4271 args
[2] = make_number (*ip
++);
4272 args
[3] = make_number (*ip
++);
4273 args
[4] = make_number (*ip
++);
4274 host
= Fformat (5, args
);
4275 service
= make_number (ntohs (saddr
.in
.sin_port
));
4277 args
[0] = build_string (" <%s:%d>");
4280 caller
= Fformat (3, args
);
4287 Lisp_Object args
[9];
4288 uint16_t *ip6
= (uint16_t *)&saddr
.in6
.sin6_addr
;
4290 args
[0] = build_string ("%x:%x:%x:%x:%x:%x:%x:%x");
4291 for (i
= 0; i
< 8; i
++)
4292 args
[i
+1] = make_number (ntohs(ip6
[i
]));
4293 host
= Fformat (9, args
);
4294 service
= make_number (ntohs (saddr
.in
.sin_port
));
4296 args
[0] = build_string (" <[%s]:%d>");
4299 caller
= Fformat (3, args
);
4304 #ifdef HAVE_LOCAL_SOCKETS
4308 caller
= Fnumber_to_string (make_number (connect_counter
));
4309 caller
= concat3 (build_string (" <"), caller
, build_string (">"));
4313 /* Create a new buffer name for this process if it doesn't have a
4314 filter. The new buffer name is based on the buffer name or
4315 process name of the server process concatenated with the caller
4318 if (!NILP (ps
->filter
) && !EQ (ps
->filter
, Qt
))
4322 buffer
= ps
->buffer
;
4324 buffer
= Fbuffer_name (buffer
);
4329 buffer
= concat2 (buffer
, caller
);
4330 buffer
= Fget_buffer_create (buffer
);
4334 /* Generate a unique name for the new server process. Combine the
4335 server process name with the caller identification. */
4337 name
= concat2 (ps
->name
, caller
);
4338 proc
= make_process (name
);
4340 chan_process
[s
] = proc
;
4343 fcntl (s
, F_SETFL
, O_NONBLOCK
);
4346 fcntl (s
, F_SETFL
, O_NDELAY
);
4350 p
= XPROCESS (proc
);
4352 /* Build new contact information for this setup. */
4353 contact
= Fcopy_sequence (ps
->childp
);
4354 contact
= Fplist_put (contact
, QCserver
, Qnil
);
4355 contact
= Fplist_put (contact
, QChost
, host
);
4356 if (!NILP (service
))
4357 contact
= Fplist_put (contact
, QCservice
, service
);
4358 contact
= Fplist_put (contact
, QCremote
,
4359 conv_sockaddr_to_lisp (&saddr
.sa
, len
));
4360 #ifdef HAVE_GETSOCKNAME
4362 if (getsockname (s
, &saddr
.sa
, &len
) == 0)
4363 contact
= Fplist_put (contact
, QClocal
,
4364 conv_sockaddr_to_lisp (&saddr
.sa
, len
));
4367 p
->childp
= contact
;
4368 p
->plist
= Fcopy_sequence (ps
->plist
);
4372 p
->sentinel
= ps
->sentinel
;
4373 p
->filter
= ps
->filter
;
4380 /* Client processes for accepted connections are not stopped initially. */
4381 if (!EQ (p
->filter
, Qt
))
4383 FD_SET (s
, &input_wait_mask
);
4384 FD_SET (s
, &non_keyboard_wait_mask
);
4387 if (s
> max_process_desc
)
4388 max_process_desc
= s
;
4390 /* Setup coding system for new process based on server process.
4391 This seems to be the proper thing to do, as the coding system
4392 of the new process should reflect the settings at the time the
4393 server socket was opened; not the current settings. */
4395 p
->decode_coding_system
= ps
->decode_coding_system
;
4396 p
->encode_coding_system
= ps
->encode_coding_system
;
4397 setup_process_coding_systems (proc
);
4399 p
->decoding_buf
= make_uninit_string (0);
4400 p
->decoding_carryover
= 0;
4401 p
->encoding_buf
= make_uninit_string (0);
4403 p
->inherit_coding_system_flag
4404 = (NILP (buffer
) ? 0 : ps
->inherit_coding_system_flag
);
4406 if (!NILP (ps
->log
))
4407 call3 (ps
->log
, server
, proc
,
4408 concat3 (build_string ("accept from "),
4409 (STRINGP (host
) ? host
: build_string ("-")),
4410 build_string ("\n")));
4412 if (!NILP (p
->sentinel
))
4413 exec_sentinel (proc
,
4414 concat3 (build_string ("open from "),
4415 (STRINGP (host
) ? host
: build_string ("-")),
4416 build_string ("\n")));
4419 /* This variable is different from waiting_for_input in keyboard.c.
4420 It is used to communicate to a lisp process-filter/sentinel (via the
4421 function Fwaiting_for_user_input_p below) whether Emacs was waiting
4422 for user-input when that process-filter was called.
4423 waiting_for_input cannot be used as that is by definition 0 when
4424 lisp code is being evalled.
4425 This is also used in record_asynch_buffer_change.
4426 For that purpose, this must be 0
4427 when not inside wait_reading_process_output. */
4428 static int waiting_for_user_input_p
;
4431 wait_reading_process_output_unwind (data
)
4434 waiting_for_user_input_p
= XINT (data
);
4438 /* This is here so breakpoints can be put on it. */
4440 wait_reading_process_output_1 ()
4444 /* Use a wrapper around select to work around a bug in gdb 5.3.
4445 Normally, the wrapper is optimzed away by inlining.
4447 If emacs is stopped inside select, the gdb backtrace doesn't
4448 show the function which called select, so it is practically
4449 impossible to step through wait_reading_process_output. */
4453 select_wrapper (n
, rfd
, wfd
, xfd
, tmo
)
4455 SELECT_TYPE
*rfd
, *wfd
, *xfd
;
4458 return select (n
, rfd
, wfd
, xfd
, tmo
);
4460 #define select select_wrapper
4463 /* Read and dispose of subprocess output while waiting for timeout to
4464 elapse and/or keyboard input to be available.
4467 timeout in seconds, or
4468 zero for no limit, or
4469 -1 means gobble data immediately available but don't wait for any.
4472 an additional duration to wait, measured in microseconds.
4473 If this is nonzero and time_limit is 0, then the timeout
4474 consists of MICROSECS only.
4476 READ_KBD is a lisp value:
4477 0 to ignore keyboard input, or
4478 1 to return when input is available, or
4479 -1 meaning caller will actually read the input, so don't throw to
4480 the quit handler, or
4482 DO_DISPLAY != 0 means redisplay should be done to show subprocess
4483 output that arrives.
4485 If WAIT_FOR_CELL is a cons cell, wait until its car is non-nil
4486 (and gobble terminal input into the buffer if any arrives).
4488 If WAIT_PROC is specified, wait until something arrives from that
4489 process. The return value is true if we read some input from
4492 If JUST_WAIT_PROC is non-nil, handle only output from WAIT_PROC
4493 (suspending output from other processes). A negative value
4494 means don't run any timers either.
4496 If WAIT_PROC is specified, then the function returns true if we
4497 received input from that process before the timeout elapsed.
4498 Otherwise, return true if we received input from any process. */
4501 wait_reading_process_output (time_limit
, microsecs
, read_kbd
, do_display
,
4502 wait_for_cell
, wait_proc
, just_wait_proc
)
4503 int time_limit
, microsecs
, read_kbd
, do_display
;
4504 Lisp_Object wait_for_cell
;
4505 struct Lisp_Process
*wait_proc
;
4508 register int channel
, nfds
;
4509 SELECT_TYPE Available
;
4510 #ifdef NON_BLOCKING_CONNECT
4511 SELECT_TYPE Connecting
;
4514 int check_delay
, no_avail
;
4517 EMACS_TIME timeout
, end_time
;
4518 int wait_channel
= -1;
4519 int got_some_input
= 0;
4520 int count
= SPECPDL_INDEX ();
4522 FD_ZERO (&Available
);
4523 #ifdef NON_BLOCKING_CONNECT
4524 FD_ZERO (&Connecting
);
4527 /* If wait_proc is a process to watch, set wait_channel accordingly. */
4528 if (wait_proc
!= NULL
)
4529 wait_channel
= wait_proc
->infd
;
4531 record_unwind_protect (wait_reading_process_output_unwind
,
4532 make_number (waiting_for_user_input_p
));
4533 waiting_for_user_input_p
= read_kbd
;
4535 /* Since we may need to wait several times,
4536 compute the absolute time to return at. */
4537 if (time_limit
|| microsecs
)
4539 EMACS_GET_TIME (end_time
);
4540 EMACS_SET_SECS_USECS (timeout
, time_limit
, microsecs
);
4541 EMACS_ADD_TIME (end_time
, end_time
, timeout
);
4546 int timeout_reduced_for_timers
= 0;
4548 /* If calling from keyboard input, do not quit
4549 since we want to return C-g as an input character.
4550 Otherwise, do pending quit if requested. */
4555 process_pending_signals ();
4558 /* Exit now if the cell we're waiting for became non-nil. */
4559 if (! NILP (wait_for_cell
) && ! NILP (XCAR (wait_for_cell
)))
4562 /* Compute time from now till when time limit is up */
4563 /* Exit if already run out */
4564 if (time_limit
== -1)
4566 /* -1 specified for timeout means
4567 gobble output available now
4568 but don't wait at all. */
4570 EMACS_SET_SECS_USECS (timeout
, 0, 0);
4572 else if (time_limit
|| microsecs
)
4574 EMACS_GET_TIME (timeout
);
4575 EMACS_SUB_TIME (timeout
, end_time
, timeout
);
4576 if (EMACS_TIME_NEG_P (timeout
))
4581 EMACS_SET_SECS_USECS (timeout
, 100000, 0);
4584 /* Normally we run timers here.
4585 But not if wait_for_cell; in those cases,
4586 the wait is supposed to be short,
4587 and those callers cannot handle running arbitrary Lisp code here. */
4588 if (NILP (wait_for_cell
)
4589 && just_wait_proc
>= 0)
4591 EMACS_TIME timer_delay
;
4595 int old_timers_run
= timers_run
;
4596 struct buffer
*old_buffer
= current_buffer
;
4597 Lisp_Object old_window
= selected_window
;
4599 timer_delay
= timer_check (1);
4601 /* If a timer has run, this might have changed buffers
4602 an alike. Make read_key_sequence aware of that. */
4603 if (timers_run
!= old_timers_run
4604 && (old_buffer
!= current_buffer
4605 || !EQ (old_window
, selected_window
))
4606 && waiting_for_user_input_p
== -1)
4607 record_asynch_buffer_change ();
4609 if (timers_run
!= old_timers_run
&& do_display
)
4610 /* We must retry, since a timer may have requeued itself
4611 and that could alter the time_delay. */
4612 redisplay_preserve_echo_area (9);
4616 while (!detect_input_pending ());
4618 /* If there is unread keyboard input, also return. */
4620 && requeued_events_pending_p ())
4623 if (! EMACS_TIME_NEG_P (timer_delay
) && time_limit
!= -1)
4625 EMACS_TIME difference
;
4626 EMACS_SUB_TIME (difference
, timer_delay
, timeout
);
4627 if (EMACS_TIME_NEG_P (difference
))
4629 timeout
= timer_delay
;
4630 timeout_reduced_for_timers
= 1;
4633 /* If time_limit is -1, we are not going to wait at all. */
4634 else if (time_limit
!= -1)
4636 /* This is so a breakpoint can be put here. */
4637 wait_reading_process_output_1 ();
4641 /* Cause C-g and alarm signals to take immediate action,
4642 and cause input available signals to zero out timeout.
4644 It is important that we do this before checking for process
4645 activity. If we get a SIGCHLD after the explicit checks for
4646 process activity, timeout is the only way we will know. */
4648 set_waiting_for_input (&timeout
);
4650 /* If status of something has changed, and no input is
4651 available, notify the user of the change right away. After
4652 this explicit check, we'll let the SIGCHLD handler zap
4653 timeout to get our attention. When Emacs is run
4654 interactively, only do this with a nonzero DO_DISPLAY
4655 argument, because status_notify triggers redisplay. */
4656 if (update_tick
!= process_tick
4657 && (do_display
|| noninteractive
))
4660 #ifdef NON_BLOCKING_CONNECT
4664 Atemp
= input_wait_mask
;
4665 IF_NON_BLOCKING_CONNECT (Ctemp
= connect_wait_mask
);
4667 EMACS_SET_SECS_USECS (timeout
, 0, 0);
4668 if ((select (max (max (max_process_desc
, max_keyboard_desc
),
4671 #ifdef NON_BLOCKING_CONNECT
4672 (num_pending_connects
> 0 ? &Ctemp
: (SELECT_TYPE
*)0),
4676 (SELECT_TYPE
*)0, &timeout
)
4679 /* It's okay for us to do this and then continue with
4680 the loop, since timeout has already been zeroed out. */
4681 clear_waiting_for_input ();
4682 status_notify (NULL
);
4686 /* Don't wait for output from a non-running process. Just
4687 read whatever data has already been received. */
4688 if (wait_proc
&& wait_proc
->raw_status_new
)
4689 update_status (wait_proc
);
4691 && ! EQ (wait_proc
->status
, Qrun
)
4692 && ! EQ (wait_proc
->status
, Qconnect
))
4694 int nread
, total_nread
= 0;
4696 clear_waiting_for_input ();
4697 XSETPROCESS (proc
, wait_proc
);
4699 /* Read data from the process, until we exhaust it. */
4700 while (wait_proc
->infd
>= 0)
4702 nread
= read_process_output (proc
, wait_proc
->infd
);
4709 total_nread
+= nread
;
4713 else if (nread
== -1 && EIO
== errno
)
4717 else if (nread
== -1 && EAGAIN
== errno
)
4721 else if (nread
== -1 && EWOULDBLOCK
== errno
)
4725 if (total_nread
> 0 && do_display
)
4726 redisplay_preserve_echo_area (10);
4731 /* Wait till there is something to do */
4733 if (wait_proc
&& just_wait_proc
)
4735 if (wait_proc
->infd
< 0) /* Terminated */
4737 FD_SET (wait_proc
->infd
, &Available
);
4739 IF_NON_BLOCKING_CONNECT (check_connect
= 0);
4741 else if (!NILP (wait_for_cell
))
4743 Available
= non_process_wait_mask
;
4745 IF_NON_BLOCKING_CONNECT (check_connect
= 0);
4750 Available
= non_keyboard_wait_mask
;
4752 Available
= input_wait_mask
;
4753 IF_NON_BLOCKING_CONNECT (check_connect
= (num_pending_connects
> 0));
4754 check_delay
= wait_channel
>= 0 ? 0 : process_output_delay_count
;
4757 /* If frame size has changed or the window is newly mapped,
4758 redisplay now, before we start to wait. There is a race
4759 condition here; if a SIGIO arrives between now and the select
4760 and indicates that a frame is trashed, the select may block
4761 displaying a trashed screen. */
4762 if (frame_garbaged
&& do_display
)
4764 clear_waiting_for_input ();
4765 redisplay_preserve_echo_area (11);
4767 set_waiting_for_input (&timeout
);
4771 if (read_kbd
&& detect_input_pending ())
4778 #ifdef NON_BLOCKING_CONNECT
4780 Connecting
= connect_wait_mask
;
4783 #ifdef ADAPTIVE_READ_BUFFERING
4784 /* Set the timeout for adaptive read buffering if any
4785 process has non-zero read_output_skip and non-zero
4786 read_output_delay, and we are not reading output for a
4787 specific wait_channel. It is not executed if
4788 Vprocess_adaptive_read_buffering is nil. */
4789 if (process_output_skip
&& check_delay
> 0)
4791 int usecs
= EMACS_USECS (timeout
);
4792 if (EMACS_SECS (timeout
) > 0 || usecs
> READ_OUTPUT_DELAY_MAX
)
4793 usecs
= READ_OUTPUT_DELAY_MAX
;
4794 for (channel
= 0; check_delay
> 0 && channel
<= max_process_desc
; channel
++)
4796 proc
= chan_process
[channel
];
4799 /* Find minimum non-zero read_output_delay among the
4800 processes with non-zero read_output_skip. */
4801 if (XPROCESS (proc
)->read_output_delay
> 0)
4804 if (!XPROCESS (proc
)->read_output_skip
)
4806 FD_CLR (channel
, &Available
);
4807 XPROCESS (proc
)->read_output_skip
= 0;
4808 if (XPROCESS (proc
)->read_output_delay
< usecs
)
4809 usecs
= XPROCESS (proc
)->read_output_delay
;
4812 EMACS_SET_SECS_USECS (timeout
, 0, usecs
);
4813 process_output_skip
= 0;
4821 (max (max (max_process_desc
, max_keyboard_desc
),
4824 #ifdef NON_BLOCKING_CONNECT
4825 (check_connect
? &Connecting
: (SELECT_TYPE
*)0),
4829 (SELECT_TYPE
*)0, &timeout
);
4834 /* Make C-g and alarm signals set flags again */
4835 clear_waiting_for_input ();
4837 /* If we woke up due to SIGWINCH, actually change size now. */
4838 do_pending_window_change (0);
4840 if (time_limit
&& nfds
== 0 && ! timeout_reduced_for_timers
)
4841 /* We wanted the full specified time, so return now. */
4845 if (xerrno
== EINTR
)
4847 else if (xerrno
== EBADF
)
4850 /* AIX doesn't handle PTY closure the same way BSD does. On AIX,
4851 the child's closure of the pts gives the parent a SIGHUP, and
4852 the ptc file descriptor is automatically closed,
4853 yielding EBADF here or at select() call above.
4854 So, SIGHUP is ignored (see def of PTY_TTY_NAME_SPRINTF
4855 in m/ibmrt-aix.h), and here we just ignore the select error.
4856 Cleanup occurs c/o status_notify after SIGCLD. */
4857 no_avail
= 1; /* Cannot depend on values returned */
4863 error ("select error: %s", emacs_strerror (xerrno
));
4868 FD_ZERO (&Available
);
4869 IF_NON_BLOCKING_CONNECT (check_connect
= 0);
4872 #if 0 /* When polling is used, interrupt_input is 0,
4873 so get_input_pending should read the input.
4874 So this should not be needed. */
4875 /* If we are using polling for input,
4876 and we see input available, make it get read now.
4877 Otherwise it might not actually get read for a second.
4878 And on hpux, since we turn off polling in wait_reading_process_output,
4879 it might never get read at all if we don't spend much time
4880 outside of wait_reading_process_output. */
4881 if (read_kbd
&& interrupt_input
4882 && keyboard_bit_set (&Available
)
4883 && input_polling_used ())
4884 kill (getpid (), SIGALRM
);
4887 /* Check for keyboard input */
4888 /* If there is any, return immediately
4889 to give it higher priority than subprocesses */
4893 int old_timers_run
= timers_run
;
4894 struct buffer
*old_buffer
= current_buffer
;
4895 Lisp_Object old_window
= selected_window
;
4898 if (detect_input_pending_run_timers (do_display
))
4900 swallow_events (do_display
);
4901 if (detect_input_pending_run_timers (do_display
))
4905 /* If a timer has run, this might have changed buffers
4906 an alike. Make read_key_sequence aware of that. */
4907 if (timers_run
!= old_timers_run
4908 && waiting_for_user_input_p
== -1
4909 && (old_buffer
!= current_buffer
4910 || !EQ (old_window
, selected_window
)))
4911 record_asynch_buffer_change ();
4917 /* If there is unread keyboard input, also return. */
4919 && requeued_events_pending_p ())
4922 /* If we are not checking for keyboard input now,
4923 do process events (but don't run any timers).
4924 This is so that X events will be processed.
4925 Otherwise they may have to wait until polling takes place.
4926 That would causes delays in pasting selections, for example.
4928 (We used to do this only if wait_for_cell.) */
4929 if (read_kbd
== 0 && detect_input_pending ())
4931 swallow_events (do_display
);
4932 #if 0 /* Exiting when read_kbd doesn't request that seems wrong, though. */
4933 if (detect_input_pending ())
4938 /* Exit now if the cell we're waiting for became non-nil. */
4939 if (! NILP (wait_for_cell
) && ! NILP (XCAR (wait_for_cell
)))
4943 /* If we think we have keyboard input waiting, but didn't get SIGIO,
4944 go read it. This can happen with X on BSD after logging out.
4945 In that case, there really is no input and no SIGIO,
4946 but select says there is input. */
4948 if (read_kbd
&& interrupt_input
4949 && keyboard_bit_set (&Available
) && ! noninteractive
)
4950 kill (getpid (), SIGIO
);
4954 got_some_input
|= nfds
> 0;
4956 /* If checking input just got us a size-change event from X,
4957 obey it now if we should. */
4958 if (read_kbd
|| ! NILP (wait_for_cell
))
4959 do_pending_window_change (0);
4961 /* Check for data from a process. */
4962 if (no_avail
|| nfds
== 0)
4965 /* Really FIRST_PROC_DESC should be 0 on Unix,
4966 but this is safer in the short run. */
4967 for (channel
= 0; channel
<= max_process_desc
; channel
++)
4969 if (FD_ISSET (channel
, &Available
)
4970 && FD_ISSET (channel
, &non_keyboard_wait_mask
))
4974 /* If waiting for this channel, arrange to return as
4975 soon as no more input to be processed. No more
4977 if (wait_channel
== channel
)
4983 proc
= chan_process
[channel
];
4987 /* If this is a server stream socket, accept connection. */
4988 if (EQ (XPROCESS (proc
)->status
, Qlisten
))
4990 server_accept_connection (proc
, channel
);
4994 /* Read data from the process, starting with our
4995 buffered-ahead character if we have one. */
4997 nread
= read_process_output (proc
, channel
);
5000 /* Since read_process_output can run a filter,
5001 which can call accept-process-output,
5002 don't try to read from any other processes
5003 before doing the select again. */
5004 FD_ZERO (&Available
);
5007 redisplay_preserve_echo_area (12);
5010 else if (nread
== -1 && errno
== EWOULDBLOCK
)
5013 /* ISC 4.1 defines both EWOULDBLOCK and O_NONBLOCK,
5014 and Emacs uses O_NONBLOCK, so what we get is EAGAIN. */
5016 else if (nread
== -1 && errno
== EAGAIN
)
5020 else if (nread
== -1 && errno
== EAGAIN
)
5022 /* Note that we cannot distinguish between no input
5023 available now and a closed pipe.
5024 With luck, a closed pipe will be accompanied by
5025 subprocess termination and SIGCHLD. */
5026 else if (nread
== 0 && !NETCONN_P (proc
) && !SERIALCONN_P (proc
))
5028 #endif /* O_NDELAY */
5029 #endif /* O_NONBLOCK */
5031 /* On some OSs with ptys, when the process on one end of
5032 a pty exits, the other end gets an error reading with
5033 errno = EIO instead of getting an EOF (0 bytes read).
5034 Therefore, if we get an error reading and errno =
5035 EIO, just continue, because the child process has
5036 exited and should clean itself up soon (e.g. when we
5039 However, it has been known to happen that the SIGCHLD
5040 got lost. So raise the signal again just in case.
5042 else if (nread
== -1 && errno
== EIO
)
5044 /* Clear the descriptor now, so we only raise the signal once. */
5045 FD_CLR (channel
, &input_wait_mask
);
5046 FD_CLR (channel
, &non_keyboard_wait_mask
);
5048 kill (getpid (), SIGCHLD
);
5050 #endif /* HAVE_PTYS */
5051 /* If we can detect process termination, don't consider the process
5052 gone just because its pipe is closed. */
5054 else if (nread
== 0 && !NETCONN_P (proc
) && !SERIALCONN_P (proc
))
5059 /* Preserve status of processes already terminated. */
5060 XPROCESS (proc
)->tick
= ++process_tick
;
5061 deactivate_process (proc
);
5062 if (XPROCESS (proc
)->raw_status_new
)
5063 update_status (XPROCESS (proc
));
5064 if (EQ (XPROCESS (proc
)->status
, Qrun
))
5065 XPROCESS (proc
)->status
5066 = Fcons (Qexit
, Fcons (make_number (256), Qnil
));
5069 #ifdef NON_BLOCKING_CONNECT
5070 if (check_connect
&& FD_ISSET (channel
, &Connecting
)
5071 && FD_ISSET (channel
, &connect_wait_mask
))
5073 struct Lisp_Process
*p
;
5075 FD_CLR (channel
, &connect_wait_mask
);
5076 if (--num_pending_connects
< 0)
5079 proc
= chan_process
[channel
];
5083 p
= XPROCESS (proc
);
5086 /* getsockopt(,,SO_ERROR,,) is said to hang on some systems.
5087 So only use it on systems where it is known to work. */
5089 int xlen
= sizeof(xerrno
);
5090 if (getsockopt(channel
, SOL_SOCKET
, SO_ERROR
, &xerrno
, &xlen
))
5095 struct sockaddr pname
;
5096 int pnamelen
= sizeof(pname
);
5098 /* If connection failed, getpeername will fail. */
5100 if (getpeername(channel
, &pname
, &pnamelen
) < 0)
5102 /* Obtain connect failure code through error slippage. */
5105 if (errno
== ENOTCONN
&& read(channel
, &dummy
, 1) < 0)
5112 p
->tick
= ++process_tick
;
5113 p
->status
= Fcons (Qfailed
, Fcons (make_number (xerrno
), Qnil
));
5114 deactivate_process (proc
);
5119 /* Execute the sentinel here. If we had relied on
5120 status_notify to do it later, it will read input
5121 from the process before calling the sentinel. */
5122 exec_sentinel (proc
, build_string ("open\n"));
5123 if (!EQ (p
->filter
, Qt
) && !EQ (p
->command
, Qt
))
5125 FD_SET (p
->infd
, &input_wait_mask
);
5126 FD_SET (p
->infd
, &non_keyboard_wait_mask
);
5130 #endif /* NON_BLOCKING_CONNECT */
5131 } /* end for each file descriptor */
5132 } /* end while exit conditions not met */
5134 unbind_to (count
, Qnil
);
5136 /* If calling from keyboard input, do not quit
5137 since we want to return C-g as an input character.
5138 Otherwise, do pending quit if requested. */
5141 /* Prevent input_pending from remaining set if we quit. */
5142 clear_input_pending ();
5146 return got_some_input
;
5149 /* Given a list (FUNCTION ARGS...), apply FUNCTION to the ARGS. */
5152 read_process_output_call (fun_and_args
)
5153 Lisp_Object fun_and_args
;
5155 return apply1 (XCAR (fun_and_args
), XCDR (fun_and_args
));
5159 read_process_output_error_handler (error
)
5162 cmd_error_internal (error
, "error in process filter: ");
5164 update_echo_area ();
5165 Fsleep_for (make_number (2), Qnil
);
5169 /* Read pending output from the process channel,
5170 starting with our buffered-ahead character if we have one.
5171 Yield number of decoded characters read.
5173 This function reads at most 4096 characters.
5174 If you want to read all available subprocess output,
5175 you must call it repeatedly until it returns zero.
5177 The characters read are decoded according to PROC's coding-system
5181 read_process_output (proc
, channel
)
5183 register int channel
;
5185 register int nbytes
;
5187 register Lisp_Object outstream
;
5188 register struct buffer
*old
= current_buffer
;
5189 register struct Lisp_Process
*p
= XPROCESS (proc
);
5190 register int opoint
;
5191 struct coding_system
*coding
= proc_decode_coding_system
[channel
];
5192 int carryover
= p
->decoding_carryover
;
5195 chars
= (char *) alloca (carryover
+ readmax
);
5197 /* See the comment above. */
5198 bcopy (SDATA (p
->decoding_buf
), chars
, carryover
);
5200 #ifdef DATAGRAM_SOCKETS
5201 /* We have a working select, so proc_buffered_char is always -1. */
5202 if (DATAGRAM_CHAN_P (channel
))
5204 int len
= datagram_address
[channel
].len
;
5205 nbytes
= recvfrom (channel
, chars
+ carryover
, readmax
,
5206 0, datagram_address
[channel
].sa
, &len
);
5210 if (proc_buffered_char
[channel
] < 0)
5212 nbytes
= emacs_read (channel
, chars
+ carryover
, readmax
);
5213 #ifdef ADAPTIVE_READ_BUFFERING
5214 if (nbytes
> 0 && p
->adaptive_read_buffering
)
5216 int delay
= p
->read_output_delay
;
5219 if (delay
< READ_OUTPUT_DELAY_MAX_MAX
)
5222 process_output_delay_count
++;
5223 delay
+= READ_OUTPUT_DELAY_INCREMENT
* 2;
5226 else if (delay
> 0 && (nbytes
== readmax
))
5228 delay
-= READ_OUTPUT_DELAY_INCREMENT
;
5230 process_output_delay_count
--;
5232 p
->read_output_delay
= delay
;
5235 p
->read_output_skip
= 1;
5236 process_output_skip
= 1;
5243 chars
[carryover
] = proc_buffered_char
[channel
];
5244 proc_buffered_char
[channel
] = -1;
5245 nbytes
= emacs_read (channel
, chars
+ carryover
+ 1, readmax
- 1);
5249 nbytes
= nbytes
+ 1;
5252 p
->decoding_carryover
= 0;
5254 /* At this point, NBYTES holds number of bytes just received
5255 (including the one in proc_buffered_char[channel]). */
5258 if (nbytes
< 0 || coding
->mode
& CODING_MODE_LAST_BLOCK
)
5260 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
5263 /* Now set NBYTES how many bytes we must decode. */
5264 nbytes
+= carryover
;
5266 /* Read and dispose of the process output. */
5267 outstream
= p
->filter
;
5268 if (!NILP (outstream
))
5270 /* We inhibit quit here instead of just catching it so that
5271 hitting ^G when a filter happens to be running won't screw
5273 int count
= SPECPDL_INDEX ();
5274 Lisp_Object odeactivate
;
5275 Lisp_Object obuffer
, okeymap
;
5277 int outer_running_asynch_code
= running_asynch_code
;
5278 int waiting
= waiting_for_user_input_p
;
5280 /* No need to gcpro these, because all we do with them later
5281 is test them for EQness, and none of them should be a string. */
5282 odeactivate
= Vdeactivate_mark
;
5283 XSETBUFFER (obuffer
, current_buffer
);
5284 okeymap
= current_buffer
->keymap
;
5286 specbind (Qinhibit_quit
, Qt
);
5287 specbind (Qlast_nonmenu_event
, Qt
);
5289 /* In case we get recursively called,
5290 and we already saved the match data nonrecursively,
5291 save the same match data in safely recursive fashion. */
5292 if (outer_running_asynch_code
)
5295 /* Don't clobber the CURRENT match data, either! */
5296 tem
= Fmatch_data (Qnil
, Qnil
, Qnil
);
5297 restore_search_regs ();
5298 record_unwind_save_match_data ();
5299 Fset_match_data (tem
, Qt
);
5302 /* For speed, if a search happens within this code,
5303 save the match data in a special nonrecursive fashion. */
5304 running_asynch_code
= 1;
5306 decode_coding_c_string (coding
, chars
, nbytes
, Qt
);
5307 text
= coding
->dst_object
;
5308 Vlast_coding_system_used
= CODING_ID_NAME (coding
->id
);
5309 /* A new coding system might be found. */
5310 if (!EQ (p
->decode_coding_system
, Vlast_coding_system_used
))
5312 p
->decode_coding_system
= Vlast_coding_system_used
;
5314 /* Don't call setup_coding_system for
5315 proc_decode_coding_system[channel] here. It is done in
5316 detect_coding called via decode_coding above. */
5318 /* If a coding system for encoding is not yet decided, we set
5319 it as the same as coding-system for decoding.
5321 But, before doing that we must check if
5322 proc_encode_coding_system[p->outfd] surely points to a
5323 valid memory because p->outfd will be changed once EOF is
5324 sent to the process. */
5325 if (NILP (p
->encode_coding_system
)
5326 && proc_encode_coding_system
[p
->outfd
])
5328 p
->encode_coding_system
5329 = coding_inherit_eol_type (Vlast_coding_system_used
, Qnil
);
5330 setup_coding_system (p
->encode_coding_system
,
5331 proc_encode_coding_system
[p
->outfd
]);
5335 if (coding
->carryover_bytes
> 0)
5337 if (SCHARS (p
->decoding_buf
) < coding
->carryover_bytes
)
5338 p
->decoding_buf
= make_uninit_string (coding
->carryover_bytes
);
5339 bcopy (coding
->carryover
, SDATA (p
->decoding_buf
),
5340 coding
->carryover_bytes
);
5341 p
->decoding_carryover
= coding
->carryover_bytes
;
5343 if (SBYTES (text
) > 0)
5344 internal_condition_case_1 (read_process_output_call
,
5346 Fcons (proc
, Fcons (text
, Qnil
))),
5347 !NILP (Vdebug_on_error
) ? Qnil
: Qerror
,
5348 read_process_output_error_handler
);
5350 /* If we saved the match data nonrecursively, restore it now. */
5351 restore_search_regs ();
5352 running_asynch_code
= outer_running_asynch_code
;
5354 /* Handling the process output should not deactivate the mark. */
5355 Vdeactivate_mark
= odeactivate
;
5357 /* Restore waiting_for_user_input_p as it was
5358 when we were called, in case the filter clobbered it. */
5359 waiting_for_user_input_p
= waiting
;
5361 #if 0 /* Call record_asynch_buffer_change unconditionally,
5362 because we might have changed minor modes or other things
5363 that affect key bindings. */
5364 if (! EQ (Fcurrent_buffer (), obuffer
)
5365 || ! EQ (current_buffer
->keymap
, okeymap
))
5367 /* But do it only if the caller is actually going to read events.
5368 Otherwise there's no need to make him wake up, and it could
5369 cause trouble (for example it would make sit_for return). */
5370 if (waiting_for_user_input_p
== -1)
5371 record_asynch_buffer_change ();
5373 unbind_to (count
, Qnil
);
5377 /* If no filter, write into buffer if it isn't dead. */
5378 if (!NILP (p
->buffer
) && !NILP (XBUFFER (p
->buffer
)->name
))
5380 Lisp_Object old_read_only
;
5381 int old_begv
, old_zv
;
5382 int old_begv_byte
, old_zv_byte
;
5383 Lisp_Object odeactivate
;
5384 int before
, before_byte
;
5389 odeactivate
= Vdeactivate_mark
;
5391 Fset_buffer (p
->buffer
);
5393 opoint_byte
= PT_BYTE
;
5394 old_read_only
= current_buffer
->read_only
;
5397 old_begv_byte
= BEGV_BYTE
;
5398 old_zv_byte
= ZV_BYTE
;
5400 current_buffer
->read_only
= Qnil
;
5402 /* Insert new output into buffer
5403 at the current end-of-output marker,
5404 thus preserving logical ordering of input and output. */
5405 if (XMARKER (p
->mark
)->buffer
)
5406 SET_PT_BOTH (clip_to_bounds (BEGV
, marker_position (p
->mark
), ZV
),
5407 clip_to_bounds (BEGV_BYTE
, marker_byte_position (p
->mark
),
5410 SET_PT_BOTH (ZV
, ZV_BYTE
);
5412 before_byte
= PT_BYTE
;
5414 /* If the output marker is outside of the visible region, save
5415 the restriction and widen. */
5416 if (! (BEGV
<= PT
&& PT
<= ZV
))
5419 decode_coding_c_string (coding
, chars
, nbytes
, Qt
);
5420 text
= coding
->dst_object
;
5421 Vlast_coding_system_used
= CODING_ID_NAME (coding
->id
);
5422 /* A new coding system might be found. See the comment in the
5423 similar code in the previous `if' block. */
5424 if (!EQ (p
->decode_coding_system
, Vlast_coding_system_used
))
5426 p
->decode_coding_system
= Vlast_coding_system_used
;
5427 if (NILP (p
->encode_coding_system
)
5428 && proc_encode_coding_system
[p
->outfd
])
5430 p
->encode_coding_system
5431 = coding_inherit_eol_type (Vlast_coding_system_used
, Qnil
);
5432 setup_coding_system (p
->encode_coding_system
,
5433 proc_encode_coding_system
[p
->outfd
]);
5436 if (coding
->carryover_bytes
> 0)
5438 if (SCHARS (p
->decoding_buf
) < coding
->carryover_bytes
)
5439 p
->decoding_buf
= make_uninit_string (coding
->carryover_bytes
);
5440 bcopy (coding
->carryover
, SDATA (p
->decoding_buf
),
5441 coding
->carryover_bytes
);
5442 p
->decoding_carryover
= coding
->carryover_bytes
;
5444 /* Adjust the multibyteness of TEXT to that of the buffer. */
5445 if (NILP (current_buffer
->enable_multibyte_characters
)
5446 != ! STRING_MULTIBYTE (text
))
5447 text
= (STRING_MULTIBYTE (text
)
5448 ? Fstring_as_unibyte (text
)
5449 : Fstring_to_multibyte (text
));
5450 /* Insert before markers in case we are inserting where
5451 the buffer's mark is, and the user's next command is Meta-y. */
5452 insert_from_string_before_markers (text
, 0, 0,
5453 SCHARS (text
), SBYTES (text
), 0);
5455 /* Make sure the process marker's position is valid when the
5456 process buffer is changed in the signal_after_change above.
5457 W3 is known to do that. */
5458 if (BUFFERP (p
->buffer
)
5459 && (b
= XBUFFER (p
->buffer
), b
!= current_buffer
))
5460 set_marker_both (p
->mark
, p
->buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
5462 set_marker_both (p
->mark
, p
->buffer
, PT
, PT_BYTE
);
5464 update_mode_lines
++;
5466 /* Make sure opoint and the old restrictions
5467 float ahead of any new text just as point would. */
5468 if (opoint
>= before
)
5470 opoint
+= PT
- before
;
5471 opoint_byte
+= PT_BYTE
- before_byte
;
5473 if (old_begv
> before
)
5475 old_begv
+= PT
- before
;
5476 old_begv_byte
+= PT_BYTE
- before_byte
;
5478 if (old_zv
>= before
)
5480 old_zv
+= PT
- before
;
5481 old_zv_byte
+= PT_BYTE
- before_byte
;
5484 /* If the restriction isn't what it should be, set it. */
5485 if (old_begv
!= BEGV
|| old_zv
!= ZV
)
5486 Fnarrow_to_region (make_number (old_begv
), make_number (old_zv
));
5488 /* Handling the process output should not deactivate the mark. */
5489 Vdeactivate_mark
= odeactivate
;
5491 current_buffer
->read_only
= old_read_only
;
5492 SET_PT_BOTH (opoint
, opoint_byte
);
5493 set_buffer_internal (old
);
5498 DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p
, Swaiting_for_user_input_p
,
5500 doc
: /* Returns non-nil if Emacs is waiting for input from the user.
5501 This is intended for use by asynchronous process output filters and sentinels. */)
5504 return (waiting_for_user_input_p
? Qt
: Qnil
);
5507 /* Sending data to subprocess */
5509 jmp_buf send_process_frame
;
5510 Lisp_Object process_sent_to
;
5513 send_process_trap ()
5515 SIGNAL_THREAD_CHECK (SIGPIPE
);
5516 sigunblock (sigmask (SIGPIPE
));
5517 longjmp (send_process_frame
, 1);
5520 /* Send some data to process PROC.
5521 BUF is the beginning of the data; LEN is the number of characters.
5522 OBJECT is the Lisp object that the data comes from. If OBJECT is
5523 nil or t, it means that the data comes from C string.
5525 If OBJECT is not nil, the data is encoded by PROC's coding-system
5526 for encoding before it is sent.
5528 This function can evaluate Lisp code and can garbage collect. */
5531 send_process (proc
, buf
, len
, object
)
5532 volatile Lisp_Object proc
;
5533 unsigned char *volatile buf
;
5535 volatile Lisp_Object object
;
5537 /* Use volatile to protect variables from being clobbered by longjmp. */
5538 struct Lisp_Process
*p
= XPROCESS (proc
);
5540 struct coding_system
*coding
;
5541 struct gcpro gcpro1
;
5542 SIGTYPE (*volatile old_sigpipe
) ();
5546 if (p
->raw_status_new
)
5548 if (! EQ (p
->status
, Qrun
))
5549 error ("Process %s not running", SDATA (p
->name
));
5551 error ("Output file descriptor of %s is closed", SDATA (p
->name
));
5553 coding
= proc_encode_coding_system
[p
->outfd
];
5554 Vlast_coding_system_used
= CODING_ID_NAME (coding
->id
);
5556 if ((STRINGP (object
) && STRING_MULTIBYTE (object
))
5557 || (BUFFERP (object
)
5558 && !NILP (XBUFFER (object
)->enable_multibyte_characters
))
5561 if (!EQ (Vlast_coding_system_used
, p
->encode_coding_system
))
5562 /* The coding system for encoding was changed to raw-text
5563 because we sent a unibyte text previously. Now we are
5564 sending a multibyte text, thus we must encode it by the
5565 original coding system specified for the current process. */
5566 setup_coding_system (p
->encode_coding_system
, coding
);
5567 coding
->src_multibyte
= 1;
5571 /* For sending a unibyte text, character code conversion should
5572 not take place but EOL conversion should. So, setup raw-text
5573 or one of the subsidiary if we have not yet done it. */
5574 if (CODING_REQUIRE_ENCODING (coding
))
5576 if (CODING_REQUIRE_FLUSHING (coding
))
5578 /* But, before changing the coding, we must flush out data. */
5579 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
5580 send_process (proc
, "", 0, Qt
);
5581 coding
->mode
&= CODING_MODE_LAST_BLOCK
;
5583 setup_coding_system (raw_text_coding_system
5584 (Vlast_coding_system_used
),
5586 coding
->src_multibyte
= 0;
5589 coding
->dst_multibyte
= 0;
5591 if (CODING_REQUIRE_ENCODING (coding
))
5593 coding
->dst_object
= Qt
;
5594 if (BUFFERP (object
))
5596 int from_byte
, from
, to
;
5597 int save_pt
, save_pt_byte
;
5598 struct buffer
*cur
= current_buffer
;
5600 set_buffer_internal (XBUFFER (object
));
5601 save_pt
= PT
, save_pt_byte
= PT_BYTE
;
5603 from_byte
= PTR_BYTE_POS (buf
);
5604 from
= BYTE_TO_CHAR (from_byte
);
5605 to
= BYTE_TO_CHAR (from_byte
+ len
);
5606 TEMP_SET_PT_BOTH (from
, from_byte
);
5607 encode_coding_object (coding
, object
, from
, from_byte
,
5608 to
, from_byte
+ len
, Qt
);
5609 TEMP_SET_PT_BOTH (save_pt
, save_pt_byte
);
5610 set_buffer_internal (cur
);
5612 else if (STRINGP (object
))
5614 encode_coding_string (coding
, object
, 1);
5618 coding
->dst_object
= make_unibyte_string (buf
, len
);
5619 coding
->produced
= len
;
5622 len
= coding
->produced
;
5623 buf
= SDATA (coding
->dst_object
);
5626 if (pty_max_bytes
== 0)
5628 #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON)
5629 pty_max_bytes
= fpathconf (p
->outfd
, _PC_MAX_CANON
);
5630 if (pty_max_bytes
< 0)
5631 pty_max_bytes
= 250;
5633 pty_max_bytes
= 250;
5635 /* Deduct one, to leave space for the eof. */
5639 /* 2000-09-21: Emacs 20.7, sparc-sun-solaris-2.6, GCC 2.95.2,
5640 CFLAGS="-g -O": The value of the parameter `proc' is clobbered
5641 when returning with longjmp despite being declared volatile. */
5642 if (!setjmp (send_process_frame
))
5644 process_sent_to
= proc
;
5649 /* Decide how much data we can send in one batch.
5650 Long lines need to be split into multiple batches. */
5653 /* Starting this at zero is always correct when not the first
5654 iteration because the previous iteration ended by sending C-d.
5655 It may not be correct for the first iteration
5656 if a partial line was sent in a separate send_process call.
5657 If that proves worth handling, we need to save linepos
5658 in the process object. */
5660 unsigned char *ptr
= (unsigned char *) buf
;
5661 unsigned char *end
= (unsigned char *) buf
+ len
;
5663 /* Scan through this text for a line that is too long. */
5664 while (ptr
!= end
&& linepos
< pty_max_bytes
)
5672 /* If we found one, break the line there
5673 and put in a C-d to force the buffer through. */
5677 /* Send this batch, using one or more write calls. */
5680 int outfd
= p
->outfd
;
5681 old_sigpipe
= (SIGTYPE (*) ()) signal (SIGPIPE
, send_process_trap
);
5682 #ifdef DATAGRAM_SOCKETS
5683 if (DATAGRAM_CHAN_P (outfd
))
5685 rv
= sendto (outfd
, (char *) buf
, this,
5686 0, datagram_address
[outfd
].sa
,
5687 datagram_address
[outfd
].len
);
5688 if (rv
< 0 && errno
== EMSGSIZE
)
5690 signal (SIGPIPE
, old_sigpipe
);
5691 report_file_error ("sending datagram",
5692 Fcons (proc
, Qnil
));
5698 rv
= emacs_write (outfd
, (char *) buf
, this);
5699 #ifdef ADAPTIVE_READ_BUFFERING
5700 if (p
->read_output_delay
> 0
5701 && p
->adaptive_read_buffering
== 1)
5703 p
->read_output_delay
= 0;
5704 process_output_delay_count
--;
5705 p
->read_output_skip
= 0;
5709 signal (SIGPIPE
, old_sigpipe
);
5715 || errno
== EWOULDBLOCK
5721 /* Buffer is full. Wait, accepting input;
5722 that may allow the program
5723 to finish doing output and read more. */
5727 #ifdef BROKEN_PTY_READ_AFTER_EAGAIN
5728 /* A gross hack to work around a bug in FreeBSD.
5729 In the following sequence, read(2) returns
5733 write(2) 954 bytes, get EAGAIN
5734 read(2) 1024 bytes in process_read_output
5735 read(2) 11 bytes in process_read_output
5737 That is, read(2) returns more bytes than have
5738 ever been written successfully. The 1033 bytes
5739 read are the 1022 bytes written successfully
5740 after processing (for example with CRs added if
5741 the terminal is set up that way which it is
5742 here). The same bytes will be seen again in a
5743 later read(2), without the CRs. */
5745 if (errno
== EAGAIN
)
5748 ioctl (p
->outfd
, TIOCFLUSH
, &flags
);
5750 #endif /* BROKEN_PTY_READ_AFTER_EAGAIN */
5752 /* Running filters might relocate buffers or strings.
5753 Arrange to relocate BUF. */
5754 if (CODING_REQUIRE_ENCODING (coding
))
5755 offset
= buf
- SDATA (coding
->dst_object
);
5756 else if (BUFFERP (object
))
5757 offset
= BUF_PTR_BYTE_POS (XBUFFER (object
), buf
);
5758 else if (STRINGP (object
))
5759 offset
= buf
- SDATA (object
);
5761 #ifdef EMACS_HAS_USECS
5762 wait_reading_process_output (0, 20000, 0, 0, Qnil
, NULL
, 0);
5764 wait_reading_process_output (1, 0, 0, 0, Qnil
, NULL
, 0);
5767 if (CODING_REQUIRE_ENCODING (coding
))
5768 buf
= offset
+ SDATA (coding
->dst_object
);
5769 else if (BUFFERP (object
))
5770 buf
= BUF_BYTE_ADDRESS (XBUFFER (object
), offset
);
5771 else if (STRINGP (object
))
5772 buf
= offset
+ SDATA (object
);
5777 /* This is a real error. */
5778 report_file_error ("writing to process", Fcons (proc
, Qnil
));
5785 /* If we sent just part of the string, put in an EOF (C-d)
5786 to force it through, before we send the rest. */
5788 Fprocess_send_eof (proc
);
5793 signal (SIGPIPE
, old_sigpipe
);
5794 proc
= process_sent_to
;
5795 p
= XPROCESS (proc
);
5796 p
->raw_status_new
= 0;
5797 p
->status
= Fcons (Qexit
, Fcons (make_number (256), Qnil
));
5798 p
->tick
= ++process_tick
;
5799 deactivate_process (proc
);
5800 error ("SIGPIPE raised on process %s; closed it", SDATA (p
->name
));
5806 DEFUN ("process-send-region", Fprocess_send_region
, Sprocess_send_region
,
5808 doc
: /* Send current contents of region as input to PROCESS.
5809 PROCESS may be a process, a buffer, the name of a process or buffer, or
5810 nil, indicating the current buffer's process.
5811 Called from program, takes three arguments, PROCESS, START and END.
5812 If the region is more than 500 characters long,
5813 it is sent in several bunches. This may happen even for shorter regions.
5814 Output from processes can arrive in between bunches. */)
5815 (process
, start
, end
)
5816 Lisp_Object process
, start
, end
;
5821 proc
= get_process (process
);
5822 validate_region (&start
, &end
);
5824 if (XINT (start
) < GPT
&& XINT (end
) > GPT
)
5825 move_gap (XINT (start
));
5827 start1
= CHAR_TO_BYTE (XINT (start
));
5828 end1
= CHAR_TO_BYTE (XINT (end
));
5829 send_process (proc
, BYTE_POS_ADDR (start1
), end1
- start1
,
5830 Fcurrent_buffer ());
5835 DEFUN ("process-send-string", Fprocess_send_string
, Sprocess_send_string
,
5837 doc
: /* Send PROCESS the contents of STRING as input.
5838 PROCESS may be a process, a buffer, the name of a process or buffer, or
5839 nil, indicating the current buffer's process.
5840 If STRING is more than 500 characters long,
5841 it is sent in several bunches. This may happen even for shorter strings.
5842 Output from processes can arrive in between bunches. */)
5844 Lisp_Object process
, string
;
5847 CHECK_STRING (string
);
5848 proc
= get_process (process
);
5849 send_process (proc
, SDATA (string
),
5850 SBYTES (string
), string
);
5854 /* Return the foreground process group for the tty/pty that
5855 the process P uses. */
5857 emacs_get_tty_pgrp (p
)
5858 struct Lisp_Process
*p
;
5863 if (ioctl (p
->infd
, TIOCGPGRP
, &gid
) == -1 && ! NILP (p
->tty_name
))
5866 /* Some OS:es (Solaris 8/9) does not allow TIOCGPGRP from the
5867 master side. Try the slave side. */
5868 fd
= emacs_open (SDATA (p
->tty_name
), O_RDONLY
, 0);
5872 ioctl (fd
, TIOCGPGRP
, &gid
);
5876 #endif /* defined (TIOCGPGRP ) */
5881 DEFUN ("process-running-child-p", Fprocess_running_child_p
,
5882 Sprocess_running_child_p
, 0, 1, 0,
5883 doc
: /* Return t if PROCESS has given the terminal to a child.
5884 If the operating system does not make it possible to find out,
5885 return t unconditionally. */)
5887 Lisp_Object process
;
5889 /* Initialize in case ioctl doesn't exist or gives an error,
5890 in a way that will cause returning t. */
5893 struct Lisp_Process
*p
;
5895 proc
= get_process (process
);
5896 p
= XPROCESS (proc
);
5898 if (!EQ (p
->type
, Qreal
))
5899 error ("Process %s is not a subprocess",
5902 error ("Process %s is not active",
5905 gid
= emacs_get_tty_pgrp (p
);
5912 /* send a signal number SIGNO to PROCESS.
5913 If CURRENT_GROUP is t, that means send to the process group
5914 that currently owns the terminal being used to communicate with PROCESS.
5915 This is used for various commands in shell mode.
5916 If CURRENT_GROUP is lambda, that means send to the process group
5917 that currently owns the terminal, but only if it is NOT the shell itself.
5919 If NOMSG is zero, insert signal-announcements into process's buffers
5922 If we can, we try to signal PROCESS by sending control characters
5923 down the pty. This allows us to signal inferiors who have changed
5924 their uid, for which killpg would return an EPERM error. */
5927 process_send_signal (process
, signo
, current_group
, nomsg
)
5928 Lisp_Object process
;
5930 Lisp_Object current_group
;
5934 register struct Lisp_Process
*p
;
5938 proc
= get_process (process
);
5939 p
= XPROCESS (proc
);
5941 if (!EQ (p
->type
, Qreal
))
5942 error ("Process %s is not a subprocess",
5945 error ("Process %s is not active",
5949 current_group
= Qnil
;
5951 /* If we are using pgrps, get a pgrp number and make it negative. */
5952 if (NILP (current_group
))
5953 /* Send the signal to the shell's process group. */
5957 #ifdef SIGNALS_VIA_CHARACTERS
5958 /* If possible, send signals to the entire pgrp
5959 by sending an input character to it. */
5961 /* TERMIOS is the latest and bestest, and seems most likely to
5962 work. If the system has it, use it. */
5965 cc_t
*sig_char
= NULL
;
5967 tcgetattr (p
->infd
, &t
);
5972 sig_char
= &t
.c_cc
[VINTR
];
5976 sig_char
= &t
.c_cc
[VQUIT
];
5980 #if defined (VSWTCH) && !defined (PREFER_VSUSP)
5981 sig_char
= &t
.c_cc
[VSWTCH
];
5983 sig_char
= &t
.c_cc
[VSUSP
];
5988 if (sig_char
&& *sig_char
!= CDISABLE
)
5990 send_process (proc
, sig_char
, 1, Qnil
);
5993 /* If we can't send the signal with a character,
5994 fall through and send it another way. */
5995 #else /* ! HAVE_TERMIOS */
5997 /* On Berkeley descendants, the following IOCTL's retrieve the
5998 current control characters. */
5999 #if defined (TIOCGLTC) && defined (TIOCGETC)
6007 ioctl (p
->infd
, TIOCGETC
, &c
);
6008 send_process (proc
, &c
.t_intrc
, 1, Qnil
);
6011 ioctl (p
->infd
, TIOCGETC
, &c
);
6012 send_process (proc
, &c
.t_quitc
, 1, Qnil
);
6016 ioctl (p
->infd
, TIOCGLTC
, &lc
);
6017 send_process (proc
, &lc
.t_suspc
, 1, Qnil
);
6019 #endif /* ! defined (SIGTSTP) */
6022 #else /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
6024 /* On SYSV descendants, the TCGETA ioctl retrieves the current control
6031 ioctl (p
->infd
, TCGETA
, &t
);
6032 send_process (proc
, &t
.c_cc
[VINTR
], 1, Qnil
);
6035 ioctl (p
->infd
, TCGETA
, &t
);
6036 send_process (proc
, &t
.c_cc
[VQUIT
], 1, Qnil
);
6040 ioctl (p
->infd
, TCGETA
, &t
);
6041 send_process (proc
, &t
.c_cc
[VSWTCH
], 1, Qnil
);
6043 #endif /* ! defined (SIGTSTP) */
6045 #else /* ! defined (TCGETA) */
6046 Your configuration files are messed up
.
6047 /* If your system configuration files define SIGNALS_VIA_CHARACTERS,
6048 you'd better be using one of the alternatives above! */
6049 #endif /* ! defined (TCGETA) */
6050 #endif /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
6051 /* In this case, the code above should alway return. */
6053 #endif /* ! defined HAVE_TERMIOS */
6055 /* The code above may fall through if it can't
6056 handle the signal. */
6057 #endif /* defined (SIGNALS_VIA_CHARACTERS) */
6060 /* Get the current pgrp using the tty itself, if we have that.
6061 Otherwise, use the pty to get the pgrp.
6062 On pfa systems, saka@pfu.fujitsu.co.JP writes:
6063 "TIOCGPGRP symbol defined in sys/ioctl.h at E50.
6064 But, TIOCGPGRP does not work on E50 ;-P works fine on E60"
6065 His patch indicates that if TIOCGPGRP returns an error, then
6066 we should just assume that p->pid is also the process group id. */
6068 gid
= emacs_get_tty_pgrp (p
);
6071 /* If we can't get the information, assume
6072 the shell owns the tty. */
6075 /* It is not clear whether anything really can set GID to -1.
6076 Perhaps on some system one of those ioctls can or could do so.
6077 Or perhaps this is vestigial. */
6080 #else /* ! defined (TIOCGPGRP ) */
6081 /* Can't select pgrps on this system, so we know that
6082 the child itself heads the pgrp. */
6084 #endif /* ! defined (TIOCGPGRP ) */
6086 /* If current_group is lambda, and the shell owns the terminal,
6087 don't send any signal. */
6088 if (EQ (current_group
, Qlambda
) && gid
== p
->pid
)
6096 p
->raw_status_new
= 0;
6098 p
->tick
= ++process_tick
;
6100 status_notify (NULL
);
6102 #endif /* ! defined (SIGCONT) */
6106 flush_pending_output (p
->infd
);
6110 /* If we don't have process groups, send the signal to the immediate
6111 subprocess. That isn't really right, but it's better than any
6112 obvious alternative. */
6115 kill (p
->pid
, signo
);
6119 /* gid may be a pid, or minus a pgrp's number */
6121 if (!NILP (current_group
))
6123 if (ioctl (p
->infd
, TIOCSIGSEND
, signo
) == -1)
6124 EMACS_KILLPG (gid
, signo
);
6131 #else /* ! defined (TIOCSIGSEND) */
6132 EMACS_KILLPG (gid
, signo
);
6133 #endif /* ! defined (TIOCSIGSEND) */
6136 DEFUN ("interrupt-process", Finterrupt_process
, Sinterrupt_process
, 0, 2, 0,
6137 doc
: /* Interrupt process PROCESS.
6138 PROCESS may be a process, a buffer, or the name of a process or buffer.
6139 No arg or nil means current buffer's process.
6140 Second arg CURRENT-GROUP non-nil means send signal to
6141 the current process-group of the process's controlling terminal
6142 rather than to the process's own process group.
6143 If the process is a shell, this means interrupt current subjob
6144 rather than the shell.
6146 If CURRENT-GROUP is `lambda', and if the shell owns the terminal,
6147 don't send the signal. */)
6148 (process
, current_group
)
6149 Lisp_Object process
, current_group
;
6151 process_send_signal (process
, SIGINT
, current_group
, 0);
6155 DEFUN ("kill-process", Fkill_process
, Skill_process
, 0, 2, 0,
6156 doc
: /* Kill process PROCESS. May be process or name of one.
6157 See function `interrupt-process' for more details on usage. */)
6158 (process
, current_group
)
6159 Lisp_Object process
, current_group
;
6161 process_send_signal (process
, SIGKILL
, current_group
, 0);
6165 DEFUN ("quit-process", Fquit_process
, Squit_process
, 0, 2, 0,
6166 doc
: /* Send QUIT signal to process PROCESS. May be process or name of one.
6167 See function `interrupt-process' for more details on usage. */)
6168 (process
, current_group
)
6169 Lisp_Object process
, current_group
;
6171 process_send_signal (process
, SIGQUIT
, current_group
, 0);
6175 DEFUN ("stop-process", Fstop_process
, Sstop_process
, 0, 2, 0,
6176 doc
: /* Stop process PROCESS. May be process or name of one.
6177 See function `interrupt-process' for more details on usage.
6178 If PROCESS is a network or serial process, inhibit handling of incoming
6180 (process
, current_group
)
6181 Lisp_Object process
, current_group
;
6184 if (PROCESSP (process
) && (NETCONN_P (process
) || SERIALCONN_P (process
)))
6186 struct Lisp_Process
*p
;
6188 p
= XPROCESS (process
);
6189 if (NILP (p
->command
)
6192 FD_CLR (p
->infd
, &input_wait_mask
);
6193 FD_CLR (p
->infd
, &non_keyboard_wait_mask
);
6200 error ("No SIGTSTP support");
6202 process_send_signal (process
, SIGTSTP
, current_group
, 0);
6207 DEFUN ("continue-process", Fcontinue_process
, Scontinue_process
, 0, 2, 0,
6208 doc
: /* Continue process PROCESS. May be process or name of one.
6209 See function `interrupt-process' for more details on usage.
6210 If PROCESS is a network or serial process, resume handling of incoming
6212 (process
, current_group
)
6213 Lisp_Object process
, current_group
;
6216 if (PROCESSP (process
) && (NETCONN_P (process
) || SERIALCONN_P (process
)))
6218 struct Lisp_Process
*p
;
6220 p
= XPROCESS (process
);
6221 if (EQ (p
->command
, Qt
)
6223 && (!EQ (p
->filter
, Qt
) || EQ (p
->status
, Qlisten
)))
6225 FD_SET (p
->infd
, &input_wait_mask
);
6226 FD_SET (p
->infd
, &non_keyboard_wait_mask
);
6228 if (fd_info
[ p
->infd
].flags
& FILE_SERIAL
)
6229 PurgeComm (fd_info
[ p
->infd
].hnd
, PURGE_RXABORT
| PURGE_RXCLEAR
);
6232 tcflush (p
->infd
, TCIFLUSH
);
6240 process_send_signal (process
, SIGCONT
, current_group
, 0);
6242 error ("No SIGCONT support");
6247 DEFUN ("signal-process", Fsignal_process
, Ssignal_process
,
6248 2, 2, "sProcess (name or number): \nnSignal code: ",
6249 doc
: /* Send PROCESS the signal with code SIGCODE.
6250 PROCESS may also be a number specifying the process id of the
6251 process to signal; in this case, the process need not be a child of
6253 SIGCODE may be an integer, or a symbol whose name is a signal name. */)
6255 Lisp_Object process
, sigcode
;
6259 if (INTEGERP (process
))
6261 pid
= XINT (process
);
6265 if (FLOATP (process
))
6267 pid
= (pid_t
) XFLOAT_DATA (process
);
6271 if (STRINGP (process
))
6274 if (tem
= Fget_process (process
), NILP (tem
))
6276 pid
= XINT (Fstring_to_number (process
, make_number (10)));
6283 process
= get_process (process
);
6288 CHECK_PROCESS (process
);
6289 pid
= XPROCESS (process
)->pid
;
6291 error ("Cannot signal process %s", SDATA (XPROCESS (process
)->name
));
6295 #define parse_signal(NAME, VALUE) \
6296 else if (!xstrcasecmp (name, NAME)) \
6297 XSETINT (sigcode, VALUE)
6299 if (INTEGERP (sigcode
))
6303 unsigned char *name
;
6305 CHECK_SYMBOL (sigcode
);
6306 name
= SDATA (SYMBOL_NAME (sigcode
));
6308 if (!strncmp(name
, "SIG", 3) || !strncmp(name
, "sig", 3))
6314 parse_signal ("usr1", SIGUSR1
);
6317 parse_signal ("usr2", SIGUSR2
);
6320 parse_signal ("term", SIGTERM
);
6323 parse_signal ("hup", SIGHUP
);
6326 parse_signal ("int", SIGINT
);
6329 parse_signal ("quit", SIGQUIT
);
6332 parse_signal ("ill", SIGILL
);
6335 parse_signal ("abrt", SIGABRT
);
6338 parse_signal ("emt", SIGEMT
);
6341 parse_signal ("kill", SIGKILL
);
6344 parse_signal ("fpe", SIGFPE
);
6347 parse_signal ("bus", SIGBUS
);
6350 parse_signal ("segv", SIGSEGV
);
6353 parse_signal ("sys", SIGSYS
);
6356 parse_signal ("pipe", SIGPIPE
);
6359 parse_signal ("alrm", SIGALRM
);
6362 parse_signal ("urg", SIGURG
);
6365 parse_signal ("stop", SIGSTOP
);
6368 parse_signal ("tstp", SIGTSTP
);
6371 parse_signal ("cont", SIGCONT
);
6374 parse_signal ("chld", SIGCHLD
);
6377 parse_signal ("ttin", SIGTTIN
);
6380 parse_signal ("ttou", SIGTTOU
);
6383 parse_signal ("io", SIGIO
);
6386 parse_signal ("xcpu", SIGXCPU
);
6389 parse_signal ("xfsz", SIGXFSZ
);
6392 parse_signal ("vtalrm", SIGVTALRM
);
6395 parse_signal ("prof", SIGPROF
);
6398 parse_signal ("winch", SIGWINCH
);
6401 parse_signal ("info", SIGINFO
);
6404 error ("Undefined signal name %s", name
);
6409 return make_number (kill (pid
, XINT (sigcode
)));
6412 DEFUN ("process-send-eof", Fprocess_send_eof
, Sprocess_send_eof
, 0, 1, 0,
6413 doc
: /* Make PROCESS see end-of-file in its input.
6414 EOF comes after any text already sent to it.
6415 PROCESS may be a process, a buffer, the name of a process or buffer, or
6416 nil, indicating the current buffer's process.
6417 If PROCESS is a network connection, or is a process communicating
6418 through a pipe (as opposed to a pty), then you cannot send any more
6419 text to PROCESS after you call this function.
6420 If PROCESS is a serial process, wait until all output written to the
6421 process has been transmitted to the serial port. */)
6423 Lisp_Object process
;
6426 struct coding_system
*coding
;
6428 if (DATAGRAM_CONN_P (process
))
6431 proc
= get_process (process
);
6432 coding
= proc_encode_coding_system
[XPROCESS (proc
)->outfd
];
6434 /* Make sure the process is really alive. */
6435 if (XPROCESS (proc
)->raw_status_new
)
6436 update_status (XPROCESS (proc
));
6437 if (! EQ (XPROCESS (proc
)->status
, Qrun
))
6438 error ("Process %s not running", SDATA (XPROCESS (proc
)->name
));
6440 if (CODING_REQUIRE_FLUSHING (coding
))
6442 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
6443 send_process (proc
, "", 0, Qnil
);
6446 if (XPROCESS (proc
)->pty_flag
)
6447 send_process (proc
, "\004", 1, Qnil
);
6448 else if (EQ (XPROCESS (proc
)->type
, Qserial
))
6451 if (tcdrain (XPROCESS (proc
)->outfd
) != 0)
6452 error ("tcdrain() failed: %s", emacs_strerror (errno
));
6454 /* Do nothing on Windows because writes are blocking. */
6458 int old_outfd
, new_outfd
;
6460 #ifdef HAVE_SHUTDOWN
6461 /* If this is a network connection, or socketpair is used
6462 for communication with the subprocess, call shutdown to cause EOF.
6463 (In some old system, shutdown to socketpair doesn't work.
6464 Then we just can't win.) */
6465 if (EQ (XPROCESS (proc
)->type
, Qnetwork
)
6466 || XPROCESS (proc
)->outfd
== XPROCESS (proc
)->infd
)
6467 shutdown (XPROCESS (proc
)->outfd
, 1);
6468 /* In case of socketpair, outfd == infd, so don't close it. */
6469 if (XPROCESS (proc
)->outfd
!= XPROCESS (proc
)->infd
)
6470 emacs_close (XPROCESS (proc
)->outfd
);
6471 #else /* not HAVE_SHUTDOWN */
6472 emacs_close (XPROCESS (proc
)->outfd
);
6473 #endif /* not HAVE_SHUTDOWN */
6474 new_outfd
= emacs_open (NULL_DEVICE
, O_WRONLY
, 0);
6477 old_outfd
= XPROCESS (proc
)->outfd
;
6479 if (!proc_encode_coding_system
[new_outfd
])
6480 proc_encode_coding_system
[new_outfd
]
6481 = (struct coding_system
*) xmalloc (sizeof (struct coding_system
));
6482 bcopy (proc_encode_coding_system
[old_outfd
],
6483 proc_encode_coding_system
[new_outfd
],
6484 sizeof (struct coding_system
));
6485 bzero (proc_encode_coding_system
[old_outfd
],
6486 sizeof (struct coding_system
));
6488 XPROCESS (proc
)->outfd
= new_outfd
;
6493 /* Kill all processes associated with `buffer'.
6494 If `buffer' is nil, kill all processes */
6497 kill_buffer_processes (buffer
)
6500 Lisp_Object tail
, proc
;
6502 for (tail
= Vprocess_alist
; CONSP (tail
); tail
= XCDR (tail
))
6504 proc
= XCDR (XCAR (tail
));
6506 && (NILP (buffer
) || EQ (XPROCESS (proc
)->buffer
, buffer
)))
6508 if (NETCONN_P (proc
) || SERIALCONN_P (proc
))
6509 Fdelete_process (proc
);
6510 else if (XPROCESS (proc
)->infd
>= 0)
6511 process_send_signal (proc
, SIGHUP
, Qnil
, 1);
6516 /* On receipt of a signal that a child status has changed, loop asking
6517 about children with changed statuses until the system says there
6520 All we do is change the status; we do not run sentinels or print
6521 notifications. That is saved for the next time keyboard input is
6522 done, in order to avoid timing errors.
6524 ** WARNING: this can be called during garbage collection.
6525 Therefore, it must not be fooled by the presence of mark bits in
6528 ** USG WARNING: Although it is not obvious from the documentation
6529 in signal(2), on a USG system the SIGCLD handler MUST NOT call
6530 signal() before executing at least one wait(), otherwise the
6531 handler will be called again, resulting in an infinite loop. The
6532 relevant portion of the documentation reads "SIGCLD signals will be
6533 queued and the signal-catching function will be continually
6534 reentered until the queue is empty". Invoking signal() causes the
6535 kernel to reexamine the SIGCLD queue. Fred Fish, UniSoft Systems
6538 ** Malloc WARNING: This should never call malloc either directly or
6539 indirectly; if it does, that is a bug */
6543 sigchld_handler (signo
)
6546 int old_errno
= errno
;
6548 register struct Lisp_Process
*p
;
6549 extern EMACS_TIME
*input_available_clear_time
;
6551 SIGNAL_THREAD_CHECK (signo
);
6562 #endif /* no WUNTRACED */
6563 /* Keep trying to get a status until we get a definitive result. */
6567 pid
= wait3 (&w
, WNOHANG
| WUNTRACED
, 0);
6569 while (pid
< 0 && errno
== EINTR
);
6573 /* PID == 0 means no processes found, PID == -1 means a real
6574 failure. We have done all our job, so return. */
6576 /* USG systems forget handlers when they are used;
6577 must reestablish each time */
6578 #if defined (USG) && !defined (POSIX_SIGNALS)
6579 signal (signo
, sigchld_handler
); /* WARNING - must come after wait3() */
6586 #endif /* no WNOHANG */
6588 /* Find the process that signaled us, and record its status. */
6590 /* The process can have been deleted by Fdelete_process. */
6591 for (tail
= deleted_pid_list
; CONSP (tail
); tail
= XCDR (tail
))
6593 Lisp_Object xpid
= XCAR (tail
);
6594 if ((INTEGERP (xpid
) && pid
== (pid_t
) XINT (xpid
))
6595 || (FLOATP (xpid
) && pid
== (pid_t
) XFLOAT_DATA (xpid
)))
6597 XSETCAR (tail
, Qnil
);
6598 goto sigchld_end_of_loop
;
6602 /* Otherwise, if it is asynchronous, it is in Vprocess_alist. */
6604 for (tail
= Vprocess_alist
; CONSP (tail
); tail
= XCDR (tail
))
6606 proc
= XCDR (XCAR (tail
));
6607 p
= XPROCESS (proc
);
6608 if (EQ (p
->type
, Qreal
) && p
->pid
== pid
)
6613 /* Look for an asynchronous process whose pid hasn't been filled
6616 for (tail
= Vprocess_alist
; CONSP (tail
); tail
= XCDR (tail
))
6618 proc
= XCDR (XCAR (tail
));
6619 p
= XPROCESS (proc
);
6625 /* Change the status of the process that was found. */
6628 int clear_desc_flag
= 0;
6630 p
->tick
= ++process_tick
;
6632 p
->raw_status_new
= 1;
6634 /* If process has terminated, stop waiting for its output. */
6635 if ((WIFSIGNALED (w
) || WIFEXITED (w
))
6637 clear_desc_flag
= 1;
6639 /* We use clear_desc_flag to avoid a compiler bug in Microsoft C. */
6640 if (clear_desc_flag
)
6642 FD_CLR (p
->infd
, &input_wait_mask
);
6643 FD_CLR (p
->infd
, &non_keyboard_wait_mask
);
6646 /* Tell wait_reading_process_output that it needs to wake up and
6648 if (input_available_clear_time
)
6649 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
6652 /* There was no asynchronous process found for that pid: we have
6653 a synchronous process. */
6656 synch_process_alive
= 0;
6658 /* Report the status of the synchronous process. */
6660 synch_process_retcode
= WRETCODE (w
);
6661 else if (WIFSIGNALED (w
))
6662 synch_process_termsig
= WTERMSIG (w
);
6664 /* Tell wait_reading_process_output that it needs to wake up and
6666 if (input_available_clear_time
)
6667 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
6670 sigchld_end_of_loop
:
6673 /* On some systems, we must return right away.
6674 If any more processes want to signal us, we will
6676 Otherwise (on systems that have WNOHANG), loop around
6677 to use up all the processes that have something to tell us. */
6678 #if (defined WINDOWSNT \
6679 || (defined USG && !defined GNU_LINUX \
6680 && !(defined HPUX && defined WNOHANG)))
6681 #if defined (USG) && ! defined (POSIX_SIGNALS)
6682 signal (signo
, sigchld_handler
);
6686 #endif /* USG, but not HPUX with WNOHANG */
6689 #endif /* SIGCHLD */
6693 exec_sentinel_unwind (data
)
6696 XPROCESS (XCAR (data
))->sentinel
= XCDR (data
);
6701 exec_sentinel_error_handler (error
)
6704 cmd_error_internal (error
, "error in process sentinel: ");
6706 update_echo_area ();
6707 Fsleep_for (make_number (2), Qnil
);
6712 exec_sentinel (proc
, reason
)
6713 Lisp_Object proc
, reason
;
6715 Lisp_Object sentinel
, obuffer
, odeactivate
, okeymap
;
6716 register struct Lisp_Process
*p
= XPROCESS (proc
);
6717 int count
= SPECPDL_INDEX ();
6718 int outer_running_asynch_code
= running_asynch_code
;
6719 int waiting
= waiting_for_user_input_p
;
6721 if (inhibit_sentinels
)
6724 /* No need to gcpro these, because all we do with them later
6725 is test them for EQness, and none of them should be a string. */
6726 odeactivate
= Vdeactivate_mark
;
6727 XSETBUFFER (obuffer
, current_buffer
);
6728 okeymap
= current_buffer
->keymap
;
6730 sentinel
= p
->sentinel
;
6731 if (NILP (sentinel
))
6734 /* Zilch the sentinel while it's running, to avoid recursive invocations;
6735 assure that it gets restored no matter how the sentinel exits. */
6737 record_unwind_protect (exec_sentinel_unwind
, Fcons (proc
, sentinel
));
6738 /* Inhibit quit so that random quits don't screw up a running filter. */
6739 specbind (Qinhibit_quit
, Qt
);
6740 specbind (Qlast_nonmenu_event
, Qt
);
6742 /* In case we get recursively called,
6743 and we already saved the match data nonrecursively,
6744 save the same match data in safely recursive fashion. */
6745 if (outer_running_asynch_code
)
6748 tem
= Fmatch_data (Qnil
, Qnil
, Qnil
);
6749 restore_search_regs ();
6750 record_unwind_save_match_data ();
6751 Fset_match_data (tem
, Qt
);
6754 /* For speed, if a search happens within this code,
6755 save the match data in a special nonrecursive fashion. */
6756 running_asynch_code
= 1;
6758 internal_condition_case_1 (read_process_output_call
,
6760 Fcons (proc
, Fcons (reason
, Qnil
))),
6761 !NILP (Vdebug_on_error
) ? Qnil
: Qerror
,
6762 exec_sentinel_error_handler
);
6764 /* If we saved the match data nonrecursively, restore it now. */
6765 restore_search_regs ();
6766 running_asynch_code
= outer_running_asynch_code
;
6768 Vdeactivate_mark
= odeactivate
;
6770 /* Restore waiting_for_user_input_p as it was
6771 when we were called, in case the filter clobbered it. */
6772 waiting_for_user_input_p
= waiting
;
6775 if (! EQ (Fcurrent_buffer (), obuffer
)
6776 || ! EQ (current_buffer
->keymap
, okeymap
))
6778 /* But do it only if the caller is actually going to read events.
6779 Otherwise there's no need to make him wake up, and it could
6780 cause trouble (for example it would make sit_for return). */
6781 if (waiting_for_user_input_p
== -1)
6782 record_asynch_buffer_change ();
6784 unbind_to (count
, Qnil
);
6787 /* Report all recent events of a change in process status
6788 (either run the sentinel or output a message).
6789 This is usually done while Emacs is waiting for keyboard input
6790 but can be done at other times. */
6793 status_notify (deleting_process
)
6794 struct Lisp_Process
*deleting_process
;
6796 register Lisp_Object proc
, buffer
;
6797 Lisp_Object tail
, msg
;
6798 struct gcpro gcpro1
, gcpro2
;
6802 /* We need to gcpro tail; if read_process_output calls a filter
6803 which deletes a process and removes the cons to which tail points
6804 from Vprocess_alist, and then causes a GC, tail is an unprotected
6808 /* Set this now, so that if new processes are created by sentinels
6809 that we run, we get called again to handle their status changes. */
6810 update_tick
= process_tick
;
6812 for (tail
= Vprocess_alist
; CONSP (tail
); tail
= XCDR (tail
))
6815 register struct Lisp_Process
*p
;
6817 proc
= Fcdr (XCAR (tail
));
6818 p
= XPROCESS (proc
);
6820 if (p
->tick
!= p
->update_tick
)
6822 p
->update_tick
= p
->tick
;
6824 /* If process is still active, read any output that remains. */
6825 while (! EQ (p
->filter
, Qt
)
6826 && ! EQ (p
->status
, Qconnect
)
6827 && ! EQ (p
->status
, Qlisten
)
6828 /* Network or serial process not stopped: */
6829 && ! EQ (p
->command
, Qt
)
6831 && p
!= deleting_process
6832 && read_process_output (proc
, p
->infd
) > 0);
6836 /* Get the text to use for the message. */
6837 if (p
->raw_status_new
)
6839 msg
= status_message (p
);
6841 /* If process is terminated, deactivate it or delete it. */
6843 if (CONSP (p
->status
))
6844 symbol
= XCAR (p
->status
);
6846 if (EQ (symbol
, Qsignal
) || EQ (symbol
, Qexit
)
6847 || EQ (symbol
, Qclosed
))
6849 if (delete_exited_processes
)
6850 remove_process (proc
);
6852 deactivate_process (proc
);
6855 /* The actions above may have further incremented p->tick.
6856 So set p->update_tick again
6857 so that an error in the sentinel will not cause
6858 this code to be run again. */
6859 p
->update_tick
= p
->tick
;
6860 /* Now output the message suitably. */
6861 if (!NILP (p
->sentinel
))
6862 exec_sentinel (proc
, msg
);
6863 /* Don't bother with a message in the buffer
6864 when a process becomes runnable. */
6865 else if (!EQ (symbol
, Qrun
) && !NILP (buffer
))
6867 Lisp_Object ro
, tem
;
6868 struct buffer
*old
= current_buffer
;
6869 int opoint
, opoint_byte
;
6870 int before
, before_byte
;
6872 ro
= XBUFFER (buffer
)->read_only
;
6874 /* Avoid error if buffer is deleted
6875 (probably that's why the process is dead, too) */
6876 if (NILP (XBUFFER (buffer
)->name
))
6878 Fset_buffer (buffer
);
6881 opoint_byte
= PT_BYTE
;
6882 /* Insert new output into buffer
6883 at the current end-of-output marker,
6884 thus preserving logical ordering of input and output. */
6885 if (XMARKER (p
->mark
)->buffer
)
6886 Fgoto_char (p
->mark
);
6888 SET_PT_BOTH (ZV
, ZV_BYTE
);
6891 before_byte
= PT_BYTE
;
6893 tem
= current_buffer
->read_only
;
6894 current_buffer
->read_only
= Qnil
;
6895 insert_string ("\nProcess ");
6896 Finsert (1, &p
->name
);
6897 insert_string (" ");
6899 current_buffer
->read_only
= tem
;
6900 set_marker_both (p
->mark
, p
->buffer
, PT
, PT_BYTE
);
6902 if (opoint
>= before
)
6903 SET_PT_BOTH (opoint
+ (PT
- before
),
6904 opoint_byte
+ (PT_BYTE
- before_byte
));
6906 SET_PT_BOTH (opoint
, opoint_byte
);
6908 set_buffer_internal (old
);
6913 update_mode_lines
++; /* in case buffers use %s in mode-line-format */
6914 redisplay_preserve_echo_area (13);
6920 DEFUN ("set-process-coding-system", Fset_process_coding_system
,
6921 Sset_process_coding_system
, 1, 3, 0,
6922 doc
: /* Set coding systems of PROCESS to DECODING and ENCODING.
6923 DECODING will be used to decode subprocess output and ENCODING to
6924 encode subprocess input. */)
6925 (process
, decoding
, encoding
)
6926 register Lisp_Object process
, decoding
, encoding
;
6928 register struct Lisp_Process
*p
;
6930 CHECK_PROCESS (process
);
6931 p
= XPROCESS (process
);
6933 error ("Input file descriptor of %s closed", SDATA (p
->name
));
6935 error ("Output file descriptor of %s closed", SDATA (p
->name
));
6936 Fcheck_coding_system (decoding
);
6937 Fcheck_coding_system (encoding
);
6938 encoding
= coding_inherit_eol_type (encoding
, Qnil
);
6939 p
->decode_coding_system
= decoding
;
6940 p
->encode_coding_system
= encoding
;
6941 setup_process_coding_systems (process
);
6946 DEFUN ("process-coding-system",
6947 Fprocess_coding_system
, Sprocess_coding_system
, 1, 1, 0,
6948 doc
: /* Return a cons of coding systems for decoding and encoding of PROCESS. */)
6950 register Lisp_Object process
;
6952 CHECK_PROCESS (process
);
6953 return Fcons (XPROCESS (process
)->decode_coding_system
,
6954 XPROCESS (process
)->encode_coding_system
);
6957 DEFUN ("set-process-filter-multibyte", Fset_process_filter_multibyte
,
6958 Sset_process_filter_multibyte
, 2, 2, 0,
6959 doc
: /* Set multibyteness of the strings given to PROCESS's filter.
6960 If FLAG is non-nil, the filter is given multibyte strings.
6961 If FLAG is nil, the filter is given unibyte strings. In this case,
6962 all character code conversion except for end-of-line conversion is
6965 Lisp_Object process
, flag
;
6967 register struct Lisp_Process
*p
;
6969 CHECK_PROCESS (process
);
6970 p
= XPROCESS (process
);
6972 p
->decode_coding_system
= raw_text_coding_system (p
->decode_coding_system
);
6973 setup_process_coding_systems (process
);
6978 DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p
,
6979 Sprocess_filter_multibyte_p
, 1, 1, 0,
6980 doc
: /* Return t if a multibyte string is given to PROCESS's filter.*/)
6982 Lisp_Object process
;
6984 register struct Lisp_Process
*p
;
6985 struct coding_system
*coding
;
6987 CHECK_PROCESS (process
);
6988 p
= XPROCESS (process
);
6989 coding
= proc_decode_coding_system
[p
->infd
];
6990 return (CODING_FOR_UNIBYTE (coding
) ? Qnil
: Qt
);
6995 /* Add DESC to the set of keyboard input descriptors. */
6998 add_keyboard_wait_descriptor (desc
)
7001 FD_SET (desc
, &input_wait_mask
);
7002 FD_SET (desc
, &non_process_wait_mask
);
7003 if (desc
> max_keyboard_desc
)
7004 max_keyboard_desc
= desc
;
7007 static int add_gpm_wait_descriptor_called_flag
;
7010 add_gpm_wait_descriptor (desc
)
7013 if (! add_gpm_wait_descriptor_called_flag
)
7014 FD_CLR (0, &input_wait_mask
);
7015 add_gpm_wait_descriptor_called_flag
= 1;
7016 FD_SET (desc
, &input_wait_mask
);
7017 FD_SET (desc
, &gpm_wait_mask
);
7018 if (desc
> max_gpm_desc
)
7019 max_gpm_desc
= desc
;
7022 /* From now on, do not expect DESC to give keyboard input. */
7025 delete_keyboard_wait_descriptor (desc
)
7029 int lim
= max_keyboard_desc
;
7031 FD_CLR (desc
, &input_wait_mask
);
7032 FD_CLR (desc
, &non_process_wait_mask
);
7034 if (desc
== max_keyboard_desc
)
7035 for (fd
= 0; fd
< lim
; fd
++)
7036 if (FD_ISSET (fd
, &input_wait_mask
)
7037 && !FD_ISSET (fd
, &non_keyboard_wait_mask
)
7038 && !FD_ISSET (fd
, &gpm_wait_mask
))
7039 max_keyboard_desc
= fd
;
7043 delete_gpm_wait_descriptor (desc
)
7047 int lim
= max_gpm_desc
;
7049 FD_CLR (desc
, &input_wait_mask
);
7050 FD_CLR (desc
, &non_process_wait_mask
);
7052 if (desc
== max_gpm_desc
)
7053 for (fd
= 0; fd
< lim
; fd
++)
7054 if (FD_ISSET (fd
, &input_wait_mask
)
7055 && !FD_ISSET (fd
, &non_keyboard_wait_mask
)
7056 && !FD_ISSET (fd
, &non_process_wait_mask
))
7060 /* Return nonzero if *MASK has a bit set
7061 that corresponds to one of the keyboard input descriptors. */
7064 keyboard_bit_set (mask
)
7069 for (fd
= 0; fd
<= max_keyboard_desc
; fd
++)
7070 if (FD_ISSET (fd
, mask
) && FD_ISSET (fd
, &input_wait_mask
)
7071 && !FD_ISSET (fd
, &non_keyboard_wait_mask
))
7077 /* Enumeration of and access to system processes a-la ps(1). */
7079 DEFUN ("list-system-processes", Flist_system_processes
, Slist_system_processes
,
7081 doc
: /* Return a list of numerical process IDs of all running processes.
7082 If this functionality is unsupported, return nil.
7084 See `process-attributes' for getting attributes of a process given its ID. */)
7087 return list_system_processes ();
7090 DEFUN ("process-attributes", Fprocess_attributes
,
7091 Sprocess_attributes
, 1, 1, 0,
7092 doc
: /* Return attributes of the process given by its PID, a number.
7094 Value is an alist where each element is a cons cell of the form
7098 If this functionality is unsupported, the value is nil.
7100 See `list-system-processes' for getting a list of all process IDs.
7102 The KEYs of the attributes that this function may return are listed
7103 below, together with the type of the associated VALUE (in parentheses).
7104 Not all platforms support all of these attributes; unsupported
7105 attributes will not appear in the returned alist.
7106 Unless explicitly indicated otherwise, numbers can have either
7107 integer or floating point values.
7109 euid -- Effective user User ID of the process (number)
7110 user -- User name corresponding to euid (string)
7111 egid -- Effective user Group ID of the process (number)
7112 group -- Group name corresponding to egid (string)
7113 comm -- Command name (executable name only) (string)
7114 state -- Process state code, such as "S", "R", or "T" (string)
7115 ppid -- Parent process ID (number)
7116 pgrp -- Process group ID (number)
7117 sess -- Session ID, i.e. process ID of session leader (number)
7118 ttname -- Controlling tty name (string)
7119 tpgid -- ID of foreground process group on the process's tty (number)
7120 minflt -- number of minor page faults (number)
7121 majflt -- number of major page faults (number)
7122 cminflt -- cumulative number of minor page faults (number)
7123 cmajflt -- cumulative number of major page faults (number)
7124 utime -- user time used by the process, in the (HIGH LOW USEC) format
7125 stime -- system time used by the process, in the (HIGH LOW USEC) format
7126 time -- sum of utime and stime, in the (HIGH LOW USEC) format
7127 cutime -- user time used by the process and its children, (HIGH LOW USEC)
7128 cstime -- system time used by the process and its children, (HIGH LOW USEC)
7129 ctime -- sum of cutime and cstime, in the (HIGH LOW USEC) format
7130 pri -- priority of the process (number)
7131 nice -- nice value of the process (number)
7132 thcount -- process thread count (number)
7133 start -- time the process started, in the (HIGH LOW USEC) format
7134 vsize -- virtual memory size of the process in KB's (number)
7135 rss -- resident set size of the process in KB's (number)
7136 etime -- elapsed time the process is running, in (HIGH LOW USEC) format
7137 pcpu -- percents of CPU time used by the process (floating-point number)
7138 pmem -- percents of total physical memory used by process's resident set
7139 (floating-point number)
7140 args -- command line which invoked the process (string). */)
7145 return system_process_attributes (pid
);
7153 inhibit_sentinels
= 0;
7157 if (! noninteractive
|| initialized
)
7159 signal (SIGCHLD
, sigchld_handler
);
7162 FD_ZERO (&input_wait_mask
);
7163 FD_ZERO (&non_keyboard_wait_mask
);
7164 FD_ZERO (&non_process_wait_mask
);
7165 max_process_desc
= 0;
7167 #ifdef NON_BLOCKING_CONNECT
7168 FD_ZERO (&connect_wait_mask
);
7169 num_pending_connects
= 0;
7172 #ifdef ADAPTIVE_READ_BUFFERING
7173 process_output_delay_count
= 0;
7174 process_output_skip
= 0;
7177 /* Don't do this, it caused infinite select loops. The display
7178 method should call add_keyboard_wait_descriptor on stdin if it
7181 FD_SET (0, &input_wait_mask
);
7184 Vprocess_alist
= Qnil
;
7186 deleted_pid_list
= Qnil
;
7188 for (i
= 0; i
< MAXDESC
; i
++)
7190 chan_process
[i
] = Qnil
;
7191 proc_buffered_char
[i
] = -1;
7193 bzero (proc_decode_coding_system
, sizeof proc_decode_coding_system
);
7194 bzero (proc_encode_coding_system
, sizeof proc_encode_coding_system
);
7195 #ifdef DATAGRAM_SOCKETS
7196 bzero (datagram_address
, sizeof datagram_address
);
7201 Lisp_Object subfeatures
= Qnil
;
7202 struct socket_options
*sopt
;
7204 #define ADD_SUBFEATURE(key, val) \
7205 subfeatures = Fcons (Fcons (key, Fcons (val, Qnil)), subfeatures)
7207 #ifdef NON_BLOCKING_CONNECT
7208 ADD_SUBFEATURE (QCnowait
, Qt
);
7210 #ifdef DATAGRAM_SOCKETS
7211 ADD_SUBFEATURE (QCtype
, Qdatagram
);
7213 #ifdef HAVE_LOCAL_SOCKETS
7214 ADD_SUBFEATURE (QCfamily
, Qlocal
);
7216 ADD_SUBFEATURE (QCfamily
, Qipv4
);
7218 ADD_SUBFEATURE (QCfamily
, Qipv6
);
7220 #ifdef HAVE_GETSOCKNAME
7221 ADD_SUBFEATURE (QCservice
, Qt
);
7223 #if defined(O_NONBLOCK) || defined(O_NDELAY)
7224 ADD_SUBFEATURE (QCserver
, Qt
);
7227 for (sopt
= socket_options
; sopt
->name
; sopt
++)
7228 subfeatures
= Fcons (intern (sopt
->name
), subfeatures
);
7230 Fprovide (intern ("make-network-process"), subfeatures
);
7232 #endif /* HAVE_SOCKETS */
7234 #if defined (DARWIN_OS)
7235 /* PTYs are broken on Darwin < 6, but are sometimes useful for interactive
7236 processes. As such, we only change the default value. */
7239 char *release
= get_operating_system_release();
7240 if (!release
|| !release
[0] || (release
[0] < MIN_PTY_KERNEL_VERSION
7241 && release
[1] == '.')) {
7242 Vprocess_connection_type
= Qnil
;
7251 Qprocessp
= intern ("processp");
7252 staticpro (&Qprocessp
);
7253 Qrun
= intern ("run");
7255 Qstop
= intern ("stop");
7257 Qsignal
= intern ("signal");
7258 staticpro (&Qsignal
);
7260 /* Qexit is already staticpro'd by syms_of_eval; don't staticpro it
7263 Qexit = intern ("exit");
7264 staticpro (&Qexit); */
7266 Qopen
= intern ("open");
7268 Qclosed
= intern ("closed");
7269 staticpro (&Qclosed
);
7270 Qconnect
= intern ("connect");
7271 staticpro (&Qconnect
);
7272 Qfailed
= intern ("failed");
7273 staticpro (&Qfailed
);
7274 Qlisten
= intern ("listen");
7275 staticpro (&Qlisten
);
7276 Qlocal
= intern ("local");
7277 staticpro (&Qlocal
);
7278 Qipv4
= intern ("ipv4");
7281 Qipv6
= intern ("ipv6");
7284 Qdatagram
= intern ("datagram");
7285 staticpro (&Qdatagram
);
7287 QCport
= intern (":port");
7288 staticpro (&QCport
);
7289 QCspeed
= intern (":speed");
7290 staticpro (&QCspeed
);
7291 QCprocess
= intern (":process");
7292 staticpro (&QCprocess
);
7294 QCbytesize
= intern (":bytesize");
7295 staticpro (&QCbytesize
);
7296 QCstopbits
= intern (":stopbits");
7297 staticpro (&QCstopbits
);
7298 QCparity
= intern (":parity");
7299 staticpro (&QCparity
);
7300 Qodd
= intern ("odd");
7302 Qeven
= intern ("even");
7304 QCflowcontrol
= intern (":flowcontrol");
7305 staticpro (&QCflowcontrol
);
7306 Qhw
= intern ("hw");
7308 Qsw
= intern ("sw");
7310 QCsummary
= intern (":summary");
7311 staticpro (&QCsummary
);
7313 Qreal
= intern ("real");
7315 Qnetwork
= intern ("network");
7316 staticpro (&Qnetwork
);
7317 Qserial
= intern ("serial");
7318 staticpro (&Qserial
);
7320 QCname
= intern (":name");
7321 staticpro (&QCname
);
7322 QCbuffer
= intern (":buffer");
7323 staticpro (&QCbuffer
);
7324 QChost
= intern (":host");
7325 staticpro (&QChost
);
7326 QCservice
= intern (":service");
7327 staticpro (&QCservice
);
7328 QCtype
= intern (":type");
7329 staticpro (&QCtype
);
7330 QClocal
= intern (":local");
7331 staticpro (&QClocal
);
7332 QCremote
= intern (":remote");
7333 staticpro (&QCremote
);
7334 QCcoding
= intern (":coding");
7335 staticpro (&QCcoding
);
7336 QCserver
= intern (":server");
7337 staticpro (&QCserver
);
7338 QCnowait
= intern (":nowait");
7339 staticpro (&QCnowait
);
7340 QCsentinel
= intern (":sentinel");
7341 staticpro (&QCsentinel
);
7342 QClog
= intern (":log");
7344 QCnoquery
= intern (":noquery");
7345 staticpro (&QCnoquery
);
7346 QCstop
= intern (":stop");
7347 staticpro (&QCstop
);
7348 QCoptions
= intern (":options");
7349 staticpro (&QCoptions
);
7350 QCplist
= intern (":plist");
7351 staticpro (&QCplist
);
7353 Qlast_nonmenu_event
= intern ("last-nonmenu-event");
7354 staticpro (&Qlast_nonmenu_event
);
7356 staticpro (&Vprocess_alist
);
7358 staticpro (&deleted_pid_list
);
7361 Qeuid
= intern ("euid");
7363 Qegid
= intern ("egid");
7365 Quser
= intern ("user");
7367 Qgroup
= intern ("group");
7368 staticpro (&Qgroup
);
7369 Qcomm
= intern ("comm");
7371 Qstate
= intern ("state");
7372 staticpro (&Qstate
);
7373 Qppid
= intern ("ppid");
7375 Qpgrp
= intern ("pgrp");
7377 Qsess
= intern ("sess");
7379 Qttname
= intern ("ttname");
7380 staticpro (&Qttname
);
7381 Qtpgid
= intern ("tpgid");
7382 staticpro (&Qtpgid
);
7383 Qminflt
= intern ("minflt");
7384 staticpro (&Qminflt
);
7385 Qmajflt
= intern ("majflt");
7386 staticpro (&Qmajflt
);
7387 Qcminflt
= intern ("cminflt");
7388 staticpro (&Qcminflt
);
7389 Qcmajflt
= intern ("cmajflt");
7390 staticpro (&Qcmajflt
);
7391 Qutime
= intern ("utime");
7392 staticpro (&Qutime
);
7393 Qstime
= intern ("stime");
7394 staticpro (&Qstime
);
7395 Qtime
= intern ("time");
7397 Qcutime
= intern ("cutime");
7398 staticpro (&Qcutime
);
7399 Qcstime
= intern ("cstime");
7400 staticpro (&Qcstime
);
7401 Qctime
= intern ("ctime");
7402 staticpro (&Qctime
);
7403 Qpri
= intern ("pri");
7405 Qnice
= intern ("nice");
7407 Qthcount
= intern ("thcount");
7408 staticpro (&Qthcount
);
7409 Qstart
= intern ("start");
7410 staticpro (&Qstart
);
7411 Qvsize
= intern ("vsize");
7412 staticpro (&Qvsize
);
7413 Qrss
= intern ("rss");
7415 Qetime
= intern ("etime");
7416 staticpro (&Qetime
);
7417 Qpcpu
= intern ("pcpu");
7419 Qpmem
= intern ("pmem");
7421 Qargs
= intern ("args");
7424 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes
,
7425 doc
: /* *Non-nil means delete processes immediately when they exit.
7426 A value of nil means don't delete them until `list-processes' is run. */);
7428 delete_exited_processes
= 1;
7430 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type
,
7431 doc
: /* Control type of device used to communicate with subprocesses.
7432 Values are nil to use a pipe, or t or `pty' to use a pty.
7433 The value has no effect if the system has no ptys or if all ptys are busy:
7434 then a pipe is used in any case.
7435 The value takes effect when `start-process' is called. */);
7436 Vprocess_connection_type
= Qt
;
7438 #ifdef ADAPTIVE_READ_BUFFERING
7439 DEFVAR_LISP ("process-adaptive-read-buffering", &Vprocess_adaptive_read_buffering
,
7440 doc
: /* If non-nil, improve receive buffering by delaying after short reads.
7441 On some systems, when Emacs reads the output from a subprocess, the output data
7442 is read in very small blocks, potentially resulting in very poor performance.
7443 This behavior can be remedied to some extent by setting this variable to a
7444 non-nil value, as it will automatically delay reading from such processes, to
7445 allow them to produce more output before Emacs tries to read it.
7446 If the value is t, the delay is reset after each write to the process; any other
7447 non-nil value means that the delay is not reset on write.
7448 The variable takes effect when `start-process' is called. */);
7449 Vprocess_adaptive_read_buffering
= Qt
;
7452 defsubr (&Sprocessp
);
7453 defsubr (&Sget_process
);
7454 defsubr (&Sget_buffer_process
);
7455 defsubr (&Sdelete_process
);
7456 defsubr (&Sprocess_status
);
7457 defsubr (&Sprocess_exit_status
);
7458 defsubr (&Sprocess_id
);
7459 defsubr (&Sprocess_name
);
7460 defsubr (&Sprocess_tty_name
);
7461 defsubr (&Sprocess_command
);
7462 defsubr (&Sset_process_buffer
);
7463 defsubr (&Sprocess_buffer
);
7464 defsubr (&Sprocess_mark
);
7465 defsubr (&Sset_process_filter
);
7466 defsubr (&Sprocess_filter
);
7467 defsubr (&Sset_process_sentinel
);
7468 defsubr (&Sprocess_sentinel
);
7469 defsubr (&Sset_process_window_size
);
7470 defsubr (&Sset_process_inherit_coding_system_flag
);
7471 defsubr (&Sprocess_inherit_coding_system_flag
);
7472 defsubr (&Sset_process_query_on_exit_flag
);
7473 defsubr (&Sprocess_query_on_exit_flag
);
7474 defsubr (&Sprocess_contact
);
7475 defsubr (&Sprocess_plist
);
7476 defsubr (&Sset_process_plist
);
7477 defsubr (&Slist_processes
);
7478 defsubr (&Sprocess_list
);
7479 defsubr (&Sstart_process
);
7481 defsubr (&Sserial_process_configure
);
7482 defsubr (&Smake_serial_process
);
7483 #endif /* HAVE_SERIAL */
7485 defsubr (&Sset_network_process_option
);
7486 defsubr (&Smake_network_process
);
7487 defsubr (&Sformat_network_address
);
7488 #endif /* HAVE_SOCKETS */
7489 #if defined(HAVE_SOCKETS) && defined(HAVE_NET_IF_H) && defined(HAVE_SYS_IOCTL_H)
7491 defsubr (&Snetwork_interface_list
);
7493 #if defined(SIOCGIFADDR) || defined(SIOCGIFHWADDR) || defined(SIOCGIFFLAGS)
7494 defsubr (&Snetwork_interface_info
);
7496 #endif /* HAVE_SOCKETS ... */
7497 #ifdef DATAGRAM_SOCKETS
7498 defsubr (&Sprocess_datagram_address
);
7499 defsubr (&Sset_process_datagram_address
);
7501 defsubr (&Saccept_process_output
);
7502 defsubr (&Sprocess_send_region
);
7503 defsubr (&Sprocess_send_string
);
7504 defsubr (&Sinterrupt_process
);
7505 defsubr (&Skill_process
);
7506 defsubr (&Squit_process
);
7507 defsubr (&Sstop_process
);
7508 defsubr (&Scontinue_process
);
7509 defsubr (&Sprocess_running_child_p
);
7510 defsubr (&Sprocess_send_eof
);
7511 defsubr (&Ssignal_process
);
7512 defsubr (&Swaiting_for_user_input_p
);
7513 defsubr (&Sprocess_type
);
7514 defsubr (&Sset_process_coding_system
);
7515 defsubr (&Sprocess_coding_system
);
7516 defsubr (&Sset_process_filter_multibyte
);
7517 defsubr (&Sprocess_filter_multibyte_p
);
7518 defsubr (&Slist_system_processes
);
7519 defsubr (&Sprocess_attributes
);
7523 #else /* not subprocesses */
7525 #include <sys/types.h>
7527 #include <sys/stat.h>
7530 #ifdef HAVE_UNISTD_H
7535 #include "systime.h"
7536 #include "character.h"
7538 #include "termopts.h"
7539 #include "sysselect.h"
7541 extern int frame_garbaged
;
7543 extern EMACS_TIME
timer_check ();
7544 extern int timers_run
;
7546 Lisp_Object QCtype
, QCname
;
7548 Lisp_Object Qeuid
, Qegid
, Qcomm
, Qstate
, Qppid
, Qpgrp
, Qsess
, Qttname
, Qtpgid
;
7549 Lisp_Object Qminflt
, Qmajflt
, Qcminflt
, Qcmajflt
, Qutime
, Qstime
, Qcstime
;
7550 Lisp_Object Qcutime
, Qpri
, Qnice
, Qthcount
, Qstart
, Qvsize
, Qrss
, Qargs
;
7551 Lisp_Object Quser
, Qgroup
, Qetime
, Qpcpu
, Qpmem
, Qtime
, Qctime
;
7553 /* As described above, except assuming that there are no subprocesses:
7555 Wait for timeout to elapse and/or keyboard input to be available.
7558 timeout in seconds, or
7559 zero for no limit, or
7560 -1 means gobble data immediately available but don't wait for any.
7562 read_kbd is a Lisp_Object:
7563 0 to ignore keyboard input, or
7564 1 to return when input is available, or
7565 -1 means caller will actually read the input, so don't throw to
7568 see full version for other parameters. We know that wait_proc will
7569 always be NULL, since `subprocesses' isn't defined.
7571 do_display != 0 means redisplay should be done to show subprocess
7572 output that arrives.
7574 Return true if we received input from any process. */
7577 wait_reading_process_output (time_limit
, microsecs
, read_kbd
, do_display
,
7578 wait_for_cell
, wait_proc
, just_wait_proc
)
7579 int time_limit
, microsecs
, read_kbd
, do_display
;
7580 Lisp_Object wait_for_cell
;
7581 struct Lisp_Process
*wait_proc
;
7585 EMACS_TIME end_time
, timeout
;
7586 SELECT_TYPE waitchannels
;
7589 /* What does time_limit really mean? */
7590 if (time_limit
|| microsecs
)
7592 EMACS_GET_TIME (end_time
);
7593 EMACS_SET_SECS_USECS (timeout
, time_limit
, microsecs
);
7594 EMACS_ADD_TIME (end_time
, end_time
, timeout
);
7597 /* Turn off periodic alarms (in case they are in use)
7598 and then turn off any other atimers,
7599 because the select emulator uses alarms. */
7601 turn_on_atimers (0);
7605 int timeout_reduced_for_timers
= 0;
7607 /* If calling from keyboard input, do not quit
7608 since we want to return C-g as an input character.
7609 Otherwise, do pending quit if requested. */
7613 /* Exit now if the cell we're waiting for became non-nil. */
7614 if (! NILP (wait_for_cell
) && ! NILP (XCAR (wait_for_cell
)))
7617 /* Compute time from now till when time limit is up */
7618 /* Exit if already run out */
7619 if (time_limit
== -1)
7621 /* -1 specified for timeout means
7622 gobble output available now
7623 but don't wait at all. */
7625 EMACS_SET_SECS_USECS (timeout
, 0, 0);
7627 else if (time_limit
|| microsecs
)
7629 EMACS_GET_TIME (timeout
);
7630 EMACS_SUB_TIME (timeout
, end_time
, timeout
);
7631 if (EMACS_TIME_NEG_P (timeout
))
7636 EMACS_SET_SECS_USECS (timeout
, 100000, 0);
7639 /* If our caller will not immediately handle keyboard events,
7640 run timer events directly.
7641 (Callers that will immediately read keyboard events
7642 call timer_delay on their own.) */
7643 if (NILP (wait_for_cell
))
7645 EMACS_TIME timer_delay
;
7649 int old_timers_run
= timers_run
;
7650 timer_delay
= timer_check (1);
7651 if (timers_run
!= old_timers_run
&& do_display
)
7652 /* We must retry, since a timer may have requeued itself
7653 and that could alter the time delay. */
7654 redisplay_preserve_echo_area (14);
7658 while (!detect_input_pending ());
7660 /* If there is unread keyboard input, also return. */
7662 && requeued_events_pending_p ())
7665 if (! EMACS_TIME_NEG_P (timer_delay
) && time_limit
!= -1)
7667 EMACS_TIME difference
;
7668 EMACS_SUB_TIME (difference
, timer_delay
, timeout
);
7669 if (EMACS_TIME_NEG_P (difference
))
7671 timeout
= timer_delay
;
7672 timeout_reduced_for_timers
= 1;
7677 /* Cause C-g and alarm signals to take immediate action,
7678 and cause input available signals to zero out timeout. */
7680 set_waiting_for_input (&timeout
);
7682 /* Wait till there is something to do. */
7684 if (! read_kbd
&& NILP (wait_for_cell
))
7685 FD_ZERO (&waitchannels
);
7687 FD_SET (0, &waitchannels
);
7689 /* If a frame has been newly mapped and needs updating,
7690 reprocess its display stuff. */
7691 if (frame_garbaged
&& do_display
)
7693 clear_waiting_for_input ();
7694 redisplay_preserve_echo_area (15);
7696 set_waiting_for_input (&timeout
);
7699 if (read_kbd
&& detect_input_pending ())
7702 FD_ZERO (&waitchannels
);
7705 nfds
= select (1, &waitchannels
, (SELECT_TYPE
*)0, (SELECT_TYPE
*)0,
7710 /* Make C-g and alarm signals set flags again */
7711 clear_waiting_for_input ();
7713 /* If we woke up due to SIGWINCH, actually change size now. */
7714 do_pending_window_change (0);
7716 if (time_limit
&& nfds
== 0 && ! timeout_reduced_for_timers
)
7717 /* We waited the full specified time, so return now. */
7722 /* If the system call was interrupted, then go around the
7724 if (xerrno
== EINTR
)
7725 FD_ZERO (&waitchannels
);
7727 error ("select error: %s", emacs_strerror (xerrno
));
7730 else if (nfds
> 0 && (waitchannels
& 1) && interrupt_input
)
7731 /* System sometimes fails to deliver SIGIO. */
7732 kill (getpid (), SIGIO
);
7735 if (read_kbd
&& interrupt_input
&& (waitchannels
& 1))
7736 kill (getpid (), SIGIO
);
7739 /* Check for keyboard input */
7742 && detect_input_pending_run_timers (do_display
))
7744 swallow_events (do_display
);
7745 if (detect_input_pending_run_timers (do_display
))
7749 /* If there is unread keyboard input, also return. */
7751 && requeued_events_pending_p ())
7754 /* If wait_for_cell. check for keyboard input
7755 but don't run any timers.
7756 ??? (It seems wrong to me to check for keyboard
7757 input at all when wait_for_cell, but the code
7758 has been this way since July 1994.
7759 Try changing this after version 19.31.) */
7760 if (! NILP (wait_for_cell
)
7761 && detect_input_pending ())
7763 swallow_events (do_display
);
7764 if (detect_input_pending ())
7768 /* Exit now if the cell we're waiting for became non-nil. */
7769 if (! NILP (wait_for_cell
) && ! NILP (XCAR (wait_for_cell
)))
7779 /* Don't confuse make-docfile by having two doc strings for this function.
7780 make-docfile does not pay attention to #if, for good reason! */
7781 DEFUN ("get-buffer-process", Fget_buffer_process
, Sget_buffer_process
, 1, 1, 0,
7784 register Lisp_Object name
;
7789 /* Don't confuse make-docfile by having two doc strings for this function.
7790 make-docfile does not pay attention to #if, for good reason! */
7791 DEFUN ("process-inherit-coding-system-flag",
7792 Fprocess_inherit_coding_system_flag
, Sprocess_inherit_coding_system_flag
,
7796 register Lisp_Object process
;
7798 /* Ignore the argument and return the value of
7799 inherit-process-coding-system. */
7800 return inherit_process_coding_system
? Qt
: Qnil
;
7803 /* Kill all processes associated with `buffer'.
7804 If `buffer' is nil, kill all processes.
7805 Since we have no subprocesses, this does nothing. */
7808 kill_buffer_processes (buffer
)
7813 DEFUN ("list-system-processes", Flist_system_processes
, Slist_system_processes
,
7815 doc
: /* Return a list of numerical process IDs of all running processes.
7816 If this functionality is unsupported, return nil.
7818 See `process-attributes' for getting attributes of a process given its ID. */)
7821 return list_system_processes ();
7824 DEFUN ("process-attributes", Fprocess_attributes
,
7825 Sprocess_attributes
, 1, 1, 0,
7826 doc
: /* Return attributes of the process given by its PID, a number.
7828 Value is an alist where each element is a cons cell of the form
7832 If this functionality is unsupported, the value is nil.
7834 See `list-system-processes' for getting a list of all process IDs.
7836 The KEYs of the attributes that this function may return are listed
7837 below, together with the type of the associated VALUE (in parentheses).
7838 Not all platforms support all of these attributes; unsupported
7839 attributes will not appear in the returned alist.
7840 Unless explicitly indicated otherwise, numbers can have either
7841 integer or floating point values.
7843 euid -- Effective user User ID of the process (number)
7844 user -- User name corresponding to euid (string)
7845 egid -- Effective user Group ID of the process (number)
7846 group -- Group name corresponding to egid (string)
7847 comm -- Command name (executable name only) (string)
7848 state -- Process state code, such as "S", "R", or "T" (string)
7849 ppid -- Parent process ID (number)
7850 pgrp -- Process group ID (number)
7851 sess -- Session ID, i.e. process ID of session leader (number)
7852 ttname -- Controlling tty name (string)
7853 tpgid -- ID of foreground process group on the process's tty (number)
7854 minflt -- number of minor page faults (number)
7855 majflt -- number of major page faults (number)
7856 cminflt -- cumulative number of minor page faults (number)
7857 cmajflt -- cumulative number of major page faults (number)
7858 utime -- user time used by the process, in the (HIGH LOW USEC) format
7859 stime -- system time used by the process, in the (HIGH LOW USEC) format
7860 time -- sum of utime and stime, in the (HIGH LOW USEC) format
7861 cutime -- user time used by the process and its children, (HIGH LOW USEC)
7862 cstime -- system time used by the process and its children, (HIGH LOW USEC)
7863 ctime -- sum of cutime and cstime, in the (HIGH LOW USEC) format
7864 pri -- priority of the process (number)
7865 nice -- nice value of the process (number)
7866 thcount -- process thread count (number)
7867 start -- time the process started, in the (HIGH LOW USEC) format
7868 vsize -- virtual memory size of the process in KB's (number)
7869 rss -- resident set size of the process in KB's (number)
7870 etime -- elapsed time the process is running, in (HIGH LOW USEC) format
7871 pcpu -- percents of CPU time used by the process (floating-point number)
7872 pmem -- percents of total physical memory used by process's resident set
7873 (floating-point number)
7874 args -- command line which invoked the process (string). */)
7879 return system_process_attributes (pid
);
7890 QCtype
= intern (":type");
7891 staticpro (&QCtype
);
7892 QCname
= intern (":name");
7893 staticpro (&QCname
);
7894 QCtype
= intern (":type");
7895 staticpro (&QCtype
);
7896 QCname
= intern (":name");
7897 staticpro (&QCname
);
7898 Qeuid
= intern ("euid");
7900 Qegid
= intern ("egid");
7902 Quser
= intern ("user");
7904 Qgroup
= intern ("group");
7905 staticpro (&Qgroup
);
7906 Qcomm
= intern ("comm");
7908 Qstate
= intern ("state");
7909 staticpro (&Qstate
);
7910 Qppid
= intern ("ppid");
7912 Qpgrp
= intern ("pgrp");
7914 Qsess
= intern ("sess");
7916 Qttname
= intern ("ttname");
7917 staticpro (&Qttname
);
7918 Qtpgid
= intern ("tpgid");
7919 staticpro (&Qtpgid
);
7920 Qminflt
= intern ("minflt");
7921 staticpro (&Qminflt
);
7922 Qmajflt
= intern ("majflt");
7923 staticpro (&Qmajflt
);
7924 Qcminflt
= intern ("cminflt");
7925 staticpro (&Qcminflt
);
7926 Qcmajflt
= intern ("cmajflt");
7927 staticpro (&Qcmajflt
);
7928 Qutime
= intern ("utime");
7929 staticpro (&Qutime
);
7930 Qstime
= intern ("stime");
7931 staticpro (&Qstime
);
7932 Qtime
= intern ("time");
7934 Qcutime
= intern ("cutime");
7935 staticpro (&Qcutime
);
7936 Qcstime
= intern ("cstime");
7937 staticpro (&Qcstime
);
7938 Qctime
= intern ("ctime");
7939 staticpro (&Qctime
);
7940 Qpri
= intern ("pri");
7942 Qnice
= intern ("nice");
7944 Qthcount
= intern ("thcount");
7945 staticpro (&Qthcount
);
7946 Qstart
= intern ("start");
7947 staticpro (&Qstart
);
7948 Qvsize
= intern ("vsize");
7949 staticpro (&Qvsize
);
7950 Qrss
= intern ("rss");
7952 Qetime
= intern ("etime");
7953 staticpro (&Qetime
);
7954 Qpcpu
= intern ("pcpu");
7956 Qpmem
= intern ("pmem");
7958 Qargs
= intern ("args");
7961 defsubr (&Sget_buffer_process
);
7962 defsubr (&Sprocess_inherit_coding_system_flag
);
7963 defsubr (&Slist_system_processes
);
7964 defsubr (&Sprocess_attributes
);
7968 #endif /* not subprocesses */
7970 /* arch-tag: 3706c011-7b9a-4117-bd4f-59e7f701a4c4
7971 (do not change this comment) */