]> git.eshelyaron.com Git - emacs.git/commitdiff
* process.c (allocate_pty) [PTY_OPEN]: Set fd's FD_CLOEXEC flag.
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 21 Aug 2013 05:39:51 +0000 (22:39 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 21 Aug 2013 05:39:51 +0000 (22:39 -0700)
We can't portably rely on PTY_OPEN doing that, even if
it calls posix_openpt with O_CLOEXEC.

src/ChangeLog
src/process.c

index 997459f01c28c54d1a5ea61f45bb601cb2bb2469..c7cceb27a4fb38ea45ddf145db5cdb63211e1bf6 100644 (file)
@@ -1,3 +1,9 @@
+2013-08-21  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * process.c (allocate_pty) [PTY_OPEN]: Set fd's FD_CLOEXEC flag.
+       We can't portably rely on PTY_OPEN doing that, even if
+       it calls posix_openpt with O_CLOEXEC.
+
 2013-08-20  Kenichi Handa  <handa@gnu.org>
 
        * character.c (string_char): Improve commentary.
index c4dd87a6b4850e984cd8c3ef46ad2cec058c5a84..349ec26534b7938fb9bfa4c992b0f7ace27d551a 100644 (file)
@@ -687,6 +687,15 @@ allocate_pty (char pty_name[PTY_NAME_SIZE])
 
        if (fd >= 0)
          {
+#ifdef PTY_OPEN
+           /* Set FD's close-on-exec flag.  This is needed even if
+              PT_OPEN calls posix_openpt with O_CLOEXEC, since POSIX
+              doesn't require support for that combination.
+              Multithreaded platforms where posix_openpt ignores
+              O_CLOEXEC (or where PTY_OPEN doesn't call posix_openpt)
+              have a race condition between the PTY_OPEN and here.  */
+           fcntl (fd, F_SETFD, FD_CLOEXEC);
+#endif
            /* check to make certain that both sides are available
               this avoids a nasty yet stupid bug in rlogins */
 #ifdef PTY_TTY_NAME_SPRINTF