aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-31 03:39:01 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-10-31 03:39:01 +0000
commit92a8bfacd9e22062bf30ca4cb996af8f5e25b7b5 (patch)
tree3f96a2c5ada752c527e44a5283df88312748d91f
parentda5ae5544d4abd95b94df303018684847e1d88f8 (diff)
downloadruby-92a8bfacd9e22062bf30ca4cb996af8f5e25b7b5.tar.gz
* ext/pty/pty.c (get_device_once): use O_CLOEXEC for posix_openpt if
available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33580 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/pty/pty.c11
2 files changed, 15 insertions, 1 deletions
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 <akr@fsij.org>
+
+ * ext/pty/pty.c (get_device_once): use O_CLOEXEC for posix_openpt if
+ available.
+
Mon Oct 31 12:05:24 2011 Tanaka Akira <akr@fsij.org>
* 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;