diff --git a/ChangeLog b/ChangeLog index 11ddbd2da8..1a5052ab45 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Oct 31 12:37:50 2011 Tanaka Akira + + * ext/pty/pty.c (get_device_once): use O_CLOEXEC for posix_openpt if + available. + Mon Oct 31 12:05:24 2011 Tanaka Akira * io.c (rb_cloexec_dup2): check oldfd == newfd at first. diff --git a/ext/pty/pty.c b/ext/pty/pty.c index ac023f70c3..98993f7c80 100644 --- a/ext/pty/pty.c +++ b/ext/pty/pty.c @@ -285,6 +285,7 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg, int masterfd = -1, slavefd = -1; char *slavedevice; struct sigaction dfl, old; + int flags; dfl.sa_handler = SIG_DFL; dfl.sa_flags = 0; @@ -297,7 +298,14 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg, if (grantpt(masterfd) == -1) goto grantpt_error; rb_fd_set_cloexec(masterfd); #else - if ((masterfd = posix_openpt(O_RDWR|O_NOCTTY)) == -1) goto error; + flags = O_RDWR|O_NOCTTY; +# ifdef O_CLOEXEC + /* glibc posix_openpt() in GNU/Linux calls open("/dev/ptmx", flags) internally. + * So version dependency on GNU/Linux is same as O_CLOEXEC with open(). + * O_CLOEXEC is available since Linux 2.6.23. Linux 2.6.18 silently ignore it. */ + flags |= O_CLOEXEC; +# endif + if ((masterfd = posix_openpt(flags)) == -1) goto error; rb_fd_set_cloexec(masterfd); if (sigaction(SIGCHLD, &dfl, &old) == -1) goto error; if (grantpt(masterfd) == -1) goto grantpt_error; @@ -349,6 +357,7 @@ get_device_once(int *master, int *slave, char SlaveName[DEVICELEN], int nomesg, return 0; #elif defined HAVE__GETPTY + /* SGI IRIX */ char *name; mode_t mode = nomesg ? 0600 : 0622;