diff options
| author | Tom Tromey | 2012-12-17 07:56:22 -0700 |
|---|---|---|
| committer | Tom Tromey | 2012-12-17 07:56:22 -0700 |
| commit | 3d6eced1ae51ffd0a782130e7c334052277e2724 (patch) | |
| tree | 5d1d2ad7cd3374f922886c4a72062511a035c168 /src/process.c | |
| parent | bf69f522a9e135f9aa483cedd53e71e915f2bf75 (diff) | |
| parent | 7c3d167f48d6262ee4e5512aa50a07ee96bc1509 (diff) | |
| download | emacs-3d6eced1ae51ffd0a782130e7c334052277e2724.tar.gz emacs-3d6eced1ae51ffd0a782130e7c334052277e2724.zip | |
merge from trunk
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 1190 |
1 files changed, 423 insertions, 767 deletions
diff --git a/src/process.c b/src/process.c index dbbb23b8627..7f647d44a93 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -23,15 +23,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 23 | 23 | ||
| 24 | #define PROCESS_INLINE EXTERN_INLINE | 24 | #define PROCESS_INLINE EXTERN_INLINE |
| 25 | 25 | ||
| 26 | #include <signal.h> | ||
| 27 | #include <stdio.h> | 26 | #include <stdio.h> |
| 28 | #include <errno.h> | 27 | #include <errno.h> |
| 29 | #include <setjmp.h> | ||
| 30 | #include <sys/types.h> /* Some typedefs are used in sys/file.h. */ | 28 | #include <sys/types.h> /* Some typedefs are used in sys/file.h. */ |
| 31 | #include <sys/file.h> | 29 | #include <sys/file.h> |
| 32 | #include <sys/stat.h> | 30 | #include <sys/stat.h> |
| 33 | #include <setjmp.h> | ||
| 34 | |||
| 35 | #include <unistd.h> | 31 | #include <unistd.h> |
| 36 | #include <fcntl.h> | 32 | #include <fcntl.h> |
| 37 | 33 | ||
| @@ -76,6 +72,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 76 | #include <bsdtty.h> | 72 | #include <bsdtty.h> |
| 77 | #endif | 73 | #endif |
| 78 | 74 | ||
| 75 | #ifdef USG5_4 | ||
| 76 | # include <sys/stream.h> | ||
| 77 | # include <sys/stropts.h> | ||
| 78 | #endif | ||
| 79 | |||
| 79 | #ifdef HAVE_RES_INIT | 80 | #ifdef HAVE_RES_INIT |
| 80 | #include <netinet/in.h> | 81 | #include <netinet/in.h> |
| 81 | #include <arpa/nameser.h> | 82 | #include <arpa/nameser.h> |
| @@ -90,6 +91,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 90 | #include <pty.h> | 91 | #include <pty.h> |
| 91 | #endif | 92 | #endif |
| 92 | 93 | ||
| 94 | #include <c-ctype.h> | ||
| 95 | #include <sig2str.h> | ||
| 96 | |||
| 93 | #endif /* subprocesses */ | 97 | #endif /* subprocesses */ |
| 94 | 98 | ||
| 95 | #include "systime.h" | 99 | #include "systime.h" |
| @@ -124,6 +128,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 124 | #include "xgselect.h" | 128 | #include "xgselect.h" |
| 125 | #endif | 129 | #endif |
| 126 | 130 | ||
| 131 | #ifdef WINDOWSNT | ||
| 132 | extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *, | ||
| 133 | EMACS_TIME *, void *); | ||
| 134 | #endif | ||
| 135 | |||
| 127 | /* Work around GCC 4.7.0 bug with strict overflow checking; see | 136 | /* Work around GCC 4.7.0 bug with strict overflow checking; see |
| 128 | <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52904>. | 137 | <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52904>. |
| 129 | These lines can be removed once the GCC bug is fixed. */ | 138 | These lines can be removed once the GCC bug is fixed. */ |
| @@ -190,11 +199,9 @@ static EMACS_INT update_tick; | |||
| 190 | #ifndef NON_BLOCKING_CONNECT | 199 | #ifndef NON_BLOCKING_CONNECT |
| 191 | #ifdef HAVE_SELECT | 200 | #ifdef HAVE_SELECT |
| 192 | #if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX) | 201 | #if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX) |
| 193 | #if defined (O_NONBLOCK) || defined (O_NDELAY) | ||
| 194 | #if defined (EWOULDBLOCK) || defined (EINPROGRESS) | 202 | #if defined (EWOULDBLOCK) || defined (EINPROGRESS) |
| 195 | #define NON_BLOCKING_CONNECT | 203 | #define NON_BLOCKING_CONNECT |
| 196 | #endif /* EWOULDBLOCK || EINPROGRESS */ | 204 | #endif /* EWOULDBLOCK || EINPROGRESS */ |
| 197 | #endif /* O_NONBLOCK || O_NDELAY */ | ||
| 198 | #endif /* HAVE_GETPEERNAME || GNU_LINUX */ | 205 | #endif /* HAVE_GETPEERNAME || GNU_LINUX */ |
| 199 | #endif /* HAVE_SELECT */ | 206 | #endif /* HAVE_SELECT */ |
| 200 | #endif /* NON_BLOCKING_CONNECT */ | 207 | #endif /* NON_BLOCKING_CONNECT */ |
| @@ -205,17 +212,13 @@ static EMACS_INT update_tick; | |||
| 205 | "non-destructive" select. So we require either native select, | 212 | "non-destructive" select. So we require either native select, |
| 206 | or emulation of select using FIONREAD. */ | 213 | or emulation of select using FIONREAD. */ |
| 207 | 214 | ||
| 208 | #ifdef BROKEN_DATAGRAM_SOCKETS | 215 | #ifndef BROKEN_DATAGRAM_SOCKETS |
| 209 | #undef DATAGRAM_SOCKETS | 216 | # if defined HAVE_SELECT || defined USABLE_FIONREAD |
| 210 | #else | 217 | # if defined HAVE_SENDTO && defined HAVE_RECVFROM && defined EMSGSIZE |
| 211 | #ifndef DATAGRAM_SOCKETS | 218 | # define DATAGRAM_SOCKETS |
| 212 | #if defined (HAVE_SELECT) || defined (FIONREAD) | 219 | # endif |
| 213 | #if defined (HAVE_SENDTO) && defined (HAVE_RECVFROM) && defined (EMSGSIZE) | 220 | # endif |
| 214 | #define DATAGRAM_SOCKETS | 221 | #endif |
| 215 | #endif /* HAVE_SENDTO && HAVE_RECVFROM && EMSGSIZE */ | ||
| 216 | #endif /* HAVE_SELECT || FIONREAD */ | ||
| 217 | #endif /* DATAGRAM_SOCKETS */ | ||
| 218 | #endif /* BROKEN_DATAGRAM_SOCKETS */ | ||
| 219 | 222 | ||
| 220 | #if defined HAVE_LOCAL_SOCKETS && defined DATAGRAM_SOCKETS | 223 | #if defined HAVE_LOCAL_SOCKETS && defined DATAGRAM_SOCKETS |
| 221 | # define HAVE_SEQPACKET | 224 | # define HAVE_SEQPACKET |
| @@ -244,17 +247,18 @@ static int process_output_skip; | |||
| 244 | #endif | 247 | #endif |
| 245 | 248 | ||
| 246 | static void create_process (Lisp_Object, char **, Lisp_Object); | 249 | static void create_process (Lisp_Object, char **, Lisp_Object); |
| 247 | #ifdef SIGIO | 250 | #ifdef USABLE_SIGIO |
| 248 | static int keyboard_bit_set (SELECT_TYPE *); | 251 | static int keyboard_bit_set (SELECT_TYPE *); |
| 249 | #endif | 252 | #endif |
| 250 | static void deactivate_process (Lisp_Object); | 253 | static void deactivate_process (Lisp_Object); |
| 251 | static void status_notify (struct Lisp_Process *); | 254 | static void status_notify (struct Lisp_Process *); |
| 252 | static int read_process_output (Lisp_Object, int); | 255 | static int read_process_output (Lisp_Object, int); |
| 256 | static void handle_child_signal (int); | ||
| 253 | static void create_pty (Lisp_Object); | 257 | static void create_pty (Lisp_Object); |
| 254 | 258 | ||
| 255 | /* If we support a window system, turn on the code to poll periodically | 259 | /* If we support a window system, turn on the code to poll periodically |
| 256 | to detect C-g. It isn't actually used when doing interrupt input. */ | 260 | to detect C-g. It isn't actually used when doing interrupt input. */ |
| 257 | #if defined (HAVE_WINDOW_SYSTEM) && !defined (USE_ASYNC_EVENTS) | 261 | #ifdef HAVE_WINDOW_SYSTEM |
| 258 | #define POLL_FOR_INPUT | 262 | #define POLL_FOR_INPUT |
| 259 | #endif | 263 | #endif |
| 260 | 264 | ||
| @@ -303,91 +307,88 @@ static struct sockaddr_and_len { | |||
| 303 | #define DATAGRAM_CONN_P(proc) (0) | 307 | #define DATAGRAM_CONN_P(proc) (0) |
| 304 | #endif | 308 | #endif |
| 305 | 309 | ||
| 306 | /* Maximum number of bytes to send to a pty without an eof. */ | ||
| 307 | static int pty_max_bytes; | ||
| 308 | |||
| 309 | /* These setters are used only in this file, so they can be private. */ | 310 | /* These setters are used only in this file, so they can be private. */ |
| 310 | static inline void | 311 | static void |
| 311 | pset_buffer (struct Lisp_Process *p, Lisp_Object val) | 312 | pset_buffer (struct Lisp_Process *p, Lisp_Object val) |
| 312 | { | 313 | { |
| 313 | p->buffer = val; | 314 | p->buffer = val; |
| 314 | } | 315 | } |
| 315 | static inline void | 316 | static void |
| 316 | pset_command (struct Lisp_Process *p, Lisp_Object val) | 317 | pset_command (struct Lisp_Process *p, Lisp_Object val) |
| 317 | { | 318 | { |
| 318 | p->command = val; | 319 | p->command = val; |
| 319 | } | 320 | } |
| 320 | static inline void | 321 | static void |
| 321 | pset_decode_coding_system (struct Lisp_Process *p, Lisp_Object val) | 322 | pset_decode_coding_system (struct Lisp_Process *p, Lisp_Object val) |
| 322 | { | 323 | { |
| 323 | p->decode_coding_system = val; | 324 | p->decode_coding_system = val; |
| 324 | } | 325 | } |
| 325 | static inline void | 326 | static void |
| 326 | pset_decoding_buf (struct Lisp_Process *p, Lisp_Object val) | 327 | pset_decoding_buf (struct Lisp_Process *p, Lisp_Object val) |
| 327 | { | 328 | { |
| 328 | p->decoding_buf = val; | 329 | p->decoding_buf = val; |
| 329 | } | 330 | } |
| 330 | static inline void | 331 | static void |
| 331 | pset_encode_coding_system (struct Lisp_Process *p, Lisp_Object val) | 332 | pset_encode_coding_system (struct Lisp_Process *p, Lisp_Object val) |
| 332 | { | 333 | { |
| 333 | p->encode_coding_system = val; | 334 | p->encode_coding_system = val; |
| 334 | } | 335 | } |
| 335 | static inline void | 336 | static void |
| 336 | pset_encoding_buf (struct Lisp_Process *p, Lisp_Object val) | 337 | pset_encoding_buf (struct Lisp_Process *p, Lisp_Object val) |
| 337 | { | 338 | { |
| 338 | p->encoding_buf = val; | 339 | p->encoding_buf = val; |
| 339 | } | 340 | } |
| 340 | static inline void | 341 | static void |
| 341 | pset_filter (struct Lisp_Process *p, Lisp_Object val) | 342 | pset_filter (struct Lisp_Process *p, Lisp_Object val) |
| 342 | { | 343 | { |
| 343 | p->filter = val; | 344 | p->filter = val; |
| 344 | } | 345 | } |
| 345 | static inline void | 346 | static void |
| 346 | pset_log (struct Lisp_Process *p, Lisp_Object val) | 347 | pset_log (struct Lisp_Process *p, Lisp_Object val) |
| 347 | { | 348 | { |
| 348 | p->log = val; | 349 | p->log = val; |
| 349 | } | 350 | } |
| 350 | static inline void | 351 | static void |
| 351 | pset_mark (struct Lisp_Process *p, Lisp_Object val) | 352 | pset_mark (struct Lisp_Process *p, Lisp_Object val) |
| 352 | { | 353 | { |
| 353 | p->mark = val; | 354 | p->mark = val; |
| 354 | } | 355 | } |
| 355 | static inline void | 356 | static void |
| 356 | pset_thread (struct Lisp_Process *p, Lisp_Object val) | 357 | pset_thread (struct Lisp_Process *p, Lisp_Object val) |
| 357 | { | 358 | { |
| 358 | p->thread = val; | 359 | p->thread = val; |
| 359 | } | 360 | } |
| 360 | static inline void | 361 | static void |
| 361 | pset_name (struct Lisp_Process *p, Lisp_Object val) | 362 | pset_name (struct Lisp_Process *p, Lisp_Object val) |
| 362 | { | 363 | { |
| 363 | p->name = val; | 364 | p->name = val; |
| 364 | } | 365 | } |
| 365 | static inline void | 366 | static void |
| 366 | pset_plist (struct Lisp_Process *p, Lisp_Object val) | 367 | pset_plist (struct Lisp_Process *p, Lisp_Object val) |
| 367 | { | 368 | { |
| 368 | p->plist = val; | 369 | p->plist = val; |
| 369 | } | 370 | } |
| 370 | static inline void | 371 | static void |
| 371 | pset_sentinel (struct Lisp_Process *p, Lisp_Object val) | 372 | pset_sentinel (struct Lisp_Process *p, Lisp_Object val) |
| 372 | { | 373 | { |
| 373 | p->sentinel = val; | 374 | p->sentinel = val; |
| 374 | } | 375 | } |
| 375 | static inline void | 376 | static void |
| 376 | pset_status (struct Lisp_Process *p, Lisp_Object val) | 377 | pset_status (struct Lisp_Process *p, Lisp_Object val) |
| 377 | { | 378 | { |
| 378 | p->status = val; | 379 | p->status = val; |
| 379 | } | 380 | } |
| 380 | static inline void | 381 | static void |
| 381 | pset_tty_name (struct Lisp_Process *p, Lisp_Object val) | 382 | pset_tty_name (struct Lisp_Process *p, Lisp_Object val) |
| 382 | { | 383 | { |
| 383 | p->tty_name = val; | 384 | p->tty_name = val; |
| 384 | } | 385 | } |
| 385 | static inline void | 386 | static void |
| 386 | pset_type (struct Lisp_Process *p, Lisp_Object val) | 387 | pset_type (struct Lisp_Process *p, Lisp_Object val) |
| 387 | { | 388 | { |
| 388 | p->type = val; | 389 | p->type = val; |
| 389 | } | 390 | } |
| 390 | static inline void | 391 | static void |
| 391 | pset_write_queue (struct Lisp_Process *p, Lisp_Object val) | 392 | pset_write_queue (struct Lisp_Process *p, Lisp_Object val) |
| 392 | { | 393 | { |
| 393 | p->write_queue = val; | 394 | p->write_queue = val; |
| @@ -703,7 +704,7 @@ status_message (struct Lisp_Process *p) | |||
| 703 | 704 | ||
| 704 | if (EQ (symbol, Qsignal) || EQ (symbol, Qstop)) | 705 | if (EQ (symbol, Qsignal) || EQ (symbol, Qstop)) |
| 705 | { | 706 | { |
| 706 | char *signame; | 707 | char const *signame; |
| 707 | synchronize_system_messages_locale (); | 708 | synchronize_system_messages_locale (); |
| 708 | signame = strsignal (code); | 709 | signame = strsignal (code); |
| 709 | if (signame == 0) | 710 | if (signame == 0) |
| @@ -778,30 +779,7 @@ allocate_pty (void) | |||
| 778 | #ifdef PTY_OPEN | 779 | #ifdef PTY_OPEN |
| 779 | PTY_OPEN; | 780 | PTY_OPEN; |
| 780 | #else /* no PTY_OPEN */ | 781 | #else /* no PTY_OPEN */ |
| 781 | { | 782 | fd = emacs_open (pty_name, O_RDWR | O_NONBLOCK, 0); |
| 782 | { /* Some systems name their pseudoterminals so that there are gaps in | ||
| 783 | the usual sequence - for example, on HP9000/S700 systems, there | ||
| 784 | are no pseudoterminals with names ending in 'f'. So we wait for | ||
| 785 | three failures in a row before deciding that we've reached the | ||
| 786 | end of the ptys. */ | ||
| 787 | int failed_count = 0; | ||
| 788 | struct stat stb; | ||
| 789 | |||
| 790 | if (stat (pty_name, &stb) < 0) | ||
| 791 | { | ||
| 792 | failed_count++; | ||
| 793 | if (failed_count >= 3) | ||
| 794 | return -1; | ||
| 795 | } | ||
| 796 | else | ||
| 797 | failed_count = 0; | ||
| 798 | } | ||
| 799 | # ifdef O_NONBLOCK | ||
| 800 | fd = emacs_open (pty_name, O_RDWR | O_NONBLOCK, 0); | ||
| 801 | # else | ||
| 802 | fd = emacs_open (pty_name, O_RDWR | O_NDELAY, 0); | ||
| 803 | # endif | ||
| 804 | } | ||
| 805 | #endif /* no PTY_OPEN */ | 783 | #endif /* no PTY_OPEN */ |
| 806 | 784 | ||
| 807 | if (fd >= 0) | 785 | if (fd >= 0) |
| @@ -813,7 +791,7 @@ allocate_pty (void) | |||
| 813 | #else | 791 | #else |
| 814 | sprintf (pty_name, "/dev/tty%c%x", c, i); | 792 | sprintf (pty_name, "/dev/tty%c%x", c, i); |
| 815 | #endif /* no PTY_TTY_NAME_SPRINTF */ | 793 | #endif /* no PTY_TTY_NAME_SPRINTF */ |
| 816 | if (access (pty_name, 6) != 0) | 794 | if (faccessat (AT_FDCWD, pty_name, R_OK | W_OK, AT_EACCESS) != 0) |
| 817 | { | 795 | { |
| 818 | emacs_close (fd); | 796 | emacs_close (fd); |
| 819 | # ifndef __sgi | 797 | # ifndef __sgi |
| @@ -959,14 +937,22 @@ get_process (register Lisp_Object name) | |||
| 959 | } | 937 | } |
| 960 | 938 | ||
| 961 | 939 | ||
| 962 | #ifdef SIGCHLD | ||
| 963 | /* Fdelete_process promises to immediately forget about the process, but in | 940 | /* Fdelete_process promises to immediately forget about the process, but in |
| 964 | reality, Emacs needs to remember those processes until they have been | 941 | reality, Emacs needs to remember those processes until they have been |
| 965 | treated by sigchld_handler; otherwise this handler would consider the | 942 | treated by the SIGCHLD handler and waitpid has been invoked on them; |
| 966 | process as being synchronous and say that the synchronous process is | 943 | otherwise they might fill up the kernel's process table. |
| 967 | dead. */ | 944 | |
| 945 | Some processes created by call-process are also put onto this list. */ | ||
| 968 | static Lisp_Object deleted_pid_list; | 946 | static Lisp_Object deleted_pid_list; |
| 969 | #endif | 947 | |
| 948 | void | ||
| 949 | record_deleted_pid (pid_t pid) | ||
| 950 | { | ||
| 951 | deleted_pid_list = Fcons (make_fixnum_or_float (pid), | ||
| 952 | /* GC treated elements set to nil. */ | ||
| 953 | Fdelq (Qnil, deleted_pid_list)); | ||
| 954 | |||
| 955 | } | ||
| 970 | 956 | ||
| 971 | DEFUN ("delete-process", Fdelete_process, Sdelete_process, 1, 1, 0, | 957 | DEFUN ("delete-process", Fdelete_process, Sdelete_process, 1, 1, 0, |
| 972 | doc: /* Delete PROCESS: kill it and forget about it immediately. | 958 | doc: /* Delete PROCESS: kill it and forget about it immediately. |
| @@ -987,31 +973,22 @@ nil, indicating the current buffer's process. */) | |||
| 987 | status_notify (p); | 973 | status_notify (p); |
| 988 | redisplay_preserve_echo_area (13); | 974 | redisplay_preserve_echo_area (13); |
| 989 | } | 975 | } |
| 990 | else if (p->infd >= 0) | 976 | else |
| 991 | { | 977 | { |
| 992 | #ifdef SIGCHLD | 978 | if (p->alive) |
| 993 | Lisp_Object symbol; | 979 | record_kill_process (p); |
| 994 | pid_t pid = p->pid; | 980 | |
| 995 | 981 | if (p->infd >= 0) | |
| 996 | /* No problem storing the pid here, as it is still in Vprocess_alist. */ | ||
| 997 | deleted_pid_list = Fcons (make_fixnum_or_float (pid), | ||
| 998 | /* GC treated elements set to nil. */ | ||
| 999 | Fdelq (Qnil, deleted_pid_list)); | ||
| 1000 | /* If the process has already signaled, remove it from the list. */ | ||
| 1001 | if (p->raw_status_new) | ||
| 1002 | update_status (p); | ||
| 1003 | symbol = p->status; | ||
| 1004 | if (CONSP (p->status)) | ||
| 1005 | symbol = XCAR (p->status); | ||
| 1006 | if (EQ (symbol, Qsignal) || EQ (symbol, Qexit)) | ||
| 1007 | deleted_pid_list | ||
| 1008 | = Fdelete (make_fixnum_or_float (pid), deleted_pid_list); | ||
| 1009 | else | ||
| 1010 | #endif | ||
| 1011 | { | 982 | { |
| 1012 | Fkill_process (process, Qnil); | 983 | /* Update P's status, since record_kill_process will make the |
| 1013 | /* Do this now, since remove_process will make sigchld_handler do nothing. */ | 984 | SIGCHLD handler update deleted_pid_list, not *P. */ |
| 1014 | pset_status (p, Fcons (Qsignal, Fcons (make_number (SIGKILL), Qnil))); | 985 | Lisp_Object symbol; |
| 986 | if (p->raw_status_new) | ||
| 987 | update_status (p); | ||
| 988 | symbol = CONSP (p->status) ? XCAR (p->status) : p->status; | ||
| 989 | if (! (EQ (symbol, Qsignal) || EQ (symbol, Qexit))) | ||
| 990 | pset_status (p, list2 (Qsignal, make_number (SIGKILL))); | ||
| 991 | |||
| 1015 | p->tick = ++process_tick; | 992 | p->tick = ++process_tick; |
| 1016 | status_notify (p); | 993 | status_notify (p); |
| 1017 | redisplay_preserve_echo_area (13); | 994 | redisplay_preserve_echo_area (13); |
| @@ -1768,7 +1745,7 @@ static Lisp_Object | |||
| 1768 | start_process_unwind (Lisp_Object proc) | 1745 | start_process_unwind (Lisp_Object proc) |
| 1769 | { | 1746 | { |
| 1770 | if (!PROCESSP (proc)) | 1747 | if (!PROCESSP (proc)) |
| 1771 | abort (); | 1748 | emacs_abort (); |
| 1772 | 1749 | ||
| 1773 | /* Was PROC started successfully? | 1750 | /* Was PROC started successfully? |
| 1774 | -2 is used for a pty with no process, eg for gdb. */ | 1751 | -2 is used for a pty with no process, eg for gdb. */ |
| @@ -1791,20 +1768,15 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1791 | int inchannel, outchannel; | 1768 | int inchannel, outchannel; |
| 1792 | pid_t pid; | 1769 | pid_t pid; |
| 1793 | int sv[2]; | 1770 | int sv[2]; |
| 1794 | #if !defined (WINDOWSNT) && defined (FD_CLOEXEC) | 1771 | #ifndef WINDOWSNT |
| 1795 | int wait_child_setup[2]; | 1772 | int wait_child_setup[2]; |
| 1796 | #endif | 1773 | #endif |
| 1797 | sigset_t procmask; | ||
| 1798 | sigset_t blocked; | 1774 | sigset_t blocked; |
| 1799 | struct sigaction sigint_action; | 1775 | /* Use volatile to protect variables from being clobbered by vfork. */ |
| 1800 | struct sigaction sigquit_action; | ||
| 1801 | struct sigaction sigpipe_action; | ||
| 1802 | #ifdef AIX | ||
| 1803 | struct sigaction sighup_action; | ||
| 1804 | #endif | ||
| 1805 | /* Use volatile to protect variables from being clobbered by longjmp. */ | ||
| 1806 | volatile int forkin, forkout; | 1776 | volatile int forkin, forkout; |
| 1807 | volatile int pty_flag = 0; | 1777 | volatile int pty_flag = 0; |
| 1778 | volatile Lisp_Object lisp_pty_name = Qnil; | ||
| 1779 | volatile Lisp_Object encoded_current_dir; | ||
| 1808 | 1780 | ||
| 1809 | inchannel = outchannel = -1; | 1781 | inchannel = outchannel = -1; |
| 1810 | 1782 | ||
| @@ -1817,19 +1789,16 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1817 | #if ! defined (USG) || defined (USG_SUBTTY_WORKS) | 1789 | #if ! defined (USG) || defined (USG_SUBTTY_WORKS) |
| 1818 | /* On most USG systems it does not work to open the pty's tty here, | 1790 | /* On most USG systems it does not work to open the pty's tty here, |
| 1819 | then close it and reopen it in the child. */ | 1791 | then close it and reopen it in the child. */ |
| 1820 | #ifdef O_NOCTTY | ||
| 1821 | /* Don't let this terminal become our controlling terminal | 1792 | /* Don't let this terminal become our controlling terminal |
| 1822 | (in case we don't have one). */ | 1793 | (in case we don't have one). */ |
| 1823 | forkout = forkin = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); | 1794 | forkout = forkin = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); |
| 1824 | #else | ||
| 1825 | forkout = forkin = emacs_open (pty_name, O_RDWR, 0); | ||
| 1826 | #endif | ||
| 1827 | if (forkin < 0) | 1795 | if (forkin < 0) |
| 1828 | report_file_error ("Opening pty", Qnil); | 1796 | report_file_error ("Opening pty", Qnil); |
| 1829 | #else | 1797 | #else |
| 1830 | forkin = forkout = -1; | 1798 | forkin = forkout = -1; |
| 1831 | #endif /* not USG, or USG_SUBTTY_WORKS */ | 1799 | #endif /* not USG, or USG_SUBTTY_WORKS */ |
| 1832 | pty_flag = 1; | 1800 | pty_flag = 1; |
| 1801 | lisp_pty_name = build_string (pty_name); | ||
| 1833 | } | 1802 | } |
| 1834 | else | 1803 | else |
| 1835 | #endif /* HAVE_PTYS */ | 1804 | #endif /* HAVE_PTYS */ |
| @@ -1851,7 +1820,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1851 | forkin = sv[0]; | 1820 | forkin = sv[0]; |
| 1852 | } | 1821 | } |
| 1853 | 1822 | ||
| 1854 | #if !defined (WINDOWSNT) && defined (FD_CLOEXEC) | 1823 | #ifndef WINDOWSNT |
| 1855 | { | 1824 | { |
| 1856 | int tem; | 1825 | int tem; |
| 1857 | 1826 | ||
| @@ -1870,15 +1839,8 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1870 | } | 1839 | } |
| 1871 | #endif | 1840 | #endif |
| 1872 | 1841 | ||
| 1873 | #ifdef O_NONBLOCK | ||
| 1874 | fcntl (inchannel, F_SETFL, O_NONBLOCK); | 1842 | fcntl (inchannel, F_SETFL, O_NONBLOCK); |
| 1875 | fcntl (outchannel, F_SETFL, O_NONBLOCK); | 1843 | fcntl (outchannel, F_SETFL, O_NONBLOCK); |
| 1876 | #else | ||
| 1877 | #ifdef O_NDELAY | ||
| 1878 | fcntl (inchannel, F_SETFL, O_NDELAY); | ||
| 1879 | fcntl (outchannel, F_SETFL, O_NDELAY); | ||
| 1880 | #endif | ||
| 1881 | #endif | ||
| 1882 | 1844 | ||
| 1883 | /* Record this as an active process, with its channels. | 1845 | /* Record this as an active process, with its channels. |
| 1884 | As a result, child_setup will close Emacs's side of the pipes. */ | 1846 | As a result, child_setup will close Emacs's side of the pipes. */ |
| @@ -1894,202 +1856,152 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1894 | XPROCESS (process)->pty_flag = pty_flag; | 1856 | XPROCESS (process)->pty_flag = pty_flag; |
| 1895 | pset_status (XPROCESS (process), Qrun); | 1857 | pset_status (XPROCESS (process), Qrun); |
| 1896 | 1858 | ||
| 1897 | /* Delay interrupts until we have a chance to store | ||
| 1898 | the new fork's pid in its process structure */ | ||
| 1899 | sigemptyset (&blocked); | ||
| 1900 | #ifdef SIGCHLD | ||
| 1901 | sigaddset (&blocked, SIGCHLD); | ||
| 1902 | #endif | ||
| 1903 | #ifdef HAVE_WORKING_VFORK | ||
| 1904 | /* On many hosts (e.g. Solaris 2.4), if a vforked child calls `signal', | ||
| 1905 | this sets the parent's signal handlers as well as the child's. | ||
| 1906 | So delay all interrupts whose handlers the child might munge, | ||
| 1907 | and record the current handlers so they can be restored later. */ | ||
| 1908 | sigaddset (&blocked, SIGINT ); sigaction (SIGINT , 0, &sigint_action ); | ||
| 1909 | sigaddset (&blocked, SIGQUIT); sigaction (SIGQUIT, 0, &sigquit_action); | ||
| 1910 | sigaddset (&blocked, SIGPIPE); sigaction (SIGPIPE, 0, &sigpipe_action); | ||
| 1911 | #ifdef AIX | ||
| 1912 | sigaddset (&blocked, SIGHUP ); sigaction (SIGHUP , 0, &sighup_action ); | ||
| 1913 | #endif | ||
| 1914 | #endif /* HAVE_WORKING_VFORK */ | ||
| 1915 | pthread_sigmask (SIG_BLOCK, &blocked, &procmask); | ||
| 1916 | |||
| 1917 | add_non_keyboard_read_fd (inchannel); | 1859 | add_non_keyboard_read_fd (inchannel); |
| 1918 | 1860 | ||
| 1919 | /* Until we store the proper pid, enable sigchld_handler | 1861 | /* This may signal an error. */ |
| 1920 | to recognize an unknown pid as standing for this process. | ||
| 1921 | It is very important not to let this `marker' value stay | ||
| 1922 | in the table after this function has returned; if it does | ||
| 1923 | it might cause call-process to hang and subsequent asynchronous | ||
| 1924 | processes to get their return values scrambled. */ | ||
| 1925 | XPROCESS (process)->pid = -1; | ||
| 1926 | |||
| 1927 | /* This must be called after the above line because it may signal an | ||
| 1928 | error. */ | ||
| 1929 | setup_process_coding_systems (process); | 1862 | setup_process_coding_systems (process); |
| 1930 | 1863 | ||
| 1931 | BLOCK_INPUT; | 1864 | encoded_current_dir = ENCODE_FILE (current_dir); |
| 1932 | 1865 | ||
| 1933 | { | 1866 | block_input (); |
| 1934 | /* child_setup must clobber environ on systems with true vfork. | 1867 | |
| 1935 | Protect it from permanent change. */ | 1868 | /* Block SIGCHLD until we have a chance to store the new fork's |
| 1936 | char **save_environ = environ; | 1869 | pid in its process structure. */ |
| 1937 | volatile Lisp_Object encoded_current_dir = ENCODE_FILE (current_dir); | 1870 | sigemptyset (&blocked); |
| 1871 | sigaddset (&blocked, SIGCHLD); | ||
| 1872 | pthread_sigmask (SIG_BLOCK, &blocked, 0); | ||
| 1938 | 1873 | ||
| 1939 | #ifndef WINDOWSNT | 1874 | #ifndef WINDOWSNT |
| 1940 | pid = vfork (); | 1875 | pid = vfork (); |
| 1941 | if (pid == 0) | 1876 | if (pid == 0) |
| 1942 | #endif /* not WINDOWSNT */ | 1877 | #endif /* not WINDOWSNT */ |
| 1943 | { | 1878 | { |
| 1944 | int xforkin = forkin; | 1879 | int xforkin = forkin; |
| 1945 | int xforkout = forkout; | 1880 | int xforkout = forkout; |
| 1946 | |||
| 1947 | #if 0 /* This was probably a mistake--it duplicates code later on, | ||
| 1948 | but fails to handle all the cases. */ | ||
| 1949 | /* Make sure SIGCHLD is not blocked in the child. */ | ||
| 1950 | sigsetmask (SIGEMPTYMASK); | ||
| 1951 | #endif | ||
| 1952 | 1881 | ||
| 1953 | /* Make the pty be the controlling terminal of the process. */ | 1882 | /* Make the pty be the controlling terminal of the process. */ |
| 1954 | #ifdef HAVE_PTYS | 1883 | #ifdef HAVE_PTYS |
| 1955 | /* First, disconnect its current controlling terminal. */ | 1884 | /* First, disconnect its current controlling terminal. */ |
| 1956 | #ifdef HAVE_SETSID | 1885 | /* We tried doing setsid only if pty_flag, but it caused |
| 1957 | /* We tried doing setsid only if pty_flag, but it caused | 1886 | process_set_signal to fail on SGI when using a pipe. */ |
| 1958 | process_set_signal to fail on SGI when using a pipe. */ | 1887 | setsid (); |
| 1959 | setsid (); | 1888 | /* Make the pty's terminal the controlling terminal. */ |
| 1960 | /* Make the pty's terminal the controlling terminal. */ | 1889 | if (pty_flag && xforkin >= 0) |
| 1961 | if (pty_flag && xforkin >= 0) | 1890 | { |
| 1962 | { | ||
| 1963 | #ifdef TIOCSCTTY | 1891 | #ifdef TIOCSCTTY |
| 1964 | /* We ignore the return value | 1892 | /* We ignore the return value |
| 1965 | because faith@cs.unc.edu says that is necessary on Linux. */ | 1893 | because faith@cs.unc.edu says that is necessary on Linux. */ |
| 1966 | ioctl (xforkin, TIOCSCTTY, 0); | 1894 | ioctl (xforkin, TIOCSCTTY, 0); |
| 1967 | #endif | 1895 | #endif |
| 1968 | } | 1896 | } |
| 1969 | #else /* not HAVE_SETSID */ | ||
| 1970 | #ifdef USG | ||
| 1971 | /* It's very important to call setpgrp here and no time | ||
| 1972 | afterwards. Otherwise, we lose our controlling tty which | ||
| 1973 | is set when we open the pty. */ | ||
| 1974 | setpgrp (); | ||
| 1975 | #endif /* USG */ | ||
| 1976 | #endif /* not HAVE_SETSID */ | ||
| 1977 | #if defined (LDISC1) | 1897 | #if defined (LDISC1) |
| 1978 | if (pty_flag && xforkin >= 0) | 1898 | if (pty_flag && xforkin >= 0) |
| 1979 | { | 1899 | { |
| 1980 | struct termios t; | 1900 | struct termios t; |
| 1981 | tcgetattr (xforkin, &t); | 1901 | tcgetattr (xforkin, &t); |
| 1982 | t.c_lflag = LDISC1; | 1902 | t.c_lflag = LDISC1; |
| 1983 | if (tcsetattr (xforkin, TCSANOW, &t) < 0) | 1903 | if (tcsetattr (xforkin, TCSANOW, &t) < 0) |
| 1984 | emacs_write (1, "create_process/tcsetattr LDISC1 failed\n", 39); | 1904 | emacs_write (1, "create_process/tcsetattr LDISC1 failed\n", 39); |
| 1985 | } | 1905 | } |
| 1986 | #else | 1906 | #else |
| 1987 | #if defined (NTTYDISC) && defined (TIOCSETD) | 1907 | #if defined (NTTYDISC) && defined (TIOCSETD) |
| 1988 | if (pty_flag && xforkin >= 0) | 1908 | if (pty_flag && xforkin >= 0) |
| 1989 | { | 1909 | { |
| 1990 | /* Use new line discipline. */ | 1910 | /* Use new line discipline. */ |
| 1991 | int ldisc = NTTYDISC; | 1911 | int ldisc = NTTYDISC; |
| 1992 | ioctl (xforkin, TIOCSETD, &ldisc); | 1912 | ioctl (xforkin, TIOCSETD, &ldisc); |
| 1993 | } | 1913 | } |
| 1994 | #endif | 1914 | #endif |
| 1995 | #endif | 1915 | #endif |
| 1996 | #ifdef TIOCNOTTY | 1916 | #ifdef TIOCNOTTY |
| 1997 | /* In 4.3BSD, the TIOCSPGRP bug has been fixed, and now you | 1917 | /* In 4.3BSD, the TIOCSPGRP bug has been fixed, and now you |
| 1998 | can do TIOCSPGRP only to the process's controlling tty. */ | 1918 | can do TIOCSPGRP only to the process's controlling tty. */ |
| 1999 | if (pty_flag) | 1919 | if (pty_flag) |
| 2000 | { | 1920 | { |
| 2001 | /* I wonder: would just ioctl (0, TIOCNOTTY, 0) work here? | 1921 | /* I wonder: would just ioctl (0, TIOCNOTTY, 0) work here? |
| 2002 | I can't test it since I don't have 4.3. */ | 1922 | I can't test it since I don't have 4.3. */ |
| 2003 | int j = emacs_open ("/dev/tty", O_RDWR, 0); | 1923 | int j = emacs_open ("/dev/tty", O_RDWR, 0); |
| 2004 | if (j >= 0) | 1924 | if (j >= 0) |
| 2005 | { | 1925 | { |
| 2006 | ioctl (j, TIOCNOTTY, 0); | 1926 | ioctl (j, TIOCNOTTY, 0); |
| 2007 | emacs_close (j); | 1927 | emacs_close (j); |
| 2008 | } | 1928 | } |
| 2009 | #ifndef USG | 1929 | } |
| 2010 | /* In order to get a controlling terminal on some versions | ||
| 2011 | of BSD, it is necessary to put the process in pgrp 0 | ||
| 2012 | before it opens the terminal. */ | ||
| 2013 | #ifdef HAVE_SETPGID | ||
| 2014 | setpgid (0, 0); | ||
| 2015 | #else | ||
| 2016 | setpgrp (0, 0); | ||
| 2017 | #endif | ||
| 2018 | #endif | ||
| 2019 | } | ||
| 2020 | #endif /* TIOCNOTTY */ | 1930 | #endif /* TIOCNOTTY */ |
| 2021 | 1931 | ||
| 2022 | #if !defined (DONT_REOPEN_PTY) | 1932 | #if !defined (DONT_REOPEN_PTY) |
| 2023 | /*** There is a suggestion that this ought to be a | 1933 | /*** There is a suggestion that this ought to be a |
| 2024 | conditional on TIOCSPGRP, | 1934 | conditional on TIOCSPGRP, or !defined TIOCSCTTY. |
| 2025 | or !(defined (HAVE_SETSID) && defined (TIOCSCTTY)). | ||
| 2026 | Trying the latter gave the wrong results on Debian GNU/Linux 1.1; | 1935 | Trying the latter gave the wrong results on Debian GNU/Linux 1.1; |
| 2027 | that system does seem to need this code, even though | 1936 | that system does seem to need this code, even though |
| 2028 | both HAVE_SETSID and TIOCSCTTY are defined. */ | 1937 | both TIOCSCTTY is defined. */ |
| 2029 | /* Now close the pty (if we had it open) and reopen it. | 1938 | /* Now close the pty (if we had it open) and reopen it. |
| 2030 | This makes the pty the controlling terminal of the subprocess. */ | 1939 | This makes the pty the controlling terminal of the subprocess. */ |
| 2031 | if (pty_flag) | 1940 | if (pty_flag) |
| 2032 | { | 1941 | { |
| 2033 | 1942 | ||
| 2034 | /* I wonder if emacs_close (emacs_open (pty_name, ...)) | 1943 | /* I wonder if emacs_close (emacs_open (pty_name, ...)) |
| 2035 | would work? */ | 1944 | would work? */ |
| 2036 | if (xforkin >= 0) | 1945 | if (xforkin >= 0) |
| 2037 | emacs_close (xforkin); | 1946 | emacs_close (xforkin); |
| 2038 | xforkout = xforkin = emacs_open (pty_name, O_RDWR, 0); | 1947 | xforkout = xforkin = emacs_open (pty_name, O_RDWR, 0); |
| 2039 | 1948 | ||
| 2040 | if (xforkin < 0) | 1949 | if (xforkin < 0) |
| 2041 | { | 1950 | { |
| 2042 | emacs_write (1, "Couldn't open the pty terminal ", 31); | 1951 | emacs_write (1, "Couldn't open the pty terminal ", 31); |
| 2043 | emacs_write (1, pty_name, strlen (pty_name)); | 1952 | emacs_write (1, pty_name, strlen (pty_name)); |
| 2044 | emacs_write (1, "\n", 1); | 1953 | emacs_write (1, "\n", 1); |
| 2045 | _exit (1); | 1954 | _exit (1); |
| 2046 | } | 1955 | } |
| 2047 | 1956 | ||
| 2048 | } | 1957 | } |
| 2049 | #endif /* not DONT_REOPEN_PTY */ | 1958 | #endif /* not DONT_REOPEN_PTY */ |
| 2050 | 1959 | ||
| 2051 | #ifdef SETUP_SLAVE_PTY | 1960 | #ifdef SETUP_SLAVE_PTY |
| 2052 | if (pty_flag) | 1961 | if (pty_flag) |
| 2053 | { | 1962 | { |
| 2054 | SETUP_SLAVE_PTY; | 1963 | SETUP_SLAVE_PTY; |
| 2055 | } | 1964 | } |
| 2056 | #endif /* SETUP_SLAVE_PTY */ | 1965 | #endif /* SETUP_SLAVE_PTY */ |
| 2057 | #ifdef AIX | 1966 | #ifdef AIX |
| 2058 | /* On AIX, we've disabled SIGHUP above once we start a child on a pty. | 1967 | /* On AIX, we've disabled SIGHUP above once we start a child on a pty. |
| 2059 | Now reenable it in the child, so it will die when we want it to. */ | 1968 | Now reenable it in the child, so it will die when we want it to. */ |
| 2060 | if (pty_flag) | 1969 | if (pty_flag) |
| 2061 | signal (SIGHUP, SIG_DFL); | 1970 | signal (SIGHUP, SIG_DFL); |
| 2062 | #endif | 1971 | #endif |
| 2063 | #endif /* HAVE_PTYS */ | 1972 | #endif /* HAVE_PTYS */ |
| 2064 | 1973 | ||
| 2065 | signal (SIGINT, SIG_DFL); | 1974 | signal (SIGINT, SIG_DFL); |
| 2066 | signal (SIGQUIT, SIG_DFL); | 1975 | signal (SIGQUIT, SIG_DFL); |
| 2067 | /* GConf causes us to ignore SIGPIPE, make sure it is restored | 1976 | |
| 2068 | in the child. */ | 1977 | /* Emacs ignores SIGPIPE, but the child should not. */ |
| 2069 | signal (SIGPIPE, SIG_DFL); | 1978 | signal (SIGPIPE, SIG_DFL); |
| 2070 | 1979 | ||
| 2071 | /* Stop blocking signals in the child. */ | 1980 | /* Stop blocking signals in the child. */ |
| 2072 | pthread_sigmask (SIG_SETMASK, &procmask, 0); | 1981 | pthread_sigmask (SIG_SETMASK, &empty_mask, 0); |
| 2073 | 1982 | ||
| 2074 | if (pty_flag) | 1983 | if (pty_flag) |
| 2075 | child_setup_tty (xforkout); | 1984 | child_setup_tty (xforkout); |
| 2076 | #ifdef WINDOWSNT | 1985 | #ifdef WINDOWSNT |
| 2077 | pid = child_setup (xforkin, xforkout, xforkout, | 1986 | pid = child_setup (xforkin, xforkout, xforkout, |
| 2078 | new_argv, 1, encoded_current_dir); | 1987 | new_argv, 1, encoded_current_dir); |
| 2079 | #else /* not WINDOWSNT */ | 1988 | #else /* not WINDOWSNT */ |
| 2080 | #ifdef FD_CLOEXEC | 1989 | emacs_close (wait_child_setup[0]); |
| 2081 | emacs_close (wait_child_setup[0]); | 1990 | child_setup (xforkin, xforkout, xforkout, |
| 2082 | #endif | 1991 | new_argv, 1, encoded_current_dir); |
| 2083 | child_setup (xforkin, xforkout, xforkout, | ||
| 2084 | new_argv, 1, encoded_current_dir); | ||
| 2085 | #endif /* not WINDOWSNT */ | 1992 | #endif /* not WINDOWSNT */ |
| 2086 | } | 1993 | } |
| 2087 | environ = save_environ; | 1994 | |
| 2088 | } | 1995 | /* Back in the parent process. */ |
| 2089 | 1996 | ||
| 2090 | UNBLOCK_INPUT; | 1997 | XPROCESS (process)->pid = pid; |
| 1998 | if (0 <= pid) | ||
| 1999 | XPROCESS (process)->alive = 1; | ||
| 2000 | |||
| 2001 | /* Stop blocking signals in the parent. */ | ||
| 2002 | pthread_sigmask (SIG_SETMASK, &empty_mask, 0); | ||
| 2003 | unblock_input (); | ||
| 2091 | 2004 | ||
| 2092 | /* This runs in the Emacs process. */ | ||
| 2093 | if (pid < 0) | 2005 | if (pid < 0) |
| 2094 | { | 2006 | { |
| 2095 | if (forkin >= 0) | 2007 | if (forkin >= 0) |
| @@ -2100,7 +2012,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 2100 | else | 2012 | else |
| 2101 | { | 2013 | { |
| 2102 | /* vfork succeeded. */ | 2014 | /* vfork succeeded. */ |
| 2103 | XPROCESS (process)->pid = pid; | ||
| 2104 | 2015 | ||
| 2105 | #ifdef WINDOWSNT | 2016 | #ifdef WINDOWSNT |
| 2106 | register_child (pid, inchannel); | 2017 | register_child (pid, inchannel); |
| @@ -2126,18 +2037,13 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 2126 | if (forkin != forkout && forkout >= 0) | 2037 | if (forkin != forkout && forkout >= 0) |
| 2127 | emacs_close (forkout); | 2038 | emacs_close (forkout); |
| 2128 | 2039 | ||
| 2129 | #ifdef HAVE_PTYS | 2040 | pset_tty_name (XPROCESS (process), lisp_pty_name); |
| 2130 | if (pty_flag) | ||
| 2131 | pset_tty_name (XPROCESS (process), build_string (pty_name)); | ||
| 2132 | else | ||
| 2133 | #endif | ||
| 2134 | pset_tty_name (XPROCESS (process), Qnil); | ||
| 2135 | 2041 | ||
| 2136 | #if !defined (WINDOWSNT) && defined (FD_CLOEXEC) | 2042 | #ifndef WINDOWSNT |
| 2137 | /* Wait for child_setup to complete in case that vfork is | 2043 | /* Wait for child_setup to complete in case that vfork is |
| 2138 | actually defined as fork. The descriptor wait_child_setup[1] | 2044 | actually defined as fork. The descriptor wait_child_setup[1] |
| 2139 | of a pipe is closed at the child side either by close-on-exec | 2045 | of a pipe is closed at the child side either by close-on-exec |
| 2140 | on successful execvp or the _exit call in child_setup. */ | 2046 | on successful execve or the _exit call in child_setup. */ |
| 2141 | { | 2047 | { |
| 2142 | char dummy; | 2048 | char dummy; |
| 2143 | 2049 | ||
| @@ -2148,20 +2054,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 2148 | #endif | 2054 | #endif |
| 2149 | } | 2055 | } |
| 2150 | 2056 | ||
| 2151 | /* Restore the signal state whether vfork succeeded or not. | ||
| 2152 | (We will signal an error, below, if it failed.) */ | ||
| 2153 | #ifdef HAVE_WORKING_VFORK | ||
| 2154 | /* Restore the parent's signal handlers. */ | ||
| 2155 | sigaction (SIGINT, &sigint_action, 0); | ||
| 2156 | sigaction (SIGQUIT, &sigquit_action, 0); | ||
| 2157 | sigaction (SIGPIPE, &sigpipe_action, 0); | ||
| 2158 | #ifdef AIX | ||
| 2159 | sigaction (SIGHUP, &sighup_action, 0); | ||
| 2160 | #endif | ||
| 2161 | #endif /* HAVE_WORKING_VFORK */ | ||
| 2162 | /* Stop blocking signals in the parent. */ | ||
| 2163 | pthread_sigmask (SIG_SETMASK, &procmask, 0); | ||
| 2164 | |||
| 2165 | /* Now generate the error if vfork failed. */ | 2057 | /* Now generate the error if vfork failed. */ |
| 2166 | if (pid < 0) | 2058 | if (pid < 0) |
| 2167 | report_file_error ("Doing vfork", Qnil); | 2059 | report_file_error ("Doing vfork", Qnil); |
| @@ -2184,13 +2076,9 @@ create_pty (Lisp_Object process) | |||
| 2184 | #if ! defined (USG) || defined (USG_SUBTTY_WORKS) | 2076 | #if ! defined (USG) || defined (USG_SUBTTY_WORKS) |
| 2185 | /* On most USG systems it does not work to open the pty's tty here, | 2077 | /* On most USG systems it does not work to open the pty's tty here, |
| 2186 | then close it and reopen it in the child. */ | 2078 | then close it and reopen it in the child. */ |
| 2187 | #ifdef O_NOCTTY | ||
| 2188 | /* Don't let this terminal become our controlling terminal | 2079 | /* Don't let this terminal become our controlling terminal |
| 2189 | (in case we don't have one). */ | 2080 | (in case we don't have one). */ |
| 2190 | int forkout = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); | 2081 | int forkout = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); |
| 2191 | #else | ||
| 2192 | int forkout = emacs_open (pty_name, O_RDWR, 0); | ||
| 2193 | #endif | ||
| 2194 | if (forkout < 0) | 2082 | if (forkout < 0) |
| 2195 | report_file_error ("Opening pty", Qnil); | 2083 | report_file_error ("Opening pty", Qnil); |
| 2196 | #if defined (DONT_REOPEN_PTY) | 2084 | #if defined (DONT_REOPEN_PTY) |
| @@ -2204,15 +2092,8 @@ create_pty (Lisp_Object process) | |||
| 2204 | } | 2092 | } |
| 2205 | #endif /* HAVE_PTYS */ | 2093 | #endif /* HAVE_PTYS */ |
| 2206 | 2094 | ||
| 2207 | #ifdef O_NONBLOCK | ||
| 2208 | fcntl (inchannel, F_SETFL, O_NONBLOCK); | 2095 | fcntl (inchannel, F_SETFL, O_NONBLOCK); |
| 2209 | fcntl (outchannel, F_SETFL, O_NONBLOCK); | 2096 | fcntl (outchannel, F_SETFL, O_NONBLOCK); |
| 2210 | #else | ||
| 2211 | #ifdef O_NDELAY | ||
| 2212 | fcntl (inchannel, F_SETFL, O_NDELAY); | ||
| 2213 | fcntl (outchannel, F_SETFL, O_NDELAY); | ||
| 2214 | #endif | ||
| 2215 | #endif | ||
| 2216 | 2097 | ||
| 2217 | /* Record this as an active process, with its channels. | 2098 | /* Record this as an active process, with its channels. |
| 2218 | As a result, child_setup will close Emacs's side of the pipes. */ | 2099 | As a result, child_setup will close Emacs's side of the pipes. */ |
| @@ -2735,7 +2616,7 @@ static Lisp_Object | |||
| 2735 | make_serial_process_unwind (Lisp_Object proc) | 2616 | make_serial_process_unwind (Lisp_Object proc) |
| 2736 | { | 2617 | { |
| 2737 | if (!PROCESSP (proc)) | 2618 | if (!PROCESSP (proc)) |
| 2738 | abort (); | 2619 | emacs_abort (); |
| 2739 | remove_process (proc); | 2620 | remove_process (proc); |
| 2740 | return Qnil; | 2621 | return Qnil; |
| 2741 | } | 2622 | } |
| @@ -3162,13 +3043,9 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3162 | { | 3043 | { |
| 3163 | /* Don't support network sockets when non-blocking mode is | 3044 | /* Don't support network sockets when non-blocking mode is |
| 3164 | not available, since a blocked Emacs is not useful. */ | 3045 | not available, since a blocked Emacs is not useful. */ |
| 3165 | #if !defined (O_NONBLOCK) && !defined (O_NDELAY) | ||
| 3166 | error ("Network servers not supported"); | ||
| 3167 | #else | ||
| 3168 | is_server = 1; | 3046 | is_server = 1; |
| 3169 | if (TYPE_RANGED_INTEGERP (int, tem)) | 3047 | if (TYPE_RANGED_INTEGERP (int, tem)) |
| 3170 | backlog = XINT (tem); | 3048 | backlog = XINT (tem); |
| 3171 | #endif | ||
| 3172 | } | 3049 | } |
| 3173 | 3050 | ||
| 3174 | /* Make QCaddress an alias for :local (server) or :remote (client). */ | 3051 | /* Make QCaddress an alias for :local (server) or :remote (client). */ |
| @@ -3428,11 +3305,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3428 | #ifdef NON_BLOCKING_CONNECT | 3305 | #ifdef NON_BLOCKING_CONNECT |
| 3429 | if (is_non_blocking_client) | 3306 | if (is_non_blocking_client) |
| 3430 | { | 3307 | { |
| 3431 | #ifdef O_NONBLOCK | ||
| 3432 | ret = fcntl (s, F_SETFL, O_NONBLOCK); | 3308 | ret = fcntl (s, F_SETFL, O_NONBLOCK); |
| 3433 | #else | ||
| 3434 | ret = fcntl (s, F_SETFL, O_NDELAY); | ||
| 3435 | #endif | ||
| 3436 | if (ret < 0) | 3309 | if (ret < 0) |
| 3437 | { | 3310 | { |
| 3438 | xerrno = errno; | 3311 | xerrno = errno; |
| @@ -3569,7 +3442,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3569 | if (socktype == SOCK_DGRAM) | 3442 | if (socktype == SOCK_DGRAM) |
| 3570 | { | 3443 | { |
| 3571 | if (datagram_address[s].sa) | 3444 | if (datagram_address[s].sa) |
| 3572 | abort (); | 3445 | emacs_abort (); |
| 3573 | datagram_address[s].sa = xmalloc (lres->ai_addrlen); | 3446 | datagram_address[s].sa = xmalloc (lres->ai_addrlen); |
| 3574 | datagram_address[s].len = lres->ai_addrlen; | 3447 | datagram_address[s].len = lres->ai_addrlen; |
| 3575 | if (is_server) | 3448 | if (is_server) |
| @@ -3608,9 +3481,9 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3608 | #ifdef HAVE_GETADDRINFO | 3481 | #ifdef HAVE_GETADDRINFO |
| 3609 | if (res != &ai) | 3482 | if (res != &ai) |
| 3610 | { | 3483 | { |
| 3611 | BLOCK_INPUT; | 3484 | block_input (); |
| 3612 | freeaddrinfo (res); | 3485 | freeaddrinfo (res); |
| 3613 | UNBLOCK_INPUT; | 3486 | unblock_input (); |
| 3614 | } | 3487 | } |
| 3615 | #endif | 3488 | #endif |
| 3616 | 3489 | ||
| @@ -3645,13 +3518,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3645 | 3518 | ||
| 3646 | chan_process[inch] = proc; | 3519 | chan_process[inch] = proc; |
| 3647 | 3520 | ||
| 3648 | #ifdef O_NONBLOCK | ||
| 3649 | fcntl (inch, F_SETFL, O_NONBLOCK); | 3521 | fcntl (inch, F_SETFL, O_NONBLOCK); |
| 3650 | #else | ||
| 3651 | #ifdef O_NDELAY | ||
| 3652 | fcntl (inch, F_SETFL, O_NDELAY); | ||
| 3653 | #endif | ||
| 3654 | #endif | ||
| 3655 | 3522 | ||
| 3656 | p = XPROCESS (proc); | 3523 | p = XPROCESS (proc); |
| 3657 | 3524 | ||
| @@ -4377,13 +4244,7 @@ server_accept_connection (Lisp_Object server, int channel) | |||
| 4377 | 4244 | ||
| 4378 | chan_process[s] = proc; | 4245 | chan_process[s] = proc; |
| 4379 | 4246 | ||
| 4380 | #ifdef O_NONBLOCK | ||
| 4381 | fcntl (s, F_SETFL, O_NONBLOCK); | 4247 | fcntl (s, F_SETFL, O_NONBLOCK); |
| 4382 | #else | ||
| 4383 | #ifdef O_NDELAY | ||
| 4384 | fcntl (s, F_SETFL, O_NDELAY); | ||
| 4385 | #endif | ||
| 4386 | #endif | ||
| 4387 | 4248 | ||
| 4388 | p = XPROCESS (proc); | 4249 | p = XPROCESS (proc); |
| 4389 | 4250 | ||
| @@ -4482,7 +4343,7 @@ wait_reading_process_output_1 (void) | |||
| 4482 | -1 meaning caller will actually read the input, so don't throw to | 4343 | -1 meaning caller will actually read the input, so don't throw to |
| 4483 | the quit handler, or | 4344 | the quit handler, or |
| 4484 | 4345 | ||
| 4485 | DO_DISPLAY != 0 means redisplay should be done to show subprocess | 4346 | DO_DISPLAY means redisplay should be done to show subprocess |
| 4486 | output that arrives. | 4347 | output that arrives. |
| 4487 | 4348 | ||
| 4488 | If WAIT_FOR_CELL is a cons cell, wait until its car is non-nil | 4349 | If WAIT_FOR_CELL is a cons cell, wait until its car is non-nil |
| @@ -4502,7 +4363,7 @@ wait_reading_process_output_1 (void) | |||
| 4502 | 4363 | ||
| 4503 | int | 4364 | int |
| 4504 | wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | 4365 | wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, |
| 4505 | int do_display, | 4366 | bool do_display, |
| 4506 | Lisp_Object wait_for_cell, | 4367 | Lisp_Object wait_for_cell, |
| 4507 | struct Lisp_Process *wait_proc, int just_wait_proc) | 4368 | struct Lisp_Process *wait_proc, int just_wait_proc) |
| 4508 | { | 4369 | { |
| @@ -4563,10 +4424,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4563 | Otherwise, do pending quit if requested. */ | 4424 | Otherwise, do pending quit if requested. */ |
| 4564 | if (read_kbd >= 0) | 4425 | if (read_kbd >= 0) |
| 4565 | QUIT; | 4426 | QUIT; |
| 4566 | #ifdef SYNC_INPUT | 4427 | else if (pending_signals) |
| 4567 | else | ||
| 4568 | process_pending_signals (); | 4428 | process_pending_signals (); |
| 4569 | #endif | ||
| 4570 | 4429 | ||
| 4571 | /* Exit now if the cell we're waiting for became non-nil. */ | 4430 | /* Exit now if the cell we're waiting for became non-nil. */ |
| 4572 | if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) | 4431 | if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) |
| @@ -4605,7 +4464,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4605 | 4464 | ||
| 4606 | do | 4465 | do |
| 4607 | { | 4466 | { |
| 4608 | int old_timers_run = timers_run; | 4467 | unsigned old_timers_run = timers_run; |
| 4609 | struct buffer *old_buffer = current_buffer; | 4468 | struct buffer *old_buffer = current_buffer; |
| 4610 | Lisp_Object old_window = selected_window; | 4469 | Lisp_Object old_window = selected_window; |
| 4611 | 4470 | ||
| @@ -4641,7 +4500,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4641 | if (EMACS_TIME_LT (timer_delay, timeout)) | 4500 | if (EMACS_TIME_LT (timer_delay, timeout)) |
| 4642 | { | 4501 | { |
| 4643 | timeout = timer_delay; | 4502 | timeout = timer_delay; |
| 4644 | timeout_reduced_for_timers = 1; | 4503 | timeout_reduced_for_timers = 1; |
| 4645 | } | 4504 | } |
| 4646 | } | 4505 | } |
| 4647 | else | 4506 | else |
| @@ -4722,14 +4581,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4722 | total_nread += nread; | 4581 | total_nread += nread; |
| 4723 | got_some_input = 1; | 4582 | got_some_input = 1; |
| 4724 | } | 4583 | } |
| 4725 | #ifdef EIO | 4584 | else if (nread == -1 && (errno == EIO || errno == EAGAIN)) |
| 4726 | else if (nread == -1 && EIO == errno) | ||
| 4727 | break; | 4585 | break; |
| 4728 | #endif | ||
| 4729 | #ifdef EAGAIN | ||
| 4730 | else if (nread == -1 && EAGAIN == errno) | ||
| 4731 | break; | ||
| 4732 | #endif | ||
| 4733 | #ifdef EWOULDBLOCK | 4586 | #ifdef EWOULDBLOCK |
| 4734 | else if (nread == -1 && EWOULDBLOCK == errno) | 4587 | else if (nread == -1 && EWOULDBLOCK == errno) |
| 4735 | break; | 4588 | break; |
| @@ -4918,10 +4771,10 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4918 | yielding EBADF here or at select() call above. | 4771 | yielding EBADF here or at select() call above. |
| 4919 | So, SIGHUP is ignored (see def of PTY_TTY_NAME_SPRINTF | 4772 | So, SIGHUP is ignored (see def of PTY_TTY_NAME_SPRINTF |
| 4920 | in m/ibmrt-aix.h), and here we just ignore the select error. | 4773 | in m/ibmrt-aix.h), and here we just ignore the select error. |
| 4921 | Cleanup occurs c/o status_notify after SIGCLD. */ | 4774 | Cleanup occurs c/o status_notify after SIGCHLD. */ |
| 4922 | no_avail = 1; /* Cannot depend on values returned */ | 4775 | no_avail = 1; /* Cannot depend on values returned */ |
| 4923 | #else | 4776 | #else |
| 4924 | abort (); | 4777 | emacs_abort (); |
| 4925 | #endif | 4778 | #endif |
| 4926 | } | 4779 | } |
| 4927 | else | 4780 | else |
| @@ -4934,28 +4787,13 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4934 | check_write = 0; | 4787 | check_write = 0; |
| 4935 | } | 4788 | } |
| 4936 | 4789 | ||
| 4937 | #if 0 /* When polling is used, interrupt_input is 0, | ||
| 4938 | so get_input_pending should read the input. | ||
| 4939 | So this should not be needed. */ | ||
| 4940 | /* If we are using polling for input, | ||
| 4941 | and we see input available, make it get read now. | ||
| 4942 | Otherwise it might not actually get read for a second. | ||
| 4943 | And on hpux, since we turn off polling in wait_reading_process_output, | ||
| 4944 | it might never get read at all if we don't spend much time | ||
| 4945 | outside of wait_reading_process_output. */ | ||
| 4946 | if (read_kbd && interrupt_input | ||
| 4947 | && keyboard_bit_set (&Available) | ||
| 4948 | && input_polling_used ()) | ||
| 4949 | kill (getpid (), SIGALRM); | ||
| 4950 | #endif | ||
| 4951 | |||
| 4952 | /* Check for keyboard input */ | 4790 | /* Check for keyboard input */ |
| 4953 | /* If there is any, return immediately | 4791 | /* If there is any, return immediately |
| 4954 | to give it higher priority than subprocesses */ | 4792 | to give it higher priority than subprocesses */ |
| 4955 | 4793 | ||
| 4956 | if (read_kbd != 0) | 4794 | if (read_kbd != 0) |
| 4957 | { | 4795 | { |
| 4958 | int old_timers_run = timers_run; | 4796 | unsigned old_timers_run = timers_run; |
| 4959 | struct buffer *old_buffer = current_buffer; | 4797 | struct buffer *old_buffer = current_buffer; |
| 4960 | Lisp_Object old_window = selected_window; | 4798 | Lisp_Object old_window = selected_window; |
| 4961 | int leave = 0; | 4799 | int leave = 0; |
| @@ -5004,7 +4842,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 5004 | if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) | 4842 | if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) |
| 5005 | break; | 4843 | break; |
| 5006 | 4844 | ||
| 5007 | #ifdef SIGIO | 4845 | #ifdef USABLE_SIGIO |
| 5008 | /* If we think we have keyboard input waiting, but didn't get SIGIO, | 4846 | /* If we think we have keyboard input waiting, but didn't get SIGIO, |
| 5009 | go read it. This can happen with X on BSD after logging out. | 4847 | go read it. This can happen with X on BSD after logging out. |
| 5010 | In that case, there really is no input and no SIGIO, | 4848 | In that case, there really is no input and no SIGIO, |
| @@ -5012,7 +4850,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 5012 | 4850 | ||
| 5013 | if (read_kbd && interrupt_input | 4851 | if (read_kbd && interrupt_input |
| 5014 | && keyboard_bit_set (&Available) && ! noninteractive) | 4852 | && keyboard_bit_set (&Available) && ! noninteractive) |
| 5015 | kill (getpid (), SIGIO); | 4853 | handle_input_available_signal (SIGIO); |
| 5016 | #endif | 4854 | #endif |
| 5017 | 4855 | ||
| 5018 | if (! wait_proc) | 4856 | if (! wait_proc) |
| @@ -5085,23 +4923,17 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 5085 | else if (nread == -1 && errno == EWOULDBLOCK) | 4923 | else if (nread == -1 && errno == EWOULDBLOCK) |
| 5086 | ; | 4924 | ; |
| 5087 | #endif | 4925 | #endif |
| 5088 | /* ISC 4.1 defines both EWOULDBLOCK and O_NONBLOCK, | ||
| 5089 | and Emacs uses O_NONBLOCK, so what we get is EAGAIN. */ | ||
| 5090 | #ifdef O_NONBLOCK | ||
| 5091 | else if (nread == -1 && errno == EAGAIN) | ||
| 5092 | ; | ||
| 5093 | #else | ||
| 5094 | #ifdef O_NDELAY | ||
| 5095 | else if (nread == -1 && errno == EAGAIN) | 4926 | else if (nread == -1 && errno == EAGAIN) |
| 5096 | ; | 4927 | ; |
| 4928 | #ifdef WINDOWSNT | ||
| 4929 | /* FIXME: Is this special case still needed? */ | ||
| 5097 | /* Note that we cannot distinguish between no input | 4930 | /* Note that we cannot distinguish between no input |
| 5098 | available now and a closed pipe. | 4931 | available now and a closed pipe. |
| 5099 | With luck, a closed pipe will be accompanied by | 4932 | With luck, a closed pipe will be accompanied by |
| 5100 | subprocess termination and SIGCHLD. */ | 4933 | subprocess termination and SIGCHLD. */ |
| 5101 | else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc)) | 4934 | else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc)) |
| 5102 | ; | 4935 | ; |
| 5103 | #endif /* O_NDELAY */ | 4936 | #endif |
| 5104 | #endif /* O_NONBLOCK */ | ||
| 5105 | #ifdef HAVE_PTYS | 4937 | #ifdef HAVE_PTYS |
| 5106 | /* On some OSs with ptys, when the process on one end of | 4938 | /* On some OSs with ptys, when the process on one end of |
| 5107 | a pty exits, the other end gets an error reading with | 4939 | a pty exits, the other end gets an error reading with |
| @@ -5124,22 +4956,20 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 5124 | 4956 | ||
| 5125 | if (p->pid == -2) | 4957 | if (p->pid == -2) |
| 5126 | { | 4958 | { |
| 5127 | /* If the EIO occurs on a pty, sigchld_handler's | 4959 | /* If the EIO occurs on a pty, the SIGCHLD handler's |
| 5128 | waitpid() will not find the process object to | 4960 | waitpid call will not find the process object to |
| 5129 | delete. Do it here. */ | 4961 | delete. Do it here. */ |
| 5130 | p->tick = ++process_tick; | 4962 | p->tick = ++process_tick; |
| 5131 | pset_status (p, Qfailed); | 4963 | pset_status (p, Qfailed); |
| 5132 | } | 4964 | } |
| 5133 | else | 4965 | else |
| 5134 | kill (getpid (), SIGCHLD); | 4966 | handle_child_signal (SIGCHLD); |
| 5135 | } | 4967 | } |
| 5136 | #endif /* HAVE_PTYS */ | 4968 | #endif /* HAVE_PTYS */ |
| 5137 | /* If we can detect process termination, don't consider the | 4969 | /* If we can detect process termination, don't consider the |
| 5138 | process gone just because its pipe is closed. */ | 4970 | process gone just because its pipe is closed. */ |
| 5139 | #ifdef SIGCHLD | ||
| 5140 | else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc)) | 4971 | else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc)) |
| 5141 | ; | 4972 | ; |
| 5142 | #endif | ||
| 5143 | else | 4973 | else |
| 5144 | { | 4974 | { |
| 5145 | /* Preserve status of processes already terminated. */ | 4975 | /* Preserve status of processes already terminated. */ |
| @@ -5460,7 +5290,7 @@ read_process_output (Lisp_Object proc, register int channel) | |||
| 5460 | } | 5290 | } |
| 5461 | 5291 | ||
| 5462 | /* If no filter, write into buffer if it isn't dead. */ | 5292 | /* If no filter, write into buffer if it isn't dead. */ |
| 5463 | else if (!NILP (p->buffer) && !NILP (BVAR (XBUFFER (p->buffer), name))) | 5293 | else if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer))) |
| 5464 | { | 5294 | { |
| 5465 | Lisp_Object old_read_only; | 5295 | Lisp_Object old_read_only; |
| 5466 | ptrdiff_t old_begv, old_zv; | 5296 | ptrdiff_t old_begv, old_zv; |
| @@ -5582,21 +5412,6 @@ read_process_output (Lisp_Object proc, register int channel) | |||
| 5582 | 5412 | ||
| 5583 | /* Sending data to subprocess */ | 5413 | /* Sending data to subprocess */ |
| 5584 | 5414 | ||
| 5585 | static jmp_buf send_process_frame; | ||
| 5586 | static Lisp_Object process_sent_to; | ||
| 5587 | |||
| 5588 | #ifndef FORWARD_SIGNAL_TO_MAIN_THREAD | ||
| 5589 | static _Noreturn void send_process_trap (int); | ||
| 5590 | #endif | ||
| 5591 | |||
| 5592 | static void | ||
| 5593 | send_process_trap (int ignore) | ||
| 5594 | { | ||
| 5595 | SIGNAL_THREAD_CHECK (SIGPIPE); | ||
| 5596 | sigunblock (sigmask (SIGPIPE)); | ||
| 5597 | _longjmp (send_process_frame, 1); | ||
| 5598 | } | ||
| 5599 | |||
| 5600 | /* In send_process, when a write fails temporarily, | 5415 | /* In send_process, when a write fails temporarily, |
| 5601 | wait_reading_process_output is called. It may execute user code, | 5416 | wait_reading_process_output is called. It may execute user code, |
| 5602 | e.g. timers, that attempts to write new data to the same process. | 5417 | e.g. timers, that attempts to write new data to the same process. |
| @@ -5680,14 +5495,12 @@ write_queue_pop (struct Lisp_Process *p, Lisp_Object *obj, | |||
| 5680 | This function can evaluate Lisp code and can garbage collect. */ | 5495 | This function can evaluate Lisp code and can garbage collect. */ |
| 5681 | 5496 | ||
| 5682 | static void | 5497 | static void |
| 5683 | send_process (volatile Lisp_Object proc, const char *volatile buf, | 5498 | send_process (Lisp_Object proc, const char *buf, ptrdiff_t len, |
| 5684 | volatile ptrdiff_t len, volatile Lisp_Object object) | 5499 | Lisp_Object object) |
| 5685 | { | 5500 | { |
| 5686 | /* Use volatile to protect variables from being clobbered by longjmp. */ | ||
| 5687 | struct Lisp_Process *p = XPROCESS (proc); | 5501 | struct Lisp_Process *p = XPROCESS (proc); |
| 5688 | ssize_t rv; | 5502 | ssize_t rv; |
| 5689 | struct coding_system *coding; | 5503 | struct coding_system *coding; |
| 5690 | void (*volatile old_sigpipe) (int); | ||
| 5691 | 5504 | ||
| 5692 | if (p->raw_status_new) | 5505 | if (p->raw_status_new) |
| 5693 | update_status (p); | 5506 | update_status (p); |
| @@ -5781,156 +5594,123 @@ send_process (volatile Lisp_Object proc, const char *volatile buf, | |||
| 5781 | buf = SSDATA (object); | 5594 | buf = SSDATA (object); |
| 5782 | } | 5595 | } |
| 5783 | 5596 | ||
| 5784 | if (pty_max_bytes == 0) | 5597 | /* If there is already data in the write_queue, put the new data |
| 5785 | { | 5598 | in the back of queue. Otherwise, ignore it. */ |
| 5786 | #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON) | 5599 | if (!NILP (p->write_queue)) |
| 5787 | pty_max_bytes = fpathconf (p->outfd, _PC_MAX_CANON); | 5600 | write_queue_push (p, object, buf, len, 0); |
| 5788 | if (pty_max_bytes < 0) | ||
| 5789 | pty_max_bytes = 250; | ||
| 5790 | #else | ||
| 5791 | pty_max_bytes = 250; | ||
| 5792 | #endif | ||
| 5793 | /* Deduct one, to leave space for the eof. */ | ||
| 5794 | pty_max_bytes--; | ||
| 5795 | } | ||
| 5796 | 5601 | ||
| 5797 | /* 2000-09-21: Emacs 20.7, sparc-sun-solaris-2.6, GCC 2.95.2, | 5602 | do /* while !NILP (p->write_queue) */ |
| 5798 | CFLAGS="-g -O": The value of the parameter `proc' is clobbered | ||
| 5799 | when returning with longjmp despite being declared volatile. */ | ||
| 5800 | if (!_setjmp (send_process_frame)) | ||
| 5801 | { | 5603 | { |
| 5802 | p = XPROCESS (proc); /* Repair any setjmp clobbering. */ | 5604 | ptrdiff_t cur_len = -1; |
| 5803 | process_sent_to = proc; | 5605 | const char *cur_buf; |
| 5804 | 5606 | Lisp_Object cur_object; | |
| 5805 | /* If there is already data in the write_queue, put the new data | ||
| 5806 | in the back of queue. Otherwise, ignore it. */ | ||
| 5807 | if (!NILP (p->write_queue)) | ||
| 5808 | write_queue_push (p, object, buf, len, 0); | ||
| 5809 | 5607 | ||
| 5810 | do /* while !NILP (p->write_queue) */ | 5608 | /* If write_queue is empty, ignore it. */ |
| 5609 | if (!write_queue_pop (p, &cur_object, &cur_buf, &cur_len)) | ||
| 5811 | { | 5610 | { |
| 5812 | ptrdiff_t cur_len = -1; | 5611 | cur_len = len; |
| 5813 | const char *cur_buf; | 5612 | cur_buf = buf; |
| 5814 | Lisp_Object cur_object; | 5613 | cur_object = object; |
| 5614 | } | ||
| 5815 | 5615 | ||
| 5816 | /* If write_queue is empty, ignore it. */ | 5616 | while (cur_len > 0) |
| 5817 | if (!write_queue_pop (p, &cur_object, &cur_buf, &cur_len)) | 5617 | { |
| 5618 | /* Send this batch, using one or more write calls. */ | ||
| 5619 | ptrdiff_t written = 0; | ||
| 5620 | int outfd = p->outfd; | ||
| 5621 | #ifdef DATAGRAM_SOCKETS | ||
| 5622 | if (DATAGRAM_CHAN_P (outfd)) | ||
| 5818 | { | 5623 | { |
| 5819 | cur_len = len; | 5624 | rv = sendto (outfd, cur_buf, cur_len, |
| 5820 | cur_buf = buf; | 5625 | 0, datagram_address[outfd].sa, |
| 5821 | cur_object = object; | 5626 | datagram_address[outfd].len); |
| 5627 | if (0 <= rv) | ||
| 5628 | written = rv; | ||
| 5629 | else if (errno == EMSGSIZE) | ||
| 5630 | report_file_error ("sending datagram", Fcons (proc, Qnil)); | ||
| 5822 | } | 5631 | } |
| 5823 | 5632 | else | |
| 5824 | while (cur_len > 0) | ||
| 5825 | { | ||
| 5826 | /* Send this batch, using one or more write calls. */ | ||
| 5827 | ptrdiff_t written = 0; | ||
| 5828 | int outfd = p->outfd; | ||
| 5829 | old_sigpipe = (void (*) (int)) signal (SIGPIPE, send_process_trap); | ||
| 5830 | #ifdef DATAGRAM_SOCKETS | ||
| 5831 | if (DATAGRAM_CHAN_P (outfd)) | ||
| 5832 | { | ||
| 5833 | rv = sendto (outfd, cur_buf, cur_len, | ||
| 5834 | 0, datagram_address[outfd].sa, | ||
| 5835 | datagram_address[outfd].len); | ||
| 5836 | if (0 <= rv) | ||
| 5837 | written = rv; | ||
| 5838 | else if (errno == EMSGSIZE) | ||
| 5839 | { | ||
| 5840 | signal (SIGPIPE, old_sigpipe); | ||
| 5841 | report_file_error ("sending datagram", | ||
| 5842 | Fcons (proc, Qnil)); | ||
| 5843 | } | ||
| 5844 | } | ||
| 5845 | else | ||
| 5846 | #endif | 5633 | #endif |
| 5847 | { | 5634 | { |
| 5848 | #ifdef HAVE_GNUTLS | 5635 | #ifdef HAVE_GNUTLS |
| 5849 | if (p->gnutls_p) | 5636 | if (p->gnutls_p) |
| 5850 | written = emacs_gnutls_write (p, cur_buf, cur_len); | 5637 | written = emacs_gnutls_write (p, cur_buf, cur_len); |
| 5851 | else | 5638 | else |
| 5852 | #endif | 5639 | #endif |
| 5853 | written = emacs_write (outfd, cur_buf, cur_len); | 5640 | written = emacs_write (outfd, cur_buf, cur_len); |
| 5854 | rv = (written ? 0 : -1); | 5641 | rv = (written ? 0 : -1); |
| 5855 | #ifdef ADAPTIVE_READ_BUFFERING | 5642 | #ifdef ADAPTIVE_READ_BUFFERING |
| 5856 | if (p->read_output_delay > 0 | 5643 | if (p->read_output_delay > 0 |
| 5857 | && p->adaptive_read_buffering == 1) | 5644 | && p->adaptive_read_buffering == 1) |
| 5858 | { | 5645 | { |
| 5859 | p->read_output_delay = 0; | 5646 | p->read_output_delay = 0; |
| 5860 | process_output_delay_count--; | 5647 | process_output_delay_count--; |
| 5861 | p->read_output_skip = 0; | 5648 | p->read_output_skip = 0; |
| 5862 | } | ||
| 5863 | #endif | ||
| 5864 | } | 5649 | } |
| 5865 | signal (SIGPIPE, old_sigpipe); | 5650 | #endif |
| 5651 | } | ||
| 5866 | 5652 | ||
| 5867 | if (rv < 0) | 5653 | if (rv < 0) |
| 5868 | { | 5654 | { |
| 5869 | if (0 | 5655 | if (errno == EAGAIN |
| 5870 | #ifdef EWOULDBLOCK | 5656 | #ifdef EWOULDBLOCK |
| 5871 | || errno == EWOULDBLOCK | 5657 | || errno == EWOULDBLOCK |
| 5872 | #endif | 5658 | #endif |
| 5873 | #ifdef EAGAIN | 5659 | ) |
| 5874 | || errno == EAGAIN | 5660 | /* Buffer is full. Wait, accepting input; |
| 5875 | #endif | 5661 | that may allow the program |
| 5876 | ) | 5662 | to finish doing output and read more. */ |
| 5877 | /* Buffer is full. Wait, accepting input; | 5663 | { |
| 5878 | that may allow the program | ||
| 5879 | to finish doing output and read more. */ | ||
| 5880 | { | ||
| 5881 | #ifdef BROKEN_PTY_READ_AFTER_EAGAIN | 5664 | #ifdef BROKEN_PTY_READ_AFTER_EAGAIN |
| 5882 | /* A gross hack to work around a bug in FreeBSD. | 5665 | /* A gross hack to work around a bug in FreeBSD. |
| 5883 | In the following sequence, read(2) returns | 5666 | In the following sequence, read(2) returns |
| 5884 | bogus data: | 5667 | bogus data: |
| 5885 | 5668 | ||
| 5886 | write(2) 1022 bytes | 5669 | write(2) 1022 bytes |
| 5887 | write(2) 954 bytes, get EAGAIN | 5670 | write(2) 954 bytes, get EAGAIN |
| 5888 | read(2) 1024 bytes in process_read_output | 5671 | read(2) 1024 bytes in process_read_output |
| 5889 | read(2) 11 bytes in process_read_output | 5672 | read(2) 11 bytes in process_read_output |
| 5890 | 5673 | ||
| 5891 | That is, read(2) returns more bytes than have | 5674 | That is, read(2) returns more bytes than have |
| 5892 | ever been written successfully. The 1033 bytes | 5675 | ever been written successfully. The 1033 bytes |
| 5893 | read are the 1022 bytes written successfully | 5676 | read are the 1022 bytes written successfully |
| 5894 | after processing (for example with CRs added if | 5677 | after processing (for example with CRs added if |
| 5895 | the terminal is set up that way which it is | 5678 | the terminal is set up that way which it is |
| 5896 | here). The same bytes will be seen again in a | 5679 | here). The same bytes will be seen again in a |
| 5897 | later read(2), without the CRs. */ | 5680 | later read(2), without the CRs. */ |
| 5898 | 5681 | ||
| 5899 | if (errno == EAGAIN) | 5682 | if (errno == EAGAIN) |
| 5900 | { | 5683 | { |
| 5901 | int flags = FWRITE; | 5684 | int flags = FWRITE; |
| 5902 | ioctl (p->outfd, TIOCFLUSH, &flags); | 5685 | ioctl (p->outfd, TIOCFLUSH, &flags); |
| 5903 | } | 5686 | } |
| 5904 | #endif /* BROKEN_PTY_READ_AFTER_EAGAIN */ | 5687 | #endif /* BROKEN_PTY_READ_AFTER_EAGAIN */ |
| 5905 | 5688 | ||
| 5906 | /* Put what we should have written in wait_queue. */ | 5689 | /* Put what we should have written in wait_queue. */ |
| 5907 | write_queue_push (p, cur_object, cur_buf, cur_len, 1); | 5690 | write_queue_push (p, cur_object, cur_buf, cur_len, 1); |
| 5908 | wait_reading_process_output (0, 20 * 1000 * 1000, | 5691 | wait_reading_process_output (0, 20 * 1000 * 1000, |
| 5909 | 0, 0, Qnil, NULL, 0); | 5692 | 0, 0, Qnil, NULL, 0); |
| 5910 | /* Reread queue, to see what is left. */ | 5693 | /* Reread queue, to see what is left. */ |
| 5911 | break; | 5694 | break; |
| 5912 | } | ||
| 5913 | else | ||
| 5914 | /* This is a real error. */ | ||
| 5915 | report_file_error ("writing to process", Fcons (proc, Qnil)); | ||
| 5916 | } | 5695 | } |
| 5917 | cur_buf += written; | 5696 | else if (errno == EPIPE) |
| 5918 | cur_len -= written; | 5697 | { |
| 5698 | p->raw_status_new = 0; | ||
| 5699 | pset_status (p, list2 (Qexit, make_number (256))); | ||
| 5700 | p->tick = ++process_tick; | ||
| 5701 | deactivate_process (proc); | ||
| 5702 | error ("process %s no longer connected to pipe; closed it", | ||
| 5703 | SDATA (p->name)); | ||
| 5704 | } | ||
| 5705 | else | ||
| 5706 | /* This is a real error. */ | ||
| 5707 | report_file_error ("writing to process", Fcons (proc, Qnil)); | ||
| 5919 | } | 5708 | } |
| 5709 | cur_buf += written; | ||
| 5710 | cur_len -= written; | ||
| 5920 | } | 5711 | } |
| 5921 | while (!NILP (p->write_queue)); | ||
| 5922 | } | ||
| 5923 | else | ||
| 5924 | { | ||
| 5925 | signal (SIGPIPE, old_sigpipe); | ||
| 5926 | proc = process_sent_to; | ||
| 5927 | p = XPROCESS (proc); | ||
| 5928 | p->raw_status_new = 0; | ||
| 5929 | pset_status (p, Fcons (Qexit, Fcons (make_number (256), Qnil))); | ||
| 5930 | p->tick = ++process_tick; | ||
| 5931 | deactivate_process (proc); | ||
| 5932 | error ("SIGPIPE raised on process %s; closed it", SDATA (p->name)); | ||
| 5933 | } | 5712 | } |
| 5713 | while (!NILP (p->write_queue)); | ||
| 5934 | } | 5714 | } |
| 5935 | 5715 | ||
| 5936 | DEFUN ("process-send-region", Fprocess_send_region, Sprocess_send_region, | 5716 | DEFUN ("process-send-region", Fprocess_send_region, Sprocess_send_region, |
| @@ -6047,7 +5827,7 @@ return t unconditionally. */) | |||
| 6047 | 5827 | ||
| 6048 | If we can, we try to signal PROCESS by sending control characters | 5828 | If we can, we try to signal PROCESS by sending control characters |
| 6049 | down the pty. This allows us to signal inferiors who have changed | 5829 | down the pty. This allows us to signal inferiors who have changed |
| 6050 | their uid, for which killpg would return an EPERM error. */ | 5830 | their uid, for which kill would return an EPERM error. */ |
| 6051 | 5831 | ||
| 6052 | static void | 5832 | static void |
| 6053 | process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group, | 5833 | process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group, |
| @@ -6185,7 +5965,7 @@ process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group, | |||
| 6185 | if (!NILP (current_group)) | 5965 | if (!NILP (current_group)) |
| 6186 | { | 5966 | { |
| 6187 | if (ioctl (p->infd, TIOCSIGSEND, signo) == -1) | 5967 | if (ioctl (p->infd, TIOCSIGSEND, signo) == -1) |
| 6188 | EMACS_KILLPG (gid, signo); | 5968 | kill (-gid, signo); |
| 6189 | } | 5969 | } |
| 6190 | else | 5970 | else |
| 6191 | { | 5971 | { |
| @@ -6193,7 +5973,7 @@ process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group, | |||
| 6193 | kill (gid, signo); | 5973 | kill (gid, signo); |
| 6194 | } | 5974 | } |
| 6195 | #else /* ! defined (TIOCSIGSEND) */ | 5975 | #else /* ! defined (TIOCSIGSEND) */ |
| 6196 | EMACS_KILLPG (gid, signo); | 5976 | kill (-gid, signo); |
| 6197 | #endif /* ! defined (TIOCSIGSEND) */ | 5977 | #endif /* ! defined (TIOCSIGSEND) */ |
| 6198 | } | 5978 | } |
| 6199 | 5979 | ||
| @@ -6294,6 +6074,27 @@ traffic. */) | |||
| 6294 | return process; | 6074 | return process; |
| 6295 | } | 6075 | } |
| 6296 | 6076 | ||
| 6077 | /* Return the integer value of the signal whose abbreviation is ABBR, | ||
| 6078 | or a negative number if there is no such signal. */ | ||
| 6079 | static int | ||
| 6080 | abbr_to_signal (char const *name) | ||
| 6081 | { | ||
| 6082 | int i, signo; | ||
| 6083 | char sigbuf[20]; /* Large enough for all valid signal abbreviations. */ | ||
| 6084 | |||
| 6085 | if (!strncmp (name, "SIG", 3) || !strncmp (name, "sig", 3)) | ||
| 6086 | name += 3; | ||
| 6087 | |||
| 6088 | for (i = 0; i < sizeof sigbuf; i++) | ||
| 6089 | { | ||
| 6090 | sigbuf[i] = c_toupper (name[i]); | ||
| 6091 | if (! sigbuf[i]) | ||
| 6092 | return str2sig (sigbuf, &signo) == 0 ? signo : -1; | ||
| 6093 | } | ||
| 6094 | |||
| 6095 | return -1; | ||
| 6096 | } | ||
| 6097 | |||
| 6297 | DEFUN ("signal-process", Fsignal_process, Ssignal_process, | 6098 | DEFUN ("signal-process", Fsignal_process, Ssignal_process, |
| 6298 | 2, 2, "sProcess (name or number): \nnSignal code: ", | 6099 | 2, 2, "sProcess (name or number): \nnSignal code: ", |
| 6299 | doc: /* Send PROCESS the signal with code SIGCODE. | 6100 | doc: /* Send PROCESS the signal with code SIGCODE. |
| @@ -6304,6 +6105,7 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */) | |||
| 6304 | (Lisp_Object process, Lisp_Object sigcode) | 6105 | (Lisp_Object process, Lisp_Object sigcode) |
| 6305 | { | 6106 | { |
| 6306 | pid_t pid; | 6107 | pid_t pid; |
| 6108 | int signo; | ||
| 6307 | 6109 | ||
| 6308 | if (STRINGP (process)) | 6110 | if (STRINGP (process)) |
| 6309 | { | 6111 | { |
| @@ -6333,12 +6135,11 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */) | |||
| 6333 | error ("Cannot signal process %s", SDATA (XPROCESS (process)->name)); | 6135 | error ("Cannot signal process %s", SDATA (XPROCESS (process)->name)); |
| 6334 | } | 6136 | } |
| 6335 | 6137 | ||
| 6336 | #define parse_signal(NAME, VALUE) \ | ||
| 6337 | else if (!xstrcasecmp (name, NAME)) \ | ||
| 6338 | XSETINT (sigcode, VALUE) | ||
| 6339 | |||
| 6340 | if (INTEGERP (sigcode)) | 6138 | if (INTEGERP (sigcode)) |
| 6341 | CHECK_TYPE_RANGED_INTEGER (int, sigcode); | 6139 | { |
| 6140 | CHECK_TYPE_RANGED_INTEGER (int, sigcode); | ||
| 6141 | signo = XINT (sigcode); | ||
| 6142 | } | ||
| 6342 | else | 6143 | else |
| 6343 | { | 6144 | { |
| 6344 | char *name; | 6145 | char *name; |
| @@ -6346,108 +6147,12 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */) | |||
| 6346 | CHECK_SYMBOL (sigcode); | 6147 | CHECK_SYMBOL (sigcode); |
| 6347 | name = SSDATA (SYMBOL_NAME (sigcode)); | 6148 | name = SSDATA (SYMBOL_NAME (sigcode)); |
| 6348 | 6149 | ||
| 6349 | if (!strncmp (name, "SIG", 3) || !strncmp (name, "sig", 3)) | 6150 | signo = abbr_to_signal (name); |
| 6350 | name += 3; | 6151 | if (signo < 0) |
| 6351 | |||
| 6352 | if (0) | ||
| 6353 | ; | ||
| 6354 | #ifdef SIGUSR1 | ||
| 6355 | parse_signal ("usr1", SIGUSR1); | ||
| 6356 | #endif | ||
| 6357 | #ifdef SIGUSR2 | ||
| 6358 | parse_signal ("usr2", SIGUSR2); | ||
| 6359 | #endif | ||
| 6360 | #ifdef SIGTERM | ||
| 6361 | parse_signal ("term", SIGTERM); | ||
| 6362 | #endif | ||
| 6363 | #ifdef SIGHUP | ||
| 6364 | parse_signal ("hup", SIGHUP); | ||
| 6365 | #endif | ||
| 6366 | #ifdef SIGINT | ||
| 6367 | parse_signal ("int", SIGINT); | ||
| 6368 | #endif | ||
| 6369 | #ifdef SIGQUIT | ||
| 6370 | parse_signal ("quit", SIGQUIT); | ||
| 6371 | #endif | ||
| 6372 | #ifdef SIGILL | ||
| 6373 | parse_signal ("ill", SIGILL); | ||
| 6374 | #endif | ||
| 6375 | #ifdef SIGABRT | ||
| 6376 | parse_signal ("abrt", SIGABRT); | ||
| 6377 | #endif | ||
| 6378 | #ifdef SIGEMT | ||
| 6379 | parse_signal ("emt", SIGEMT); | ||
| 6380 | #endif | ||
| 6381 | #ifdef SIGKILL | ||
| 6382 | parse_signal ("kill", SIGKILL); | ||
| 6383 | #endif | ||
| 6384 | #ifdef SIGFPE | ||
| 6385 | parse_signal ("fpe", SIGFPE); | ||
| 6386 | #endif | ||
| 6387 | #ifdef SIGBUS | ||
| 6388 | parse_signal ("bus", SIGBUS); | ||
| 6389 | #endif | ||
| 6390 | #ifdef SIGSEGV | ||
| 6391 | parse_signal ("segv", SIGSEGV); | ||
| 6392 | #endif | ||
| 6393 | #ifdef SIGSYS | ||
| 6394 | parse_signal ("sys", SIGSYS); | ||
| 6395 | #endif | ||
| 6396 | #ifdef SIGPIPE | ||
| 6397 | parse_signal ("pipe", SIGPIPE); | ||
| 6398 | #endif | ||
| 6399 | #ifdef SIGALRM | ||
| 6400 | parse_signal ("alrm", SIGALRM); | ||
| 6401 | #endif | ||
| 6402 | #ifdef SIGURG | ||
| 6403 | parse_signal ("urg", SIGURG); | ||
| 6404 | #endif | ||
| 6405 | #ifdef SIGSTOP | ||
| 6406 | parse_signal ("stop", SIGSTOP); | ||
| 6407 | #endif | ||
| 6408 | #ifdef SIGTSTP | ||
| 6409 | parse_signal ("tstp", SIGTSTP); | ||
| 6410 | #endif | ||
| 6411 | #ifdef SIGCONT | ||
| 6412 | parse_signal ("cont", SIGCONT); | ||
| 6413 | #endif | ||
| 6414 | #ifdef SIGCHLD | ||
| 6415 | parse_signal ("chld", SIGCHLD); | ||
| 6416 | #endif | ||
| 6417 | #ifdef SIGTTIN | ||
| 6418 | parse_signal ("ttin", SIGTTIN); | ||
| 6419 | #endif | ||
| 6420 | #ifdef SIGTTOU | ||
| 6421 | parse_signal ("ttou", SIGTTOU); | ||
| 6422 | #endif | ||
| 6423 | #ifdef SIGIO | ||
| 6424 | parse_signal ("io", SIGIO); | ||
| 6425 | #endif | ||
| 6426 | #ifdef SIGXCPU | ||
| 6427 | parse_signal ("xcpu", SIGXCPU); | ||
| 6428 | #endif | ||
| 6429 | #ifdef SIGXFSZ | ||
| 6430 | parse_signal ("xfsz", SIGXFSZ); | ||
| 6431 | #endif | ||
| 6432 | #ifdef SIGVTALRM | ||
| 6433 | parse_signal ("vtalrm", SIGVTALRM); | ||
| 6434 | #endif | ||
| 6435 | #ifdef SIGPROF | ||
| 6436 | parse_signal ("prof", SIGPROF); | ||
| 6437 | #endif | ||
| 6438 | #ifdef SIGWINCH | ||
| 6439 | parse_signal ("winch", SIGWINCH); | ||
| 6440 | #endif | ||
| 6441 | #ifdef SIGINFO | ||
| 6442 | parse_signal ("info", SIGINFO); | ||
| 6443 | #endif | ||
| 6444 | else | ||
| 6445 | error ("Undefined signal name %s", name); | 6152 | error ("Undefined signal name %s", name); |
| 6446 | } | 6153 | } |
| 6447 | 6154 | ||
| 6448 | #undef parse_signal | 6155 | return make_number (kill (pid, signo)); |
| 6449 | |||
| 6450 | return make_number (kill (pid, XINT (sigcode))); | ||
| 6451 | } | 6156 | } |
| 6452 | 6157 | ||
| 6453 | DEFUN ("process-send-eof", Fprocess_send_eof, Sprocess_send_eof, 0, 1, 0, | 6158 | DEFUN ("process-send-eof", Fprocess_send_eof, Sprocess_send_eof, 0, 1, 0, |
| @@ -6513,15 +6218,14 @@ process has been transmitted to the serial port. */) | |||
| 6513 | #endif /* not HAVE_SHUTDOWN */ | 6218 | #endif /* not HAVE_SHUTDOWN */ |
| 6514 | new_outfd = emacs_open (NULL_DEVICE, O_WRONLY, 0); | 6219 | new_outfd = emacs_open (NULL_DEVICE, O_WRONLY, 0); |
| 6515 | if (new_outfd < 0) | 6220 | if (new_outfd < 0) |
| 6516 | abort (); | 6221 | emacs_abort (); |
| 6517 | old_outfd = XPROCESS (proc)->outfd; | 6222 | old_outfd = XPROCESS (proc)->outfd; |
| 6518 | 6223 | ||
| 6519 | if (!proc_encode_coding_system[new_outfd]) | 6224 | if (!proc_encode_coding_system[new_outfd]) |
| 6520 | proc_encode_coding_system[new_outfd] | 6225 | proc_encode_coding_system[new_outfd] |
| 6521 | = xmalloc (sizeof (struct coding_system)); | 6226 | = xmalloc (sizeof (struct coding_system)); |
| 6522 | memcpy (proc_encode_coding_system[new_outfd], | 6227 | *proc_encode_coding_system[new_outfd] |
| 6523 | proc_encode_coding_system[old_outfd], | 6228 | = *proc_encode_coding_system[old_outfd]; |
| 6524 | sizeof (struct coding_system)); | ||
| 6525 | memset (proc_encode_coding_system[old_outfd], 0, | 6229 | memset (proc_encode_coding_system[old_outfd], 0, |
| 6526 | sizeof (struct coding_system)); | 6230 | sizeof (struct coding_system)); |
| 6527 | 6231 | ||
| @@ -6530,9 +6234,35 @@ process has been transmitted to the serial port. */) | |||
| 6530 | return process; | 6234 | return process; |
| 6531 | } | 6235 | } |
| 6532 | 6236 | ||
| 6533 | /* On receipt of a signal that a child status has changed, loop asking | 6237 | /* The main Emacs thread records child processes in three places: |
| 6534 | about children with changed statuses until the system says there | 6238 | |
| 6535 | are no more. | 6239 | - Vprocess_alist, for asynchronous subprocesses, which are child |
| 6240 | processes visible to Lisp. | ||
| 6241 | |||
| 6242 | - deleted_pid_list, for child processes invisible to Lisp, | ||
| 6243 | typically because of delete-process. These are recorded so that | ||
| 6244 | the processes can be reaped when they exit, so that the operating | ||
| 6245 | system's process table is not cluttered by zombies. | ||
| 6246 | |||
| 6247 | - the local variable PID in Fcall_process, call_process_cleanup and | ||
| 6248 | call_process_kill, for synchronous subprocesses. | ||
| 6249 | record_unwind_protect is used to make sure this process is not | ||
| 6250 | forgotten: if the user interrupts call-process and the child | ||
| 6251 | process refuses to exit immediately even with two C-g's, | ||
| 6252 | call_process_kill adds PID's contents to deleted_pid_list before | ||
| 6253 | returning. | ||
| 6254 | |||
| 6255 | The main Emacs thread invokes waitpid only on child processes that | ||
| 6256 | it creates and that have not been reaped. This avoid races on | ||
| 6257 | platforms such as GTK, where other threads create their own | ||
| 6258 | subprocesses which the main thread should not reap. For example, | ||
| 6259 | if the main thread attempted to reap an already-reaped child, it | ||
| 6260 | might inadvertently reap a GTK-created process that happened to | ||
| 6261 | have the same process ID. */ | ||
| 6262 | |||
| 6263 | /* Handle a SIGCHLD signal by looking for known child processes of | ||
| 6264 | Emacs whose status have changed. For each one found, record its | ||
| 6265 | new status. | ||
| 6536 | 6266 | ||
| 6537 | All we do is change the status; we do not run sentinels or print | 6267 | All we do is change the status; we do not run sentinels or print |
| 6538 | notifications. That is saved for the next time keyboard input is | 6268 | notifications. That is saved for the next time keyboard input is |
| @@ -6555,142 +6285,72 @@ process has been transmitted to the serial port. */) | |||
| 6555 | ** Malloc WARNING: This should never call malloc either directly or | 6285 | ** Malloc WARNING: This should never call malloc either directly or |
| 6556 | indirectly; if it does, that is a bug */ | 6286 | indirectly; if it does, that is a bug */ |
| 6557 | 6287 | ||
| 6558 | #ifdef SIGCHLD | ||
| 6559 | static void | 6288 | static void |
| 6560 | sigchld_handler (int signo) | 6289 | handle_child_signal (int sig) |
| 6561 | { | 6290 | { |
| 6562 | int old_errno = errno; | 6291 | Lisp_Object tail; |
| 6563 | Lisp_Object proc; | ||
| 6564 | struct Lisp_Process *p; | ||
| 6565 | 6292 | ||
| 6566 | SIGNAL_THREAD_CHECK (signo); | 6293 | /* Find the process that signaled us, and record its status. */ |
| 6567 | 6294 | ||
| 6568 | while (1) | 6295 | /* The process can have been deleted by Fdelete_process, or have |
| 6296 | been started asynchronously by Fcall_process. */ | ||
| 6297 | for (tail = deleted_pid_list; CONSP (tail); tail = XCDR (tail)) | ||
| 6569 | { | 6298 | { |
| 6570 | pid_t pid; | 6299 | bool all_pids_are_fixnums |
| 6571 | int w; | 6300 | = (MOST_NEGATIVE_FIXNUM <= TYPE_MINIMUM (pid_t) |
| 6572 | Lisp_Object tail; | 6301 | && TYPE_MAXIMUM (pid_t) <= MOST_POSITIVE_FIXNUM); |
| 6573 | 6302 | Lisp_Object xpid = XCAR (tail); | |
| 6574 | #ifdef WNOHANG | 6303 | if (all_pids_are_fixnums ? INTEGERP (xpid) : NUMBERP (xpid)) |
| 6575 | #ifndef WUNTRACED | ||
| 6576 | #define WUNTRACED 0 | ||
| 6577 | #endif /* no WUNTRACED */ | ||
| 6578 | /* Keep trying to get a status until we get a definitive result. */ | ||
| 6579 | do | ||
| 6580 | { | ||
| 6581 | errno = 0; | ||
| 6582 | pid = waitpid (-1, &w, WNOHANG | WUNTRACED); | ||
| 6583 | } | ||
| 6584 | while (pid < 0 && errno == EINTR); | ||
| 6585 | |||
| 6586 | if (pid <= 0) | ||
| 6587 | { | 6304 | { |
| 6588 | /* PID == 0 means no processes found, PID == -1 means a real | 6305 | pid_t deleted_pid; |
| 6589 | failure. We have done all our job, so return. */ | 6306 | if (INTEGERP (xpid)) |
| 6590 | 6307 | deleted_pid = XINT (xpid); | |
| 6591 | errno = old_errno; | 6308 | else |
| 6592 | return; | 6309 | deleted_pid = XFLOAT_DATA (xpid); |
| 6593 | } | 6310 | if (child_status_changed (deleted_pid, 0, 0)) |
| 6594 | #else | 6311 | XSETCAR (tail, Qnil); |
| 6595 | pid = wait (&w); | ||
| 6596 | #endif /* no WNOHANG */ | ||
| 6597 | |||
| 6598 | /* Find the process that signaled us, and record its status. */ | ||
| 6599 | |||
| 6600 | /* The process can have been deleted by Fdelete_process. */ | ||
| 6601 | for (tail = deleted_pid_list; CONSP (tail); tail = XCDR (tail)) | ||
| 6602 | { | ||
| 6603 | Lisp_Object xpid = XCAR (tail); | ||
| 6604 | if ((INTEGERP (xpid) && pid == XINT (xpid)) | ||
| 6605 | || (FLOATP (xpid) && pid == XFLOAT_DATA (xpid))) | ||
| 6606 | { | ||
| 6607 | XSETCAR (tail, Qnil); | ||
| 6608 | goto sigchld_end_of_loop; | ||
| 6609 | } | ||
| 6610 | } | ||
| 6611 | |||
| 6612 | /* Otherwise, if it is asynchronous, it is in Vprocess_alist. */ | ||
| 6613 | p = 0; | ||
| 6614 | for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) | ||
| 6615 | { | ||
| 6616 | proc = XCDR (XCAR (tail)); | ||
| 6617 | p = XPROCESS (proc); | ||
| 6618 | if (EQ (p->type, Qreal) && p->pid == pid) | ||
| 6619 | break; | ||
| 6620 | p = 0; | ||
| 6621 | } | 6312 | } |
| 6313 | } | ||
| 6622 | 6314 | ||
| 6623 | /* Look for an asynchronous process whose pid hasn't been filled | 6315 | /* Otherwise, if it is asynchronous, it is in Vprocess_alist. */ |
| 6624 | in yet. */ | 6316 | for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) |
| 6625 | if (p == 0) | 6317 | { |
| 6626 | for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) | 6318 | Lisp_Object proc = XCDR (XCAR (tail)); |
| 6627 | { | 6319 | struct Lisp_Process *p = XPROCESS (proc); |
| 6628 | proc = XCDR (XCAR (tail)); | 6320 | int status; |
| 6629 | p = XPROCESS (proc); | ||
| 6630 | if (p->pid == -1) | ||
| 6631 | break; | ||
| 6632 | p = 0; | ||
| 6633 | } | ||
| 6634 | 6321 | ||
| 6635 | /* Change the status of the process that was found. */ | 6322 | if (p->alive && child_status_changed (p->pid, &status, WUNTRACED)) |
| 6636 | if (p != 0) | ||
| 6637 | { | 6323 | { |
| 6638 | int clear_desc_flag = 0; | 6324 | /* Change the status of the process that was found. */ |
| 6639 | |||
| 6640 | p->tick = ++process_tick; | 6325 | p->tick = ++process_tick; |
| 6641 | p->raw_status = w; | 6326 | p->raw_status = status; |
| 6642 | p->raw_status_new = 1; | 6327 | p->raw_status_new = 1; |
| 6643 | 6328 | ||
| 6644 | /* If process has terminated, stop waiting for its output. */ | 6329 | /* If process has terminated, stop waiting for its output. */ |
| 6645 | if ((WIFSIGNALED (w) || WIFEXITED (w)) | 6330 | if (WIFSIGNALED (status) || WIFEXITED (status)) |
| 6646 | && p->infd >= 0) | 6331 | { |
| 6647 | clear_desc_flag = 1; | 6332 | int clear_desc_flag = 0; |
| 6648 | 6333 | p->alive = 0; | |
| 6649 | /* We use clear_desc_flag to avoid a compiler bug in Microsoft C. */ | 6334 | if (p->infd >= 0) |
| 6650 | if (clear_desc_flag) | 6335 | clear_desc_flag = 1; |
| 6651 | delete_read_fd (p->infd); | 6336 | |
| 6652 | 6337 | /* clear_desc_flag avoids a compiler bug in Microsoft C. */ | |
| 6653 | /* Tell wait_reading_process_output that it needs to wake up and | 6338 | if (clear_desc_flag) |
| 6654 | look around. */ | 6339 | delete_read_fd (p->infd); |
| 6655 | if (input_available_clear_time) | 6340 | { |
| 6656 | *input_available_clear_time = make_emacs_time (0, 0); | 6341 | FD_CLR (p->infd, &input_wait_mask); |
| 6657 | } | 6342 | FD_CLR (p->infd, &non_keyboard_wait_mask); |
| 6658 | 6343 | } | |
| 6659 | /* There was no asynchronous process found for that pid: we have | 6344 | } |
| 6660 | a synchronous process. */ | ||
| 6661 | else | ||
| 6662 | { | ||
| 6663 | synch_process_alive = 0; | ||
| 6664 | |||
| 6665 | /* Report the status of the synchronous process. */ | ||
| 6666 | if (WIFEXITED (w)) | ||
| 6667 | synch_process_retcode = WEXITSTATUS (w); | ||
| 6668 | else if (WIFSIGNALED (w)) | ||
| 6669 | synch_process_termsig = WTERMSIG (w); | ||
| 6670 | |||
| 6671 | /* Tell wait_reading_process_output that it needs to wake up and | ||
| 6672 | look around. */ | ||
| 6673 | if (input_available_clear_time) | ||
| 6674 | *input_available_clear_time = make_emacs_time (0, 0); | ||
| 6675 | } | 6345 | } |
| 6676 | |||
| 6677 | sigchld_end_of_loop: | ||
| 6678 | ; | ||
| 6679 | |||
| 6680 | /* On some systems, we must return right away. | ||
| 6681 | If any more processes want to signal us, we will | ||
| 6682 | get another signal. | ||
| 6683 | Otherwise (on systems that have WNOHANG), loop around | ||
| 6684 | to use up all the processes that have something to tell us. */ | ||
| 6685 | #if (defined WINDOWSNT \ | ||
| 6686 | || (defined USG && !defined GNU_LINUX \ | ||
| 6687 | && !(defined HPUX && defined WNOHANG))) | ||
| 6688 | errno = old_errno; | ||
| 6689 | return; | ||
| 6690 | #endif /* USG, but not HPUX with WNOHANG */ | ||
| 6691 | } | 6346 | } |
| 6692 | } | 6347 | } |
| 6693 | #endif /* SIGCHLD */ | 6348 | |
| 6349 | static void | ||
| 6350 | deliver_child_signal (int sig) | ||
| 6351 | { | ||
| 6352 | deliver_process_signal (sig, handle_child_signal); | ||
| 6353 | } | ||
| 6694 | 6354 | ||
| 6695 | 6355 | ||
| 6696 | static Lisp_Object | 6356 | static Lisp_Object |
| @@ -6879,7 +6539,7 @@ status_notify (struct Lisp_Process *deleting_process) | |||
| 6879 | 6539 | ||
| 6880 | /* Avoid error if buffer is deleted | 6540 | /* Avoid error if buffer is deleted |
| 6881 | (probably that's why the process is dead, too) */ | 6541 | (probably that's why the process is dead, too) */ |
| 6882 | if (NILP (BVAR (XBUFFER (buffer), name))) | 6542 | if (!BUFFER_LIVE_P (XBUFFER (buffer))) |
| 6883 | continue; | 6543 | continue; |
| 6884 | Fset_buffer (buffer); | 6544 | Fset_buffer (buffer); |
| 6885 | 6545 | ||
| @@ -7011,7 +6671,7 @@ delete_gpm_wait_descriptor (int desc) | |||
| 7011 | 6671 | ||
| 7012 | # endif | 6672 | # endif |
| 7013 | 6673 | ||
| 7014 | # ifdef SIGIO | 6674 | # ifdef USABLE_SIGIO |
| 7015 | 6675 | ||
| 7016 | /* Return nonzero if *MASK has a bit set | 6676 | /* Return nonzero if *MASK has a bit set |
| 7017 | that corresponds to one of the keyboard input descriptors. */ | 6677 | that corresponds to one of the keyboard input descriptors. */ |
| @@ -7061,14 +6721,14 @@ extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *, | |||
| 7061 | see full version for other parameters. We know that wait_proc will | 6721 | see full version for other parameters. We know that wait_proc will |
| 7062 | always be NULL, since `subprocesses' isn't defined. | 6722 | always be NULL, since `subprocesses' isn't defined. |
| 7063 | 6723 | ||
| 7064 | DO_DISPLAY != 0 means redisplay should be done to show subprocess | 6724 | DO_DISPLAY means redisplay should be done to show subprocess |
| 7065 | output that arrives. | 6725 | output that arrives. |
| 7066 | 6726 | ||
| 7067 | Return true if we received input from any process. */ | 6727 | Return true if we received input from any process. */ |
| 7068 | 6728 | ||
| 7069 | int | 6729 | int |
| 7070 | wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | 6730 | wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, |
| 7071 | int do_display, | 6731 | bool do_display, |
| 7072 | Lisp_Object wait_for_cell, | 6732 | Lisp_Object wait_for_cell, |
| 7073 | struct Lisp_Process *wait_proc, int just_wait_proc) | 6733 | struct Lisp_Process *wait_proc, int just_wait_proc) |
| 7074 | { | 6734 | { |
| @@ -7144,7 +6804,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 7144 | 6804 | ||
| 7145 | do | 6805 | do |
| 7146 | { | 6806 | { |
| 7147 | int old_timers_run = timers_run; | 6807 | unsigned old_timers_run = timers_run; |
| 7148 | timer_delay = timer_check (); | 6808 | timer_delay = timer_check (); |
| 7149 | if (timers_run != old_timers_run && do_display) | 6809 | if (timers_run != old_timers_run && do_display) |
| 7150 | /* We must retry, since a timer may have requeued itself | 6810 | /* We must retry, since a timer may have requeued itself |
| @@ -7545,12 +7205,14 @@ init_process_emacs (void) | |||
| 7545 | 7205 | ||
| 7546 | inhibit_sentinels = 0; | 7206 | inhibit_sentinels = 0; |
| 7547 | 7207 | ||
| 7548 | #ifdef SIGCHLD | ||
| 7549 | #ifndef CANNOT_DUMP | 7208 | #ifndef CANNOT_DUMP |
| 7550 | if (! noninteractive || initialized) | 7209 | if (! noninteractive || initialized) |
| 7551 | #endif | 7210 | #endif |
| 7552 | signal (SIGCHLD, sigchld_handler); | 7211 | { |
| 7553 | #endif | 7212 | struct sigaction action; |
| 7213 | emacs_sigaction_init (&action, deliver_child_signal); | ||
| 7214 | sigaction (SIGCHLD, &action, 0); | ||
| 7215 | } | ||
| 7554 | 7216 | ||
| 7555 | max_process_desc = 0; | 7217 | max_process_desc = 0; |
| 7556 | memset (fd_callback_info, 0, sizeof (fd_callback_info)); | 7218 | memset (fd_callback_info, 0, sizeof (fd_callback_info)); |
| @@ -7572,9 +7234,7 @@ init_process_emacs (void) | |||
| 7572 | #endif | 7234 | #endif |
| 7573 | 7235 | ||
| 7574 | Vprocess_alist = Qnil; | 7236 | Vprocess_alist = Qnil; |
| 7575 | #ifdef SIGCHLD | ||
| 7576 | deleted_pid_list = Qnil; | 7237 | deleted_pid_list = Qnil; |
| 7577 | #endif | ||
| 7578 | for (i = 0; i < MAXDESC; i++) | 7238 | for (i = 0; i < MAXDESC; i++) |
| 7579 | { | 7239 | { |
| 7580 | chan_process[i] = Qnil; | 7240 | chan_process[i] = Qnil; |
| @@ -7612,9 +7272,7 @@ init_process_emacs (void) | |||
| 7612 | #ifdef HAVE_GETSOCKNAME | 7272 | #ifdef HAVE_GETSOCKNAME |
| 7613 | ADD_SUBFEATURE (QCservice, Qt); | 7273 | ADD_SUBFEATURE (QCservice, Qt); |
| 7614 | #endif | 7274 | #endif |
| 7615 | #if defined (O_NONBLOCK) || defined (O_NDELAY) | ||
| 7616 | ADD_SUBFEATURE (QCserver, Qt); | 7275 | ADD_SUBFEATURE (QCserver, Qt); |
| 7617 | #endif | ||
| 7618 | 7276 | ||
| 7619 | for (sopt = socket_options; sopt->name; sopt++) | 7277 | for (sopt = socket_options; sopt->name; sopt++) |
| 7620 | subfeatures = pure_cons (intern_c_string (sopt->name), subfeatures); | 7278 | subfeatures = pure_cons (intern_c_string (sopt->name), subfeatures); |
| @@ -7703,9 +7361,7 @@ syms_of_process (void) | |||
| 7703 | DEFSYM (Qlast_nonmenu_event, "last-nonmenu-event"); | 7361 | DEFSYM (Qlast_nonmenu_event, "last-nonmenu-event"); |
| 7704 | 7362 | ||
| 7705 | staticpro (&Vprocess_alist); | 7363 | staticpro (&Vprocess_alist); |
| 7706 | #ifdef SIGCHLD | ||
| 7707 | staticpro (&deleted_pid_list); | 7364 | staticpro (&deleted_pid_list); |
| 7708 | #endif | ||
| 7709 | 7365 | ||
| 7710 | #endif /* subprocesses */ | 7366 | #endif /* subprocesses */ |
| 7711 | 7367 | ||