diff options
| author | YAMAMOTO Mitsuharu | 2008-07-17 09:06:58 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2008-07-17 09:06:58 +0000 |
| commit | 2c4df14348bbe667422a0205e1de215ae56ea4ed (patch) | |
| tree | fd411e874d54b94fd65e04a07ac526479014c519 /src/process.c | |
| parent | 31edef9d84fd62ee60ece8335b6f6c60306756f3 (diff) | |
| download | emacs-2c4df14348bbe667422a0205e1de215ae56ea4ed.tar.gz emacs-2c4df14348bbe667422a0205e1de215ae56ea4ed.zip | |
(create_process) [!WINDOWSNT && FD_CLOEXEC]: Wait for
child process to complete child_setup. Undo 2005-09-21 change.
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/src/process.c b/src/process.c index 184701e4d1b..c4c6cfd1b86 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -1842,6 +1842,9 @@ create_process (process, new_argv, current_dir) | |||
| 1842 | int inchannel, outchannel; | 1842 | int inchannel, outchannel; |
| 1843 | pid_t pid; | 1843 | pid_t pid; |
| 1844 | int sv[2]; | 1844 | int sv[2]; |
| 1845 | #if !defined (WINDOWSNT) && defined (FD_CLOEXEC) | ||
| 1846 | int wait_child_setup[2]; | ||
| 1847 | #endif | ||
| 1845 | #ifdef POSIX_SIGNALS | 1848 | #ifdef POSIX_SIGNALS |
| 1846 | sigset_t procmask; | 1849 | sigset_t procmask; |
| 1847 | sigset_t blocked; | 1850 | sigset_t blocked; |
| @@ -1884,12 +1887,6 @@ create_process (process, new_argv, current_dir) | |||
| 1884 | #endif | 1887 | #endif |
| 1885 | if (forkin < 0) | 1888 | if (forkin < 0) |
| 1886 | report_file_error ("Opening pty", Qnil); | 1889 | report_file_error ("Opening pty", Qnil); |
| 1887 | #if defined (RTU) || defined (UNIPLUS) || defined (DONT_REOPEN_PTY) | ||
| 1888 | /* In the case that vfork is defined as fork, the parent process | ||
| 1889 | (Emacs) may send some data before the child process completes | ||
| 1890 | tty options setup. So we setup tty before forking. */ | ||
| 1891 | child_setup_tty (forkout); | ||
| 1892 | #endif /* RTU or UNIPLUS or DONT_REOPEN_PTY */ | ||
| 1893 | #else | 1890 | #else |
| 1894 | forkin = forkout = -1; | 1891 | forkin = forkout = -1; |
| 1895 | #endif /* not USG, or USG_SUBTTY_WORKS */ | 1892 | #endif /* not USG, or USG_SUBTTY_WORKS */ |
| @@ -1924,6 +1921,25 @@ create_process (process, new_argv, current_dir) | |||
| 1924 | } | 1921 | } |
| 1925 | #endif /* not SKTPAIR */ | 1922 | #endif /* not SKTPAIR */ |
| 1926 | 1923 | ||
| 1924 | #if !defined (WINDOWSNT) && defined (FD_CLOEXEC) | ||
| 1925 | { | ||
| 1926 | int tem; | ||
| 1927 | |||
| 1928 | tem = pipe (wait_child_setup); | ||
| 1929 | if (tem < 0) | ||
| 1930 | report_file_error ("Creating pipe", Qnil); | ||
| 1931 | tem = fcntl (wait_child_setup[1], F_GETFD, 0); | ||
| 1932 | if (tem >= 0) | ||
| 1933 | tem = fcntl (wait_child_setup[1], F_SETFD, tem | FD_CLOEXEC); | ||
| 1934 | if (tem < 0) | ||
| 1935 | { | ||
| 1936 | emacs_close (wait_child_setup[0]); | ||
| 1937 | emacs_close (wait_child_setup[1]); | ||
| 1938 | report_file_error ("Setting file descriptor flags", Qnil); | ||
| 1939 | } | ||
| 1940 | } | ||
| 1941 | #endif | ||
| 1942 | |||
| 1927 | #if 0 | 1943 | #if 0 |
| 1928 | /* Replaced by close_process_descs */ | 1944 | /* Replaced by close_process_descs */ |
| 1929 | set_exclusive_use (inchannel); | 1945 | set_exclusive_use (inchannel); |
| @@ -2174,14 +2190,15 @@ create_process (process, new_argv, current_dir) | |||
| 2174 | #endif /* SIGCHLD */ | 2190 | #endif /* SIGCHLD */ |
| 2175 | #endif /* !POSIX_SIGNALS */ | 2191 | #endif /* !POSIX_SIGNALS */ |
| 2176 | 2192 | ||
| 2177 | #if !defined (RTU) && !defined (UNIPLUS) && !defined (DONT_REOPEN_PTY) | ||
| 2178 | if (pty_flag) | 2193 | if (pty_flag) |
| 2179 | child_setup_tty (xforkout); | 2194 | child_setup_tty (xforkout); |
| 2180 | #endif /* not RTU and not UNIPLUS and not DONT_REOPEN_PTY */ | ||
| 2181 | #ifdef WINDOWSNT | 2195 | #ifdef WINDOWSNT |
| 2182 | pid = child_setup (xforkin, xforkout, xforkout, | 2196 | pid = child_setup (xforkin, xforkout, xforkout, |
| 2183 | new_argv, 1, current_dir); | 2197 | new_argv, 1, current_dir); |
| 2184 | #else /* not WINDOWSNT */ | 2198 | #else /* not WINDOWSNT */ |
| 2199 | #ifdef FD_CLOEXEC | ||
| 2200 | emacs_close (wait_child_setup[0]); | ||
| 2201 | #endif | ||
| 2185 | child_setup (xforkin, xforkout, xforkout, | 2202 | child_setup (xforkin, xforkout, xforkout, |
| 2186 | new_argv, 1, current_dir); | 2203 | new_argv, 1, current_dir); |
| 2187 | #endif /* not WINDOWSNT */ | 2204 | #endif /* not WINDOWSNT */ |
| @@ -2235,6 +2252,20 @@ create_process (process, new_argv, current_dir) | |||
| 2235 | else | 2252 | else |
| 2236 | #endif | 2253 | #endif |
| 2237 | XPROCESS (process)->tty_name = Qnil; | 2254 | XPROCESS (process)->tty_name = Qnil; |
| 2255 | |||
| 2256 | #if !defined (WINDOWSNT) && defined (FD_CLOEXEC) | ||
| 2257 | /* Wait for child_setup to complete in case that vfork is | ||
| 2258 | actually defined as fork. The descriptor wait_child_setup[1] | ||
| 2259 | of a pipe is closed at the child side either by close-on-exec | ||
| 2260 | on successful execvp or the _exit call in child_setup. */ | ||
| 2261 | { | ||
| 2262 | char dummy; | ||
| 2263 | |||
| 2264 | emacs_close (wait_child_setup[1]); | ||
| 2265 | emacs_read (wait_child_setup[0], &dummy, 1); | ||
| 2266 | emacs_close (wait_child_setup[0]); | ||
| 2267 | } | ||
| 2268 | #endif | ||
| 2238 | } | 2269 | } |
| 2239 | 2270 | ||
| 2240 | /* Restore the signal state whether vfork succeeded or not. | 2271 | /* Restore the signal state whether vfork succeeded or not. |
| @@ -4441,15 +4472,6 @@ wait_reading_process_output (time_limit, microsecs, read_kbd, do_display, | |||
| 4441 | #endif | 4472 | #endif |
| 4442 | 4473 | ||
| 4443 | Atemp = input_wait_mask; | 4474 | Atemp = input_wait_mask; |
| 4444 | #if 0 | ||
| 4445 | /* On Mac OS X 10.0, the SELECT system call always says input is | ||
| 4446 | present (for reading) at stdin, even when none is. This | ||
| 4447 | causes the call to SELECT below to return 1 and | ||
| 4448 | status_notify not to be called. As a result output of | ||
| 4449 | subprocesses are incorrectly discarded. | ||
| 4450 | */ | ||
| 4451 | FD_CLR (0, &Atemp); | ||
| 4452 | #endif | ||
| 4453 | IF_NON_BLOCKING_CONNECT (Ctemp = connect_wait_mask); | 4475 | IF_NON_BLOCKING_CONNECT (Ctemp = connect_wait_mask); |
| 4454 | 4476 | ||
| 4455 | EMACS_SET_SECS_USECS (timeout, 0, 0); | 4477 | EMACS_SET_SECS_USECS (timeout, 0, 0); |