summaryrefslogtreecommitdiff
path: root/ext/pty/pty.c
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 /ext/pty/pty.c
parentda5ae5544d4abd95b94df303018684847e1d88f8 (diff)
* 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
Diffstat (limited to 'ext/pty/pty.c')
-rw-r--r--ext/pty/pty.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/ext/pty/pty.c b/ext/pty/pty.c
index ac023f7..98993f7 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;