diff options
| author | Ken Raeburn | 2015-11-01 01:42:21 -0400 |
|---|---|---|
| committer | Ken Raeburn | 2015-11-01 01:42:21 -0400 |
| commit | 39372e1a1032521be74575bb06f95a3898fbae30 (patch) | |
| tree | 754bd242a23d2358ea116126fcb0a629947bd9ec /src/process.c | |
| parent | 6a3121904d76e3b2f63007341d48c5c1af55de80 (diff) | |
| parent | e11aaee266da52937a3a031cb108fe13f68958c3 (diff) | |
| download | emacs-39372e1a1032521be74575bb06f95a3898fbae30.tar.gz emacs-39372e1a1032521be74575bb06f95a3898fbae30.zip | |
merge from trunk
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 1862 |
1 files changed, 1098 insertions, 764 deletions
diff --git a/src/process.c b/src/process.c index 899c0035866..791f8f5c308 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Asynchronous subprocess control for GNU Emacs. | 1 | /* Asynchronous subprocess control for GNU Emacs. |
| 2 | 2 | ||
| 3 | Copyright (C) 1985-1988, 1993-1996, 1998-1999, 2001-2013 Free Software | 3 | Copyright (C) 1985-1988, 1993-1996, 1998-1999, 2001-2015 Free Software |
| 4 | Foundation, Inc. | 4 | Foundation, Inc. |
| 5 | 5 | ||
| 6 | This file is part of GNU Emacs. | 6 | This file is part of GNU Emacs. |
| @@ -21,8 +21,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 21 | 21 | ||
| 22 | #include <config.h> | 22 | #include <config.h> |
| 23 | 23 | ||
| 24 | #define PROCESS_INLINE EXTERN_INLINE | ||
| 25 | |||
| 26 | #include <stdio.h> | 24 | #include <stdio.h> |
| 27 | #include <errno.h> | 25 | #include <errno.h> |
| 28 | #include <sys/types.h> /* Some typedefs are used in sys/file.h. */ | 26 | #include <sys/types.h> /* Some typedefs are used in sys/file.h. */ |
| @@ -105,13 +103,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 105 | #include "coding.h" | 103 | #include "coding.h" |
| 106 | #include "process.h" | 104 | #include "process.h" |
| 107 | #include "frame.h" | 105 | #include "frame.h" |
| 108 | #include "termhooks.h" | ||
| 109 | #include "termopts.h" | 106 | #include "termopts.h" |
| 110 | #include "commands.h" | ||
| 111 | #include "keyboard.h" | 107 | #include "keyboard.h" |
| 112 | #include "blockinput.h" | 108 | #include "blockinput.h" |
| 113 | #include "dispextern.h" | ||
| 114 | #include "composite.h" | ||
| 115 | #include "atimer.h" | 109 | #include "atimer.h" |
| 116 | #include "sysselect.h" | 110 | #include "sysselect.h" |
| 117 | #include "syssignal.h" | 111 | #include "syssignal.h" |
| @@ -135,6 +129,23 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 135 | #include "w32.h" | 129 | #include "w32.h" |
| 136 | #endif | 130 | #endif |
| 137 | 131 | ||
| 132 | /* Work around GCC 4.7.0 bug with strict overflow checking; see | ||
| 133 | <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52904>. | ||
| 134 | This bug appears to be fixed in GCC 5.1, so don't work around it there. */ | ||
| 135 | #if __GNUC__ == 4 && __GNUC_MINOR__ >= 3 | ||
| 136 | # pragma GCC diagnostic ignored "-Wstrict-overflow" | ||
| 137 | #endif | ||
| 138 | |||
| 139 | /* True if keyboard input is on hold, zero otherwise. */ | ||
| 140 | |||
| 141 | static bool kbd_is_on_hold; | ||
| 142 | |||
| 143 | /* Nonzero means don't run process sentinels. This is used | ||
| 144 | when exiting. */ | ||
| 145 | bool inhibit_sentinels; | ||
| 146 | |||
| 147 | #ifdef subprocesses | ||
| 148 | |||
| 138 | #ifndef SOCK_CLOEXEC | 149 | #ifndef SOCK_CLOEXEC |
| 139 | # define SOCK_CLOEXEC 0 | 150 | # define SOCK_CLOEXEC 0 |
| 140 | #endif | 151 | #endif |
| @@ -151,6 +162,9 @@ close_on_exec (int fd) | |||
| 151 | return fd; | 162 | return fd; |
| 152 | } | 163 | } |
| 153 | 164 | ||
| 165 | # undef accept4 | ||
| 166 | # define accept4(sockfd, addr, addrlen, flags) \ | ||
| 167 | process_accept4 (sockfd, addr, addrlen, flags) | ||
| 154 | static int | 168 | static int |
| 155 | accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) | 169 | accept4 (int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) |
| 156 | { | 170 | { |
| @@ -166,77 +180,27 @@ process_socket (int domain, int type, int protocol) | |||
| 166 | # define socket(domain, type, protocol) process_socket (domain, type, protocol) | 180 | # define socket(domain, type, protocol) process_socket (domain, type, protocol) |
| 167 | #endif | 181 | #endif |
| 168 | 182 | ||
| 169 | /* Work around GCC 4.7.0 bug with strict overflow checking; see | ||
| 170 | <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52904>. | ||
| 171 | These lines can be removed once the GCC bug is fixed. */ | ||
| 172 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) | ||
| 173 | # pragma GCC diagnostic ignored "-Wstrict-overflow" | ||
| 174 | #endif | ||
| 175 | |||
| 176 | Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid; | ||
| 177 | Lisp_Object Qminflt, Qmajflt, Qcminflt, Qcmajflt, Qutime, Qstime, Qcstime; | ||
| 178 | Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs; | ||
| 179 | Lisp_Object Quser, Qgroup, Qetime, Qpcpu, Qpmem, Qtime, Qctime; | ||
| 180 | Lisp_Object QCname, QCtype; | ||
| 181 | |||
| 182 | /* True if keyboard input is on hold, zero otherwise. */ | ||
| 183 | |||
| 184 | static bool kbd_is_on_hold; | ||
| 185 | |||
| 186 | /* Nonzero means don't run process sentinels. This is used | ||
| 187 | when exiting. */ | ||
| 188 | bool inhibit_sentinels; | ||
| 189 | |||
| 190 | #ifdef subprocesses | ||
| 191 | |||
| 192 | Lisp_Object Qprocessp; | ||
| 193 | static Lisp_Object Qrun, Qstop, Qsignal; | ||
| 194 | static Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten; | ||
| 195 | Lisp_Object Qlocal; | ||
| 196 | static Lisp_Object Qipv4, Qdatagram, Qseqpacket; | ||
| 197 | static Lisp_Object Qreal, Qnetwork, Qserial; | ||
| 198 | #ifdef AF_INET6 | ||
| 199 | static Lisp_Object Qipv6; | ||
| 200 | #endif | ||
| 201 | static Lisp_Object QCport, QCprocess; | ||
| 202 | Lisp_Object QCspeed; | ||
| 203 | Lisp_Object QCbytesize, QCstopbits, QCparity, Qodd, Qeven; | ||
| 204 | Lisp_Object QCflowcontrol, Qhw, Qsw, QCsummary; | ||
| 205 | static Lisp_Object QCbuffer, QChost, QCservice; | ||
| 206 | static Lisp_Object QClocal, QCremote, QCcoding; | ||
| 207 | static Lisp_Object QCserver, QCnowait, QCnoquery, QCstop; | ||
| 208 | static Lisp_Object QCsentinel, QClog, QCoptions, QCplist; | ||
| 209 | static Lisp_Object Qlast_nonmenu_event; | ||
| 210 | static Lisp_Object Qinternal_default_process_sentinel; | ||
| 211 | static Lisp_Object Qinternal_default_process_filter; | ||
| 212 | |||
| 213 | #define NETCONN_P(p) (EQ (XPROCESS (p)->type, Qnetwork)) | 183 | #define NETCONN_P(p) (EQ (XPROCESS (p)->type, Qnetwork)) |
| 214 | #define NETCONN1_P(p) (EQ (p->type, Qnetwork)) | 184 | #define NETCONN1_P(p) (EQ (p->type, Qnetwork)) |
| 215 | #define SERIALCONN_P(p) (EQ (XPROCESS (p)->type, Qserial)) | 185 | #define SERIALCONN_P(p) (EQ (XPROCESS (p)->type, Qserial)) |
| 216 | #define SERIALCONN1_P(p) (EQ (p->type, Qserial)) | 186 | #define SERIALCONN1_P(p) (EQ (p->type, Qserial)) |
| 187 | #define PIPECONN_P(p) (EQ (XPROCESS (p)->type, Qpipe)) | ||
| 188 | #define PIPECONN1_P(p) (EQ (p->type, Qpipe)) | ||
| 217 | 189 | ||
| 218 | /* Number of events of change of status of a process. */ | 190 | /* Number of events of change of status of a process. */ |
| 219 | static EMACS_INT process_tick; | 191 | static EMACS_INT process_tick; |
| 220 | /* Number of events for which the user or sentinel has been notified. */ | 192 | /* Number of events for which the user or sentinel has been notified. */ |
| 221 | static EMACS_INT update_tick; | 193 | static EMACS_INT update_tick; |
| 222 | 194 | ||
| 223 | /* Define NON_BLOCKING_CONNECT if we can support non-blocking connects. */ | 195 | /* Define NON_BLOCKING_CONNECT if we can support non-blocking connects. |
| 196 | The code can be simplified by assuming NON_BLOCKING_CONNECT once | ||
| 197 | Emacs starts assuming POSIX 1003.1-2001 or later. */ | ||
| 224 | 198 | ||
| 225 | /* Only W32 has this, it really means that select can't take write mask. */ | 199 | #if (defined HAVE_SELECT \ |
| 226 | #ifdef BROKEN_NON_BLOCKING_CONNECT | 200 | && (defined GNU_LINUX || defined HAVE_GETPEERNAME) \ |
| 227 | #undef NON_BLOCKING_CONNECT | 201 | && (defined EWOULDBLOCK || defined EINPROGRESS)) |
| 228 | #define SELECT_CANT_DO_WRITE_MASK | 202 | # define NON_BLOCKING_CONNECT |
| 229 | #else | 203 | #endif |
| 230 | #ifndef NON_BLOCKING_CONNECT | ||
| 231 | #ifdef HAVE_SELECT | ||
| 232 | #if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX) | ||
| 233 | #if defined (EWOULDBLOCK) || defined (EINPROGRESS) | ||
| 234 | #define NON_BLOCKING_CONNECT | ||
| 235 | #endif /* EWOULDBLOCK || EINPROGRESS */ | ||
| 236 | #endif /* HAVE_GETPEERNAME || GNU_LINUX */ | ||
| 237 | #endif /* HAVE_SELECT */ | ||
| 238 | #endif /* NON_BLOCKING_CONNECT */ | ||
| 239 | #endif /* BROKEN_NON_BLOCKING_CONNECT */ | ||
| 240 | 204 | ||
| 241 | /* Define DATAGRAM_SOCKETS if datagrams can be used safely on | 205 | /* Define DATAGRAM_SOCKETS if datagrams can be used safely on |
| 242 | this system. We need to read full packets, so we need a | 206 | this system. We need to read full packets, so we need a |
| @@ -255,12 +219,7 @@ static EMACS_INT update_tick; | |||
| 255 | # define HAVE_SEQPACKET | 219 | # define HAVE_SEQPACKET |
| 256 | #endif | 220 | #endif |
| 257 | 221 | ||
| 258 | #if !defined (ADAPTIVE_READ_BUFFERING) && !defined (NO_ADAPTIVE_READ_BUFFERING) | 222 | #define READ_OUTPUT_DELAY_INCREMENT (TIMESPEC_RESOLUTION / 100) |
| 259 | #define ADAPTIVE_READ_BUFFERING | ||
| 260 | #endif | ||
| 261 | |||
| 262 | #ifdef ADAPTIVE_READ_BUFFERING | ||
| 263 | #define READ_OUTPUT_DELAY_INCREMENT (EMACS_TIME_RESOLUTION / 100) | ||
| 264 | #define READ_OUTPUT_DELAY_MAX (READ_OUTPUT_DELAY_INCREMENT * 5) | 223 | #define READ_OUTPUT_DELAY_MAX (READ_OUTPUT_DELAY_INCREMENT * 5) |
| 265 | #define READ_OUTPUT_DELAY_MAX_MAX (READ_OUTPUT_DELAY_INCREMENT * 7) | 224 | #define READ_OUTPUT_DELAY_MAX_MAX (READ_OUTPUT_DELAY_INCREMENT * 7) |
| 266 | 225 | ||
| @@ -273,26 +232,16 @@ static int process_output_delay_count; | |||
| 273 | 232 | ||
| 274 | static bool process_output_skip; | 233 | static bool process_output_skip; |
| 275 | 234 | ||
| 276 | #else | ||
| 277 | #define process_output_delay_count 0 | ||
| 278 | #endif | ||
| 279 | |||
| 280 | static void create_process (Lisp_Object, char **, Lisp_Object); | 235 | static void create_process (Lisp_Object, char **, Lisp_Object); |
| 281 | #ifdef USABLE_SIGIO | 236 | #ifdef USABLE_SIGIO |
| 282 | static bool keyboard_bit_set (SELECT_TYPE *); | 237 | static bool keyboard_bit_set (fd_set *); |
| 283 | #endif | 238 | #endif |
| 284 | static void deactivate_process (Lisp_Object); | 239 | static void deactivate_process (Lisp_Object); |
| 285 | static void status_notify (struct Lisp_Process *); | 240 | static int status_notify (struct Lisp_Process *, struct Lisp_Process *); |
| 286 | static int read_process_output (Lisp_Object, int); | 241 | static int read_process_output (Lisp_Object, int); |
| 287 | static void handle_child_signal (int); | 242 | static void handle_child_signal (int); |
| 288 | static void create_pty (Lisp_Object); | 243 | static void create_pty (Lisp_Object); |
| 289 | 244 | ||
| 290 | /* If we support a window system, turn on the code to poll periodically | ||
| 291 | to detect C-g. It isn't actually used when doing interrupt input. */ | ||
| 292 | #ifdef HAVE_WINDOW_SYSTEM | ||
| 293 | #define POLL_FOR_INPUT | ||
| 294 | #endif | ||
| 295 | |||
| 296 | static Lisp_Object get_process (register Lisp_Object name); | 245 | static Lisp_Object get_process (register Lisp_Object name); |
| 297 | static void exec_sentinel (Lisp_Object proc, Lisp_Object reason); | 246 | static void exec_sentinel (Lisp_Object proc, Lisp_Object reason); |
| 298 | 247 | ||
| @@ -304,10 +253,10 @@ static int num_pending_connects; | |||
| 304 | /* The largest descriptor currently in use; -1 if none. */ | 253 | /* The largest descriptor currently in use; -1 if none. */ |
| 305 | static int max_desc; | 254 | static int max_desc; |
| 306 | 255 | ||
| 307 | /* Indexed by descriptor, gives the process (if any) for that descriptor */ | 256 | /* Indexed by descriptor, gives the process (if any) for that descriptor. */ |
| 308 | static Lisp_Object chan_process[MAXDESC]; | 257 | static Lisp_Object chan_process[FD_SETSIZE]; |
| 309 | 258 | ||
| 310 | /* Alist of elements (NAME . PROCESS) */ | 259 | /* Alist of elements (NAME . PROCESS). */ |
| 311 | static Lisp_Object Vprocess_alist; | 260 | static Lisp_Object Vprocess_alist; |
| 312 | 261 | ||
| 313 | /* Buffered-ahead input char from process, indexed by channel. | 262 | /* Buffered-ahead input char from process, indexed by channel. |
| @@ -316,20 +265,23 @@ static Lisp_Object Vprocess_alist; | |||
| 316 | output from the process is to read at least one char. | 265 | output from the process is to read at least one char. |
| 317 | Always -1 on systems that support FIONREAD. */ | 266 | Always -1 on systems that support FIONREAD. */ |
| 318 | 267 | ||
| 319 | static int proc_buffered_char[MAXDESC]; | 268 | static int proc_buffered_char[FD_SETSIZE]; |
| 320 | 269 | ||
| 321 | /* Table of `struct coding-system' for each process. */ | 270 | /* Table of `struct coding-system' for each process. */ |
| 322 | static struct coding_system *proc_decode_coding_system[MAXDESC]; | 271 | static struct coding_system *proc_decode_coding_system[FD_SETSIZE]; |
| 323 | static struct coding_system *proc_encode_coding_system[MAXDESC]; | 272 | static struct coding_system *proc_encode_coding_system[FD_SETSIZE]; |
| 324 | 273 | ||
| 325 | #ifdef DATAGRAM_SOCKETS | 274 | #ifdef DATAGRAM_SOCKETS |
| 326 | /* Table of `partner address' for datagram sockets. */ | 275 | /* Table of `partner address' for datagram sockets. */ |
| 327 | static struct sockaddr_and_len { | 276 | static struct sockaddr_and_len { |
| 328 | struct sockaddr *sa; | 277 | struct sockaddr *sa; |
| 329 | int len; | 278 | int len; |
| 330 | } datagram_address[MAXDESC]; | 279 | } datagram_address[FD_SETSIZE]; |
| 331 | #define DATAGRAM_CHAN_P(chan) (datagram_address[chan].sa != 0) | 280 | #define DATAGRAM_CHAN_P(chan) (datagram_address[chan].sa != 0) |
| 332 | #define DATAGRAM_CONN_P(proc) (PROCESSP (proc) && datagram_address[XPROCESS (proc)->infd].sa != 0) | 281 | #define DATAGRAM_CONN_P(proc) \ |
| 282 | (PROCESSP (proc) && \ | ||
| 283 | XPROCESS (proc)->infd >= 0 && \ | ||
| 284 | datagram_address[XPROCESS (proc)->infd].sa != 0) | ||
| 333 | #else | 285 | #else |
| 334 | #define DATAGRAM_CHAN_P(chan) (0) | 286 | #define DATAGRAM_CHAN_P(chan) (0) |
| 335 | #define DATAGRAM_CONN_P(proc) (0) | 287 | #define DATAGRAM_CONN_P(proc) (0) |
| @@ -427,8 +379,18 @@ pset_write_queue (struct Lisp_Process *p, Lisp_Object val) | |||
| 427 | { | 379 | { |
| 428 | p->write_queue = val; | 380 | p->write_queue = val; |
| 429 | } | 381 | } |
| 382 | static void | ||
| 383 | pset_stderrproc (struct Lisp_Process *p, Lisp_Object val) | ||
| 384 | { | ||
| 385 | p->stderrproc = val; | ||
| 386 | } | ||
| 430 | 387 | ||
| 431 | 388 | ||
| 389 | static Lisp_Object | ||
| 390 | make_lisp_proc (struct Lisp_Process *p) | ||
| 391 | { | ||
| 392 | return make_lisp_ptr (p, Lisp_Vectorlike); | ||
| 393 | } | ||
| 432 | 394 | ||
| 433 | enum fd_bits | 395 | enum fd_bits |
| 434 | { | 396 | { |
| @@ -458,7 +420,7 @@ static struct fd_callback_data | |||
| 458 | /* If this fd is currently being selected on by a thread, this | 420 | /* If this fd is currently being selected on by a thread, this |
| 459 | points to the thread. Otherwise it is NULL. */ | 421 | points to the thread. Otherwise it is NULL. */ |
| 460 | struct thread_state *waiting_thread; | 422 | struct thread_state *waiting_thread; |
| 461 | } fd_callback_info[MAXDESC]; | 423 | } fd_callback_info[FD_SETSIZE]; |
| 462 | 424 | ||
| 463 | 425 | ||
| 464 | /* Add a file descriptor FD to be monitored for when read is possible. | 426 | /* Add a file descriptor FD to be monitored for when read is possible. |
| @@ -467,7 +429,6 @@ static struct fd_callback_data | |||
| 467 | void | 429 | void |
| 468 | add_read_fd (int fd, fd_callback func, void *data) | 430 | add_read_fd (int fd, fd_callback func, void *data) |
| 469 | { | 431 | { |
| 470 | eassert (fd < MAXDESC); | ||
| 471 | add_keyboard_wait_descriptor (fd); | 432 | add_keyboard_wait_descriptor (fd); |
| 472 | 433 | ||
| 473 | fd_callback_info[fd].func = func; | 434 | fd_callback_info[fd].func = func; |
| @@ -477,7 +438,7 @@ add_read_fd (int fd, fd_callback func, void *data) | |||
| 477 | static void | 438 | static void |
| 478 | add_non_keyboard_read_fd (int fd) | 439 | add_non_keyboard_read_fd (int fd) |
| 479 | { | 440 | { |
| 480 | eassert (fd >= 0 && fd < MAXDESC); | 441 | eassert (fd >= 0 && fd < FD_SETSIZE); |
| 481 | eassert (fd_callback_info[fd].func == NULL); | 442 | eassert (fd_callback_info[fd].func == NULL); |
| 482 | fd_callback_info[fd].flags |= FOR_READ; | 443 | fd_callback_info[fd].flags |= FOR_READ; |
| 483 | if (fd > max_desc) | 444 | if (fd > max_desc) |
| @@ -496,7 +457,6 @@ add_process_read_fd (int fd) | |||
| 496 | void | 457 | void |
| 497 | delete_read_fd (int fd) | 458 | delete_read_fd (int fd) |
| 498 | { | 459 | { |
| 499 | eassert (fd < MAXDESC); | ||
| 500 | delete_keyboard_wait_descriptor (fd); | 460 | delete_keyboard_wait_descriptor (fd); |
| 501 | 461 | ||
| 502 | if (fd_callback_info[fd].flags == 0) | 462 | if (fd_callback_info[fd].flags == 0) |
| @@ -512,7 +472,6 @@ delete_read_fd (int fd) | |||
| 512 | void | 472 | void |
| 513 | add_write_fd (int fd, fd_callback func, void *data) | 473 | add_write_fd (int fd, fd_callback func, void *data) |
| 514 | { | 474 | { |
| 515 | eassert (fd < MAXDESC); | ||
| 516 | if (fd > max_desc) | 475 | if (fd > max_desc) |
| 517 | max_desc = fd; | 476 | max_desc = fd; |
| 518 | 477 | ||
| @@ -524,7 +483,7 @@ add_write_fd (int fd, fd_callback func, void *data) | |||
| 524 | static void | 483 | static void |
| 525 | add_non_blocking_write_fd (int fd) | 484 | add_non_blocking_write_fd (int fd) |
| 526 | { | 485 | { |
| 527 | eassert (fd >= 0 && fd < MAXDESC); | 486 | eassert (fd >= 0 && fd < FD_SETSIZE); |
| 528 | eassert (fd_callback_info[fd].func == NULL); | 487 | eassert (fd_callback_info[fd].func == NULL); |
| 529 | 488 | ||
| 530 | fd_callback_info[fd].flags |= FOR_WRITE | NON_BLOCKING_CONNECT_FD; | 489 | fd_callback_info[fd].flags |= FOR_WRITE | NON_BLOCKING_CONNECT_FD; |
| @@ -557,8 +516,6 @@ delete_write_fd (int fd) | |||
| 557 | { | 516 | { |
| 558 | int lim = max_desc; | 517 | int lim = max_desc; |
| 559 | 518 | ||
| 560 | eassert (fd < MAXDESC); | ||
| 561 | |||
| 562 | #ifdef NON_BLOCKING_CONNECT | 519 | #ifdef NON_BLOCKING_CONNECT |
| 563 | if ((fd_callback_info[fd].flags & NON_BLOCKING_CONNECT_FD) != 0) | 520 | if ((fd_callback_info[fd].flags & NON_BLOCKING_CONNECT_FD) != 0) |
| 564 | { | 521 | { |
| @@ -578,7 +535,7 @@ delete_write_fd (int fd) | |||
| 578 | } | 535 | } |
| 579 | 536 | ||
| 580 | static void | 537 | static void |
| 581 | compute_input_wait_mask (SELECT_TYPE *mask) | 538 | compute_input_wait_mask (fd_set *mask) |
| 582 | { | 539 | { |
| 583 | int fd; | 540 | int fd; |
| 584 | 541 | ||
| @@ -600,7 +557,7 @@ compute_input_wait_mask (SELECT_TYPE *mask) | |||
| 600 | } | 557 | } |
| 601 | 558 | ||
| 602 | static void | 559 | static void |
| 603 | compute_non_process_wait_mask (SELECT_TYPE *mask) | 560 | compute_non_process_wait_mask (fd_set *mask) |
| 604 | { | 561 | { |
| 605 | int fd; | 562 | int fd; |
| 606 | 563 | ||
| @@ -623,7 +580,7 @@ compute_non_process_wait_mask (SELECT_TYPE *mask) | |||
| 623 | } | 580 | } |
| 624 | 581 | ||
| 625 | static void | 582 | static void |
| 626 | compute_non_keyboard_wait_mask (SELECT_TYPE *mask) | 583 | compute_non_keyboard_wait_mask (fd_set *mask) |
| 627 | { | 584 | { |
| 628 | int fd; | 585 | int fd; |
| 629 | 586 | ||
| @@ -646,7 +603,7 @@ compute_non_keyboard_wait_mask (SELECT_TYPE *mask) | |||
| 646 | } | 603 | } |
| 647 | 604 | ||
| 648 | static void | 605 | static void |
| 649 | compute_write_mask (SELECT_TYPE *mask) | 606 | compute_write_mask (fd_set *mask) |
| 650 | { | 607 | { |
| 651 | int fd; | 608 | int fd; |
| 652 | 609 | ||
| @@ -744,7 +701,7 @@ status_message (struct Lisp_Process *p) | |||
| 744 | Lisp_Object symbol; | 701 | Lisp_Object symbol; |
| 745 | int code; | 702 | int code; |
| 746 | bool coredump; | 703 | bool coredump; |
| 747 | Lisp_Object string, string2; | 704 | Lisp_Object string; |
| 748 | 705 | ||
| 749 | decode_status (status, &symbol, &code, &coredump); | 706 | decode_status (status, &symbol, &code, &coredump); |
| 750 | 707 | ||
| @@ -768,8 +725,8 @@ status_message (struct Lisp_Process *p) | |||
| 768 | if (c1 != c2) | 725 | if (c1 != c2) |
| 769 | Faset (string, make_number (0), make_number (c2)); | 726 | Faset (string, make_number (0), make_number (c2)); |
| 770 | } | 727 | } |
| 771 | string2 = build_string (coredump ? " (core dumped)\n" : "\n"); | 728 | AUTO_STRING (suffix, coredump ? " (core dumped)\n" : "\n"); |
| 772 | return concat2 (string, string2); | 729 | return concat2 (string, suffix); |
| 773 | } | 730 | } |
| 774 | else if (EQ (symbol, Qexit)) | 731 | else if (EQ (symbol, Qexit)) |
| 775 | { | 732 | { |
| @@ -777,17 +734,17 @@ status_message (struct Lisp_Process *p) | |||
| 777 | return build_string (code == 0 ? "deleted\n" : "connection broken by remote peer\n"); | 734 | return build_string (code == 0 ? "deleted\n" : "connection broken by remote peer\n"); |
| 778 | if (code == 0) | 735 | if (code == 0) |
| 779 | return build_string ("finished\n"); | 736 | return build_string ("finished\n"); |
| 737 | AUTO_STRING (prefix, "exited abnormally with code "); | ||
| 780 | string = Fnumber_to_string (make_number (code)); | 738 | string = Fnumber_to_string (make_number (code)); |
| 781 | string2 = build_string (coredump ? " (core dumped)\n" : "\n"); | 739 | AUTO_STRING (suffix, coredump ? " (core dumped)\n" : "\n"); |
| 782 | return concat3 (build_string ("exited abnormally with code "), | 740 | return concat3 (prefix, string, suffix); |
| 783 | string, string2); | ||
| 784 | } | 741 | } |
| 785 | else if (EQ (symbol, Qfailed)) | 742 | else if (EQ (symbol, Qfailed)) |
| 786 | { | 743 | { |
| 744 | AUTO_STRING (prefix, "failed with code "); | ||
| 787 | string = Fnumber_to_string (make_number (code)); | 745 | string = Fnumber_to_string (make_number (code)); |
| 788 | string2 = build_string ("\n"); | 746 | AUTO_STRING (suffix, "\n"); |
| 789 | return concat3 (build_string ("failed with code "), | 747 | return concat3 (prefix, string, suffix); |
| 790 | string, string2); | ||
| 791 | } | 748 | } |
| 792 | else | 749 | else |
| 793 | return Fcopy_sequence (Fsymbol_name (symbol)); | 750 | return Fcopy_sequence (Fsymbol_name (symbol)); |
| @@ -827,22 +784,24 @@ allocate_pty (char pty_name[PTY_NAME_SIZE]) | |||
| 827 | 784 | ||
| 828 | if (fd >= 0) | 785 | if (fd >= 0) |
| 829 | { | 786 | { |
| 830 | #ifdef PTY_OPEN | 787 | #ifdef PTY_TTY_NAME_SPRINTF |
| 788 | PTY_TTY_NAME_SPRINTF | ||
| 789 | #else | ||
| 790 | sprintf (pty_name, "/dev/tty%c%x", c, i); | ||
| 791 | #endif /* no PTY_TTY_NAME_SPRINTF */ | ||
| 792 | |||
| 831 | /* Set FD's close-on-exec flag. This is needed even if | 793 | /* Set FD's close-on-exec flag. This is needed even if |
| 832 | PT_OPEN calls posix_openpt with O_CLOEXEC, since POSIX | 794 | PT_OPEN calls posix_openpt with O_CLOEXEC, since POSIX |
| 833 | doesn't require support for that combination. | 795 | doesn't require support for that combination. |
| 796 | Do this after PTY_TTY_NAME_SPRINTF, which on some platforms | ||
| 797 | doesn't work if the close-on-exec flag is set (Bug#20555). | ||
| 834 | Multithreaded platforms where posix_openpt ignores | 798 | Multithreaded platforms where posix_openpt ignores |
| 835 | O_CLOEXEC (or where PTY_OPEN doesn't call posix_openpt) | 799 | O_CLOEXEC (or where PTY_OPEN doesn't call posix_openpt) |
| 836 | have a race condition between the PTY_OPEN and here. */ | 800 | have a race condition between the PTY_OPEN and here. */ |
| 837 | fcntl (fd, F_SETFD, FD_CLOEXEC); | 801 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
| 838 | #endif | 802 | |
| 839 | /* check to make certain that both sides are available | 803 | /* Check to make certain that both sides are available. |
| 840 | this avoids a nasty yet stupid bug in rlogins */ | 804 | This avoids a nasty yet stupid bug in rlogins. */ |
| 841 | #ifdef PTY_TTY_NAME_SPRINTF | ||
| 842 | PTY_TTY_NAME_SPRINTF | ||
| 843 | #else | ||
| 844 | sprintf (pty_name, "/dev/tty%c%x", c, i); | ||
| 845 | #endif /* no PTY_TTY_NAME_SPRINTF */ | ||
| 846 | if (faccessat (AT_FDCWD, pty_name, R_OK | W_OK, AT_EACCESS) != 0) | 805 | if (faccessat (AT_FDCWD, pty_name, R_OK | W_OK, AT_EACCESS) != 0) |
| 847 | { | 806 | { |
| 848 | emacs_close (fd); | 807 | emacs_close (fd); |
| @@ -859,7 +818,15 @@ allocate_pty (char pty_name[PTY_NAME_SIZE]) | |||
| 859 | #endif /* HAVE_PTYS */ | 818 | #endif /* HAVE_PTYS */ |
| 860 | return -1; | 819 | return -1; |
| 861 | } | 820 | } |
| 862 | 821 | ||
| 822 | /* Allocate basically initialized process. */ | ||
| 823 | |||
| 824 | static struct Lisp_Process * | ||
| 825 | allocate_process (void) | ||
| 826 | { | ||
| 827 | return ALLOCATE_ZEROED_PSEUDOVECTOR (struct Lisp_Process, pid, PVEC_PROCESS); | ||
| 828 | } | ||
| 829 | |||
| 863 | static Lisp_Object | 830 | static Lisp_Object |
| 864 | make_process (Lisp_Object name) | 831 | make_process (Lisp_Object name) |
| 865 | { | 832 | { |
| @@ -976,13 +943,14 @@ get_process (register Lisp_Object name) | |||
| 976 | else | 943 | else |
| 977 | obj = name; | 944 | obj = name; |
| 978 | 945 | ||
| 979 | /* Now obj should be either a buffer object or a process object. | 946 | /* Now obj should be either a buffer object or a process object. */ |
| 980 | */ | ||
| 981 | if (BUFFERP (obj)) | 947 | if (BUFFERP (obj)) |
| 982 | { | 948 | { |
| 949 | if (NILP (BVAR (XBUFFER (obj), name))) | ||
| 950 | error ("Attempt to get process for a dead buffer"); | ||
| 983 | proc = Fget_buffer_process (obj); | 951 | proc = Fget_buffer_process (obj); |
| 984 | if (NILP (proc)) | 952 | if (NILP (proc)) |
| 985 | error ("Buffer %s has no process", SDATA (BVAR (XBUFFER (obj), name))); | 953 | error ("Buffer %s has no process", SDATA (BVAR (XBUFFER (obj), name))); |
| 986 | } | 954 | } |
| 987 | else | 955 | else |
| 988 | { | 956 | { |
| @@ -1026,11 +994,11 @@ nil, indicating the current buffer's process. */) | |||
| 1026 | p = XPROCESS (process); | 994 | p = XPROCESS (process); |
| 1027 | 995 | ||
| 1028 | p->raw_status_new = 0; | 996 | p->raw_status_new = 0; |
| 1029 | if (NETCONN1_P (p) || SERIALCONN1_P (p)) | 997 | if (NETCONN1_P (p) || SERIALCONN1_P (p) || PIPECONN1_P (p)) |
| 1030 | { | 998 | { |
| 1031 | pset_status (p, list2 (Qexit, make_number (0))); | 999 | pset_status (p, list2 (Qexit, make_number (0))); |
| 1032 | p->tick = ++process_tick; | 1000 | p->tick = ++process_tick; |
| 1033 | status_notify (p); | 1001 | status_notify (p, NULL); |
| 1034 | redisplay_preserve_echo_area (13); | 1002 | redisplay_preserve_echo_area (13); |
| 1035 | } | 1003 | } |
| 1036 | else | 1004 | else |
| @@ -1050,7 +1018,7 @@ nil, indicating the current buffer's process. */) | |||
| 1050 | pset_status (p, list2 (Qsignal, make_number (SIGKILL))); | 1018 | pset_status (p, list2 (Qsignal, make_number (SIGKILL))); |
| 1051 | 1019 | ||
| 1052 | p->tick = ++process_tick; | 1020 | p->tick = ++process_tick; |
| 1053 | status_notify (p); | 1021 | status_notify (p, NULL); |
| 1054 | redisplay_preserve_echo_area (13); | 1022 | redisplay_preserve_echo_area (13); |
| 1055 | } | 1023 | } |
| 1056 | } | 1024 | } |
| @@ -1092,7 +1060,7 @@ nil, indicating the current buffer's process. */) | |||
| 1092 | status = p->status; | 1060 | status = p->status; |
| 1093 | if (CONSP (status)) | 1061 | if (CONSP (status)) |
| 1094 | status = XCAR (status); | 1062 | status = XCAR (status); |
| 1095 | if (NETCONN1_P (p) || SERIALCONN1_P (p)) | 1063 | if (NETCONN1_P (p) || SERIALCONN1_P (p) || PIPECONN1_P (p)) |
| 1096 | { | 1064 | { |
| 1097 | if (EQ (status, Qexit)) | 1065 | if (EQ (status, Qexit)) |
| 1098 | status = Qclosed; | 1066 | status = Qclosed; |
| @@ -1146,7 +1114,7 @@ DEFUN ("process-command", Fprocess_command, Sprocess_command, 1, 1, 0, | |||
| 1146 | This is a list of strings, the first string being the program executed | 1114 | This is a list of strings, the first string being the program executed |
| 1147 | and the rest of the strings being the arguments given to it. | 1115 | and the rest of the strings being the arguments given to it. |
| 1148 | For a network or serial process, this is nil (process is running) or t | 1116 | For a network or serial process, this is nil (process is running) or t |
| 1149 | \(process is stopped). */) | 1117 | (process is stopped). */) |
| 1150 | (register Lisp_Object process) | 1118 | (register Lisp_Object process) |
| 1151 | { | 1119 | { |
| 1152 | CHECK_PROCESS (process); | 1120 | CHECK_PROCESS (process); |
| @@ -1176,7 +1144,7 @@ Return BUFFER. */) | |||
| 1176 | CHECK_BUFFER (buffer); | 1144 | CHECK_BUFFER (buffer); |
| 1177 | p = XPROCESS (process); | 1145 | p = XPROCESS (process); |
| 1178 | pset_buffer (p, buffer); | 1146 | pset_buffer (p, buffer); |
| 1179 | if (NETCONN1_P (p) || SERIALCONN1_P (p)) | 1147 | if (NETCONN1_P (p) || SERIALCONN1_P (p) || PIPECONN1_P (p)) |
| 1180 | pset_childp (p, Fplist_put (p->childp, QCbuffer, buffer)); | 1148 | pset_childp (p, Fplist_put (p->childp, QCbuffer, buffer)); |
| 1181 | setup_process_coding_systems (process); | 1149 | setup_process_coding_systems (process); |
| 1182 | return buffer; | 1150 | return buffer; |
| @@ -1185,7 +1153,7 @@ Return BUFFER. */) | |||
| 1185 | DEFUN ("process-buffer", Fprocess_buffer, Sprocess_buffer, | 1153 | DEFUN ("process-buffer", Fprocess_buffer, Sprocess_buffer, |
| 1186 | 1, 1, 0, | 1154 | 1, 1, 0, |
| 1187 | doc: /* Return the buffer PROCESS is associated with. | 1155 | doc: /* Return the buffer PROCESS is associated with. |
| 1188 | Output from PROCESS is inserted in this buffer unless PROCESS has a filter. */) | 1156 | The default process filter inserts output from PROCESS into this buffer. */) |
| 1189 | (register Lisp_Object process) | 1157 | (register Lisp_Object process) |
| 1190 | { | 1158 | { |
| 1191 | CHECK_PROCESS (process); | 1159 | CHECK_PROCESS (process); |
| @@ -1212,7 +1180,7 @@ passed to the filter. | |||
| 1212 | 1180 | ||
| 1213 | The filter gets two arguments: the process and the string of output. | 1181 | The filter gets two arguments: the process and the string of output. |
| 1214 | The string argument is normally a multibyte string, except: | 1182 | The string argument is normally a multibyte string, except: |
| 1215 | - if the process' input coding system is no-conversion or raw-text, | 1183 | - if the process's input coding system is no-conversion or raw-text, |
| 1216 | it is a unibyte string (the non-converted input), or else | 1184 | it is a unibyte string (the non-converted input), or else |
| 1217 | - if `default-enable-multibyte-characters' is nil, it is a unibyte | 1185 | - if `default-enable-multibyte-characters' is nil, it is a unibyte |
| 1218 | string (the result of converting the decoded input multibyte | 1186 | string (the result of converting the decoded input multibyte |
| @@ -1224,7 +1192,7 @@ The string argument is normally a multibyte string, except: | |||
| 1224 | CHECK_PROCESS (process); | 1192 | CHECK_PROCESS (process); |
| 1225 | p = XPROCESS (process); | 1193 | p = XPROCESS (process); |
| 1226 | 1194 | ||
| 1227 | /* Don't signal an error if the process' input file descriptor | 1195 | /* Don't signal an error if the process's input file descriptor |
| 1228 | is closed. This could make debugging Lisp more difficult, | 1196 | is closed. This could make debugging Lisp more difficult, |
| 1229 | for example when doing something like | 1197 | for example when doing something like |
| 1230 | 1198 | ||
| @@ -1246,7 +1214,7 @@ The string argument is normally a multibyte string, except: | |||
| 1246 | } | 1214 | } |
| 1247 | 1215 | ||
| 1248 | pset_filter (p, filter); | 1216 | pset_filter (p, filter); |
| 1249 | if (NETCONN1_P (p) || SERIALCONN1_P (p)) | 1217 | if (NETCONN1_P (p) || SERIALCONN1_P (p) || PIPECONN1_P (p)) |
| 1250 | pset_childp (p, Fplist_put (p->childp, QCfilter, filter)); | 1218 | pset_childp (p, Fplist_put (p->childp, QCfilter, filter)); |
| 1251 | setup_process_coding_systems (process); | 1219 | setup_process_coding_systems (process); |
| 1252 | return filter; | 1220 | return filter; |
| @@ -1278,7 +1246,7 @@ It gets two arguments: the process, and a string describing the change. */) | |||
| 1278 | sentinel = Qinternal_default_process_sentinel; | 1246 | sentinel = Qinternal_default_process_sentinel; |
| 1279 | 1247 | ||
| 1280 | pset_sentinel (p, sentinel); | 1248 | pset_sentinel (p, sentinel); |
| 1281 | if (NETCONN1_P (p) || SERIALCONN1_P (p)) | 1249 | if (NETCONN1_P (p) || SERIALCONN1_P (p) || PIPECONN1_P (p)) |
| 1282 | pset_childp (p, Fplist_put (p->childp, QCsentinel, sentinel)); | 1250 | pset_childp (p, Fplist_put (p->childp, QCsentinel, sentinel)); |
| 1283 | return sentinel; | 1251 | return sentinel; |
| 1284 | } | 1252 | } |
| @@ -1423,7 +1391,8 @@ list of keywords. */) | |||
| 1423 | Fprocess_datagram_address (process)); | 1391 | Fprocess_datagram_address (process)); |
| 1424 | #endif | 1392 | #endif |
| 1425 | 1393 | ||
| 1426 | if ((!NETCONN_P (process) && !SERIALCONN_P (process)) || EQ (key, Qt)) | 1394 | if ((!NETCONN_P (process) && !SERIALCONN_P (process) && !PIPECONN_P (process)) |
| 1395 | || EQ (key, Qt)) | ||
| 1427 | return contact; | 1396 | return contact; |
| 1428 | if (NILP (key) && NETCONN_P (process)) | 1397 | if (NILP (key) && NETCONN_P (process)) |
| 1429 | return list2 (Fplist_get (contact, QChost), | 1398 | return list2 (Fplist_get (contact, QChost), |
| @@ -1431,6 +1400,11 @@ list of keywords. */) | |||
| 1431 | if (NILP (key) && SERIALCONN_P (process)) | 1400 | if (NILP (key) && SERIALCONN_P (process)) |
| 1432 | return list2 (Fplist_get (contact, QCport), | 1401 | return list2 (Fplist_get (contact, QCport), |
| 1433 | Fplist_get (contact, QCspeed)); | 1402 | Fplist_get (contact, QCspeed)); |
| 1403 | /* FIXME: Return a meaningful value (e.g., the child end of the pipe) | ||
| 1404 | if the pipe process is useful for purposes other than receiving | ||
| 1405 | stderr. */ | ||
| 1406 | if (NILP (key) && PIPECONN_P (process)) | ||
| 1407 | return Qt; | ||
| 1434 | return Fplist_get (contact, key); | 1408 | return Fplist_get (contact, key); |
| 1435 | } | 1409 | } |
| 1436 | 1410 | ||
| @@ -1501,30 +1475,34 @@ Returns nil if format of ADDRESS is invalid. */) | |||
| 1501 | ptrdiff_t size = p->header.size; | 1475 | ptrdiff_t size = p->header.size; |
| 1502 | Lisp_Object args[10]; | 1476 | Lisp_Object args[10]; |
| 1503 | int nargs, i; | 1477 | int nargs, i; |
| 1478 | char const *format; | ||
| 1504 | 1479 | ||
| 1505 | if (size == 4 || (size == 5 && !NILP (omit_port))) | 1480 | if (size == 4 || (size == 5 && !NILP (omit_port))) |
| 1506 | { | 1481 | { |
| 1507 | args[0] = build_string ("%d.%d.%d.%d"); | 1482 | format = "%d.%d.%d.%d"; |
| 1508 | nargs = 4; | 1483 | nargs = 4; |
| 1509 | } | 1484 | } |
| 1510 | else if (size == 5) | 1485 | else if (size == 5) |
| 1511 | { | 1486 | { |
| 1512 | args[0] = build_string ("%d.%d.%d.%d:%d"); | 1487 | format = "%d.%d.%d.%d:%d"; |
| 1513 | nargs = 5; | 1488 | nargs = 5; |
| 1514 | } | 1489 | } |
| 1515 | else if (size == 8 || (size == 9 && !NILP (omit_port))) | 1490 | else if (size == 8 || (size == 9 && !NILP (omit_port))) |
| 1516 | { | 1491 | { |
| 1517 | args[0] = build_string ("%x:%x:%x:%x:%x:%x:%x:%x"); | 1492 | format = "%x:%x:%x:%x:%x:%x:%x:%x"; |
| 1518 | nargs = 8; | 1493 | nargs = 8; |
| 1519 | } | 1494 | } |
| 1520 | else if (size == 9) | 1495 | else if (size == 9) |
| 1521 | { | 1496 | { |
| 1522 | args[0] = build_string ("[%x:%x:%x:%x:%x:%x:%x:%x]:%d"); | 1497 | format = "[%x:%x:%x:%x:%x:%x:%x:%x]:%d"; |
| 1523 | nargs = 9; | 1498 | nargs = 9; |
| 1524 | } | 1499 | } |
| 1525 | else | 1500 | else |
| 1526 | return Qnil; | 1501 | return Qnil; |
| 1527 | 1502 | ||
| 1503 | AUTO_STRING (format_obj, format); | ||
| 1504 | args[0] = format_obj; | ||
| 1505 | |||
| 1528 | for (i = 0; i < nargs; i++) | 1506 | for (i = 0; i < nargs; i++) |
| 1529 | { | 1507 | { |
| 1530 | if (! RANGED_INTEGERP (0, p->contents[i], 65535)) | 1508 | if (! RANGED_INTEGERP (0, p->contents[i], 65535)) |
| @@ -1535,18 +1513,16 @@ Returns nil if format of ADDRESS is invalid. */) | |||
| 1535 | && XINT (p->contents[i]) > 255) | 1513 | && XINT (p->contents[i]) > 255) |
| 1536 | return Qnil; | 1514 | return Qnil; |
| 1537 | 1515 | ||
| 1538 | args[i+1] = p->contents[i]; | 1516 | args[i + 1] = p->contents[i]; |
| 1539 | } | 1517 | } |
| 1540 | 1518 | ||
| 1541 | return Fformat (nargs+1, args); | 1519 | return Fformat (nargs + 1, args); |
| 1542 | } | 1520 | } |
| 1543 | 1521 | ||
| 1544 | if (CONSP (address)) | 1522 | if (CONSP (address)) |
| 1545 | { | 1523 | { |
| 1546 | Lisp_Object args[2]; | 1524 | AUTO_STRING (format, "<Family %d>"); |
| 1547 | args[0] = build_string ("<Family %d>"); | 1525 | return CALLN (Fformat, format, Fcar (address)); |
| 1548 | args[1] = Fcar (address); | ||
| 1549 | return Fformat (2, args); | ||
| 1550 | } | 1526 | } |
| 1551 | 1527 | ||
| 1552 | return Qnil; | 1528 | return Qnil; |
| @@ -1563,60 +1539,104 @@ DEFUN ("process-list", Fprocess_list, Sprocess_list, 0, 0, 0, | |||
| 1563 | 1539 | ||
| 1564 | static void start_process_unwind (Lisp_Object proc); | 1540 | static void start_process_unwind (Lisp_Object proc); |
| 1565 | 1541 | ||
| 1566 | DEFUN ("start-process", Fstart_process, Sstart_process, 3, MANY, 0, | 1542 | DEFUN ("make-process", Fmake_process, Smake_process, 0, MANY, 0, |
| 1567 | doc: /* Start a program in a subprocess. Return the process object for it. | 1543 | doc: /* Start a program in a subprocess. Return the process object for it. |
| 1568 | NAME is name for process. It is modified if necessary to make it unique. | ||
| 1569 | BUFFER is the buffer (or buffer name) to associate with the process. | ||
| 1570 | 1544 | ||
| 1571 | Process output (both standard output and standard error streams) goes | 1545 | This is similar to `start-process', but arguments are specified as |
| 1572 | at end of BUFFER, unless you specify an output stream or filter | 1546 | keyword/argument pairs. The following arguments are defined: |
| 1573 | function to handle the output. BUFFER may also be nil, meaning that | ||
| 1574 | this process is not associated with any buffer. | ||
| 1575 | 1547 | ||
| 1576 | PROGRAM is the program file name. It is searched for in `exec-path' | 1548 | :name NAME -- NAME is name for process. It is modified if necessary |
| 1577 | (which see). If nil, just associate a pty with the buffer. Remaining | 1549 | to make it unique. |
| 1578 | arguments are strings to give program as arguments. | 1550 | |
| 1551 | :buffer BUFFER -- BUFFER is the buffer (or buffer-name) to associate | ||
| 1552 | with the process. Process output goes at end of that buffer, unless | ||
| 1553 | you specify an output stream or filter function to handle the output. | ||
| 1554 | BUFFER may be also nil, meaning that this process is not associated | ||
| 1555 | with any buffer. | ||
| 1579 | 1556 | ||
| 1580 | If you want to separate standard output from standard error, invoke | 1557 | :command COMMAND -- COMMAND is a list starting with the program file |
| 1581 | the command through a shell and redirect one of them using the shell | 1558 | name, followed by strings to give to the program as arguments. |
| 1582 | syntax. | ||
| 1583 | 1559 | ||
| 1584 | usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) | 1560 | :coding CODING -- If CODING is a symbol, it specifies the coding |
| 1561 | system used for both reading and writing for this process. If CODING | ||
| 1562 | is a cons (DECODING . ENCODING), DECODING is used for reading, and | ||
| 1563 | ENCODING is used for writing. | ||
| 1564 | |||
| 1565 | :noquery BOOL -- When exiting Emacs, query the user if BOOL is nil and | ||
| 1566 | the process is running. If BOOL is not given, query before exiting. | ||
| 1567 | |||
| 1568 | :stop BOOL -- Start process in the `stopped' state if BOOL non-nil. | ||
| 1569 | In the stopped state, a process does not accept incoming data, but you | ||
| 1570 | can send outgoing data. The stopped state is cleared by | ||
| 1571 | `continue-process' and set by `stop-process'. | ||
| 1572 | |||
| 1573 | :connection-type TYPE -- TYPE is control type of device used to | ||
| 1574 | communicate with subprocesses. Values are `pipe' to use a pipe, `pty' | ||
| 1575 | to use a pty, or nil to use the default specified through | ||
| 1576 | `process-connection-type'. | ||
| 1577 | |||
| 1578 | :filter FILTER -- Install FILTER as the process filter. | ||
| 1579 | |||
| 1580 | :sentinel SENTINEL -- Install SENTINEL as the process sentinel. | ||
| 1581 | |||
| 1582 | :stderr STDERR -- STDERR is either a buffer or a pipe process attached | ||
| 1583 | to the standard error of subprocess. Specifying this implies | ||
| 1584 | `:connection-type' is set to `pipe'. | ||
| 1585 | |||
| 1586 | usage: (make-process &rest ARGS) */) | ||
| 1585 | (ptrdiff_t nargs, Lisp_Object *args) | 1587 | (ptrdiff_t nargs, Lisp_Object *args) |
| 1586 | { | 1588 | { |
| 1587 | Lisp_Object buffer, name, program, proc, current_dir, tem; | 1589 | Lisp_Object buffer, name, command, program, proc, contact, current_dir, tem; |
| 1588 | register unsigned char **new_argv; | 1590 | Lisp_Object xstderr, stderrproc; |
| 1589 | ptrdiff_t i; | ||
| 1590 | ptrdiff_t count = SPECPDL_INDEX (); | 1591 | ptrdiff_t count = SPECPDL_INDEX (); |
| 1592 | USE_SAFE_ALLOCA; | ||
| 1593 | |||
| 1594 | if (nargs == 0) | ||
| 1595 | return Qnil; | ||
| 1591 | 1596 | ||
| 1592 | buffer = args[1]; | 1597 | /* Save arguments for process-contact and clone-process. */ |
| 1598 | contact = Flist (nargs, args); | ||
| 1599 | |||
| 1600 | buffer = Fplist_get (contact, QCbuffer); | ||
| 1593 | if (!NILP (buffer)) | 1601 | if (!NILP (buffer)) |
| 1594 | buffer = Fget_buffer_create (buffer); | 1602 | buffer = Fget_buffer_create (buffer); |
| 1595 | 1603 | ||
| 1596 | /* Make sure that the child will be able to chdir to the current | 1604 | /* Make sure that the child will be able to chdir to the current |
| 1597 | buffer's current directory, or its unhandled equivalent. We | 1605 | buffer's current directory, or its unhandled equivalent. We |
| 1598 | can't just have the child check for an error when it does the | 1606 | can't just have the child check for an error when it does the |
| 1599 | chdir, since it's in a vfork. | 1607 | chdir, since it's in a vfork. */ |
| 1608 | current_dir = encode_current_directory (); | ||
| 1600 | 1609 | ||
| 1601 | We have to GCPRO around this because Fexpand_file_name and | 1610 | name = Fplist_get (contact, QCname); |
| 1602 | Funhandled_file_name_directory might call a file name handling | ||
| 1603 | function. The argument list is protected by the caller, so all | ||
| 1604 | we really have to worry about is buffer. */ | ||
| 1605 | { | ||
| 1606 | struct gcpro gcpro1; | ||
| 1607 | GCPRO1 (buffer); | ||
| 1608 | current_dir = encode_current_directory (); | ||
| 1609 | UNGCPRO; | ||
| 1610 | } | ||
| 1611 | |||
| 1612 | name = args[0]; | ||
| 1613 | CHECK_STRING (name); | 1611 | CHECK_STRING (name); |
| 1614 | 1612 | ||
| 1615 | program = args[2]; | 1613 | command = Fplist_get (contact, QCcommand); |
| 1614 | if (CONSP (command)) | ||
| 1615 | program = XCAR (command); | ||
| 1616 | else | ||
| 1617 | program = Qnil; | ||
| 1616 | 1618 | ||
| 1617 | if (!NILP (program)) | 1619 | if (!NILP (program)) |
| 1618 | CHECK_STRING (program); | 1620 | CHECK_STRING (program); |
| 1619 | 1621 | ||
| 1622 | stderrproc = Qnil; | ||
| 1623 | xstderr = Fplist_get (contact, QCstderr); | ||
| 1624 | if (PROCESSP (xstderr)) | ||
| 1625 | { | ||
| 1626 | if (!PIPECONN_P (xstderr)) | ||
| 1627 | error ("Process is not a pipe process"); | ||
| 1628 | stderrproc = xstderr; | ||
| 1629 | } | ||
| 1630 | else if (!NILP (xstderr)) | ||
| 1631 | { | ||
| 1632 | CHECK_STRING (program); | ||
| 1633 | stderrproc = CALLN (Fmake_pipe_process, | ||
| 1634 | QCname, | ||
| 1635 | concat2 (name, build_string (" stderr")), | ||
| 1636 | QCbuffer, | ||
| 1637 | Fget_buffer_create (xstderr)); | ||
| 1638 | } | ||
| 1639 | |||
| 1620 | proc = make_process (name); | 1640 | proc = make_process (name); |
| 1621 | /* If an error occurs and we can't start the process, we want to | 1641 | /* If an error occurs and we can't start the process, we want to |
| 1622 | remove it from the process list. This means that each error | 1642 | remove it from the process list. This means that each error |
| @@ -1628,9 +1648,31 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) | |||
| 1628 | pset_plist (XPROCESS (proc), Qnil); | 1648 | pset_plist (XPROCESS (proc), Qnil); |
| 1629 | pset_type (XPROCESS (proc), Qreal); | 1649 | pset_type (XPROCESS (proc), Qreal); |
| 1630 | pset_buffer (XPROCESS (proc), buffer); | 1650 | pset_buffer (XPROCESS (proc), buffer); |
| 1631 | pset_sentinel (XPROCESS (proc), Qinternal_default_process_sentinel); | 1651 | pset_sentinel (XPROCESS (proc), Fplist_get (contact, QCsentinel)); |
| 1632 | pset_filter (XPROCESS (proc), Qinternal_default_process_filter); | 1652 | pset_filter (XPROCESS (proc), Fplist_get (contact, QCfilter)); |
| 1633 | pset_command (XPROCESS (proc), Flist (nargs - 2, args + 2)); | 1653 | pset_command (XPROCESS (proc), Fcopy_sequence (command)); |
| 1654 | |||
| 1655 | if (tem = Fplist_get (contact, QCnoquery), !NILP (tem)) | ||
| 1656 | XPROCESS (proc)->kill_without_query = 1; | ||
| 1657 | if (tem = Fplist_get (contact, QCstop), !NILP (tem)) | ||
| 1658 | pset_command (XPROCESS (proc), Qt); | ||
| 1659 | |||
| 1660 | tem = Fplist_get (contact, QCconnection_type); | ||
| 1661 | if (EQ (tem, Qpty)) | ||
| 1662 | XPROCESS (proc)->pty_flag = true; | ||
| 1663 | else if (EQ (tem, Qpipe)) | ||
| 1664 | XPROCESS (proc)->pty_flag = false; | ||
| 1665 | else if (NILP (tem)) | ||
| 1666 | XPROCESS (proc)->pty_flag = !NILP (Vprocess_connection_type); | ||
| 1667 | else | ||
| 1668 | report_file_error ("Unknown connection type", tem); | ||
| 1669 | |||
| 1670 | if (!NILP (stderrproc)) | ||
| 1671 | { | ||
| 1672 | pset_stderrproc (XPROCESS (proc), stderrproc); | ||
| 1673 | |||
| 1674 | XPROCESS (proc)->pty_flag = false; | ||
| 1675 | } | ||
| 1634 | 1676 | ||
| 1635 | #ifdef HAVE_GNUTLS | 1677 | #ifdef HAVE_GNUTLS |
| 1636 | /* AKA GNUTLS_INITSTAGE(proc). */ | 1678 | /* AKA GNUTLS_INITSTAGE(proc). */ |
| @@ -1638,11 +1680,9 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) | |||
| 1638 | pset_gnutls_cred_type (XPROCESS (proc), Qnil); | 1680 | pset_gnutls_cred_type (XPROCESS (proc), Qnil); |
| 1639 | #endif | 1681 | #endif |
| 1640 | 1682 | ||
| 1641 | #ifdef ADAPTIVE_READ_BUFFERING | ||
| 1642 | XPROCESS (proc)->adaptive_read_buffering | 1683 | XPROCESS (proc)->adaptive_read_buffering |
| 1643 | = (NILP (Vprocess_adaptive_read_buffering) ? 0 | 1684 | = (NILP (Vprocess_adaptive_read_buffering) ? 0 |
| 1644 | : EQ (Vprocess_adaptive_read_buffering, Qt) ? 1 : 2); | 1685 | : EQ (Vprocess_adaptive_read_buffering, Qt) ? 1 : 2); |
| 1645 | #endif | ||
| 1646 | 1686 | ||
| 1647 | /* Make the process marker point into the process buffer (if any). */ | 1687 | /* Make the process marker point into the process buffer (if any). */ |
| 1648 | if (BUFFERP (buffer)) | 1688 | if (BUFFERP (buffer)) |
| @@ -1658,18 +1698,29 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) | |||
| 1658 | /* Qt denotes we have not yet called Ffind_operation_coding_system. */ | 1698 | /* Qt denotes we have not yet called Ffind_operation_coding_system. */ |
| 1659 | Lisp_Object coding_systems = Qt; | 1699 | Lisp_Object coding_systems = Qt; |
| 1660 | Lisp_Object val, *args2; | 1700 | Lisp_Object val, *args2; |
| 1661 | struct gcpro gcpro1, gcpro2; | ||
| 1662 | 1701 | ||
| 1663 | val = Vcoding_system_for_read; | 1702 | tem = Fplist_get (contact, QCcoding); |
| 1703 | if (!NILP (tem)) | ||
| 1704 | { | ||
| 1705 | val = tem; | ||
| 1706 | if (CONSP (val)) | ||
| 1707 | val = XCAR (val); | ||
| 1708 | } | ||
| 1709 | else | ||
| 1710 | val = Vcoding_system_for_read; | ||
| 1664 | if (NILP (val)) | 1711 | if (NILP (val)) |
| 1665 | { | 1712 | { |
| 1666 | args2 = alloca ((nargs + 1) * sizeof *args2); | 1713 | ptrdiff_t nargs2 = 3 + XINT (Flength (command)); |
| 1667 | args2[0] = Qstart_process; | 1714 | Lisp_Object tem2; |
| 1668 | for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; | 1715 | SAFE_ALLOCA_LISP (args2, nargs2); |
| 1669 | GCPRO2 (proc, current_dir); | 1716 | ptrdiff_t i = 0; |
| 1717 | args2[i++] = Qstart_process; | ||
| 1718 | args2[i++] = name; | ||
| 1719 | args2[i++] = buffer; | ||
| 1720 | for (tem2 = command; CONSP (tem2); tem2 = XCDR (tem2)) | ||
| 1721 | args2[i++] = XCAR (tem2); | ||
| 1670 | if (!NILP (program)) | 1722 | if (!NILP (program)) |
| 1671 | coding_systems = Ffind_operation_coding_system (nargs + 1, args2); | 1723 | coding_systems = Ffind_operation_coding_system (nargs2, args2); |
| 1672 | UNGCPRO; | ||
| 1673 | if (CONSP (coding_systems)) | 1724 | if (CONSP (coding_systems)) |
| 1674 | val = XCAR (coding_systems); | 1725 | val = XCAR (coding_systems); |
| 1675 | else if (CONSP (Vdefault_process_coding_system)) | 1726 | else if (CONSP (Vdefault_process_coding_system)) |
| @@ -1677,18 +1728,29 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) | |||
| 1677 | } | 1728 | } |
| 1678 | pset_decode_coding_system (XPROCESS (proc), val); | 1729 | pset_decode_coding_system (XPROCESS (proc), val); |
| 1679 | 1730 | ||
| 1680 | val = Vcoding_system_for_write; | 1731 | if (!NILP (tem)) |
| 1732 | { | ||
| 1733 | val = tem; | ||
| 1734 | if (CONSP (val)) | ||
| 1735 | val = XCDR (val); | ||
| 1736 | } | ||
| 1737 | else | ||
| 1738 | val = Vcoding_system_for_write; | ||
| 1681 | if (NILP (val)) | 1739 | if (NILP (val)) |
| 1682 | { | 1740 | { |
| 1683 | if (EQ (coding_systems, Qt)) | 1741 | if (EQ (coding_systems, Qt)) |
| 1684 | { | 1742 | { |
| 1685 | args2 = alloca ((nargs + 1) * sizeof *args2); | 1743 | ptrdiff_t nargs2 = 3 + XINT (Flength (command)); |
| 1686 | args2[0] = Qstart_process; | 1744 | Lisp_Object tem2; |
| 1687 | for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; | 1745 | SAFE_ALLOCA_LISP (args2, nargs2); |
| 1688 | GCPRO2 (proc, current_dir); | 1746 | ptrdiff_t i = 0; |
| 1747 | args2[i++] = Qstart_process; | ||
| 1748 | args2[i++] = name; | ||
| 1749 | args2[i++] = buffer; | ||
| 1750 | for (tem2 = command; CONSP (tem2); tem2 = XCDR (tem2)) | ||
| 1751 | args2[i++] = XCAR (tem2); | ||
| 1689 | if (!NILP (program)) | 1752 | if (!NILP (program)) |
| 1690 | coding_systems = Ffind_operation_coding_system (nargs + 1, args2); | 1753 | coding_systems = Ffind_operation_coding_system (nargs2, args2); |
| 1691 | UNGCPRO; | ||
| 1692 | } | 1754 | } |
| 1693 | if (CONSP (coding_systems)) | 1755 | if (CONSP (coding_systems)) |
| 1694 | val = XCDR (coding_systems); | 1756 | val = XCDR (coding_systems); |
| @@ -1713,18 +1775,17 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) | |||
| 1713 | 1775 | ||
| 1714 | if (!NILP (program)) | 1776 | if (!NILP (program)) |
| 1715 | { | 1777 | { |
| 1778 | Lisp_Object program_args = XCDR (command); | ||
| 1779 | |||
| 1716 | /* If program file name is not absolute, search our path for it. | 1780 | /* If program file name is not absolute, search our path for it. |
| 1717 | Put the name we will really use in TEM. */ | 1781 | Put the name we will really use in TEM. */ |
| 1718 | if (!IS_DIRECTORY_SEP (SREF (program, 0)) | 1782 | if (!IS_DIRECTORY_SEP (SREF (program, 0)) |
| 1719 | && !(SCHARS (program) > 1 | 1783 | && !(SCHARS (program) > 1 |
| 1720 | && IS_DEVICE_SEP (SREF (program, 1)))) | 1784 | && IS_DEVICE_SEP (SREF (program, 1)))) |
| 1721 | { | 1785 | { |
| 1722 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | ||
| 1723 | |||
| 1724 | tem = Qnil; | 1786 | tem = Qnil; |
| 1725 | GCPRO4 (name, program, buffer, current_dir); | 1787 | openp (Vexec_path, program, Vexec_suffixes, &tem, |
| 1726 | openp (Vexec_path, program, Vexec_suffixes, &tem, make_number (X_OK)); | 1788 | make_number (X_OK), false); |
| 1727 | UNGCPRO; | ||
| 1728 | if (NILP (tem)) | 1789 | if (NILP (tem)) |
| 1729 | report_file_error ("Searching for program", program); | 1790 | report_file_error ("Searching for program", program); |
| 1730 | tem = Fexpand_file_name (tem, Qnil); | 1791 | tem = Fexpand_file_name (tem, Qnil); |
| @@ -1736,60 +1797,54 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) | |||
| 1736 | tem = program; | 1797 | tem = program; |
| 1737 | } | 1798 | } |
| 1738 | 1799 | ||
| 1739 | /* If program file name starts with /: for quoting a magic name, | 1800 | /* Remove "/:" from TEM. */ |
| 1740 | discard that. */ | 1801 | tem = remove_slash_colon (tem); |
| 1741 | if (SBYTES (tem) > 2 && SREF (tem, 0) == '/' | ||
| 1742 | && SREF (tem, 1) == ':') | ||
| 1743 | tem = Fsubstring (tem, make_number (2), Qnil); | ||
| 1744 | |||
| 1745 | { | ||
| 1746 | Lisp_Object arg_encoding = Qnil; | ||
| 1747 | struct gcpro gcpro1; | ||
| 1748 | GCPRO1 (tem); | ||
| 1749 | 1802 | ||
| 1750 | /* Encode the file name and put it in NEW_ARGV. | 1803 | Lisp_Object arg_encoding = Qnil; |
| 1751 | That's where the child will use it to execute the program. */ | ||
| 1752 | tem = list1 (ENCODE_FILE (tem)); | ||
| 1753 | 1804 | ||
| 1754 | /* Here we encode arguments by the coding system used for sending | 1805 | /* Encode the file name and put it in NEW_ARGV. |
| 1755 | data to the process. We don't support using different coding | 1806 | That's where the child will use it to execute the program. */ |
| 1756 | systems for encoding arguments and for encoding data sent to the | 1807 | tem = list1 (ENCODE_FILE (tem)); |
| 1757 | process. */ | 1808 | ptrdiff_t new_argc = 1; |
| 1758 | 1809 | ||
| 1759 | for (i = 3; i < nargs; i++) | 1810 | /* Here we encode arguments by the coding system used for sending |
| 1760 | { | 1811 | data to the process. We don't support using different coding |
| 1761 | tem = Fcons (args[i], tem); | 1812 | systems for encoding arguments and for encoding data sent to the |
| 1762 | CHECK_STRING (XCAR (tem)); | 1813 | process. */ |
| 1763 | if (STRING_MULTIBYTE (XCAR (tem))) | ||
| 1764 | { | ||
| 1765 | if (NILP (arg_encoding)) | ||
| 1766 | arg_encoding = (complement_process_encoding_system | ||
| 1767 | (XPROCESS (proc)->encode_coding_system)); | ||
| 1768 | XSETCAR (tem, | ||
| 1769 | code_convert_string_norecord | ||
| 1770 | (XCAR (tem), arg_encoding, 1)); | ||
| 1771 | } | ||
| 1772 | } | ||
| 1773 | 1814 | ||
| 1774 | UNGCPRO; | 1815 | for (Lisp_Object tem2 = program_args; CONSP (tem2); tem2 = XCDR (tem2)) |
| 1775 | } | 1816 | { |
| 1817 | Lisp_Object arg = XCAR (tem2); | ||
| 1818 | CHECK_STRING (arg); | ||
| 1819 | if (STRING_MULTIBYTE (arg)) | ||
| 1820 | { | ||
| 1821 | if (NILP (arg_encoding)) | ||
| 1822 | arg_encoding = (complement_process_encoding_system | ||
| 1823 | (XPROCESS (proc)->encode_coding_system)); | ||
| 1824 | arg = code_convert_string_norecord (arg, arg_encoding, 1); | ||
| 1825 | } | ||
| 1826 | tem = Fcons (arg, tem); | ||
| 1827 | new_argc++; | ||
| 1828 | } | ||
| 1776 | 1829 | ||
| 1777 | /* Now that everything is encoded we can collect the strings into | 1830 | /* Now that everything is encoded we can collect the strings into |
| 1778 | NEW_ARGV. */ | 1831 | NEW_ARGV. */ |
| 1779 | new_argv = alloca ((nargs - 1) * sizeof *new_argv); | 1832 | char **new_argv; |
| 1780 | new_argv[nargs - 2] = 0; | 1833 | SAFE_NALLOCA (new_argv, 1, new_argc + 1); |
| 1834 | new_argv[new_argc] = 0; | ||
| 1781 | 1835 | ||
| 1782 | for (i = nargs - 2; i-- != 0; ) | 1836 | for (ptrdiff_t i = new_argc - 1; i >= 0; i--) |
| 1783 | { | 1837 | { |
| 1784 | new_argv[i] = SDATA (XCAR (tem)); | 1838 | new_argv[i] = SSDATA (XCAR (tem)); |
| 1785 | tem = XCDR (tem); | 1839 | tem = XCDR (tem); |
| 1786 | } | 1840 | } |
| 1787 | 1841 | ||
| 1788 | create_process (proc, (char **) new_argv, current_dir); | 1842 | create_process (proc, new_argv, current_dir); |
| 1789 | } | 1843 | } |
| 1790 | else | 1844 | else |
| 1791 | create_pty (proc); | 1845 | create_pty (proc); |
| 1792 | 1846 | ||
| 1847 | SAFE_FREE (); | ||
| 1793 | return unbind_to (count, proc); | 1848 | return unbind_to (count, proc); |
| 1794 | } | 1849 | } |
| 1795 | 1850 | ||
| @@ -1848,14 +1903,15 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1848 | int inchannel, outchannel; | 1903 | int inchannel, outchannel; |
| 1849 | pid_t pid; | 1904 | pid_t pid; |
| 1850 | int vfork_errno; | 1905 | int vfork_errno; |
| 1851 | int forkin, forkout; | 1906 | int forkin, forkout, forkerr = -1; |
| 1852 | bool pty_flag = 0; | 1907 | bool pty_flag = 0; |
| 1853 | char pty_name[PTY_NAME_SIZE]; | 1908 | char pty_name[PTY_NAME_SIZE]; |
| 1854 | Lisp_Object lisp_pty_name = Qnil; | 1909 | Lisp_Object lisp_pty_name = Qnil; |
| 1910 | sigset_t oldset; | ||
| 1855 | 1911 | ||
| 1856 | inchannel = outchannel = -1; | 1912 | inchannel = outchannel = -1; |
| 1857 | 1913 | ||
| 1858 | if (!NILP (Vprocess_connection_type)) | 1914 | if (p->pty_flag) |
| 1859 | outchannel = inchannel = allocate_pty (pty_name); | 1915 | outchannel = inchannel = allocate_pty (pty_name); |
| 1860 | 1916 | ||
| 1861 | if (inchannel >= 0) | 1917 | if (inchannel >= 0) |
| @@ -1885,6 +1941,17 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1885 | outchannel = p->open_fd[WRITE_TO_SUBPROCESS]; | 1941 | outchannel = p->open_fd[WRITE_TO_SUBPROCESS]; |
| 1886 | inchannel = p->open_fd[READ_FROM_SUBPROCESS]; | 1942 | inchannel = p->open_fd[READ_FROM_SUBPROCESS]; |
| 1887 | forkout = p->open_fd[SUBPROCESS_STDOUT]; | 1943 | forkout = p->open_fd[SUBPROCESS_STDOUT]; |
| 1944 | |||
| 1945 | if (!NILP (p->stderrproc)) | ||
| 1946 | { | ||
| 1947 | struct Lisp_Process *pp = XPROCESS (p->stderrproc); | ||
| 1948 | |||
| 1949 | forkerr = pp->open_fd[SUBPROCESS_STDOUT]; | ||
| 1950 | |||
| 1951 | /* Close unnecessary file descriptors. */ | ||
| 1952 | close_process_fd (&pp->open_fd[WRITE_TO_SUBPROCESS]); | ||
| 1953 | close_process_fd (&pp->open_fd[SUBPROCESS_STDIN]); | ||
| 1954 | } | ||
| 1888 | } | 1955 | } |
| 1889 | 1956 | ||
| 1890 | #ifndef WINDOWSNT | 1957 | #ifndef WINDOWSNT |
| @@ -1910,40 +1977,37 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1910 | 1977 | ||
| 1911 | add_process_read_fd (inchannel); | 1978 | add_process_read_fd (inchannel); |
| 1912 | 1979 | ||
| 1913 | /* This may signal an error. */ | 1980 | /* This may signal an error. */ |
| 1914 | setup_process_coding_systems (process); | 1981 | setup_process_coding_systems (process); |
| 1915 | 1982 | ||
| 1916 | block_input (); | 1983 | block_input (); |
| 1917 | block_child_signal (); | 1984 | block_child_signal (&oldset); |
| 1918 | 1985 | ||
| 1919 | #ifndef WINDOWSNT | 1986 | #ifndef WINDOWSNT |
| 1920 | /* vfork, and prevent local vars from being clobbered by the vfork. */ | 1987 | /* vfork, and prevent local vars from being clobbered by the vfork. */ |
| 1921 | { | 1988 | Lisp_Object volatile current_dir_volatile = current_dir; |
| 1922 | Lisp_Object volatile current_dir_volatile = current_dir; | 1989 | Lisp_Object volatile lisp_pty_name_volatile = lisp_pty_name; |
| 1923 | Lisp_Object volatile lisp_pty_name_volatile = lisp_pty_name; | 1990 | char **volatile new_argv_volatile = new_argv; |
| 1924 | char **volatile new_argv_volatile = new_argv; | 1991 | int volatile forkin_volatile = forkin; |
| 1925 | int volatile forkin_volatile = forkin; | 1992 | int volatile forkout_volatile = forkout; |
| 1926 | int volatile forkout_volatile = forkout; | 1993 | int volatile forkerr_volatile = forkerr; |
| 1927 | struct Lisp_Process *p_volatile = p; | 1994 | struct Lisp_Process *p_volatile = p; |
| 1928 | 1995 | ||
| 1929 | pid = vfork (); | 1996 | pid = vfork (); |
| 1930 | 1997 | ||
| 1931 | current_dir = current_dir_volatile; | 1998 | current_dir = current_dir_volatile; |
| 1932 | lisp_pty_name = lisp_pty_name_volatile; | 1999 | lisp_pty_name = lisp_pty_name_volatile; |
| 1933 | new_argv = new_argv_volatile; | 2000 | new_argv = new_argv_volatile; |
| 1934 | forkin = forkin_volatile; | 2001 | forkin = forkin_volatile; |
| 1935 | forkout = forkout_volatile; | 2002 | forkout = forkout_volatile; |
| 1936 | p = p_volatile; | 2003 | forkerr = forkerr_volatile; |
| 1937 | 2004 | p = p_volatile; | |
| 1938 | pty_flag = p->pty_flag; | 2005 | |
| 1939 | } | 2006 | pty_flag = p->pty_flag; |
| 1940 | 2007 | ||
| 1941 | if (pid == 0) | 2008 | if (pid == 0) |
| 1942 | #endif /* not WINDOWSNT */ | 2009 | #endif /* not WINDOWSNT */ |
| 1943 | { | 2010 | { |
| 1944 | int xforkin = forkin; | ||
| 1945 | int xforkout = forkout; | ||
| 1946 | |||
| 1947 | /* Make the pty be the controlling terminal of the process. */ | 2011 | /* Make the pty be the controlling terminal of the process. */ |
| 1948 | #ifdef HAVE_PTYS | 2012 | #ifdef HAVE_PTYS |
| 1949 | /* First, disconnect its current controlling terminal. */ | 2013 | /* First, disconnect its current controlling terminal. */ |
| @@ -1951,30 +2015,30 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1951 | process_set_signal to fail on SGI when using a pipe. */ | 2015 | process_set_signal to fail on SGI when using a pipe. */ |
| 1952 | setsid (); | 2016 | setsid (); |
| 1953 | /* Make the pty's terminal the controlling terminal. */ | 2017 | /* Make the pty's terminal the controlling terminal. */ |
| 1954 | if (pty_flag && xforkin >= 0) | 2018 | if (pty_flag && forkin >= 0) |
| 1955 | { | 2019 | { |
| 1956 | #ifdef TIOCSCTTY | 2020 | #ifdef TIOCSCTTY |
| 1957 | /* We ignore the return value | 2021 | /* We ignore the return value |
| 1958 | because faith@cs.unc.edu says that is necessary on Linux. */ | 2022 | because faith@cs.unc.edu says that is necessary on Linux. */ |
| 1959 | ioctl (xforkin, TIOCSCTTY, 0); | 2023 | ioctl (forkin, TIOCSCTTY, 0); |
| 1960 | #endif | 2024 | #endif |
| 1961 | } | 2025 | } |
| 1962 | #if defined (LDISC1) | 2026 | #if defined (LDISC1) |
| 1963 | if (pty_flag && xforkin >= 0) | 2027 | if (pty_flag && forkin >= 0) |
| 1964 | { | 2028 | { |
| 1965 | struct termios t; | 2029 | struct termios t; |
| 1966 | tcgetattr (xforkin, &t); | 2030 | tcgetattr (forkin, &t); |
| 1967 | t.c_lflag = LDISC1; | 2031 | t.c_lflag = LDISC1; |
| 1968 | if (tcsetattr (xforkin, TCSANOW, &t) < 0) | 2032 | if (tcsetattr (forkin, TCSANOW, &t) < 0) |
| 1969 | emacs_perror ("create_process/tcsetattr LDISC1"); | 2033 | emacs_perror ("create_process/tcsetattr LDISC1"); |
| 1970 | } | 2034 | } |
| 1971 | #else | 2035 | #else |
| 1972 | #if defined (NTTYDISC) && defined (TIOCSETD) | 2036 | #if defined (NTTYDISC) && defined (TIOCSETD) |
| 1973 | if (pty_flag && xforkin >= 0) | 2037 | if (pty_flag && forkin >= 0) |
| 1974 | { | 2038 | { |
| 1975 | /* Use new line discipline. */ | 2039 | /* Use new line discipline. */ |
| 1976 | int ldisc = NTTYDISC; | 2040 | int ldisc = NTTYDISC; |
| 1977 | ioctl (xforkin, TIOCSETD, &ldisc); | 2041 | ioctl (forkin, TIOCSETD, &ldisc); |
| 1978 | } | 2042 | } |
| 1979 | #endif | 2043 | #endif |
| 1980 | #endif | 2044 | #endif |
| @@ -2007,11 +2071,11 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 2007 | 2071 | ||
| 2008 | /* I wonder if emacs_close (emacs_open (SSDATA (lisp_pty_name), ...)) | 2072 | /* I wonder if emacs_close (emacs_open (SSDATA (lisp_pty_name), ...)) |
| 2009 | would work? */ | 2073 | would work? */ |
| 2010 | if (xforkin >= 0) | 2074 | if (forkin >= 0) |
| 2011 | emacs_close (xforkin); | 2075 | emacs_close (forkin); |
| 2012 | xforkout = xforkin = emacs_open (SSDATA (lisp_pty_name), O_RDWR, 0); | 2076 | forkout = forkin = emacs_open (SSDATA (lisp_pty_name), O_RDWR, 0); |
| 2013 | 2077 | ||
| 2014 | if (xforkin < 0) | 2078 | if (forkin < 0) |
| 2015 | { | 2079 | { |
| 2016 | emacs_perror (SSDATA (lisp_pty_name)); | 2080 | emacs_perror (SSDATA (lisp_pty_name)); |
| 2017 | _exit (EXIT_CANCELED); | 2081 | _exit (EXIT_CANCELED); |
| @@ -2030,19 +2094,25 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 2030 | 2094 | ||
| 2031 | signal (SIGINT, SIG_DFL); | 2095 | signal (SIGINT, SIG_DFL); |
| 2032 | signal (SIGQUIT, SIG_DFL); | 2096 | signal (SIGQUIT, SIG_DFL); |
| 2097 | #ifdef SIGPROF | ||
| 2098 | signal (SIGPROF, SIG_DFL); | ||
| 2099 | #endif | ||
| 2033 | 2100 | ||
| 2034 | /* Emacs ignores SIGPIPE, but the child should not. */ | 2101 | /* Emacs ignores SIGPIPE, but the child should not. */ |
| 2035 | signal (SIGPIPE, SIG_DFL); | 2102 | signal (SIGPIPE, SIG_DFL); |
| 2036 | 2103 | ||
| 2037 | /* Stop blocking SIGCHLD in the child. */ | 2104 | /* Stop blocking SIGCHLD in the child. */ |
| 2038 | unblock_child_signal (); | 2105 | unblock_child_signal (&oldset); |
| 2039 | 2106 | ||
| 2040 | if (pty_flag) | 2107 | if (pty_flag) |
| 2041 | child_setup_tty (xforkout); | 2108 | child_setup_tty (forkout); |
| 2109 | |||
| 2110 | if (forkerr < 0) | ||
| 2111 | forkerr = forkout; | ||
| 2042 | #ifdef WINDOWSNT | 2112 | #ifdef WINDOWSNT |
| 2043 | pid = child_setup (xforkin, xforkout, xforkout, new_argv, 1, current_dir); | 2113 | pid = child_setup (forkin, forkout, forkerr, new_argv, 1, current_dir); |
| 2044 | #else /* not WINDOWSNT */ | 2114 | #else /* not WINDOWSNT */ |
| 2045 | child_setup (xforkin, xforkout, xforkout, new_argv, 1, current_dir); | 2115 | child_setup (forkin, forkout, forkerr, new_argv, 1, current_dir); |
| 2046 | #endif /* not WINDOWSNT */ | 2116 | #endif /* not WINDOWSNT */ |
| 2047 | } | 2117 | } |
| 2048 | 2118 | ||
| @@ -2054,7 +2124,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 2054 | p->alive = 1; | 2124 | p->alive = 1; |
| 2055 | 2125 | ||
| 2056 | /* Stop blocking in the parent. */ | 2126 | /* Stop blocking in the parent. */ |
| 2057 | unblock_child_signal (); | 2127 | unblock_child_signal (&oldset); |
| 2058 | unblock_input (); | 2128 | unblock_input (); |
| 2059 | 2129 | ||
| 2060 | if (pid < 0) | 2130 | if (pid < 0) |
| @@ -2087,6 +2157,11 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 2087 | close_process_fd (&p->open_fd[READ_FROM_EXEC_MONITOR]); | 2157 | close_process_fd (&p->open_fd[READ_FROM_EXEC_MONITOR]); |
| 2088 | } | 2158 | } |
| 2089 | #endif | 2159 | #endif |
| 2160 | if (!NILP (p->stderrproc)) | ||
| 2161 | { | ||
| 2162 | struct Lisp_Process *pp = XPROCESS (p->stderrproc); | ||
| 2163 | close_process_fd (&pp->open_fd[SUBPROCESS_STDOUT]); | ||
| 2164 | } | ||
| 2090 | } | 2165 | } |
| 2091 | } | 2166 | } |
| 2092 | 2167 | ||
| @@ -2095,7 +2170,7 @@ create_pty (Lisp_Object process) | |||
| 2095 | { | 2170 | { |
| 2096 | struct Lisp_Process *p = XPROCESS (process); | 2171 | struct Lisp_Process *p = XPROCESS (process); |
| 2097 | char pty_name[PTY_NAME_SIZE]; | 2172 | char pty_name[PTY_NAME_SIZE]; |
| 2098 | int pty_fd = NILP (Vprocess_connection_type) ? -1 : allocate_pty (pty_name); | 2173 | int pty_fd = !p->pty_flag ? -1 : allocate_pty (pty_name); |
| 2099 | 2174 | ||
| 2100 | if (pty_fd >= 0) | 2175 | if (pty_fd >= 0) |
| 2101 | { | 2176 | { |
| @@ -2142,11 +2217,184 @@ create_pty (Lisp_Object process) | |||
| 2142 | p->pid = -2; | 2217 | p->pid = -2; |
| 2143 | } | 2218 | } |
| 2144 | 2219 | ||
| 2220 | DEFUN ("make-pipe-process", Fmake_pipe_process, Smake_pipe_process, | ||
| 2221 | 0, MANY, 0, | ||
| 2222 | doc: /* Create and return a bidirectional pipe process. | ||
| 2223 | |||
| 2224 | In Emacs, pipes are represented by process objects, so input and | ||
| 2225 | output work as for subprocesses, and `delete-process' closes a pipe. | ||
| 2226 | However, a pipe process has no process id, it cannot be signaled, | ||
| 2227 | and the status codes are different from normal processes. | ||
| 2228 | |||
| 2229 | Arguments are specified as keyword/argument pairs. The following | ||
| 2230 | arguments are defined: | ||
| 2231 | |||
| 2232 | :name NAME -- NAME is the name of the process. It is modified if necessary to make it unique. | ||
| 2233 | |||
| 2234 | :buffer BUFFER -- BUFFER is the buffer (or buffer-name) to associate | ||
| 2235 | with the process. Process output goes at the end of that buffer, | ||
| 2236 | unless you specify an output stream or filter function to handle the | ||
| 2237 | output. If BUFFER is not given, the value of NAME is used. | ||
| 2238 | |||
| 2239 | :coding CODING -- If CODING is a symbol, it specifies the coding | ||
| 2240 | system used for both reading and writing for this process. If CODING | ||
| 2241 | is a cons (DECODING . ENCODING), DECODING is used for reading, and | ||
| 2242 | ENCODING is used for writing. | ||
| 2243 | |||
| 2244 | :noquery BOOL -- When exiting Emacs, query the user if BOOL is nil and | ||
| 2245 | the process is running. If BOOL is not given, query before exiting. | ||
| 2246 | |||
| 2247 | :stop BOOL -- Start process in the `stopped' state if BOOL non-nil. | ||
| 2248 | In the stopped state, a pipe process does not accept incoming data, | ||
| 2249 | but you can send outgoing data. The stopped state is cleared by | ||
| 2250 | `continue-process' and set by `stop-process'. | ||
| 2251 | |||
| 2252 | :filter FILTER -- Install FILTER as the process filter. | ||
| 2253 | |||
| 2254 | :sentinel SENTINEL -- Install SENTINEL as the process sentinel. | ||
| 2255 | |||
| 2256 | usage: (make-pipe-process &rest ARGS) */) | ||
| 2257 | (ptrdiff_t nargs, Lisp_Object *args) | ||
| 2258 | { | ||
| 2259 | Lisp_Object proc, contact; | ||
| 2260 | struct Lisp_Process *p; | ||
| 2261 | Lisp_Object name, buffer; | ||
| 2262 | Lisp_Object tem; | ||
| 2263 | ptrdiff_t specpdl_count; | ||
| 2264 | int inchannel, outchannel; | ||
| 2265 | |||
| 2266 | if (nargs == 0) | ||
| 2267 | return Qnil; | ||
| 2268 | |||
| 2269 | contact = Flist (nargs, args); | ||
| 2270 | |||
| 2271 | name = Fplist_get (contact, QCname); | ||
| 2272 | CHECK_STRING (name); | ||
| 2273 | proc = make_process (name); | ||
| 2274 | specpdl_count = SPECPDL_INDEX (); | ||
| 2275 | record_unwind_protect (remove_process, proc); | ||
| 2276 | p = XPROCESS (proc); | ||
| 2277 | |||
| 2278 | if (emacs_pipe (p->open_fd + SUBPROCESS_STDIN) != 0 | ||
| 2279 | || emacs_pipe (p->open_fd + READ_FROM_SUBPROCESS) != 0) | ||
| 2280 | report_file_error ("Creating pipe", Qnil); | ||
| 2281 | outchannel = p->open_fd[WRITE_TO_SUBPROCESS]; | ||
| 2282 | inchannel = p->open_fd[READ_FROM_SUBPROCESS]; | ||
| 2283 | |||
| 2284 | fcntl (inchannel, F_SETFL, O_NONBLOCK); | ||
| 2285 | fcntl (outchannel, F_SETFL, O_NONBLOCK); | ||
| 2286 | |||
| 2287 | #ifdef WINDOWSNT | ||
| 2288 | register_aux_fd (inchannel); | ||
| 2289 | #endif | ||
| 2290 | |||
| 2291 | /* Record this as an active process, with its channels. */ | ||
| 2292 | chan_process[inchannel] = proc; | ||
| 2293 | p->infd = inchannel; | ||
| 2294 | p->outfd = outchannel; | ||
| 2295 | |||
| 2296 | if (inchannel > max_desc) | ||
| 2297 | max_desc = inchannel; | ||
| 2298 | |||
| 2299 | buffer = Fplist_get (contact, QCbuffer); | ||
| 2300 | if (NILP (buffer)) | ||
| 2301 | buffer = name; | ||
| 2302 | buffer = Fget_buffer_create (buffer); | ||
| 2303 | pset_buffer (p, buffer); | ||
| 2304 | |||
| 2305 | pset_childp (p, contact); | ||
| 2306 | pset_plist (p, Fcopy_sequence (Fplist_get (contact, QCplist))); | ||
| 2307 | pset_type (p, Qpipe); | ||
| 2308 | pset_sentinel (p, Fplist_get (contact, QCsentinel)); | ||
| 2309 | pset_filter (p, Fplist_get (contact, QCfilter)); | ||
| 2310 | pset_log (p, Qnil); | ||
| 2311 | if (tem = Fplist_get (contact, QCnoquery), !NILP (tem)) | ||
| 2312 | p->kill_without_query = 1; | ||
| 2313 | if (tem = Fplist_get (contact, QCstop), !NILP (tem)) | ||
| 2314 | pset_command (p, Qt); | ||
| 2315 | eassert (! p->pty_flag); | ||
| 2316 | |||
| 2317 | if (!EQ (p->command, Qt)) | ||
| 2318 | add_non_keyboard_read_fd (inchannel); | ||
| 2319 | p->adaptive_read_buffering | ||
| 2320 | = (NILP (Vprocess_adaptive_read_buffering) ? 0 | ||
| 2321 | : EQ (Vprocess_adaptive_read_buffering, Qt) ? 1 : 2); | ||
| 2322 | |||
| 2323 | /* Make the process marker point into the process buffer (if any). */ | ||
| 2324 | if (BUFFERP (buffer)) | ||
| 2325 | set_marker_both (p->mark, buffer, | ||
| 2326 | BUF_ZV (XBUFFER (buffer)), | ||
| 2327 | BUF_ZV_BYTE (XBUFFER (buffer))); | ||
| 2328 | |||
| 2329 | { | ||
| 2330 | /* Setup coding systems for communicating with the network stream. */ | ||
| 2331 | |||
| 2332 | /* Qt denotes we have not yet called Ffind_operation_coding_system. */ | ||
| 2333 | Lisp_Object coding_systems = Qt; | ||
| 2334 | Lisp_Object val; | ||
| 2335 | |||
| 2336 | tem = Fplist_get (contact, QCcoding); | ||
| 2337 | val = Qnil; | ||
| 2338 | if (!NILP (tem)) | ||
| 2339 | { | ||
| 2340 | val = tem; | ||
| 2341 | if (CONSP (val)) | ||
| 2342 | val = XCAR (val); | ||
| 2343 | } | ||
| 2344 | else if (!NILP (Vcoding_system_for_read)) | ||
| 2345 | val = Vcoding_system_for_read; | ||
| 2346 | else if ((!NILP (buffer) && NILP (BVAR (XBUFFER (buffer), enable_multibyte_characters))) | ||
| 2347 | || (NILP (buffer) && NILP (BVAR (&buffer_defaults, enable_multibyte_characters)))) | ||
| 2348 | /* We dare not decode end-of-line format by setting VAL to | ||
| 2349 | Qraw_text, because the existing Emacs Lisp libraries | ||
| 2350 | assume that they receive bare code including a sequence of | ||
| 2351 | CR LF. */ | ||
| 2352 | val = Qnil; | ||
| 2353 | else | ||
| 2354 | { | ||
| 2355 | if (CONSP (coding_systems)) | ||
| 2356 | val = XCAR (coding_systems); | ||
| 2357 | else if (CONSP (Vdefault_process_coding_system)) | ||
| 2358 | val = XCAR (Vdefault_process_coding_system); | ||
| 2359 | else | ||
| 2360 | val = Qnil; | ||
| 2361 | } | ||
| 2362 | pset_decode_coding_system (p, val); | ||
| 2363 | |||
| 2364 | if (!NILP (tem)) | ||
| 2365 | { | ||
| 2366 | val = tem; | ||
| 2367 | if (CONSP (val)) | ||
| 2368 | val = XCDR (val); | ||
| 2369 | } | ||
| 2370 | else if (!NILP (Vcoding_system_for_write)) | ||
| 2371 | val = Vcoding_system_for_write; | ||
| 2372 | else if (NILP (BVAR (current_buffer, enable_multibyte_characters))) | ||
| 2373 | val = Qnil; | ||
| 2374 | else | ||
| 2375 | { | ||
| 2376 | if (CONSP (coding_systems)) | ||
| 2377 | val = XCDR (coding_systems); | ||
| 2378 | else if (CONSP (Vdefault_process_coding_system)) | ||
| 2379 | val = XCDR (Vdefault_process_coding_system); | ||
| 2380 | else | ||
| 2381 | val = Qnil; | ||
| 2382 | } | ||
| 2383 | pset_encode_coding_system (p, val); | ||
| 2384 | } | ||
| 2385 | /* This may signal an error. */ | ||
| 2386 | setup_process_coding_systems (proc); | ||
| 2387 | |||
| 2388 | specpdl_ptr = specpdl + specpdl_count; | ||
| 2389 | |||
| 2390 | return proc; | ||
| 2391 | } | ||
| 2392 | |||
| 2145 | 2393 | ||
| 2146 | /* Convert an internal struct sockaddr to a lisp object (vector or string). | 2394 | /* Convert an internal struct sockaddr to a lisp object (vector or string). |
| 2147 | The address family of sa is not included in the result. */ | 2395 | The address family of sa is not included in the result. */ |
| 2148 | 2396 | ||
| 2149 | static Lisp_Object | 2397 | Lisp_Object |
| 2150 | conv_sockaddr_to_lisp (struct sockaddr *sa, int len) | 2398 | conv_sockaddr_to_lisp (struct sockaddr *sa, int len) |
| 2151 | { | 2399 | { |
| 2152 | Lisp_Object address; | 2400 | Lisp_Object address; |
| @@ -2177,7 +2425,7 @@ conv_sockaddr_to_lisp (struct sockaddr *sa, int len) | |||
| 2177 | { | 2425 | { |
| 2178 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa; | 2426 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa; |
| 2179 | uint16_t *ip6 = (uint16_t *) &sin6->sin6_addr; | 2427 | uint16_t *ip6 = (uint16_t *) &sin6->sin6_addr; |
| 2180 | len = sizeof (sin6->sin6_addr)/2 + 1; | 2428 | len = sizeof (sin6->sin6_addr) / 2 + 1; |
| 2181 | address = Fmake_vector (make_number (len), Qnil); | 2429 | address = Fmake_vector (make_number (len), Qnil); |
| 2182 | p = XVECTOR (address); | 2430 | p = XVECTOR (address); |
| 2183 | p->contents[--len] = make_number (ntohs (sin6->sin6_port)); | 2431 | p->contents[--len] = make_number (ntohs (sin6->sin6_port)); |
| @@ -2190,10 +2438,22 @@ conv_sockaddr_to_lisp (struct sockaddr *sa, int len) | |||
| 2190 | case AF_LOCAL: | 2438 | case AF_LOCAL: |
| 2191 | { | 2439 | { |
| 2192 | struct sockaddr_un *sockun = (struct sockaddr_un *) sa; | 2440 | struct sockaddr_un *sockun = (struct sockaddr_un *) sa; |
| 2193 | for (i = 0; i < sizeof (sockun->sun_path); i++) | 2441 | ptrdiff_t name_length = len - offsetof (struct sockaddr_un, sun_path); |
| 2194 | if (sockun->sun_path[i] == 0) | 2442 | /* If the first byte is NUL, the name is a Linux abstract |
| 2195 | break; | 2443 | socket name, and the name can contain embedded NULs. If |
| 2196 | return make_unibyte_string (sockun->sun_path, i); | 2444 | it's not, we have a NUL-terminated string. Be careful not |
| 2445 | to walk past the end of the object looking for the name | ||
| 2446 | terminator, however. */ | ||
| 2447 | if (name_length > 0 && sockun->sun_path[0] != '\0') | ||
| 2448 | { | ||
| 2449 | const char *terminator | ||
| 2450 | = memchr (sockun->sun_path, '\0', name_length); | ||
| 2451 | |||
| 2452 | if (terminator) | ||
| 2453 | name_length = terminator - (const char *) sockun->sun_path; | ||
| 2454 | } | ||
| 2455 | |||
| 2456 | return make_unibyte_string (sockun->sun_path, name_length); | ||
| 2197 | } | 2457 | } |
| 2198 | #endif | 2458 | #endif |
| 2199 | default: | 2459 | default: |
| @@ -2247,8 +2507,10 @@ get_lisp_to_sockaddr_size (Lisp_Object address, int *familyp) | |||
| 2247 | && VECTORP (XCDR (address))) | 2507 | && VECTORP (XCDR (address))) |
| 2248 | { | 2508 | { |
| 2249 | struct sockaddr *sa; | 2509 | struct sockaddr *sa; |
| 2250 | *familyp = XINT (XCAR (address)); | ||
| 2251 | p = XVECTOR (XCDR (address)); | 2510 | p = XVECTOR (XCDR (address)); |
| 2511 | if (MAX_ALLOCA - sizeof sa->sa_family < p->header.size) | ||
| 2512 | return 0; | ||
| 2513 | *familyp = XINT (XCAR (address)); | ||
| 2252 | return p->header.size + sizeof (sa->sa_family); | 2514 | return p->header.size + sizeof (sa->sa_family); |
| 2253 | } | 2515 | } |
| 2254 | return 0; | 2516 | return 0; |
| @@ -2374,14 +2636,14 @@ Returns nil upon error setting address, ADDRESS otherwise. */) | |||
| 2374 | 2636 | ||
| 2375 | static const struct socket_options { | 2637 | static const struct socket_options { |
| 2376 | /* The name of this option. Should be lowercase version of option | 2638 | /* The name of this option. Should be lowercase version of option |
| 2377 | name without SO_ prefix. */ | 2639 | name without SO_ prefix. */ |
| 2378 | const char *name; | 2640 | const char *name; |
| 2379 | /* Option level SOL_... */ | 2641 | /* Option level SOL_... */ |
| 2380 | int optlevel; | 2642 | int optlevel; |
| 2381 | /* Option number SO_... */ | 2643 | /* Option number SO_... */ |
| 2382 | int optnum; | 2644 | int optnum; |
| 2383 | enum { SOPT_UNKNOWN, SOPT_BOOL, SOPT_INT, SOPT_IFNAME, SOPT_LINGER } opttype; | 2645 | enum { SOPT_UNKNOWN, SOPT_BOOL, SOPT_INT, SOPT_IFNAME, SOPT_LINGER } opttype; |
| 2384 | enum { OPIX_NONE=0, OPIX_MISC=1, OPIX_REUSEADDR=2 } optbit; | 2646 | enum { OPIX_NONE = 0, OPIX_MISC = 1, OPIX_REUSEADDR = 2 } optbit; |
| 2385 | } socket_options[] = | 2647 | } socket_options[] = |
| 2386 | { | 2648 | { |
| 2387 | #ifdef SO_BINDTODEVICE | 2649 | #ifdef SO_BINDTODEVICE |
| @@ -2457,7 +2719,7 @@ set_socket_option (int s, Lisp_Object opt, Lisp_Object val) | |||
| 2457 | #ifdef SO_BINDTODEVICE | 2719 | #ifdef SO_BINDTODEVICE |
| 2458 | case SOPT_IFNAME: | 2720 | case SOPT_IFNAME: |
| 2459 | { | 2721 | { |
| 2460 | char devname[IFNAMSIZ+1]; | 2722 | char devname[IFNAMSIZ + 1]; |
| 2461 | 2723 | ||
| 2462 | /* This is broken, at least in the Linux 2.4 kernel. | 2724 | /* This is broken, at least in the Linux 2.4 kernel. |
| 2463 | To unbind, the arg must be a zero integer, not the empty string. | 2725 | To unbind, the arg must be a zero integer, not the empty string. |
| @@ -2586,7 +2848,7 @@ is not given or nil, 1 stopbit is used. | |||
| 2586 | :flowcontrol FLOWCONTROL -- FLOWCONTROL determines the type of | 2848 | :flowcontrol FLOWCONTROL -- FLOWCONTROL determines the type of |
| 2587 | flowcontrol to be used, which is either nil (don't use flowcontrol), | 2849 | flowcontrol to be used, which is either nil (don't use flowcontrol), |
| 2588 | the symbol `hw' (use RTS/CTS hardware flowcontrol), or the symbol `sw' | 2850 | the symbol `hw' (use RTS/CTS hardware flowcontrol), or the symbol `sw' |
| 2589 | \(use XON/XOFF software flowcontrol). If FLOWCONTROL is not given, no | 2851 | (use XON/XOFF software flowcontrol). If FLOWCONTROL is not given, no |
| 2590 | flowcontrol is used. | 2852 | flowcontrol is used. |
| 2591 | 2853 | ||
| 2592 | `serial-process-configure' is called by `make-serial-process' for the | 2854 | `serial-process-configure' is called by `make-serial-process' for the |
| @@ -2594,12 +2856,12 @@ initial configuration of the serial port. | |||
| 2594 | 2856 | ||
| 2595 | Examples: | 2857 | Examples: |
| 2596 | 2858 | ||
| 2597 | \(serial-process-configure :process "/dev/ttyS0" :speed 1200) | 2859 | (serial-process-configure :process "/dev/ttyS0" :speed 1200) |
| 2598 | 2860 | ||
| 2599 | \(serial-process-configure | 2861 | (serial-process-configure |
| 2600 | :buffer "COM1" :stopbits 1 :parity 'odd :flowcontrol 'hw) | 2862 | :buffer "COM1" :stopbits 1 :parity \\='odd :flowcontrol \\='hw) |
| 2601 | 2863 | ||
| 2602 | \(serial-process-configure :port "\\\\.\\COM13" :bytesize 7) | 2864 | (serial-process-configure :port "\\\\.\\COM13" :bytesize 7) |
| 2603 | 2865 | ||
| 2604 | usage: (serial-process-configure &rest ARGS) */) | 2866 | usage: (serial-process-configure &rest ARGS) */) |
| 2605 | (ptrdiff_t nargs, Lisp_Object *args) | 2867 | (ptrdiff_t nargs, Lisp_Object *args) |
| @@ -2607,10 +2869,8 @@ usage: (serial-process-configure &rest ARGS) */) | |||
| 2607 | struct Lisp_Process *p; | 2869 | struct Lisp_Process *p; |
| 2608 | Lisp_Object contact = Qnil; | 2870 | Lisp_Object contact = Qnil; |
| 2609 | Lisp_Object proc = Qnil; | 2871 | Lisp_Object proc = Qnil; |
| 2610 | struct gcpro gcpro1; | ||
| 2611 | 2872 | ||
| 2612 | contact = Flist (nargs, args); | 2873 | contact = Flist (nargs, args); |
| 2613 | GCPRO1 (contact); | ||
| 2614 | 2874 | ||
| 2615 | proc = Fplist_get (contact, QCprocess); | 2875 | proc = Fplist_get (contact, QCprocess); |
| 2616 | if (NILP (proc)) | 2876 | if (NILP (proc)) |
| @@ -2625,14 +2885,9 @@ usage: (serial-process-configure &rest ARGS) */) | |||
| 2625 | error ("Not a serial process"); | 2885 | error ("Not a serial process"); |
| 2626 | 2886 | ||
| 2627 | if (NILP (Fplist_get (p->childp, QCspeed))) | 2887 | if (NILP (Fplist_get (p->childp, QCspeed))) |
| 2628 | { | 2888 | return Qnil; |
| 2629 | UNGCPRO; | ||
| 2630 | return Qnil; | ||
| 2631 | } | ||
| 2632 | 2889 | ||
| 2633 | serial_configure (p, contact); | 2890 | serial_configure (p, contact); |
| 2634 | |||
| 2635 | UNGCPRO; | ||
| 2636 | return Qnil; | 2891 | return Qnil; |
| 2637 | } | 2892 | } |
| 2638 | 2893 | ||
| @@ -2700,13 +2955,13 @@ is available via the function `process-contact'. | |||
| 2700 | 2955 | ||
| 2701 | Examples: | 2956 | Examples: |
| 2702 | 2957 | ||
| 2703 | \(make-serial-process :port "/dev/ttyS0" :speed 9600) | 2958 | (make-serial-process :port "/dev/ttyS0" :speed 9600) |
| 2704 | 2959 | ||
| 2705 | \(make-serial-process :port "COM1" :speed 115200 :stopbits 2) | 2960 | (make-serial-process :port "COM1" :speed 115200 :stopbits 2) |
| 2706 | 2961 | ||
| 2707 | \(make-serial-process :port "\\\\.\\COM13" :speed 1200 :bytesize 7 :parity 'odd) | 2962 | (make-serial-process :port "\\\\.\\COM13" :speed 1200 :bytesize 7 :parity \\='odd) |
| 2708 | 2963 | ||
| 2709 | \(make-serial-process :port "/dev/tty.BlueConsole-SPP-1" :speed nil) | 2964 | (make-serial-process :port "/dev/tty.BlueConsole-SPP-1" :speed nil) |
| 2710 | 2965 | ||
| 2711 | usage: (make-serial-process &rest ARGS) */) | 2966 | usage: (make-serial-process &rest ARGS) */) |
| 2712 | (ptrdiff_t nargs, Lisp_Object *args) | 2967 | (ptrdiff_t nargs, Lisp_Object *args) |
| @@ -2714,7 +2969,6 @@ usage: (make-serial-process &rest ARGS) */) | |||
| 2714 | int fd = -1; | 2969 | int fd = -1; |
| 2715 | Lisp_Object proc, contact, port; | 2970 | Lisp_Object proc, contact, port; |
| 2716 | struct Lisp_Process *p; | 2971 | struct Lisp_Process *p; |
| 2717 | struct gcpro gcpro1; | ||
| 2718 | Lisp_Object name, buffer; | 2972 | Lisp_Object name, buffer; |
| 2719 | Lisp_Object tem, val; | 2973 | Lisp_Object tem, val; |
| 2720 | ptrdiff_t specpdl_count; | 2974 | ptrdiff_t specpdl_count; |
| @@ -2723,7 +2977,6 @@ usage: (make-serial-process &rest ARGS) */) | |||
| 2723 | return Qnil; | 2977 | return Qnil; |
| 2724 | 2978 | ||
| 2725 | contact = Flist (nargs, args); | 2979 | contact = Flist (nargs, args); |
| 2726 | GCPRO1 (contact); | ||
| 2727 | 2980 | ||
| 2728 | port = Fplist_get (contact, QCport); | 2981 | port = Fplist_get (contact, QCport); |
| 2729 | if (NILP (port)) | 2982 | if (NILP (port)) |
| @@ -2823,7 +3076,6 @@ usage: (make-serial-process &rest ARGS) */) | |||
| 2823 | 3076 | ||
| 2824 | specpdl_ptr = specpdl + specpdl_count; | 3077 | specpdl_ptr = specpdl + specpdl_count; |
| 2825 | 3078 | ||
| 2826 | UNGCPRO; | ||
| 2827 | return proc; | 3079 | return proc; |
| 2828 | } | 3080 | } |
| 2829 | 3081 | ||
| @@ -2831,7 +3083,7 @@ usage: (make-serial-process &rest ARGS) */) | |||
| 2831 | exactly like a normal process when reading and writing. Primary | 3083 | exactly like a normal process when reading and writing. Primary |
| 2832 | differences are in status display and process deletion. A network | 3084 | differences are in status display and process deletion. A network |
| 2833 | connection has no PID; you cannot signal it. All you can do is | 3085 | connection has no PID; you cannot signal it. All you can do is |
| 2834 | stop/continue it and deactivate/close it via delete-process */ | 3086 | stop/continue it and deactivate/close it via delete-process. */ |
| 2835 | 3087 | ||
| 2836 | DEFUN ("make-network-process", Fmake_network_process, Smake_network_process, | 3088 | DEFUN ("make-network-process", Fmake_network_process, Smake_network_process, |
| 2837 | 0, MANY, 0, | 3089 | 0, MANY, 0, |
| @@ -2935,7 +3187,7 @@ client. The arguments are SERVER, CLIENT, and MESSAGE, where SERVER | |||
| 2935 | is the server process, CLIENT is the new process for the connection, | 3187 | is the server process, CLIENT is the new process for the connection, |
| 2936 | and MESSAGE is a string. | 3188 | and MESSAGE is a string. |
| 2937 | 3189 | ||
| 2938 | :plist PLIST -- Install PLIST as the new process' initial plist. | 3190 | :plist PLIST -- Install PLIST as the new process's initial plist. |
| 2939 | 3191 | ||
| 2940 | :server QLEN -- if QLEN is non-nil, create a server process for the | 3192 | :server QLEN -- if QLEN is non-nil, create a server process for the |
| 2941 | specified FAMILY, SERVICE, and connection type (stream or datagram). | 3193 | specified FAMILY, SERVICE, and connection type (stream or datagram). |
| @@ -2965,21 +3217,21 @@ When a client connection is accepted, a new network process is created | |||
| 2965 | for the connection with the following parameters: | 3217 | for the connection with the following parameters: |
| 2966 | 3218 | ||
| 2967 | - The client's process name is constructed by concatenating the server | 3219 | - The client's process name is constructed by concatenating the server |
| 2968 | process' NAME and a client identification string. | 3220 | process's NAME and a client identification string. |
| 2969 | - If the FILTER argument is non-nil, the client process will not get a | 3221 | - If the FILTER argument is non-nil, the client process will not get a |
| 2970 | separate process buffer; otherwise, the client's process buffer is a newly | 3222 | separate process buffer; otherwise, the client's process buffer is a newly |
| 2971 | created buffer named after the server process' BUFFER name or process | 3223 | created buffer named after the server process's BUFFER name or process |
| 2972 | NAME concatenated with the client identification string. | 3224 | NAME concatenated with the client identification string. |
| 2973 | - The connection type and the process filter and sentinel parameters are | 3225 | - The connection type and the process filter and sentinel parameters are |
| 2974 | inherited from the server process' TYPE, FILTER and SENTINEL. | 3226 | inherited from the server process's TYPE, FILTER and SENTINEL. |
| 2975 | - The client process' contact info is set according to the client's | 3227 | - The client process's contact info is set according to the client's |
| 2976 | addressing information (typically an IP address and a port number). | 3228 | addressing information (typically an IP address and a port number). |
| 2977 | - The client process' plist is initialized from the server's plist. | 3229 | - The client process's plist is initialized from the server's plist. |
| 2978 | 3230 | ||
| 2979 | Notice that the FILTER and SENTINEL args are never used directly by | 3231 | Notice that the FILTER and SENTINEL args are never used directly by |
| 2980 | the server process. Also, the BUFFER argument is not used directly by | 3232 | the server process. Also, the BUFFER argument is not used directly by |
| 2981 | the server process, but via the optional :log function, accepted (and | 3233 | the server process, but via the optional :log function, accepted (and |
| 2982 | failed) connections may be logged in the server process' buffer. | 3234 | failed) connections may be logged in the server process's buffer. |
| 2983 | 3235 | ||
| 2984 | The original argument list, modified with the actual connection | 3236 | The original argument list, modified with the actual connection |
| 2985 | information, is available via the `process-contact' function. | 3237 | information, is available via the `process-contact' function. |
| @@ -3014,10 +3266,9 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3014 | int ret = 0; | 3266 | int ret = 0; |
| 3015 | int xerrno = 0; | 3267 | int xerrno = 0; |
| 3016 | int s = -1, outch, inch; | 3268 | int s = -1, outch, inch; |
| 3017 | struct gcpro gcpro1; | ||
| 3018 | ptrdiff_t count = SPECPDL_INDEX (); | 3269 | ptrdiff_t count = SPECPDL_INDEX (); |
| 3019 | ptrdiff_t count1; | 3270 | ptrdiff_t count1; |
| 3020 | Lisp_Object QCaddress; /* one of QClocal or QCremote */ | 3271 | Lisp_Object colon_address; /* Either QClocal or QCremote. */ |
| 3021 | Lisp_Object tem; | 3272 | Lisp_Object tem; |
| 3022 | Lisp_Object name, buffer, host, service, address; | 3273 | Lisp_Object name, buffer, host, service, address; |
| 3023 | Lisp_Object filter, sentinel; | 3274 | Lisp_Object filter, sentinel; |
| @@ -3032,10 +3283,9 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3032 | 3283 | ||
| 3033 | /* Save arguments for process-contact and clone-process. */ | 3284 | /* Save arguments for process-contact and clone-process. */ |
| 3034 | contact = Flist (nargs, args); | 3285 | contact = Flist (nargs, args); |
| 3035 | GCPRO1 (contact); | ||
| 3036 | 3286 | ||
| 3037 | #ifdef WINDOWSNT | 3287 | #ifdef WINDOWSNT |
| 3038 | /* Ensure socket support is loaded if available. */ | 3288 | /* Ensure socket support is loaded if available. */ |
| 3039 | init_winsock (TRUE); | 3289 | init_winsock (TRUE); |
| 3040 | #endif | 3290 | #endif |
| 3041 | 3291 | ||
| @@ -3065,8 +3315,8 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3065 | backlog = XINT (tem); | 3315 | backlog = XINT (tem); |
| 3066 | } | 3316 | } |
| 3067 | 3317 | ||
| 3068 | /* Make QCaddress an alias for :local (server) or :remote (client). */ | 3318 | /* Make colon_address an alias for :local (server) or :remote (client). */ |
| 3069 | QCaddress = is_server ? QClocal : QCremote; | 3319 | colon_address = is_server ? QClocal : QCremote; |
| 3070 | 3320 | ||
| 3071 | /* :nowait BOOL */ | 3321 | /* :nowait BOOL */ |
| 3072 | if (!is_server && socktype != SOCK_DGRAM | 3322 | if (!is_server && socktype != SOCK_DGRAM |
| @@ -3093,7 +3343,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3093 | res = &ai; | 3343 | res = &ai; |
| 3094 | 3344 | ||
| 3095 | /* :local ADDRESS or :remote ADDRESS */ | 3345 | /* :local ADDRESS or :remote ADDRESS */ |
| 3096 | address = Fplist_get (contact, QCaddress); | 3346 | address = Fplist_get (contact, colon_address); |
| 3097 | if (!NILP (address)) | 3347 | if (!NILP (address)) |
| 3098 | { | 3348 | { |
| 3099 | host = service = Qnil; | 3349 | host = service = Qnil; |
| @@ -3142,7 +3392,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3142 | { | 3392 | { |
| 3143 | if (EQ (host, Qlocal)) | 3393 | if (EQ (host, Qlocal)) |
| 3144 | /* Depending on setup, "localhost" may map to different IPv4 and/or | 3394 | /* Depending on setup, "localhost" may map to different IPv4 and/or |
| 3145 | IPv6 addresses, so it's better to be explicit. (Bug#6781) */ | 3395 | IPv6 addresses, so it's better to be explicit (Bug#6781). */ |
| 3146 | host = build_string ("127.0.0.1"); | 3396 | host = build_string ("127.0.0.1"); |
| 3147 | CHECK_STRING (host); | 3397 | CHECK_STRING (host); |
| 3148 | } | 3398 | } |
| @@ -3152,8 +3402,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3152 | { | 3402 | { |
| 3153 | if (!NILP (host)) | 3403 | if (!NILP (host)) |
| 3154 | { | 3404 | { |
| 3155 | message (":family local ignores the :host \"%s\" property", | 3405 | message (":family local ignores the :host property"); |
| 3156 | SDATA (host)); | ||
| 3157 | contact = Fplist_put (contact, QChost, Qnil); | 3406 | contact = Fplist_put (contact, QChost, Qnil); |
| 3158 | host = Qnil; | 3407 | host = Qnil; |
| 3159 | } | 3408 | } |
| @@ -3162,7 +3411,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3162 | address_un.sun_family = AF_LOCAL; | 3411 | address_un.sun_family = AF_LOCAL; |
| 3163 | if (sizeof address_un.sun_path <= SBYTES (service)) | 3412 | if (sizeof address_un.sun_path <= SBYTES (service)) |
| 3164 | error ("Service name too long"); | 3413 | error ("Service name too long"); |
| 3165 | strcpy (address_un.sun_path, SSDATA (service)); | 3414 | lispstpcpy (address_un.sun_path, service); |
| 3166 | ai.ai_addr = (struct sockaddr *) &address_un; | 3415 | ai.ai_addr = (struct sockaddr *) &address_un; |
| 3167 | ai.ai_addrlen = sizeof address_un; | 3416 | ai.ai_addrlen = sizeof address_un; |
| 3168 | goto open_socket; | 3417 | goto open_socket; |
| @@ -3274,7 +3523,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3274 | address_in.sin_family = family; | 3523 | address_in.sin_family = family; |
| 3275 | } | 3524 | } |
| 3276 | else | 3525 | else |
| 3277 | /* Attempt to interpret host as numeric inet address */ | 3526 | /* Attempt to interpret host as numeric inet address. */ |
| 3278 | { | 3527 | { |
| 3279 | unsigned long numeric_addr; | 3528 | unsigned long numeric_addr; |
| 3280 | numeric_addr = inet_addr (SSDATA (host)); | 3529 | numeric_addr = inet_addr (SSDATA (host)); |
| @@ -3340,8 +3589,8 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3340 | /* Parse network options in the arg list. | 3589 | /* Parse network options in the arg list. |
| 3341 | We simply ignore anything which isn't a known option (including other keywords). | 3590 | We simply ignore anything which isn't a known option (including other keywords). |
| 3342 | An error is signaled if setting a known option fails. */ | 3591 | An error is signaled if setting a known option fails. */ |
| 3343 | for (optn = optbits = 0; optn < nargs-1; optn += 2) | 3592 | for (optn = optbits = 0; optn < nargs - 1; optn += 2) |
| 3344 | optbits |= set_socket_option (s, args[optn], args[optn+1]); | 3593 | optbits |= set_socket_option (s, args[optn], args[optn + 1]); |
| 3345 | 3594 | ||
| 3346 | if (is_server) | 3595 | if (is_server) |
| 3347 | { | 3596 | { |
| @@ -3412,10 +3661,10 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3412 | { | 3661 | { |
| 3413 | /* Unlike most other syscalls connect() cannot be called | 3662 | /* Unlike most other syscalls connect() cannot be called |
| 3414 | again. (That would return EALREADY.) The proper way to | 3663 | again. (That would return EALREADY.) The proper way to |
| 3415 | wait for completion is pselect(). */ | 3664 | wait for completion is pselect(). */ |
| 3416 | int sc; | 3665 | int sc; |
| 3417 | socklen_t len; | 3666 | socklen_t len; |
| 3418 | SELECT_TYPE fdset; | 3667 | fd_set fdset; |
| 3419 | retry_select: | 3668 | retry_select: |
| 3420 | FD_ZERO (&fdset); | 3669 | FD_ZERO (&fdset); |
| 3421 | FD_SET (s, &fdset); | 3670 | FD_SET (s, &fdset); |
| @@ -3480,7 +3729,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3480 | memcpy (datagram_address[s].sa, lres->ai_addr, lres->ai_addrlen); | 3729 | memcpy (datagram_address[s].sa, lres->ai_addr, lres->ai_addrlen); |
| 3481 | } | 3730 | } |
| 3482 | #endif | 3731 | #endif |
| 3483 | contact = Fplist_put (contact, QCaddress, | 3732 | contact = Fplist_put (contact, colon_address, |
| 3484 | conv_sockaddr_to_lisp (lres->ai_addr, lres->ai_addrlen)); | 3733 | conv_sockaddr_to_lisp (lres->ai_addr, lres->ai_addrlen)); |
| 3485 | #ifdef HAVE_GETSOCKNAME | 3734 | #ifdef HAVE_GETSOCKNAME |
| 3486 | if (!is_server) | 3735 | if (!is_server) |
| @@ -3593,10 +3842,9 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3593 | 3842 | ||
| 3594 | { | 3843 | { |
| 3595 | /* Setup coding systems for communicating with the network stream. */ | 3844 | /* Setup coding systems for communicating with the network stream. */ |
| 3596 | struct gcpro gcpro1; | ||
| 3597 | /* Qt denotes we have not yet called Ffind_operation_coding_system. */ | 3845 | /* Qt denotes we have not yet called Ffind_operation_coding_system. */ |
| 3598 | Lisp_Object coding_systems = Qt; | 3846 | Lisp_Object coding_systems = Qt; |
| 3599 | Lisp_Object fargs[5], val; | 3847 | Lisp_Object val; |
| 3600 | 3848 | ||
| 3601 | if (!NILP (tem)) | 3849 | if (!NILP (tem)) |
| 3602 | { | 3850 | { |
| @@ -3618,13 +3866,9 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3618 | if (NILP (host) || NILP (service)) | 3866 | if (NILP (host) || NILP (service)) |
| 3619 | coding_systems = Qnil; | 3867 | coding_systems = Qnil; |
| 3620 | else | 3868 | else |
| 3621 | { | 3869 | coding_systems = CALLN (Ffind_operation_coding_system, |
| 3622 | fargs[0] = Qopen_network_stream, fargs[1] = name, | 3870 | Qopen_network_stream, name, buffer, |
| 3623 | fargs[2] = buffer, fargs[3] = host, fargs[4] = service; | 3871 | host, service); |
| 3624 | GCPRO1 (proc); | ||
| 3625 | coding_systems = Ffind_operation_coding_system (5, fargs); | ||
| 3626 | UNGCPRO; | ||
| 3627 | } | ||
| 3628 | if (CONSP (coding_systems)) | 3872 | if (CONSP (coding_systems)) |
| 3629 | val = XCAR (coding_systems); | 3873 | val = XCAR (coding_systems); |
| 3630 | else if (CONSP (Vdefault_process_coding_system)) | 3874 | else if (CONSP (Vdefault_process_coding_system)) |
| @@ -3651,13 +3895,9 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3651 | if (NILP (host) || NILP (service)) | 3895 | if (NILP (host) || NILP (service)) |
| 3652 | coding_systems = Qnil; | 3896 | coding_systems = Qnil; |
| 3653 | else | 3897 | else |
| 3654 | { | 3898 | coding_systems = CALLN (Ffind_operation_coding_system, |
| 3655 | fargs[0] = Qopen_network_stream, fargs[1] = name, | 3899 | Qopen_network_stream, name, buffer, |
| 3656 | fargs[2] = buffer, fargs[3] = host, fargs[4] = service; | 3900 | host, service); |
| 3657 | GCPRO1 (proc); | ||
| 3658 | coding_systems = Ffind_operation_coding_system (5, fargs); | ||
| 3659 | UNGCPRO; | ||
| 3660 | } | ||
| 3661 | } | 3901 | } |
| 3662 | if (CONSP (coding_systems)) | 3902 | if (CONSP (coding_systems)) |
| 3663 | val = XCDR (coding_systems); | 3903 | val = XCDR (coding_systems); |
| @@ -3677,20 +3917,15 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3677 | p->inherit_coding_system_flag | 3917 | p->inherit_coding_system_flag |
| 3678 | = !(!NILP (tem) || NILP (buffer) || !inherit_process_coding_system); | 3918 | = !(!NILP (tem) || NILP (buffer) || !inherit_process_coding_system); |
| 3679 | 3919 | ||
| 3680 | UNGCPRO; | ||
| 3681 | return proc; | 3920 | return proc; |
| 3682 | } | 3921 | } |
| 3683 | 3922 | ||
| 3684 | 3923 | ||
| 3685 | #if defined (HAVE_NET_IF_H) | 3924 | #ifdef HAVE_NET_IF_H |
| 3686 | 3925 | ||
| 3687 | #ifdef SIOCGIFCONF | 3926 | #ifdef SIOCGIFCONF |
| 3688 | DEFUN ("network-interface-list", Fnetwork_interface_list, Snetwork_interface_list, 0, 0, 0, | 3927 | static Lisp_Object |
| 3689 | doc: /* Return an alist of all network interfaces and their network address. | 3928 | network_interface_list (void) |
| 3690 | Each element is a cons, the car of which is a string containing the | ||
| 3691 | interface name, and the cdr is the network address in internal | ||
| 3692 | format; see the description of ADDRESS in `make-network-process'. */) | ||
| 3693 | (void) | ||
| 3694 | { | 3929 | { |
| 3695 | struct ifconf ifconf; | 3930 | struct ifconf ifconf; |
| 3696 | struct ifreq *ifreq; | 3931 | struct ifreq *ifreq; |
| @@ -3787,7 +4022,7 @@ static const struct ifflag_def ifflag_table[] = { | |||
| 3787 | #endif | 4022 | #endif |
| 3788 | #ifdef IFF_NOTRAILERS | 4023 | #ifdef IFF_NOTRAILERS |
| 3789 | #ifdef NS_IMPL_COCOA | 4024 | #ifdef NS_IMPL_COCOA |
| 3790 | /* Really means smart, notrailers is obsolete */ | 4025 | /* Really means smart, notrailers is obsolete. */ |
| 3791 | { IFF_NOTRAILERS, "smart" }, | 4026 | { IFF_NOTRAILERS, "smart" }, |
| 3792 | #else | 4027 | #else |
| 3793 | { IFF_NOTRAILERS, "notrailers" }, | 4028 | { IFF_NOTRAILERS, "notrailers" }, |
| @@ -3815,30 +4050,25 @@ static const struct ifflag_def ifflag_table[] = { | |||
| 3815 | { IFF_DYNAMIC, "dynamic" }, | 4050 | { IFF_DYNAMIC, "dynamic" }, |
| 3816 | #endif | 4051 | #endif |
| 3817 | #ifdef IFF_OACTIVE | 4052 | #ifdef IFF_OACTIVE |
| 3818 | { IFF_OACTIVE, "oactive" }, /* OpenBSD: transmission in progress */ | 4053 | { IFF_OACTIVE, "oactive" }, /* OpenBSD: transmission in progress. */ |
| 3819 | #endif | 4054 | #endif |
| 3820 | #ifdef IFF_SIMPLEX | 4055 | #ifdef IFF_SIMPLEX |
| 3821 | { IFF_SIMPLEX, "simplex" }, /* OpenBSD: can't hear own transmissions */ | 4056 | { IFF_SIMPLEX, "simplex" }, /* OpenBSD: can't hear own transmissions. */ |
| 3822 | #endif | 4057 | #endif |
| 3823 | #ifdef IFF_LINK0 | 4058 | #ifdef IFF_LINK0 |
| 3824 | { IFF_LINK0, "link0" }, /* OpenBSD: per link layer defined bit */ | 4059 | { IFF_LINK0, "link0" }, /* OpenBSD: per link layer defined bit. */ |
| 3825 | #endif | 4060 | #endif |
| 3826 | #ifdef IFF_LINK1 | 4061 | #ifdef IFF_LINK1 |
| 3827 | { IFF_LINK1, "link1" }, /* OpenBSD: per link layer defined bit */ | 4062 | { IFF_LINK1, "link1" }, /* OpenBSD: per link layer defined bit. */ |
| 3828 | #endif | 4063 | #endif |
| 3829 | #ifdef IFF_LINK2 | 4064 | #ifdef IFF_LINK2 |
| 3830 | { IFF_LINK2, "link2" }, /* OpenBSD: per link layer defined bit */ | 4065 | { IFF_LINK2, "link2" }, /* OpenBSD: per link layer defined bit. */ |
| 3831 | #endif | 4066 | #endif |
| 3832 | { 0, 0 } | 4067 | { 0, 0 } |
| 3833 | }; | 4068 | }; |
| 3834 | 4069 | ||
| 3835 | DEFUN ("network-interface-info", Fnetwork_interface_info, Snetwork_interface_info, 1, 1, 0, | 4070 | static Lisp_Object |
| 3836 | doc: /* Return information about network interface named IFNAME. | 4071 | network_interface_info (Lisp_Object ifname) |
| 3837 | The return value is a list (ADDR BCAST NETMASK HWADDR FLAGS), | ||
| 3838 | where ADDR is the layer 3 address, BCAST is the layer 3 broadcast address, | ||
| 3839 | NETMASK is the layer 3 network mask, HWADDR is the layer 2 address, and | ||
| 3840 | FLAGS is the current flags of the interface. */) | ||
| 3841 | (Lisp_Object ifname) | ||
| 3842 | { | 4072 | { |
| 3843 | struct ifreq rq; | 4073 | struct ifreq rq; |
| 3844 | Lisp_Object res = Qnil; | 4074 | Lisp_Object res = Qnil; |
| @@ -3855,7 +4085,7 @@ FLAGS is the current flags of the interface. */) | |||
| 3855 | 4085 | ||
| 3856 | if (sizeof rq.ifr_name <= SBYTES (ifname)) | 4086 | if (sizeof rq.ifr_name <= SBYTES (ifname)) |
| 3857 | error ("interface name too long"); | 4087 | error ("interface name too long"); |
| 3858 | strcpy (rq.ifr_name, SSDATA (ifname)); | 4088 | lispstpcpy (rq.ifr_name, ifname); |
| 3859 | 4089 | ||
| 3860 | s = socket (AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0); | 4090 | s = socket (AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0); |
| 3861 | if (s < 0) | 4091 | if (s < 0) |
| @@ -3907,7 +4137,9 @@ FLAGS is the current flags of the interface. */) | |||
| 3907 | 4137 | ||
| 3908 | any = 1; | 4138 | any = 1; |
| 3909 | for (n = 0; n < 6; n++) | 4139 | for (n = 0; n < 6; n++) |
| 3910 | p->contents[n] = make_number (((unsigned char *)&rq.ifr_hwaddr.sa_data[0])[n]); | 4140 | p->contents[n] = make_number (((unsigned char *) |
| 4141 | &rq.ifr_hwaddr.sa_data[0]) | ||
| 4142 | [n]); | ||
| 3911 | elt = Fcons (make_number (rq.ifr_hwaddr.sa_family), hwaddr); | 4143 | elt = Fcons (make_number (rq.ifr_hwaddr.sa_family), hwaddr); |
| 3912 | } | 4144 | } |
| 3913 | #elif defined (HAVE_GETIFADDRS) && defined (LLADDR) | 4145 | #elif defined (HAVE_GETIFADDRS) && defined (LLADDR) |
| @@ -3980,9 +4212,60 @@ FLAGS is the current flags of the interface. */) | |||
| 3980 | 4212 | ||
| 3981 | return unbind_to (count, any ? res : Qnil); | 4213 | return unbind_to (count, any ? res : Qnil); |
| 3982 | } | 4214 | } |
| 3983 | #endif | 4215 | #endif /* !SIOCGIFADDR && !SIOCGIFHWADDR && !SIOCGIFFLAGS */ |
| 3984 | #endif /* defined (HAVE_NET_IF_H) */ | 4216 | #endif /* defined (HAVE_NET_IF_H) */ |
| 3985 | 4217 | ||
| 4218 | DEFUN ("network-interface-list", Fnetwork_interface_list, | ||
| 4219 | Snetwork_interface_list, 0, 0, 0, | ||
| 4220 | doc: /* Return an alist of all network interfaces and their network address. | ||
| 4221 | Each element is a cons, the car of which is a string containing the | ||
| 4222 | interface name, and the cdr is the network address in internal | ||
| 4223 | format; see the description of ADDRESS in `make-network-process'. | ||
| 4224 | |||
| 4225 | If the information is not available, return nil. */) | ||
| 4226 | (void) | ||
| 4227 | { | ||
| 4228 | #if (defined HAVE_NET_IF_H && defined SIOCGIFCONF) || defined WINDOWSNT | ||
| 4229 | return network_interface_list (); | ||
| 4230 | #else | ||
| 4231 | return Qnil; | ||
| 4232 | #endif | ||
| 4233 | } | ||
| 4234 | |||
| 4235 | DEFUN ("network-interface-info", Fnetwork_interface_info, | ||
| 4236 | Snetwork_interface_info, 1, 1, 0, | ||
| 4237 | doc: /* Return information about network interface named IFNAME. | ||
| 4238 | The return value is a list (ADDR BCAST NETMASK HWADDR FLAGS), | ||
| 4239 | where ADDR is the layer 3 address, BCAST is the layer 3 broadcast address, | ||
| 4240 | NETMASK is the layer 3 network mask, HWADDR is the layer 2 address, and | ||
| 4241 | FLAGS is the current flags of the interface. | ||
| 4242 | |||
| 4243 | Data that is unavailable is returned as nil. */) | ||
| 4244 | (Lisp_Object ifname) | ||
| 4245 | { | ||
| 4246 | #if ((defined HAVE_NET_IF_H \ | ||
| 4247 | && (defined SIOCGIFADDR || defined SIOCGIFHWADDR \ | ||
| 4248 | || defined SIOCGIFFLAGS)) \ | ||
| 4249 | || defined WINDOWSNT) | ||
| 4250 | return network_interface_info (ifname); | ||
| 4251 | #else | ||
| 4252 | return Qnil; | ||
| 4253 | #endif | ||
| 4254 | } | ||
| 4255 | |||
| 4256 | /* If program file NAME starts with /: for quoting a magic | ||
| 4257 | name, remove that, preserving the multibyteness of NAME. */ | ||
| 4258 | |||
| 4259 | Lisp_Object | ||
| 4260 | remove_slash_colon (Lisp_Object name) | ||
| 4261 | { | ||
| 4262 | return | ||
| 4263 | ((SBYTES (name) > 2 && SREF (name, 0) == '/' && SREF (name, 1) == ':') | ||
| 4264 | ? make_specified_string (SSDATA (name) + 2, SCHARS (name) - 2, | ||
| 4265 | SBYTES (name) - 2, STRING_MULTIBYTE (name)) | ||
| 4266 | : name); | ||
| 4267 | } | ||
| 4268 | |||
| 3986 | /* Turn off input and output for process PROC. */ | 4269 | /* Turn off input and output for process PROC. */ |
| 3987 | 4270 | ||
| 3988 | static void | 4271 | static void |
| @@ -3997,7 +4280,6 @@ deactivate_process (Lisp_Object proc) | |||
| 3997 | emacs_gnutls_deinit (proc); | 4280 | emacs_gnutls_deinit (proc); |
| 3998 | #endif /* HAVE_GNUTLS */ | 4281 | #endif /* HAVE_GNUTLS */ |
| 3999 | 4282 | ||
| 4000 | #ifdef ADAPTIVE_READ_BUFFERING | ||
| 4001 | if (p->read_output_delay > 0) | 4283 | if (p->read_output_delay > 0) |
| 4002 | { | 4284 | { |
| 4003 | if (--process_output_delay_count < 0) | 4285 | if (--process_output_delay_count < 0) |
| @@ -4005,9 +4287,8 @@ deactivate_process (Lisp_Object proc) | |||
| 4005 | p->read_output_delay = 0; | 4287 | p->read_output_delay = 0; |
| 4006 | p->read_output_skip = 0; | 4288 | p->read_output_skip = 0; |
| 4007 | } | 4289 | } |
| 4008 | #endif | ||
| 4009 | 4290 | ||
| 4010 | /* Beware SIGCHLD hereabouts. */ | 4291 | /* Beware SIGCHLD hereabouts. */ |
| 4011 | 4292 | ||
| 4012 | for (i = 0; i < PROCESS_OPEN_FDS; i++) | 4293 | for (i = 0; i < PROCESS_OPEN_FDS; i++) |
| 4013 | close_process_fd (&p->open_fd[i]); | 4294 | close_process_fd (&p->open_fd[i]); |
| @@ -4040,20 +4321,21 @@ deactivate_process (Lisp_Object proc) | |||
| 4040 | DEFUN ("accept-process-output", Faccept_process_output, Saccept_process_output, | 4321 | DEFUN ("accept-process-output", Faccept_process_output, Saccept_process_output, |
| 4041 | 0, 4, 0, | 4322 | 0, 4, 0, |
| 4042 | doc: /* Allow any pending output from subprocesses to be read by Emacs. | 4323 | doc: /* Allow any pending output from subprocesses to be read by Emacs. |
| 4043 | It is read into the process' buffers or given to their filter functions. | 4324 | It is given to their filter functions. |
| 4044 | Non-nil arg PROCESS means do not return until some output has been received | 4325 | Optional argument PROCESS means do not return until output has been |
| 4045 | from PROCESS. | 4326 | received from PROCESS. |
| 4046 | 4327 | ||
| 4047 | Non-nil second arg SECONDS and third arg MILLISEC are number of seconds | 4328 | Optional second argument SECONDS and third argument MILLISEC |
| 4048 | and milliseconds to wait; return after that much time whether or not | 4329 | specify a timeout; return after that much time even if there is |
| 4049 | there is any subprocess output. If SECONDS is a floating point number, | 4330 | no subprocess output. If SECONDS is a floating point number, |
| 4050 | it specifies a fractional number of seconds to wait. | 4331 | it specifies a fractional number of seconds to wait. |
| 4051 | The MILLISEC argument is obsolete and should be avoided. | 4332 | The MILLISEC argument is obsolete and should be avoided. |
| 4052 | 4333 | ||
| 4053 | If optional fourth arg JUST-THIS-ONE is non-nil, only accept output | 4334 | If optional fourth argument JUST-THIS-ONE is non-nil, accept output |
| 4054 | from PROCESS, suspending reading output from other processes. | 4335 | from PROCESS only, suspending reading output from other processes. |
| 4055 | If JUST-THIS-ONE is an integer, don't run any timers either. | 4336 | If JUST-THIS-ONE is an integer, don't run any timers either. |
| 4056 | Return non-nil if we received any output before the timeout expired. */) | 4337 | Return non-nil if we received any output from PROCESS (or, if PROCESS |
| 4338 | is nil, from any process) before the timeout expired. */) | ||
| 4057 | (register Lisp_Object process, Lisp_Object seconds, Lisp_Object millisec, Lisp_Object just_this_one) | 4339 | (register Lisp_Object process, Lisp_Object seconds, Lisp_Object millisec, Lisp_Object just_this_one) |
| 4058 | { | 4340 | { |
| 4059 | intmax_t secs; | 4341 | intmax_t secs; |
| @@ -4103,9 +4385,9 @@ Return non-nil if we received any output before the timeout expired. */) | |||
| 4103 | { | 4385 | { |
| 4104 | if (XFLOAT_DATA (seconds) > 0) | 4386 | if (XFLOAT_DATA (seconds) > 0) |
| 4105 | { | 4387 | { |
| 4106 | EMACS_TIME t = EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (seconds)); | 4388 | struct timespec t = dtotimespec (XFLOAT_DATA (seconds)); |
| 4107 | secs = min (EMACS_SECS (t), WAIT_READING_MAX); | 4389 | secs = min (t.tv_sec, WAIT_READING_MAX); |
| 4108 | nsecs = EMACS_NSECS (t); | 4390 | nsecs = t.tv_nsec; |
| 4109 | } | 4391 | } |
| 4110 | } | 4392 | } |
| 4111 | else | 4393 | else |
| @@ -4115,12 +4397,13 @@ Return non-nil if we received any output before the timeout expired. */) | |||
| 4115 | nsecs = 0; | 4397 | nsecs = 0; |
| 4116 | 4398 | ||
| 4117 | return | 4399 | return |
| 4118 | (wait_reading_process_output (secs, nsecs, 0, 0, | 4400 | ((wait_reading_process_output (secs, nsecs, 0, 0, |
| 4119 | Qnil, | 4401 | Qnil, |
| 4120 | !NILP (process) ? XPROCESS (process) : NULL, | 4402 | !NILP (process) ? XPROCESS (process) : NULL, |
| 4121 | NILP (just_this_one) ? 0 : | 4403 | (NILP (just_this_one) ? 0 |
| 4122 | !INTEGERP (just_this_one) ? 1 : -1) | 4404 | : !INTEGERP (just_this_one) ? 1 : -1)) |
| 4123 | ? Qt : Qnil); | 4405 | <= 0) |
| 4406 | ? Qnil : Qt); | ||
| 4124 | } | 4407 | } |
| 4125 | 4408 | ||
| 4126 | /* Accept a connection for server process SERVER on CHANNEL. */ | 4409 | /* Accept a connection for server process SERVER on CHANNEL. */ |
| @@ -4132,7 +4415,7 @@ server_accept_connection (Lisp_Object server, int channel) | |||
| 4132 | { | 4415 | { |
| 4133 | Lisp_Object proc, caller, name, buffer; | 4416 | Lisp_Object proc, caller, name, buffer; |
| 4134 | Lisp_Object contact, host, service; | 4417 | Lisp_Object contact, host, service; |
| 4135 | struct Lisp_Process *ps= XPROCESS (server); | 4418 | struct Lisp_Process *ps = XPROCESS (server); |
| 4136 | struct Lisp_Process *p; | 4419 | struct Lisp_Process *p; |
| 4137 | int s; | 4420 | int s; |
| 4138 | union u_sockaddr { | 4421 | union u_sockaddr { |
| @@ -4184,20 +4467,15 @@ server_accept_connection (Lisp_Object server, int channel) | |||
| 4184 | { | 4467 | { |
| 4185 | case AF_INET: | 4468 | case AF_INET: |
| 4186 | { | 4469 | { |
| 4187 | Lisp_Object args[5]; | ||
| 4188 | unsigned char *ip = (unsigned char *)&saddr.in.sin_addr.s_addr; | 4470 | unsigned char *ip = (unsigned char *)&saddr.in.sin_addr.s_addr; |
| 4189 | args[0] = build_string ("%d.%d.%d.%d"); | ||
| 4190 | args[1] = make_number (*ip++); | ||
| 4191 | args[2] = make_number (*ip++); | ||
| 4192 | args[3] = make_number (*ip++); | ||
| 4193 | args[4] = make_number (*ip++); | ||
| 4194 | host = Fformat (5, args); | ||
| 4195 | service = make_number (ntohs (saddr.in.sin_port)); | ||
| 4196 | 4471 | ||
| 4197 | args[0] = build_string (" <%s:%d>"); | 4472 | AUTO_STRING (ipv4_format, "%d.%d.%d.%d"); |
| 4198 | args[1] = host; | 4473 | host = CALLN (Fformat, ipv4_format, |
| 4199 | args[2] = service; | 4474 | make_number (ip[0]), make_number (ip[1]), |
| 4200 | caller = Fformat (3, args); | 4475 | make_number (ip[2]), make_number (ip[3])); |
| 4476 | service = make_number (ntohs (saddr.in.sin_port)); | ||
| 4477 | AUTO_STRING (caller_format, " <%s:%d>"); | ||
| 4478 | caller = CALLN (Fformat, caller_format, host, service); | ||
| 4201 | } | 4479 | } |
| 4202 | break; | 4480 | break; |
| 4203 | 4481 | ||
| @@ -4207,16 +4485,15 @@ server_accept_connection (Lisp_Object server, int channel) | |||
| 4207 | Lisp_Object args[9]; | 4485 | Lisp_Object args[9]; |
| 4208 | uint16_t *ip6 = (uint16_t *)&saddr.in6.sin6_addr; | 4486 | uint16_t *ip6 = (uint16_t *)&saddr.in6.sin6_addr; |
| 4209 | int i; | 4487 | int i; |
| 4210 | args[0] = build_string ("%x:%x:%x:%x:%x:%x:%x:%x"); | 4488 | |
| 4489 | AUTO_STRING (ipv6_format, "%x:%x:%x:%x:%x:%x:%x:%x"); | ||
| 4490 | args[0] = ipv6_format; | ||
| 4211 | for (i = 0; i < 8; i++) | 4491 | for (i = 0; i < 8; i++) |
| 4212 | args[i+1] = make_number (ntohs (ip6[i])); | 4492 | args[i + 1] = make_number (ntohs (ip6[i])); |
| 4213 | host = Fformat (9, args); | 4493 | host = CALLMANY (Fformat, args); |
| 4214 | service = make_number (ntohs (saddr.in.sin_port)); | 4494 | service = make_number (ntohs (saddr.in.sin_port)); |
| 4215 | 4495 | AUTO_STRING (caller_format, " <[%s]:%d>"); | |
| 4216 | args[0] = build_string (" <[%s]:%d>"); | 4496 | caller = CALLN (Fformat, caller_format, host, service); |
| 4217 | args[1] = host; | ||
| 4218 | args[2] = service; | ||
| 4219 | caller = Fformat (3, args); | ||
| 4220 | } | 4497 | } |
| 4221 | break; | 4498 | break; |
| 4222 | #endif | 4499 | #endif |
| @@ -4226,7 +4503,9 @@ server_accept_connection (Lisp_Object server, int channel) | |||
| 4226 | #endif | 4503 | #endif |
| 4227 | default: | 4504 | default: |
| 4228 | caller = Fnumber_to_string (make_number (connect_counter)); | 4505 | caller = Fnumber_to_string (make_number (connect_counter)); |
| 4229 | caller = concat3 (build_string (" <"), caller, build_string (">")); | 4506 | AUTO_STRING (space_less_than, " <"); |
| 4507 | AUTO_STRING (greater_than, ">"); | ||
| 4508 | caller = concat3 (space_less_than, caller, greater_than); | ||
| 4230 | break; | 4509 | break; |
| 4231 | } | 4510 | } |
| 4232 | 4511 | ||
| @@ -4317,16 +4596,18 @@ server_accept_connection (Lisp_Object server, int channel) | |||
| 4317 | p->inherit_coding_system_flag | 4596 | p->inherit_coding_system_flag |
| 4318 | = (NILP (buffer) ? 0 : ps->inherit_coding_system_flag); | 4597 | = (NILP (buffer) ? 0 : ps->inherit_coding_system_flag); |
| 4319 | 4598 | ||
| 4599 | AUTO_STRING (dash, "-"); | ||
| 4600 | AUTO_STRING (nl, "\n"); | ||
| 4601 | Lisp_Object host_string = STRINGP (host) ? host : dash; | ||
| 4602 | |||
| 4320 | if (!NILP (ps->log)) | 4603 | if (!NILP (ps->log)) |
| 4321 | call3 (ps->log, server, proc, | 4604 | { |
| 4322 | concat3 (build_string ("accept from "), | 4605 | AUTO_STRING (accept_from, "accept from "); |
| 4323 | (STRINGP (host) ? host : build_string ("-")), | 4606 | call3 (ps->log, server, proc, concat3 (accept_from, host_string, nl)); |
| 4324 | build_string ("\n"))); | 4607 | } |
| 4325 | 4608 | ||
| 4326 | exec_sentinel (proc, | 4609 | AUTO_STRING (open_from, "open from "); |
| 4327 | concat3 (build_string ("open from "), | 4610 | exec_sentinel (proc, concat3 (open_from, host_string, nl)); |
| 4328 | (STRINGP (host) ? host : build_string ("-")), | ||
| 4329 | build_string ("\n"))); | ||
| 4330 | } | 4611 | } |
| 4331 | 4612 | ||
| 4332 | static void | 4613 | static void |
| @@ -4369,36 +4650,39 @@ wait_reading_process_output_1 (void) | |||
| 4369 | (and gobble terminal input into the buffer if any arrives). | 4650 | (and gobble terminal input into the buffer if any arrives). |
| 4370 | 4651 | ||
| 4371 | If WAIT_PROC is specified, wait until something arrives from that | 4652 | If WAIT_PROC is specified, wait until something arrives from that |
| 4372 | process. The return value is true if we read some input from | 4653 | process. |
| 4373 | that process. | ||
| 4374 | 4654 | ||
| 4375 | If JUST_WAIT_PROC is nonzero, handle only output from WAIT_PROC | 4655 | If JUST_WAIT_PROC is nonzero, handle only output from WAIT_PROC |
| 4376 | (suspending output from other processes). A negative value | 4656 | (suspending output from other processes). A negative value |
| 4377 | means don't run any timers either. | 4657 | means don't run any timers either. |
| 4378 | 4658 | ||
| 4379 | If WAIT_PROC is specified, then the function returns true if we | 4659 | Return positive if we received input from WAIT_PROC (or from any |
| 4380 | received input from that process before the timeout elapsed. | 4660 | process if WAIT_PROC is null), zero if we attempted to receive |
| 4381 | Otherwise, return true if we received input from any process. */ | 4661 | input but got none, and negative if we didn't even try. */ |
| 4382 | 4662 | ||
| 4383 | bool | 4663 | int |
| 4384 | wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | 4664 | wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, |
| 4385 | bool do_display, | 4665 | bool do_display, |
| 4386 | Lisp_Object wait_for_cell, | 4666 | Lisp_Object wait_for_cell, |
| 4387 | struct Lisp_Process *wait_proc, int just_wait_proc) | 4667 | struct Lisp_Process *wait_proc, int just_wait_proc) |
| 4388 | { | 4668 | { |
| 4389 | int channel, nfds; | 4669 | int channel, nfds; |
| 4390 | SELECT_TYPE Available; | 4670 | fd_set Available; |
| 4391 | SELECT_TYPE Writeok; | 4671 | fd_set Writeok; |
| 4392 | bool check_write; | 4672 | bool check_write; |
| 4393 | int check_delay; | 4673 | int check_delay; |
| 4394 | bool no_avail; | 4674 | bool no_avail; |
| 4395 | int xerrno; | 4675 | int xerrno; |
| 4396 | Lisp_Object proc; | 4676 | Lisp_Object proc; |
| 4397 | EMACS_TIME timeout, end_time; | 4677 | struct timespec timeout, end_time, timer_delay; |
| 4398 | int wait_channel = -1; | 4678 | struct timespec got_output_end_time = invalid_timespec (); |
| 4399 | bool got_some_input = 0; | 4679 | enum { MINIMUM = -1, TIMEOUT, INFINITY } wait; |
| 4680 | int got_some_output = -1; | ||
| 4400 | ptrdiff_t count = SPECPDL_INDEX (); | 4681 | ptrdiff_t count = SPECPDL_INDEX (); |
| 4401 | 4682 | ||
| 4683 | /* Close to the current time if known, an invalid timespec otherwise. */ | ||
| 4684 | struct timespec now = invalid_timespec (); | ||
| 4685 | |||
| 4402 | eassert (wait_proc == NULL | 4686 | eassert (wait_proc == NULL |
| 4403 | || EQ (wait_proc->thread, Qnil) | 4687 | || EQ (wait_proc->thread, Qnil) |
| 4404 | || XTHREAD (wait_proc->thread) == current_thread); | 4688 | || XTHREAD (wait_proc->thread) == current_thread); |
| @@ -4411,33 +4695,27 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4411 | && EQ (XCAR (wait_proc->status), Qexit))) | 4695 | && EQ (XCAR (wait_proc->status), Qexit))) |
| 4412 | message1 ("Blocking call to accept-process-output with quit inhibited!!"); | 4696 | message1 ("Blocking call to accept-process-output with quit inhibited!!"); |
| 4413 | 4697 | ||
| 4414 | /* If wait_proc is a process to watch, set wait_channel accordingly. */ | ||
| 4415 | if (wait_proc != NULL) | ||
| 4416 | wait_channel = wait_proc->infd; | ||
| 4417 | |||
| 4418 | record_unwind_protect_int (wait_reading_process_output_unwind, | 4698 | record_unwind_protect_int (wait_reading_process_output_unwind, |
| 4419 | waiting_for_user_input_p); | 4699 | waiting_for_user_input_p); |
| 4420 | waiting_for_user_input_p = read_kbd; | 4700 | waiting_for_user_input_p = read_kbd; |
| 4421 | 4701 | ||
| 4422 | if (time_limit < 0) | 4702 | if (TYPE_MAXIMUM (time_t) < time_limit) |
| 4423 | { | ||
| 4424 | time_limit = 0; | ||
| 4425 | nsecs = -1; | ||
| 4426 | } | ||
| 4427 | else if (TYPE_MAXIMUM (time_t) < time_limit) | ||
| 4428 | time_limit = TYPE_MAXIMUM (time_t); | 4703 | time_limit = TYPE_MAXIMUM (time_t); |
| 4429 | 4704 | ||
| 4430 | /* Since we may need to wait several times, | 4705 | if (time_limit < 0 || nsecs < 0) |
| 4431 | compute the absolute time to return at. */ | 4706 | wait = MINIMUM; |
| 4432 | if (time_limit || nsecs > 0) | 4707 | else if (time_limit > 0 || nsecs > 0) |
| 4433 | { | 4708 | { |
| 4434 | timeout = make_emacs_time (time_limit, nsecs); | 4709 | wait = TIMEOUT; |
| 4435 | end_time = add_emacs_time (current_emacs_time (), timeout); | 4710 | now = current_timespec (); |
| 4711 | end_time = timespec_add (now, make_timespec (time_limit, nsecs)); | ||
| 4436 | } | 4712 | } |
| 4713 | else | ||
| 4714 | wait = INFINITY; | ||
| 4437 | 4715 | ||
| 4438 | while (1) | 4716 | while (1) |
| 4439 | { | 4717 | { |
| 4440 | bool timeout_reduced_for_timers = 0; | 4718 | bool process_skipped = false; |
| 4441 | 4719 | ||
| 4442 | /* If calling from keyboard input, do not quit | 4720 | /* If calling from keyboard input, do not quit |
| 4443 | since we want to return C-g as an input character. | 4721 | since we want to return C-g as an input character. |
| @@ -4453,25 +4731,16 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4453 | 4731 | ||
| 4454 | /* Compute time from now till when time limit is up. */ | 4732 | /* Compute time from now till when time limit is up. */ |
| 4455 | /* Exit if already run out. */ | 4733 | /* Exit if already run out. */ |
| 4456 | if (nsecs < 0) | 4734 | if (wait == TIMEOUT) |
| 4457 | { | 4735 | { |
| 4458 | /* A negative timeout means | 4736 | if (!timespec_valid_p (now)) |
| 4459 | gobble output available now | 4737 | now = current_timespec (); |
| 4460 | but don't wait at all. */ | 4738 | if (timespec_cmp (end_time, now) <= 0) |
| 4461 | |||
| 4462 | timeout = make_emacs_time (0, 0); | ||
| 4463 | } | ||
| 4464 | else if (time_limit || nsecs > 0) | ||
| 4465 | { | ||
| 4466 | EMACS_TIME now = current_emacs_time (); | ||
| 4467 | if (EMACS_TIME_LE (end_time, now)) | ||
| 4468 | break; | 4739 | break; |
| 4469 | timeout = sub_emacs_time (end_time, now); | 4740 | timeout = timespec_sub (end_time, now); |
| 4470 | } | 4741 | } |
| 4471 | else | 4742 | else |
| 4472 | { | 4743 | timeout = make_timespec (wait < TIMEOUT ? 0 : 100000, 0); |
| 4473 | timeout = make_emacs_time (100000, 0); | ||
| 4474 | } | ||
| 4475 | 4744 | ||
| 4476 | /* Normally we run timers here. | 4745 | /* Normally we run timers here. |
| 4477 | But not if wait_for_cell; in those cases, | 4746 | But not if wait_for_cell; in those cases, |
| @@ -4480,8 +4749,6 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4480 | if (NILP (wait_for_cell) | 4749 | if (NILP (wait_for_cell) |
| 4481 | && just_wait_proc >= 0) | 4750 | && just_wait_proc >= 0) |
| 4482 | { | 4751 | { |
| 4483 | EMACS_TIME timer_delay; | ||
| 4484 | |||
| 4485 | do | 4752 | do |
| 4486 | { | 4753 | { |
| 4487 | unsigned old_timers_run = timers_run; | 4754 | unsigned old_timers_run = timers_run; |
| @@ -4512,24 +4779,10 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4512 | && requeued_events_pending_p ()) | 4779 | && requeued_events_pending_p ()) |
| 4513 | break; | 4780 | break; |
| 4514 | 4781 | ||
| 4515 | /* A negative timeout means do not wait at all. */ | 4782 | /* This is so a breakpoint can be put here. */ |
| 4516 | if (nsecs >= 0) | 4783 | if (!timespec_valid_p (timer_delay)) |
| 4517 | { | 4784 | wait_reading_process_output_1 (); |
| 4518 | if (EMACS_TIME_VALID_P (timer_delay)) | 4785 | } |
| 4519 | { | ||
| 4520 | if (EMACS_TIME_LT (timer_delay, timeout)) | ||
| 4521 | { | ||
| 4522 | timeout = timer_delay; | ||
| 4523 | timeout_reduced_for_timers = 1; | ||
| 4524 | } | ||
| 4525 | } | ||
| 4526 | else | ||
| 4527 | { | ||
| 4528 | /* This is so a breakpoint can be put here. */ | ||
| 4529 | wait_reading_process_output_1 (); | ||
| 4530 | } | ||
| 4531 | } | ||
| 4532 | } | ||
| 4533 | 4786 | ||
| 4534 | /* Cause C-g and alarm signals to take immediate action, | 4787 | /* Cause C-g and alarm signals to take immediate action, |
| 4535 | and cause input available signals to zero out timeout. | 4788 | and cause input available signals to zero out timeout. |
| @@ -4546,8 +4799,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4546 | timeout to get our attention. */ | 4799 | timeout to get our attention. */ |
| 4547 | if (update_tick != process_tick) | 4800 | if (update_tick != process_tick) |
| 4548 | { | 4801 | { |
| 4549 | SELECT_TYPE Atemp; | 4802 | fd_set Atemp; |
| 4550 | SELECT_TYPE Ctemp; | 4803 | fd_set Ctemp; |
| 4551 | 4804 | ||
| 4552 | if (kbd_on_hold_p ()) | 4805 | if (kbd_on_hold_p ()) |
| 4553 | FD_ZERO (&Atemp); | 4806 | FD_ZERO (&Atemp); |
| @@ -4555,7 +4808,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4555 | compute_input_wait_mask (&Atemp); | 4808 | compute_input_wait_mask (&Atemp); |
| 4556 | compute_write_mask (&Ctemp); | 4809 | compute_write_mask (&Ctemp); |
| 4557 | 4810 | ||
| 4558 | timeout = make_emacs_time (0, 0); | 4811 | timeout = make_timespec (0, 0); |
| 4559 | if ((thread_select (pselect, max_desc + 1, | 4812 | if ((thread_select (pselect, max_desc + 1, |
| 4560 | &Atemp, | 4813 | &Atemp, |
| 4561 | #ifdef NON_BLOCKING_CONNECT | 4814 | #ifdef NON_BLOCKING_CONNECT |
| @@ -4569,7 +4822,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4569 | /* It's okay for us to do this and then continue with | 4822 | /* It's okay for us to do this and then continue with |
| 4570 | the loop, since timeout has already been zeroed out. */ | 4823 | the loop, since timeout has already been zeroed out. */ |
| 4571 | clear_waiting_for_input (); | 4824 | clear_waiting_for_input (); |
| 4572 | status_notify (NULL); | 4825 | got_some_output = status_notify (NULL, wait_proc); |
| 4573 | if (do_display) redisplay_preserve_echo_area (13); | 4826 | if (do_display) redisplay_preserve_echo_area (13); |
| 4574 | } | 4827 | } |
| 4575 | } | 4828 | } |
| @@ -4582,39 +4835,49 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4582 | && ! EQ (wait_proc->status, Qrun) | 4835 | && ! EQ (wait_proc->status, Qrun) |
| 4583 | && ! EQ (wait_proc->status, Qconnect)) | 4836 | && ! EQ (wait_proc->status, Qconnect)) |
| 4584 | { | 4837 | { |
| 4585 | bool read_some_bytes = 0; | 4838 | bool read_some_bytes = false; |
| 4586 | 4839 | ||
| 4587 | clear_waiting_for_input (); | 4840 | clear_waiting_for_input (); |
| 4588 | XSETPROCESS (proc, wait_proc); | ||
| 4589 | 4841 | ||
| 4590 | /* Read data from the process, until we exhaust it. */ | 4842 | /* If data can be read from the process, do so until exhausted. */ |
| 4591 | while (wait_proc->infd >= 0) | 4843 | if (wait_proc->infd >= 0) |
| 4592 | { | 4844 | { |
| 4593 | int nread = read_process_output (proc, wait_proc->infd); | 4845 | XSETPROCESS (proc, wait_proc); |
| 4594 | 4846 | ||
| 4595 | if (nread == 0) | 4847 | while (true) |
| 4596 | break; | 4848 | { |
| 4597 | 4849 | int nread = read_process_output (proc, wait_proc->infd); | |
| 4598 | if (nread > 0) | 4850 | if (nread < 0) |
| 4599 | got_some_input = read_some_bytes = 1; | 4851 | { |
| 4600 | else if (nread == -1 && (errno == EIO || errno == EAGAIN)) | 4852 | if (errno == EIO || errno == EAGAIN) |
| 4601 | break; | 4853 | break; |
| 4602 | #ifdef EWOULDBLOCK | 4854 | #ifdef EWOULDBLOCK |
| 4603 | else if (nread == -1 && EWOULDBLOCK == errno) | 4855 | if (errno == EWOULDBLOCK) |
| 4604 | break; | 4856 | break; |
| 4605 | #endif | 4857 | #endif |
| 4858 | } | ||
| 4859 | else | ||
| 4860 | { | ||
| 4861 | if (got_some_output < nread) | ||
| 4862 | got_some_output = nread; | ||
| 4863 | if (nread == 0) | ||
| 4864 | break; | ||
| 4865 | read_some_bytes = true; | ||
| 4866 | } | ||
| 4867 | } | ||
| 4606 | } | 4868 | } |
| 4869 | |||
| 4607 | if (read_some_bytes && do_display) | 4870 | if (read_some_bytes && do_display) |
| 4608 | redisplay_preserve_echo_area (10); | 4871 | redisplay_preserve_echo_area (10); |
| 4609 | 4872 | ||
| 4610 | break; | 4873 | break; |
| 4611 | } | 4874 | } |
| 4612 | 4875 | ||
| 4613 | /* Wait till there is something to do */ | 4876 | /* Wait till there is something to do. */ |
| 4614 | 4877 | ||
| 4615 | if (wait_proc && just_wait_proc) | 4878 | if (wait_proc && just_wait_proc) |
| 4616 | { | 4879 | { |
| 4617 | if (wait_proc->infd < 0) /* Terminated */ | 4880 | if (wait_proc->infd < 0) /* Terminated. */ |
| 4618 | break; | 4881 | break; |
| 4619 | FD_SET (wait_proc->infd, &Available); | 4882 | FD_SET (wait_proc->infd, &Available); |
| 4620 | check_delay = 0; | 4883 | check_delay = 0; |
| @@ -4633,12 +4896,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4633 | else | 4896 | else |
| 4634 | compute_input_wait_mask (&Available); | 4897 | compute_input_wait_mask (&Available); |
| 4635 | compute_write_mask (&Writeok); | 4898 | compute_write_mask (&Writeok); |
| 4636 | #ifdef SELECT_CANT_DO_WRITE_MASK | 4899 | check_delay = wait_proc ? 0 : process_output_delay_count; |
| 4637 | check_write = 0; | 4900 | check_write = true; |
| 4638 | #else | ||
| 4639 | check_write = 1; | ||
| 4640 | #endif | ||
| 4641 | check_delay = wait_channel >= 0 ? 0 : process_output_delay_count; | ||
| 4642 | } | 4901 | } |
| 4643 | 4902 | ||
| 4644 | /* If frame size has changed or the window is newly mapped, | 4903 | /* If frame size has changed or the window is newly mapped, |
| @@ -4664,22 +4923,20 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4664 | { | 4923 | { |
| 4665 | nfds = read_kbd ? 0 : 1; | 4924 | nfds = read_kbd ? 0 : 1; |
| 4666 | no_avail = 1; | 4925 | no_avail = 1; |
| 4926 | FD_ZERO (&Available); | ||
| 4667 | } | 4927 | } |
| 4668 | 4928 | else | |
| 4669 | if (!no_avail) | ||
| 4670 | { | 4929 | { |
| 4671 | |||
| 4672 | #ifdef ADAPTIVE_READ_BUFFERING | ||
| 4673 | /* Set the timeout for adaptive read buffering if any | 4930 | /* Set the timeout for adaptive read buffering if any |
| 4674 | process has non-zero read_output_skip and non-zero | 4931 | process has non-zero read_output_skip and non-zero |
| 4675 | read_output_delay, and we are not reading output for a | 4932 | read_output_delay, and we are not reading output for a |
| 4676 | specific wait_channel. It is not executed if | 4933 | specific process. It is not executed if |
| 4677 | Vprocess_adaptive_read_buffering is nil. */ | 4934 | Vprocess_adaptive_read_buffering is nil. */ |
| 4678 | if (process_output_skip && check_delay > 0) | 4935 | if (process_output_skip && check_delay > 0) |
| 4679 | { | 4936 | { |
| 4680 | int nsecs = EMACS_NSECS (timeout); | 4937 | int adaptive_nsecs = timeout.tv_nsec; |
| 4681 | if (EMACS_SECS (timeout) > 0 || nsecs > READ_OUTPUT_DELAY_MAX) | 4938 | if (timeout.tv_sec > 0 || adaptive_nsecs > READ_OUTPUT_DELAY_MAX) |
| 4682 | nsecs = READ_OUTPUT_DELAY_MAX; | 4939 | adaptive_nsecs = READ_OUTPUT_DELAY_MAX; |
| 4683 | for (channel = 0; check_delay > 0 && channel <= max_desc; channel++) | 4940 | for (channel = 0; check_delay > 0 && channel <= max_desc; channel++) |
| 4684 | { | 4941 | { |
| 4685 | proc = chan_process[channel]; | 4942 | proc = chan_process[channel]; |
| @@ -4693,15 +4950,43 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4693 | if (!XPROCESS (proc)->read_output_skip) | 4950 | if (!XPROCESS (proc)->read_output_skip) |
| 4694 | continue; | 4951 | continue; |
| 4695 | FD_CLR (channel, &Available); | 4952 | FD_CLR (channel, &Available); |
| 4953 | process_skipped = true; | ||
| 4696 | XPROCESS (proc)->read_output_skip = 0; | 4954 | XPROCESS (proc)->read_output_skip = 0; |
| 4697 | if (XPROCESS (proc)->read_output_delay < nsecs) | 4955 | if (XPROCESS (proc)->read_output_delay < adaptive_nsecs) |
| 4698 | nsecs = XPROCESS (proc)->read_output_delay; | 4956 | adaptive_nsecs = XPROCESS (proc)->read_output_delay; |
| 4699 | } | 4957 | } |
| 4700 | } | 4958 | } |
| 4701 | timeout = make_emacs_time (0, nsecs); | 4959 | timeout = make_timespec (0, adaptive_nsecs); |
| 4702 | process_output_skip = 0; | 4960 | process_output_skip = 0; |
| 4703 | } | 4961 | } |
| 4704 | #endif | 4962 | |
| 4963 | /* If we've got some output and haven't limited our timeout | ||
| 4964 | with adaptive read buffering, limit it. */ | ||
| 4965 | if (got_some_output > 0 && !process_skipped | ||
| 4966 | && (timeout.tv_sec | ||
| 4967 | || timeout.tv_nsec > READ_OUTPUT_DELAY_INCREMENT)) | ||
| 4968 | timeout = make_timespec (0, READ_OUTPUT_DELAY_INCREMENT); | ||
| 4969 | |||
| 4970 | |||
| 4971 | if (NILP (wait_for_cell) && just_wait_proc >= 0 | ||
| 4972 | && timespec_valid_p (timer_delay) | ||
| 4973 | && timespec_cmp (timer_delay, timeout) < 0) | ||
| 4974 | { | ||
| 4975 | if (!timespec_valid_p (now)) | ||
| 4976 | now = current_timespec (); | ||
| 4977 | struct timespec timeout_abs = timespec_add (now, timeout); | ||
| 4978 | if (!timespec_valid_p (got_output_end_time) | ||
| 4979 | || timespec_cmp (timeout_abs, got_output_end_time) < 0) | ||
| 4980 | got_output_end_time = timeout_abs; | ||
| 4981 | timeout = timer_delay; | ||
| 4982 | } | ||
| 4983 | else | ||
| 4984 | got_output_end_time = invalid_timespec (); | ||
| 4985 | |||
| 4986 | /* NOW can become inaccurate if time can pass during pselect. */ | ||
| 4987 | if (timeout.tv_sec > 0 || timeout.tv_nsec > 0) | ||
| 4988 | now = invalid_timespec (); | ||
| 4989 | |||
| 4705 | nfds = thread_select ( | 4990 | nfds = thread_select ( |
| 4706 | #if defined (HAVE_NS) | 4991 | #if defined (HAVE_NS) |
| 4707 | ns_select | 4992 | ns_select |
| @@ -4722,6 +5007,10 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4722 | data is available in the buffers manually. */ | 5007 | data is available in the buffers manually. */ |
| 4723 | if (nfds == 0) | 5008 | if (nfds == 0) |
| 4724 | { | 5009 | { |
| 5010 | fd_set tls_available; | ||
| 5011 | int set = 0; | ||
| 5012 | |||
| 5013 | FD_ZERO (&tls_available); | ||
| 4725 | if (! wait_proc) | 5014 | if (! wait_proc) |
| 4726 | { | 5015 | { |
| 4727 | /* We're not waiting on a specific process, so loop | 5016 | /* We're not waiting on a specific process, so loop |
| @@ -4730,50 +5019,78 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4730 | the gnutls library -- 2.12.14 has been confirmed | 5019 | the gnutls library -- 2.12.14 has been confirmed |
| 4731 | to need it. See | 5020 | to need it. See |
| 4732 | http://comments.gmane.org/gmane.emacs.devel/145074 */ | 5021 | http://comments.gmane.org/gmane.emacs.devel/145074 */ |
| 4733 | for (channel = 0; channel < MAXDESC; ++channel) | 5022 | for (channel = 0; channel < FD_SETSIZE; ++channel) |
| 4734 | if (! NILP (chan_process[channel])) | 5023 | if (! NILP (chan_process[channel])) |
| 4735 | { | 5024 | { |
| 4736 | struct Lisp_Process *p = | 5025 | struct Lisp_Process *p = |
| 4737 | XPROCESS (chan_process[channel]); | 5026 | XPROCESS (chan_process[channel]); |
| 4738 | if (p && p->gnutls_p && p->infd | 5027 | if (p && p->gnutls_p && p->gnutls_state |
| 4739 | && ((emacs_gnutls_record_check_pending | 5028 | && ((emacs_gnutls_record_check_pending |
| 4740 | (p->gnutls_state)) | 5029 | (p->gnutls_state)) |
| 4741 | > 0)) | 5030 | > 0)) |
| 4742 | { | 5031 | { |
| 4743 | nfds++; | 5032 | nfds++; |
| 4744 | FD_SET (p->infd, &Available); | 5033 | eassert (p->infd == channel); |
| 5034 | FD_SET (p->infd, &tls_available); | ||
| 5035 | set++; | ||
| 4745 | } | 5036 | } |
| 4746 | } | 5037 | } |
| 4747 | } | 5038 | } |
| 4748 | else | 5039 | else |
| 4749 | { | 5040 | { |
| 4750 | /* Check this specific channel. */ | 5041 | /* Check this specific channel. */ |
| 4751 | if (wait_proc->gnutls_p /* Check for valid process. */ | 5042 | if (wait_proc->gnutls_p /* Check for valid process. */ |
| 5043 | && wait_proc->gnutls_state | ||
| 4752 | /* Do we have pending data? */ | 5044 | /* Do we have pending data? */ |
| 4753 | && ((emacs_gnutls_record_check_pending | 5045 | && ((emacs_gnutls_record_check_pending |
| 4754 | (wait_proc->gnutls_state)) | 5046 | (wait_proc->gnutls_state)) |
| 4755 | > 0)) | 5047 | > 0)) |
| 4756 | { | 5048 | { |
| 4757 | nfds = 1; | 5049 | nfds = 1; |
| 5050 | eassert (0 <= wait_proc->infd); | ||
| 4758 | /* Set to Available. */ | 5051 | /* Set to Available. */ |
| 4759 | FD_SET (wait_proc->infd, &Available); | 5052 | FD_SET (wait_proc->infd, &tls_available); |
| 5053 | set++; | ||
| 4760 | } | 5054 | } |
| 4761 | } | 5055 | } |
| 5056 | if (set) | ||
| 5057 | Available = tls_available; | ||
| 4762 | } | 5058 | } |
| 4763 | #endif | 5059 | #endif |
| 4764 | } | 5060 | } |
| 4765 | 5061 | ||
| 4766 | xerrno = errno; | 5062 | xerrno = errno; |
| 4767 | 5063 | ||
| 4768 | /* Make C-g and alarm signals set flags again */ | 5064 | /* Make C-g and alarm signals set flags again. */ |
| 4769 | clear_waiting_for_input (); | 5065 | clear_waiting_for_input (); |
| 4770 | 5066 | ||
| 4771 | /* If we woke up due to SIGWINCH, actually change size now. */ | 5067 | /* If we woke up due to SIGWINCH, actually change size now. */ |
| 4772 | do_pending_window_change (0); | 5068 | do_pending_window_change (0); |
| 4773 | 5069 | ||
| 4774 | if ((time_limit || nsecs) && nfds == 0 && ! timeout_reduced_for_timers) | 5070 | if (nfds == 0) |
| 4775 | /* We waited the full specified time, so return now. */ | 5071 | { |
| 4776 | break; | 5072 | /* Exit the main loop if we've passed the requested timeout, |
| 5073 | or aren't skipping processes and got some output and | ||
| 5074 | haven't lowered our timeout due to timers or SIGIO and | ||
| 5075 | have waited a long amount of time due to repeated | ||
| 5076 | timers. */ | ||
| 5077 | if (wait < TIMEOUT) | ||
| 5078 | break; | ||
| 5079 | struct timespec cmp_time | ||
| 5080 | = (wait == TIMEOUT | ||
| 5081 | ? end_time | ||
| 5082 | : (!process_skipped && got_some_output > 0 | ||
| 5083 | && (timeout.tv_sec > 0 || timeout.tv_nsec > 0)) | ||
| 5084 | ? got_output_end_time | ||
| 5085 | : invalid_timespec ()); | ||
| 5086 | if (timespec_valid_p (cmp_time)) | ||
| 5087 | { | ||
| 5088 | now = current_timespec (); | ||
| 5089 | if (timespec_cmp (cmp_time, now) <= 0) | ||
| 5090 | break; | ||
| 5091 | } | ||
| 5092 | } | ||
| 5093 | |||
| 4777 | if (nfds < 0) | 5094 | if (nfds < 0) |
| 4778 | { | 5095 | { |
| 4779 | if (xerrno == EINTR) | 5096 | if (xerrno == EINTR) |
| @@ -4784,28 +5101,22 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4784 | report_file_errno ("Failed select", Qnil, xerrno); | 5101 | report_file_errno ("Failed select", Qnil, xerrno); |
| 4785 | } | 5102 | } |
| 4786 | 5103 | ||
| 4787 | if (no_avail) | 5104 | /* Check for keyboard input. */ |
| 4788 | { | ||
| 4789 | FD_ZERO (&Available); | ||
| 4790 | check_write = 0; | ||
| 4791 | } | ||
| 4792 | |||
| 4793 | /* Check for keyboard input */ | ||
| 4794 | /* If there is any, return immediately | 5105 | /* If there is any, return immediately |
| 4795 | to give it higher priority than subprocesses */ | 5106 | to give it higher priority than subprocesses. */ |
| 4796 | 5107 | ||
| 4797 | if (read_kbd != 0) | 5108 | if (read_kbd != 0) |
| 4798 | { | 5109 | { |
| 4799 | unsigned old_timers_run = timers_run; | 5110 | unsigned old_timers_run = timers_run; |
| 4800 | struct buffer *old_buffer = current_buffer; | 5111 | struct buffer *old_buffer = current_buffer; |
| 4801 | Lisp_Object old_window = selected_window; | 5112 | Lisp_Object old_window = selected_window; |
| 4802 | bool leave = 0; | 5113 | bool leave = false; |
| 4803 | 5114 | ||
| 4804 | if (detect_input_pending_run_timers (do_display)) | 5115 | if (detect_input_pending_run_timers (do_display)) |
| 4805 | { | 5116 | { |
| 4806 | swallow_events (do_display); | 5117 | swallow_events (do_display); |
| 4807 | if (detect_input_pending_run_timers (do_display)) | 5118 | if (detect_input_pending_run_timers (do_display)) |
| 4808 | leave = 1; | 5119 | leave = true; |
| 4809 | } | 5120 | } |
| 4810 | 5121 | ||
| 4811 | /* If a timer has run, this might have changed buffers | 5122 | /* If a timer has run, this might have changed buffers |
| @@ -4856,9 +5167,6 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4856 | handle_input_available_signal (SIGIO); | 5167 | handle_input_available_signal (SIGIO); |
| 4857 | #endif | 5168 | #endif |
| 4858 | 5169 | ||
| 4859 | if (! wait_proc) | ||
| 4860 | got_some_input |= nfds > 0; | ||
| 4861 | |||
| 4862 | /* If checking input just got us a size-change event from X, | 5170 | /* If checking input just got us a size-change event from X, |
| 4863 | obey it now if we should. */ | 5171 | obey it now if we should. */ |
| 4864 | if (read_kbd || ! NILP (wait_for_cell)) | 5172 | if (read_kbd || ! NILP (wait_for_cell)) |
| @@ -4890,12 +5198,6 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4890 | /* If waiting for this channel, arrange to return as | 5198 | /* If waiting for this channel, arrange to return as |
| 4891 | soon as no more input to be processed. No more | 5199 | soon as no more input to be processed. No more |
| 4892 | waiting. */ | 5200 | waiting. */ |
| 4893 | if (wait_channel == channel) | ||
| 4894 | { | ||
| 4895 | wait_channel = -1; | ||
| 4896 | nsecs = -1; | ||
| 4897 | got_some_input = 1; | ||
| 4898 | } | ||
| 4899 | proc = chan_process[channel]; | 5201 | proc = chan_process[channel]; |
| 4900 | if (NILP (proc)) | 5202 | if (NILP (proc)) |
| 4901 | continue; | 5203 | continue; |
| @@ -4911,8 +5213,14 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4911 | buffered-ahead character if we have one. */ | 5213 | buffered-ahead character if we have one. */ |
| 4912 | 5214 | ||
| 4913 | nread = read_process_output (proc, channel); | 5215 | nread = read_process_output (proc, channel); |
| 5216 | if ((!wait_proc || wait_proc == XPROCESS (proc)) | ||
| 5217 | && got_some_output < nread) | ||
| 5218 | got_some_output = nread; | ||
| 4914 | if (nread > 0) | 5219 | if (nread > 0) |
| 4915 | { | 5220 | { |
| 5221 | /* Vacuum up any leftovers without waiting. */ | ||
| 5222 | if (wait_proc == XPROCESS (proc)) | ||
| 5223 | wait = MINIMUM; | ||
| 4916 | /* Since read_process_output can run a filter, | 5224 | /* Since read_process_output can run a filter, |
| 4917 | which can call accept-process-output, | 5225 | which can call accept-process-output, |
| 4918 | don't try to read from any other processes | 5226 | don't try to read from any other processes |
| @@ -4934,7 +5242,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4934 | available now and a closed pipe. | 5242 | available now and a closed pipe. |
| 4935 | With luck, a closed pipe will be accompanied by | 5243 | With luck, a closed pipe will be accompanied by |
| 4936 | subprocess termination and SIGCHLD. */ | 5244 | subprocess termination and SIGCHLD. */ |
| 4937 | else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc)) | 5245 | else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc) |
| 5246 | && !PIPECONN_P (proc)) | ||
| 4938 | ; | 5247 | ; |
| 4939 | #endif | 5248 | #endif |
| 4940 | #ifdef HAVE_PTYS | 5249 | #ifdef HAVE_PTYS |
| @@ -4965,8 +5274,18 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4965 | #endif /* HAVE_PTYS */ | 5274 | #endif /* HAVE_PTYS */ |
| 4966 | /* If we can detect process termination, don't consider the | 5275 | /* If we can detect process termination, don't consider the |
| 4967 | process gone just because its pipe is closed. */ | 5276 | process gone just because its pipe is closed. */ |
| 4968 | else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc)) | 5277 | else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc) |
| 5278 | && !PIPECONN_P (proc)) | ||
| 4969 | ; | 5279 | ; |
| 5280 | else if (nread == 0 && PIPECONN_P (proc)) | ||
| 5281 | { | ||
| 5282 | /* Preserve status of processes already terminated. */ | ||
| 5283 | XPROCESS (proc)->tick = ++process_tick; | ||
| 5284 | deactivate_process (proc); | ||
| 5285 | if (EQ (XPROCESS (proc)->status, Qrun)) | ||
| 5286 | pset_status (XPROCESS (proc), | ||
| 5287 | list2 (Qexit, make_number (0))); | ||
| 5288 | } | ||
| 4970 | else | 5289 | else |
| 4971 | { | 5290 | { |
| 4972 | /* Preserve status of processes already terminated. */ | 5291 | /* Preserve status of processes already terminated. */ |
| @@ -5005,7 +5324,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 5005 | #else | 5324 | #else |
| 5006 | { | 5325 | { |
| 5007 | struct sockaddr pname; | 5326 | struct sockaddr pname; |
| 5008 | int pnamelen = sizeof (pname); | 5327 | socklen_t pnamelen = sizeof (pname); |
| 5009 | 5328 | ||
| 5010 | /* If connection failed, getpeername will fail. */ | 5329 | /* If connection failed, getpeername will fail. */ |
| 5011 | xerrno = 0; | 5330 | xerrno = 0; |
| @@ -5032,7 +5351,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 5032 | status_notify to do it later, it will read input | 5351 | status_notify to do it later, it will read input |
| 5033 | from the process before calling the sentinel. */ | 5352 | from the process before calling the sentinel. */ |
| 5034 | exec_sentinel (proc, build_string ("open\n")); | 5353 | exec_sentinel (proc, build_string ("open\n")); |
| 5035 | if (!EQ (p->filter, Qt) && !EQ (p->command, Qt)) | 5354 | if (0 <= p->infd && !EQ (p->filter, Qt) |
| 5355 | && !EQ (p->command, Qt)) | ||
| 5036 | delete_read_fd (p->infd); | 5356 | delete_read_fd (p->infd); |
| 5037 | } | 5357 | } |
| 5038 | } | 5358 | } |
| @@ -5052,7 +5372,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 5052 | QUIT; | 5372 | QUIT; |
| 5053 | } | 5373 | } |
| 5054 | 5374 | ||
| 5055 | return got_some_input; | 5375 | return got_some_output; |
| 5056 | } | 5376 | } |
| 5057 | 5377 | ||
| 5058 | /* Given a list (FUNCTION ARGS...), apply FUNCTION to the ARGS. */ | 5378 | /* Given a list (FUNCTION ARGS...), apply FUNCTION to the ARGS. */ |
| @@ -5090,18 +5410,17 @@ read_and_dispose_of_process_output (struct Lisp_Process *p, char *chars, | |||
| 5090 | for decoding. */ | 5410 | for decoding. */ |
| 5091 | 5411 | ||
| 5092 | static int | 5412 | static int |
| 5093 | read_process_output (Lisp_Object proc, register int channel) | 5413 | read_process_output (Lisp_Object proc, int channel) |
| 5094 | { | 5414 | { |
| 5095 | register ssize_t nbytes; | 5415 | ssize_t nbytes; |
| 5096 | char *chars; | 5416 | struct Lisp_Process *p = XPROCESS (proc); |
| 5097 | register struct Lisp_Process *p = XPROCESS (proc); | ||
| 5098 | struct coding_system *coding = proc_decode_coding_system[channel]; | 5417 | struct coding_system *coding = proc_decode_coding_system[channel]; |
| 5099 | int carryover = p->decoding_carryover; | 5418 | int carryover = p->decoding_carryover; |
| 5100 | int readmax = 4096; | 5419 | enum { readmax = 4096 }; |
| 5101 | ptrdiff_t count = SPECPDL_INDEX (); | 5420 | ptrdiff_t count = SPECPDL_INDEX (); |
| 5102 | Lisp_Object odeactivate; | 5421 | Lisp_Object odeactivate; |
| 5422 | char chars[sizeof coding->carryover + readmax]; | ||
| 5103 | 5423 | ||
| 5104 | chars = alloca (carryover + readmax); | ||
| 5105 | if (carryover) | 5424 | if (carryover) |
| 5106 | /* See the comment above. */ | 5425 | /* See the comment above. */ |
| 5107 | memcpy (chars, SDATA (p->decoding_buf), carryover); | 5426 | memcpy (chars, SDATA (p->decoding_buf), carryover); |
| @@ -5124,14 +5443,13 @@ read_process_output (Lisp_Object proc, register int channel) | |||
| 5124 | proc_buffered_char[channel] = -1; | 5443 | proc_buffered_char[channel] = -1; |
| 5125 | } | 5444 | } |
| 5126 | #ifdef HAVE_GNUTLS | 5445 | #ifdef HAVE_GNUTLS |
| 5127 | if (p->gnutls_p) | 5446 | if (p->gnutls_p && p->gnutls_state) |
| 5128 | nbytes = emacs_gnutls_read (p, chars + carryover + buffered, | 5447 | nbytes = emacs_gnutls_read (p, chars + carryover + buffered, |
| 5129 | readmax - buffered); | 5448 | readmax - buffered); |
| 5130 | else | 5449 | else |
| 5131 | #endif | 5450 | #endif |
| 5132 | nbytes = emacs_read (channel, chars + carryover + buffered, | 5451 | nbytes = emacs_read (channel, chars + carryover + buffered, |
| 5133 | readmax - buffered); | 5452 | readmax - buffered); |
| 5134 | #ifdef ADAPTIVE_READ_BUFFERING | ||
| 5135 | if (nbytes > 0 && p->adaptive_read_buffering) | 5453 | if (nbytes > 0 && p->adaptive_read_buffering) |
| 5136 | { | 5454 | { |
| 5137 | int delay = p->read_output_delay; | 5455 | int delay = p->read_output_delay; |
| @@ -5157,7 +5475,6 @@ read_process_output (Lisp_Object proc, register int channel) | |||
| 5157 | process_output_skip = 1; | 5475 | process_output_skip = 1; |
| 5158 | } | 5476 | } |
| 5159 | } | 5477 | } |
| 5160 | #endif | ||
| 5161 | nbytes += buffered; | 5478 | nbytes += buffered; |
| 5162 | nbytes += buffered && nbytes <= 0; | 5479 | nbytes += buffered && nbytes <= 0; |
| 5163 | } | 5480 | } |
| @@ -5201,8 +5518,6 @@ read_and_dispose_of_process_output (struct Lisp_Process *p, char *chars, | |||
| 5201 | bool outer_running_asynch_code = running_asynch_code; | 5518 | bool outer_running_asynch_code = running_asynch_code; |
| 5202 | int waiting = waiting_for_user_input_p; | 5519 | int waiting = waiting_for_user_input_p; |
| 5203 | 5520 | ||
| 5204 | /* No need to gcpro these, because all we do with them later | ||
| 5205 | is test them for EQness, and none of them should be a string. */ | ||
| 5206 | #if 0 | 5521 | #if 0 |
| 5207 | Lisp_Object obuffer, okeymap; | 5522 | Lisp_Object obuffer, okeymap; |
| 5208 | XSETBUFFER (obuffer, current_buffer); | 5523 | XSETBUFFER (obuffer, current_buffer); |
| @@ -5251,7 +5566,7 @@ read_and_dispose_of_process_output (struct Lisp_Process *p, char *chars, | |||
| 5251 | proc_encode_coding_system[p->outfd] surely points to a | 5566 | proc_encode_coding_system[p->outfd] surely points to a |
| 5252 | valid memory because p->outfd will be changed once EOF is | 5567 | valid memory because p->outfd will be changed once EOF is |
| 5253 | sent to the process. */ | 5568 | sent to the process. */ |
| 5254 | if (NILP (p->encode_coding_system) | 5569 | if (NILP (p->encode_coding_system) && p->outfd >= 0 |
| 5255 | && proc_encode_coding_system[p->outfd]) | 5570 | && proc_encode_coding_system[p->outfd]) |
| 5256 | { | 5571 | { |
| 5257 | pset_encode_coding_system | 5572 | pset_encode_coding_system |
| @@ -5301,7 +5616,9 @@ read_and_dispose_of_process_output (struct Lisp_Process *p, char *chars, | |||
| 5301 | 5616 | ||
| 5302 | DEFUN ("internal-default-process-filter", Finternal_default_process_filter, | 5617 | DEFUN ("internal-default-process-filter", Finternal_default_process_filter, |
| 5303 | Sinternal_default_process_filter, 2, 2, 0, | 5618 | Sinternal_default_process_filter, 2, 2, 0, |
| 5304 | doc: /* Function used as default process filter. */) | 5619 | doc: /* Function used as default process filter. |
| 5620 | This inserts the process's output into its buffer, if there is one. | ||
| 5621 | Otherwise it discards the output. */) | ||
| 5305 | (Lisp_Object proc, Lisp_Object text) | 5622 | (Lisp_Object proc, Lisp_Object text) |
| 5306 | { | 5623 | { |
| 5307 | struct Lisp_Process *p; | 5624 | struct Lisp_Process *p; |
| @@ -5331,15 +5648,10 @@ DEFUN ("internal-default-process-filter", Finternal_default_process_filter, | |||
| 5331 | 5648 | ||
| 5332 | bset_read_only (current_buffer, Qnil); | 5649 | bset_read_only (current_buffer, Qnil); |
| 5333 | 5650 | ||
| 5334 | /* Insert new output into buffer | 5651 | /* Insert new output into buffer at the current end-of-output |
| 5335 | at the current end-of-output marker, | 5652 | marker, thus preserving logical ordering of input and output. */ |
| 5336 | thus preserving logical ordering of input and output. */ | ||
| 5337 | if (XMARKER (p->mark)->buffer) | 5653 | if (XMARKER (p->mark)->buffer) |
| 5338 | SET_PT_BOTH (clip_to_bounds (BEGV, | 5654 | set_point_from_marker (p->mark); |
| 5339 | marker_position (p->mark), ZV), | ||
| 5340 | clip_to_bounds (BEGV_BYTE, | ||
| 5341 | marker_byte_position (p->mark), | ||
| 5342 | ZV_BYTE)); | ||
| 5343 | else | 5655 | else |
| 5344 | SET_PT_BOTH (ZV, ZV_BYTE); | 5656 | SET_PT_BOTH (ZV, ZV_BYTE); |
| 5345 | before = PT; | 5657 | before = PT; |
| @@ -5370,7 +5682,7 @@ DEFUN ("internal-default-process-filter", Finternal_default_process_filter, | |||
| 5370 | else | 5682 | else |
| 5371 | set_marker_both (p->mark, p->buffer, PT, PT_BYTE); | 5683 | set_marker_both (p->mark, p->buffer, PT, PT_BYTE); |
| 5372 | 5684 | ||
| 5373 | update_mode_lines++; | 5685 | update_mode_lines = 23; |
| 5374 | 5686 | ||
| 5375 | /* Make sure opoint and the old restrictions | 5687 | /* Make sure opoint and the old restrictions |
| 5376 | float ahead of any new text just as point would. */ | 5688 | float ahead of any new text just as point would. */ |
| @@ -5623,13 +5935,12 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len, | |||
| 5623 | #endif | 5935 | #endif |
| 5624 | { | 5936 | { |
| 5625 | #ifdef HAVE_GNUTLS | 5937 | #ifdef HAVE_GNUTLS |
| 5626 | if (p->gnutls_p) | 5938 | if (p->gnutls_p && p->gnutls_state) |
| 5627 | written = emacs_gnutls_write (p, cur_buf, cur_len); | 5939 | written = emacs_gnutls_write (p, cur_buf, cur_len); |
| 5628 | else | 5940 | else |
| 5629 | #endif | 5941 | #endif |
| 5630 | written = emacs_write_sig (outfd, cur_buf, cur_len); | 5942 | written = emacs_write_sig (outfd, cur_buf, cur_len); |
| 5631 | rv = (written ? 0 : -1); | 5943 | rv = (written ? 0 : -1); |
| 5632 | #ifdef ADAPTIVE_READ_BUFFERING | ||
| 5633 | if (p->read_output_delay > 0 | 5944 | if (p->read_output_delay > 0 |
| 5634 | && p->adaptive_read_buffering == 1) | 5945 | && p->adaptive_read_buffering == 1) |
| 5635 | { | 5946 | { |
| @@ -5637,7 +5948,6 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len, | |||
| 5637 | process_output_delay_count--; | 5948 | process_output_delay_count--; |
| 5638 | p->read_output_skip = 0; | 5949 | p->read_output_skip = 0; |
| 5639 | } | 5950 | } |
| 5640 | #endif | ||
| 5641 | } | 5951 | } |
| 5642 | 5952 | ||
| 5643 | if (rv < 0) | 5953 | if (rv < 0) |
| @@ -5777,9 +6087,10 @@ emacs_get_tty_pgrp (struct Lisp_Process *p) | |||
| 5777 | 6087 | ||
| 5778 | DEFUN ("process-running-child-p", Fprocess_running_child_p, | 6088 | DEFUN ("process-running-child-p", Fprocess_running_child_p, |
| 5779 | Sprocess_running_child_p, 0, 1, 0, | 6089 | Sprocess_running_child_p, 0, 1, 0, |
| 5780 | doc: /* Return t if PROCESS has given the terminal to a child. | 6090 | doc: /* Return non-nil if PROCESS has given the terminal to a |
| 5781 | If the operating system does not make it possible to find out, | 6091 | child. If the operating system does not make it possible to find out, |
| 5782 | return t unconditionally. */) | 6092 | return t. If we can find out, return the numeric ID of the foreground |
| 6093 | process group. */) | ||
| 5783 | (Lisp_Object process) | 6094 | (Lisp_Object process) |
| 5784 | { | 6095 | { |
| 5785 | /* Initialize in case ioctl doesn't exist or gives an error, | 6096 | /* Initialize in case ioctl doesn't exist or gives an error, |
| @@ -5802,10 +6113,12 @@ return t unconditionally. */) | |||
| 5802 | 6113 | ||
| 5803 | if (gid == p->pid) | 6114 | if (gid == p->pid) |
| 5804 | return Qnil; | 6115 | return Qnil; |
| 6116 | if (gid != -1) | ||
| 6117 | return make_number (gid); | ||
| 5805 | return Qt; | 6118 | return Qt; |
| 5806 | } | 6119 | } |
| 5807 | 6120 | ||
| 5808 | /* send a signal number SIGNO to PROCESS. | 6121 | /* Send a signal number SIGNO to PROCESS. |
| 5809 | If CURRENT_GROUP is t, that means send to the process group | 6122 | If CURRENT_GROUP is t, that means send to the process group |
| 5810 | that currently owns the terminal being used to communicate with PROCESS. | 6123 | that currently owns the terminal being used to communicate with PROCESS. |
| 5811 | This is used for various commands in shell mode. | 6124 | This is used for various commands in shell mode. |
| @@ -5908,11 +6221,11 @@ process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group, | |||
| 5908 | Or perhaps this is vestigial. */ | 6221 | Or perhaps this is vestigial. */ |
| 5909 | if (gid == -1) | 6222 | if (gid == -1) |
| 5910 | no_pgrp = 1; | 6223 | no_pgrp = 1; |
| 5911 | #else /* ! defined (TIOCGPGRP ) */ | 6224 | #else /* ! defined (TIOCGPGRP) */ |
| 5912 | /* Can't select pgrps on this system, so we know that | 6225 | /* Can't select pgrps on this system, so we know that |
| 5913 | the child itself heads the pgrp. */ | 6226 | the child itself heads the pgrp. */ |
| 5914 | gid = p->pid; | 6227 | gid = p->pid; |
| 5915 | #endif /* ! defined (TIOCGPGRP ) */ | 6228 | #endif /* ! defined (TIOCGPGRP) */ |
| 5916 | 6229 | ||
| 5917 | /* If current_group is lambda, and the shell owns the terminal, | 6230 | /* If current_group is lambda, and the shell owns the terminal, |
| 5918 | don't send any signal. */ | 6231 | don't send any signal. */ |
| @@ -5928,36 +6241,31 @@ process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group, | |||
| 5928 | p->tick = ++process_tick; | 6241 | p->tick = ++process_tick; |
| 5929 | if (!nomsg) | 6242 | if (!nomsg) |
| 5930 | { | 6243 | { |
| 5931 | status_notify (NULL); | 6244 | status_notify (NULL, NULL); |
| 5932 | redisplay_preserve_echo_area (13); | 6245 | redisplay_preserve_echo_area (13); |
| 5933 | } | 6246 | } |
| 5934 | } | 6247 | } |
| 5935 | #endif | 6248 | #endif |
| 5936 | 6249 | ||
| 6250 | #ifdef TIOCSIGSEND | ||
| 6251 | /* Work around a HP-UX 7.0 bug that mishandles signals to subjobs. | ||
| 6252 | We don't know whether the bug is fixed in later HP-UX versions. */ | ||
| 6253 | if (! NILP (current_group) && ioctl (p->infd, TIOCSIGSEND, signo) != -1) | ||
| 6254 | return; | ||
| 6255 | #endif | ||
| 6256 | |||
| 5937 | /* If we don't have process groups, send the signal to the immediate | 6257 | /* If we don't have process groups, send the signal to the immediate |
| 5938 | subprocess. That isn't really right, but it's better than any | 6258 | subprocess. That isn't really right, but it's better than any |
| 5939 | obvious alternative. */ | 6259 | obvious alternative. */ |
| 5940 | if (no_pgrp) | 6260 | pid_t pid = no_pgrp ? gid : - gid; |
| 5941 | { | ||
| 5942 | kill (p->pid, signo); | ||
| 5943 | return; | ||
| 5944 | } | ||
| 5945 | 6261 | ||
| 5946 | /* gid may be a pid, or minus a pgrp's number */ | 6262 | /* Do not kill an already-reaped process, as that could kill an |
| 5947 | #ifdef TIOCSIGSEND | 6263 | innocent bystander that happens to have the same process ID. */ |
| 5948 | if (!NILP (current_group)) | 6264 | sigset_t oldset; |
| 5949 | { | 6265 | block_child_signal (&oldset); |
| 5950 | if (ioctl (p->infd, TIOCSIGSEND, signo) == -1) | 6266 | if (p->alive) |
| 5951 | kill (-gid, signo); | 6267 | kill (pid, signo); |
| 5952 | } | 6268 | unblock_child_signal (&oldset); |
| 5953 | else | ||
| 5954 | { | ||
| 5955 | gid = - p->pid; | ||
| 5956 | kill (gid, signo); | ||
| 5957 | } | ||
| 5958 | #else /* ! defined (TIOCSIGSEND) */ | ||
| 5959 | kill (-gid, signo); | ||
| 5960 | #endif /* ! defined (TIOCSIGSEND) */ | ||
| 5961 | } | 6269 | } |
| 5962 | 6270 | ||
| 5963 | DEFUN ("interrupt-process", Finterrupt_process, Sinterrupt_process, 0, 2, 0, | 6271 | DEFUN ("interrupt-process", Finterrupt_process, Sinterrupt_process, 0, 2, 0, |
| @@ -6003,7 +6311,8 @@ If PROCESS is a network or serial process, inhibit handling of incoming | |||
| 6003 | traffic. */) | 6311 | traffic. */) |
| 6004 | (Lisp_Object process, Lisp_Object current_group) | 6312 | (Lisp_Object process, Lisp_Object current_group) |
| 6005 | { | 6313 | { |
| 6006 | if (PROCESSP (process) && (NETCONN_P (process) || SERIALCONN_P (process))) | 6314 | if (PROCESSP (process) && (NETCONN_P (process) || SERIALCONN_P (process) |
| 6315 | || PIPECONN_P (process))) | ||
| 6007 | { | 6316 | { |
| 6008 | struct Lisp_Process *p; | 6317 | struct Lisp_Process *p; |
| 6009 | 6318 | ||
| @@ -6029,7 +6338,8 @@ If PROCESS is a network or serial process, resume handling of incoming | |||
| 6029 | traffic. */) | 6338 | traffic. */) |
| 6030 | (Lisp_Object process, Lisp_Object current_group) | 6339 | (Lisp_Object process, Lisp_Object current_group) |
| 6031 | { | 6340 | { |
| 6032 | if (PROCESSP (process) && (NETCONN_P (process) || SERIALCONN_P (process))) | 6341 | if (PROCESSP (process) && (NETCONN_P (process) || SERIALCONN_P (process) |
| 6342 | || PIPECONN_P (process))) | ||
| 6033 | { | 6343 | { |
| 6034 | struct Lisp_Process *p; | 6344 | struct Lisp_Process *p; |
| 6035 | 6345 | ||
| @@ -6095,9 +6405,9 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */) | |||
| 6095 | Lisp_Object tem = Fget_process (process); | 6405 | Lisp_Object tem = Fget_process (process); |
| 6096 | if (NILP (tem)) | 6406 | if (NILP (tem)) |
| 6097 | { | 6407 | { |
| 6098 | Lisp_Object process_number = | 6408 | Lisp_Object process_number |
| 6099 | string_to_number (SSDATA (process), 10, 1); | 6409 | = string_to_number (SSDATA (process), 10, 1); |
| 6100 | if (INTEGERP (process_number) || FLOATP (process_number)) | 6410 | if (NUMBERP (process_number)) |
| 6101 | tem = process_number; | 6411 | tem = process_number; |
| 6102 | } | 6412 | } |
| 6103 | process = tem; | 6413 | process = tem; |
| @@ -6151,13 +6461,16 @@ process has been transmitted to the serial port. */) | |||
| 6151 | (Lisp_Object process) | 6461 | (Lisp_Object process) |
| 6152 | { | 6462 | { |
| 6153 | Lisp_Object proc; | 6463 | Lisp_Object proc; |
| 6154 | struct coding_system *coding; | 6464 | struct coding_system *coding = NULL; |
| 6465 | int outfd; | ||
| 6155 | 6466 | ||
| 6156 | if (DATAGRAM_CONN_P (process)) | 6467 | if (DATAGRAM_CONN_P (process)) |
| 6157 | return process; | 6468 | return process; |
| 6158 | 6469 | ||
| 6159 | proc = get_process (process); | 6470 | proc = get_process (process); |
| 6160 | coding = proc_encode_coding_system[XPROCESS (proc)->outfd]; | 6471 | outfd = XPROCESS (proc)->outfd; |
| 6472 | if (outfd >= 0) | ||
| 6473 | coding = proc_encode_coding_system[outfd]; | ||
| 6161 | 6474 | ||
| 6162 | /* Make sure the process is really alive. */ | 6475 | /* Make sure the process is really alive. */ |
| 6163 | if (XPROCESS (proc)->raw_status_new) | 6476 | if (XPROCESS (proc)->raw_status_new) |
| @@ -6165,7 +6478,7 @@ process has been transmitted to the serial port. */) | |||
| 6165 | if (! EQ (XPROCESS (proc)->status, Qrun)) | 6478 | if (! EQ (XPROCESS (proc)->status, Qrun)) |
| 6166 | error ("Process %s not running", SDATA (XPROCESS (proc)->name)); | 6479 | error ("Process %s not running", SDATA (XPROCESS (proc)->name)); |
| 6167 | 6480 | ||
| 6168 | if (CODING_REQUIRE_FLUSHING (coding)) | 6481 | if (coding && CODING_REQUIRE_FLUSHING (coding)) |
| 6169 | { | 6482 | { |
| 6170 | coding->mode |= CODING_MODE_LAST_BLOCK; | 6483 | coding->mode |= CODING_MODE_LAST_BLOCK; |
| 6171 | send_process (proc, "", 0, Qnil); | 6484 | send_process (proc, "", 0, Qnil); |
| @@ -6183,7 +6496,8 @@ process has been transmitted to the serial port. */) | |||
| 6183 | } | 6496 | } |
| 6184 | else | 6497 | else |
| 6185 | { | 6498 | { |
| 6186 | int old_outfd = XPROCESS (proc)->outfd; | 6499 | struct Lisp_Process *p = XPROCESS (proc); |
| 6500 | int old_outfd = p->outfd; | ||
| 6187 | int new_outfd; | 6501 | int new_outfd; |
| 6188 | 6502 | ||
| 6189 | #ifdef HAVE_SHUTDOWN | 6503 | #ifdef HAVE_SHUTDOWN |
| @@ -6191,24 +6505,30 @@ process has been transmitted to the serial port. */) | |||
| 6191 | for communication with the subprocess, call shutdown to cause EOF. | 6505 | for communication with the subprocess, call shutdown to cause EOF. |
| 6192 | (In some old system, shutdown to socketpair doesn't work. | 6506 | (In some old system, shutdown to socketpair doesn't work. |
| 6193 | Then we just can't win.) */ | 6507 | Then we just can't win.) */ |
| 6194 | if (EQ (XPROCESS (proc)->type, Qnetwork) | 6508 | if (0 <= old_outfd |
| 6195 | || XPROCESS (proc)->infd == old_outfd) | 6509 | && (EQ (p->type, Qnetwork) || p->infd == old_outfd)) |
| 6196 | shutdown (old_outfd, 1); | 6510 | shutdown (old_outfd, 1); |
| 6197 | #endif | 6511 | #endif |
| 6198 | close_process_fd (&XPROCESS (proc)->open_fd[WRITE_TO_SUBPROCESS]); | 6512 | close_process_fd (&p->open_fd[WRITE_TO_SUBPROCESS]); |
| 6199 | new_outfd = emacs_open (NULL_DEVICE, O_WRONLY, 0); | 6513 | new_outfd = emacs_open (NULL_DEVICE, O_WRONLY, 0); |
| 6200 | if (new_outfd < 0) | 6514 | if (new_outfd < 0) |
| 6201 | report_file_error ("Opening null device", Qnil); | 6515 | report_file_error ("Opening null device", Qnil); |
| 6202 | XPROCESS (proc)->open_fd[WRITE_TO_SUBPROCESS] = new_outfd; | 6516 | p->open_fd[WRITE_TO_SUBPROCESS] = new_outfd; |
| 6203 | XPROCESS (proc)->outfd = new_outfd; | 6517 | p->outfd = new_outfd; |
| 6204 | 6518 | ||
| 6205 | if (!proc_encode_coding_system[new_outfd]) | 6519 | if (!proc_encode_coding_system[new_outfd]) |
| 6206 | proc_encode_coding_system[new_outfd] | 6520 | proc_encode_coding_system[new_outfd] |
| 6207 | = xmalloc (sizeof (struct coding_system)); | 6521 | = xmalloc (sizeof (struct coding_system)); |
| 6208 | *proc_encode_coding_system[new_outfd] | 6522 | if (old_outfd >= 0) |
| 6209 | = *proc_encode_coding_system[old_outfd]; | 6523 | { |
| 6210 | memset (proc_encode_coding_system[old_outfd], 0, | 6524 | *proc_encode_coding_system[new_outfd] |
| 6211 | sizeof (struct coding_system)); | 6525 | = *proc_encode_coding_system[old_outfd]; |
| 6526 | memset (proc_encode_coding_system[old_outfd], 0, | ||
| 6527 | sizeof (struct coding_system)); | ||
| 6528 | } | ||
| 6529 | else | ||
| 6530 | setup_coding_system (p->encode_coding_system, | ||
| 6531 | proc_encode_coding_system[new_outfd]); | ||
| 6212 | } | 6532 | } |
| 6213 | return process; | 6533 | return process; |
| 6214 | } | 6534 | } |
| @@ -6269,7 +6589,7 @@ static signal_handler_t volatile lib_child_handler; | |||
| 6269 | Inc. | 6589 | Inc. |
| 6270 | 6590 | ||
| 6271 | ** Malloc WARNING: This should never call malloc either directly or | 6591 | ** Malloc WARNING: This should never call malloc either directly or |
| 6272 | indirectly; if it does, that is a bug */ | 6592 | indirectly; if it does, that is a bug. */ |
| 6273 | 6593 | ||
| 6274 | static void | 6594 | static void |
| 6275 | handle_child_signal (int sig) | 6595 | handle_child_signal (int sig) |
| @@ -6337,9 +6657,9 @@ handle_child_signal (int sig) | |||
| 6337 | 6657 | ||
| 6338 | lib_child_handler (sig); | 6658 | lib_child_handler (sig); |
| 6339 | #ifdef NS_IMPL_GNUSTEP | 6659 | #ifdef NS_IMPL_GNUSTEP |
| 6340 | /* NSTask in GNUStep sets its child handler each time it is called. | 6660 | /* NSTask in GNUstep sets its child handler each time it is called. |
| 6341 | So we must re-set ours. */ | 6661 | So we must re-set ours. */ |
| 6342 | catch_child_signal(); | 6662 | catch_child_signal (); |
| 6343 | #endif | 6663 | #endif |
| 6344 | } | 6664 | } |
| 6345 | 6665 | ||
| @@ -6372,8 +6692,6 @@ exec_sentinel (Lisp_Object proc, Lisp_Object reason) | |||
| 6372 | if (inhibit_sentinels) | 6692 | if (inhibit_sentinels) |
| 6373 | return; | 6693 | return; |
| 6374 | 6694 | ||
| 6375 | /* No need to gcpro these, because all we do with them later | ||
| 6376 | is test them for EQness, and none of them should be a string. */ | ||
| 6377 | odeactivate = Vdeactivate_mark; | 6695 | odeactivate = Vdeactivate_mark; |
| 6378 | #if 0 | 6696 | #if 0 |
| 6379 | Lisp_Object obuffer, okeymap; | 6697 | Lisp_Object obuffer, okeymap; |
| @@ -6439,22 +6757,22 @@ exec_sentinel (Lisp_Object proc, Lisp_Object reason) | |||
| 6439 | /* Report all recent events of a change in process status | 6757 | /* Report all recent events of a change in process status |
| 6440 | (either run the sentinel or output a message). | 6758 | (either run the sentinel or output a message). |
| 6441 | This is usually done while Emacs is waiting for keyboard input | 6759 | This is usually done while Emacs is waiting for keyboard input |
| 6442 | but can be done at other times. */ | 6760 | but can be done at other times. |
| 6443 | 6761 | ||
| 6444 | static void | 6762 | Return positive if any input was received from WAIT_PROC (or from |
| 6445 | status_notify (struct Lisp_Process *deleting_process) | 6763 | any process if WAIT_PROC is null), zero if input was attempted but |
| 6764 | none received, and negative if we didn't even try. */ | ||
| 6765 | |||
| 6766 | static int | ||
| 6767 | status_notify (struct Lisp_Process *deleting_process, | ||
| 6768 | struct Lisp_Process *wait_proc) | ||
| 6446 | { | 6769 | { |
| 6447 | register Lisp_Object proc; | 6770 | Lisp_Object proc; |
| 6448 | Lisp_Object tail, msg; | 6771 | Lisp_Object tail, msg; |
| 6449 | struct gcpro gcpro1, gcpro2; | 6772 | int got_some_output = -1; |
| 6450 | 6773 | ||
| 6451 | tail = Qnil; | 6774 | tail = Qnil; |
| 6452 | msg = Qnil; | 6775 | msg = Qnil; |
| 6453 | /* We need to gcpro tail; if read_process_output calls a filter | ||
| 6454 | which deletes a process and removes the cons to which tail points | ||
| 6455 | from Vprocess_alist, and then causes a GC, tail is an unprotected | ||
| 6456 | reference. */ | ||
| 6457 | GCPRO2 (tail, msg); | ||
| 6458 | 6776 | ||
| 6459 | /* Set this now, so that if new processes are created by sentinels | 6777 | /* Set this now, so that if new processes are created by sentinels |
| 6460 | that we run, we get called again to handle their status changes. */ | 6778 | that we run, we get called again to handle their status changes. */ |
| @@ -6476,8 +6794,15 @@ status_notify (struct Lisp_Process *deleting_process) | |||
| 6476 | /* Network or serial process not stopped: */ | 6794 | /* Network or serial process not stopped: */ |
| 6477 | && ! EQ (p->command, Qt) | 6795 | && ! EQ (p->command, Qt) |
| 6478 | && p->infd >= 0 | 6796 | && p->infd >= 0 |
| 6479 | && p != deleting_process | 6797 | && p != deleting_process) |
| 6480 | && read_process_output (proc, p->infd) > 0); | 6798 | { |
| 6799 | int nread = read_process_output (proc, p->infd); | ||
| 6800 | if ((!wait_proc || wait_proc == XPROCESS (proc)) | ||
| 6801 | && got_some_output < nread) | ||
| 6802 | got_some_output = nread; | ||
| 6803 | if (nread <= 0) | ||
| 6804 | break; | ||
| 6805 | } | ||
| 6481 | 6806 | ||
| 6482 | /* Get the text to use for the message. */ | 6807 | /* Get the text to use for the message. */ |
| 6483 | if (p->raw_status_new) | 6808 | if (p->raw_status_new) |
| @@ -6504,16 +6829,19 @@ status_notify (struct Lisp_Process *deleting_process) | |||
| 6504 | p->update_tick = p->tick; | 6829 | p->update_tick = p->tick; |
| 6505 | /* Now output the message suitably. */ | 6830 | /* Now output the message suitably. */ |
| 6506 | exec_sentinel (proc, msg); | 6831 | exec_sentinel (proc, msg); |
| 6832 | if (BUFFERP (p->buffer)) | ||
| 6833 | /* In case it uses %s in mode-line-format. */ | ||
| 6834 | bset_update_mode_line (XBUFFER (p->buffer)); | ||
| 6507 | } | 6835 | } |
| 6508 | } /* end for */ | 6836 | } /* end for */ |
| 6509 | 6837 | ||
| 6510 | update_mode_lines++; /* In case buffers use %s in mode-line-format. */ | 6838 | return got_some_output; |
| 6511 | UNGCPRO; | ||
| 6512 | } | 6839 | } |
| 6513 | 6840 | ||
| 6514 | DEFUN ("internal-default-process-sentinel", Finternal_default_process_sentinel, | 6841 | DEFUN ("internal-default-process-sentinel", Finternal_default_process_sentinel, |
| 6515 | Sinternal_default_process_sentinel, 2, 2, 0, | 6842 | Sinternal_default_process_sentinel, 2, 2, 0, |
| 6516 | doc: /* Function used as default sentinel for processes. */) | 6843 | doc: /* Function used as default sentinel for processes. |
| 6844 | This inserts a status message into the process's buffer, if there is one. */) | ||
| 6517 | (Lisp_Object proc, Lisp_Object msg) | 6845 | (Lisp_Object proc, Lisp_Object msg) |
| 6518 | { | 6846 | { |
| 6519 | Lisp_Object buffer, symbol; | 6847 | Lisp_Object buffer, symbol; |
| @@ -6643,6 +6971,8 @@ DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p, | |||
| 6643 | 6971 | ||
| 6644 | CHECK_PROCESS (process); | 6972 | CHECK_PROCESS (process); |
| 6645 | p = XPROCESS (process); | 6973 | p = XPROCESS (process); |
| 6974 | if (p->infd < 0) | ||
| 6975 | return Qnil; | ||
| 6646 | coding = proc_decode_coding_system[p->infd]; | 6976 | coding = proc_decode_coding_system[p->infd]; |
| 6647 | return (CODING_FOR_UNIBYTE (coding) ? Qnil : Qt); | 6977 | return (CODING_FOR_UNIBYTE (coding) ? Qnil : Qt); |
| 6648 | } | 6978 | } |
| @@ -6687,9 +7017,9 @@ keyboard_bit_set (fd_set *mask) | |||
| 6687 | 7017 | ||
| 6688 | #else /* not subprocesses */ | 7018 | #else /* not subprocesses */ |
| 6689 | 7019 | ||
| 6690 | /* Defined on msdos.c. */ | 7020 | /* Defined in msdos.c. */ |
| 6691 | extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *, | 7021 | extern int sys_select (int, fd_set *, fd_set *, fd_set *, |
| 6692 | EMACS_TIME *, void *); | 7022 | struct timespec *, void *); |
| 6693 | 7023 | ||
| 6694 | /* Implementation of wait_reading_process_output, assuming that there | 7024 | /* Implementation of wait_reading_process_output, assuming that there |
| 6695 | are no subprocesses. Used only by the MS-DOS build. | 7025 | are no subprocesses. Used only by the MS-DOS build. |
| @@ -6719,31 +7049,31 @@ extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *, | |||
| 6719 | DO_DISPLAY means redisplay should be done to show subprocess | 7049 | DO_DISPLAY means redisplay should be done to show subprocess |
| 6720 | output that arrives. | 7050 | output that arrives. |
| 6721 | 7051 | ||
| 6722 | Return true if we received input from any process. */ | 7052 | Return -1 signifying we got no output and did not try. */ |
| 6723 | 7053 | ||
| 6724 | bool | 7054 | int |
| 6725 | wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | 7055 | wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, |
| 6726 | bool do_display, | 7056 | bool do_display, |
| 6727 | Lisp_Object wait_for_cell, | 7057 | Lisp_Object wait_for_cell, |
| 6728 | struct Lisp_Process *wait_proc, int just_wait_proc) | 7058 | struct Lisp_Process *wait_proc, int just_wait_proc) |
| 6729 | { | 7059 | { |
| 6730 | register int nfds; | 7060 | register int nfds; |
| 6731 | EMACS_TIME end_time, timeout; | 7061 | struct timespec end_time, timeout; |
| 7062 | enum { MINIMUM = -1, TIMEOUT, INFINITY } wait; | ||
| 6732 | 7063 | ||
| 6733 | if (time_limit < 0) | 7064 | if (TYPE_MAXIMUM (time_t) < time_limit) |
| 6734 | { | ||
| 6735 | time_limit = 0; | ||
| 6736 | nsecs = -1; | ||
| 6737 | } | ||
| 6738 | else if (TYPE_MAXIMUM (time_t) < time_limit) | ||
| 6739 | time_limit = TYPE_MAXIMUM (time_t); | 7065 | time_limit = TYPE_MAXIMUM (time_t); |
| 6740 | 7066 | ||
| 6741 | /* What does time_limit really mean? */ | 7067 | if (time_limit < 0 || nsecs < 0) |
| 6742 | if (time_limit || nsecs > 0) | 7068 | wait = MINIMUM; |
| 7069 | else if (time_limit > 0 || nsecs > 0) | ||
| 6743 | { | 7070 | { |
| 6744 | timeout = make_emacs_time (time_limit, nsecs); | 7071 | wait = TIMEOUT; |
| 6745 | end_time = add_emacs_time (current_emacs_time (), timeout); | 7072 | end_time = timespec_add (current_timespec (), |
| 7073 | make_timespec (time_limit, nsecs)); | ||
| 6746 | } | 7074 | } |
| 7075 | else | ||
| 7076 | wait = INFINITY; | ||
| 6747 | 7077 | ||
| 6748 | /* Turn off periodic alarms (in case they are in use) | 7078 | /* Turn off periodic alarms (in case they are in use) |
| 6749 | and then turn off any other atimers, | 7079 | and then turn off any other atimers, |
| @@ -6753,8 +7083,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 6753 | 7083 | ||
| 6754 | while (1) | 7084 | while (1) |
| 6755 | { | 7085 | { |
| 6756 | bool timeout_reduced_for_timers = 0; | 7086 | bool timeout_reduced_for_timers = false; |
| 6757 | SELECT_TYPE waitchannels; | 7087 | fd_set waitchannels; |
| 6758 | int xerrno; | 7088 | int xerrno; |
| 6759 | 7089 | ||
| 6760 | /* If calling from keyboard input, do not quit | 7090 | /* If calling from keyboard input, do not quit |
| @@ -6769,25 +7099,15 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 6769 | 7099 | ||
| 6770 | /* Compute time from now till when time limit is up. */ | 7100 | /* Compute time from now till when time limit is up. */ |
| 6771 | /* Exit if already run out. */ | 7101 | /* Exit if already run out. */ |
| 6772 | if (nsecs < 0) | 7102 | if (wait == TIMEOUT) |
| 6773 | { | ||
| 6774 | /* A negative timeout means | ||
| 6775 | gobble output available now | ||
| 6776 | but don't wait at all. */ | ||
| 6777 | |||
| 6778 | timeout = make_emacs_time (0, 0); | ||
| 6779 | } | ||
| 6780 | else if (time_limit || nsecs > 0) | ||
| 6781 | { | 7103 | { |
| 6782 | EMACS_TIME now = current_emacs_time (); | 7104 | struct timespec now = current_timespec (); |
| 6783 | if (EMACS_TIME_LE (end_time, now)) | 7105 | if (timespec_cmp (end_time, now) <= 0) |
| 6784 | break; | 7106 | break; |
| 6785 | timeout = sub_emacs_time (end_time, now); | 7107 | timeout = timespec_sub (end_time, now); |
| 6786 | } | 7108 | } |
| 6787 | else | 7109 | else |
| 6788 | { | 7110 | timeout = make_timespec (wait < TIMEOUT ? 0 : 100000, 0); |
| 6789 | timeout = make_emacs_time (100000, 0); | ||
| 6790 | } | ||
| 6791 | 7111 | ||
| 6792 | /* If our caller will not immediately handle keyboard events, | 7112 | /* If our caller will not immediately handle keyboard events, |
| 6793 | run timer events directly. | 7113 | run timer events directly. |
| @@ -6795,7 +7115,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 6795 | call timer_delay on their own.) */ | 7115 | call timer_delay on their own.) */ |
| 6796 | if (NILP (wait_for_cell)) | 7116 | if (NILP (wait_for_cell)) |
| 6797 | { | 7117 | { |
| 6798 | EMACS_TIME timer_delay; | 7118 | struct timespec timer_delay; |
| 6799 | 7119 | ||
| 6800 | do | 7120 | do |
| 6801 | { | 7121 | { |
| @@ -6815,12 +7135,12 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 6815 | && requeued_events_pending_p ()) | 7135 | && requeued_events_pending_p ()) |
| 6816 | break; | 7136 | break; |
| 6817 | 7137 | ||
| 6818 | if (EMACS_TIME_VALID_P (timer_delay) && nsecs >= 0) | 7138 | if (timespec_valid_p (timer_delay)) |
| 6819 | { | 7139 | { |
| 6820 | if (EMACS_TIME_LT (timer_delay, timeout)) | 7140 | if (timespec_cmp (timer_delay, timeout) < 0) |
| 6821 | { | 7141 | { |
| 6822 | timeout = timer_delay; | 7142 | timeout = timer_delay; |
| 6823 | timeout_reduced_for_timers = 1; | 7143 | timeout_reduced_for_timers = true; |
| 6824 | } | 7144 | } |
| 6825 | } | 7145 | } |
| 6826 | } | 7146 | } |
| @@ -6853,13 +7173,13 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 6853 | 7173 | ||
| 6854 | xerrno = errno; | 7174 | xerrno = errno; |
| 6855 | 7175 | ||
| 6856 | /* Make C-g and alarm signals set flags again */ | 7176 | /* Make C-g and alarm signals set flags again. */ |
| 6857 | clear_waiting_for_input (); | 7177 | clear_waiting_for_input (); |
| 6858 | 7178 | ||
| 6859 | /* If we woke up due to SIGWINCH, actually change size now. */ | 7179 | /* If we woke up due to SIGWINCH, actually change size now. */ |
| 6860 | do_pending_window_change (0); | 7180 | do_pending_window_change (0); |
| 6861 | 7181 | ||
| 6862 | if ((time_limit || nsecs) && nfds == 0 && ! timeout_reduced_for_timers) | 7182 | if (wait < INFINITY && nfds == 0 && ! timeout_reduced_for_timers) |
| 6863 | /* We waited the full specified time, so return now. */ | 7183 | /* We waited the full specified time, so return now. */ |
| 6864 | break; | 7184 | break; |
| 6865 | 7185 | ||
| @@ -6873,7 +7193,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 6873 | report_file_errno ("Failed select", Qnil, xerrno); | 7193 | report_file_errno ("Failed select", Qnil, xerrno); |
| 6874 | } | 7194 | } |
| 6875 | 7195 | ||
| 6876 | /* Check for keyboard input */ | 7196 | /* Check for keyboard input. */ |
| 6877 | 7197 | ||
| 6878 | if (read_kbd | 7198 | if (read_kbd |
| 6879 | && detect_input_pending_run_timers (do_display)) | 7199 | && detect_input_pending_run_timers (do_display)) |
| @@ -6909,7 +7229,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 6909 | 7229 | ||
| 6910 | start_polling (); | 7230 | start_polling (); |
| 6911 | 7231 | ||
| 6912 | return 0; | 7232 | return -1; |
| 6913 | } | 7233 | } |
| 6914 | 7234 | ||
| 6915 | #endif /* not subprocesses */ | 7235 | #endif /* not subprocesses */ |
| @@ -6917,13 +7237,28 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 6917 | /* The following functions are needed even if async subprocesses are | 7237 | /* The following functions are needed even if async subprocesses are |
| 6918 | not supported. Some of them are no-op stubs in that case. */ | 7238 | not supported. Some of them are no-op stubs in that case. */ |
| 6919 | 7239 | ||
| 7240 | #ifdef HAVE_TIMERFD | ||
| 7241 | |||
| 7242 | /* Add FD, which is a descriptor returned by timerfd_create, | ||
| 7243 | to the set of non-keyboard input descriptors. */ | ||
| 7244 | |||
| 7245 | void | ||
| 7246 | add_timer_wait_descriptor (int fd) | ||
| 7247 | { | ||
| 7248 | add_read_fd (fd, timerfd_callback, NULL); | ||
| 7249 | if (fd > max_desc) | ||
| 7250 | max_desc = fd; | ||
| 7251 | } | ||
| 7252 | |||
| 7253 | #endif /* HAVE_TIMERFD */ | ||
| 7254 | |||
| 6920 | /* Add DESC to the set of keyboard input descriptors. */ | 7255 | /* Add DESC to the set of keyboard input descriptors. */ |
| 6921 | 7256 | ||
| 6922 | void | 7257 | void |
| 6923 | add_keyboard_wait_descriptor (int desc) | 7258 | add_keyboard_wait_descriptor (int desc) |
| 6924 | { | 7259 | { |
| 6925 | #ifdef subprocesses /* actually means "not MSDOS" */ | 7260 | #ifdef subprocesses /* Actually means "not MSDOS". */ |
| 6926 | eassert (desc >= 0 && desc < MAXDESC); | 7261 | eassert (desc >= 0 && desc < FD_SETSIZE); |
| 6927 | fd_callback_info[desc].flags |= FOR_READ | KEYBOARD_FD; | 7262 | fd_callback_info[desc].flags |= FOR_READ | KEYBOARD_FD; |
| 6928 | if (desc > max_desc) | 7263 | if (desc > max_desc) |
| 6929 | max_desc = desc; | 7264 | max_desc = desc; |
| @@ -6939,7 +7274,7 @@ delete_keyboard_wait_descriptor (int desc) | |||
| 6939 | int fd; | 7274 | int fd; |
| 6940 | int lim = max_desc; | 7275 | int lim = max_desc; |
| 6941 | 7276 | ||
| 6942 | eassert (desc >= 0 && desc < MAXDESC); | 7277 | eassert (desc >= 0 && desc < FD_SETSIZE); |
| 6943 | 7278 | ||
| 6944 | fd_callback_info[desc].flags &= ~(FOR_READ | KEYBOARD_FD | PROCESS_FD); | 7279 | fd_callback_info[desc].flags &= ~(FOR_READ | KEYBOARD_FD | PROCESS_FD); |
| 6945 | 7280 | ||
| @@ -6981,8 +7316,10 @@ setup_process_coding_systems (Lisp_Object process) | |||
| 6981 | } | 7316 | } |
| 6982 | 7317 | ||
| 6983 | DEFUN ("get-buffer-process", Fget_buffer_process, Sget_buffer_process, 1, 1, 0, | 7318 | DEFUN ("get-buffer-process", Fget_buffer_process, Sget_buffer_process, 1, 1, 0, |
| 6984 | doc: /* Return the (or a) process associated with BUFFER. | 7319 | doc: /* Return the (or a) live process associated with BUFFER. |
| 6985 | BUFFER may be a buffer or the name of one. */) | 7320 | BUFFER may be a buffer or the name of one. |
| 7321 | Return nil if all processes associated with BUFFER have been | ||
| 7322 | deleted or killed. */) | ||
| 6986 | (register Lisp_Object buffer) | 7323 | (register Lisp_Object buffer) |
| 6987 | { | 7324 | { |
| 6988 | #ifdef subprocesses | 7325 | #ifdef subprocesses |
| @@ -7019,7 +7356,7 @@ the process output. */) | |||
| 7019 | } | 7356 | } |
| 7020 | 7357 | ||
| 7021 | /* Kill all processes associated with `buffer'. | 7358 | /* Kill all processes associated with `buffer'. |
| 7022 | If `buffer' is nil, kill all processes */ | 7359 | If `buffer' is nil, kill all processes. */ |
| 7023 | 7360 | ||
| 7024 | void | 7361 | void |
| 7025 | kill_buffer_processes (Lisp_Object buffer) | 7362 | kill_buffer_processes (Lisp_Object buffer) |
| @@ -7030,7 +7367,7 @@ kill_buffer_processes (Lisp_Object buffer) | |||
| 7030 | FOR_EACH_PROCESS (tail, proc) | 7367 | FOR_EACH_PROCESS (tail, proc) |
| 7031 | if (NILP (buffer) || EQ (XPROCESS (proc)->buffer, buffer)) | 7368 | if (NILP (buffer) || EQ (XPROCESS (proc)->buffer, buffer)) |
| 7032 | { | 7369 | { |
| 7033 | if (NETCONN_P (proc) || SERIALCONN_P (proc)) | 7370 | if (NETCONN_P (proc) || SERIALCONN_P (proc) || PIPECONN_P (proc)) |
| 7034 | Fdelete_process (proc); | 7371 | Fdelete_process (proc); |
| 7035 | else if (XPROCESS (proc)->infd >= 0) | 7372 | else if (XPROCESS (proc)->infd >= 0) |
| 7036 | process_send_signal (proc, SIGHUP, Qnil, 1); | 7373 | process_send_signal (proc, SIGHUP, Qnil, 1); |
| @@ -7097,7 +7434,7 @@ DEFUN ("process-attributes", Fprocess_attributes, | |||
| 7097 | 7434 | ||
| 7098 | Value is an alist where each element is a cons cell of the form | 7435 | Value is an alist where each element is a cons cell of the form |
| 7099 | 7436 | ||
| 7100 | \(KEY . VALUE) | 7437 | (KEY . VALUE) |
| 7101 | 7438 | ||
| 7102 | If this functionality is unsupported, the value is nil. | 7439 | If this functionality is unsupported, the value is nil. |
| 7103 | 7440 | ||
| @@ -7148,30 +7485,31 @@ integer or floating point values. | |||
| 7148 | return system_process_attributes (pid); | 7485 | return system_process_attributes (pid); |
| 7149 | } | 7486 | } |
| 7150 | 7487 | ||
| 7488 | #ifdef subprocesses | ||
| 7151 | /* Arrange to catch SIGCHLD if this hasn't already been arranged. | 7489 | /* Arrange to catch SIGCHLD if this hasn't already been arranged. |
| 7152 | Invoke this after init_process_emacs, and after glib and/or GNUstep | 7490 | Invoke this after init_process_emacs, and after glib and/or GNUstep |
| 7153 | futz with the SIGCHLD handler, but before Emacs forks any children. | 7491 | futz with the SIGCHLD handler, but before Emacs forks any children. |
| 7154 | This function's caller should block SIGCHLD. */ | 7492 | This function's caller should block SIGCHLD. */ |
| 7155 | 7493 | ||
| 7156 | #ifndef NS_IMPL_GNUSTEP | ||
| 7157 | static | ||
| 7158 | #endif | ||
| 7159 | void | 7494 | void |
| 7160 | catch_child_signal (void) | 7495 | catch_child_signal (void) |
| 7161 | { | 7496 | { |
| 7162 | struct sigaction action, old_action; | 7497 | struct sigaction action, old_action; |
| 7498 | sigset_t oldset; | ||
| 7163 | emacs_sigaction_init (&action, deliver_child_signal); | 7499 | emacs_sigaction_init (&action, deliver_child_signal); |
| 7164 | block_child_signal (); | 7500 | block_child_signal (&oldset); |
| 7165 | sigaction (SIGCHLD, &action, &old_action); | 7501 | sigaction (SIGCHLD, &action, &old_action); |
| 7166 | eassert (! (old_action.sa_flags & SA_SIGINFO)); | 7502 | eassert (old_action.sa_handler == SIG_DFL || old_action.sa_handler == SIG_IGN |
| 7503 | || ! (old_action.sa_flags & SA_SIGINFO)); | ||
| 7167 | 7504 | ||
| 7168 | if (old_action.sa_handler != deliver_child_signal) | 7505 | if (old_action.sa_handler != deliver_child_signal) |
| 7169 | lib_child_handler | 7506 | lib_child_handler |
| 7170 | = (old_action.sa_handler == SIG_DFL || old_action.sa_handler == SIG_IGN | 7507 | = (old_action.sa_handler == SIG_DFL || old_action.sa_handler == SIG_IGN |
| 7171 | ? dummy_handler | 7508 | ? dummy_handler |
| 7172 | : old_action.sa_handler); | 7509 | : old_action.sa_handler); |
| 7173 | unblock_child_signal (); | 7510 | unblock_child_signal (&oldset); |
| 7174 | } | 7511 | } |
| 7512 | #endif /* subprocesses */ | ||
| 7175 | 7513 | ||
| 7176 | 7514 | ||
| 7177 | /* This is not called "init_process" because that is the name of a | 7515 | /* This is not called "init_process" because that is the name of a |
| @@ -7205,10 +7543,8 @@ init_process_emacs (void) | |||
| 7205 | num_pending_connects = 0; | 7543 | num_pending_connects = 0; |
| 7206 | #endif | 7544 | #endif |
| 7207 | 7545 | ||
| 7208 | #ifdef ADAPTIVE_READ_BUFFERING | ||
| 7209 | process_output_delay_count = 0; | 7546 | process_output_delay_count = 0; |
| 7210 | process_output_skip = 0; | 7547 | process_output_skip = 0; |
| 7211 | #endif | ||
| 7212 | 7548 | ||
| 7213 | /* Don't do this, it caused infinite select loops. The display | 7549 | /* Don't do this, it caused infinite select loops. The display |
| 7214 | method should call add_keyboard_wait_descriptor on stdin if it | 7550 | method should call add_keyboard_wait_descriptor on stdin if it |
| @@ -7219,7 +7555,7 @@ init_process_emacs (void) | |||
| 7219 | 7555 | ||
| 7220 | Vprocess_alist = Qnil; | 7556 | Vprocess_alist = Qnil; |
| 7221 | deleted_pid_list = Qnil; | 7557 | deleted_pid_list = Qnil; |
| 7222 | for (i = 0; i < MAXDESC; i++) | 7558 | for (i = 0; i < FD_SETSIZE; i++) |
| 7223 | { | 7559 | { |
| 7224 | chan_process[i] = Qnil; | 7560 | chan_process[i] = Qnil; |
| 7225 | proc_buffered_char[i] = -1; | 7561 | proc_buffered_char[i] = -1; |
| @@ -7230,40 +7566,6 @@ init_process_emacs (void) | |||
| 7230 | memset (datagram_address, 0, sizeof datagram_address); | 7566 | memset (datagram_address, 0, sizeof datagram_address); |
| 7231 | #endif | 7567 | #endif |
| 7232 | 7568 | ||
| 7233 | { | ||
| 7234 | Lisp_Object subfeatures = Qnil; | ||
| 7235 | const struct socket_options *sopt; | ||
| 7236 | |||
| 7237 | #define ADD_SUBFEATURE(key, val) \ | ||
| 7238 | subfeatures = pure_cons (pure_cons (key, pure_cons (val, Qnil)), subfeatures) | ||
| 7239 | |||
| 7240 | #ifdef NON_BLOCKING_CONNECT | ||
| 7241 | ADD_SUBFEATURE (QCnowait, Qt); | ||
| 7242 | #endif | ||
| 7243 | #ifdef DATAGRAM_SOCKETS | ||
| 7244 | ADD_SUBFEATURE (QCtype, Qdatagram); | ||
| 7245 | #endif | ||
| 7246 | #ifdef HAVE_SEQPACKET | ||
| 7247 | ADD_SUBFEATURE (QCtype, Qseqpacket); | ||
| 7248 | #endif | ||
| 7249 | #ifdef HAVE_LOCAL_SOCKETS | ||
| 7250 | ADD_SUBFEATURE (QCfamily, Qlocal); | ||
| 7251 | #endif | ||
| 7252 | ADD_SUBFEATURE (QCfamily, Qipv4); | ||
| 7253 | #ifdef AF_INET6 | ||
| 7254 | ADD_SUBFEATURE (QCfamily, Qipv6); | ||
| 7255 | #endif | ||
| 7256 | #ifdef HAVE_GETSOCKNAME | ||
| 7257 | ADD_SUBFEATURE (QCservice, Qt); | ||
| 7258 | #endif | ||
| 7259 | ADD_SUBFEATURE (QCserver, Qt); | ||
| 7260 | |||
| 7261 | for (sopt = socket_options; sopt->name; sopt++) | ||
| 7262 | subfeatures = pure_cons (intern_c_string (sopt->name), subfeatures); | ||
| 7263 | |||
| 7264 | Fprovide (intern_c_string ("make-network-process"), subfeatures); | ||
| 7265 | } | ||
| 7266 | |||
| 7267 | #if defined (DARWIN_OS) | 7569 | #if defined (DARWIN_OS) |
| 7268 | /* PTYs are broken on Darwin < 6, but are sometimes useful for interactive | 7570 | /* PTYs are broken on Darwin < 6, but are sometimes useful for interactive |
| 7269 | processes. As such, we only change the default value. */ | 7571 | processes. As such, we only change the default value. */ |
| @@ -7292,10 +7594,7 @@ syms_of_process (void) | |||
| 7292 | DEFSYM (Qsignal, "signal"); | 7594 | DEFSYM (Qsignal, "signal"); |
| 7293 | 7595 | ||
| 7294 | /* Qexit is already staticpro'd by syms_of_eval; don't staticpro it | 7596 | /* Qexit is already staticpro'd by syms_of_eval; don't staticpro it |
| 7295 | here again. | 7597 | here again. */ |
| 7296 | |||
| 7297 | Qexit = intern_c_string ("exit"); | ||
| 7298 | staticpro (&Qexit); */ | ||
| 7299 | 7598 | ||
| 7300 | DEFSYM (Qopen, "open"); | 7599 | DEFSYM (Qopen, "open"); |
| 7301 | DEFSYM (Qclosed, "closed"); | 7600 | DEFSYM (Qclosed, "closed"); |
| @@ -7327,6 +7626,7 @@ syms_of_process (void) | |||
| 7327 | DEFSYM (Qreal, "real"); | 7626 | DEFSYM (Qreal, "real"); |
| 7328 | DEFSYM (Qnetwork, "network"); | 7627 | DEFSYM (Qnetwork, "network"); |
| 7329 | DEFSYM (Qserial, "serial"); | 7628 | DEFSYM (Qserial, "serial"); |
| 7629 | DEFSYM (Qpipe, "pipe"); | ||
| 7330 | DEFSYM (QCbuffer, ":buffer"); | 7630 | DEFSYM (QCbuffer, ":buffer"); |
| 7331 | DEFSYM (QChost, ":host"); | 7631 | DEFSYM (QChost, ":host"); |
| 7332 | DEFSYM (QCservice, ":service"); | 7632 | DEFSYM (QCservice, ":service"); |
| @@ -7339,8 +7639,12 @@ syms_of_process (void) | |||
| 7339 | DEFSYM (QClog, ":log"); | 7639 | DEFSYM (QClog, ":log"); |
| 7340 | DEFSYM (QCnoquery, ":noquery"); | 7640 | DEFSYM (QCnoquery, ":noquery"); |
| 7341 | DEFSYM (QCstop, ":stop"); | 7641 | DEFSYM (QCstop, ":stop"); |
| 7342 | DEFSYM (QCoptions, ":options"); | ||
| 7343 | DEFSYM (QCplist, ":plist"); | 7642 | DEFSYM (QCplist, ":plist"); |
| 7643 | DEFSYM (QCcommand, ":command"); | ||
| 7644 | DEFSYM (QCconnection_type, ":connection-type"); | ||
| 7645 | DEFSYM (QCstderr, ":stderr"); | ||
| 7646 | DEFSYM (Qpty, "pty"); | ||
| 7647 | DEFSYM (Qpipe, "pipe"); | ||
| 7344 | 7648 | ||
| 7345 | DEFSYM (Qlast_nonmenu_event, "last-nonmenu-event"); | 7649 | DEFSYM (Qlast_nonmenu_event, "last-nonmenu-event"); |
| 7346 | 7650 | ||
| @@ -7373,10 +7677,12 @@ syms_of_process (void) | |||
| 7373 | DEFSYM (Qcutime, "cutime"); | 7677 | DEFSYM (Qcutime, "cutime"); |
| 7374 | DEFSYM (Qcstime, "cstime"); | 7678 | DEFSYM (Qcstime, "cstime"); |
| 7375 | DEFSYM (Qctime, "ctime"); | 7679 | DEFSYM (Qctime, "ctime"); |
| 7680 | #ifdef subprocesses | ||
| 7376 | DEFSYM (Qinternal_default_process_sentinel, | 7681 | DEFSYM (Qinternal_default_process_sentinel, |
| 7377 | "internal-default-process-sentinel"); | 7682 | "internal-default-process-sentinel"); |
| 7378 | DEFSYM (Qinternal_default_process_filter, | 7683 | DEFSYM (Qinternal_default_process_filter, |
| 7379 | "internal-default-process-filter"); | 7684 | "internal-default-process-filter"); |
| 7685 | #endif | ||
| 7380 | DEFSYM (Qpri, "pri"); | 7686 | DEFSYM (Qpri, "pri"); |
| 7381 | DEFSYM (Qnice, "nice"); | 7687 | DEFSYM (Qnice, "nice"); |
| 7382 | DEFSYM (Qthcount, "thcount"); | 7688 | DEFSYM (Qthcount, "thcount"); |
| @@ -7403,7 +7709,6 @@ then a pipe is used in any case. | |||
| 7403 | The value takes effect when `start-process' is called. */); | 7709 | The value takes effect when `start-process' is called. */); |
| 7404 | Vprocess_connection_type = Qt; | 7710 | Vprocess_connection_type = Qt; |
| 7405 | 7711 | ||
| 7406 | #ifdef ADAPTIVE_READ_BUFFERING | ||
| 7407 | DEFVAR_LISP ("process-adaptive-read-buffering", Vprocess_adaptive_read_buffering, | 7712 | DEFVAR_LISP ("process-adaptive-read-buffering", Vprocess_adaptive_read_buffering, |
| 7408 | doc: /* If non-nil, improve receive buffering by delaying after short reads. | 7713 | doc: /* If non-nil, improve receive buffering by delaying after short reads. |
| 7409 | On some systems, when Emacs reads the output from a subprocess, the output data | 7714 | On some systems, when Emacs reads the output from a subprocess, the output data |
| @@ -7415,7 +7720,6 @@ If the value is t, the delay is reset after each write to the process; any other | |||
| 7415 | non-nil value means that the delay is not reset on write. | 7720 | non-nil value means that the delay is not reset on write. |
| 7416 | The variable takes effect when `start-process' is called. */); | 7721 | The variable takes effect when `start-process' is called. */); |
| 7417 | Vprocess_adaptive_read_buffering = Qt; | 7722 | Vprocess_adaptive_read_buffering = Qt; |
| 7418 | #endif | ||
| 7419 | 7723 | ||
| 7420 | defsubr (&Sprocessp); | 7724 | defsubr (&Sprocessp); |
| 7421 | defsubr (&Sget_process); | 7725 | defsubr (&Sget_process); |
| @@ -7443,20 +7747,15 @@ The variable takes effect when `start-process' is called. */); | |||
| 7443 | defsubr (&Sprocess_plist); | 7747 | defsubr (&Sprocess_plist); |
| 7444 | defsubr (&Sset_process_plist); | 7748 | defsubr (&Sset_process_plist); |
| 7445 | defsubr (&Sprocess_list); | 7749 | defsubr (&Sprocess_list); |
| 7446 | defsubr (&Sstart_process); | 7750 | defsubr (&Smake_process); |
| 7751 | defsubr (&Smake_pipe_process); | ||
| 7447 | defsubr (&Sserial_process_configure); | 7752 | defsubr (&Sserial_process_configure); |
| 7448 | defsubr (&Smake_serial_process); | 7753 | defsubr (&Smake_serial_process); |
| 7449 | defsubr (&Sset_network_process_option); | 7754 | defsubr (&Sset_network_process_option); |
| 7450 | defsubr (&Smake_network_process); | 7755 | defsubr (&Smake_network_process); |
| 7451 | defsubr (&Sformat_network_address); | 7756 | defsubr (&Sformat_network_address); |
| 7452 | #if defined (HAVE_NET_IF_H) | ||
| 7453 | #ifdef SIOCGIFCONF | ||
| 7454 | defsubr (&Snetwork_interface_list); | 7757 | defsubr (&Snetwork_interface_list); |
| 7455 | #endif | ||
| 7456 | #if defined (SIOCGIFADDR) || defined (SIOCGIFHWADDR) || defined (SIOCGIFFLAGS) | ||
| 7457 | defsubr (&Snetwork_interface_info); | 7758 | defsubr (&Snetwork_interface_info); |
| 7458 | #endif | ||
| 7459 | #endif /* defined (HAVE_NET_IF_H) */ | ||
| 7460 | #ifdef DATAGRAM_SOCKETS | 7759 | #ifdef DATAGRAM_SOCKETS |
| 7461 | defsubr (&Sprocess_datagram_address); | 7760 | defsubr (&Sprocess_datagram_address); |
| 7462 | defsubr (&Sset_process_datagram_address); | 7761 | defsubr (&Sset_process_datagram_address); |
| @@ -7487,4 +7786,39 @@ The variable takes effect when `start-process' is called. */); | |||
| 7487 | defsubr (&Sprocess_inherit_coding_system_flag); | 7786 | defsubr (&Sprocess_inherit_coding_system_flag); |
| 7488 | defsubr (&Slist_system_processes); | 7787 | defsubr (&Slist_system_processes); |
| 7489 | defsubr (&Sprocess_attributes); | 7788 | defsubr (&Sprocess_attributes); |
| 7789 | |||
| 7790 | { | ||
| 7791 | Lisp_Object subfeatures = Qnil; | ||
| 7792 | const struct socket_options *sopt; | ||
| 7793 | |||
| 7794 | #define ADD_SUBFEATURE(key, val) \ | ||
| 7795 | subfeatures = pure_cons (pure_cons (key, pure_cons (val, Qnil)), subfeatures) | ||
| 7796 | |||
| 7797 | #ifdef NON_BLOCKING_CONNECT | ||
| 7798 | ADD_SUBFEATURE (QCnowait, Qt); | ||
| 7799 | #endif | ||
| 7800 | #ifdef DATAGRAM_SOCKETS | ||
| 7801 | ADD_SUBFEATURE (QCtype, Qdatagram); | ||
| 7802 | #endif | ||
| 7803 | #ifdef HAVE_SEQPACKET | ||
| 7804 | ADD_SUBFEATURE (QCtype, Qseqpacket); | ||
| 7805 | #endif | ||
| 7806 | #ifdef HAVE_LOCAL_SOCKETS | ||
| 7807 | ADD_SUBFEATURE (QCfamily, Qlocal); | ||
| 7808 | #endif | ||
| 7809 | ADD_SUBFEATURE (QCfamily, Qipv4); | ||
| 7810 | #ifdef AF_INET6 | ||
| 7811 | ADD_SUBFEATURE (QCfamily, Qipv6); | ||
| 7812 | #endif | ||
| 7813 | #ifdef HAVE_GETSOCKNAME | ||
| 7814 | ADD_SUBFEATURE (QCservice, Qt); | ||
| 7815 | #endif | ||
| 7816 | ADD_SUBFEATURE (QCserver, Qt); | ||
| 7817 | |||
| 7818 | for (sopt = socket_options; sopt->name; sopt++) | ||
| 7819 | subfeatures = pure_cons (intern_c_string (sopt->name), subfeatures); | ||
| 7820 | |||
| 7821 | Fprovide (intern_c_string ("make-network-process"), subfeatures); | ||
| 7822 | } | ||
| 7823 | |||
| 7490 | } | 7824 | } |