[前][次][番号順一覧][スレッド一覧]

ruby-changes:21531

From: akr <ko1@a...>
Date: Mon, 31 Oct 2011 12:39:16 +0900 (JST)
Subject: [ruby-changes:21531] akr:r33580 (trunk): * ext/pty/pty.c (get_device_once): use O_CLOEXEC for posix_openpt if

akr	2011-10-31 12:39:01 +0900 (Mon, 31 Oct 2011)

  New Revision: 33580

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33580

  Log:
    * ext/pty/pty.c (get_device_once): use O_CLOEXEC for posix_openpt if
      available.

  Modified files:
    trunk/ChangeLog
    trunk/ext/pty/pty.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33579)
+++ ChangeLog	(revision 33580)
@@ -1,3 +1,8 @@
+Mon Oct 31 12:37:50 2011  Tanaka Akira  <akr@f...>
+
+	* 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@f...>
 
 	* io.c (rb_cloexec_dup2): check oldfd == newfd at first.
Index: ext/pty/pty.c
===================================================================
--- ext/pty/pty.c	(revision 33579)
+++ ext/pty/pty.c	(revision 33580)
@@ -285,6 +285,7 @@
     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 @@
     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 @@
     return 0;
 
 #elif defined HAVE__GETPTY
+    /* SGI IRIX */
     char *name;
     mode_t mode = nomesg ? 0600 : 0622;
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]