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 new_argv
= (unsigned char **) alloca ((nargs
- 1) * sizeof (char *));
1703 /* If program file name is not absolute, search our path for it.
1704 Put the name we will really use in TEM. */
1705 if (!IS_DIRECTORY_SEP (SREF (program
, 0))
1706 && !(SCHARS (program
) > 1
1707 && IS_DEVICE_SEP (SREF (program
, 1))))
1709 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
1712 GCPRO4 (name
, program
, buffer
, current_dir
);
1713 openp (Vexec_path
, program
, Vexec_suffixes
, &tem
, make_number (X_OK
));
1716 report_file_error ("Searching for program", Fcons (program
, Qnil
));
1717 tem
= Fexpand_file_name (tem
, Qnil
);
1721 if (!NILP (Ffile_directory_p (program
)))
1722 error ("Specified program for new process is a directory");
1726 /* If program file name starts with /: for quoting a magic name,
1728 if (SBYTES (tem
) > 2 && SREF (tem
, 0) == '/'
1729 && SREF (tem
, 1) == ':')
1730 tem
= Fsubstring (tem
, make_number (2), Qnil
);
1732 /* Encode the file name and put it in NEW_ARGV.
1733 That's where the child will use it to execute the program. */
1734 tem
= ENCODE_FILE (tem
);
1735 new_argv
[0] = SDATA (tem
);
1737 /* Here we encode arguments by the coding system used for sending
1738 data to the process. We don't support using different coding
1739 systems for encoding arguments and for encoding data sent to the
1742 for (i
= 3; i
< nargs
; i
++)
1746 if (STRING_MULTIBYTE (tem
))
1747 tem
= (code_convert_string_norecord
1748 (tem
, XPROCESS (proc
)->encode_coding_system
, 1));
1749 new_argv
[i
- 2] = SDATA (tem
);
1751 new_argv
[i
- 2] = 0;
1753 XPROCESS (proc
)->decoding_buf
= make_uninit_string (0);
1754 XPROCESS (proc
)->decoding_carryover
= 0;
1755 XPROCESS (proc
)->encoding_buf
= make_uninit_string (0);
1757 XPROCESS (proc
)->inherit_coding_system_flag
1758 = !(NILP (buffer
) || !inherit_process_coding_system
);
1760 create_process (proc
, (char **) new_argv
, current_dir
);
1762 return unbind_to (count
, proc
);
1765 /* This function is the unwind_protect form for Fstart_process. If
1766 PROC doesn't have its pid set, then we know someone has signaled
1767 an error and the process wasn't started successfully, so we should
1768 remove it from the process list. */
1770 start_process_unwind (proc
)
1773 if (!PROCESSP (proc
))
1776 /* Was PROC started successfully? */
1777 if (XPROCESS (proc
)->pid
<= 0)
1778 remove_process (proc
);
1784 create_process_1 (timer
)
1785 struct atimer
*timer
;
1787 /* Nothing to do. */
1791 #if 0 /* This doesn't work; see the note before sigchld_handler. */
1794 /* Mimic blocking of signals on system V, which doesn't really have it. */
1796 /* Nonzero means we got a SIGCHLD when it was supposed to be blocked. */
1797 int sigchld_deferred
;
1800 create_process_sigchld ()
1802 signal (SIGCHLD
, create_process_sigchld
);
1804 sigchld_deferred
= 1;
1811 create_process (process
, new_argv
, current_dir
)
1812 Lisp_Object process
;
1814 Lisp_Object current_dir
;
1816 int inchannel
, outchannel
;
1819 #if !defined (WINDOWSNT) && defined (FD_CLOEXEC)
1820 int wait_child_setup
[2];
1822 #ifdef POSIX_SIGNALS
1825 struct sigaction sigint_action
;
1826 struct sigaction sigquit_action
;
1828 struct sigaction sighup_action
;
1830 #else /* !POSIX_SIGNALS */
1833 SIGTYPE (*sigchld
)();
1836 #endif /* !POSIX_SIGNALS */
1837 /* Use volatile to protect variables from being clobbered by longjmp. */
1838 volatile int forkin
, forkout
;
1839 volatile int pty_flag
= 0;
1841 extern char **environ
;
1844 inchannel
= outchannel
= -1;
1847 if (!NILP (Vprocess_connection_type
))
1848 outchannel
= inchannel
= allocate_pty ();
1852 #if ! defined (USG) || defined (USG_SUBTTY_WORKS)
1853 /* On most USG systems it does not work to open the pty's tty here,
1854 then close it and reopen it in the child. */
1856 /* Don't let this terminal become our controlling terminal
1857 (in case we don't have one). */
1858 forkout
= forkin
= emacs_open (pty_name
, O_RDWR
| O_NOCTTY
, 0);
1860 forkout
= forkin
= emacs_open (pty_name
, O_RDWR
, 0);
1863 report_file_error ("Opening pty", Qnil
);
1864 #if defined (DONT_REOPEN_PTY)
1865 /* In the case that vfork is defined as fork, the parent process
1866 (Emacs) may send some data before the child process completes
1867 tty options setup. So we setup tty before forking. */
1868 child_setup_tty (forkout
);
1869 #endif /* DONT_REOPEN_PTY */
1871 forkin
= forkout
= -1;
1872 #endif /* not USG, or USG_SUBTTY_WORKS */
1876 #endif /* HAVE_PTYS */
1881 report_file_error ("Creating pipe", Qnil
);
1887 emacs_close (inchannel
);
1888 emacs_close (forkout
);
1889 report_file_error ("Creating pipe", Qnil
);
1895 #if !defined (WINDOWSNT) && defined (FD_CLOEXEC)
1899 tem
= pipe (wait_child_setup
);
1901 report_file_error ("Creating pipe", Qnil
);
1902 tem
= fcntl (wait_child_setup
[1], F_GETFD
, 0);
1904 tem
= fcntl (wait_child_setup
[1], F_SETFD
, tem
| FD_CLOEXEC
);
1907 emacs_close (wait_child_setup
[0]);
1908 emacs_close (wait_child_setup
[1]);
1909 report_file_error ("Setting file descriptor flags", Qnil
);
1915 /* Replaced by close_process_descs */
1916 set_exclusive_use (inchannel
);
1917 set_exclusive_use (outchannel
);
1921 fcntl (inchannel
, F_SETFL
, O_NONBLOCK
);
1922 fcntl (outchannel
, F_SETFL
, O_NONBLOCK
);
1925 fcntl (inchannel
, F_SETFL
, O_NDELAY
);
1926 fcntl (outchannel
, F_SETFL
, O_NDELAY
);
1930 /* Record this as an active process, with its channels.
1931 As a result, child_setup will close Emacs's side of the pipes. */
1932 chan_process
[inchannel
] = process
;
1933 XPROCESS (process
)->infd
= inchannel
;
1934 XPROCESS (process
)->outfd
= outchannel
;
1936 /* Previously we recorded the tty descriptor used in the subprocess.
1937 It was only used for getting the foreground tty process, so now
1938 we just reopen the device (see emacs_get_tty_pgrp) as this is
1939 more portable (see USG_SUBTTY_WORKS above). */
1941 XPROCESS (process
)->pty_flag
= pty_flag
;
1942 XPROCESS (process
)->status
= Qrun
;
1943 setup_process_coding_systems (process
);
1945 /* Delay interrupts until we have a chance to store
1946 the new fork's pid in its process structure */
1947 #ifdef POSIX_SIGNALS
1948 sigemptyset (&blocked
);
1950 sigaddset (&blocked
, SIGCHLD
);
1952 #ifdef HAVE_WORKING_VFORK
1953 /* On many hosts (e.g. Solaris 2.4), if a vforked child calls `signal',
1954 this sets the parent's signal handlers as well as the child's.
1955 So delay all interrupts whose handlers the child might munge,
1956 and record the current handlers so they can be restored later. */
1957 sigaddset (&blocked
, SIGINT
); sigaction (SIGINT
, 0, &sigint_action
);
1958 sigaddset (&blocked
, SIGQUIT
); sigaction (SIGQUIT
, 0, &sigquit_action
);
1960 sigaddset (&blocked
, SIGHUP
); sigaction (SIGHUP
, 0, &sighup_action
);
1962 #endif /* HAVE_WORKING_VFORK */
1963 sigprocmask (SIG_BLOCK
, &blocked
, &procmask
);
1964 #else /* !POSIX_SIGNALS */
1966 #if defined (BSD_SYSTEM) || defined (HPUX)
1967 sigsetmask (sigmask (SIGCHLD
));
1968 #else /* ordinary USG */
1970 sigchld_deferred
= 0;
1971 sigchld
= signal (SIGCHLD
, create_process_sigchld
);
1973 #endif /* ordinary USG */
1974 #endif /* SIGCHLD */
1975 #endif /* !POSIX_SIGNALS */
1977 FD_SET (inchannel
, &input_wait_mask
);
1978 FD_SET (inchannel
, &non_keyboard_wait_mask
);
1979 if (inchannel
> max_process_desc
)
1980 max_process_desc
= inchannel
;
1982 /* Until we store the proper pid, enable sigchld_handler
1983 to recognize an unknown pid as standing for this process.
1984 It is very important not to let this `marker' value stay
1985 in the table after this function has returned; if it does
1986 it might cause call-process to hang and subsequent asynchronous
1987 processes to get their return values scrambled. */
1988 XPROCESS (process
)->pid
= -1;
1993 /* child_setup must clobber environ on systems with true vfork.
1994 Protect it from permanent change. */
1995 char **save_environ
= environ
;
1997 current_dir
= ENCODE_FILE (current_dir
);
2002 #endif /* not WINDOWSNT */
2004 int xforkin
= forkin
;
2005 int xforkout
= forkout
;
2007 #if 0 /* This was probably a mistake--it duplicates code later on,
2008 but fails to handle all the cases. */
2009 /* Make sure SIGCHLD is not blocked in the child. */
2010 sigsetmask (SIGEMPTYMASK
);
2013 /* Make the pty be the controlling terminal of the process. */
2015 /* First, disconnect its current controlling terminal. */
2017 /* We tried doing setsid only if pty_flag, but it caused
2018 process_set_signal to fail on SGI when using a pipe. */
2020 /* Make the pty's terminal the controlling terminal. */
2024 /* We ignore the return value
2025 because faith@cs.unc.edu says that is necessary on Linux. */
2026 ioctl (xforkin
, TIOCSCTTY
, 0);
2029 #else /* not HAVE_SETSID */
2031 /* It's very important to call setpgrp here and no time
2032 afterwards. Otherwise, we lose our controlling tty which
2033 is set when we open the pty. */
2036 #endif /* not HAVE_SETSID */
2037 #if defined (HAVE_TERMIOS) && defined (LDISC1)
2038 if (pty_flag
&& xforkin
>= 0)
2041 tcgetattr (xforkin
, &t
);
2043 if (tcsetattr (xforkin
, TCSANOW
, &t
) < 0)
2044 emacs_write (1, "create_process/tcsetattr LDISC1 failed\n", 39);
2047 #if defined (NTTYDISC) && defined (TIOCSETD)
2048 if (pty_flag
&& xforkin
>= 0)
2050 /* Use new line discipline. */
2051 int ldisc
= NTTYDISC
;
2052 ioctl (xforkin
, TIOCSETD
, &ldisc
);
2057 /* In 4.3BSD, the TIOCSPGRP bug has been fixed, and now you
2058 can do TIOCSPGRP only to the process's controlling tty. */
2061 /* I wonder: would just ioctl (0, TIOCNOTTY, 0) work here?
2062 I can't test it since I don't have 4.3. */
2063 int j
= emacs_open ("/dev/tty", O_RDWR
, 0);
2064 ioctl (j
, TIOCNOTTY
, 0);
2067 /* In order to get a controlling terminal on some versions
2068 of BSD, it is necessary to put the process in pgrp 0
2069 before it opens the terminal. */
2077 #endif /* TIOCNOTTY */
2079 #if !defined (DONT_REOPEN_PTY)
2080 /*** There is a suggestion that this ought to be a
2081 conditional on TIOCSPGRP,
2082 or !(defined (HAVE_SETSID) && defined (TIOCSCTTY)).
2083 Trying the latter gave the wrong results on Debian GNU/Linux 1.1;
2084 that system does seem to need this code, even though
2085 both HAVE_SETSID and TIOCSCTTY are defined. */
2086 /* Now close the pty (if we had it open) and reopen it.
2087 This makes the pty the controlling terminal of the subprocess. */
2091 /* I wonder if emacs_close (emacs_open (pty_name, ...))
2094 emacs_close (xforkin
);
2095 xforkout
= xforkin
= emacs_open (pty_name
, O_RDWR
, 0);
2099 emacs_write (1, "Couldn't open the pty terminal ", 31);
2100 emacs_write (1, pty_name
, strlen (pty_name
));
2101 emacs_write (1, "\n", 1);
2106 #endif /* not DONT_REOPEN_PTY */
2108 #ifdef SETUP_SLAVE_PTY
2113 #endif /* SETUP_SLAVE_PTY */
2115 /* On AIX, we've disabled SIGHUP above once we start a child on a pty.
2116 Now reenable it in the child, so it will die when we want it to. */
2118 signal (SIGHUP
, SIG_DFL
);
2120 #endif /* HAVE_PTYS */
2122 signal (SIGINT
, SIG_DFL
);
2123 signal (SIGQUIT
, SIG_DFL
);
2125 /* Stop blocking signals in the child. */
2126 #ifdef POSIX_SIGNALS
2127 sigprocmask (SIG_SETMASK
, &procmask
, 0);
2128 #else /* !POSIX_SIGNALS */
2130 #if defined (BSD_SYSTEM) || defined (HPUX)
2131 sigsetmask (SIGEMPTYMASK
);
2132 #else /* ordinary USG */
2134 signal (SIGCHLD
, sigchld
);
2136 #endif /* ordinary USG */
2137 #endif /* SIGCHLD */
2138 #endif /* !POSIX_SIGNALS */
2140 #if !defined (DONT_REOPEN_PTY)
2142 child_setup_tty (xforkout
);
2143 #endif /* not DONT_REOPEN_PTY */
2145 pid
= child_setup (xforkin
, xforkout
, xforkout
,
2146 new_argv
, 1, current_dir
);
2147 #else /* not WINDOWSNT */
2149 emacs_close (wait_child_setup
[0]);
2151 child_setup (xforkin
, xforkout
, xforkout
,
2152 new_argv
, 1, current_dir
);
2153 #endif /* not WINDOWSNT */
2155 environ
= save_environ
;
2160 /* This runs in the Emacs process. */
2164 emacs_close (forkin
);
2165 if (forkin
!= forkout
&& forkout
>= 0)
2166 emacs_close (forkout
);
2170 /* vfork succeeded. */
2171 XPROCESS (process
)->pid
= pid
;
2174 register_child (pid
, inchannel
);
2175 #endif /* WINDOWSNT */
2177 /* If the subfork execv fails, and it exits,
2178 this close hangs. I don't know why.
2179 So have an interrupt jar it loose. */
2181 struct atimer
*timer
;
2185 EMACS_SET_SECS_USECS (offset
, 1, 0);
2186 timer
= start_atimer (ATIMER_RELATIVE
, offset
, create_process_1
, 0);
2189 emacs_close (forkin
);
2191 cancel_atimer (timer
);
2195 if (forkin
!= forkout
&& forkout
>= 0)
2196 emacs_close (forkout
);
2200 XPROCESS (process
)->tty_name
= build_string (pty_name
);
2203 XPROCESS (process
)->tty_name
= Qnil
;
2205 #if !defined (WINDOWSNT) && defined (FD_CLOEXEC)
2206 /* Wait for child_setup to complete in case that vfork is
2207 actually defined as fork. The descriptor wait_child_setup[1]
2208 of a pipe is closed at the child side either by close-on-exec
2209 on successful execvp or the _exit call in child_setup. */
2213 emacs_close (wait_child_setup
[1]);
2214 emacs_read (wait_child_setup
[0], &dummy
, 1);
2215 emacs_close (wait_child_setup
[0]);
2220 /* Restore the signal state whether vfork succeeded or not.
2221 (We will signal an error, below, if it failed.) */
2222 #ifdef POSIX_SIGNALS
2223 #ifdef HAVE_WORKING_VFORK
2224 /* Restore the parent's signal handlers. */
2225 sigaction (SIGINT
, &sigint_action
, 0);
2226 sigaction (SIGQUIT
, &sigquit_action
, 0);
2228 sigaction (SIGHUP
, &sighup_action
, 0);
2230 #endif /* HAVE_WORKING_VFORK */
2231 /* Stop blocking signals in the parent. */
2232 sigprocmask (SIG_SETMASK
, &procmask
, 0);
2233 #else /* !POSIX_SIGNALS */
2235 #if defined (BSD_SYSTEM) || defined (HPUX)
2236 sigsetmask (SIGEMPTYMASK
);
2237 #else /* ordinary USG */
2239 signal (SIGCHLD
, sigchld
);
2240 /* Now really handle any of these signals
2241 that came in during this function. */
2242 if (sigchld_deferred
)
2243 kill (getpid (), SIGCHLD
);
2245 #endif /* ordinary USG */
2246 #endif /* SIGCHLD */
2247 #endif /* !POSIX_SIGNALS */
2249 /* Now generate the error if vfork failed. */
2251 report_file_error ("Doing vfork", Qnil
);
2257 /* Convert an internal struct sockaddr to a lisp object (vector or string).
2258 The address family of sa is not included in the result. */
2261 conv_sockaddr_to_lisp (sa
, len
)
2262 struct sockaddr
*sa
;
2265 Lisp_Object address
;
2268 register struct Lisp_Vector
*p
;
2270 /* Workaround for a bug in getsockname on BSD: Names bound to
2271 sockets in the UNIX domain are inaccessible; getsockname returns
2272 a zero length name. */
2273 if (len
< OFFSETOF (struct sockaddr
, sa_family
) + sizeof (sa
->sa_family
))
2274 return empty_unibyte_string
;
2276 switch (sa
->sa_family
)
2280 struct sockaddr_in
*sin
= (struct sockaddr_in
*) sa
;
2281 len
= sizeof (sin
->sin_addr
) + 1;
2282 address
= Fmake_vector (make_number (len
), Qnil
);
2283 p
= XVECTOR (address
);
2284 p
->contents
[--len
] = make_number (ntohs (sin
->sin_port
));
2285 cp
= (unsigned char *) &sin
->sin_addr
;
2291 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*) sa
;
2292 uint16_t *ip6
= (uint16_t *) &sin6
->sin6_addr
;
2293 len
= sizeof (sin6
->sin6_addr
)/2 + 1;
2294 address
= Fmake_vector (make_number (len
), Qnil
);
2295 p
= XVECTOR (address
);
2296 p
->contents
[--len
] = make_number (ntohs (sin6
->sin6_port
));
2297 for (i
= 0; i
< len
; i
++)
2298 p
->contents
[i
] = make_number (ntohs (ip6
[i
]));
2302 #ifdef HAVE_LOCAL_SOCKETS
2305 struct sockaddr_un
*sockun
= (struct sockaddr_un
*) sa
;
2306 for (i
= 0; i
< sizeof (sockun
->sun_path
); i
++)
2307 if (sockun
->sun_path
[i
] == 0)
2309 return make_unibyte_string (sockun
->sun_path
, i
);
2313 len
-= OFFSETOF (struct sockaddr
, sa_family
) + sizeof (sa
->sa_family
);
2314 address
= Fcons (make_number (sa
->sa_family
),
2315 Fmake_vector (make_number (len
), Qnil
));
2316 p
= XVECTOR (XCDR (address
));
2317 cp
= (unsigned char *) &sa
->sa_family
+ sizeof (sa
->sa_family
);
2323 p
->contents
[i
++] = make_number (*cp
++);
2329 /* Get family and required size for sockaddr structure to hold ADDRESS. */
2332 get_lisp_to_sockaddr_size (address
, familyp
)
2333 Lisp_Object address
;
2336 register struct Lisp_Vector
*p
;
2338 if (VECTORP (address
))
2340 p
= XVECTOR (address
);
2344 return sizeof (struct sockaddr_in
);
2347 else if (p
->size
== 9)
2349 *familyp
= AF_INET6
;
2350 return sizeof (struct sockaddr_in6
);
2354 #ifdef HAVE_LOCAL_SOCKETS
2355 else if (STRINGP (address
))
2357 *familyp
= AF_LOCAL
;
2358 return sizeof (struct sockaddr_un
);
2361 else if (CONSP (address
) && INTEGERP (XCAR (address
)) && VECTORP (XCDR (address
)))
2363 struct sockaddr
*sa
;
2364 *familyp
= XINT (XCAR (address
));
2365 p
= XVECTOR (XCDR (address
));
2366 return p
->size
+ sizeof (sa
->sa_family
);
2371 /* Convert an address object (vector or string) to an internal sockaddr.
2373 The address format has been basically validated by
2374 get_lisp_to_sockaddr_size, but this does not mean FAMILY is valid;
2375 it could have come from user data. So if FAMILY is not valid,
2376 we return after zeroing *SA. */
2379 conv_lisp_to_sockaddr (family
, address
, sa
, len
)
2381 Lisp_Object address
;
2382 struct sockaddr
*sa
;
2385 register struct Lisp_Vector
*p
;
2386 register unsigned char *cp
= NULL
;
2391 if (VECTORP (address
))
2393 p
= XVECTOR (address
);
2394 if (family
== AF_INET
)
2396 struct sockaddr_in
*sin
= (struct sockaddr_in
*) sa
;
2397 len
= sizeof (sin
->sin_addr
) + 1;
2398 i
= XINT (p
->contents
[--len
]);
2399 sin
->sin_port
= htons (i
);
2400 cp
= (unsigned char *)&sin
->sin_addr
;
2401 sa
->sa_family
= family
;
2404 else if (family
== AF_INET6
)
2406 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*) sa
;
2407 uint16_t *ip6
= (uint16_t *)&sin6
->sin6_addr
;
2408 len
= sizeof (sin6
->sin6_addr
) + 1;
2409 i
= XINT (p
->contents
[--len
]);
2410 sin6
->sin6_port
= htons (i
);
2411 for (i
= 0; i
< len
; i
++)
2412 if (INTEGERP (p
->contents
[i
]))
2414 int j
= XFASTINT (p
->contents
[i
]) & 0xffff;
2417 sa
->sa_family
= family
;
2422 else if (STRINGP (address
))
2424 #ifdef HAVE_LOCAL_SOCKETS
2425 if (family
== AF_LOCAL
)
2427 struct sockaddr_un
*sockun
= (struct sockaddr_un
*) sa
;
2428 cp
= SDATA (address
);
2429 for (i
= 0; i
< sizeof (sockun
->sun_path
) && *cp
; i
++)
2430 sockun
->sun_path
[i
] = *cp
++;
2431 sa
->sa_family
= family
;
2438 p
= XVECTOR (XCDR (address
));
2439 cp
= (unsigned char *)sa
+ sizeof (sa
->sa_family
);
2442 for (i
= 0; i
< len
; i
++)
2443 if (INTEGERP (p
->contents
[i
]))
2444 *cp
++ = XFASTINT (p
->contents
[i
]) & 0xff;
2447 #ifdef DATAGRAM_SOCKETS
2448 DEFUN ("process-datagram-address", Fprocess_datagram_address
, Sprocess_datagram_address
,
2450 doc
: /* Get the current datagram address associated with PROCESS. */)
2452 Lisp_Object process
;
2456 CHECK_PROCESS (process
);
2458 if (!DATAGRAM_CONN_P (process
))
2461 channel
= XPROCESS (process
)->infd
;
2462 return conv_sockaddr_to_lisp (datagram_address
[channel
].sa
,
2463 datagram_address
[channel
].len
);
2466 DEFUN ("set-process-datagram-address", Fset_process_datagram_address
, Sset_process_datagram_address
,
2468 doc
: /* Set the datagram address for PROCESS to ADDRESS.
2469 Returns nil upon error setting address, ADDRESS otherwise. */)
2471 Lisp_Object process
, address
;
2476 CHECK_PROCESS (process
);
2478 if (!DATAGRAM_CONN_P (process
))
2481 channel
= XPROCESS (process
)->infd
;
2483 len
= get_lisp_to_sockaddr_size (address
, &family
);
2484 if (datagram_address
[channel
].len
!= len
)
2486 conv_lisp_to_sockaddr (family
, address
, datagram_address
[channel
].sa
, len
);
2492 static struct socket_options
{
2493 /* The name of this option. Should be lowercase version of option
2494 name without SO_ prefix. */
2496 /* Option level SOL_... */
2498 /* Option number SO_... */
2500 enum { SOPT_UNKNOWN
, SOPT_BOOL
, SOPT_INT
, SOPT_IFNAME
, SOPT_LINGER
} opttype
;
2501 enum { OPIX_NONE
=0, OPIX_MISC
=1, OPIX_REUSEADDR
=2 } optbit
;
2502 } socket_options
[] =
2504 #ifdef SO_BINDTODEVICE
2505 { ":bindtodevice", SOL_SOCKET
, SO_BINDTODEVICE
, SOPT_IFNAME
, OPIX_MISC
},
2508 { ":broadcast", SOL_SOCKET
, SO_BROADCAST
, SOPT_BOOL
, OPIX_MISC
},
2511 { ":dontroute", SOL_SOCKET
, SO_DONTROUTE
, SOPT_BOOL
, OPIX_MISC
},
2514 { ":keepalive", SOL_SOCKET
, SO_KEEPALIVE
, SOPT_BOOL
, OPIX_MISC
},
2517 { ":linger", SOL_SOCKET
, SO_LINGER
, SOPT_LINGER
, OPIX_MISC
},
2520 { ":oobinline", SOL_SOCKET
, SO_OOBINLINE
, SOPT_BOOL
, OPIX_MISC
},
2523 { ":priority", SOL_SOCKET
, SO_PRIORITY
, SOPT_INT
, OPIX_MISC
},
2526 { ":reuseaddr", SOL_SOCKET
, SO_REUSEADDR
, SOPT_BOOL
, OPIX_REUSEADDR
},
2528 { 0, 0, 0, SOPT_UNKNOWN
, OPIX_NONE
}
2531 /* Set option OPT to value VAL on socket S.
2533 Returns (1<<socket_options[OPT].optbit) if option is known, 0 otherwise.
2534 Signals an error if setting a known option fails.
2538 set_socket_option (s
, opt
, val
)
2540 Lisp_Object opt
, val
;
2543 struct socket_options
*sopt
;
2548 name
= (char *) SDATA (SYMBOL_NAME (opt
));
2549 for (sopt
= socket_options
; sopt
->name
; sopt
++)
2550 if (strcmp (name
, sopt
->name
) == 0)
2553 switch (sopt
->opttype
)
2558 optval
= NILP (val
) ? 0 : 1;
2559 ret
= setsockopt (s
, sopt
->optlevel
, sopt
->optnum
,
2560 &optval
, sizeof (optval
));
2568 optval
= XINT (val
);
2570 error ("Bad option value for %s", name
);
2571 ret
= setsockopt (s
, sopt
->optlevel
, sopt
->optnum
,
2572 &optval
, sizeof (optval
));
2576 #ifdef SO_BINDTODEVICE
2579 char devname
[IFNAMSIZ
+1];
2581 /* This is broken, at least in the Linux 2.4 kernel.
2582 To unbind, the arg must be a zero integer, not the empty string.
2583 This should work on all systems. KFS. 2003-09-23. */
2584 bzero (devname
, sizeof devname
);
2587 char *arg
= (char *) SDATA (val
);
2588 int len
= min (strlen (arg
), IFNAMSIZ
);
2589 bcopy (arg
, devname
, len
);
2591 else if (!NILP (val
))
2592 error ("Bad option value for %s", name
);
2593 ret
= setsockopt (s
, sopt
->optlevel
, sopt
->optnum
,
2602 struct linger linger
;
2605 linger
.l_linger
= 0;
2607 linger
.l_linger
= XINT (val
);
2609 linger
.l_onoff
= NILP (val
) ? 0 : 1;
2610 ret
= setsockopt (s
, sopt
->optlevel
, sopt
->optnum
,
2611 &linger
, sizeof (linger
));
2621 report_file_error ("Cannot set network option",
2622 Fcons (opt
, Fcons (val
, Qnil
)));
2623 return (1 << sopt
->optbit
);
2627 DEFUN ("set-network-process-option",
2628 Fset_network_process_option
, Sset_network_process_option
,
2630 doc
: /* For network process PROCESS set option OPTION to value VALUE.
2631 See `make-network-process' for a list of options and values.
2632 If optional fourth arg NO-ERROR is non-nil, don't signal an error if
2633 OPTION is not a supported option, return nil instead; otherwise return t. */)
2634 (process
, option
, value
, no_error
)
2635 Lisp_Object process
, option
, value
;
2636 Lisp_Object no_error
;
2639 struct Lisp_Process
*p
;
2641 CHECK_PROCESS (process
);
2642 p
= XPROCESS (process
);
2643 if (!NETCONN1_P (p
))
2644 error ("Process is not a network process");
2648 error ("Process is not running");
2650 if (set_socket_option (s
, option
, value
))
2652 p
->childp
= Fplist_put (p
->childp
, option
, value
);
2656 if (NILP (no_error
))
2657 error ("Unknown or unsupported option");
2664 DEFUN ("serial-process-configure",
2665 Fserial_process_configure
,
2666 Sserial_process_configure
,
2668 doc
: /* Configure speed, bytesize, etc. of a serial process.
2670 Arguments are specified as keyword/argument pairs. Attributes that
2671 are not given are re-initialized from the process's current
2672 configuration (available via the function `process-contact') or set to
2673 reasonable default values. The following arguments are defined:
2679 -- Any of these arguments can be given to identify the process that is
2680 to be configured. If none of these arguments is given, the current
2681 buffer's process is used.
2683 :speed SPEED -- SPEED is the speed of the serial port in bits per
2684 second, also called baud rate. Any value can be given for SPEED, but
2685 most serial ports work only at a few defined values between 1200 and
2686 115200, with 9600 being the most common value. If SPEED is nil, the
2687 serial port is not configured any further, i.e., all other arguments
2688 are ignored. This may be useful for special serial ports such as
2689 Bluetooth-to-serial converters which can only be configured through AT
2690 commands. A value of nil for SPEED can be used only when passed
2691 through `make-serial-process' or `serial-term'.
2693 :bytesize BYTESIZE -- BYTESIZE is the number of bits per byte, which
2694 can be 7 or 8. If BYTESIZE is not given or nil, a value of 8 is used.
2696 :parity PARITY -- PARITY can be nil (don't use parity), the symbol
2697 `odd' (use odd parity), or the symbol `even' (use even parity). If
2698 PARITY is not given, no parity is used.
2700 :stopbits STOPBITS -- STOPBITS is the number of stopbits used to
2701 terminate a byte transmission. STOPBITS can be 1 or 2. If STOPBITS
2702 is not given or nil, 1 stopbit is used.
2704 :flowcontrol FLOWCONTROL -- FLOWCONTROL determines the type of
2705 flowcontrol to be used, which is either nil (don't use flowcontrol),
2706 the symbol `hw' (use RTS/CTS hardware flowcontrol), or the symbol `sw'
2707 \(use XON/XOFF software flowcontrol). If FLOWCONTROL is not given, no
2708 flowcontrol is used.
2710 `serial-process-configure' is called by `make-serial-process' for the
2711 initial configuration of the serial port.
2715 \(serial-process-configure :process "/dev/ttyS0" :speed 1200)
2717 \(serial-process-configure
2718 :buffer "COM1" :stopbits 1 :parity 'odd :flowcontrol 'hw)
2720 \(serial-process-configure :port "\\\\.\\COM13" :bytesize 7)
2722 usage: (serial-process-configure &rest ARGS) */)
2727 struct Lisp_Process
*p
;
2728 Lisp_Object contact
= Qnil
;
2729 Lisp_Object proc
= Qnil
;
2730 struct gcpro gcpro1
;
2732 contact
= Flist (nargs
, args
);
2735 proc
= Fplist_get (contact
, QCprocess
);
2737 proc
= Fplist_get (contact
, QCname
);
2739 proc
= Fplist_get (contact
, QCbuffer
);
2741 proc
= Fplist_get (contact
, QCport
);
2742 proc
= get_process (proc
);
2743 p
= XPROCESS (proc
);
2744 if (!EQ (p
->type
, Qserial
))
2745 error ("Not a serial process");
2747 if (NILP (Fplist_get (p
->childp
, QCspeed
)))
2753 serial_configure (p
, contact
);
2759 /* Used by make-serial-process to recover from errors. */
2760 Lisp_Object
make_serial_process_unwind (Lisp_Object proc
)
2762 if (!PROCESSP (proc
))
2764 remove_process (proc
);
2768 DEFUN ("make-serial-process", Fmake_serial_process
, Smake_serial_process
,
2770 doc
: /* Create and return a serial port process.
2772 In Emacs, serial port connections are represented by process objects,
2773 so input and output work as for subprocesses, and `delete-process'
2774 closes a serial port connection. However, a serial process has no
2775 process id, it cannot be signaled, and the status codes are different
2776 from normal processes.
2778 `make-serial-process' creates a process and a buffer, on which you
2779 probably want to use `process-send-string'. Try \\[serial-term] for
2780 an interactive terminal. See below for examples.
2782 Arguments are specified as keyword/argument pairs. The following
2783 arguments are defined:
2785 :port PORT -- (mandatory) PORT is the path or name of the serial port.
2786 For example, this could be "/dev/ttyS0" on Unix. On Windows, this
2787 could be "COM1", or "\\\\.\\COM10" for ports higher than COM9 (double
2788 the backslashes in strings).
2790 :speed SPEED -- (mandatory) is handled by `serial-process-configure',
2791 which is called by `make-serial-process'.
2793 :name NAME -- NAME is the name of the process. If NAME is not given,
2794 the value of PORT is used.
2796 :buffer BUFFER -- BUFFER is the buffer (or buffer-name) to associate
2797 with the process. Process output goes at the end of that buffer,
2798 unless you specify an output stream or filter function to handle the
2799 output. If BUFFER is not given, the value of NAME is used.
2801 :coding CODING -- If CODING is a symbol, it specifies the coding
2802 system used for both reading and writing for this process. If CODING
2803 is a cons (DECODING . ENCODING), DECODING is used for reading, and
2804 ENCODING is used for writing.
2806 :noquery BOOL -- When exiting Emacs, query the user if BOOL is nil and
2807 the process is running. If BOOL is not given, query before exiting.
2809 :stop BOOL -- Start process in the `stopped' state if BOOL is non-nil.
2810 In the stopped state, a serial process does not accept incoming data,
2811 but you can send outgoing data. The stopped state is cleared by
2812 `continue-process' and set by `stop-process'.
2814 :filter FILTER -- Install FILTER as the process filter.
2816 :sentinel SENTINEL -- Install SENTINEL as the process sentinel.
2818 :plist PLIST -- Install PLIST as the initial plist of the process.
2825 -- These arguments are handled by `serial-process-configure', which is
2826 called by `make-serial-process'.
2828 The original argument list, possibly modified by later configuration,
2829 is available via the function `process-contact'.
2833 \(make-serial-process :port "/dev/ttyS0" :speed 9600)
2835 \(make-serial-process :port "COM1" :speed 115200 :stopbits 2)
2837 \(make-serial-process :port "\\\\.\\COM13" :speed 1200 :bytesize 7 :parity 'odd)
2839 \(make-serial-process :port "/dev/tty.BlueConsole-SPP-1" :speed nil)
2841 usage: (make-serial-process &rest ARGS) */)
2847 Lisp_Object proc
, contact
, port
;
2848 struct Lisp_Process
*p
;
2849 struct gcpro gcpro1
;
2850 Lisp_Object name
, buffer
;
2851 Lisp_Object tem
, val
;
2852 int specpdl_count
= -1;
2857 contact
= Flist (nargs
, args
);
2860 port
= Fplist_get (contact
, QCport
);
2862 error ("No port specified");
2863 CHECK_STRING (port
);
2865 if (NILP (Fplist_member (contact
, QCspeed
)))
2866 error (":speed not specified");
2867 if (!NILP (Fplist_get (contact
, QCspeed
)))
2868 CHECK_NUMBER (Fplist_get (contact
, QCspeed
));
2870 name
= Fplist_get (contact
, QCname
);
2873 CHECK_STRING (name
);
2874 proc
= make_process (name
);
2875 specpdl_count
= SPECPDL_INDEX ();
2876 record_unwind_protect (make_serial_process_unwind
, proc
);
2877 p
= XPROCESS (proc
);
2879 fd
= serial_open ((char*) SDATA (port
));
2882 if (fd
> max_process_desc
)
2883 max_process_desc
= fd
;
2884 chan_process
[fd
] = proc
;
2886 buffer
= Fplist_get (contact
, QCbuffer
);
2889 buffer
= Fget_buffer_create (buffer
);
2892 p
->childp
= contact
;
2893 p
->plist
= Fcopy_sequence (Fplist_get (contact
, QCplist
));
2895 p
->sentinel
= Fplist_get (contact
, QCsentinel
);
2896 p
->filter
= Fplist_get (contact
, QCfilter
);
2898 if (tem
= Fplist_get (contact
, QCnoquery
), !NILP (tem
))
2899 p
->kill_without_query
= 1;
2900 if (tem
= Fplist_get (contact
, QCstop
), !NILP (tem
))
2904 if (!EQ (p
->command
, Qt
))
2906 FD_SET (fd
, &input_wait_mask
);
2907 FD_SET (fd
, &non_keyboard_wait_mask
);
2910 if (BUFFERP (buffer
))
2912 set_marker_both (p
->mark
, buffer
,
2913 BUF_ZV (XBUFFER (buffer
)),
2914 BUF_ZV_BYTE (XBUFFER (buffer
)));
2917 tem
= Fplist_member (contact
, QCcoding
);
2918 if (!NILP (tem
) && (!CONSP (tem
) || !CONSP (XCDR (tem
))))
2924 val
= XCAR (XCDR (tem
));
2928 else if (!NILP (Vcoding_system_for_read
))
2929 val
= Vcoding_system_for_read
;
2930 else if ((!NILP (buffer
) && NILP (XBUFFER (buffer
)->enable_multibyte_characters
))
2931 || (NILP (buffer
) && NILP (buffer_defaults
.enable_multibyte_characters
)))
2933 p
->decode_coding_system
= val
;
2938 val
= XCAR (XCDR (tem
));
2942 else if (!NILP (Vcoding_system_for_write
))
2943 val
= Vcoding_system_for_write
;
2944 else if ((!NILP (buffer
) && NILP (XBUFFER (buffer
)->enable_multibyte_characters
))
2945 || (NILP (buffer
) && NILP (buffer_defaults
.enable_multibyte_characters
)))
2947 p
->encode_coding_system
= val
;
2949 setup_process_coding_systems (proc
);
2950 p
->decoding_buf
= make_uninit_string (0);
2951 p
->decoding_carryover
= 0;
2952 p
->encoding_buf
= make_uninit_string (0);
2953 p
->inherit_coding_system_flag
2954 = !(!NILP (tem
) || NILP (buffer
) || !inherit_process_coding_system
);
2956 Fserial_process_configure(nargs
, args
);
2958 specpdl_ptr
= specpdl
+ specpdl_count
;
2963 #endif /* HAVE_SERIAL */
2965 /* Create a network stream/datagram client/server process. Treated
2966 exactly like a normal process when reading and writing. Primary
2967 differences are in status display and process deletion. A network
2968 connection has no PID; you cannot signal it. All you can do is
2969 stop/continue it and deactivate/close it via delete-process */
2971 DEFUN ("make-network-process", Fmake_network_process
, Smake_network_process
,
2973 doc
: /* Create and return a network server or client process.
2975 In Emacs, network connections are represented by process objects, so
2976 input and output work as for subprocesses and `delete-process' closes
2977 a network connection. However, a network process has no process id,
2978 it cannot be signaled, and the status codes are different from normal
2981 Arguments are specified as keyword/argument pairs. The following
2982 arguments are defined:
2984 :name NAME -- NAME is name for process. It is modified if necessary
2987 :buffer BUFFER -- BUFFER is the buffer (or buffer-name) to associate
2988 with the process. Process output goes at end of that buffer, unless
2989 you specify an output stream or filter function to handle the output.
2990 BUFFER may be also nil, meaning that this process is not associated
2993 :host HOST -- HOST is name of the host to connect to, or its IP
2994 address. The symbol `local' specifies the local host. If specified
2995 for a server process, it must be a valid name or address for the local
2996 host, and only clients connecting to that address will be accepted.
2998 :service SERVICE -- SERVICE is name of the service desired, or an
2999 integer specifying a port number to connect to. If SERVICE is t,
3000 a random port number is selected for the server. (If Emacs was
3001 compiled with getaddrinfo, a port number can also be specified as a
3002 string, e.g. "80", as well as an integer. This is not portable.)
3004 :type TYPE -- TYPE is the type of connection. The default (nil) is a
3005 stream type connection, `datagram' creates a datagram type connection.
3007 :family FAMILY -- FAMILY is the address (and protocol) family for the
3008 service specified by HOST and SERVICE. The default (nil) is to use
3009 whatever address family (IPv4 or IPv6) that is defined for the host
3010 and port number specified by HOST and SERVICE. Other address families
3012 local -- for a local (i.e. UNIX) address specified by SERVICE.
3013 ipv4 -- use IPv4 address family only.
3014 ipv6 -- use IPv6 address family only.
3016 :local ADDRESS -- ADDRESS is the local address used for the connection.
3017 This parameter is ignored when opening a client process. When specified
3018 for a server process, the FAMILY, HOST and SERVICE args are ignored.
3020 :remote ADDRESS -- ADDRESS is the remote partner's address for the
3021 connection. This parameter is ignored when opening a stream server
3022 process. For a datagram server process, it specifies the initial
3023 setting of the remote datagram address. When specified for a client
3024 process, the FAMILY, HOST, and SERVICE args are ignored.
3026 The format of ADDRESS depends on the address family:
3027 - An IPv4 address is represented as an vector of integers [A B C D P]
3028 corresponding to numeric IP address A.B.C.D and port number P.
3029 - A local address is represented as a string with the address in the
3030 local address space.
3031 - An "unsupported family" address is represented by a cons (F . AV)
3032 where F is the family number and AV is a vector containing the socket
3033 address data with one element per address data byte. Do not rely on
3034 this format in portable code, as it may depend on implementation
3035 defined constants, data sizes, and data structure alignment.
3037 :coding CODING -- If CODING is a symbol, it specifies the coding
3038 system used for both reading and writing for this process. If CODING
3039 is a cons (DECODING . ENCODING), DECODING is used for reading, and
3040 ENCODING is used for writing.
3042 :nowait BOOL -- If BOOL is non-nil for a stream type client process,
3043 return without waiting for the connection to complete; instead, the
3044 sentinel function will be called with second arg matching "open" (if
3045 successful) or "failed" when the connect completes. Default is to use
3046 a blocking connect (i.e. wait) for stream type connections.
3048 :noquery BOOL -- Query the user unless BOOL is non-nil, and process is
3049 running when Emacs is exited.
3051 :stop BOOL -- Start process in the `stopped' state if BOOL non-nil.
3052 In the stopped state, a server process does not accept new
3053 connections, and a client process does not handle incoming traffic.
3054 The stopped state is cleared by `continue-process' and set by
3057 :filter FILTER -- Install FILTER as the process filter.
3059 :filter-multibyte BOOL -- If BOOL is non-nil, strings given to the
3060 process filter are multibyte, otherwise they are unibyte.
3061 If this keyword is not specified, the strings are multibyte if
3062 `default-enable-multibyte-characters' is non-nil.
3064 :sentinel SENTINEL -- Install SENTINEL as the process sentinel.
3066 :log LOG -- Install LOG as the server process log function. This
3067 function is called when the server accepts a network connection from a
3068 client. The arguments are SERVER, CLIENT, and MESSAGE, where SERVER
3069 is the server process, CLIENT is the new process for the connection,
3070 and MESSAGE is a string.
3072 :plist PLIST -- Install PLIST as the new process' initial plist.
3074 :server QLEN -- if QLEN is non-nil, create a server process for the
3075 specified FAMILY, SERVICE, and connection type (stream or datagram).
3076 If QLEN is an integer, it is used as the max. length of the server's
3077 pending connection queue (also known as the backlog); the default
3078 queue length is 5. Default is to create a client process.
3080 The following network options can be specified for this connection:
3082 :broadcast BOOL -- Allow send and receive of datagram broadcasts.
3083 :dontroute BOOL -- Only send to directly connected hosts.
3084 :keepalive BOOL -- Send keep-alive messages on network stream.
3085 :linger BOOL or TIMEOUT -- Send queued messages before closing.
3086 :oobinline BOOL -- Place out-of-band data in receive data stream.
3087 :priority INT -- Set protocol defined priority for sent packets.
3088 :reuseaddr BOOL -- Allow reusing a recently used local address
3089 (this is allowed by default for a server process).
3090 :bindtodevice NAME -- bind to interface NAME. Using this may require
3091 special privileges on some systems.
3093 Consult the relevant system programmer's manual pages for more
3094 information on using these options.
3097 A server process will listen for and accept connections from clients.
3098 When a client connection is accepted, a new network process is created
3099 for the connection with the following parameters:
3101 - The client's process name is constructed by concatenating the server
3102 process' NAME and a client identification string.
3103 - If the FILTER argument is non-nil, the client process will not get a
3104 separate process buffer; otherwise, the client's process buffer is a newly
3105 created buffer named after the server process' BUFFER name or process
3106 NAME concatenated with the client identification string.
3107 - The connection type and the process filter and sentinel parameters are
3108 inherited from the server process' TYPE, FILTER and SENTINEL.
3109 - The client process' contact info is set according to the client's
3110 addressing information (typically an IP address and a port number).
3111 - The client process' plist is initialized from the server's plist.
3113 Notice that the FILTER and SENTINEL args are never used directly by
3114 the server process. Also, the BUFFER argument is not used directly by
3115 the server process, but via the optional :log function, accepted (and
3116 failed) connections may be logged in the server process' buffer.
3118 The original argument list, modified with the actual connection
3119 information, is available via the `process-contact' function.
3121 usage: (make-network-process &rest ARGS) */)
3127 Lisp_Object contact
;
3128 struct Lisp_Process
*p
;
3129 #ifdef HAVE_GETADDRINFO
3130 struct addrinfo ai
, *res
, *lres
;
3131 struct addrinfo hints
;
3132 char *portstring
, portbuf
[128];
3133 #else /* HAVE_GETADDRINFO */
3134 struct _emacs_addrinfo
3140 struct sockaddr
*ai_addr
;
3141 struct _emacs_addrinfo
*ai_next
;
3143 #endif /* HAVE_GETADDRINFO */
3144 struct sockaddr_in address_in
;
3145 #ifdef HAVE_LOCAL_SOCKETS
3146 struct sockaddr_un address_un
;
3151 int s
= -1, outch
, inch
;
3152 struct gcpro gcpro1
;
3153 int count
= SPECPDL_INDEX ();
3155 Lisp_Object QCaddress
; /* one of QClocal or QCremote */
3157 Lisp_Object name
, buffer
, host
, service
, address
;
3158 Lisp_Object filter
, sentinel
;
3159 int is_non_blocking_client
= 0;
3160 int is_server
= 0, backlog
= 5;
3167 /* Save arguments for process-contact and clone-process. */
3168 contact
= Flist (nargs
, args
);
3172 /* Ensure socket support is loaded if available. */
3173 init_winsock (TRUE
);
3176 /* :type TYPE (nil: stream, datagram */
3177 tem
= Fplist_get (contact
, QCtype
);
3179 socktype
= SOCK_STREAM
;
3180 #ifdef DATAGRAM_SOCKETS
3181 else if (EQ (tem
, Qdatagram
))
3182 socktype
= SOCK_DGRAM
;
3185 error ("Unsupported connection type");
3188 tem
= Fplist_get (contact
, QCserver
);
3191 /* Don't support network sockets when non-blocking mode is
3192 not available, since a blocked Emacs is not useful. */
3193 #if !defined(O_NONBLOCK) && !defined(O_NDELAY)
3194 error ("Network servers not supported");
3198 backlog
= XINT (tem
);
3202 /* Make QCaddress an alias for :local (server) or :remote (client). */
3203 QCaddress
= is_server
? QClocal
: QCremote
;
3206 if (!is_server
&& socktype
== SOCK_STREAM
3207 && (tem
= Fplist_get (contact
, QCnowait
), !NILP (tem
)))
3209 #ifndef NON_BLOCKING_CONNECT
3210 error ("Non-blocking connect not supported");
3212 is_non_blocking_client
= 1;
3216 name
= Fplist_get (contact
, QCname
);
3217 buffer
= Fplist_get (contact
, QCbuffer
);
3218 filter
= Fplist_get (contact
, QCfilter
);
3219 sentinel
= Fplist_get (contact
, QCsentinel
);
3221 CHECK_STRING (name
);
3223 /* Initialize addrinfo structure in case we don't use getaddrinfo. */
3224 ai
.ai_socktype
= socktype
;
3229 /* :local ADDRESS or :remote ADDRESS */
3230 address
= Fplist_get (contact
, QCaddress
);
3231 if (!NILP (address
))
3233 host
= service
= Qnil
;
3235 if (!(ai
.ai_addrlen
= get_lisp_to_sockaddr_size (address
, &family
)))
3236 error ("Malformed :address");
3237 ai
.ai_family
= family
;
3238 ai
.ai_addr
= alloca (ai
.ai_addrlen
);
3239 conv_lisp_to_sockaddr (family
, address
, ai
.ai_addr
, ai
.ai_addrlen
);
3243 /* :family FAMILY -- nil (for Inet), local, or integer. */
3244 tem
= Fplist_get (contact
, QCfamily
);
3247 #if defined(HAVE_GETADDRINFO) && defined(AF_INET6)
3253 #ifdef HAVE_LOCAL_SOCKETS
3254 else if (EQ (tem
, Qlocal
))
3258 else if (EQ (tem
, Qipv6
))
3261 else if (EQ (tem
, Qipv4
))
3263 else if (INTEGERP (tem
))
3264 family
= XINT (tem
);
3266 error ("Unknown address family");
3268 ai
.ai_family
= family
;
3270 /* :service SERVICE -- string, integer (port number), or t (random port). */
3271 service
= Fplist_get (contact
, QCservice
);
3273 #ifdef HAVE_LOCAL_SOCKETS
3274 if (family
== AF_LOCAL
)
3276 /* Host is not used. */
3278 CHECK_STRING (service
);
3279 bzero (&address_un
, sizeof address_un
);
3280 address_un
.sun_family
= AF_LOCAL
;
3281 strncpy (address_un
.sun_path
, SDATA (service
), sizeof address_un
.sun_path
);
3282 ai
.ai_addr
= (struct sockaddr
*) &address_un
;
3283 ai
.ai_addrlen
= sizeof address_un
;
3288 /* :host HOST -- hostname, ip address, or 'local for localhost. */
3289 host
= Fplist_get (contact
, QChost
);
3292 if (EQ (host
, Qlocal
))
3293 host
= build_string ("localhost");
3294 CHECK_STRING (host
);
3297 /* Slow down polling to every ten seconds.
3298 Some kernels have a bug which causes retrying connect to fail
3299 after a connect. Polling can interfere with gethostbyname too. */
3300 #ifdef POLL_FOR_INPUT
3301 if (socktype
== SOCK_STREAM
)
3303 record_unwind_protect (unwind_stop_other_atimers
, Qnil
);
3304 bind_polling_period (10);
3308 #ifdef HAVE_GETADDRINFO
3309 /* If we have a host, use getaddrinfo to resolve both host and service.
3310 Otherwise, use getservbyname to lookup the service. */
3314 /* SERVICE can either be a string or int.
3315 Convert to a C string for later use by getaddrinfo. */
3316 if (EQ (service
, Qt
))
3318 else if (INTEGERP (service
))
3320 sprintf (portbuf
, "%ld", (long) XINT (service
));
3321 portstring
= portbuf
;
3325 CHECK_STRING (service
);
3326 portstring
= SDATA (service
);
3331 memset (&hints
, 0, sizeof (hints
));
3333 hints
.ai_family
= family
;
3334 hints
.ai_socktype
= socktype
;
3335 hints
.ai_protocol
= 0;
3337 #ifdef HAVE_RES_INIT
3341 ret
= getaddrinfo (SDATA (host
), portstring
, &hints
, &res
);
3343 #ifdef HAVE_GAI_STRERROR
3344 error ("%s/%s %s", SDATA (host
), portstring
, gai_strerror(ret
));
3346 error ("%s/%s getaddrinfo error %d", SDATA (host
), portstring
, ret
);
3352 #endif /* HAVE_GETADDRINFO */
3354 /* We end up here if getaddrinfo is not defined, or in case no hostname
3355 has been specified (e.g. for a local server process). */
3357 if (EQ (service
, Qt
))
3359 else if (INTEGERP (service
))
3360 port
= htons ((unsigned short) XINT (service
));
3363 struct servent
*svc_info
;
3364 CHECK_STRING (service
);
3365 svc_info
= getservbyname (SDATA (service
),
3366 (socktype
== SOCK_DGRAM
? "udp" : "tcp"));
3368 error ("Unknown service: %s", SDATA (service
));
3369 port
= svc_info
->s_port
;
3372 bzero (&address_in
, sizeof address_in
);
3373 address_in
.sin_family
= family
;
3374 address_in
.sin_addr
.s_addr
= INADDR_ANY
;
3375 address_in
.sin_port
= port
;
3377 #ifndef HAVE_GETADDRINFO
3380 struct hostent
*host_info_ptr
;
3382 /* gethostbyname may fail with TRY_AGAIN, but we don't honour that,
3383 as it may `hang' Emacs for a very long time. */
3387 #ifdef HAVE_RES_INIT
3391 host_info_ptr
= gethostbyname (SDATA (host
));
3396 bcopy (host_info_ptr
->h_addr
, (char *) &address_in
.sin_addr
,
3397 host_info_ptr
->h_length
);
3398 family
= host_info_ptr
->h_addrtype
;
3399 address_in
.sin_family
= family
;
3402 /* Attempt to interpret host as numeric inet address */
3404 unsigned long numeric_addr
;
3405 numeric_addr
= inet_addr ((char *) SDATA (host
));
3406 if (numeric_addr
== -1)
3407 error ("Unknown host \"%s\"", SDATA (host
));
3409 bcopy ((char *)&numeric_addr
, (char *) &address_in
.sin_addr
,
3410 sizeof (address_in
.sin_addr
));
3414 #endif /* not HAVE_GETADDRINFO */
3416 ai
.ai_family
= family
;
3417 ai
.ai_addr
= (struct sockaddr
*) &address_in
;
3418 ai
.ai_addrlen
= sizeof address_in
;
3422 /* Do this in case we never enter the for-loop below. */
3423 count1
= SPECPDL_INDEX ();
3426 for (lres
= res
; lres
; lres
= lres
->ai_next
)
3432 s
= socket (lres
->ai_family
, lres
->ai_socktype
, lres
->ai_protocol
);
3439 #ifdef DATAGRAM_SOCKETS
3440 if (!is_server
&& socktype
== SOCK_DGRAM
)
3442 #endif /* DATAGRAM_SOCKETS */
3444 #ifdef NON_BLOCKING_CONNECT
3445 if (is_non_blocking_client
)
3448 ret
= fcntl (s
, F_SETFL
, O_NONBLOCK
);
3450 ret
= fcntl (s
, F_SETFL
, O_NDELAY
);
3462 /* Make us close S if quit. */
3463 record_unwind_protect (close_file_unwind
, make_number (s
));
3465 /* Parse network options in the arg list.
3466 We simply ignore anything which isn't a known option (including other keywords).
3467 An error is signaled if setting a known option fails. */
3468 for (optn
= optbits
= 0; optn
< nargs
-1; optn
+= 2)
3469 optbits
|= set_socket_option (s
, args
[optn
], args
[optn
+1]);
3473 /* Configure as a server socket. */
3475 /* SO_REUSEADDR = 1 is default for server sockets; must specify
3476 explicit :reuseaddr key to override this. */
3477 #ifdef HAVE_LOCAL_SOCKETS
3478 if (family
!= AF_LOCAL
)
3480 if (!(optbits
& (1 << OPIX_REUSEADDR
)))
3483 if (setsockopt (s
, SOL_SOCKET
, SO_REUSEADDR
, &optval
, sizeof optval
))
3484 report_file_error ("Cannot set reuse option on server socket", Qnil
);
3487 if (bind (s
, lres
->ai_addr
, lres
->ai_addrlen
))
3488 report_file_error ("Cannot bind server socket", Qnil
);
3490 #ifdef HAVE_GETSOCKNAME
3491 if (EQ (service
, Qt
))
3493 struct sockaddr_in sa1
;
3494 int len1
= sizeof (sa1
);
3495 if (getsockname (s
, (struct sockaddr
*)&sa1
, &len1
) == 0)
3497 ((struct sockaddr_in
*)(lres
->ai_addr
))->sin_port
= sa1
.sin_port
;
3498 service
= make_number (ntohs (sa1
.sin_port
));
3499 contact
= Fplist_put (contact
, QCservice
, service
);
3504 if (socktype
== SOCK_STREAM
&& listen (s
, backlog
))
3505 report_file_error ("Cannot listen on server socket", Qnil
);
3513 /* This turns off all alarm-based interrupts; the
3514 bind_polling_period call above doesn't always turn all the
3515 short-interval ones off, especially if interrupt_input is
3518 It'd be nice to be able to control the connect timeout
3519 though. Would non-blocking connect calls be portable?
3521 This used to be conditioned by HAVE_GETADDRINFO. Why? */
3523 turn_on_atimers (0);
3525 ret
= connect (s
, lres
->ai_addr
, lres
->ai_addrlen
);
3528 turn_on_atimers (1);
3530 if (ret
== 0 || xerrno
== EISCONN
)
3532 /* The unwind-protect will be discarded afterwards.
3533 Likewise for immediate_quit. */
3537 #ifdef NON_BLOCKING_CONNECT
3539 if (is_non_blocking_client
&& xerrno
== EINPROGRESS
)
3543 if (is_non_blocking_client
&& xerrno
== EWOULDBLOCK
)
3551 /* Discard the unwind protect closing S. */
3552 specpdl_ptr
= specpdl
+ count1
;
3556 if (xerrno
== EINTR
)
3562 #ifdef DATAGRAM_SOCKETS
3563 if (socktype
== SOCK_DGRAM
)
3565 if (datagram_address
[s
].sa
)
3567 datagram_address
[s
].sa
= (struct sockaddr
*) xmalloc (lres
->ai_addrlen
);
3568 datagram_address
[s
].len
= lres
->ai_addrlen
;
3572 bzero (datagram_address
[s
].sa
, lres
->ai_addrlen
);
3573 if (remote
= Fplist_get (contact
, QCremote
), !NILP (remote
))
3576 rlen
= get_lisp_to_sockaddr_size (remote
, &rfamily
);
3577 if (rfamily
== lres
->ai_family
&& rlen
== lres
->ai_addrlen
)
3578 conv_lisp_to_sockaddr (rfamily
, remote
,
3579 datagram_address
[s
].sa
, rlen
);
3583 bcopy (lres
->ai_addr
, datagram_address
[s
].sa
, lres
->ai_addrlen
);
3586 contact
= Fplist_put (contact
, QCaddress
,
3587 conv_sockaddr_to_lisp (lres
->ai_addr
, lres
->ai_addrlen
));
3588 #ifdef HAVE_GETSOCKNAME
3591 struct sockaddr_in sa1
;
3592 int len1
= sizeof (sa1
);
3593 if (getsockname (s
, (struct sockaddr
*)&sa1
, &len1
) == 0)
3594 contact
= Fplist_put (contact
, QClocal
,
3595 conv_sockaddr_to_lisp (&sa1
, len1
));
3602 #ifdef HAVE_GETADDRINFO
3611 /* Discard the unwind protect for closing S, if any. */
3612 specpdl_ptr
= specpdl
+ count1
;
3614 /* Unwind bind_polling_period and request_sigio. */
3615 unbind_to (count
, Qnil
);
3619 /* If non-blocking got this far - and failed - assume non-blocking is
3620 not supported after all. This is probably a wrong assumption, but
3621 the normal blocking calls to open-network-stream handles this error
3623 if (is_non_blocking_client
)
3628 report_file_error ("make server process failed", contact
);
3630 report_file_error ("make client process failed", contact
);
3637 buffer
= Fget_buffer_create (buffer
);
3638 proc
= make_process (name
);
3640 chan_process
[inch
] = proc
;
3643 fcntl (inch
, F_SETFL
, O_NONBLOCK
);
3646 fcntl (inch
, F_SETFL
, O_NDELAY
);
3650 p
= XPROCESS (proc
);
3652 p
->childp
= contact
;
3653 p
->plist
= Fcopy_sequence (Fplist_get (contact
, QCplist
));
3657 p
->sentinel
= sentinel
;
3659 p
->log
= Fplist_get (contact
, QClog
);
3660 if (tem
= Fplist_get (contact
, QCnoquery
), !NILP (tem
))
3661 p
->kill_without_query
= 1;
3662 if ((tem
= Fplist_get (contact
, QCstop
), !NILP (tem
)))
3667 if (is_server
&& socktype
== SOCK_STREAM
)
3668 p
->status
= Qlisten
;
3670 /* Make the process marker point into the process buffer (if any). */
3671 if (BUFFERP (buffer
))
3672 set_marker_both (p
->mark
, buffer
,
3673 BUF_ZV (XBUFFER (buffer
)),
3674 BUF_ZV_BYTE (XBUFFER (buffer
)));
3676 #ifdef NON_BLOCKING_CONNECT
3677 if (is_non_blocking_client
)
3679 /* We may get here if connect did succeed immediately. However,
3680 in that case, we still need to signal this like a non-blocking
3682 p
->status
= Qconnect
;
3683 if (!FD_ISSET (inch
, &connect_wait_mask
))
3685 FD_SET (inch
, &connect_wait_mask
);
3686 num_pending_connects
++;
3691 /* A server may have a client filter setting of Qt, but it must
3692 still listen for incoming connects unless it is stopped. */
3693 if ((!EQ (p
->filter
, Qt
) && !EQ (p
->command
, Qt
))
3694 || (EQ (p
->status
, Qlisten
) && NILP (p
->command
)))
3696 FD_SET (inch
, &input_wait_mask
);
3697 FD_SET (inch
, &non_keyboard_wait_mask
);
3700 if (inch
> max_process_desc
)
3701 max_process_desc
= inch
;
3703 tem
= Fplist_member (contact
, QCcoding
);
3704 if (!NILP (tem
) && (!CONSP (tem
) || !CONSP (XCDR (tem
))))
3705 tem
= Qnil
; /* No error message (too late!). */
3708 /* Setup coding systems for communicating with the network stream. */
3709 struct gcpro gcpro1
;
3710 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
3711 Lisp_Object coding_systems
= Qt
;
3712 Lisp_Object args
[5], val
;
3716 val
= XCAR (XCDR (tem
));
3720 else if (!NILP (Vcoding_system_for_read
))
3721 val
= Vcoding_system_for_read
;
3722 else if ((!NILP (buffer
) && NILP (XBUFFER (buffer
)->enable_multibyte_characters
))
3723 || (NILP (buffer
) && NILP (buffer_defaults
.enable_multibyte_characters
)))
3724 /* We dare not decode end-of-line format by setting VAL to
3725 Qraw_text, because the existing Emacs Lisp libraries
3726 assume that they receive bare code including a sequene of
3731 if (NILP (host
) || NILP (service
))
3732 coding_systems
= Qnil
;
3735 args
[0] = Qopen_network_stream
, args
[1] = name
,
3736 args
[2] = buffer
, args
[3] = host
, args
[4] = service
;
3738 coding_systems
= Ffind_operation_coding_system (5, args
);
3741 if (CONSP (coding_systems
))
3742 val
= XCAR (coding_systems
);
3743 else if (CONSP (Vdefault_process_coding_system
))
3744 val
= XCAR (Vdefault_process_coding_system
);
3748 p
->decode_coding_system
= val
;
3752 val
= XCAR (XCDR (tem
));
3756 else if (!NILP (Vcoding_system_for_write
))
3757 val
= Vcoding_system_for_write
;
3758 else if (NILP (current_buffer
->enable_multibyte_characters
))
3762 if (EQ (coding_systems
, Qt
))
3764 if (NILP (host
) || NILP (service
))
3765 coding_systems
= Qnil
;
3768 args
[0] = Qopen_network_stream
, args
[1] = name
,
3769 args
[2] = buffer
, args
[3] = host
, args
[4] = service
;
3771 coding_systems
= Ffind_operation_coding_system (5, args
);
3775 if (CONSP (coding_systems
))
3776 val
= XCDR (coding_systems
);
3777 else if (CONSP (Vdefault_process_coding_system
))
3778 val
= XCDR (Vdefault_process_coding_system
);
3782 p
->encode_coding_system
= val
;
3784 setup_process_coding_systems (proc
);
3786 p
->decoding_buf
= make_uninit_string (0);
3787 p
->decoding_carryover
= 0;
3788 p
->encoding_buf
= make_uninit_string (0);
3790 p
->inherit_coding_system_flag
3791 = !(!NILP (tem
) || NILP (buffer
) || !inherit_process_coding_system
);
3796 #endif /* HAVE_SOCKETS */
3799 #if defined(HAVE_SOCKETS) && defined(HAVE_NET_IF_H) && defined(HAVE_SYS_IOCTL_H)
3802 DEFUN ("network-interface-list", Fnetwork_interface_list
, Snetwork_interface_list
, 0, 0, 0,
3803 doc
: /* Return an alist of all network interfaces and their network address.
3804 Each element is a cons, the car of which is a string containing the
3805 interface name, and the cdr is the network address in internal
3806 format; see the description of ADDRESS in `make-network-process'. */)
3809 struct ifconf ifconf
;
3810 struct ifreq
*ifreqs
= NULL
;
3815 s
= socket (AF_INET
, SOCK_STREAM
, 0);
3821 buf_size
= ifaces
* sizeof(ifreqs
[0]);
3822 ifreqs
= (struct ifreq
*)xrealloc(ifreqs
, buf_size
);
3829 ifconf
.ifc_len
= buf_size
;
3830 ifconf
.ifc_req
= ifreqs
;
3831 if (ioctl (s
, SIOCGIFCONF
, &ifconf
))
3837 if (ifconf
.ifc_len
== buf_size
)
3841 ifaces
= ifconf
.ifc_len
/ sizeof (ifreqs
[0]);
3844 while (--ifaces
>= 0)
3846 struct ifreq
*ifq
= &ifreqs
[ifaces
];
3847 char namebuf
[sizeof (ifq
->ifr_name
) + 1];
3848 if (ifq
->ifr_addr
.sa_family
!= AF_INET
)
3850 bcopy (ifq
->ifr_name
, namebuf
, sizeof (ifq
->ifr_name
));
3851 namebuf
[sizeof (ifq
->ifr_name
)] = 0;
3852 res
= Fcons (Fcons (build_string (namebuf
),
3853 conv_sockaddr_to_lisp (&ifq
->ifr_addr
,
3854 sizeof (struct sockaddr
))),
3860 #endif /* SIOCGIFCONF */
3862 #if defined(SIOCGIFADDR) || defined(SIOCGIFHWADDR) || defined(SIOCGIFFLAGS)
3869 static struct ifflag_def ifflag_table
[] = {
3873 #ifdef IFF_BROADCAST
3874 { IFF_BROADCAST
, "broadcast" },
3877 { IFF_DEBUG
, "debug" },
3880 { IFF_LOOPBACK
, "loopback" },
3882 #ifdef IFF_POINTOPOINT
3883 { IFF_POINTOPOINT
, "pointopoint" },
3886 { IFF_RUNNING
, "running" },
3889 { IFF_NOARP
, "noarp" },
3892 { IFF_PROMISC
, "promisc" },
3894 #ifdef IFF_NOTRAILERS
3895 { IFF_NOTRAILERS
, "notrailers" },
3898 { IFF_ALLMULTI
, "allmulti" },
3901 { IFF_MASTER
, "master" },
3904 { IFF_SLAVE
, "slave" },
3906 #ifdef IFF_MULTICAST
3907 { IFF_MULTICAST
, "multicast" },
3910 { IFF_PORTSEL
, "portsel" },
3912 #ifdef IFF_AUTOMEDIA
3913 { IFF_AUTOMEDIA
, "automedia" },
3916 { IFF_DYNAMIC
, "dynamic" },
3919 { IFF_OACTIVE
, "oactive" }, /* OpenBSD: transmission in progress */
3922 { IFF_SIMPLEX
, "simplex" }, /* OpenBSD: can't hear own transmissions */
3925 { IFF_LINK0
, "link0" }, /* OpenBSD: per link layer defined bit */
3928 { IFF_LINK1
, "link1" }, /* OpenBSD: per link layer defined bit */
3931 { IFF_LINK2
, "link2" }, /* OpenBSD: per link layer defined bit */
3936 DEFUN ("network-interface-info", Fnetwork_interface_info
, Snetwork_interface_info
, 1, 1, 0,
3937 doc
: /* Return information about network interface named IFNAME.
3938 The return value is a list (ADDR BCAST NETMASK HWADDR FLAGS),
3939 where ADDR is the layer 3 address, BCAST is the layer 3 broadcast address,
3940 NETMASK is the layer 3 network mask, HWADDR is the layer 2 addres, and
3941 FLAGS is the current flags of the interface. */)
3946 Lisp_Object res
= Qnil
;
3951 CHECK_STRING (ifname
);
3953 bzero (rq
.ifr_name
, sizeof rq
.ifr_name
);
3954 strncpy (rq
.ifr_name
, SDATA (ifname
), sizeof (rq
.ifr_name
));
3956 s
= socket (AF_INET
, SOCK_STREAM
, 0);
3961 #if defined(SIOCGIFFLAGS) && defined(HAVE_STRUCT_IFREQ_IFR_FLAGS)
3962 if (ioctl (s
, SIOCGIFFLAGS
, &rq
) == 0)
3964 int flags
= rq
.ifr_flags
;
3965 struct ifflag_def
*fp
;
3969 for (fp
= ifflag_table
; flags
!= 0 && fp
->flag_sym
; fp
++)
3971 if (flags
& fp
->flag_bit
)
3973 elt
= Fcons (intern (fp
->flag_sym
), elt
);
3974 flags
-= fp
->flag_bit
;
3977 for (fnum
= 0; flags
&& fnum
< 32; fnum
++)
3979 if (flags
& (1 << fnum
))
3981 elt
= Fcons (make_number (fnum
), elt
);
3986 res
= Fcons (elt
, res
);
3989 #if defined(SIOCGIFHWADDR) && defined(HAVE_STRUCT_IFREQ_IFR_HWADDR)
3990 if (ioctl (s
, SIOCGIFHWADDR
, &rq
) == 0)
3992 Lisp_Object hwaddr
= Fmake_vector (make_number (6), Qnil
);
3993 register struct Lisp_Vector
*p
= XVECTOR (hwaddr
);
3997 for (n
= 0; n
< 6; n
++)
3998 p
->contents
[n
] = make_number (((unsigned char *)&rq
.ifr_hwaddr
.sa_data
[0])[n
]);
3999 elt
= Fcons (make_number (rq
.ifr_hwaddr
.sa_family
), hwaddr
);
4002 res
= Fcons (elt
, res
);
4005 #if defined(SIOCGIFNETMASK) && (defined(HAVE_STRUCT_IFREQ_IFR_NETMASK) || defined(HAVE_STRUCT_IFREQ_IFR_ADDR))
4006 if (ioctl (s
, SIOCGIFNETMASK
, &rq
) == 0)
4009 #ifdef HAVE_STRUCT_IFREQ_IFR_NETMASK
4010 elt
= conv_sockaddr_to_lisp (&rq
.ifr_netmask
, sizeof (rq
.ifr_netmask
));
4012 elt
= conv_sockaddr_to_lisp (&rq
.ifr_addr
, sizeof (rq
.ifr_addr
));
4016 res
= Fcons (elt
, res
);
4019 #if defined(SIOCGIFBRDADDR) && defined(HAVE_STRUCT_IFREQ_IFR_BROADADDR)
4020 if (ioctl (s
, SIOCGIFBRDADDR
, &rq
) == 0)
4023 elt
= conv_sockaddr_to_lisp (&rq
.ifr_broadaddr
, sizeof (rq
.ifr_broadaddr
));
4026 res
= Fcons (elt
, res
);
4029 #if defined(SIOCGIFADDR) && defined(HAVE_STRUCT_IFREQ_IFR_ADDR)
4030 if (ioctl (s
, SIOCGIFADDR
, &rq
) == 0)
4033 elt
= conv_sockaddr_to_lisp (&rq
.ifr_addr
, sizeof (rq
.ifr_addr
));
4036 res
= Fcons (elt
, res
);
4040 return any
? res
: Qnil
;
4043 #endif /* HAVE_SOCKETS */
4045 /* Turn off input and output for process PROC. */
4048 deactivate_process (proc
)
4051 register int inchannel
, outchannel
;
4052 register struct Lisp_Process
*p
= XPROCESS (proc
);
4054 inchannel
= p
->infd
;
4055 outchannel
= p
->outfd
;
4057 #ifdef ADAPTIVE_READ_BUFFERING
4058 if (p
->read_output_delay
> 0)
4060 if (--process_output_delay_count
< 0)
4061 process_output_delay_count
= 0;
4062 p
->read_output_delay
= 0;
4063 p
->read_output_skip
= 0;
4069 /* Beware SIGCHLD hereabouts. */
4070 flush_pending_output (inchannel
);
4071 emacs_close (inchannel
);
4072 if (outchannel
>= 0 && outchannel
!= inchannel
)
4073 emacs_close (outchannel
);
4077 #ifdef DATAGRAM_SOCKETS
4078 if (DATAGRAM_CHAN_P (inchannel
))
4080 xfree (datagram_address
[inchannel
].sa
);
4081 datagram_address
[inchannel
].sa
= 0;
4082 datagram_address
[inchannel
].len
= 0;
4085 chan_process
[inchannel
] = Qnil
;
4086 FD_CLR (inchannel
, &input_wait_mask
);
4087 FD_CLR (inchannel
, &non_keyboard_wait_mask
);
4088 #ifdef NON_BLOCKING_CONNECT
4089 if (FD_ISSET (inchannel
, &connect_wait_mask
))
4091 FD_CLR (inchannel
, &connect_wait_mask
);
4092 if (--num_pending_connects
< 0)
4096 if (inchannel
== max_process_desc
)
4099 /* We just closed the highest-numbered process input descriptor,
4100 so recompute the highest-numbered one now. */
4101 max_process_desc
= 0;
4102 for (i
= 0; i
< MAXDESC
; i
++)
4103 if (!NILP (chan_process
[i
]))
4104 max_process_desc
= i
;
4109 /* Close all descriptors currently in use for communication
4110 with subprocess. This is used in a newly-forked subprocess
4111 to get rid of irrelevant descriptors. */
4114 close_process_descs ()
4118 for (i
= 0; i
< MAXDESC
; i
++)
4120 Lisp_Object process
;
4121 process
= chan_process
[i
];
4122 if (!NILP (process
))
4124 int in
= XPROCESS (process
)->infd
;
4125 int out
= XPROCESS (process
)->outfd
;
4128 if (out
>= 0 && in
!= out
)
4135 DEFUN ("accept-process-output", Faccept_process_output
, Saccept_process_output
,
4137 doc
: /* Allow any pending output from subprocesses to be read by Emacs.
4138 It is read into the process' buffers or given to their filter functions.
4139 Non-nil arg PROCESS means do not return until some output has been received
4142 Non-nil second arg SECONDS and third arg MILLISEC are number of seconds
4143 and milliseconds to wait; return after that much time whether or not
4144 there is any subprocess output. If SECONDS is a floating point number,
4145 it specifies a fractional number of seconds to wait.
4146 The MILLISEC argument is obsolete and should be avoided.
4148 If optional fourth arg JUST-THIS-ONE is non-nil, only accept output
4149 from PROCESS, suspending reading output from other processes.
4150 If JUST-THIS-ONE is an integer, don't run any timers either.
4151 Return non-nil if we received any output before the timeout expired. */)
4152 (process
, seconds
, millisec
, just_this_one
)
4153 register Lisp_Object process
, seconds
, millisec
, just_this_one
;
4155 int secs
, usecs
= 0;
4157 if (! NILP (process
))
4158 CHECK_PROCESS (process
);
4160 just_this_one
= Qnil
;
4162 if (!NILP (millisec
))
4163 { /* Obsolete calling convention using integers rather than floats. */
4164 CHECK_NUMBER (millisec
);
4166 seconds
= make_float (XINT (millisec
) / 1000.0);
4169 CHECK_NUMBER (seconds
);
4170 seconds
= make_float (XINT (millisec
) / 1000.0 + XINT (seconds
));
4174 if (!NILP (seconds
))
4176 if (INTEGERP (seconds
))
4177 secs
= XINT (seconds
);
4178 else if (FLOATP (seconds
))
4180 double timeout
= XFLOAT_DATA (seconds
);
4181 secs
= (int) timeout
;
4182 usecs
= (int) ((timeout
- (double) secs
) * 1000000);
4185 wrong_type_argument (Qnumberp
, seconds
);
4187 if (secs
< 0 || (secs
== 0 && usecs
== 0))
4188 secs
= -1, usecs
= 0;
4191 secs
= NILP (process
) ? -1 : 0;
4194 (wait_reading_process_output (secs
, usecs
, 0, 0,
4196 !NILP (process
) ? XPROCESS (process
) : NULL
,
4197 NILP (just_this_one
) ? 0 :
4198 !INTEGERP (just_this_one
) ? 1 : -1)
4202 /* Accept a connection for server process SERVER on CHANNEL. */
4204 static int connect_counter
= 0;
4207 server_accept_connection (server
, channel
)
4211 Lisp_Object proc
, caller
, name
, buffer
;
4212 Lisp_Object contact
, host
, service
;
4213 struct Lisp_Process
*ps
= XPROCESS (server
);
4214 struct Lisp_Process
*p
;
4218 struct sockaddr_in in
;
4220 struct sockaddr_in6 in6
;
4222 #ifdef HAVE_LOCAL_SOCKETS
4223 struct sockaddr_un un
;
4226 int len
= sizeof saddr
;
4228 s
= accept (channel
, &saddr
.sa
, &len
);
4237 if (code
== EWOULDBLOCK
)
4241 if (!NILP (ps
->log
))
4242 call3 (ps
->log
, server
, Qnil
,
4243 concat3 (build_string ("accept failed with code"),
4244 Fnumber_to_string (make_number (code
)),
4245 build_string ("\n")));
4251 /* Setup a new process to handle the connection. */
4253 /* Generate a unique identification of the caller, and build contact
4254 information for this process. */
4257 switch (saddr
.sa
.sa_family
)
4261 Lisp_Object args
[5];
4262 unsigned char *ip
= (unsigned char *)&saddr
.in
.sin_addr
.s_addr
;
4263 args
[0] = build_string ("%d.%d.%d.%d");
4264 args
[1] = make_number (*ip
++);
4265 args
[2] = make_number (*ip
++);
4266 args
[3] = make_number (*ip
++);
4267 args
[4] = make_number (*ip
++);
4268 host
= Fformat (5, args
);
4269 service
= make_number (ntohs (saddr
.in
.sin_port
));
4271 args
[0] = build_string (" <%s:%d>");
4274 caller
= Fformat (3, args
);
4281 Lisp_Object args
[9];
4282 uint16_t *ip6
= (uint16_t *)&saddr
.in6
.sin6_addr
;
4284 args
[0] = build_string ("%x:%x:%x:%x:%x:%x:%x:%x");
4285 for (i
= 0; i
< 8; i
++)
4286 args
[i
+1] = make_number (ntohs(ip6
[i
]));
4287 host
= Fformat (9, args
);
4288 service
= make_number (ntohs (saddr
.in
.sin_port
));
4290 args
[0] = build_string (" <[%s]:%d>");
4293 caller
= Fformat (3, args
);
4298 #ifdef HAVE_LOCAL_SOCKETS
4302 caller
= Fnumber_to_string (make_number (connect_counter
));
4303 caller
= concat3 (build_string (" <"), caller
, build_string (">"));
4307 /* Create a new buffer name for this process if it doesn't have a
4308 filter. The new buffer name is based on the buffer name or
4309 process name of the server process concatenated with the caller
4312 if (!NILP (ps
->filter
) && !EQ (ps
->filter
, Qt
))
4316 buffer
= ps
->buffer
;
4318 buffer
= Fbuffer_name (buffer
);
4323 buffer
= concat2 (buffer
, caller
);
4324 buffer
= Fget_buffer_create (buffer
);
4328 /* Generate a unique name for the new server process. Combine the
4329 server process name with the caller identification. */
4331 name
= concat2 (ps
->name
, caller
);
4332 proc
= make_process (name
);
4334 chan_process
[s
] = proc
;
4337 fcntl (s
, F_SETFL
, O_NONBLOCK
);
4340 fcntl (s
, F_SETFL
, O_NDELAY
);
4344 p
= XPROCESS (proc
);
4346 /* Build new contact information for this setup. */
4347 contact
= Fcopy_sequence (ps
->childp
);
4348 contact
= Fplist_put (contact
, QCserver
, Qnil
);
4349 contact
= Fplist_put (contact
, QChost
, host
);
4350 if (!NILP (service
))
4351 contact
= Fplist_put (contact
, QCservice
, service
);
4352 contact
= Fplist_put (contact
, QCremote
,
4353 conv_sockaddr_to_lisp (&saddr
.sa
, len
));
4354 #ifdef HAVE_GETSOCKNAME
4356 if (getsockname (s
, &saddr
.sa
, &len
) == 0)
4357 contact
= Fplist_put (contact
, QClocal
,
4358 conv_sockaddr_to_lisp (&saddr
.sa
, len
));
4361 p
->childp
= contact
;
4362 p
->plist
= Fcopy_sequence (ps
->plist
);
4366 p
->sentinel
= ps
->sentinel
;
4367 p
->filter
= ps
->filter
;
4374 /* Client processes for accepted connections are not stopped initially. */
4375 if (!EQ (p
->filter
, Qt
))
4377 FD_SET (s
, &input_wait_mask
);
4378 FD_SET (s
, &non_keyboard_wait_mask
);
4381 if (s
> max_process_desc
)
4382 max_process_desc
= s
;
4384 /* Setup coding system for new process based on server process.
4385 This seems to be the proper thing to do, as the coding system
4386 of the new process should reflect the settings at the time the
4387 server socket was opened; not the current settings. */
4389 p
->decode_coding_system
= ps
->decode_coding_system
;
4390 p
->encode_coding_system
= ps
->encode_coding_system
;
4391 setup_process_coding_systems (proc
);
4393 p
->decoding_buf
= make_uninit_string (0);
4394 p
->decoding_carryover
= 0;
4395 p
->encoding_buf
= make_uninit_string (0);
4397 p
->inherit_coding_system_flag
4398 = (NILP (buffer
) ? 0 : ps
->inherit_coding_system_flag
);
4400 if (!NILP (ps
->log
))
4401 call3 (ps
->log
, server
, proc
,
4402 concat3 (build_string ("accept from "),
4403 (STRINGP (host
) ? host
: build_string ("-")),
4404 build_string ("\n")));
4406 if (!NILP (p
->sentinel
))
4407 exec_sentinel (proc
,
4408 concat3 (build_string ("open from "),
4409 (STRINGP (host
) ? host
: build_string ("-")),
4410 build_string ("\n")));
4413 /* This variable is different from waiting_for_input in keyboard.c.
4414 It is used to communicate to a lisp process-filter/sentinel (via the
4415 function Fwaiting_for_user_input_p below) whether Emacs was waiting
4416 for user-input when that process-filter was called.
4417 waiting_for_input cannot be used as that is by definition 0 when
4418 lisp code is being evalled.
4419 This is also used in record_asynch_buffer_change.
4420 For that purpose, this must be 0
4421 when not inside wait_reading_process_output. */
4422 static int waiting_for_user_input_p
;
4425 wait_reading_process_output_unwind (data
)
4428 waiting_for_user_input_p
= XINT (data
);
4432 /* This is here so breakpoints can be put on it. */
4434 wait_reading_process_output_1 ()
4438 /* Use a wrapper around select to work around a bug in gdb 5.3.
4439 Normally, the wrapper is optimzed away by inlining.
4441 If emacs is stopped inside select, the gdb backtrace doesn't
4442 show the function which called select, so it is practically
4443 impossible to step through wait_reading_process_output. */
4447 select_wrapper (n
, rfd
, wfd
, xfd
, tmo
)
4449 SELECT_TYPE
*rfd
, *wfd
, *xfd
;
4452 return select (n
, rfd
, wfd
, xfd
, tmo
);
4454 #define select select_wrapper
4457 /* Read and dispose of subprocess output while waiting for timeout to
4458 elapse and/or keyboard input to be available.
4461 timeout in seconds, or
4462 zero for no limit, or
4463 -1 means gobble data immediately available but don't wait for any.
4466 an additional duration to wait, measured in microseconds.
4467 If this is nonzero and time_limit is 0, then the timeout
4468 consists of MICROSECS only.
4470 READ_KBD is a lisp value:
4471 0 to ignore keyboard input, or
4472 1 to return when input is available, or
4473 -1 meaning caller will actually read the input, so don't throw to
4474 the quit handler, or
4476 DO_DISPLAY != 0 means redisplay should be done to show subprocess
4477 output that arrives.
4479 If WAIT_FOR_CELL is a cons cell, wait until its car is non-nil
4480 (and gobble terminal input into the buffer if any arrives).
4482 If WAIT_PROC is specified, wait until something arrives from that
4483 process. The return value is true if we read some input from
4486 If JUST_WAIT_PROC is non-nil, handle only output from WAIT_PROC
4487 (suspending output from other processes). A negative value
4488 means don't run any timers either.
4490 If WAIT_PROC is specified, then the function returns true if we
4491 received input from that process before the timeout elapsed.
4492 Otherwise, return true if we received input from any process. */
4495 wait_reading_process_output (time_limit
, microsecs
, read_kbd
, do_display
,
4496 wait_for_cell
, wait_proc
, just_wait_proc
)
4497 int time_limit
, microsecs
, read_kbd
, do_display
;
4498 Lisp_Object wait_for_cell
;
4499 struct Lisp_Process
*wait_proc
;
4502 register int channel
, nfds
;
4503 SELECT_TYPE Available
;
4504 #ifdef NON_BLOCKING_CONNECT
4505 SELECT_TYPE Connecting
;
4508 int check_delay
, no_avail
;
4511 EMACS_TIME timeout
, end_time
;
4512 int wait_channel
= -1;
4513 int got_some_input
= 0;
4514 int count
= SPECPDL_INDEX ();
4516 FD_ZERO (&Available
);
4517 #ifdef NON_BLOCKING_CONNECT
4518 FD_ZERO (&Connecting
);
4521 /* If wait_proc is a process to watch, set wait_channel accordingly. */
4522 if (wait_proc
!= NULL
)
4523 wait_channel
= wait_proc
->infd
;
4525 record_unwind_protect (wait_reading_process_output_unwind
,
4526 make_number (waiting_for_user_input_p
));
4527 waiting_for_user_input_p
= read_kbd
;
4529 /* Since we may need to wait several times,
4530 compute the absolute time to return at. */
4531 if (time_limit
|| microsecs
)
4533 EMACS_GET_TIME (end_time
);
4534 EMACS_SET_SECS_USECS (timeout
, time_limit
, microsecs
);
4535 EMACS_ADD_TIME (end_time
, end_time
, timeout
);
4540 int timeout_reduced_for_timers
= 0;
4542 /* If calling from keyboard input, do not quit
4543 since we want to return C-g as an input character.
4544 Otherwise, do pending quit if requested. */
4549 process_pending_signals ();
4552 /* Exit now if the cell we're waiting for became non-nil. */
4553 if (! NILP (wait_for_cell
) && ! NILP (XCAR (wait_for_cell
)))
4556 /* Compute time from now till when time limit is up */
4557 /* Exit if already run out */
4558 if (time_limit
== -1)
4560 /* -1 specified for timeout means
4561 gobble output available now
4562 but don't wait at all. */
4564 EMACS_SET_SECS_USECS (timeout
, 0, 0);
4566 else if (time_limit
|| microsecs
)
4568 EMACS_GET_TIME (timeout
);
4569 EMACS_SUB_TIME (timeout
, end_time
, timeout
);
4570 if (EMACS_TIME_NEG_P (timeout
))
4575 EMACS_SET_SECS_USECS (timeout
, 100000, 0);
4578 /* Normally we run timers here.
4579 But not if wait_for_cell; in those cases,
4580 the wait is supposed to be short,
4581 and those callers cannot handle running arbitrary Lisp code here. */
4582 if (NILP (wait_for_cell
)
4583 && just_wait_proc
>= 0)
4585 EMACS_TIME timer_delay
;
4589 int old_timers_run
= timers_run
;
4590 struct buffer
*old_buffer
= current_buffer
;
4591 Lisp_Object old_window
= selected_window
;
4593 timer_delay
= timer_check (1);
4595 /* If a timer has run, this might have changed buffers
4596 an alike. Make read_key_sequence aware of that. */
4597 if (timers_run
!= old_timers_run
4598 && (old_buffer
!= current_buffer
4599 || !EQ (old_window
, selected_window
))
4600 && waiting_for_user_input_p
== -1)
4601 record_asynch_buffer_change ();
4603 if (timers_run
!= old_timers_run
&& do_display
)
4604 /* We must retry, since a timer may have requeued itself
4605 and that could alter the time_delay. */
4606 redisplay_preserve_echo_area (9);
4610 while (!detect_input_pending ());
4612 /* If there is unread keyboard input, also return. */
4614 && requeued_events_pending_p ())
4617 if (! EMACS_TIME_NEG_P (timer_delay
) && time_limit
!= -1)
4619 EMACS_TIME difference
;
4620 EMACS_SUB_TIME (difference
, timer_delay
, timeout
);
4621 if (EMACS_TIME_NEG_P (difference
))
4623 timeout
= timer_delay
;
4624 timeout_reduced_for_timers
= 1;
4627 /* If time_limit is -1, we are not going to wait at all. */
4628 else if (time_limit
!= -1)
4630 /* This is so a breakpoint can be put here. */
4631 wait_reading_process_output_1 ();
4635 /* Cause C-g and alarm signals to take immediate action,
4636 and cause input available signals to zero out timeout.
4638 It is important that we do this before checking for process
4639 activity. If we get a SIGCHLD after the explicit checks for
4640 process activity, timeout is the only way we will know. */
4642 set_waiting_for_input (&timeout
);
4644 /* If status of something has changed, and no input is
4645 available, notify the user of the change right away. After
4646 this explicit check, we'll let the SIGCHLD handler zap
4647 timeout to get our attention. When Emacs is run
4648 interactively, only do this with a nonzero DO_DISPLAY
4649 argument, because status_notify triggers redisplay. */
4650 if (update_tick
!= process_tick
4651 && (do_display
|| noninteractive
))
4654 #ifdef NON_BLOCKING_CONNECT
4658 Atemp
= input_wait_mask
;
4659 IF_NON_BLOCKING_CONNECT (Ctemp
= connect_wait_mask
);
4661 EMACS_SET_SECS_USECS (timeout
, 0, 0);
4662 if ((select (max (max (max_process_desc
, max_keyboard_desc
),
4665 #ifdef NON_BLOCKING_CONNECT
4666 (num_pending_connects
> 0 ? &Ctemp
: (SELECT_TYPE
*)0),
4670 (SELECT_TYPE
*)0, &timeout
)
4673 /* It's okay for us to do this and then continue with
4674 the loop, since timeout has already been zeroed out. */
4675 clear_waiting_for_input ();
4676 status_notify (NULL
);
4680 /* Don't wait for output from a non-running process. Just
4681 read whatever data has already been received. */
4682 if (wait_proc
&& wait_proc
->raw_status_new
)
4683 update_status (wait_proc
);
4685 && ! EQ (wait_proc
->status
, Qrun
)
4686 && ! EQ (wait_proc
->status
, Qconnect
))
4688 int nread
, total_nread
= 0;
4690 clear_waiting_for_input ();
4691 XSETPROCESS (proc
, wait_proc
);
4693 /* Read data from the process, until we exhaust it. */
4694 while (wait_proc
->infd
>= 0)
4696 nread
= read_process_output (proc
, wait_proc
->infd
);
4703 total_nread
+= nread
;
4707 else if (nread
== -1 && EIO
== errno
)
4711 else if (nread
== -1 && EAGAIN
== errno
)
4715 else if (nread
== -1 && EWOULDBLOCK
== errno
)
4719 if (total_nread
> 0 && do_display
)
4720 redisplay_preserve_echo_area (10);
4725 /* Wait till there is something to do */
4727 if (wait_proc
&& just_wait_proc
)
4729 if (wait_proc
->infd
< 0) /* Terminated */
4731 FD_SET (wait_proc
->infd
, &Available
);
4733 IF_NON_BLOCKING_CONNECT (check_connect
= 0);
4735 else if (!NILP (wait_for_cell
))
4737 Available
= non_process_wait_mask
;
4739 IF_NON_BLOCKING_CONNECT (check_connect
= 0);
4744 Available
= non_keyboard_wait_mask
;
4746 Available
= input_wait_mask
;
4747 IF_NON_BLOCKING_CONNECT (check_connect
= (num_pending_connects
> 0));
4748 check_delay
= wait_channel
>= 0 ? 0 : process_output_delay_count
;
4751 /* If frame size has changed or the window is newly mapped,
4752 redisplay now, before we start to wait. There is a race
4753 condition here; if a SIGIO arrives between now and the select
4754 and indicates that a frame is trashed, the select may block
4755 displaying a trashed screen. */
4756 if (frame_garbaged
&& do_display
)
4758 clear_waiting_for_input ();
4759 redisplay_preserve_echo_area (11);
4761 set_waiting_for_input (&timeout
);
4765 if (read_kbd
&& detect_input_pending ())
4772 #ifdef NON_BLOCKING_CONNECT
4774 Connecting
= connect_wait_mask
;
4777 #ifdef ADAPTIVE_READ_BUFFERING
4778 /* Set the timeout for adaptive read buffering if any
4779 process has non-zero read_output_skip and non-zero
4780 read_output_delay, and we are not reading output for a
4781 specific wait_channel. It is not executed if
4782 Vprocess_adaptive_read_buffering is nil. */
4783 if (process_output_skip
&& check_delay
> 0)
4785 int usecs
= EMACS_USECS (timeout
);
4786 if (EMACS_SECS (timeout
) > 0 || usecs
> READ_OUTPUT_DELAY_MAX
)
4787 usecs
= READ_OUTPUT_DELAY_MAX
;
4788 for (channel
= 0; check_delay
> 0 && channel
<= max_process_desc
; channel
++)
4790 proc
= chan_process
[channel
];
4793 /* Find minimum non-zero read_output_delay among the
4794 processes with non-zero read_output_skip. */
4795 if (XPROCESS (proc
)->read_output_delay
> 0)
4798 if (!XPROCESS (proc
)->read_output_skip
)
4800 FD_CLR (channel
, &Available
);
4801 XPROCESS (proc
)->read_output_skip
= 0;
4802 if (XPROCESS (proc
)->read_output_delay
< usecs
)
4803 usecs
= XPROCESS (proc
)->read_output_delay
;
4806 EMACS_SET_SECS_USECS (timeout
, 0, usecs
);
4807 process_output_skip
= 0;
4815 (max (max (max_process_desc
, max_keyboard_desc
),
4818 #ifdef NON_BLOCKING_CONNECT
4819 (check_connect
? &Connecting
: (SELECT_TYPE
*)0),
4823 (SELECT_TYPE
*)0, &timeout
);
4828 /* Make C-g and alarm signals set flags again */
4829 clear_waiting_for_input ();
4831 /* If we woke up due to SIGWINCH, actually change size now. */
4832 do_pending_window_change (0);
4834 if (time_limit
&& nfds
== 0 && ! timeout_reduced_for_timers
)
4835 /* We wanted the full specified time, so return now. */
4839 if (xerrno
== EINTR
)
4841 else if (xerrno
== EBADF
)
4844 /* AIX doesn't handle PTY closure the same way BSD does. On AIX,
4845 the child's closure of the pts gives the parent a SIGHUP, and
4846 the ptc file descriptor is automatically closed,
4847 yielding EBADF here or at select() call above.
4848 So, SIGHUP is ignored (see def of PTY_TTY_NAME_SPRINTF
4849 in m/ibmrt-aix.h), and here we just ignore the select error.
4850 Cleanup occurs c/o status_notify after SIGCLD. */
4851 no_avail
= 1; /* Cannot depend on values returned */
4857 error ("select error: %s", emacs_strerror (xerrno
));
4862 FD_ZERO (&Available
);
4863 IF_NON_BLOCKING_CONNECT (check_connect
= 0);
4866 #if 0 /* When polling is used, interrupt_input is 0,
4867 so get_input_pending should read the input.
4868 So this should not be needed. */
4869 /* If we are using polling for input,
4870 and we see input available, make it get read now.
4871 Otherwise it might not actually get read for a second.
4872 And on hpux, since we turn off polling in wait_reading_process_output,
4873 it might never get read at all if we don't spend much time
4874 outside of wait_reading_process_output. */
4875 if (read_kbd
&& interrupt_input
4876 && keyboard_bit_set (&Available
)
4877 && input_polling_used ())
4878 kill (getpid (), SIGALRM
);
4881 /* Check for keyboard input */
4882 /* If there is any, return immediately
4883 to give it higher priority than subprocesses */
4887 int old_timers_run
= timers_run
;
4888 struct buffer
*old_buffer
= current_buffer
;
4889 Lisp_Object old_window
= selected_window
;
4892 if (detect_input_pending_run_timers (do_display
))
4894 swallow_events (do_display
);
4895 if (detect_input_pending_run_timers (do_display
))
4899 /* If a timer has run, this might have changed buffers
4900 an alike. Make read_key_sequence aware of that. */
4901 if (timers_run
!= old_timers_run
4902 && waiting_for_user_input_p
== -1
4903 && (old_buffer
!= current_buffer
4904 || !EQ (old_window
, selected_window
)))
4905 record_asynch_buffer_change ();
4911 /* If there is unread keyboard input, also return. */
4913 && requeued_events_pending_p ())
4916 /* If we are not checking for keyboard input now,
4917 do process events (but don't run any timers).
4918 This is so that X events will be processed.
4919 Otherwise they may have to wait until polling takes place.
4920 That would causes delays in pasting selections, for example.
4922 (We used to do this only if wait_for_cell.) */
4923 if (read_kbd
== 0 && detect_input_pending ())
4925 swallow_events (do_display
);
4926 #if 0 /* Exiting when read_kbd doesn't request that seems wrong, though. */
4927 if (detect_input_pending ())
4932 /* Exit now if the cell we're waiting for became non-nil. */
4933 if (! NILP (wait_for_cell
) && ! NILP (XCAR (wait_for_cell
)))
4937 /* If we think we have keyboard input waiting, but didn't get SIGIO,
4938 go read it. This can happen with X on BSD after logging out.
4939 In that case, there really is no input and no SIGIO,
4940 but select says there is input. */
4942 if (read_kbd
&& interrupt_input
4943 && keyboard_bit_set (&Available
) && ! noninteractive
)
4944 kill (getpid (), SIGIO
);
4948 got_some_input
|= nfds
> 0;
4950 /* If checking input just got us a size-change event from X,
4951 obey it now if we should. */
4952 if (read_kbd
|| ! NILP (wait_for_cell
))
4953 do_pending_window_change (0);
4955 /* Check for data from a process. */
4956 if (no_avail
|| nfds
== 0)
4959 /* Really FIRST_PROC_DESC should be 0 on Unix,
4960 but this is safer in the short run. */
4961 for (channel
= 0; channel
<= max_process_desc
; channel
++)
4963 if (FD_ISSET (channel
, &Available
)
4964 && FD_ISSET (channel
, &non_keyboard_wait_mask
))
4968 /* If waiting for this channel, arrange to return as
4969 soon as no more input to be processed. No more
4971 if (wait_channel
== channel
)
4977 proc
= chan_process
[channel
];
4981 /* If this is a server stream socket, accept connection. */
4982 if (EQ (XPROCESS (proc
)->status
, Qlisten
))
4984 server_accept_connection (proc
, channel
);
4988 /* Read data from the process, starting with our
4989 buffered-ahead character if we have one. */
4991 nread
= read_process_output (proc
, channel
);
4994 /* Since read_process_output can run a filter,
4995 which can call accept-process-output,
4996 don't try to read from any other processes
4997 before doing the select again. */
4998 FD_ZERO (&Available
);
5001 redisplay_preserve_echo_area (12);
5004 else if (nread
== -1 && errno
== EWOULDBLOCK
)
5007 /* ISC 4.1 defines both EWOULDBLOCK and O_NONBLOCK,
5008 and Emacs uses O_NONBLOCK, so what we get is EAGAIN. */
5010 else if (nread
== -1 && errno
== EAGAIN
)
5014 else if (nread
== -1 && errno
== EAGAIN
)
5016 /* Note that we cannot distinguish between no input
5017 available now and a closed pipe.
5018 With luck, a closed pipe will be accompanied by
5019 subprocess termination and SIGCHLD. */
5020 else if (nread
== 0 && !NETCONN_P (proc
) && !SERIALCONN_P (proc
))
5022 #endif /* O_NDELAY */
5023 #endif /* O_NONBLOCK */
5025 /* On some OSs with ptys, when the process on one end of
5026 a pty exits, the other end gets an error reading with
5027 errno = EIO instead of getting an EOF (0 bytes read).
5028 Therefore, if we get an error reading and errno =
5029 EIO, just continue, because the child process has
5030 exited and should clean itself up soon (e.g. when we
5033 However, it has been known to happen that the SIGCHLD
5034 got lost. So raise the signal again just in case.
5036 else if (nread
== -1 && errno
== EIO
)
5038 /* Clear the descriptor now, so we only raise the signal once. */
5039 FD_CLR (channel
, &input_wait_mask
);
5040 FD_CLR (channel
, &non_keyboard_wait_mask
);
5042 kill (getpid (), SIGCHLD
);
5044 #endif /* HAVE_PTYS */
5045 /* If we can detect process termination, don't consider the process
5046 gone just because its pipe is closed. */
5048 else if (nread
== 0 && !NETCONN_P (proc
) && !SERIALCONN_P (proc
))
5053 /* Preserve status of processes already terminated. */
5054 XPROCESS (proc
)->tick
= ++process_tick
;
5055 deactivate_process (proc
);
5056 if (XPROCESS (proc
)->raw_status_new
)
5057 update_status (XPROCESS (proc
));
5058 if (EQ (XPROCESS (proc
)->status
, Qrun
))
5059 XPROCESS (proc
)->status
5060 = Fcons (Qexit
, Fcons (make_number (256), Qnil
));
5063 #ifdef NON_BLOCKING_CONNECT
5064 if (check_connect
&& FD_ISSET (channel
, &Connecting
)
5065 && FD_ISSET (channel
, &connect_wait_mask
))
5067 struct Lisp_Process
*p
;
5069 FD_CLR (channel
, &connect_wait_mask
);
5070 if (--num_pending_connects
< 0)
5073 proc
= chan_process
[channel
];
5077 p
= XPROCESS (proc
);
5080 /* getsockopt(,,SO_ERROR,,) is said to hang on some systems.
5081 So only use it on systems where it is known to work. */
5083 int xlen
= sizeof(xerrno
);
5084 if (getsockopt(channel
, SOL_SOCKET
, SO_ERROR
, &xerrno
, &xlen
))
5089 struct sockaddr pname
;
5090 int pnamelen
= sizeof(pname
);
5092 /* If connection failed, getpeername will fail. */
5094 if (getpeername(channel
, &pname
, &pnamelen
) < 0)
5096 /* Obtain connect failure code through error slippage. */
5099 if (errno
== ENOTCONN
&& read(channel
, &dummy
, 1) < 0)
5106 p
->tick
= ++process_tick
;
5107 p
->status
= Fcons (Qfailed
, Fcons (make_number (xerrno
), Qnil
));
5108 deactivate_process (proc
);
5113 /* Execute the sentinel here. If we had relied on
5114 status_notify to do it later, it will read input
5115 from the process before calling the sentinel. */
5116 exec_sentinel (proc
, build_string ("open\n"));
5117 if (!EQ (p
->filter
, Qt
) && !EQ (p
->command
, Qt
))
5119 FD_SET (p
->infd
, &input_wait_mask
);
5120 FD_SET (p
->infd
, &non_keyboard_wait_mask
);
5124 #endif /* NON_BLOCKING_CONNECT */
5125 } /* end for each file descriptor */
5126 } /* end while exit conditions not met */
5128 unbind_to (count
, Qnil
);
5130 /* If calling from keyboard input, do not quit
5131 since we want to return C-g as an input character.
5132 Otherwise, do pending quit if requested. */
5135 /* Prevent input_pending from remaining set if we quit. */
5136 clear_input_pending ();
5140 return got_some_input
;
5143 /* Given a list (FUNCTION ARGS...), apply FUNCTION to the ARGS. */
5146 read_process_output_call (fun_and_args
)
5147 Lisp_Object fun_and_args
;
5149 return apply1 (XCAR (fun_and_args
), XCDR (fun_and_args
));
5153 read_process_output_error_handler (error
)
5156 cmd_error_internal (error
, "error in process filter: ");
5158 update_echo_area ();
5159 Fsleep_for (make_number (2), Qnil
);
5163 /* Read pending output from the process channel,
5164 starting with our buffered-ahead character if we have one.
5165 Yield number of decoded characters read.
5167 This function reads at most 4096 characters.
5168 If you want to read all available subprocess output,
5169 you must call it repeatedly until it returns zero.
5171 The characters read are decoded according to PROC's coding-system
5175 read_process_output (proc
, channel
)
5177 register int channel
;
5179 register int nbytes
;
5181 register Lisp_Object outstream
;
5182 register struct buffer
*old
= current_buffer
;
5183 register struct Lisp_Process
*p
= XPROCESS (proc
);
5184 register int opoint
;
5185 struct coding_system
*coding
= proc_decode_coding_system
[channel
];
5186 int carryover
= p
->decoding_carryover
;
5189 chars
= (char *) alloca (carryover
+ readmax
);
5191 /* See the comment above. */
5192 bcopy (SDATA (p
->decoding_buf
), chars
, carryover
);
5194 #ifdef DATAGRAM_SOCKETS
5195 /* We have a working select, so proc_buffered_char is always -1. */
5196 if (DATAGRAM_CHAN_P (channel
))
5198 int len
= datagram_address
[channel
].len
;
5199 nbytes
= recvfrom (channel
, chars
+ carryover
, readmax
,
5200 0, datagram_address
[channel
].sa
, &len
);
5204 if (proc_buffered_char
[channel
] < 0)
5206 nbytes
= emacs_read (channel
, chars
+ carryover
, readmax
);
5207 #ifdef ADAPTIVE_READ_BUFFERING
5208 if (nbytes
> 0 && p
->adaptive_read_buffering
)
5210 int delay
= p
->read_output_delay
;
5213 if (delay
< READ_OUTPUT_DELAY_MAX_MAX
)
5216 process_output_delay_count
++;
5217 delay
+= READ_OUTPUT_DELAY_INCREMENT
* 2;
5220 else if (delay
> 0 && (nbytes
== readmax
))
5222 delay
-= READ_OUTPUT_DELAY_INCREMENT
;
5224 process_output_delay_count
--;
5226 p
->read_output_delay
= delay
;
5229 p
->read_output_skip
= 1;
5230 process_output_skip
= 1;
5237 chars
[carryover
] = proc_buffered_char
[channel
];
5238 proc_buffered_char
[channel
] = -1;
5239 nbytes
= emacs_read (channel
, chars
+ carryover
+ 1, readmax
- 1);
5243 nbytes
= nbytes
+ 1;
5246 p
->decoding_carryover
= 0;
5248 /* At this point, NBYTES holds number of bytes just received
5249 (including the one in proc_buffered_char[channel]). */
5252 if (nbytes
< 0 || coding
->mode
& CODING_MODE_LAST_BLOCK
)
5254 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
5257 /* Now set NBYTES how many bytes we must decode. */
5258 nbytes
+= carryover
;
5260 /* Read and dispose of the process output. */
5261 outstream
= p
->filter
;
5262 if (!NILP (outstream
))
5264 /* We inhibit quit here instead of just catching it so that
5265 hitting ^G when a filter happens to be running won't screw
5267 int count
= SPECPDL_INDEX ();
5268 Lisp_Object odeactivate
;
5269 Lisp_Object obuffer
, okeymap
;
5271 int outer_running_asynch_code
= running_asynch_code
;
5272 int waiting
= waiting_for_user_input_p
;
5274 /* No need to gcpro these, because all we do with them later
5275 is test them for EQness, and none of them should be a string. */
5276 odeactivate
= Vdeactivate_mark
;
5277 XSETBUFFER (obuffer
, current_buffer
);
5278 okeymap
= current_buffer
->keymap
;
5280 specbind (Qinhibit_quit
, Qt
);
5281 specbind (Qlast_nonmenu_event
, Qt
);
5283 /* In case we get recursively called,
5284 and we already saved the match data nonrecursively,
5285 save the same match data in safely recursive fashion. */
5286 if (outer_running_asynch_code
)
5289 /* Don't clobber the CURRENT match data, either! */
5290 tem
= Fmatch_data (Qnil
, Qnil
, Qnil
);
5291 restore_search_regs ();
5292 record_unwind_save_match_data ();
5293 Fset_match_data (tem
, Qt
);
5296 /* For speed, if a search happens within this code,
5297 save the match data in a special nonrecursive fashion. */
5298 running_asynch_code
= 1;
5300 decode_coding_c_string (coding
, chars
, nbytes
, Qt
);
5301 text
= coding
->dst_object
;
5302 Vlast_coding_system_used
= CODING_ID_NAME (coding
->id
);
5303 /* A new coding system might be found. */
5304 if (!EQ (p
->decode_coding_system
, Vlast_coding_system_used
))
5306 p
->decode_coding_system
= Vlast_coding_system_used
;
5308 /* Don't call setup_coding_system for
5309 proc_decode_coding_system[channel] here. It is done in
5310 detect_coding called via decode_coding above. */
5312 /* If a coding system for encoding is not yet decided, we set
5313 it as the same as coding-system for decoding.
5315 But, before doing that we must check if
5316 proc_encode_coding_system[p->outfd] surely points to a
5317 valid memory because p->outfd will be changed once EOF is
5318 sent to the process. */
5319 if (NILP (p
->encode_coding_system
)
5320 && proc_encode_coding_system
[p
->outfd
])
5322 p
->encode_coding_system
5323 = coding_inherit_eol_type (Vlast_coding_system_used
, Qnil
);
5324 setup_coding_system (p
->encode_coding_system
,
5325 proc_encode_coding_system
[p
->outfd
]);
5329 if (coding
->carryover_bytes
> 0)
5331 if (SCHARS (p
->decoding_buf
) < coding
->carryover_bytes
)
5332 p
->decoding_buf
= make_uninit_string (coding
->carryover_bytes
);
5333 bcopy (coding
->carryover
, SDATA (p
->decoding_buf
),
5334 coding
->carryover_bytes
);
5335 p
->decoding_carryover
= coding
->carryover_bytes
;
5337 if (SBYTES (text
) > 0)
5338 internal_condition_case_1 (read_process_output_call
,
5340 Fcons (proc
, Fcons (text
, Qnil
))),
5341 !NILP (Vdebug_on_error
) ? Qnil
: Qerror
,
5342 read_process_output_error_handler
);
5344 /* If we saved the match data nonrecursively, restore it now. */
5345 restore_search_regs ();
5346 running_asynch_code
= outer_running_asynch_code
;
5348 /* Handling the process output should not deactivate the mark. */
5349 Vdeactivate_mark
= odeactivate
;
5351 /* Restore waiting_for_user_input_p as it was
5352 when we were called, in case the filter clobbered it. */
5353 waiting_for_user_input_p
= waiting
;
5355 #if 0 /* Call record_asynch_buffer_change unconditionally,
5356 because we might have changed minor modes or other things
5357 that affect key bindings. */
5358 if (! EQ (Fcurrent_buffer (), obuffer
)
5359 || ! EQ (current_buffer
->keymap
, okeymap
))
5361 /* But do it only if the caller is actually going to read events.
5362 Otherwise there's no need to make him wake up, and it could
5363 cause trouble (for example it would make sit_for return). */
5364 if (waiting_for_user_input_p
== -1)
5365 record_asynch_buffer_change ();
5367 unbind_to (count
, Qnil
);
5371 /* If no filter, write into buffer if it isn't dead. */
5372 if (!NILP (p
->buffer
) && !NILP (XBUFFER (p
->buffer
)->name
))
5374 Lisp_Object old_read_only
;
5375 int old_begv
, old_zv
;
5376 int old_begv_byte
, old_zv_byte
;
5377 Lisp_Object odeactivate
;
5378 int before
, before_byte
;
5383 odeactivate
= Vdeactivate_mark
;
5385 Fset_buffer (p
->buffer
);
5387 opoint_byte
= PT_BYTE
;
5388 old_read_only
= current_buffer
->read_only
;
5391 old_begv_byte
= BEGV_BYTE
;
5392 old_zv_byte
= ZV_BYTE
;
5394 current_buffer
->read_only
= Qnil
;
5396 /* Insert new output into buffer
5397 at the current end-of-output marker,
5398 thus preserving logical ordering of input and output. */
5399 if (XMARKER (p
->mark
)->buffer
)
5400 SET_PT_BOTH (clip_to_bounds (BEGV
, marker_position (p
->mark
), ZV
),
5401 clip_to_bounds (BEGV_BYTE
, marker_byte_position (p
->mark
),
5404 SET_PT_BOTH (ZV
, ZV_BYTE
);
5406 before_byte
= PT_BYTE
;
5408 /* If the output marker is outside of the visible region, save
5409 the restriction and widen. */
5410 if (! (BEGV
<= PT
&& PT
<= ZV
))
5413 decode_coding_c_string (coding
, chars
, nbytes
, Qt
);
5414 text
= coding
->dst_object
;
5415 Vlast_coding_system_used
= CODING_ID_NAME (coding
->id
);
5416 /* A new coding system might be found. See the comment in the
5417 similar code in the previous `if' block. */
5418 if (!EQ (p
->decode_coding_system
, Vlast_coding_system_used
))
5420 p
->decode_coding_system
= Vlast_coding_system_used
;
5421 if (NILP (p
->encode_coding_system
)
5422 && proc_encode_coding_system
[p
->outfd
])
5424 p
->encode_coding_system
5425 = coding_inherit_eol_type (Vlast_coding_system_used
, Qnil
);
5426 setup_coding_system (p
->encode_coding_system
,
5427 proc_encode_coding_system
[p
->outfd
]);
5430 if (coding
->carryover_bytes
> 0)
5432 if (SCHARS (p
->decoding_buf
) < coding
->carryover_bytes
)
5433 p
->decoding_buf
= make_uninit_string (coding
->carryover_bytes
);
5434 bcopy (coding
->carryover
, SDATA (p
->decoding_buf
),
5435 coding
->carryover_bytes
);
5436 p
->decoding_carryover
= coding
->carryover_bytes
;
5438 /* Adjust the multibyteness of TEXT to that of the buffer. */
5439 if (NILP (current_buffer
->enable_multibyte_characters
)
5440 != ! STRING_MULTIBYTE (text
))
5441 text
= (STRING_MULTIBYTE (text
)
5442 ? Fstring_as_unibyte (text
)
5443 : Fstring_to_multibyte (text
));
5444 /* Insert before markers in case we are inserting where
5445 the buffer's mark is, and the user's next command is Meta-y. */
5446 insert_from_string_before_markers (text
, 0, 0,
5447 SCHARS (text
), SBYTES (text
), 0);
5449 /* Make sure the process marker's position is valid when the
5450 process buffer is changed in the signal_after_change above.
5451 W3 is known to do that. */
5452 if (BUFFERP (p
->buffer
)
5453 && (b
= XBUFFER (p
->buffer
), b
!= current_buffer
))
5454 set_marker_both (p
->mark
, p
->buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
5456 set_marker_both (p
->mark
, p
->buffer
, PT
, PT_BYTE
);
5458 update_mode_lines
++;
5460 /* Make sure opoint and the old restrictions
5461 float ahead of any new text just as point would. */
5462 if (opoint
>= before
)
5464 opoint
+= PT
- before
;
5465 opoint_byte
+= PT_BYTE
- before_byte
;
5467 if (old_begv
> before
)
5469 old_begv
+= PT
- before
;
5470 old_begv_byte
+= PT_BYTE
- before_byte
;
5472 if (old_zv
>= before
)
5474 old_zv
+= PT
- before
;
5475 old_zv_byte
+= PT_BYTE
- before_byte
;
5478 /* If the restriction isn't what it should be, set it. */
5479 if (old_begv
!= BEGV
|| old_zv
!= ZV
)
5480 Fnarrow_to_region (make_number (old_begv
), make_number (old_zv
));
5482 /* Handling the process output should not deactivate the mark. */
5483 Vdeactivate_mark
= odeactivate
;
5485 current_buffer
->read_only
= old_read_only
;
5486 SET_PT_BOTH (opoint
, opoint_byte
);
5487 set_buffer_internal (old
);
5492 DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p
, Swaiting_for_user_input_p
,
5494 doc
: /* Returns non-nil if Emacs is waiting for input from the user.
5495 This is intended for use by asynchronous process output filters and sentinels. */)
5498 return (waiting_for_user_input_p
? Qt
: Qnil
);
5501 /* Sending data to subprocess */
5503 jmp_buf send_process_frame
;
5504 Lisp_Object process_sent_to
;
5507 send_process_trap ()
5509 SIGNAL_THREAD_CHECK (SIGPIPE
);
5510 sigunblock (sigmask (SIGPIPE
));
5511 longjmp (send_process_frame
, 1);
5514 /* Send some data to process PROC.
5515 BUF is the beginning of the data; LEN is the number of characters.
5516 OBJECT is the Lisp object that the data comes from. If OBJECT is
5517 nil or t, it means that the data comes from C string.
5519 If OBJECT is not nil, the data is encoded by PROC's coding-system
5520 for encoding before it is sent.
5522 This function can evaluate Lisp code and can garbage collect. */
5525 send_process (proc
, buf
, len
, object
)
5526 volatile Lisp_Object proc
;
5527 unsigned char *volatile buf
;
5529 volatile Lisp_Object object
;
5531 /* Use volatile to protect variables from being clobbered by longjmp. */
5532 struct Lisp_Process
*p
= XPROCESS (proc
);
5534 struct coding_system
*coding
;
5535 struct gcpro gcpro1
;
5536 SIGTYPE (*volatile old_sigpipe
) ();
5540 if (p
->raw_status_new
)
5542 if (! EQ (p
->status
, Qrun
))
5543 error ("Process %s not running", SDATA (p
->name
));
5545 error ("Output file descriptor of %s is closed", SDATA (p
->name
));
5547 coding
= proc_encode_coding_system
[p
->outfd
];
5548 Vlast_coding_system_used
= CODING_ID_NAME (coding
->id
);
5550 if ((STRINGP (object
) && STRING_MULTIBYTE (object
))
5551 || (BUFFERP (object
)
5552 && !NILP (XBUFFER (object
)->enable_multibyte_characters
))
5555 if (!EQ (Vlast_coding_system_used
, p
->encode_coding_system
))
5556 /* The coding system for encoding was changed to raw-text
5557 because we sent a unibyte text previously. Now we are
5558 sending a multibyte text, thus we must encode it by the
5559 original coding system specified for the current process. */
5560 setup_coding_system (p
->encode_coding_system
, coding
);
5561 coding
->src_multibyte
= 1;
5565 /* For sending a unibyte text, character code conversion should
5566 not take place but EOL conversion should. So, setup raw-text
5567 or one of the subsidiary if we have not yet done it. */
5568 if (CODING_REQUIRE_ENCODING (coding
))
5570 if (CODING_REQUIRE_FLUSHING (coding
))
5572 /* But, before changing the coding, we must flush out data. */
5573 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
5574 send_process (proc
, "", 0, Qt
);
5575 coding
->mode
&= CODING_MODE_LAST_BLOCK
;
5577 setup_coding_system (raw_text_coding_system
5578 (Vlast_coding_system_used
),
5580 coding
->src_multibyte
= 0;
5583 coding
->dst_multibyte
= 0;
5585 if (CODING_REQUIRE_ENCODING (coding
))
5587 coding
->dst_object
= Qt
;
5588 if (BUFFERP (object
))
5590 int from_byte
, from
, to
;
5591 int save_pt
, save_pt_byte
;
5592 struct buffer
*cur
= current_buffer
;
5594 set_buffer_internal (XBUFFER (object
));
5595 save_pt
= PT
, save_pt_byte
= PT_BYTE
;
5597 from_byte
= PTR_BYTE_POS (buf
);
5598 from
= BYTE_TO_CHAR (from_byte
);
5599 to
= BYTE_TO_CHAR (from_byte
+ len
);
5600 TEMP_SET_PT_BOTH (from
, from_byte
);
5601 encode_coding_object (coding
, object
, from
, from_byte
,
5602 to
, from_byte
+ len
, Qt
);
5603 TEMP_SET_PT_BOTH (save_pt
, save_pt_byte
);
5604 set_buffer_internal (cur
);
5606 else if (STRINGP (object
))
5608 encode_coding_string (coding
, object
, 1);
5612 coding
->dst_object
= make_unibyte_string (buf
, len
);
5613 coding
->produced
= len
;
5616 len
= coding
->produced
;
5617 buf
= SDATA (coding
->dst_object
);
5620 if (pty_max_bytes
== 0)
5622 #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON)
5623 pty_max_bytes
= fpathconf (p
->outfd
, _PC_MAX_CANON
);
5624 if (pty_max_bytes
< 0)
5625 pty_max_bytes
= 250;
5627 pty_max_bytes
= 250;
5629 /* Deduct one, to leave space for the eof. */
5633 /* 2000-09-21: Emacs 20.7, sparc-sun-solaris-2.6, GCC 2.95.2,
5634 CFLAGS="-g -O": The value of the parameter `proc' is clobbered
5635 when returning with longjmp despite being declared volatile. */
5636 if (!setjmp (send_process_frame
))
5638 process_sent_to
= proc
;
5643 /* Decide how much data we can send in one batch.
5644 Long lines need to be split into multiple batches. */
5647 /* Starting this at zero is always correct when not the first
5648 iteration because the previous iteration ended by sending C-d.
5649 It may not be correct for the first iteration
5650 if a partial line was sent in a separate send_process call.
5651 If that proves worth handling, we need to save linepos
5652 in the process object. */
5654 unsigned char *ptr
= (unsigned char *) buf
;
5655 unsigned char *end
= (unsigned char *) buf
+ len
;
5657 /* Scan through this text for a line that is too long. */
5658 while (ptr
!= end
&& linepos
< pty_max_bytes
)
5666 /* If we found one, break the line there
5667 and put in a C-d to force the buffer through. */
5671 /* Send this batch, using one or more write calls. */
5674 int outfd
= p
->outfd
;
5675 old_sigpipe
= (SIGTYPE (*) ()) signal (SIGPIPE
, send_process_trap
);
5676 #ifdef DATAGRAM_SOCKETS
5677 if (DATAGRAM_CHAN_P (outfd
))
5679 rv
= sendto (outfd
, (char *) buf
, this,
5680 0, datagram_address
[outfd
].sa
,
5681 datagram_address
[outfd
].len
);
5682 if (rv
< 0 && errno
== EMSGSIZE
)
5684 signal (SIGPIPE
, old_sigpipe
);
5685 report_file_error ("sending datagram",
5686 Fcons (proc
, Qnil
));
5692 rv
= emacs_write (outfd
, (char *) buf
, this);
5693 #ifdef ADAPTIVE_READ_BUFFERING
5694 if (p
->read_output_delay
> 0
5695 && p
->adaptive_read_buffering
== 1)
5697 p
->read_output_delay
= 0;
5698 process_output_delay_count
--;
5699 p
->read_output_skip
= 0;
5703 signal (SIGPIPE
, old_sigpipe
);
5709 || errno
== EWOULDBLOCK
5715 /* Buffer is full. Wait, accepting input;
5716 that may allow the program
5717 to finish doing output and read more. */
5721 #ifdef BROKEN_PTY_READ_AFTER_EAGAIN
5722 /* A gross hack to work around a bug in FreeBSD.
5723 In the following sequence, read(2) returns
5727 write(2) 954 bytes, get EAGAIN
5728 read(2) 1024 bytes in process_read_output
5729 read(2) 11 bytes in process_read_output
5731 That is, read(2) returns more bytes than have
5732 ever been written successfully. The 1033 bytes
5733 read are the 1022 bytes written successfully
5734 after processing (for example with CRs added if
5735 the terminal is set up that way which it is
5736 here). The same bytes will be seen again in a
5737 later read(2), without the CRs. */
5739 if (errno
== EAGAIN
)
5742 ioctl (p
->outfd
, TIOCFLUSH
, &flags
);
5744 #endif /* BROKEN_PTY_READ_AFTER_EAGAIN */
5746 /* Running filters might relocate buffers or strings.
5747 Arrange to relocate BUF. */
5748 if (CODING_REQUIRE_ENCODING (coding
))
5749 offset
= buf
- SDATA (coding
->dst_object
);
5750 else if (BUFFERP (object
))
5751 offset
= BUF_PTR_BYTE_POS (XBUFFER (object
), buf
);
5752 else if (STRINGP (object
))
5753 offset
= buf
- SDATA (object
);
5755 #ifdef EMACS_HAS_USECS
5756 wait_reading_process_output (0, 20000, 0, 0, Qnil
, NULL
, 0);
5758 wait_reading_process_output (1, 0, 0, 0, Qnil
, NULL
, 0);
5761 if (CODING_REQUIRE_ENCODING (coding
))
5762 buf
= offset
+ SDATA (coding
->dst_object
);
5763 else if (BUFFERP (object
))
5764 buf
= BUF_BYTE_ADDRESS (XBUFFER (object
), offset
);
5765 else if (STRINGP (object
))
5766 buf
= offset
+ SDATA (object
);
5771 /* This is a real error. */
5772 report_file_error ("writing to process", Fcons (proc
, Qnil
));
5779 /* If we sent just part of the string, put in an EOF (C-d)
5780 to force it through, before we send the rest. */
5782 Fprocess_send_eof (proc
);
5787 signal (SIGPIPE
, old_sigpipe
);
5788 proc
= process_sent_to
;
5789 p
= XPROCESS (proc
);
5790 p
->raw_status_new
= 0;
5791 p
->status
= Fcons (Qexit
, Fcons (make_number (256), Qnil
));
5792 p
->tick
= ++process_tick
;
5793 deactivate_process (proc
);
5794 error ("SIGPIPE raised on process %s; closed it", SDATA (p
->name
));
5800 DEFUN ("process-send-region", Fprocess_send_region
, Sprocess_send_region
,
5802 doc
: /* Send current contents of region as input to PROCESS.
5803 PROCESS may be a process, a buffer, the name of a process or buffer, or
5804 nil, indicating the current buffer's process.
5805 Called from program, takes three arguments, PROCESS, START and END.
5806 If the region is more than 500 characters long,
5807 it is sent in several bunches. This may happen even for shorter regions.
5808 Output from processes can arrive in between bunches. */)
5809 (process
, start
, end
)
5810 Lisp_Object process
, start
, end
;
5815 proc
= get_process (process
);
5816 validate_region (&start
, &end
);
5818 if (XINT (start
) < GPT
&& XINT (end
) > GPT
)
5819 move_gap (XINT (start
));
5821 start1
= CHAR_TO_BYTE (XINT (start
));
5822 end1
= CHAR_TO_BYTE (XINT (end
));
5823 send_process (proc
, BYTE_POS_ADDR (start1
), end1
- start1
,
5824 Fcurrent_buffer ());
5829 DEFUN ("process-send-string", Fprocess_send_string
, Sprocess_send_string
,
5831 doc
: /* Send PROCESS the contents of STRING as input.
5832 PROCESS may be a process, a buffer, the name of a process or buffer, or
5833 nil, indicating the current buffer's process.
5834 If STRING is more than 500 characters long,
5835 it is sent in several bunches. This may happen even for shorter strings.
5836 Output from processes can arrive in between bunches. */)
5838 Lisp_Object process
, string
;
5841 CHECK_STRING (string
);
5842 proc
= get_process (process
);
5843 send_process (proc
, SDATA (string
),
5844 SBYTES (string
), string
);
5848 /* Return the foreground process group for the tty/pty that
5849 the process P uses. */
5851 emacs_get_tty_pgrp (p
)
5852 struct Lisp_Process
*p
;
5857 if (ioctl (p
->infd
, TIOCGPGRP
, &gid
) == -1 && ! NILP (p
->tty_name
))
5860 /* Some OS:es (Solaris 8/9) does not allow TIOCGPGRP from the
5861 master side. Try the slave side. */
5862 fd
= emacs_open (SDATA (p
->tty_name
), O_RDONLY
, 0);
5866 ioctl (fd
, TIOCGPGRP
, &gid
);
5870 #endif /* defined (TIOCGPGRP ) */
5875 DEFUN ("process-running-child-p", Fprocess_running_child_p
,
5876 Sprocess_running_child_p
, 0, 1, 0,
5877 doc
: /* Return t if PROCESS has given the terminal to a child.
5878 If the operating system does not make it possible to find out,
5879 return t unconditionally. */)
5881 Lisp_Object process
;
5883 /* Initialize in case ioctl doesn't exist or gives an error,
5884 in a way that will cause returning t. */
5887 struct Lisp_Process
*p
;
5889 proc
= get_process (process
);
5890 p
= XPROCESS (proc
);
5892 if (!EQ (p
->type
, Qreal
))
5893 error ("Process %s is not a subprocess",
5896 error ("Process %s is not active",
5899 gid
= emacs_get_tty_pgrp (p
);
5906 /* send a signal number SIGNO to PROCESS.
5907 If CURRENT_GROUP is t, that means send to the process group
5908 that currently owns the terminal being used to communicate with PROCESS.
5909 This is used for various commands in shell mode.
5910 If CURRENT_GROUP is lambda, that means send to the process group
5911 that currently owns the terminal, but only if it is NOT the shell itself.
5913 If NOMSG is zero, insert signal-announcements into process's buffers
5916 If we can, we try to signal PROCESS by sending control characters
5917 down the pty. This allows us to signal inferiors who have changed
5918 their uid, for which killpg would return an EPERM error. */
5921 process_send_signal (process
, signo
, current_group
, nomsg
)
5922 Lisp_Object process
;
5924 Lisp_Object current_group
;
5928 register struct Lisp_Process
*p
;
5932 proc
= get_process (process
);
5933 p
= XPROCESS (proc
);
5935 if (!EQ (p
->type
, Qreal
))
5936 error ("Process %s is not a subprocess",
5939 error ("Process %s is not active",
5943 current_group
= Qnil
;
5945 /* If we are using pgrps, get a pgrp number and make it negative. */
5946 if (NILP (current_group
))
5947 /* Send the signal to the shell's process group. */
5951 #ifdef SIGNALS_VIA_CHARACTERS
5952 /* If possible, send signals to the entire pgrp
5953 by sending an input character to it. */
5955 /* TERMIOS is the latest and bestest, and seems most likely to
5956 work. If the system has it, use it. */
5959 cc_t
*sig_char
= NULL
;
5961 tcgetattr (p
->infd
, &t
);
5966 sig_char
= &t
.c_cc
[VINTR
];
5970 sig_char
= &t
.c_cc
[VQUIT
];
5974 #if defined (VSWTCH) && !defined (PREFER_VSUSP)
5975 sig_char
= &t
.c_cc
[VSWTCH
];
5977 sig_char
= &t
.c_cc
[VSUSP
];
5982 if (sig_char
&& *sig_char
!= CDISABLE
)
5984 send_process (proc
, sig_char
, 1, Qnil
);
5987 /* If we can't send the signal with a character,
5988 fall through and send it another way. */
5989 #else /* ! HAVE_TERMIOS */
5991 /* On Berkeley descendants, the following IOCTL's retrieve the
5992 current control characters. */
5993 #if defined (TIOCGLTC) && defined (TIOCGETC)
6001 ioctl (p
->infd
, TIOCGETC
, &c
);
6002 send_process (proc
, &c
.t_intrc
, 1, Qnil
);
6005 ioctl (p
->infd
, TIOCGETC
, &c
);
6006 send_process (proc
, &c
.t_quitc
, 1, Qnil
);
6010 ioctl (p
->infd
, TIOCGLTC
, &lc
);
6011 send_process (proc
, &lc
.t_suspc
, 1, Qnil
);
6013 #endif /* ! defined (SIGTSTP) */
6016 #else /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
6018 /* On SYSV descendants, the TCGETA ioctl retrieves the current control
6025 ioctl (p
->infd
, TCGETA
, &t
);
6026 send_process (proc
, &t
.c_cc
[VINTR
], 1, Qnil
);
6029 ioctl (p
->infd
, TCGETA
, &t
);
6030 send_process (proc
, &t
.c_cc
[VQUIT
], 1, Qnil
);
6034 ioctl (p
->infd
, TCGETA
, &t
);
6035 send_process (proc
, &t
.c_cc
[VSWTCH
], 1, Qnil
);
6037 #endif /* ! defined (SIGTSTP) */
6039 #else /* ! defined (TCGETA) */
6040 Your configuration files are messed up
.
6041 /* If your system configuration files define SIGNALS_VIA_CHARACTERS,
6042 you'd better be using one of the alternatives above! */
6043 #endif /* ! defined (TCGETA) */
6044 #endif /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
6045 /* In this case, the code above should alway return. */
6047 #endif /* ! defined HAVE_TERMIOS */
6049 /* The code above may fall through if it can't
6050 handle the signal. */
6051 #endif /* defined (SIGNALS_VIA_CHARACTERS) */
6054 /* Get the current pgrp using the tty itself, if we have that.
6055 Otherwise, use the pty to get the pgrp.
6056 On pfa systems, saka@pfu.fujitsu.co.JP writes:
6057 "TIOCGPGRP symbol defined in sys/ioctl.h at E50.
6058 But, TIOCGPGRP does not work on E50 ;-P works fine on E60"
6059 His patch indicates that if TIOCGPGRP returns an error, then
6060 we should just assume that p->pid is also the process group id. */
6062 gid
= emacs_get_tty_pgrp (p
);
6065 /* If we can't get the information, assume
6066 the shell owns the tty. */
6069 /* It is not clear whether anything really can set GID to -1.
6070 Perhaps on some system one of those ioctls can or could do so.
6071 Or perhaps this is vestigial. */
6074 #else /* ! defined (TIOCGPGRP ) */
6075 /* Can't select pgrps on this system, so we know that
6076 the child itself heads the pgrp. */
6078 #endif /* ! defined (TIOCGPGRP ) */
6080 /* If current_group is lambda, and the shell owns the terminal,
6081 don't send any signal. */
6082 if (EQ (current_group
, Qlambda
) && gid
== p
->pid
)
6090 p
->raw_status_new
= 0;
6092 p
->tick
= ++process_tick
;
6094 status_notify (NULL
);
6096 #endif /* ! defined (SIGCONT) */
6100 flush_pending_output (p
->infd
);
6104 /* If we don't have process groups, send the signal to the immediate
6105 subprocess. That isn't really right, but it's better than any
6106 obvious alternative. */
6109 kill (p
->pid
, signo
);
6113 /* gid may be a pid, or minus a pgrp's number */
6115 if (!NILP (current_group
))
6117 if (ioctl (p
->infd
, TIOCSIGSEND
, signo
) == -1)
6118 EMACS_KILLPG (gid
, signo
);
6125 #else /* ! defined (TIOCSIGSEND) */
6126 EMACS_KILLPG (gid
, signo
);
6127 #endif /* ! defined (TIOCSIGSEND) */
6130 DEFUN ("interrupt-process", Finterrupt_process
, Sinterrupt_process
, 0, 2, 0,
6131 doc
: /* Interrupt process PROCESS.
6132 PROCESS may be a process, a buffer, or the name of a process or buffer.
6133 No arg or nil means current buffer's process.
6134 Second arg CURRENT-GROUP non-nil means send signal to
6135 the current process-group of the process's controlling terminal
6136 rather than to the process's own process group.
6137 If the process is a shell, this means interrupt current subjob
6138 rather than the shell.
6140 If CURRENT-GROUP is `lambda', and if the shell owns the terminal,
6141 don't send the signal. */)
6142 (process
, current_group
)
6143 Lisp_Object process
, current_group
;
6145 process_send_signal (process
, SIGINT
, current_group
, 0);
6149 DEFUN ("kill-process", Fkill_process
, Skill_process
, 0, 2, 0,
6150 doc
: /* Kill process PROCESS. May be process or name of one.
6151 See function `interrupt-process' for more details on usage. */)
6152 (process
, current_group
)
6153 Lisp_Object process
, current_group
;
6155 process_send_signal (process
, SIGKILL
, current_group
, 0);
6159 DEFUN ("quit-process", Fquit_process
, Squit_process
, 0, 2, 0,
6160 doc
: /* Send QUIT signal to process PROCESS. May be process or name of one.
6161 See function `interrupt-process' for more details on usage. */)
6162 (process
, current_group
)
6163 Lisp_Object process
, current_group
;
6165 process_send_signal (process
, SIGQUIT
, current_group
, 0);
6169 DEFUN ("stop-process", Fstop_process
, Sstop_process
, 0, 2, 0,
6170 doc
: /* Stop process PROCESS. May be process or name of one.
6171 See function `interrupt-process' for more details on usage.
6172 If PROCESS is a network or serial process, inhibit handling of incoming
6174 (process
, current_group
)
6175 Lisp_Object process
, current_group
;
6178 if (PROCESSP (process
) && (NETCONN_P (process
) || SERIALCONN_P (process
)))
6180 struct Lisp_Process
*p
;
6182 p
= XPROCESS (process
);
6183 if (NILP (p
->command
)
6186 FD_CLR (p
->infd
, &input_wait_mask
);
6187 FD_CLR (p
->infd
, &non_keyboard_wait_mask
);
6194 error ("No SIGTSTP support");
6196 process_send_signal (process
, SIGTSTP
, current_group
, 0);
6201 DEFUN ("continue-process", Fcontinue_process
, Scontinue_process
, 0, 2, 0,
6202 doc
: /* Continue process PROCESS. May be process or name of one.
6203 See function `interrupt-process' for more details on usage.
6204 If PROCESS is a network or serial process, resume handling of incoming
6206 (process
, current_group
)
6207 Lisp_Object process
, current_group
;
6210 if (PROCESSP (process
) && (NETCONN_P (process
) || SERIALCONN_P (process
)))
6212 struct Lisp_Process
*p
;
6214 p
= XPROCESS (process
);
6215 if (EQ (p
->command
, Qt
)
6217 && (!EQ (p
->filter
, Qt
) || EQ (p
->status
, Qlisten
)))
6219 FD_SET (p
->infd
, &input_wait_mask
);
6220 FD_SET (p
->infd
, &non_keyboard_wait_mask
);
6222 if (fd_info
[ p
->infd
].flags
& FILE_SERIAL
)
6223 PurgeComm (fd_info
[ p
->infd
].hnd
, PURGE_RXABORT
| PURGE_RXCLEAR
);
6226 tcflush (p
->infd
, TCIFLUSH
);
6234 process_send_signal (process
, SIGCONT
, current_group
, 0);
6236 error ("No SIGCONT support");
6241 DEFUN ("signal-process", Fsignal_process
, Ssignal_process
,
6242 2, 2, "sProcess (name or number): \nnSignal code: ",
6243 doc
: /* Send PROCESS the signal with code SIGCODE.
6244 PROCESS may also be a number specifying the process id of the
6245 process to signal; in this case, the process need not be a child of
6247 SIGCODE may be an integer, or a symbol whose name is a signal name. */)
6249 Lisp_Object process
, sigcode
;
6253 if (INTEGERP (process
))
6255 pid
= XINT (process
);
6259 if (FLOATP (process
))
6261 pid
= (pid_t
) XFLOAT_DATA (process
);
6265 if (STRINGP (process
))
6268 if (tem
= Fget_process (process
), NILP (tem
))
6270 pid
= XINT (Fstring_to_number (process
, make_number (10)));
6277 process
= get_process (process
);
6282 CHECK_PROCESS (process
);
6283 pid
= XPROCESS (process
)->pid
;
6285 error ("Cannot signal process %s", SDATA (XPROCESS (process
)->name
));
6289 #define parse_signal(NAME, VALUE) \
6290 else if (!xstrcasecmp (name, NAME)) \
6291 XSETINT (sigcode, VALUE)
6293 if (INTEGERP (sigcode
))
6297 unsigned char *name
;
6299 CHECK_SYMBOL (sigcode
);
6300 name
= SDATA (SYMBOL_NAME (sigcode
));
6302 if (!strncmp(name
, "SIG", 3) || !strncmp(name
, "sig", 3))
6308 parse_signal ("usr1", SIGUSR1
);
6311 parse_signal ("usr2", SIGUSR2
);
6314 parse_signal ("term", SIGTERM
);
6317 parse_signal ("hup", SIGHUP
);
6320 parse_signal ("int", SIGINT
);
6323 parse_signal ("quit", SIGQUIT
);
6326 parse_signal ("ill", SIGILL
);
6329 parse_signal ("abrt", SIGABRT
);
6332 parse_signal ("emt", SIGEMT
);
6335 parse_signal ("kill", SIGKILL
);
6338 parse_signal ("fpe", SIGFPE
);
6341 parse_signal ("bus", SIGBUS
);
6344 parse_signal ("segv", SIGSEGV
);
6347 parse_signal ("sys", SIGSYS
);
6350 parse_signal ("pipe", SIGPIPE
);
6353 parse_signal ("alrm", SIGALRM
);
6356 parse_signal ("urg", SIGURG
);
6359 parse_signal ("stop", SIGSTOP
);
6362 parse_signal ("tstp", SIGTSTP
);
6365 parse_signal ("cont", SIGCONT
);
6368 parse_signal ("chld", SIGCHLD
);
6371 parse_signal ("ttin", SIGTTIN
);
6374 parse_signal ("ttou", SIGTTOU
);
6377 parse_signal ("io", SIGIO
);
6380 parse_signal ("xcpu", SIGXCPU
);
6383 parse_signal ("xfsz", SIGXFSZ
);
6386 parse_signal ("vtalrm", SIGVTALRM
);
6389 parse_signal ("prof", SIGPROF
);
6392 parse_signal ("winch", SIGWINCH
);
6395 parse_signal ("info", SIGINFO
);
6398 error ("Undefined signal name %s", name
);
6403 return make_number (kill (pid
, XINT (sigcode
)));
6406 DEFUN ("process-send-eof", Fprocess_send_eof
, Sprocess_send_eof
, 0, 1, 0,
6407 doc
: /* Make PROCESS see end-of-file in its input.
6408 EOF comes after any text already sent to it.
6409 PROCESS may be a process, a buffer, the name of a process or buffer, or
6410 nil, indicating the current buffer's process.
6411 If PROCESS is a network connection, or is a process communicating
6412 through a pipe (as opposed to a pty), then you cannot send any more
6413 text to PROCESS after you call this function.
6414 If PROCESS is a serial process, wait until all output written to the
6415 process has been transmitted to the serial port. */)
6417 Lisp_Object process
;
6420 struct coding_system
*coding
;
6422 if (DATAGRAM_CONN_P (process
))
6425 proc
= get_process (process
);
6426 coding
= proc_encode_coding_system
[XPROCESS (proc
)->outfd
];
6428 /* Make sure the process is really alive. */
6429 if (XPROCESS (proc
)->raw_status_new
)
6430 update_status (XPROCESS (proc
));
6431 if (! EQ (XPROCESS (proc
)->status
, Qrun
))
6432 error ("Process %s not running", SDATA (XPROCESS (proc
)->name
));
6434 if (CODING_REQUIRE_FLUSHING (coding
))
6436 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
6437 send_process (proc
, "", 0, Qnil
);
6440 if (XPROCESS (proc
)->pty_flag
)
6441 send_process (proc
, "\004", 1, Qnil
);
6442 else if (EQ (XPROCESS (proc
)->type
, Qserial
))
6445 if (tcdrain (XPROCESS (proc
)->outfd
) != 0)
6446 error ("tcdrain() failed: %s", emacs_strerror (errno
));
6448 /* Do nothing on Windows because writes are blocking. */
6452 int old_outfd
, new_outfd
;
6454 #ifdef HAVE_SHUTDOWN
6455 /* If this is a network connection, or socketpair is used
6456 for communication with the subprocess, call shutdown to cause EOF.
6457 (In some old system, shutdown to socketpair doesn't work.
6458 Then we just can't win.) */
6459 if (EQ (XPROCESS (proc
)->type
, Qnetwork
)
6460 || XPROCESS (proc
)->outfd
== XPROCESS (proc
)->infd
)
6461 shutdown (XPROCESS (proc
)->outfd
, 1);
6462 /* In case of socketpair, outfd == infd, so don't close it. */
6463 if (XPROCESS (proc
)->outfd
!= XPROCESS (proc
)->infd
)
6464 emacs_close (XPROCESS (proc
)->outfd
);
6465 #else /* not HAVE_SHUTDOWN */
6466 emacs_close (XPROCESS (proc
)->outfd
);
6467 #endif /* not HAVE_SHUTDOWN */
6468 new_outfd
= emacs_open (NULL_DEVICE
, O_WRONLY
, 0);
6471 old_outfd
= XPROCESS (proc
)->outfd
;
6473 if (!proc_encode_coding_system
[new_outfd
])
6474 proc_encode_coding_system
[new_outfd
]
6475 = (struct coding_system
*) xmalloc (sizeof (struct coding_system
));
6476 bcopy (proc_encode_coding_system
[old_outfd
],
6477 proc_encode_coding_system
[new_outfd
],
6478 sizeof (struct coding_system
));
6479 bzero (proc_encode_coding_system
[old_outfd
],
6480 sizeof (struct coding_system
));
6482 XPROCESS (proc
)->outfd
= new_outfd
;
6487 /* Kill all processes associated with `buffer'.
6488 If `buffer' is nil, kill all processes */
6491 kill_buffer_processes (buffer
)
6494 Lisp_Object tail
, proc
;
6496 for (tail
= Vprocess_alist
; CONSP (tail
); tail
= XCDR (tail
))
6498 proc
= XCDR (XCAR (tail
));
6500 && (NILP (buffer
) || EQ (XPROCESS (proc
)->buffer
, buffer
)))
6502 if (NETCONN_P (proc
) || SERIALCONN_P (proc
))
6503 Fdelete_process (proc
);
6504 else if (XPROCESS (proc
)->infd
>= 0)
6505 process_send_signal (proc
, SIGHUP
, Qnil
, 1);
6510 /* On receipt of a signal that a child status has changed, loop asking
6511 about children with changed statuses until the system says there
6514 All we do is change the status; we do not run sentinels or print
6515 notifications. That is saved for the next time keyboard input is
6516 done, in order to avoid timing errors.
6518 ** WARNING: this can be called during garbage collection.
6519 Therefore, it must not be fooled by the presence of mark bits in
6522 ** USG WARNING: Although it is not obvious from the documentation
6523 in signal(2), on a USG system the SIGCLD handler MUST NOT call
6524 signal() before executing at least one wait(), otherwise the
6525 handler will be called again, resulting in an infinite loop. The
6526 relevant portion of the documentation reads "SIGCLD signals will be
6527 queued and the signal-catching function will be continually
6528 reentered until the queue is empty". Invoking signal() causes the
6529 kernel to reexamine the SIGCLD queue. Fred Fish, UniSoft Systems
6532 ** Malloc WARNING: This should never call malloc either directly or
6533 indirectly; if it does, that is a bug */
6537 sigchld_handler (signo
)
6540 int old_errno
= errno
;
6542 register struct Lisp_Process
*p
;
6543 extern EMACS_TIME
*input_available_clear_time
;
6545 SIGNAL_THREAD_CHECK (signo
);
6556 #endif /* no WUNTRACED */
6557 /* Keep trying to get a status until we get a definitive result. */
6561 pid
= wait3 (&w
, WNOHANG
| WUNTRACED
, 0);
6563 while (pid
< 0 && errno
== EINTR
);
6567 /* PID == 0 means no processes found, PID == -1 means a real
6568 failure. We have done all our job, so return. */
6570 /* USG systems forget handlers when they are used;
6571 must reestablish each time */
6572 #if defined (USG) && !defined (POSIX_SIGNALS)
6573 signal (signo
, sigchld_handler
); /* WARNING - must come after wait3() */
6580 #endif /* no WNOHANG */
6582 /* Find the process that signaled us, and record its status. */
6584 /* The process can have been deleted by Fdelete_process. */
6585 for (tail
= deleted_pid_list
; CONSP (tail
); tail
= XCDR (tail
))
6587 Lisp_Object xpid
= XCAR (tail
);
6588 if ((INTEGERP (xpid
) && pid
== (pid_t
) XINT (xpid
))
6589 || (FLOATP (xpid
) && pid
== (pid_t
) XFLOAT_DATA (xpid
)))
6591 XSETCAR (tail
, Qnil
);
6592 goto sigchld_end_of_loop
;
6596 /* Otherwise, if it is asynchronous, it is in Vprocess_alist. */
6598 for (tail
= Vprocess_alist
; CONSP (tail
); tail
= XCDR (tail
))
6600 proc
= XCDR (XCAR (tail
));
6601 p
= XPROCESS (proc
);
6602 if (EQ (p
->type
, Qreal
) && p
->pid
== pid
)
6607 /* Look for an asynchronous process whose pid hasn't been filled
6610 for (tail
= Vprocess_alist
; CONSP (tail
); tail
= XCDR (tail
))
6612 proc
= XCDR (XCAR (tail
));
6613 p
= XPROCESS (proc
);
6619 /* Change the status of the process that was found. */
6622 int clear_desc_flag
= 0;
6624 p
->tick
= ++process_tick
;
6626 p
->raw_status_new
= 1;
6628 /* If process has terminated, stop waiting for its output. */
6629 if ((WIFSIGNALED (w
) || WIFEXITED (w
))
6631 clear_desc_flag
= 1;
6633 /* We use clear_desc_flag to avoid a compiler bug in Microsoft C. */
6634 if (clear_desc_flag
)
6636 FD_CLR (p
->infd
, &input_wait_mask
);
6637 FD_CLR (p
->infd
, &non_keyboard_wait_mask
);
6640 /* Tell wait_reading_process_output that it needs to wake up and
6642 if (input_available_clear_time
)
6643 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
6646 /* There was no asynchronous process found for that pid: we have
6647 a synchronous process. */
6650 synch_process_alive
= 0;
6652 /* Report the status of the synchronous process. */
6654 synch_process_retcode
= WRETCODE (w
);
6655 else if (WIFSIGNALED (w
))
6656 synch_process_termsig
= WTERMSIG (w
);
6658 /* Tell wait_reading_process_output that it needs to wake up and
6660 if (input_available_clear_time
)
6661 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
6664 sigchld_end_of_loop
:
6667 /* On some systems, we must return right away.
6668 If any more processes want to signal us, we will
6670 Otherwise (on systems that have WNOHANG), loop around
6671 to use up all the processes that have something to tell us. */
6672 #if (defined WINDOWSNT \
6673 || (defined USG && !defined GNU_LINUX \
6674 && !(defined HPUX && defined WNOHANG)))
6675 #if defined (USG) && ! defined (POSIX_SIGNALS)
6676 signal (signo
, sigchld_handler
);
6680 #endif /* USG, but not HPUX with WNOHANG */
6683 #endif /* SIGCHLD */
6687 exec_sentinel_unwind (data
)
6690 XPROCESS (XCAR (data
))->sentinel
= XCDR (data
);
6695 exec_sentinel_error_handler (error
)
6698 cmd_error_internal (error
, "error in process sentinel: ");
6700 update_echo_area ();
6701 Fsleep_for (make_number (2), Qnil
);
6706 exec_sentinel (proc
, reason
)
6707 Lisp_Object proc
, reason
;
6709 Lisp_Object sentinel
, obuffer
, odeactivate
, okeymap
;
6710 register struct Lisp_Process
*p
= XPROCESS (proc
);
6711 int count
= SPECPDL_INDEX ();
6712 int outer_running_asynch_code
= running_asynch_code
;
6713 int waiting
= waiting_for_user_input_p
;
6715 if (inhibit_sentinels
)
6718 /* No need to gcpro these, because all we do with them later
6719 is test them for EQness, and none of them should be a string. */
6720 odeactivate
= Vdeactivate_mark
;
6721 XSETBUFFER (obuffer
, current_buffer
);
6722 okeymap
= current_buffer
->keymap
;
6724 sentinel
= p
->sentinel
;
6725 if (NILP (sentinel
))
6728 /* Zilch the sentinel while it's running, to avoid recursive invocations;
6729 assure that it gets restored no matter how the sentinel exits. */
6731 record_unwind_protect (exec_sentinel_unwind
, Fcons (proc
, sentinel
));
6732 /* Inhibit quit so that random quits don't screw up a running filter. */
6733 specbind (Qinhibit_quit
, Qt
);
6734 specbind (Qlast_nonmenu_event
, Qt
);
6736 /* In case we get recursively called,
6737 and we already saved the match data nonrecursively,
6738 save the same match data in safely recursive fashion. */
6739 if (outer_running_asynch_code
)
6742 tem
= Fmatch_data (Qnil
, Qnil
, Qnil
);
6743 restore_search_regs ();
6744 record_unwind_save_match_data ();
6745 Fset_match_data (tem
, Qt
);
6748 /* For speed, if a search happens within this code,
6749 save the match data in a special nonrecursive fashion. */
6750 running_asynch_code
= 1;
6752 internal_condition_case_1 (read_process_output_call
,
6754 Fcons (proc
, Fcons (reason
, Qnil
))),
6755 !NILP (Vdebug_on_error
) ? Qnil
: Qerror
,
6756 exec_sentinel_error_handler
);
6758 /* If we saved the match data nonrecursively, restore it now. */
6759 restore_search_regs ();
6760 running_asynch_code
= outer_running_asynch_code
;
6762 Vdeactivate_mark
= odeactivate
;
6764 /* Restore waiting_for_user_input_p as it was
6765 when we were called, in case the filter clobbered it. */
6766 waiting_for_user_input_p
= waiting
;
6769 if (! EQ (Fcurrent_buffer (), obuffer
)
6770 || ! EQ (current_buffer
->keymap
, okeymap
))
6772 /* But do it only if the caller is actually going to read events.
6773 Otherwise there's no need to make him wake up, and it could
6774 cause trouble (for example it would make sit_for return). */
6775 if (waiting_for_user_input_p
== -1)
6776 record_asynch_buffer_change ();
6778 unbind_to (count
, Qnil
);
6781 /* Report all recent events of a change in process status
6782 (either run the sentinel or output a message).
6783 This is usually done while Emacs is waiting for keyboard input
6784 but can be done at other times. */
6787 status_notify (deleting_process
)
6788 struct Lisp_Process
*deleting_process
;
6790 register Lisp_Object proc
, buffer
;
6791 Lisp_Object tail
, msg
;
6792 struct gcpro gcpro1
, gcpro2
;
6796 /* We need to gcpro tail; if read_process_output calls a filter
6797 which deletes a process and removes the cons to which tail points
6798 from Vprocess_alist, and then causes a GC, tail is an unprotected
6802 /* Set this now, so that if new processes are created by sentinels
6803 that we run, we get called again to handle their status changes. */
6804 update_tick
= process_tick
;
6806 for (tail
= Vprocess_alist
; CONSP (tail
); tail
= XCDR (tail
))
6809 register struct Lisp_Process
*p
;
6811 proc
= Fcdr (XCAR (tail
));
6812 p
= XPROCESS (proc
);
6814 if (p
->tick
!= p
->update_tick
)
6816 p
->update_tick
= p
->tick
;
6818 /* If process is still active, read any output that remains. */
6819 while (! EQ (p
->filter
, Qt
)
6820 && ! EQ (p
->status
, Qconnect
)
6821 && ! EQ (p
->status
, Qlisten
)
6822 /* Network or serial process not stopped: */
6823 && ! EQ (p
->command
, Qt
)
6825 && p
!= deleting_process
6826 && read_process_output (proc
, p
->infd
) > 0);
6830 /* Get the text to use for the message. */
6831 if (p
->raw_status_new
)
6833 msg
= status_message (p
);
6835 /* If process is terminated, deactivate it or delete it. */
6837 if (CONSP (p
->status
))
6838 symbol
= XCAR (p
->status
);
6840 if (EQ (symbol
, Qsignal
) || EQ (symbol
, Qexit
)
6841 || EQ (symbol
, Qclosed
))
6843 if (delete_exited_processes
)
6844 remove_process (proc
);
6846 deactivate_process (proc
);
6849 /* The actions above may have further incremented p->tick.
6850 So set p->update_tick again
6851 so that an error in the sentinel will not cause
6852 this code to be run again. */
6853 p
->update_tick
= p
->tick
;
6854 /* Now output the message suitably. */
6855 if (!NILP (p
->sentinel
))
6856 exec_sentinel (proc
, msg
);
6857 /* Don't bother with a message in the buffer
6858 when a process becomes runnable. */
6859 else if (!EQ (symbol
, Qrun
) && !NILP (buffer
))
6861 Lisp_Object ro
, tem
;
6862 struct buffer
*old
= current_buffer
;
6863 int opoint
, opoint_byte
;
6864 int before
, before_byte
;
6866 ro
= XBUFFER (buffer
)->read_only
;
6868 /* Avoid error if buffer is deleted
6869 (probably that's why the process is dead, too) */
6870 if (NILP (XBUFFER (buffer
)->name
))
6872 Fset_buffer (buffer
);
6875 opoint_byte
= PT_BYTE
;
6876 /* Insert new output into buffer
6877 at the current end-of-output marker,
6878 thus preserving logical ordering of input and output. */
6879 if (XMARKER (p
->mark
)->buffer
)
6880 Fgoto_char (p
->mark
);
6882 SET_PT_BOTH (ZV
, ZV_BYTE
);
6885 before_byte
= PT_BYTE
;
6887 tem
= current_buffer
->read_only
;
6888 current_buffer
->read_only
= Qnil
;
6889 insert_string ("\nProcess ");
6890 Finsert (1, &p
->name
);
6891 insert_string (" ");
6893 current_buffer
->read_only
= tem
;
6894 set_marker_both (p
->mark
, p
->buffer
, PT
, PT_BYTE
);
6896 if (opoint
>= before
)
6897 SET_PT_BOTH (opoint
+ (PT
- before
),
6898 opoint_byte
+ (PT_BYTE
- before_byte
));
6900 SET_PT_BOTH (opoint
, opoint_byte
);
6902 set_buffer_internal (old
);
6907 update_mode_lines
++; /* in case buffers use %s in mode-line-format */
6908 redisplay_preserve_echo_area (13);
6914 DEFUN ("set-process-coding-system", Fset_process_coding_system
,
6915 Sset_process_coding_system
, 1, 3, 0,
6916 doc
: /* Set coding systems of PROCESS to DECODING and ENCODING.
6917 DECODING will be used to decode subprocess output and ENCODING to
6918 encode subprocess input. */)
6919 (process
, decoding
, encoding
)
6920 register Lisp_Object process
, decoding
, encoding
;
6922 register struct Lisp_Process
*p
;
6924 CHECK_PROCESS (process
);
6925 p
= XPROCESS (process
);
6927 error ("Input file descriptor of %s closed", SDATA (p
->name
));
6929 error ("Output file descriptor of %s closed", SDATA (p
->name
));
6930 Fcheck_coding_system (decoding
);
6931 Fcheck_coding_system (encoding
);
6932 encoding
= coding_inherit_eol_type (encoding
, Qnil
);
6933 p
->decode_coding_system
= decoding
;
6934 p
->encode_coding_system
= encoding
;
6935 setup_process_coding_systems (process
);
6940 DEFUN ("process-coding-system",
6941 Fprocess_coding_system
, Sprocess_coding_system
, 1, 1, 0,
6942 doc
: /* Return a cons of coding systems for decoding and encoding of PROCESS. */)
6944 register Lisp_Object process
;
6946 CHECK_PROCESS (process
);
6947 return Fcons (XPROCESS (process
)->decode_coding_system
,
6948 XPROCESS (process
)->encode_coding_system
);
6951 DEFUN ("set-process-filter-multibyte", Fset_process_filter_multibyte
,
6952 Sset_process_filter_multibyte
, 2, 2, 0,
6953 doc
: /* Set multibyteness of the strings given to PROCESS's filter.
6954 If FLAG is non-nil, the filter is given multibyte strings.
6955 If FLAG is nil, the filter is given unibyte strings. In this case,
6956 all character code conversion except for end-of-line conversion is
6959 Lisp_Object process
, flag
;
6961 register struct Lisp_Process
*p
;
6963 CHECK_PROCESS (process
);
6964 p
= XPROCESS (process
);
6966 p
->decode_coding_system
= raw_text_coding_system (p
->decode_coding_system
);
6967 setup_process_coding_systems (process
);
6972 DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p
,
6973 Sprocess_filter_multibyte_p
, 1, 1, 0,
6974 doc
: /* Return t if a multibyte string is given to PROCESS's filter.*/)
6976 Lisp_Object process
;
6978 register struct Lisp_Process
*p
;
6979 struct coding_system
*coding
;
6981 CHECK_PROCESS (process
);
6982 p
= XPROCESS (process
);
6983 coding
= proc_decode_coding_system
[p
->infd
];
6984 return (CODING_FOR_UNIBYTE (coding
) ? Qnil
: Qt
);
6989 /* Add DESC to the set of keyboard input descriptors. */
6992 add_keyboard_wait_descriptor (desc
)
6995 FD_SET (desc
, &input_wait_mask
);
6996 FD_SET (desc
, &non_process_wait_mask
);
6997 if (desc
> max_keyboard_desc
)
6998 max_keyboard_desc
= desc
;
7001 static int add_gpm_wait_descriptor_called_flag
;
7004 add_gpm_wait_descriptor (desc
)
7007 if (! add_gpm_wait_descriptor_called_flag
)
7008 FD_CLR (0, &input_wait_mask
);
7009 add_gpm_wait_descriptor_called_flag
= 1;
7010 FD_SET (desc
, &input_wait_mask
);
7011 FD_SET (desc
, &gpm_wait_mask
);
7012 if (desc
> max_gpm_desc
)
7013 max_gpm_desc
= desc
;
7016 /* From now on, do not expect DESC to give keyboard input. */
7019 delete_keyboard_wait_descriptor (desc
)
7023 int lim
= max_keyboard_desc
;
7025 FD_CLR (desc
, &input_wait_mask
);
7026 FD_CLR (desc
, &non_process_wait_mask
);
7028 if (desc
== max_keyboard_desc
)
7029 for (fd
= 0; fd
< lim
; fd
++)
7030 if (FD_ISSET (fd
, &input_wait_mask
)
7031 && !FD_ISSET (fd
, &non_keyboard_wait_mask
)
7032 && !FD_ISSET (fd
, &gpm_wait_mask
))
7033 max_keyboard_desc
= fd
;
7037 delete_gpm_wait_descriptor (desc
)
7041 int lim
= max_gpm_desc
;
7043 FD_CLR (desc
, &input_wait_mask
);
7044 FD_CLR (desc
, &non_process_wait_mask
);
7046 if (desc
== max_gpm_desc
)
7047 for (fd
= 0; fd
< lim
; fd
++)
7048 if (FD_ISSET (fd
, &input_wait_mask
)
7049 && !FD_ISSET (fd
, &non_keyboard_wait_mask
)
7050 && !FD_ISSET (fd
, &non_process_wait_mask
))
7054 /* Return nonzero if *MASK has a bit set
7055 that corresponds to one of the keyboard input descriptors. */
7058 keyboard_bit_set (mask
)
7063 for (fd
= 0; fd
<= max_keyboard_desc
; fd
++)
7064 if (FD_ISSET (fd
, mask
) && FD_ISSET (fd
, &input_wait_mask
)
7065 && !FD_ISSET (fd
, &non_keyboard_wait_mask
))
7071 /* Enumeration of and access to system processes a-la ps(1). */
7073 DEFUN ("list-system-processes", Flist_system_processes
, Slist_system_processes
,
7075 doc
: /* Return a list of numerical process IDs of all running processes.
7076 If this functionality is unsupported, return nil.
7078 See `process-attributes' for getting attributes of a process given its ID. */)
7081 return list_system_processes ();
7084 DEFUN ("process-attributes", Fprocess_attributes
,
7085 Sprocess_attributes
, 1, 1, 0,
7086 doc
: /* Return attributes of the process given by its PID, a number.
7088 Value is an alist where each element is a cons cell of the form
7092 If this functionality is unsupported, the value is nil.
7094 See `list-system-processes' for getting a list of all process IDs.
7096 The KEYs of the attributes that this function may return are listed
7097 below, together with the type of the associated VALUE (in parentheses).
7098 Not all platforms support all of these attributes; unsupported
7099 attributes will not appear in the returned alist.
7100 Unless explicitly indicated otherwise, numbers can have either
7101 integer or floating point values.
7103 euid -- Effective user User ID of the process (number)
7104 user -- User name corresponding to euid (string)
7105 egid -- Effective user Group ID of the process (number)
7106 group -- Group name corresponding to egid (string)
7107 comm -- Command name (executable name only) (string)
7108 state -- Process state code, such as "S", "R", or "T" (string)
7109 ppid -- Parent process ID (number)
7110 pgrp -- Process group ID (number)
7111 sess -- Session ID, i.e. process ID of session leader (number)
7112 ttname -- Controlling tty name (string)
7113 tpgid -- ID of foreground process group on the process's tty (number)
7114 minflt -- number of minor page faults (number)
7115 majflt -- number of major page faults (number)
7116 cminflt -- cumulative number of minor page faults (number)
7117 cmajflt -- cumulative number of major page faults (number)
7118 utime -- user time used by the process, in the (HIGH LOW USEC) format
7119 stime -- system time used by the process, in the (HIGH LOW USEC) format
7120 time -- sum of utime and stime, in the (HIGH LOW USEC) format
7121 cutime -- user time used by the process and its children, (HIGH LOW USEC)
7122 cstime -- system time used by the process and its children, (HIGH LOW USEC)
7123 ctime -- sum of cutime and cstime, in the (HIGH LOW USEC) format
7124 pri -- priority of the process (number)
7125 nice -- nice value of the process (number)
7126 thcount -- process thread count (number)
7127 start -- time the process started, in the (HIGH LOW USEC) format
7128 vsize -- virtual memory size of the process in KB's (number)
7129 rss -- resident set size of the process in KB's (number)
7130 etime -- elapsed time the process is running, in (HIGH LOW USEC) format
7131 pcpu -- percents of CPU time used by the process (floating-point number)
7132 pmem -- percents of total physical memory used by process's resident set
7133 (floating-point number)
7134 args -- command line which invoked the process (string). */)
7139 return system_process_attributes (pid
);
7147 inhibit_sentinels
= 0;
7151 if (! noninteractive
|| initialized
)
7153 signal (SIGCHLD
, sigchld_handler
);
7156 FD_ZERO (&input_wait_mask
);
7157 FD_ZERO (&non_keyboard_wait_mask
);
7158 FD_ZERO (&non_process_wait_mask
);
7159 max_process_desc
= 0;
7161 #ifdef NON_BLOCKING_CONNECT
7162 FD_ZERO (&connect_wait_mask
);
7163 num_pending_connects
= 0;
7166 #ifdef ADAPTIVE_READ_BUFFERING
7167 process_output_delay_count
= 0;
7168 process_output_skip
= 0;
7171 /* Don't do this, it caused infinite select loops. The display
7172 method should call add_keyboard_wait_descriptor on stdin if it
7175 FD_SET (0, &input_wait_mask
);
7178 Vprocess_alist
= Qnil
;
7180 deleted_pid_list
= Qnil
;
7182 for (i
= 0; i
< MAXDESC
; i
++)
7184 chan_process
[i
] = Qnil
;
7185 proc_buffered_char
[i
] = -1;
7187 bzero (proc_decode_coding_system
, sizeof proc_decode_coding_system
);
7188 bzero (proc_encode_coding_system
, sizeof proc_encode_coding_system
);
7189 #ifdef DATAGRAM_SOCKETS
7190 bzero (datagram_address
, sizeof datagram_address
);
7195 Lisp_Object subfeatures
= Qnil
;
7196 struct socket_options
*sopt
;
7198 #define ADD_SUBFEATURE(key, val) \
7199 subfeatures = Fcons (Fcons (key, Fcons (val, Qnil)), subfeatures)
7201 #ifdef NON_BLOCKING_CONNECT
7202 ADD_SUBFEATURE (QCnowait
, Qt
);
7204 #ifdef DATAGRAM_SOCKETS
7205 ADD_SUBFEATURE (QCtype
, Qdatagram
);
7207 #ifdef HAVE_LOCAL_SOCKETS
7208 ADD_SUBFEATURE (QCfamily
, Qlocal
);
7210 ADD_SUBFEATURE (QCfamily
, Qipv4
);
7212 ADD_SUBFEATURE (QCfamily
, Qipv6
);
7214 #ifdef HAVE_GETSOCKNAME
7215 ADD_SUBFEATURE (QCservice
, Qt
);
7217 #if defined(O_NONBLOCK) || defined(O_NDELAY)
7218 ADD_SUBFEATURE (QCserver
, Qt
);
7221 for (sopt
= socket_options
; sopt
->name
; sopt
++)
7222 subfeatures
= Fcons (intern (sopt
->name
), subfeatures
);
7224 Fprovide (intern ("make-network-process"), subfeatures
);
7226 #endif /* HAVE_SOCKETS */
7228 #if defined (DARWIN_OS)
7229 /* PTYs are broken on Darwin < 6, but are sometimes useful for interactive
7230 processes. As such, we only change the default value. */
7233 char *release
= get_operating_system_release();
7234 if (!release
|| !release
[0] || (release
[0] < MIN_PTY_KERNEL_VERSION
7235 && release
[1] == '.')) {
7236 Vprocess_connection_type
= Qnil
;
7245 Qprocessp
= intern ("processp");
7246 staticpro (&Qprocessp
);
7247 Qrun
= intern ("run");
7249 Qstop
= intern ("stop");
7251 Qsignal
= intern ("signal");
7252 staticpro (&Qsignal
);
7254 /* Qexit is already staticpro'd by syms_of_eval; don't staticpro it
7257 Qexit = intern ("exit");
7258 staticpro (&Qexit); */
7260 Qopen
= intern ("open");
7262 Qclosed
= intern ("closed");
7263 staticpro (&Qclosed
);
7264 Qconnect
= intern ("connect");
7265 staticpro (&Qconnect
);
7266 Qfailed
= intern ("failed");
7267 staticpro (&Qfailed
);
7268 Qlisten
= intern ("listen");
7269 staticpro (&Qlisten
);
7270 Qlocal
= intern ("local");
7271 staticpro (&Qlocal
);
7272 Qipv4
= intern ("ipv4");
7275 Qipv6
= intern ("ipv6");
7278 Qdatagram
= intern ("datagram");
7279 staticpro (&Qdatagram
);
7281 QCport
= intern (":port");
7282 staticpro (&QCport
);
7283 QCspeed
= intern (":speed");
7284 staticpro (&QCspeed
);
7285 QCprocess
= intern (":process");
7286 staticpro (&QCprocess
);
7288 QCbytesize
= intern (":bytesize");
7289 staticpro (&QCbytesize
);
7290 QCstopbits
= intern (":stopbits");
7291 staticpro (&QCstopbits
);
7292 QCparity
= intern (":parity");
7293 staticpro (&QCparity
);
7294 Qodd
= intern ("odd");
7296 Qeven
= intern ("even");
7298 QCflowcontrol
= intern (":flowcontrol");
7299 staticpro (&QCflowcontrol
);
7300 Qhw
= intern ("hw");
7302 Qsw
= intern ("sw");
7304 QCsummary
= intern (":summary");
7305 staticpro (&QCsummary
);
7307 Qreal
= intern ("real");
7309 Qnetwork
= intern ("network");
7310 staticpro (&Qnetwork
);
7311 Qserial
= intern ("serial");
7312 staticpro (&Qserial
);
7314 QCname
= intern (":name");
7315 staticpro (&QCname
);
7316 QCbuffer
= intern (":buffer");
7317 staticpro (&QCbuffer
);
7318 QChost
= intern (":host");
7319 staticpro (&QChost
);
7320 QCservice
= intern (":service");
7321 staticpro (&QCservice
);
7322 QCtype
= intern (":type");
7323 staticpro (&QCtype
);
7324 QClocal
= intern (":local");
7325 staticpro (&QClocal
);
7326 QCremote
= intern (":remote");
7327 staticpro (&QCremote
);
7328 QCcoding
= intern (":coding");
7329 staticpro (&QCcoding
);
7330 QCserver
= intern (":server");
7331 staticpro (&QCserver
);
7332 QCnowait
= intern (":nowait");
7333 staticpro (&QCnowait
);
7334 QCsentinel
= intern (":sentinel");
7335 staticpro (&QCsentinel
);
7336 QClog
= intern (":log");
7338 QCnoquery
= intern (":noquery");
7339 staticpro (&QCnoquery
);
7340 QCstop
= intern (":stop");
7341 staticpro (&QCstop
);
7342 QCoptions
= intern (":options");
7343 staticpro (&QCoptions
);
7344 QCplist
= intern (":plist");
7345 staticpro (&QCplist
);
7347 Qlast_nonmenu_event
= intern ("last-nonmenu-event");
7348 staticpro (&Qlast_nonmenu_event
);
7350 staticpro (&Vprocess_alist
);
7352 staticpro (&deleted_pid_list
);
7355 Qeuid
= intern ("euid");
7357 Qegid
= intern ("egid");
7359 Quser
= intern ("user");
7361 Qgroup
= intern ("group");
7362 staticpro (&Qgroup
);
7363 Qcomm
= intern ("comm");
7365 Qstate
= intern ("state");
7366 staticpro (&Qstate
);
7367 Qppid
= intern ("ppid");
7369 Qpgrp
= intern ("pgrp");
7371 Qsess
= intern ("sess");
7373 Qttname
= intern ("ttname");
7374 staticpro (&Qttname
);
7375 Qtpgid
= intern ("tpgid");
7376 staticpro (&Qtpgid
);
7377 Qminflt
= intern ("minflt");
7378 staticpro (&Qminflt
);
7379 Qmajflt
= intern ("majflt");
7380 staticpro (&Qmajflt
);
7381 Qcminflt
= intern ("cminflt");
7382 staticpro (&Qcminflt
);
7383 Qcmajflt
= intern ("cmajflt");
7384 staticpro (&Qcmajflt
);
7385 Qutime
= intern ("utime");
7386 staticpro (&Qutime
);
7387 Qstime
= intern ("stime");
7388 staticpro (&Qstime
);
7389 Qtime
= intern ("time");
7391 Qcutime
= intern ("cutime");
7392 staticpro (&Qcutime
);
7393 Qcstime
= intern ("cstime");
7394 staticpro (&Qcstime
);
7395 Qctime
= intern ("ctime");
7396 staticpro (&Qctime
);
7397 Qpri
= intern ("pri");
7399 Qnice
= intern ("nice");
7401 Qthcount
= intern ("thcount");
7402 staticpro (&Qthcount
);
7403 Qstart
= intern ("start");
7404 staticpro (&Qstart
);
7405 Qvsize
= intern ("vsize");
7406 staticpro (&Qvsize
);
7407 Qrss
= intern ("rss");
7409 Qetime
= intern ("etime");
7410 staticpro (&Qetime
);
7411 Qpcpu
= intern ("pcpu");
7413 Qpmem
= intern ("pmem");
7415 Qargs
= intern ("args");
7418 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes
,
7419 doc
: /* *Non-nil means delete processes immediately when they exit.
7420 A value of nil means don't delete them until `list-processes' is run. */);
7422 delete_exited_processes
= 1;
7424 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type
,
7425 doc
: /* Control type of device used to communicate with subprocesses.
7426 Values are nil to use a pipe, or t or `pty' to use a pty.
7427 The value has no effect if the system has no ptys or if all ptys are busy:
7428 then a pipe is used in any case.
7429 The value takes effect when `start-process' is called. */);
7430 Vprocess_connection_type
= Qt
;
7432 #ifdef ADAPTIVE_READ_BUFFERING
7433 DEFVAR_LISP ("process-adaptive-read-buffering", &Vprocess_adaptive_read_buffering
,
7434 doc
: /* If non-nil, improve receive buffering by delaying after short reads.
7435 On some systems, when Emacs reads the output from a subprocess, the output data
7436 is read in very small blocks, potentially resulting in very poor performance.
7437 This behavior can be remedied to some extent by setting this variable to a
7438 non-nil value, as it will automatically delay reading from such processes, to
7439 allow them to produce more output before Emacs tries to read it.
7440 If the value is t, the delay is reset after each write to the process; any other
7441 non-nil value means that the delay is not reset on write.
7442 The variable takes effect when `start-process' is called. */);
7443 Vprocess_adaptive_read_buffering
= Qt
;
7446 defsubr (&Sprocessp
);
7447 defsubr (&Sget_process
);
7448 defsubr (&Sget_buffer_process
);
7449 defsubr (&Sdelete_process
);
7450 defsubr (&Sprocess_status
);
7451 defsubr (&Sprocess_exit_status
);
7452 defsubr (&Sprocess_id
);
7453 defsubr (&Sprocess_name
);
7454 defsubr (&Sprocess_tty_name
);
7455 defsubr (&Sprocess_command
);
7456 defsubr (&Sset_process_buffer
);
7457 defsubr (&Sprocess_buffer
);
7458 defsubr (&Sprocess_mark
);
7459 defsubr (&Sset_process_filter
);
7460 defsubr (&Sprocess_filter
);
7461 defsubr (&Sset_process_sentinel
);
7462 defsubr (&Sprocess_sentinel
);
7463 defsubr (&Sset_process_window_size
);
7464 defsubr (&Sset_process_inherit_coding_system_flag
);
7465 defsubr (&Sprocess_inherit_coding_system_flag
);
7466 defsubr (&Sset_process_query_on_exit_flag
);
7467 defsubr (&Sprocess_query_on_exit_flag
);
7468 defsubr (&Sprocess_contact
);
7469 defsubr (&Sprocess_plist
);
7470 defsubr (&Sset_process_plist
);
7471 defsubr (&Slist_processes
);
7472 defsubr (&Sprocess_list
);
7473 defsubr (&Sstart_process
);
7475 defsubr (&Sserial_process_configure
);
7476 defsubr (&Smake_serial_process
);
7477 #endif /* HAVE_SERIAL */
7479 defsubr (&Sset_network_process_option
);
7480 defsubr (&Smake_network_process
);
7481 defsubr (&Sformat_network_address
);
7482 #endif /* HAVE_SOCKETS */
7483 #if defined(HAVE_SOCKETS) && defined(HAVE_NET_IF_H) && defined(HAVE_SYS_IOCTL_H)
7485 defsubr (&Snetwork_interface_list
);
7487 #if defined(SIOCGIFADDR) || defined(SIOCGIFHWADDR) || defined(SIOCGIFFLAGS)
7488 defsubr (&Snetwork_interface_info
);
7490 #endif /* HAVE_SOCKETS ... */
7491 #ifdef DATAGRAM_SOCKETS
7492 defsubr (&Sprocess_datagram_address
);
7493 defsubr (&Sset_process_datagram_address
);
7495 defsubr (&Saccept_process_output
);
7496 defsubr (&Sprocess_send_region
);
7497 defsubr (&Sprocess_send_string
);
7498 defsubr (&Sinterrupt_process
);
7499 defsubr (&Skill_process
);
7500 defsubr (&Squit_process
);
7501 defsubr (&Sstop_process
);
7502 defsubr (&Scontinue_process
);
7503 defsubr (&Sprocess_running_child_p
);
7504 defsubr (&Sprocess_send_eof
);
7505 defsubr (&Ssignal_process
);
7506 defsubr (&Swaiting_for_user_input_p
);
7507 defsubr (&Sprocess_type
);
7508 defsubr (&Sset_process_coding_system
);
7509 defsubr (&Sprocess_coding_system
);
7510 defsubr (&Sset_process_filter_multibyte
);
7511 defsubr (&Sprocess_filter_multibyte_p
);
7512 defsubr (&Slist_system_processes
);
7513 defsubr (&Sprocess_attributes
);
7517 #else /* not subprocesses */
7519 #include <sys/types.h>
7521 #include <sys/stat.h>
7524 #ifdef HAVE_UNISTD_H
7529 #include "systime.h"
7530 #include "character.h"
7532 #include "termopts.h"
7533 #include "sysselect.h"
7535 extern int frame_garbaged
;
7537 extern EMACS_TIME
timer_check ();
7538 extern int timers_run
;
7540 Lisp_Object QCtype
, QCname
;
7542 Lisp_Object Qeuid
, Qegid
, Qcomm
, Qstate
, Qppid
, Qpgrp
, Qsess
, Qttname
, Qtpgid
;
7543 Lisp_Object Qminflt
, Qmajflt
, Qcminflt
, Qcmajflt
, Qutime
, Qstime
, Qcstime
;
7544 Lisp_Object Qcutime
, Qpri
, Qnice
, Qthcount
, Qstart
, Qvsize
, Qrss
, Qargs
;
7545 Lisp_Object Quser
, Qgroup
, Qetime
, Qpcpu
, Qpmem
, Qtime
, Qctime
;
7547 /* As described above, except assuming that there are no subprocesses:
7549 Wait for timeout to elapse and/or keyboard input to be available.
7552 timeout in seconds, or
7553 zero for no limit, or
7554 -1 means gobble data immediately available but don't wait for any.
7556 read_kbd is a Lisp_Object:
7557 0 to ignore keyboard input, or
7558 1 to return when input is available, or
7559 -1 means caller will actually read the input, so don't throw to
7562 see full version for other parameters. We know that wait_proc will
7563 always be NULL, since `subprocesses' isn't defined.
7565 do_display != 0 means redisplay should be done to show subprocess
7566 output that arrives.
7568 Return true if we received input from any process. */
7571 wait_reading_process_output (time_limit
, microsecs
, read_kbd
, do_display
,
7572 wait_for_cell
, wait_proc
, just_wait_proc
)
7573 int time_limit
, microsecs
, read_kbd
, do_display
;
7574 Lisp_Object wait_for_cell
;
7575 struct Lisp_Process
*wait_proc
;
7579 EMACS_TIME end_time
, timeout
;
7580 SELECT_TYPE waitchannels
;
7583 /* What does time_limit really mean? */
7584 if (time_limit
|| microsecs
)
7586 EMACS_GET_TIME (end_time
);
7587 EMACS_SET_SECS_USECS (timeout
, time_limit
, microsecs
);
7588 EMACS_ADD_TIME (end_time
, end_time
, timeout
);
7591 /* Turn off periodic alarms (in case they are in use)
7592 and then turn off any other atimers,
7593 because the select emulator uses alarms. */
7595 turn_on_atimers (0);
7599 int timeout_reduced_for_timers
= 0;
7601 /* If calling from keyboard input, do not quit
7602 since we want to return C-g as an input character.
7603 Otherwise, do pending quit if requested. */
7607 /* Exit now if the cell we're waiting for became non-nil. */
7608 if (! NILP (wait_for_cell
) && ! NILP (XCAR (wait_for_cell
)))
7611 /* Compute time from now till when time limit is up */
7612 /* Exit if already run out */
7613 if (time_limit
== -1)
7615 /* -1 specified for timeout means
7616 gobble output available now
7617 but don't wait at all. */
7619 EMACS_SET_SECS_USECS (timeout
, 0, 0);
7621 else if (time_limit
|| microsecs
)
7623 EMACS_GET_TIME (timeout
);
7624 EMACS_SUB_TIME (timeout
, end_time
, timeout
);
7625 if (EMACS_TIME_NEG_P (timeout
))
7630 EMACS_SET_SECS_USECS (timeout
, 100000, 0);
7633 /* If our caller will not immediately handle keyboard events,
7634 run timer events directly.
7635 (Callers that will immediately read keyboard events
7636 call timer_delay on their own.) */
7637 if (NILP (wait_for_cell
))
7639 EMACS_TIME timer_delay
;
7643 int old_timers_run
= timers_run
;
7644 timer_delay
= timer_check (1);
7645 if (timers_run
!= old_timers_run
&& do_display
)
7646 /* We must retry, since a timer may have requeued itself
7647 and that could alter the time delay. */
7648 redisplay_preserve_echo_area (14);
7652 while (!detect_input_pending ());
7654 /* If there is unread keyboard input, also return. */
7656 && requeued_events_pending_p ())
7659 if (! EMACS_TIME_NEG_P (timer_delay
) && time_limit
!= -1)
7661 EMACS_TIME difference
;
7662 EMACS_SUB_TIME (difference
, timer_delay
, timeout
);
7663 if (EMACS_TIME_NEG_P (difference
))
7665 timeout
= timer_delay
;
7666 timeout_reduced_for_timers
= 1;
7671 /* Cause C-g and alarm signals to take immediate action,
7672 and cause input available signals to zero out timeout. */
7674 set_waiting_for_input (&timeout
);
7676 /* Wait till there is something to do. */
7678 if (! read_kbd
&& NILP (wait_for_cell
))
7679 FD_ZERO (&waitchannels
);
7681 FD_SET (0, &waitchannels
);
7683 /* If a frame has been newly mapped and needs updating,
7684 reprocess its display stuff. */
7685 if (frame_garbaged
&& do_display
)
7687 clear_waiting_for_input ();
7688 redisplay_preserve_echo_area (15);
7690 set_waiting_for_input (&timeout
);
7693 if (read_kbd
&& detect_input_pending ())
7696 FD_ZERO (&waitchannels
);
7699 nfds
= select (1, &waitchannels
, (SELECT_TYPE
*)0, (SELECT_TYPE
*)0,
7704 /* Make C-g and alarm signals set flags again */
7705 clear_waiting_for_input ();
7707 /* If we woke up due to SIGWINCH, actually change size now. */
7708 do_pending_window_change (0);
7710 if (time_limit
&& nfds
== 0 && ! timeout_reduced_for_timers
)
7711 /* We waited the full specified time, so return now. */
7716 /* If the system call was interrupted, then go around the
7718 if (xerrno
== EINTR
)
7719 FD_ZERO (&waitchannels
);
7721 error ("select error: %s", emacs_strerror (xerrno
));
7724 else if (nfds
> 0 && (waitchannels
& 1) && interrupt_input
)
7725 /* System sometimes fails to deliver SIGIO. */
7726 kill (getpid (), SIGIO
);
7729 if (read_kbd
&& interrupt_input
&& (waitchannels
& 1))
7730 kill (getpid (), SIGIO
);
7733 /* Check for keyboard input */
7736 && detect_input_pending_run_timers (do_display
))
7738 swallow_events (do_display
);
7739 if (detect_input_pending_run_timers (do_display
))
7743 /* If there is unread keyboard input, also return. */
7745 && requeued_events_pending_p ())
7748 /* If wait_for_cell. check for keyboard input
7749 but don't run any timers.
7750 ??? (It seems wrong to me to check for keyboard
7751 input at all when wait_for_cell, but the code
7752 has been this way since July 1994.
7753 Try changing this after version 19.31.) */
7754 if (! NILP (wait_for_cell
)
7755 && detect_input_pending ())
7757 swallow_events (do_display
);
7758 if (detect_input_pending ())
7762 /* Exit now if the cell we're waiting for became non-nil. */
7763 if (! NILP (wait_for_cell
) && ! NILP (XCAR (wait_for_cell
)))
7773 /* Don't confuse make-docfile by having two doc strings for this function.
7774 make-docfile does not pay attention to #if, for good reason! */
7775 DEFUN ("get-buffer-process", Fget_buffer_process
, Sget_buffer_process
, 1, 1, 0,
7778 register Lisp_Object name
;
7783 /* Don't confuse make-docfile by having two doc strings for this function.
7784 make-docfile does not pay attention to #if, for good reason! */
7785 DEFUN ("process-inherit-coding-system-flag",
7786 Fprocess_inherit_coding_system_flag
, Sprocess_inherit_coding_system_flag
,
7790 register Lisp_Object process
;
7792 /* Ignore the argument and return the value of
7793 inherit-process-coding-system. */
7794 return inherit_process_coding_system
? Qt
: Qnil
;
7797 /* Kill all processes associated with `buffer'.
7798 If `buffer' is nil, kill all processes.
7799 Since we have no subprocesses, this does nothing. */
7802 kill_buffer_processes (buffer
)
7807 DEFUN ("list-system-processes", Flist_system_processes
, Slist_system_processes
,
7809 doc
: /* Return a list of numerical process IDs of all running processes.
7810 If this functionality is unsupported, return nil.
7812 See `process-attributes' for getting attributes of a process given its ID. */)
7815 return list_system_processes ();
7818 DEFUN ("process-attributes", Fprocess_attributes
,
7819 Sprocess_attributes
, 1, 1, 0,
7820 doc
: /* Return attributes of the process given by its PID, a number.
7822 Value is an alist where each element is a cons cell of the form
7826 If this functionality is unsupported, the value is nil.
7828 See `list-system-processes' for getting a list of all process IDs.
7830 The KEYs of the attributes that this function may return are listed
7831 below, together with the type of the associated VALUE (in parentheses).
7832 Not all platforms support all of these attributes; unsupported
7833 attributes will not appear in the returned alist.
7834 Unless explicitly indicated otherwise, numbers can have either
7835 integer or floating point values.
7837 euid -- Effective user User ID of the process (number)
7838 user -- User name corresponding to euid (string)
7839 egid -- Effective user Group ID of the process (number)
7840 group -- Group name corresponding to egid (string)
7841 comm -- Command name (executable name only) (string)
7842 state -- Process state code, such as "S", "R", or "T" (string)
7843 ppid -- Parent process ID (number)
7844 pgrp -- Process group ID (number)
7845 sess -- Session ID, i.e. process ID of session leader (number)
7846 ttname -- Controlling tty name (string)
7847 tpgid -- ID of foreground process group on the process's tty (number)
7848 minflt -- number of minor page faults (number)
7849 majflt -- number of major page faults (number)
7850 cminflt -- cumulative number of minor page faults (number)
7851 cmajflt -- cumulative number of major page faults (number)
7852 utime -- user time used by the process, in the (HIGH LOW USEC) format
7853 stime -- system time used by the process, in the (HIGH LOW USEC) format
7854 time -- sum of utime and stime, in the (HIGH LOW USEC) format
7855 cutime -- user time used by the process and its children, (HIGH LOW USEC)
7856 cstime -- system time used by the process and its children, (HIGH LOW USEC)
7857 ctime -- sum of cutime and cstime, in the (HIGH LOW USEC) format
7858 pri -- priority of the process (number)
7859 nice -- nice value of the process (number)
7860 thcount -- process thread count (number)
7861 start -- time the process started, in the (HIGH LOW USEC) format
7862 vsize -- virtual memory size of the process in KB's (number)
7863 rss -- resident set size of the process in KB's (number)
7864 etime -- elapsed time the process is running, in (HIGH LOW USEC) format
7865 pcpu -- percents of CPU time used by the process (floating-point number)
7866 pmem -- percents of total physical memory used by process's resident set
7867 (floating-point number)
7868 args -- command line which invoked the process (string). */)
7873 return system_process_attributes (pid
);
7884 QCtype
= intern (":type");
7885 staticpro (&QCtype
);
7886 QCname
= intern (":name");
7887 staticpro (&QCname
);
7888 QCtype
= intern (":type");
7889 staticpro (&QCtype
);
7890 QCname
= intern (":name");
7891 staticpro (&QCname
);
7892 Qeuid
= intern ("euid");
7894 Qegid
= intern ("egid");
7896 Quser
= intern ("user");
7898 Qgroup
= intern ("group");
7899 staticpro (&Qgroup
);
7900 Qcomm
= intern ("comm");
7902 Qstate
= intern ("state");
7903 staticpro (&Qstate
);
7904 Qppid
= intern ("ppid");
7906 Qpgrp
= intern ("pgrp");
7908 Qsess
= intern ("sess");
7910 Qttname
= intern ("ttname");
7911 staticpro (&Qttname
);
7912 Qtpgid
= intern ("tpgid");
7913 staticpro (&Qtpgid
);
7914 Qminflt
= intern ("minflt");
7915 staticpro (&Qminflt
);
7916 Qmajflt
= intern ("majflt");
7917 staticpro (&Qmajflt
);
7918 Qcminflt
= intern ("cminflt");
7919 staticpro (&Qcminflt
);
7920 Qcmajflt
= intern ("cmajflt");
7921 staticpro (&Qcmajflt
);
7922 Qutime
= intern ("utime");
7923 staticpro (&Qutime
);
7924 Qstime
= intern ("stime");
7925 staticpro (&Qstime
);
7926 Qtime
= intern ("time");
7928 Qcutime
= intern ("cutime");
7929 staticpro (&Qcutime
);
7930 Qcstime
= intern ("cstime");
7931 staticpro (&Qcstime
);
7932 Qctime
= intern ("ctime");
7933 staticpro (&Qctime
);
7934 Qpri
= intern ("pri");
7936 Qnice
= intern ("nice");
7938 Qthcount
= intern ("thcount");
7939 staticpro (&Qthcount
);
7940 Qstart
= intern ("start");
7941 staticpro (&Qstart
);
7942 Qvsize
= intern ("vsize");
7943 staticpro (&Qvsize
);
7944 Qrss
= intern ("rss");
7946 Qetime
= intern ("etime");
7947 staticpro (&Qetime
);
7948 Qpcpu
= intern ("pcpu");
7950 Qpmem
= intern ("pmem");
7952 Qargs
= intern ("args");
7955 defsubr (&Sget_buffer_process
);
7956 defsubr (&Sprocess_inherit_coding_system_flag
);
7957 defsubr (&Slist_system_processes
);
7958 defsubr (&Sprocess_attributes
);
7962 #endif /* not subprocesses */
7964 /* arch-tag: 3706c011-7b9a-4117-bd4f-59e7f701a4c4
7965 (do not change this comment) */