IO.popen raise Errno::EBADF


#1

e$B$H$_$?$G$9!#e(B

IO.popen() e$B$Ge(B fork e$B$K<:GT$7$?;~$N%(%i!<$,e(B EBADF
e$B$K$J$k$3$H$,$"$j$^$9!#e(B

~% ruby -v
ruby 1.8.4 (2005-12-24) [i686-linux]
~% ruby -e ‘"1"10241024*500; IO.popen(“cat”,“w”)’
-e:1:in `popen’: Bad file descriptor - cat (Errno::EBADF)
from -e:1

strace e$B$N7k2L$O$3$s$J46$8!#e(B

25722 pipe([3, 4]) = 0
25722 clone(child_stack=0,
flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD,
child_tidptr=0xb7e1c0c8) = -1 ENOMEM (Cannot allocate memory)
25722 close(-1081300760) = -1 EBADF (Bad file descriptor)
25722 close(4) = 0

e$B$H$$$&$3$H$G!"$*$=$i$/$3$s$J46$8$G$O$J$$$+$H!#e(B

— io.c.orig 2005-12-20 02:11:20.000000000 +0900
+++ io.c 2006-04-24 23:49:48.000000000 +0900
@@ -2994,7 +2994,14 @@
rb_thread_sleep(1);
goto retry;
}

  •   close(pr[0]); close(pw[1]);
    
  •   if ((modef & FMODE_READABLE)) {
    
  •     close(pr[0]);
    
  •     close(pr[1]);
    
  •   }
    
  •   if ((modef & FMODE_WRITABLE)) {
    
  •     close(pw[0]);
    
  •     close(pw[1]);
    
  •   }
      rb_sys_fail(pname);
      break;