[#41278] [BUG:1.9] BINARY should not be ASCII-compatible — Yugui <yugui@...>

WXVndWkbJEIkRyQ5ISMbKEIKCgo+IBskQiRHISIkKiQqJGAkTSQzJDMkXiRHJE41RE9AJEclKyVQ

15 messages 2010/05/11

[#41407] [Bug #3339] win32ole test failure — Usaku NAKAMURA <redmine@...>

Bug #3339: win32ole test failure

20 messages 2010/05/25
[#41411] Re: [Bug #3339] win32ole test failure — Masaki Suketa <masaki.suketa@...> 2010/05/25

助田です。

[#41412] Re: [Bug #3339] win32ole test failure — "U.Nakamura" <usa@...> 2010/05/25

こんにちは、なかむら(う)です。

[ruby-dev:41238] Re: io/console IO#raw error when io is closed in the block

From: Tanaka Akira <akr@...>
Date: 2010-05-09 03:59:42 UTC
List: ruby-dev #41238
2010年5月8日23:24 Tanaka Akira <akr@fsij.org>:

> ブロック無しのが NEWS から消えて、IO#raw {|io| } は内部で dup して確実に
> 状態を戻すようになったようですが、これは困ります。
>
> 例にあげた PTY の用法だと、戻したくないんです。

> そんなわけで、slave tty を親プロセスでは close し、かつ、
> 端末は子プロセスからのために raw のままにする、
> というのが不可能な気がするんですが、なにか方法はありますか?

現状だと上記が実現できなくて困るので以下のようにしたいんですがどうでしょうか。

こうであれば、IO#raw のブロック内で close すると、tty の状態が戻らさないことが
実現でき、また、裏で fd が隠れて保存されることもありません。

Index: ext/io/console/console.c
===================================================================
--- ext/io/console/console.c	(revision 27700)
+++ ext/io/console/console.c	(working copy)
@@ -173,23 +173,6 @@

 #define FD_PER_IO 2

-#if defined HAVE_DUP3
-#define dup_private(fd) dup3((fd), -1, O_CLOEXEC)
-#elif defined F_DUPFD_CLOEXEC
-#define dup_private(fd) fcntl((fd), F_DUPFD_CLOEXEC)
-#elif defined O_CLOEXEC
-static inline int
-dup_private(int fd)
-{
-    fd = dup(fd);
-    if (fd != -1) fcntl(fd, F_SETFD, O_CLOEXEC);
-    return fd;
-}
-#define dup_private(fd) dup_private(fd)
-#else
-#define dup_private(fd) dup(fd)
-#endif
-
 static VALUE
 ttymode(VALUE io, VALUE (*func)(VALUE), void (*setter)(conmode *))
 {
@@ -197,7 +180,6 @@
     int status = -1;
     int error = 0;
     int fd[FD_PER_IO];
-    int tmpfd, dupped = 0;
     conmode t[FD_PER_IO];
     VALUE result = Qnil;

@@ -205,10 +187,6 @@
     fd[0] = GetReadFD(fptr);
     if (fd[0] != -1) {
 	if (set_ttymode(fd[0], t+0, setter)) {
-	    if ((tmpfd = dup_private(fd[0])) != -1) {
-		fd[0] = tmpfd;
-		dupped |= 1 << 0;
-	    }
 	    status = 0;
 	}
 	else {
@@ -219,10 +197,6 @@
     fd[1] = GetWriteFD(fptr);
     if (fd[1] != -1 && fd[1] != fd[0]) {
 	if (set_ttymode(fd[1], t+1, setter)) {
-	    if ((tmpfd = dup_private(fd[1])) != -1) {
-		fd[1] = tmpfd;
-		dupped |= 1 << 1;
-	    }
 	    status = 0;
 	}
 	else {
@@ -233,19 +207,20 @@
     if (status == 0) {
 	result = rb_protect(func, io, &status);
     }
-    if (fd[0] != -1) {
-	if (!setattr(fd[0], t+0)) {
-	    error = errno;
-	    status = -1;
-	}
-	if (dupped & (1 << 0)) close(fd[0]);
-    }
-    if (fd[1] != -1 && fd[1] != fd[0]) {
-	if (!setattr(fd[1], t+1)) {
-	    error = errno;
-	    status = -1;
-	}
-	if (dupped & (1 << 1)) close(fd[1]);
+    if (0 <= RFILE(io)->fptr->fd) {
+        GetOpenFile(io, fptr);
+        if (fd[0] != -1 && fd[0] == GetReadFD(fptr)) {
+            if (!setattr(fd[0], t+0)) {
+                error = errno;
+                status = -1;
+            }
+        }
+        if (fd[1] != -1 && fd[1] != fd[0] && fd[1] == GetWriteFD(fptr)) {
+            if (!setattr(fd[1], t+1)) {
+                error = errno;
+                status = -1;
+            }
+        }
     }
     if (status) {
 	if (status == -1) {
Index: ext/io/console/extconf.rb
===================================================================
--- ext/io/console/extconf.rb	(revision 27700)
+++ ext/io/console/extconf.rb	(working copy)
@@ -14,7 +14,6 @@
 end
 have_header("sys/ioctl.h")
 have_func("rb_io_get_write_io", "ruby/io.h")
-have_func("dup3", "unistd.h")
 if ok
   create_makefile("io/console")
 end
-- 
[田中 哲][たなか あきら][Tanaka Akira]

In This Thread

Prev Next