diff options
| author | Kenichi Handa | 2012-11-18 20:29:54 +0900 |
|---|---|---|
| committer | Kenichi Handa | 2012-11-18 20:29:54 +0900 |
| commit | e1d276cbf9e18f13101328f56bed1a1c0a66e63a (patch) | |
| tree | f1fdfc9550866b9e323da072ff2eb38821996246 /src/process.c | |
| parent | 00dc3ead070e2e8017629f4d60d8366ac00c32cb (diff) | |
| parent | dfa8939b2827d23e02f3d7f6622e3a619ec6fd90 (diff) | |
| download | emacs-e1d276cbf9e18f13101328f56bed1a1c0a66e63a.tar.gz emacs-e1d276cbf9e18f13101328f56bed1a1c0a66e63a.zip | |
merge trunk
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 114 |
1 files changed, 9 insertions, 105 deletions
diff --git a/src/process.c b/src/process.c index 728abebe758..0036ce595f5 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -130,18 +130,6 @@ extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *, | |||
| 130 | EMACS_TIME *, void *); | 130 | EMACS_TIME *, void *); |
| 131 | #endif | 131 | #endif |
| 132 | 132 | ||
| 133 | /* This is for DOS_NT ports. FIXME: Remove this old portability cruft | ||
| 134 | by having DOS_NT ports implement waitpid instead of wait. Nowadays | ||
| 135 | POSIXish hosts all define waitpid, WNOHANG, and WUNTRACED, as these | ||
| 136 | have been standard since POSIX.1-1988. */ | ||
| 137 | #ifndef WNOHANG | ||
| 138 | # undef waitpid | ||
| 139 | # define waitpid(pid, status, options) wait (status) | ||
| 140 | #endif | ||
| 141 | #ifndef WUNTRACED | ||
| 142 | # define WUNTRACED 0 | ||
| 143 | #endif | ||
| 144 | |||
| 145 | /* Work around GCC 4.7.0 bug with strict overflow checking; see | 133 | /* Work around GCC 4.7.0 bug with strict overflow checking; see |
| 146 | <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52904>. | 134 | <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52904>. |
| 147 | These lines can be removed once the GCC bug is fixed. */ | 135 | These lines can be removed once the GCC bug is fixed. */ |
| @@ -208,11 +196,9 @@ static EMACS_INT update_tick; | |||
| 208 | #ifndef NON_BLOCKING_CONNECT | 196 | #ifndef NON_BLOCKING_CONNECT |
| 209 | #ifdef HAVE_SELECT | 197 | #ifdef HAVE_SELECT |
| 210 | #if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX) | 198 | #if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX) |
| 211 | #if O_NONBLOCK || O_NDELAY | ||
| 212 | #if defined (EWOULDBLOCK) || defined (EINPROGRESS) | 199 | #if defined (EWOULDBLOCK) || defined (EINPROGRESS) |
| 213 | #define NON_BLOCKING_CONNECT | 200 | #define NON_BLOCKING_CONNECT |
| 214 | #endif /* EWOULDBLOCK || EINPROGRESS */ | 201 | #endif /* EWOULDBLOCK || EINPROGRESS */ |
| 215 | #endif /* O_NONBLOCK || O_NDELAY */ | ||
| 216 | #endif /* HAVE_GETPEERNAME || GNU_LINUX */ | 202 | #endif /* HAVE_GETPEERNAME || GNU_LINUX */ |
| 217 | #endif /* HAVE_SELECT */ | 203 | #endif /* HAVE_SELECT */ |
| 218 | #endif /* NON_BLOCKING_CONNECT */ | 204 | #endif /* NON_BLOCKING_CONNECT */ |
| @@ -340,9 +326,6 @@ static struct sockaddr_and_len { | |||
| 340 | #define DATAGRAM_CONN_P(proc) (0) | 326 | #define DATAGRAM_CONN_P(proc) (0) |
| 341 | #endif | 327 | #endif |
| 342 | 328 | ||
| 343 | /* Maximum number of bytes to send to a pty without an eof. */ | ||
| 344 | static int pty_max_bytes; | ||
| 345 | |||
| 346 | /* These setters are used only in this file, so they can be private. */ | 329 | /* These setters are used only in this file, so they can be private. */ |
| 347 | static void | 330 | static void |
| 348 | pset_buffer (struct Lisp_Process *p, Lisp_Object val) | 331 | pset_buffer (struct Lisp_Process *p, Lisp_Object val) |
| @@ -654,13 +637,7 @@ allocate_pty (void) | |||
| 654 | #ifdef PTY_OPEN | 637 | #ifdef PTY_OPEN |
| 655 | PTY_OPEN; | 638 | PTY_OPEN; |
| 656 | #else /* no PTY_OPEN */ | 639 | #else /* no PTY_OPEN */ |
| 657 | { | 640 | fd = emacs_open (pty_name, O_RDWR | O_NONBLOCK, 0); |
| 658 | # if O_NONBLOCK | ||
| 659 | fd = emacs_open (pty_name, O_RDWR | O_NONBLOCK, 0); | ||
| 660 | # else | ||
| 661 | fd = emacs_open (pty_name, O_RDWR | O_NDELAY, 0); | ||
| 662 | # endif | ||
| 663 | } | ||
| 664 | #endif /* no PTY_OPEN */ | 641 | #endif /* no PTY_OPEN */ |
| 665 | 642 | ||
| 666 | if (fd >= 0) | 643 | if (fd >= 0) |
| @@ -1598,7 +1575,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1598 | int inchannel, outchannel; | 1575 | int inchannel, outchannel; |
| 1599 | pid_t pid; | 1576 | pid_t pid; |
| 1600 | int sv[2]; | 1577 | int sv[2]; |
| 1601 | #if !defined (WINDOWSNT) && defined (FD_CLOEXEC) | 1578 | #ifndef WINDOWSNT |
| 1602 | int wait_child_setup[2]; | 1579 | int wait_child_setup[2]; |
| 1603 | #endif | 1580 | #endif |
| 1604 | #ifdef SIGCHLD | 1581 | #ifdef SIGCHLD |
| @@ -1624,13 +1601,9 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1624 | #if ! defined (USG) || defined (USG_SUBTTY_WORKS) | 1601 | #if ! defined (USG) || defined (USG_SUBTTY_WORKS) |
| 1625 | /* On most USG systems it does not work to open the pty's tty here, | 1602 | /* On most USG systems it does not work to open the pty's tty here, |
| 1626 | then close it and reopen it in the child. */ | 1603 | then close it and reopen it in the child. */ |
| 1627 | #if O_NOCTTY | ||
| 1628 | /* Don't let this terminal become our controlling terminal | 1604 | /* Don't let this terminal become our controlling terminal |
| 1629 | (in case we don't have one). */ | 1605 | (in case we don't have one). */ |
| 1630 | forkout = forkin = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); | 1606 | forkout = forkin = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); |
| 1631 | #else | ||
| 1632 | forkout = forkin = emacs_open (pty_name, O_RDWR, 0); | ||
| 1633 | #endif | ||
| 1634 | if (forkin < 0) | 1607 | if (forkin < 0) |
| 1635 | report_file_error ("Opening pty", Qnil); | 1608 | report_file_error ("Opening pty", Qnil); |
| 1636 | #else | 1609 | #else |
| @@ -1659,7 +1632,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1659 | forkin = sv[0]; | 1632 | forkin = sv[0]; |
| 1660 | } | 1633 | } |
| 1661 | 1634 | ||
| 1662 | #if !defined (WINDOWSNT) && defined (FD_CLOEXEC) | 1635 | #ifndef WINDOWSNT |
| 1663 | { | 1636 | { |
| 1664 | int tem; | 1637 | int tem; |
| 1665 | 1638 | ||
| @@ -1678,15 +1651,8 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1678 | } | 1651 | } |
| 1679 | #endif | 1652 | #endif |
| 1680 | 1653 | ||
| 1681 | #if O_NONBLOCK | ||
| 1682 | fcntl (inchannel, F_SETFL, O_NONBLOCK); | 1654 | fcntl (inchannel, F_SETFL, O_NONBLOCK); |
| 1683 | fcntl (outchannel, F_SETFL, O_NONBLOCK); | 1655 | fcntl (outchannel, F_SETFL, O_NONBLOCK); |
| 1684 | #else | ||
| 1685 | #if O_NDELAY | ||
| 1686 | fcntl (inchannel, F_SETFL, O_NDELAY); | ||
| 1687 | fcntl (outchannel, F_SETFL, O_NDELAY); | ||
| 1688 | #endif | ||
| 1689 | #endif | ||
| 1690 | 1656 | ||
| 1691 | /* Record this as an active process, with its channels. | 1657 | /* Record this as an active process, with its channels. |
| 1692 | As a result, child_setup will close Emacs's side of the pipes. */ | 1658 | As a result, child_setup will close Emacs's side of the pipes. */ |
| @@ -1845,9 +1811,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1845 | pid = child_setup (xforkin, xforkout, xforkout, | 1811 | pid = child_setup (xforkin, xforkout, xforkout, |
| 1846 | new_argv, 1, encoded_current_dir); | 1812 | new_argv, 1, encoded_current_dir); |
| 1847 | #else /* not WINDOWSNT */ | 1813 | #else /* not WINDOWSNT */ |
| 1848 | #ifdef FD_CLOEXEC | ||
| 1849 | emacs_close (wait_child_setup[0]); | 1814 | emacs_close (wait_child_setup[0]); |
| 1850 | #endif | ||
| 1851 | child_setup (xforkin, xforkout, xforkout, | 1815 | child_setup (xforkin, xforkout, xforkout, |
| 1852 | new_argv, 1, encoded_current_dir); | 1816 | new_argv, 1, encoded_current_dir); |
| 1853 | #endif /* not WINDOWSNT */ | 1817 | #endif /* not WINDOWSNT */ |
| @@ -1906,7 +1870,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1906 | 1870 | ||
| 1907 | pset_tty_name (XPROCESS (process), lisp_pty_name); | 1871 | pset_tty_name (XPROCESS (process), lisp_pty_name); |
| 1908 | 1872 | ||
| 1909 | #if !defined (WINDOWSNT) && defined (FD_CLOEXEC) | 1873 | #ifndef WINDOWSNT |
| 1910 | /* Wait for child_setup to complete in case that vfork is | 1874 | /* Wait for child_setup to complete in case that vfork is |
| 1911 | actually defined as fork. The descriptor wait_child_setup[1] | 1875 | actually defined as fork. The descriptor wait_child_setup[1] |
| 1912 | of a pipe is closed at the child side either by close-on-exec | 1876 | of a pipe is closed at the child side either by close-on-exec |
| @@ -1943,13 +1907,9 @@ create_pty (Lisp_Object process) | |||
| 1943 | #if ! defined (USG) || defined (USG_SUBTTY_WORKS) | 1907 | #if ! defined (USG) || defined (USG_SUBTTY_WORKS) |
| 1944 | /* On most USG systems it does not work to open the pty's tty here, | 1908 | /* On most USG systems it does not work to open the pty's tty here, |
| 1945 | then close it and reopen it in the child. */ | 1909 | then close it and reopen it in the child. */ |
| 1946 | #if O_NOCTTY | ||
| 1947 | /* Don't let this terminal become our controlling terminal | 1910 | /* Don't let this terminal become our controlling terminal |
| 1948 | (in case we don't have one). */ | 1911 | (in case we don't have one). */ |
| 1949 | int forkout = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); | 1912 | int forkout = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); |
| 1950 | #else | ||
| 1951 | int forkout = emacs_open (pty_name, O_RDWR, 0); | ||
| 1952 | #endif | ||
| 1953 | if (forkout < 0) | 1913 | if (forkout < 0) |
| 1954 | report_file_error ("Opening pty", Qnil); | 1914 | report_file_error ("Opening pty", Qnil); |
| 1955 | #if defined (DONT_REOPEN_PTY) | 1915 | #if defined (DONT_REOPEN_PTY) |
| @@ -1963,15 +1923,8 @@ create_pty (Lisp_Object process) | |||
| 1963 | } | 1923 | } |
| 1964 | #endif /* HAVE_PTYS */ | 1924 | #endif /* HAVE_PTYS */ |
| 1965 | 1925 | ||
| 1966 | #if O_NONBLOCK | ||
| 1967 | fcntl (inchannel, F_SETFL, O_NONBLOCK); | 1926 | fcntl (inchannel, F_SETFL, O_NONBLOCK); |
| 1968 | fcntl (outchannel, F_SETFL, O_NONBLOCK); | 1927 | fcntl (outchannel, F_SETFL, O_NONBLOCK); |
| 1969 | #else | ||
| 1970 | #if O_NDELAY | ||
| 1971 | fcntl (inchannel, F_SETFL, O_NDELAY); | ||
| 1972 | fcntl (outchannel, F_SETFL, O_NDELAY); | ||
| 1973 | #endif | ||
| 1974 | #endif | ||
| 1975 | 1928 | ||
| 1976 | /* Record this as an active process, with its channels. | 1929 | /* Record this as an active process, with its channels. |
| 1977 | As a result, child_setup will close Emacs's side of the pipes. */ | 1930 | As a result, child_setup will close Emacs's side of the pipes. */ |
| @@ -2927,13 +2880,9 @@ usage: (make-network-process &rest ARGS) */) | |||
| 2927 | { | 2880 | { |
| 2928 | /* Don't support network sockets when non-blocking mode is | 2881 | /* Don't support network sockets when non-blocking mode is |
| 2929 | not available, since a blocked Emacs is not useful. */ | 2882 | not available, since a blocked Emacs is not useful. */ |
| 2930 | #if !O_NONBLOCK && !O_NDELAY | ||
| 2931 | error ("Network servers not supported"); | ||
| 2932 | #else | ||
| 2933 | is_server = 1; | 2883 | is_server = 1; |
| 2934 | if (TYPE_RANGED_INTEGERP (int, tem)) | 2884 | if (TYPE_RANGED_INTEGERP (int, tem)) |
| 2935 | backlog = XINT (tem); | 2885 | backlog = XINT (tem); |
| 2936 | #endif | ||
| 2937 | } | 2886 | } |
| 2938 | 2887 | ||
| 2939 | /* Make QCaddress an alias for :local (server) or :remote (client). */ | 2888 | /* Make QCaddress an alias for :local (server) or :remote (client). */ |
| @@ -3193,11 +3142,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3193 | #ifdef NON_BLOCKING_CONNECT | 3142 | #ifdef NON_BLOCKING_CONNECT |
| 3194 | if (is_non_blocking_client) | 3143 | if (is_non_blocking_client) |
| 3195 | { | 3144 | { |
| 3196 | #if O_NONBLOCK | ||
| 3197 | ret = fcntl (s, F_SETFL, O_NONBLOCK); | 3145 | ret = fcntl (s, F_SETFL, O_NONBLOCK); |
| 3198 | #else | ||
| 3199 | ret = fcntl (s, F_SETFL, O_NDELAY); | ||
| 3200 | #endif | ||
| 3201 | if (ret < 0) | 3146 | if (ret < 0) |
| 3202 | { | 3147 | { |
| 3203 | xerrno = errno; | 3148 | xerrno = errno; |
| @@ -3410,13 +3355,7 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3410 | 3355 | ||
| 3411 | chan_process[inch] = proc; | 3356 | chan_process[inch] = proc; |
| 3412 | 3357 | ||
| 3413 | #if O_NONBLOCK | ||
| 3414 | fcntl (inch, F_SETFL, O_NONBLOCK); | 3358 | fcntl (inch, F_SETFL, O_NONBLOCK); |
| 3415 | #else | ||
| 3416 | #if O_NDELAY | ||
| 3417 | fcntl (inch, F_SETFL, O_NDELAY); | ||
| 3418 | #endif | ||
| 3419 | #endif | ||
| 3420 | 3359 | ||
| 3421 | p = XPROCESS (proc); | 3360 | p = XPROCESS (proc); |
| 3422 | 3361 | ||
| @@ -4145,13 +4084,7 @@ server_accept_connection (Lisp_Object server, int channel) | |||
| 4145 | 4084 | ||
| 4146 | chan_process[s] = proc; | 4085 | chan_process[s] = proc; |
| 4147 | 4086 | ||
| 4148 | #if O_NONBLOCK | ||
| 4149 | fcntl (s, F_SETFL, O_NONBLOCK); | 4087 | fcntl (s, F_SETFL, O_NONBLOCK); |
| 4150 | #else | ||
| 4151 | #if O_NDELAY | ||
| 4152 | fcntl (s, F_SETFL, O_NDELAY); | ||
| 4153 | #endif | ||
| 4154 | #endif | ||
| 4155 | 4088 | ||
| 4156 | p = XPROCESS (proc); | 4089 | p = XPROCESS (proc); |
| 4157 | 4090 | ||
| @@ -4847,23 +4780,17 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4847 | else if (nread == -1 && errno == EWOULDBLOCK) | 4780 | else if (nread == -1 && errno == EWOULDBLOCK) |
| 4848 | ; | 4781 | ; |
| 4849 | #endif | 4782 | #endif |
| 4850 | /* ISC 4.1 defines both EWOULDBLOCK and O_NONBLOCK, | ||
| 4851 | and Emacs uses O_NONBLOCK, so what we get is EAGAIN. */ | ||
| 4852 | #if O_NONBLOCK | ||
| 4853 | else if (nread == -1 && errno == EAGAIN) | ||
| 4854 | ; | ||
| 4855 | #else | ||
| 4856 | #if O_NDELAY | ||
| 4857 | else if (nread == -1 && errno == EAGAIN) | 4783 | else if (nread == -1 && errno == EAGAIN) |
| 4858 | ; | 4784 | ; |
| 4785 | #ifdef WINDOWSNT | ||
| 4786 | /* FIXME: Is this special case still needed? */ | ||
| 4859 | /* Note that we cannot distinguish between no input | 4787 | /* Note that we cannot distinguish between no input |
| 4860 | available now and a closed pipe. | 4788 | available now and a closed pipe. |
| 4861 | With luck, a closed pipe will be accompanied by | 4789 | With luck, a closed pipe will be accompanied by |
| 4862 | subprocess termination and SIGCHLD. */ | 4790 | subprocess termination and SIGCHLD. */ |
| 4863 | else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc)) | 4791 | else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc)) |
| 4864 | ; | 4792 | ; |
| 4865 | #endif /* O_NDELAY */ | 4793 | #endif |
| 4866 | #endif /* O_NONBLOCK */ | ||
| 4867 | #ifdef HAVE_PTYS | 4794 | #ifdef HAVE_PTYS |
| 4868 | /* On some OSs with ptys, when the process on one end of | 4795 | /* On some OSs with ptys, when the process on one end of |
| 4869 | a pty exits, the other end gets an error reading with | 4796 | a pty exits, the other end gets an error reading with |
| @@ -5532,19 +5459,6 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len, | |||
| 5532 | buf = SSDATA (object); | 5459 | buf = SSDATA (object); |
| 5533 | } | 5460 | } |
| 5534 | 5461 | ||
| 5535 | if (pty_max_bytes == 0) | ||
| 5536 | { | ||
| 5537 | #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON) | ||
| 5538 | pty_max_bytes = fpathconf (p->outfd, _PC_MAX_CANON); | ||
| 5539 | if (pty_max_bytes < 0) | ||
| 5540 | pty_max_bytes = 250; | ||
| 5541 | #else | ||
| 5542 | pty_max_bytes = 250; | ||
| 5543 | #endif | ||
| 5544 | /* Deduct one, to leave space for the eof. */ | ||
| 5545 | pty_max_bytes--; | ||
| 5546 | } | ||
| 5547 | |||
| 5548 | /* If there is already data in the write_queue, put the new data | 5462 | /* If there is already data in the write_queue, put the new data |
| 5549 | in the back of queue. Otherwise, ignore it. */ | 5463 | in the back of queue. Otherwise, ignore it. */ |
| 5550 | if (!NILP (p->write_queue)) | 5464 | if (!NILP (p->write_queue)) |
| @@ -6311,17 +6225,9 @@ record_child_status_change (pid_t pid, int w) | |||
| 6311 | { | 6225 | { |
| 6312 | #ifdef SIGCHLD | 6226 | #ifdef SIGCHLD |
| 6313 | 6227 | ||
| 6314 | # ifdef WNOHANG | 6228 | /* Record at most one child only if we already know one child that |
| 6315 | /* On POSIXish hosts, record at most one child only if we already | 6229 | has exited. */ |
| 6316 | know one child that has exited. */ | ||
| 6317 | bool record_at_most_one_child = 0 <= pid; | 6230 | bool record_at_most_one_child = 0 <= pid; |
| 6318 | # else | ||
| 6319 | /* On DOS_NT (the only porting target that lacks WNOHANG), | ||
| 6320 | record the status of at most one child process, since the SIGCHLD | ||
| 6321 | handler must return right away. If any more processes want to | ||
| 6322 | signal us, we will get another signal. */ | ||
| 6323 | bool record_at_most_one_child = 1; | ||
| 6324 | # endif | ||
| 6325 | 6231 | ||
| 6326 | Lisp_Object tail; | 6232 | Lisp_Object tail; |
| 6327 | 6233 | ||
| @@ -7348,9 +7254,7 @@ init_process_emacs (void) | |||
| 7348 | #ifdef HAVE_GETSOCKNAME | 7254 | #ifdef HAVE_GETSOCKNAME |
| 7349 | ADD_SUBFEATURE (QCservice, Qt); | 7255 | ADD_SUBFEATURE (QCservice, Qt); |
| 7350 | #endif | 7256 | #endif |
| 7351 | #if O_NONBLOCK || O_NDELAY | ||
| 7352 | ADD_SUBFEATURE (QCserver, Qt); | 7257 | ADD_SUBFEATURE (QCserver, Qt); |
| 7353 | #endif | ||
| 7354 | 7258 | ||
| 7355 | for (sopt = socket_options; sopt->name; sopt++) | 7259 | for (sopt = socket_options; sopt->name; sopt++) |
| 7356 | subfeatures = pure_cons (intern_c_string (sopt->name), subfeatures); | 7260 | subfeatures = pure_cons (intern_c_string (sopt->name), subfeatures); |