aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorEli Zaretskii2013-03-28 20:13:59 +0200
committerEli Zaretskii2013-03-28 20:13:59 +0200
commitd76bf86f438d4f5f9fe493ab76f02ffc78f3ae2e (patch)
tree04fa8bc7bd2058a316a7ee30f8741d25bfd0b060 /src/process.c
parent2ef26ceb192c7683754cf0b4aa3087f501254332 (diff)
parente74aeda863cd6896e06e92586f87b45d63d67d15 (diff)
downloademacs-d76bf86f438d4f5f9fe493ab76f02ffc78f3ae2e.tar.gz
emacs-d76bf86f438d4f5f9fe493ab76f02ffc78f3ae2e.zip
Merge from trunk and resolve conflicts.
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c501
1 files changed, 175 insertions, 326 deletions
diff --git a/src/process.c b/src/process.c
index 0036ce595f5..6a14a536707 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1,7 +1,7 @@
1/* Asynchronous subprocess control for GNU Emacs. 1/* Asynchronous subprocess control for GNU Emacs.
2 2
3Copyright (C) 1985-1988, 1993-1996, 1998-1999, 2001-2012 3Copyright (C) 1985-1988, 1993-1996, 1998-1999, 2001-2013 Free Software
4 Free Software Foundation, Inc. 4Foundation, Inc.
5 5
6This file is part of GNU Emacs. 6This file is part of GNU Emacs.
7 7
@@ -91,6 +91,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
91#include <pty.h> 91#include <pty.h>
92#endif 92#endif
93 93
94#include <c-ctype.h>
95#include <sig2str.h>
96
94#endif /* subprocesses */ 97#endif /* subprocesses */
95 98
96#include "systime.h" 99#include "systime.h"
@@ -133,7 +136,7 @@ extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *,
133/* 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
134 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52904>. 137 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52904>.
135 These lines can be removed once the GCC bug is fixed. */ 138 These lines can be removed once the GCC bug is fixed. */
136#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ 139#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
137# pragma GCC diagnostic ignored "-Wstrict-overflow" 140# pragma GCC diagnostic ignored "-Wstrict-overflow"
138#endif 141#endif
139 142
@@ -143,13 +146,13 @@ Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs;
143Lisp_Object Quser, Qgroup, Qetime, Qpcpu, Qpmem, Qtime, Qctime; 146Lisp_Object Quser, Qgroup, Qetime, Qpcpu, Qpmem, Qtime, Qctime;
144Lisp_Object QCname, QCtype; 147Lisp_Object QCname, QCtype;
145 148
146/* Non-zero if keyboard input is on hold, zero otherwise. */ 149/* True if keyboard input is on hold, zero otherwise. */
147 150
148static int kbd_is_on_hold; 151static bool kbd_is_on_hold;
149 152
150/* Nonzero means don't run process sentinels. This is used 153/* Nonzero means don't run process sentinels. This is used
151 when exiting. */ 154 when exiting. */
152int inhibit_sentinels; 155bool inhibit_sentinels;
153 156
154#ifdef subprocesses 157#ifdef subprocesses
155 158
@@ -177,10 +180,6 @@ static Lisp_Object Qlast_nonmenu_event;
177#define SERIALCONN_P(p) (EQ (XPROCESS (p)->type, Qserial)) 180#define SERIALCONN_P(p) (EQ (XPROCESS (p)->type, Qserial))
178#define SERIALCONN1_P(p) (EQ (p->type, Qserial)) 181#define SERIALCONN1_P(p) (EQ (p->type, Qserial))
179 182
180#ifndef HAVE_H_ERRNO
181extern int h_errno;
182#endif
183
184/* Number of events of change of status of a process. */ 183/* Number of events of change of status of a process. */
185static EMACS_INT process_tick; 184static EMACS_INT process_tick;
186/* Number of events for which the user or sentinel has been notified. */ 185/* Number of events for which the user or sentinel has been notified. */
@@ -235,9 +234,9 @@ static EMACS_INT update_tick;
235 234
236static int process_output_delay_count; 235static int process_output_delay_count;
237 236
238/* Non-zero if any process has non-nil read_output_skip. */ 237/* True if any process has non-nil read_output_skip. */
239 238
240static int process_output_skip; 239static bool process_output_skip;
241 240
242#else 241#else
243#define process_output_delay_count 0 242#define process_output_delay_count 0
@@ -245,7 +244,7 @@ static int process_output_skip;
245 244
246static void create_process (Lisp_Object, char **, Lisp_Object); 245static void create_process (Lisp_Object, char **, Lisp_Object);
247#ifdef USABLE_SIGIO 246#ifdef USABLE_SIGIO
248static int keyboard_bit_set (SELECT_TYPE *); 247static bool keyboard_bit_set (SELECT_TYPE *);
249#endif 248#endif
250static void deactivate_process (Lisp_Object); 249static void deactivate_process (Lisp_Object);
251static void status_notify (struct Lisp_Process *); 250static void status_notify (struct Lisp_Process *);
@@ -528,7 +527,7 @@ status_convert (int w)
528 and store them individually through the three pointers. */ 527 and store them individually through the three pointers. */
529 528
530static void 529static void
531decode_status (Lisp_Object l, Lisp_Object *symbol, int *code, int *coredump) 530decode_status (Lisp_Object l, Lisp_Object *symbol, int *code, bool *coredump)
532{ 531{
533 Lisp_Object tem; 532 Lisp_Object tem;
534 533
@@ -555,7 +554,8 @@ status_message (struct Lisp_Process *p)
555{ 554{
556 Lisp_Object status = p->status; 555 Lisp_Object status = p->status;
557 Lisp_Object symbol; 556 Lisp_Object symbol;
558 int code, coredump; 557 int code;
558 bool coredump;
559 Lisp_Object string, string2; 559 Lisp_Object string, string2;
560 560
561 decode_status (status, &symbol, &code, &coredump); 561 decode_status (status, &symbol, &code, &coredump);
@@ -773,13 +773,22 @@ get_process (register Lisp_Object name)
773} 773}
774 774
775 775
776#ifdef SIGCHLD
777/* Fdelete_process promises to immediately forget about the process, but in 776/* Fdelete_process promises to immediately forget about the process, but in
778 reality, Emacs needs to remember those processes until they have been 777 reality, Emacs needs to remember those processes until they have been
779 treated by the SIGCHLD handler and waitpid has been invoked on them; 778 treated by the SIGCHLD handler and waitpid has been invoked on them;
780 otherwise they might fill up the kernel's process table. */ 779 otherwise they might fill up the kernel's process table.
780
781 Some processes created by call-process are also put onto this list. */
781static Lisp_Object deleted_pid_list; 782static Lisp_Object deleted_pid_list;
782#endif 783
784void
785record_deleted_pid (pid_t pid)
786{
787 deleted_pid_list = Fcons (make_fixnum_or_float (pid),
788 /* GC treated elements set to nil. */
789 Fdelq (Qnil, deleted_pid_list));
790
791}
783 792
784DEFUN ("delete-process", Fdelete_process, Sdelete_process, 1, 1, 0, 793DEFUN ("delete-process", Fdelete_process, Sdelete_process, 1, 1, 0,
785 doc: /* Delete PROCESS: kill it and forget about it immediately. 794 doc: /* Delete PROCESS: kill it and forget about it immediately.
@@ -800,32 +809,22 @@ nil, indicating the current buffer's process. */)
800 status_notify (p); 809 status_notify (p);
801 redisplay_preserve_echo_area (13); 810 redisplay_preserve_echo_area (13);
802 } 811 }
803 else if (p->infd >= 0) 812 else
804 { 813 {
805#ifdef SIGCHLD 814 if (p->alive)
806 Lisp_Object symbol; 815 record_kill_process (p);
807 pid_t pid = p->pid; 816
808 817 if (p->infd >= 0)
809 /* No problem storing the pid here, as it is still in Vprocess_alist. */
810 deleted_pid_list = Fcons (make_fixnum_or_float (pid),
811 /* GC treated elements set to nil. */
812 Fdelq (Qnil, deleted_pid_list));
813 /* If the process has already signaled, remove it from the list. */
814 if (p->raw_status_new)
815 update_status (p);
816 symbol = p->status;
817 if (CONSP (p->status))
818 symbol = XCAR (p->status);
819 if (EQ (symbol, Qsignal) || EQ (symbol, Qexit))
820 deleted_pid_list
821 = Fdelete (make_fixnum_or_float (pid), deleted_pid_list);
822 else
823#endif
824 { 818 {
825 Fkill_process (process, Qnil); 819 /* Update P's status, since record_kill_process will make the
826 /* Do this now, since remove_process will make the 820 SIGCHLD handler update deleted_pid_list, not *P. */
827 SIGCHLD handler do nothing. */ 821 Lisp_Object symbol;
828 pset_status (p, Fcons (Qsignal, Fcons (make_number (SIGKILL), Qnil))); 822 if (p->raw_status_new)
823 update_status (p);
824 symbol = CONSP (p->status) ? XCAR (p->status) : p->status;
825 if (! (EQ (symbol, Qsignal) || EQ (symbol, Qexit)))
826 pset_status (p, list2 (Qsignal, make_number (SIGKILL)));
827
829 p->tick = ++process_tick; 828 p->tick = ++process_tick;
830 status_notify (p); 829 status_notify (p);
831 redisplay_preserve_echo_area (13); 830 redisplay_preserve_echo_area (13);
@@ -1578,17 +1577,12 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1578#ifndef WINDOWSNT 1577#ifndef WINDOWSNT
1579 int wait_child_setup[2]; 1578 int wait_child_setup[2];
1580#endif 1579#endif
1581#ifdef SIGCHLD
1582 sigset_t blocked; 1580 sigset_t blocked;
1583#endif
1584 /* Use volatile to protect variables from being clobbered by vfork. */ 1581 /* Use volatile to protect variables from being clobbered by vfork. */
1585 volatile int forkin, forkout; 1582 volatile int forkin, forkout;
1586 volatile int pty_flag = 0; 1583 volatile bool pty_flag = 0;
1587 volatile Lisp_Object lisp_pty_name = Qnil; 1584 volatile Lisp_Object lisp_pty_name = Qnil;
1588 volatile Lisp_Object encoded_current_dir; 1585 volatile Lisp_Object encoded_current_dir;
1589#if HAVE_WORKING_VFORK
1590 char **volatile save_environ;
1591#endif
1592 1586
1593 inchannel = outchannel = -1; 1587 inchannel = outchannel = -1;
1594 1588
@@ -1680,19 +1674,11 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1680 1674
1681 block_input (); 1675 block_input ();
1682 1676
1683#ifdef SIGCHLD
1684 /* Block SIGCHLD until we have a chance to store the new fork's 1677 /* Block SIGCHLD until we have a chance to store the new fork's
1685 pid in its process structure. */ 1678 pid in its process structure. */
1686 sigemptyset (&blocked); 1679 sigemptyset (&blocked);
1687 sigaddset (&blocked, SIGCHLD); 1680 sigaddset (&blocked, SIGCHLD);
1688 pthread_sigmask (SIG_BLOCK, &blocked, 0); 1681 pthread_sigmask (SIG_BLOCK, &blocked, 0);
1689#endif
1690
1691#if HAVE_WORKING_VFORK
1692 /* child_setup must clobber environ on systems with true vfork.
1693 Protect it from permanent change. */
1694 save_environ = environ;
1695#endif
1696 1682
1697#ifndef WINDOWSNT 1683#ifndef WINDOWSNT
1698 pid = vfork (); 1684 pid = vfork ();
@@ -1800,10 +1786,8 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1800 /* Emacs ignores SIGPIPE, but the child should not. */ 1786 /* Emacs ignores SIGPIPE, but the child should not. */
1801 signal (SIGPIPE, SIG_DFL); 1787 signal (SIGPIPE, SIG_DFL);
1802 1788
1803#ifdef SIGCHLD
1804 /* Stop blocking signals in the child. */ 1789 /* Stop blocking signals in the child. */
1805 pthread_sigmask (SIG_SETMASK, &empty_mask, 0); 1790 pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
1806#endif
1807 1791
1808 if (pty_flag) 1792 if (pty_flag)
1809 child_setup_tty (xforkout); 1793 child_setup_tty (xforkout);
@@ -1819,18 +1803,12 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1819 1803
1820 /* Back in the parent process. */ 1804 /* Back in the parent process. */
1821 1805
1822#if HAVE_WORKING_VFORK
1823 environ = save_environ;
1824#endif
1825
1826 XPROCESS (process)->pid = pid; 1806 XPROCESS (process)->pid = pid;
1827 if (0 <= pid) 1807 if (pid >= 0)
1828 XPROCESS (process)->alive = 1; 1808 XPROCESS (process)->alive = 1;
1829 1809
1830 /* Stop blocking signals in the parent. */ 1810 /* Stop blocking signals in the parent. */
1831#ifdef SIGCHLD
1832 pthread_sigmask (SIG_SETMASK, &empty_mask, 0); 1811 pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
1833#endif
1834 unblock_input (); 1812 unblock_input ();
1835 1813
1836 if (pid < 0) 1814 if (pid < 0)
@@ -1874,7 +1852,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1874 /* Wait for child_setup to complete in case that vfork is 1852 /* Wait for child_setup to complete in case that vfork is
1875 actually defined as fork. The descriptor wait_child_setup[1] 1853 actually defined as fork. The descriptor wait_child_setup[1]
1876 of a pipe is closed at the child side either by close-on-exec 1854 of a pipe is closed at the child side either by close-on-exec
1877 on successful execvp or the _exit call in child_setup. */ 1855 on successful execve or the _exit call in child_setup. */
1878 { 1856 {
1879 char dummy; 1857 char dummy;
1880 1858
@@ -1894,7 +1872,7 @@ void
1894create_pty (Lisp_Object process) 1872create_pty (Lisp_Object process)
1895{ 1873{
1896 int inchannel, outchannel; 1874 int inchannel, outchannel;
1897 int pty_flag = 0; 1875 bool pty_flag = 0;
1898 1876
1899 inchannel = outchannel = -1; 1877 inchannel = outchannel = -1;
1900 1878
@@ -2177,7 +2155,7 @@ Returns nil upon error setting address, ADDRESS otherwise. */)
2177 channel = XPROCESS (process)->infd; 2155 channel = XPROCESS (process)->infd;
2178 2156
2179 len = get_lisp_to_sockaddr_size (address, &family); 2157 len = get_lisp_to_sockaddr_size (address, &family);
2180 if (datagram_address[channel].len != len) 2158 if (len == 0 || datagram_address[channel].len != len)
2181 return Qnil; 2159 return Qnil;
2182 conv_lisp_to_sockaddr (family, address, datagram_address[channel].sa, len); 2160 conv_lisp_to_sockaddr (family, address, datagram_address[channel].sa, len);
2183 return address; 2161 return address;
@@ -2842,8 +2820,9 @@ usage: (make-network-process &rest ARGS) */)
2842 Lisp_Object tem; 2820 Lisp_Object tem;
2843 Lisp_Object name, buffer, host, service, address; 2821 Lisp_Object name, buffer, host, service, address;
2844 Lisp_Object filter, sentinel; 2822 Lisp_Object filter, sentinel;
2845 int is_non_blocking_client = 0; 2823 bool is_non_blocking_client = 0;
2846 int is_server = 0, backlog = 5; 2824 bool is_server = 0;
2825 int backlog = 5;
2847 int socktype; 2826 int socktype;
2848 int family = -1; 2827 int family = -1;
2849 2828
@@ -3290,7 +3269,8 @@ usage: (make-network-process &rest ARGS) */)
3290 { 3269 {
3291 int rfamily, rlen; 3270 int rfamily, rlen;
3292 rlen = get_lisp_to_sockaddr_size (remote, &rfamily); 3271 rlen = get_lisp_to_sockaddr_size (remote, &rfamily);
3293 if (rfamily == lres->ai_family && rlen == lres->ai_addrlen) 3272 if (rlen != 0 && rfamily == lres->ai_family
3273 && rlen == lres->ai_addrlen)
3294 conv_lisp_to_sockaddr (rfamily, remote, 3274 conv_lisp_to_sockaddr (rfamily, remote,
3295 datagram_address[s].sa, rlen); 3275 datagram_address[s].sa, rlen);
3296 } 3276 }
@@ -3520,7 +3500,7 @@ format; see the description of ADDRESS in `make-network-process'. */)
3520 struct ifreq *ifreq; 3500 struct ifreq *ifreq;
3521 void *buf = NULL; 3501 void *buf = NULL;
3522 ptrdiff_t buf_size = 512; 3502 ptrdiff_t buf_size = 512;
3523 int s, i; 3503 int s;
3524 Lisp_Object res; 3504 Lisp_Object res;
3525 3505
3526 s = socket (AF_INET, SOCK_STREAM, 0); 3506 s = socket (AF_INET, SOCK_STREAM, 0);
@@ -3558,7 +3538,6 @@ format; see the description of ADDRESS in `make-network-process'. */)
3558 int len = sizeof (*ifreq); 3538 int len = sizeof (*ifreq);
3559#endif 3539#endif
3560 char namebuf[sizeof (ifq->ifr_name) + 1]; 3540 char namebuf[sizeof (ifq->ifr_name) + 1];
3561 i += len;
3562 ifreq = (struct ifreq *) ((char *) ifreq + len); 3541 ifreq = (struct ifreq *) ((char *) ifreq + len);
3563 3542
3564 if (ifq->ifr_addr.sa_family != AF_INET) 3543 if (ifq->ifr_addr.sa_family != AF_INET)
@@ -3668,7 +3647,7 @@ FLAGS is the current flags of the interface. */)
3668 Lisp_Object res = Qnil; 3647 Lisp_Object res = Qnil;
3669 Lisp_Object elt; 3648 Lisp_Object elt;
3670 int s; 3649 int s;
3671 int any = 0; 3650 bool any = 0;
3672#if (! (defined SIOCGIFHWADDR && defined HAVE_STRUCT_IFREQ_IFR_HWADDR) \ 3651#if (! (defined SIOCGIFHWADDR && defined HAVE_STRUCT_IFREQ_IFR_HWADDR) \
3673 && defined HAVE_GETIFADDRS && defined LLADDR) 3652 && defined HAVE_GETIFADDRS && defined LLADDR)
3674 struct ifaddrs *ifap; 3653 struct ifaddrs *ifap;
@@ -3922,7 +3901,7 @@ Return non-nil if we received any output before the timeout expired. */)
3922 { 3901 {
3923 if (INTEGERP (seconds)) 3902 if (INTEGERP (seconds))
3924 { 3903 {
3925 if (0 < XINT (seconds)) 3904 if (XINT (seconds) > 0)
3926 { 3905 {
3927 secs = XINT (seconds); 3906 secs = XINT (seconds);
3928 nsecs = 0; 3907 nsecs = 0;
@@ -3930,7 +3909,7 @@ Return non-nil if we received any output before the timeout expired. */)
3930 } 3909 }
3931 else if (FLOATP (seconds)) 3910 else if (FLOATP (seconds))
3932 { 3911 {
3933 if (0 < XFLOAT_DATA (seconds)) 3912 if (XFLOAT_DATA (seconds) > 0)
3934 { 3913 {
3935 EMACS_TIME t = EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (seconds)); 3914 EMACS_TIME t = EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (seconds));
3936 secs = min (EMACS_SECS (t), WAIT_READING_MAX); 3915 secs = min (EMACS_SECS (t), WAIT_READING_MAX);
@@ -3954,7 +3933,7 @@ Return non-nil if we received any output before the timeout expired. */)
3954 3933
3955/* Accept a connection for server process SERVER on CHANNEL. */ 3934/* Accept a connection for server process SERVER on CHANNEL. */
3956 3935
3957static int connect_counter = 0; 3936static EMACS_INT connect_counter = 0;
3958 3937
3959static void 3938static void
3960server_accept_connection (Lisp_Object server, int channel) 3939server_accept_connection (Lisp_Object server, int channel)
@@ -4209,7 +4188,7 @@ wait_reading_process_output_1 (void)
4209 process. The return value is true if we read some input from 4188 process. The return value is true if we read some input from
4210 that process. 4189 that process.
4211 4190
4212 If JUST_WAIT_PROC is non-nil, handle only output from WAIT_PROC 4191 If JUST_WAIT_PROC is nonzero, handle only output from WAIT_PROC
4213 (suspending output from other processes). A negative value 4192 (suspending output from other processes). A negative value
4214 means don't run any timers either. 4193 means don't run any timers either.
4215 4194
@@ -4217,22 +4196,23 @@ wait_reading_process_output_1 (void)
4217 received input from that process before the timeout elapsed. 4196 received input from that process before the timeout elapsed.
4218 Otherwise, return true if we received input from any process. */ 4197 Otherwise, return true if we received input from any process. */
4219 4198
4220int 4199bool
4221wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, 4200wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4222 bool do_display, 4201 bool do_display,
4223 Lisp_Object wait_for_cell, 4202 Lisp_Object wait_for_cell,
4224 struct Lisp_Process *wait_proc, int just_wait_proc) 4203 struct Lisp_Process *wait_proc, int just_wait_proc)
4225{ 4204{
4226 register int channel, nfds; 4205 int channel, nfds;
4227 SELECT_TYPE Available; 4206 SELECT_TYPE Available;
4228 SELECT_TYPE Writeok; 4207 SELECT_TYPE Writeok;
4229 int check_write; 4208 bool check_write;
4230 int check_delay, no_avail; 4209 int check_delay;
4210 bool no_avail;
4231 int xerrno; 4211 int xerrno;
4232 Lisp_Object proc; 4212 Lisp_Object proc;
4233 EMACS_TIME timeout, end_time; 4213 EMACS_TIME timeout, end_time;
4234 int wait_channel = -1; 4214 int wait_channel = -1;
4235 int got_some_input = 0; 4215 bool got_some_input = 0;
4236 ptrdiff_t count = SPECPDL_INDEX (); 4216 ptrdiff_t count = SPECPDL_INDEX ();
4237 4217
4238 FD_ZERO (&Available); 4218 FD_ZERO (&Available);
@@ -4241,7 +4221,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4241 if (time_limit == 0 && nsecs == 0 && wait_proc && !NILP (Vinhibit_quit) 4221 if (time_limit == 0 && nsecs == 0 && wait_proc && !NILP (Vinhibit_quit)
4242 && !(CONSP (wait_proc->status) 4222 && !(CONSP (wait_proc->status)
4243 && EQ (XCAR (wait_proc->status), Qexit))) 4223 && EQ (XCAR (wait_proc->status), Qexit)))
4244 message ("Blocking call to accept-process-output with quit inhibited!!"); 4224 message1 ("Blocking call to accept-process-output with quit inhibited!!");
4245 4225
4246 /* If wait_proc is a process to watch, set wait_channel accordingly. */ 4226 /* If wait_proc is a process to watch, set wait_channel accordingly. */
4247 if (wait_proc != NULL) 4227 if (wait_proc != NULL)
@@ -4256,12 +4236,12 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4256 time_limit = 0; 4236 time_limit = 0;
4257 nsecs = -1; 4237 nsecs = -1;
4258 } 4238 }
4259 else if (TYPE_MAXIMUM (time_t) < time_limit) 4239 else if (time_limit > TYPE_MAXIMUM (time_t))
4260 time_limit = TYPE_MAXIMUM (time_t); 4240 time_limit = TYPE_MAXIMUM (time_t);
4261 4241
4262 /* Since we may need to wait several times, 4242 /* Since we may need to wait several times,
4263 compute the absolute time to return at. */ 4243 compute the absolute time to return at. */
4264 if (time_limit || 0 < nsecs) 4244 if (time_limit || nsecs > 0)
4265 { 4245 {
4266 timeout = make_emacs_time (time_limit, nsecs); 4246 timeout = make_emacs_time (time_limit, nsecs);
4267 end_time = add_emacs_time (current_emacs_time (), timeout); 4247 end_time = add_emacs_time (current_emacs_time (), timeout);
@@ -4269,7 +4249,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4269 4249
4270 while (1) 4250 while (1)
4271 { 4251 {
4272 int timeout_reduced_for_timers = 0; 4252 bool timeout_reduced_for_timers = 0;
4273 4253
4274 /* If calling from keyboard input, do not quit 4254 /* If calling from keyboard input, do not quit
4275 since we want to return C-g as an input character. 4255 since we want to return C-g as an input character.
@@ -4293,7 +4273,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4293 4273
4294 timeout = make_emacs_time (0, 0); 4274 timeout = make_emacs_time (0, 0);
4295 } 4275 }
4296 else if (time_limit || 0 < nsecs) 4276 else if (time_limit || nsecs > 0)
4297 { 4277 {
4298 EMACS_TIME now = current_emacs_time (); 4278 EMACS_TIME now = current_emacs_time ();
4299 if (EMACS_TIME_LE (end_time, now)) 4279 if (EMACS_TIME_LE (end_time, now))
@@ -4345,7 +4325,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4345 break; 4325 break;
4346 4326
4347 /* A negative timeout means do not wait at all. */ 4327 /* A negative timeout means do not wait at all. */
4348 if (0 <= nsecs) 4328 if (nsecs >= 0)
4349 { 4329 {
4350 if (EMACS_TIME_VALID_P (timer_delay)) 4330 if (EMACS_TIME_VALID_P (timer_delay))
4351 { 4331 {
@@ -4427,19 +4407,13 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4427 if (nread == 0) 4407 if (nread == 0)
4428 break; 4408 break;
4429 4409
4430 if (0 < nread) 4410 if (nread > 0)
4431 { 4411 {
4432 total_nread += nread; 4412 total_nread += nread;
4433 got_some_input = 1; 4413 got_some_input = 1;
4434 } 4414 }
4435#ifdef EIO 4415 else if (nread == -1 && (errno == EIO || errno == EAGAIN))
4436 else if (nread == -1 && EIO == errno)
4437 break; 4416 break;
4438#endif
4439#ifdef EAGAIN
4440 else if (nread == -1 && EAGAIN == errno)
4441 break;
4442#endif
4443#ifdef EWOULDBLOCK 4417#ifdef EWOULDBLOCK
4444 else if (nread == -1 && EWOULDBLOCK == errno) 4418 else if (nread == -1 && EWOULDBLOCK == errno)
4445 break; 4419 break;
@@ -4628,7 +4602,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4628 yielding EBADF here or at select() call above. 4602 yielding EBADF here or at select() call above.
4629 So, SIGHUP is ignored (see def of PTY_TTY_NAME_SPRINTF 4603 So, SIGHUP is ignored (see def of PTY_TTY_NAME_SPRINTF
4630 in m/ibmrt-aix.h), and here we just ignore the select error. 4604 in m/ibmrt-aix.h), and here we just ignore the select error.
4631 Cleanup occurs c/o status_notify after SIGCLD. */ 4605 Cleanup occurs c/o status_notify after SIGCHLD. */
4632 no_avail = 1; /* Cannot depend on values returned */ 4606 no_avail = 1; /* Cannot depend on values returned */
4633#else 4607#else
4634 emacs_abort (); 4608 emacs_abort ();
@@ -4653,7 +4627,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4653 unsigned old_timers_run = timers_run; 4627 unsigned old_timers_run = timers_run;
4654 struct buffer *old_buffer = current_buffer; 4628 struct buffer *old_buffer = current_buffer;
4655 Lisp_Object old_window = selected_window; 4629 Lisp_Object old_window = selected_window;
4656 int leave = 0; 4630 bool leave = 0;
4657 4631
4658 if (detect_input_pending_run_timers (do_display)) 4632 if (detect_input_pending_run_timers (do_display))
4659 { 4633 {
@@ -4798,11 +4772,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4798 Therefore, if we get an error reading and errno = 4772 Therefore, if we get an error reading and errno =
4799 EIO, just continue, because the child process has 4773 EIO, just continue, because the child process has
4800 exited and should clean itself up soon (e.g. when we 4774 exited and should clean itself up soon (e.g. when we
4801 get a SIGCHLD). 4775 get a SIGCHLD). */
4802
4803 However, it has been known to happen that the SIGCHLD
4804 got lost. So raise the signal again just in case.
4805 It can't hurt. */
4806 else if (nread == -1 && errno == EIO) 4776 else if (nread == -1 && errno == EIO)
4807 { 4777 {
4808 struct Lisp_Process *p = XPROCESS (proc); 4778 struct Lisp_Process *p = XPROCESS (proc);
@@ -4820,16 +4790,12 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4820 p->tick = ++process_tick; 4790 p->tick = ++process_tick;
4821 pset_status (p, Qfailed); 4791 pset_status (p, Qfailed);
4822 } 4792 }
4823 else
4824 handle_child_signal (SIGCHLD);
4825 } 4793 }
4826#endif /* HAVE_PTYS */ 4794#endif /* HAVE_PTYS */
4827 /* If we can detect process termination, don't consider the 4795 /* If we can detect process termination, don't consider the
4828 process gone just because its pipe is closed. */ 4796 process gone just because its pipe is closed. */
4829#ifdef SIGCHLD
4830 else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc)) 4797 else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc))
4831 ; 4798 ;
4832#endif
4833 else 4799 else
4834 { 4800 {
4835 /* Preserve status of processes already terminated. */ 4801 /* Preserve status of processes already terminated. */
@@ -4982,7 +4948,7 @@ read_process_output (Lisp_Object proc, register int channel)
4982 else 4948 else
4983#endif 4949#endif
4984 { 4950 {
4985 int buffered = 0 <= proc_buffered_char[channel]; 4951 bool buffered = proc_buffered_char[channel] >= 0;
4986 if (buffered) 4952 if (buffered)
4987 { 4953 {
4988 chars[carryover] = proc_buffered_char[channel]; 4954 chars[carryover] = proc_buffered_char[channel];
@@ -5298,7 +5264,7 @@ read_process_output (Lisp_Object proc, register int channel)
5298 5264
5299static void 5265static void
5300write_queue_push (struct Lisp_Process *p, Lisp_Object input_obj, 5266write_queue_push (struct Lisp_Process *p, Lisp_Object input_obj,
5301 const char *buf, ptrdiff_t len, int front) 5267 const char *buf, ptrdiff_t len, bool front)
5302{ 5268{
5303 ptrdiff_t offset; 5269 ptrdiff_t offset;
5304 Lisp_Object entry, obj; 5270 Lisp_Object entry, obj;
@@ -5323,10 +5289,10 @@ write_queue_push (struct Lisp_Process *p, Lisp_Object input_obj,
5323} 5289}
5324 5290
5325/* Remove the first element in the write_queue of process P, put its 5291/* Remove the first element in the write_queue of process P, put its
5326 contents in OBJ, BUF and LEN, and return non-zero. If the 5292 contents in OBJ, BUF and LEN, and return true. If the
5327 write_queue is empty, return zero. */ 5293 write_queue is empty, return false. */
5328 5294
5329static int 5295static bool
5330write_queue_pop (struct Lisp_Process *p, Lisp_Object *obj, 5296write_queue_pop (struct Lisp_Process *p, Lisp_Object *obj,
5331 const char **buf, ptrdiff_t *len) 5297 const char **buf, ptrdiff_t *len)
5332{ 5298{
@@ -5489,7 +5455,7 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len,
5489 rv = sendto (outfd, cur_buf, cur_len, 5455 rv = sendto (outfd, cur_buf, cur_len,
5490 0, datagram_address[outfd].sa, 5456 0, datagram_address[outfd].sa,
5491 datagram_address[outfd].len); 5457 datagram_address[outfd].len);
5492 if (0 <= rv) 5458 if (rv >= 0)
5493 written = rv; 5459 written = rv;
5494 else if (errno == EMSGSIZE) 5460 else if (errno == EMSGSIZE)
5495 report_file_error ("sending datagram", Fcons (proc, Qnil)); 5461 report_file_error ("sending datagram", Fcons (proc, Qnil));
@@ -5517,13 +5483,10 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len,
5517 5483
5518 if (rv < 0) 5484 if (rv < 0)
5519 { 5485 {
5520 if (0 5486 if (errno == EAGAIN
5521#ifdef EWOULDBLOCK 5487#ifdef EWOULDBLOCK
5522 || errno == EWOULDBLOCK 5488 || errno == EWOULDBLOCK
5523#endif 5489#endif
5524#ifdef EAGAIN
5525 || errno == EAGAIN
5526#endif
5527 ) 5490 )
5528 /* Buffer is full. Wait, accepting input; 5491 /* Buffer is full. Wait, accepting input;
5529 that may allow the program 5492 that may allow the program
@@ -5592,19 +5555,19 @@ it is sent in several bunches. This may happen even for shorter regions.
5592Output from processes can arrive in between bunches. */) 5555Output from processes can arrive in between bunches. */)
5593 (Lisp_Object process, Lisp_Object start, Lisp_Object end) 5556 (Lisp_Object process, Lisp_Object start, Lisp_Object end)
5594{ 5557{
5595 Lisp_Object proc; 5558 Lisp_Object proc = get_process (process);
5596 ptrdiff_t start1, end1; 5559 ptrdiff_t start_byte, end_byte;
5597 5560
5598 proc = get_process (process);
5599 validate_region (&start, &end); 5561 validate_region (&start, &end);
5600 5562
5563 start_byte = CHAR_TO_BYTE (XINT (start));
5564 end_byte = CHAR_TO_BYTE (XINT (end));
5565
5601 if (XINT (start) < GPT && XINT (end) > GPT) 5566 if (XINT (start) < GPT && XINT (end) > GPT)
5602 move_gap (XINT (start)); 5567 move_gap_both (XINT (start), start_byte);
5603 5568
5604 start1 = CHAR_TO_BYTE (XINT (start)); 5569 send_process (proc, (char *) BYTE_POS_ADDR (start_byte),
5605 end1 = CHAR_TO_BYTE (XINT (end)); 5570 end_byte - start_byte, Fcurrent_buffer ());
5606 send_process (proc, (char *) BYTE_POS_ADDR (start1), end1 - start1,
5607 Fcurrent_buffer ());
5608 5571
5609 return Qnil; 5572 return Qnil;
5610} 5573}
@@ -5690,21 +5653,21 @@ return t unconditionally. */)
5690 If CURRENT_GROUP is lambda, that means send to the process group 5653 If CURRENT_GROUP is lambda, that means send to the process group
5691 that currently owns the terminal, but only if it is NOT the shell itself. 5654 that currently owns the terminal, but only if it is NOT the shell itself.
5692 5655
5693 If NOMSG is zero, insert signal-announcements into process's buffers 5656 If NOMSG is false, insert signal-announcements into process's buffers
5694 right away. 5657 right away.
5695 5658
5696 If we can, we try to signal PROCESS by sending control characters 5659 If we can, we try to signal PROCESS by sending control characters
5697 down the pty. This allows us to signal inferiors who have changed 5660 down the pty. This allows us to signal inferiors who have changed
5698 their uid, for which killpg would return an EPERM error. */ 5661 their uid, for which kill would return an EPERM error. */
5699 5662
5700static void 5663static void
5701process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group, 5664process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group,
5702 int nomsg) 5665 bool nomsg)
5703{ 5666{
5704 Lisp_Object proc; 5667 Lisp_Object proc;
5705 register struct Lisp_Process *p; 5668 struct Lisp_Process *p;
5706 pid_t gid; 5669 pid_t gid;
5707 int no_pgrp = 0; 5670 bool no_pgrp = 0;
5708 5671
5709 proc = get_process (process); 5672 proc = get_process (process);
5710 p = XPROCESS (proc); 5673 p = XPROCESS (proc);
@@ -5833,7 +5796,7 @@ process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group,
5833 if (!NILP (current_group)) 5796 if (!NILP (current_group))
5834 { 5797 {
5835 if (ioctl (p->infd, TIOCSIGSEND, signo) == -1) 5798 if (ioctl (p->infd, TIOCSIGSEND, signo) == -1)
5836 EMACS_KILLPG (gid, signo); 5799 kill (-gid, signo);
5837 } 5800 }
5838 else 5801 else
5839 { 5802 {
@@ -5841,7 +5804,7 @@ process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group,
5841 kill (gid, signo); 5804 kill (gid, signo);
5842 } 5805 }
5843#else /* ! defined (TIOCSIGSEND) */ 5806#else /* ! defined (TIOCSIGSEND) */
5844 EMACS_KILLPG (gid, signo); 5807 kill (-gid, signo);
5845#endif /* ! defined (TIOCSIGSEND) */ 5808#endif /* ! defined (TIOCSIGSEND) */
5846} 5809}
5847 5810
@@ -5946,6 +5909,27 @@ traffic. */)
5946 return process; 5909 return process;
5947} 5910}
5948 5911
5912/* Return the integer value of the signal whose abbreviation is ABBR,
5913 or a negative number if there is no such signal. */
5914static int
5915abbr_to_signal (char const *name)
5916{
5917 int i, signo;
5918 char sigbuf[20]; /* Large enough for all valid signal abbreviations. */
5919
5920 if (!strncmp (name, "SIG", 3) || !strncmp (name, "sig", 3))
5921 name += 3;
5922
5923 for (i = 0; i < sizeof sigbuf; i++)
5924 {
5925 sigbuf[i] = c_toupper (name[i]);
5926 if (! sigbuf[i])
5927 return str2sig (sigbuf, &signo) == 0 ? signo : -1;
5928 }
5929
5930 return -1;
5931}
5932
5949DEFUN ("signal-process", Fsignal_process, Ssignal_process, 5933DEFUN ("signal-process", Fsignal_process, Ssignal_process,
5950 2, 2, "sProcess (name or number): \nnSignal code: ", 5934 2, 2, "sProcess (name or number): \nnSignal code: ",
5951 doc: /* Send PROCESS the signal with code SIGCODE. 5935 doc: /* Send PROCESS the signal with code SIGCODE.
@@ -5956,6 +5940,7 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */)
5956 (Lisp_Object process, Lisp_Object sigcode) 5940 (Lisp_Object process, Lisp_Object sigcode)
5957{ 5941{
5958 pid_t pid; 5942 pid_t pid;
5943 int signo;
5959 5944
5960 if (STRINGP (process)) 5945 if (STRINGP (process))
5961 { 5946 {
@@ -5985,12 +5970,11 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */)
5985 error ("Cannot signal process %s", SDATA (XPROCESS (process)->name)); 5970 error ("Cannot signal process %s", SDATA (XPROCESS (process)->name));
5986 } 5971 }
5987 5972
5988#define parse_signal(NAME, VALUE) \
5989 else if (!xstrcasecmp (name, NAME)) \
5990 XSETINT (sigcode, VALUE)
5991
5992 if (INTEGERP (sigcode)) 5973 if (INTEGERP (sigcode))
5993 CHECK_TYPE_RANGED_INTEGER (int, sigcode); 5974 {
5975 CHECK_TYPE_RANGED_INTEGER (int, sigcode);
5976 signo = XINT (sigcode);
5977 }
5994 else 5978 else
5995 { 5979 {
5996 char *name; 5980 char *name;
@@ -5998,96 +5982,12 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */)
5998 CHECK_SYMBOL (sigcode); 5982 CHECK_SYMBOL (sigcode);
5999 name = SSDATA (SYMBOL_NAME (sigcode)); 5983 name = SSDATA (SYMBOL_NAME (sigcode));
6000 5984
6001 if (!strncmp (name, "SIG", 3) || !strncmp (name, "sig", 3)) 5985 signo = abbr_to_signal (name);
6002 name += 3; 5986 if (signo < 0)
6003
6004 if (0)
6005 ;
6006#ifdef SIGUSR1
6007 parse_signal ("usr1", SIGUSR1);
6008#endif
6009#ifdef SIGUSR2
6010 parse_signal ("usr2", SIGUSR2);
6011#endif
6012 parse_signal ("term", SIGTERM);
6013#ifdef SIGHUP
6014 parse_signal ("hup", SIGHUP);
6015#endif
6016 parse_signal ("int", SIGINT);
6017#ifdef SIGQUIT
6018 parse_signal ("quit", SIGQUIT);
6019#endif
6020 parse_signal ("ill", SIGILL);
6021 parse_signal ("abrt", SIGABRT);
6022#ifdef SIGEMT
6023 parse_signal ("emt", SIGEMT);
6024#endif
6025#ifdef SIGKILL
6026 parse_signal ("kill", SIGKILL);
6027#endif
6028 parse_signal ("fpe", SIGFPE);
6029#ifdef SIGBUS
6030 parse_signal ("bus", SIGBUS);
6031#endif
6032 parse_signal ("segv", SIGSEGV);
6033#ifdef SIGSYS
6034 parse_signal ("sys", SIGSYS);
6035#endif
6036#ifdef SIGPIPE
6037 parse_signal ("pipe", SIGPIPE);
6038#endif
6039#ifdef SIGALRM
6040 parse_signal ("alrm", SIGALRM);
6041#endif
6042#ifdef SIGURG
6043 parse_signal ("urg", SIGURG);
6044#endif
6045#ifdef SIGSTOP
6046 parse_signal ("stop", SIGSTOP);
6047#endif
6048#ifdef SIGTSTP
6049 parse_signal ("tstp", SIGTSTP);
6050#endif
6051#ifdef SIGCONT
6052 parse_signal ("cont", SIGCONT);
6053#endif
6054#ifdef SIGCHLD
6055 parse_signal ("chld", SIGCHLD);
6056#endif
6057#ifdef SIGTTIN
6058 parse_signal ("ttin", SIGTTIN);
6059#endif
6060#ifdef SIGTTOU
6061 parse_signal ("ttou", SIGTTOU);
6062#endif
6063#ifdef SIGIO
6064 parse_signal ("io", SIGIO);
6065#endif
6066#ifdef SIGXCPU
6067 parse_signal ("xcpu", SIGXCPU);
6068#endif
6069#ifdef SIGXFSZ
6070 parse_signal ("xfsz", SIGXFSZ);
6071#endif
6072#ifdef SIGVTALRM
6073 parse_signal ("vtalrm", SIGVTALRM);
6074#endif
6075#ifdef SIGPROF
6076 parse_signal ("prof", SIGPROF);
6077#endif
6078#ifdef SIGWINCH
6079 parse_signal ("winch", SIGWINCH);
6080#endif
6081#ifdef SIGINFO
6082 parse_signal ("info", SIGINFO);
6083#endif
6084 else
6085 error ("Undefined signal name %s", name); 5987 error ("Undefined signal name %s", name);
6086 } 5988 }
6087 5989
6088#undef parse_signal 5990 return make_number (kill (pid, signo));
6089
6090 return make_number (kill (pid, XINT (sigcode)));
6091} 5991}
6092 5992
6093DEFUN ("process-send-eof", Fprocess_send_eof, Sprocess_send_eof, 0, 1, 0, 5993DEFUN ("process-send-eof", Fprocess_send_eof, Sprocess_send_eof, 0, 1, 0,
@@ -6169,35 +6069,35 @@ process has been transmitted to the serial port. */)
6169 return process; 6069 return process;
6170} 6070}
6171 6071
6172/* If the status of the process DESIRED has changed, return true and 6072/* The main Emacs thread records child processes in three places:
6173 set *STATUS to its exit status; otherwise, return false. 6073
6174 If HAVE is nonnegative, assume that HAVE = waitpid (HAVE, STATUS, ...) 6074 - Vprocess_alist, for asynchronous subprocesses, which are child
6175 has already been invoked, and do not invoke waitpid again. */ 6075 processes visible to Lisp.
6176 6076
6177static bool 6077 - deleted_pid_list, for child processes invisible to Lisp,
6178process_status_retrieved (pid_t desired, pid_t have, int *status) 6078 typically because of delete-process. These are recorded so that
6179{ 6079 the processes can be reaped when they exit, so that the operating
6180 if (have < 0) 6080 system's process table is not cluttered by zombies.
6181 { 6081
6182 /* Invoke waitpid only with a known process ID; do not invoke 6082 - the local variable PID in Fcall_process, call_process_cleanup and
6183 waitpid with a nonpositive argument. Otherwise, Emacs might 6083 call_process_kill, for synchronous subprocesses.
6184 reap an unwanted process by mistake. For example, invoking 6084 record_unwind_protect is used to make sure this process is not
6185 waitpid (-1, ...) can mess up glib by reaping glib's subprocesses, 6085 forgotten: if the user interrupts call-process and the child
6186 so that another thread running glib won't find them. */ 6086 process refuses to exit immediately even with two C-g's,
6187 do 6087 call_process_kill adds PID's contents to deleted_pid_list before
6188 have = waitpid (desired, status, WNOHANG | WUNTRACED); 6088 returning.
6189 while (have < 0 && errno == EINTR); 6089
6190 } 6090 The main Emacs thread invokes waitpid only on child processes that
6191 6091 it creates and that have not been reaped. This avoid races on
6192 return have == desired; 6092 platforms such as GTK, where other threads create their own
6193} 6093 subprocesses which the main thread should not reap. For example,
6194 6094 if the main thread attempted to reap an already-reaped child, it
6195/* If PID is nonnegative, the child process PID with wait status W has 6095 might inadvertently reap a GTK-created process that happened to
6196 changed its status; record this and return true. 6096 have the same process ID. */
6197 6097
6198 If PID is negative, ignore W, and look for known child processes 6098/* Handle a SIGCHLD signal by looking for known child processes of
6199 of Emacs whose status have changed. For each one found, record its new 6099 Emacs whose status have changed. For each one found, record its
6200 status. 6100 new status.
6201 6101
6202 All we do is change the status; we do not run sentinels or print 6102 All we do is change the status; we do not run sentinels or print
6203 notifications. That is saved for the next time keyboard input is 6103 notifications. That is saved for the next time keyboard input is
@@ -6220,20 +6120,15 @@ process_status_retrieved (pid_t desired, pid_t have, int *status)
6220 ** Malloc WARNING: This should never call malloc either directly or 6120 ** Malloc WARNING: This should never call malloc either directly or
6221 indirectly; if it does, that is a bug */ 6121 indirectly; if it does, that is a bug */
6222 6122
6223void 6123static void
6224record_child_status_change (pid_t pid, int w) 6124handle_child_signal (int sig)
6225{ 6125{
6226#ifdef SIGCHLD
6227
6228 /* Record at most one child only if we already know one child that
6229 has exited. */
6230 bool record_at_most_one_child = 0 <= pid;
6231
6232 Lisp_Object tail; 6126 Lisp_Object tail;
6233 6127
6234 /* Find the process that signaled us, and record its status. */ 6128 /* Find the process that signaled us, and record its status. */
6235 6129
6236 /* The process can have been deleted by Fdelete_process. */ 6130 /* The process can have been deleted by Fdelete_process, or have
6131 been started asynchronously by Fcall_process. */
6237 for (tail = deleted_pid_list; CONSP (tail); tail = XCDR (tail)) 6132 for (tail = deleted_pid_list; CONSP (tail); tail = XCDR (tail))
6238 { 6133 {
6239 bool all_pids_are_fixnums 6134 bool all_pids_are_fixnums
@@ -6247,12 +6142,8 @@ record_child_status_change (pid_t pid, int w)
6247 deleted_pid = XINT (xpid); 6142 deleted_pid = XINT (xpid);
6248 else 6143 else
6249 deleted_pid = XFLOAT_DATA (xpid); 6144 deleted_pid = XFLOAT_DATA (xpid);
6250 if (process_status_retrieved (deleted_pid, pid, &w)) 6145 if (child_status_changed (deleted_pid, 0, 0))
6251 { 6146 XSETCAR (tail, Qnil);
6252 XSETCAR (tail, Qnil);
6253 if (record_at_most_one_child)
6254 return;
6255 }
6256 } 6147 }
6257 } 6148 }
6258 6149
@@ -6261,17 +6152,19 @@ record_child_status_change (pid_t pid, int w)
6261 { 6152 {
6262 Lisp_Object proc = XCDR (XCAR (tail)); 6153 Lisp_Object proc = XCDR (XCAR (tail));
6263 struct Lisp_Process *p = XPROCESS (proc); 6154 struct Lisp_Process *p = XPROCESS (proc);
6264 if (p->alive && process_status_retrieved (p->pid, pid, &w)) 6155 int status;
6156
6157 if (p->alive && child_status_changed (p->pid, &status, WUNTRACED))
6265 { 6158 {
6266 /* Change the status of the process that was found. */ 6159 /* Change the status of the process that was found. */
6267 p->tick = ++process_tick; 6160 p->tick = ++process_tick;
6268 p->raw_status = w; 6161 p->raw_status = status;
6269 p->raw_status_new = 1; 6162 p->raw_status_new = 1;
6270 6163
6271 /* If process has terminated, stop waiting for its output. */ 6164 /* If process has terminated, stop waiting for its output. */
6272 if (WIFSIGNALED (w) || WIFEXITED (w)) 6165 if (WIFSIGNALED (status) || WIFEXITED (status))
6273 { 6166 {
6274 int clear_desc_flag = 0; 6167 bool clear_desc_flag = 0;
6275 p->alive = 0; 6168 p->alive = 0;
6276 if (p->infd >= 0) 6169 if (p->infd >= 0)
6277 clear_desc_flag = 1; 6170 clear_desc_flag = 1;
@@ -6283,44 +6176,8 @@ record_child_status_change (pid_t pid, int w)
6283 FD_CLR (p->infd, &non_keyboard_wait_mask); 6176 FD_CLR (p->infd, &non_keyboard_wait_mask);
6284 } 6177 }
6285 } 6178 }
6286
6287 /* Tell wait_reading_process_output that it needs to wake up and
6288 look around. */
6289 if (input_available_clear_time)
6290 *input_available_clear_time = make_emacs_time (0, 0);
6291
6292 if (record_at_most_one_child)
6293 return;
6294 } 6179 }
6295 } 6180 }
6296
6297 if (0 <= pid)
6298 {
6299 /* The caller successfully waited for a pid but no asynchronous
6300 process was found for it, so this is a synchronous process. */
6301
6302 synch_process_alive = 0;
6303
6304 /* Report the status of the synchronous process. */
6305 if (WIFEXITED (w))
6306 synch_process_retcode = WEXITSTATUS (w);
6307 else if (WIFSIGNALED (w))
6308 synch_process_termsig = WTERMSIG (w);
6309
6310 /* Tell wait_reading_process_output that it needs to wake up and
6311 look around. */
6312 if (input_available_clear_time)
6313 *input_available_clear_time = make_emacs_time (0, 0);
6314 }
6315#endif
6316}
6317
6318#ifdef SIGCHLD
6319
6320static void
6321handle_child_signal (int sig)
6322{
6323 record_child_status_change (-1, 0);
6324} 6181}
6325 6182
6326static void 6183static void
@@ -6328,8 +6185,6 @@ deliver_child_signal (int sig)
6328{ 6185{
6329 deliver_process_signal (sig, handle_child_signal); 6186 deliver_process_signal (sig, handle_child_signal);
6330} 6187}
6331
6332#endif /* SIGCHLD */
6333 6188
6334 6189
6335static Lisp_Object 6190static Lisp_Object
@@ -6652,10 +6507,10 @@ delete_gpm_wait_descriptor (int desc)
6652 6507
6653# ifdef USABLE_SIGIO 6508# ifdef USABLE_SIGIO
6654 6509
6655/* Return nonzero if *MASK has a bit set 6510/* Return true if *MASK has a bit set
6656 that corresponds to one of the keyboard input descriptors. */ 6511 that corresponds to one of the keyboard input descriptors. */
6657 6512
6658static int 6513static bool
6659keyboard_bit_set (fd_set *mask) 6514keyboard_bit_set (fd_set *mask)
6660{ 6515{
6661 int fd; 6516 int fd;
@@ -6705,7 +6560,7 @@ extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *,
6705 6560
6706 Return true if we received input from any process. */ 6561 Return true if we received input from any process. */
6707 6562
6708int 6563bool
6709wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, 6564wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
6710 bool do_display, 6565 bool do_display,
6711 Lisp_Object wait_for_cell, 6566 Lisp_Object wait_for_cell,
@@ -6723,7 +6578,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
6723 time_limit = TYPE_MAXIMUM (time_t); 6578 time_limit = TYPE_MAXIMUM (time_t);
6724 6579
6725 /* What does time_limit really mean? */ 6580 /* What does time_limit really mean? */
6726 if (time_limit || 0 < nsecs) 6581 if (time_limit || nsecs > 0)
6727 { 6582 {
6728 timeout = make_emacs_time (time_limit, nsecs); 6583 timeout = make_emacs_time (time_limit, nsecs);
6729 end_time = add_emacs_time (current_emacs_time (), timeout); 6584 end_time = add_emacs_time (current_emacs_time (), timeout);
@@ -6737,7 +6592,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
6737 6592
6738 while (1) 6593 while (1)
6739 { 6594 {
6740 int timeout_reduced_for_timers = 0; 6595 bool timeout_reduced_for_timers = 0;
6741 SELECT_TYPE waitchannels; 6596 SELECT_TYPE waitchannels;
6742 int xerrno; 6597 int xerrno;
6743 6598
@@ -6761,7 +6616,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
6761 6616
6762 timeout = make_emacs_time (0, 0); 6617 timeout = make_emacs_time (0, 0);
6763 } 6618 }
6764 else if (time_limit || 0 < nsecs) 6619 else if (time_limit || nsecs > 0)
6765 { 6620 {
6766 EMACS_TIME now = current_emacs_time (); 6621 EMACS_TIME now = current_emacs_time ();
6767 if (EMACS_TIME_LE (end_time, now)) 6622 if (EMACS_TIME_LE (end_time, now))
@@ -6799,7 +6654,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
6799 && requeued_events_pending_p ()) 6654 && requeued_events_pending_p ())
6800 break; 6655 break;
6801 6656
6802 if (EMACS_TIME_VALID_P (timer_delay) && 0 <= nsecs) 6657 if (EMACS_TIME_VALID_P (timer_delay) && nsecs >= 0)
6803 { 6658 {
6804 if (EMACS_TIME_LT (timer_delay, timeout)) 6659 if (EMACS_TIME_LT (timer_delay, timeout))
6805 { 6660 {
@@ -7088,9 +6943,9 @@ unhold_keyboard_input (void)
7088 kbd_is_on_hold = 0; 6943 kbd_is_on_hold = 0;
7089} 6944}
7090 6945
7091/* Return non-zero if keyboard input is on hold, zero otherwise. */ 6946/* Return true if keyboard input is on hold, zero otherwise. */
7092 6947
7093int 6948bool
7094kbd_on_hold_p (void) 6949kbd_on_hold_p (void)
7095{ 6950{
7096 return kbd_is_on_hold; 6951 return kbd_is_on_hold;
@@ -7178,7 +7033,6 @@ init_process_emacs (void)
7178 7033
7179 inhibit_sentinels = 0; 7034 inhibit_sentinels = 0;
7180 7035
7181#ifdef SIGCHLD
7182#ifndef CANNOT_DUMP 7036#ifndef CANNOT_DUMP
7183 if (! noninteractive || initialized) 7037 if (! noninteractive || initialized)
7184#endif 7038#endif
@@ -7187,7 +7041,6 @@ init_process_emacs (void)
7187 emacs_sigaction_init (&action, deliver_child_signal); 7041 emacs_sigaction_init (&action, deliver_child_signal);
7188 sigaction (SIGCHLD, &action, 0); 7042 sigaction (SIGCHLD, &action, 0);
7189 } 7043 }
7190#endif
7191 7044
7192 FD_ZERO (&input_wait_mask); 7045 FD_ZERO (&input_wait_mask);
7193 FD_ZERO (&non_keyboard_wait_mask); 7046 FD_ZERO (&non_keyboard_wait_mask);
@@ -7214,9 +7067,7 @@ init_process_emacs (void)
7214#endif 7067#endif
7215 7068
7216 Vprocess_alist = Qnil; 7069 Vprocess_alist = Qnil;
7217#ifdef SIGCHLD
7218 deleted_pid_list = Qnil; 7070 deleted_pid_list = Qnil;
7219#endif
7220 for (i = 0; i < MAXDESC; i++) 7071 for (i = 0; i < MAXDESC; i++)
7221 { 7072 {
7222 chan_process[i] = Qnil; 7073 chan_process[i] = Qnil;
@@ -7343,9 +7194,7 @@ syms_of_process (void)
7343 DEFSYM (Qlast_nonmenu_event, "last-nonmenu-event"); 7194 DEFSYM (Qlast_nonmenu_event, "last-nonmenu-event");
7344 7195
7345 staticpro (&Vprocess_alist); 7196 staticpro (&Vprocess_alist);
7346#ifdef SIGCHLD
7347 staticpro (&deleted_pid_list); 7197 staticpro (&deleted_pid_list);
7348#endif
7349 7198
7350#endif /* subprocesses */ 7199#endif /* subprocesses */
7351 7200