diff options
author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> | 2008-07-17 09:06:58 +0000 |
---|---|---|
committer | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> | 2008-07-17 09:06:58 +0000 |
commit | 2c4df14348bbe667422a0205e1de215ae56ea4ed (patch) | |
tree | fd411e874d54b94fd65e04a07ac526479014c519 /src/process.c | |
parent | 31edef9d84fd62ee60ece8335b6f6c60306756f3 (diff) | |
download | emacs-2c4df14348bbe667422a0205e1de215ae56ea4ed.tar.gz |
(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) int inchannel, outchannel; pid_t pid; int sv[2]; +#if !defined (WINDOWSNT) && defined (FD_CLOEXEC) + int wait_child_setup[2]; +#endif #ifdef POSIX_SIGNALS sigset_t procmask; sigset_t blocked; @@ -1884,12 +1887,6 @@ create_process (process, new_argv, current_dir) #endif if (forkin < 0) report_file_error ("Opening pty", Qnil); -#if defined (RTU) || defined (UNIPLUS) || defined (DONT_REOPEN_PTY) - /* In the case that vfork is defined as fork, the parent process - (Emacs) may send some data before the child process completes - tty options setup. So we setup tty before forking. */ - child_setup_tty (forkout); -#endif /* RTU or UNIPLUS or DONT_REOPEN_PTY */ #else forkin = forkout = -1; #endif /* not USG, or USG_SUBTTY_WORKS */ @@ -1924,6 +1921,25 @@ create_process (process, new_argv, current_dir) } #endif /* not SKTPAIR */ +#if !defined (WINDOWSNT) && defined (FD_CLOEXEC) + { + int tem; + + tem = pipe (wait_child_setup); + if (tem < 0) + report_file_error ("Creating pipe", Qnil); + tem = fcntl (wait_child_setup[1], F_GETFD, 0); + if (tem >= 0) + tem = fcntl (wait_child_setup[1], F_SETFD, tem | FD_CLOEXEC); + if (tem < 0) + { + emacs_close (wait_child_setup[0]); + emacs_close (wait_child_setup[1]); + report_file_error ("Setting file descriptor flags", Qnil); + } + } +#endif + #if 0 /* Replaced by close_process_descs */ set_exclusive_use (inchannel); @@ -2174,14 +2190,15 @@ create_process (process, new_argv, current_dir) #endif /* SIGCHLD */ #endif /* !POSIX_SIGNALS */ -#if !defined (RTU) && !defined (UNIPLUS) && !defined (DONT_REOPEN_PTY) if (pty_flag) child_setup_tty (xforkout); -#endif /* not RTU and not UNIPLUS and not DONT_REOPEN_PTY */ #ifdef WINDOWSNT pid = child_setup (xforkin, xforkout, xforkout, new_argv, 1, current_dir); #else /* not WINDOWSNT */ +#ifdef FD_CLOEXEC + emacs_close (wait_child_setup[0]); +#endif child_setup (xforkin, xforkout, xforkout, new_argv, 1, current_dir); #endif /* not WINDOWSNT */ @@ -2235,6 +2252,20 @@ create_process (process, new_argv, current_dir) else #endif XPROCESS (process)->tty_name = Qnil; + +#if !defined (WINDOWSNT) && defined (FD_CLOEXEC) + /* Wait for child_setup to complete in case that vfork is + actually defined as fork. The descriptor wait_child_setup[1] + of a pipe is closed at the child side either by close-on-exec + on successful execvp or the _exit call in child_setup. */ + { + char dummy; + + emacs_close (wait_child_setup[1]); + emacs_read (wait_child_setup[0], &dummy, 1); + emacs_close (wait_child_setup[0]); + } +#endif } /* Restore the signal state whether vfork succeeded or not. @@ -4441,15 +4472,6 @@ wait_reading_process_output (time_limit, microsecs, read_kbd, do_display, #endif Atemp = input_wait_mask; -#if 0 - /* On Mac OS X 10.0, the SELECT system call always says input is - present (for reading) at stdin, even when none is. This - causes the call to SELECT below to return 1 and - status_notify not to be called. As a result output of - subprocesses are incorrectly discarded. - */ - FD_CLR (0, &Atemp); -#endif IF_NON_BLOCKING_CONNECT (Ctemp = connect_wait_mask); EMACS_SET_SECS_USECS (timeout, 0, 0); |