Mercurial > emacs
comparison src/process.c @ 80610:a6adb4611f10
(create_process) [!WINDOWSNT && FD_CLOEXEC]: Wait for
child process to complete child_setup. Undo 2005-09-21 change.
author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> |
---|---|
date | Thu, 17 Jul 2008 09:06:58 +0000 |
parents | 2958d9bca9be |
children | fe3520e6a00e 3760da9fe15e |
comparison
equal
deleted
inserted
replaced
80609:e1d8fddfb15a | 80610:a6adb4611f10 |
---|---|
1840 Lisp_Object current_dir; | 1840 Lisp_Object current_dir; |
1841 { | 1841 { |
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; |
1848 struct sigaction sigint_action; | 1851 struct sigaction sigint_action; |
1849 struct sigaction sigquit_action; | 1852 struct sigaction sigquit_action; |
1882 #else | 1885 #else |
1883 forkout = forkin = emacs_open (pty_name, O_RDWR, 0); | 1886 forkout = forkin = emacs_open (pty_name, O_RDWR, 0); |
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 */ |
1896 pty_flag = 1; | 1893 pty_flag = 1; |
1897 } | 1894 } |
1921 } | 1918 } |
1922 outchannel = sv[1]; | 1919 outchannel = sv[1]; |
1923 forkin = sv[0]; | 1920 forkin = sv[0]; |
1924 } | 1921 } |
1925 #endif /* not SKTPAIR */ | 1922 #endif /* not SKTPAIR */ |
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 | |
1926 | 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); |
1930 set_exclusive_use (outchannel); | 1946 set_exclusive_use (outchannel); |
2172 #endif /* ordinary USG */ | 2188 #endif /* ordinary USG */ |
2173 #endif /* not BSD4_1 */ | 2189 #endif /* not BSD4_1 */ |
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 */ |
2188 } | 2205 } |
2189 environ = save_environ; | 2206 environ = save_environ; |
2233 if (pty_flag) | 2250 if (pty_flag) |
2234 XPROCESS (process)->tty_name = build_string (pty_name); | 2251 XPROCESS (process)->tty_name = build_string (pty_name); |
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. |
2241 (We will signal an error, below, if it failed.) */ | 2272 (We will signal an error, below, if it failed.) */ |
2242 #ifdef POSIX_SIGNALS | 2273 #ifdef POSIX_SIGNALS |
4439 #ifdef NON_BLOCKING_CONNECT | 4470 #ifdef NON_BLOCKING_CONNECT |
4440 SELECT_TYPE Ctemp; | 4471 SELECT_TYPE Ctemp; |
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); |
4456 if ((select (max (max_process_desc, max_keyboard_desc) + 1, | 4478 if ((select (max (max_process_desc, max_keyboard_desc) + 1, |
4457 &Atemp, | 4479 &Atemp, |