From: ngotogenome@... Date: 2015-07-14T06:03:18+00:00 Subject: [ruby-core:69963] [Ruby trunk - Bug #11350] [Open] When Process.exec failed, redirections were still changed and not restored Issue #11350 has been updated by Naohisa Goto. Status changed from Feedback to Open Assignee deleted (Nobuyoshi Nakada) > Consider to create a child process using ::spawn or Kernel#system if this is > not acceptable. I think so, and I agree this is a spec. I think the documentation should be added about the risk of ASYNC BUG when redirecting FDs that Ruby timer thread internally uses. PS. It seems that Japanese documentation of Process.exec does not describe about the limitation. (but this is not a bug of Ruby itself) http://docs.ruby-lang.org/ja/2.2.0/class/Process.html#S_EXEC ---------------------------------------- Bug #11350: When Process.exec failed, redirections were still changed and not restored https://bugs.ruby-lang.org/issues/11350#change-53395 * Author: Naohisa Goto * Status: Open * Priority: Normal * Assignee: * ruby -v: * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- When Process.exec failed, redirections of file descriptors were changed and not restored. When redirecting fd 3 or 5, ASYNC BUG occurred as below. ~~~ $ ruby -e 'begin; Process.exec("/does_not_exist", "arg", { 3=>["/dev/null", "w"]}); rescue Errno::ENOENT => e; $stdout.print "stdout: ", e.inspect, "\n"; $stderr.print "stderr: ", e.inspect, "\n"; end' [ASYNC BUG] consume_communication_pipe: read EBADF ruby 2.3.0dev (2015-07-13) [sparc64-solaris2.10] [NOTE] You may have encountered a bug in the Ruby interpreter or extension libraries. Bug reports are welcome. For details: http://www.ruby-lang.org/bugreport.html stdout: # stderr: #Abort ~~~ ~~~ $ ruby -e 'begin; Process.exec("/does_not_exist", "arg", { 5=>["/dev/null", "w"]}); rescue Errno::ENOENT => e; $stdout.print "stdout: ", e.inspect, "\n"; $stderr.print "stderr: ", e.inspect, "\n"; end' [ASYNC BUG] consume_communication_pipe: read EBADF ruby 2.3.0dev (2015-07-13) [sparc64-solaris2.10] stdout: [NOTE] You may have encountered a bug in the Ruby interpreter or extension libraries. Bug reports are welcome. For details: http://www.ruby-lang.org/bugreport.html # stderr: #Abort ~~~ When redirecting fd 1 or 2 to /dev/null, stdout or stderr is still redirected to /dev/null and the printed contents are not shown. ~~~ % ruby -e 'begin; Process.exec("/does_not_exist", "arg", { 1=>["/dev/null", "w"]}); rescue Errno::ENOENT => e; $stdout.print "stdout: ", e.inspect, "\n"; $stderr.print "stderr: ", e.inspect, "\n"; end' stderr: # ~~~ ~~~ % ruby -e 'begin; Process.exec("/does_not_exist", "arg", { 2=>["/dev/null", "w"]}); rescue Errno::ENOENT => e; $stdout.print "stdout: ", e.inspect, "\n"; $stderr.print "stderr: ", e.inspect, "\n"; end' stdout: # ~~~ All of the above are observed both on x86_64 Linux and sparc Solaris. Is this spec or bug? -- https://bugs.ruby-lang.org/