IO.popen doesn't fail for non-existent command

e$B$J$+$@$G$9!#e(B

http://bts.vinelinux.org/guest.cgi?project=VineLinux&action=view_report&id=481
e$B!Ve(B481: ri e$B$Ge(B command not found:
pagere$B!W$K4XO"$7$?OC$G$9$,!“e(B
IO.popene$B$KB8:_$7$J$$%3%^%s%I$r;XDj$7$?$H$-$K%(%i!<$K$J$i$J$$$Ne(B
e$B$O!”>/$J$/$H$be(B1.9e$B$G%P%0$@$H;W$$$^$9!#e(B

  • io.c (popen_exec): should not close close-on-exec fds.

Index: io.c

— io.c (revision 12141)
+++ io.c (working copy)
@@ -3041,4 +3041,7 @@ popen_exec(void *pp)
popen_redirect(p);
for (fd = 3; fd < NOFILE; fd++) {
+#ifdef FD_CLOEXEC

  • if (fcntl(fd, F_GETFD) & FD_CLOEXEC) continue;
    +#endif
    close(fd);
    }

e$B$J$+$@$G$9!#e(B

At Tue, 3 Apr 2007 19:26:15 +0900,
[email protected] wrote in [ruby-dev:30679]:

http://bts.vinelinux.org/guest.cgi?project=VineLinux&action=view_report&id=481
e$B!Ve(B481: ri e$B$Ge(B command not found: pagere$B!W$K4XO"$7$?OC$G$9$,!“e(B
IO.popene$B$KB8:_$7$J$$%3%^%s%I$r;XDj$7$?$H$-$K%(%i!<$K$J$i$J$$$Ne(B
e$B$O!”>/$J$/$H$be(B1.9e$B$G%P%0$@$H;W$$$^$9!#e(B

1.8e$BMQ$K!"e(Bri_display.rbe$B$N%Q%C%A$G$9!#$d$C$F$k$3$H$Oe(B1.9e$B$HF1$8$G$9!#e(B

Index: lib/rdoc/ri/ri_display.rb

— lib/rdoc/ri/ri_display.rb (revision 12136)
+++ lib/rdoc/ri/ri_display.rb (working copy)
@@ -211,5 +211,30 @@ class DefaultDisplay
def setup_pager
unless @options.use_stdout

  •  for pager in [ ENV['PAGER'], "less", "more", 'pager' 
    

].compact.uniq

  •  pagers = [ ENV['PAGER'], "less", "more", 'pager' ].compact.uniq
    
  •  begin
    
  • require ‘fcntl’
  • if defined?(Fcntl::F_SETFD) and defined?(Fcntl::FD_CLOEXEC)
  • r, w = IO.pipe
  • w.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
  • unless f = IO.popen(“-”, “w”)
  •  r.close
    
  •  for pager in pagers
    
  •    exec(pager) rescue nil
    
  •  end
    
  •  w.write("\0")
    
  •  w.close
    
  •  exit!
    
  • end
  • w.close
  • w = nil
  • return f unless r.getc
  • f.close
  • pagers.clear
  • end
  •  rescue LoadError, Errno::ENOENT, NotImplementedError
    
  •  ensure
    
  • [r, w].each {|f| (f.close if f and !f.closed?) rescue nil}
  •  end
    
  •  for pager in pagers
       return IO.popen(pager, "w") rescue nil
     end
    

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:30679] IO.popen doesn’t fail for non-existent
command”
on Tue, 3 Apr 2007 19:26:15 +0900, [email protected] writes:

|http://bts.vinelinux.org/guest.cgi?project=VineLinux&action=view_report&id=481
|e$B!Ve(B481: ri e$B$Ge(B command not found: pagere$B!W$K4XO"$7$?OC$G$9$,!“e(B
|IO.popene$B$KB8:_$7$J$$%3%^%s%I$r;XDj$7$?$H$-$K%(%i!<$K$J$i$J$$$Ne(B
|e$B$O!”>/$J$/$H$be(B1.9e$B$G%P%0$@$H;W$$$^$9!#e(B
|
|* io.c (popen_exec): should not close close-on-exec fds.

e$B%3%_%C%H$7$F$/$@$5$$!#e(B1.8e$B$Ke(B[ruby-dev:30680]e$B$rEv$F$k$+$I$&$+e(B
e$B$Oe(Bknue$B$5$s$K$*G$$;$7$^$9!#e(B

At Wed, 4 Apr 2007 00:34:47 +0900,
Nobuyoshi N. wrote:

なかだです。

At Tue, 3 Apr 2007 19:26:15 +0900,
[email protected] wrote in [ruby-dev:30679]:

http://bts.vinelinux.org/guest.cgi?project=VineLinux&action=view_report&id=481
「481: ri で command not found: pager」に関連した話ですが、
IO.popenに存在しないコマンドを指定したときにエラーにならないの
は、少なくとも1.9でバグだと思います。

1.8用に、ri_display.rbのパッチです。やってることは1.9と同じです。

 入れてください。

 しかし、1.8だと面倒ですね。できれば popen ごとbackportできれば
いいんですが、ちょっと大かがりですか。


/
/__ __ Akinori.org / MUSHA.org
/ ) ) ) ) / FreeBSD.org / Ruby-lang.org
Akinori MUSHA aka / (_ / ( (__( @ iDaemons.org / and.or.jp

“Different eyes see different things,
Different hearts beat on different strings –
But there are times for you and me when all such things agree”