JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-2253

Kernel#exec should raise Errno::ENOENT if the program to execute doesn't exist

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.1RC2
    • Fix Version/s: JRuby 1.5
    • Component/s: Core Classes/Modules
    • Labels:
      None
    • Environment:
      JRuby 1.1RC2
    • Number of attachments :
      2

      Description

      Kernel#exec behavior for MRI (1.8 and 1.9) is that it raises Errno::ENOENT if the program to execute doesn't exist.
      But for JRuby, the Errno is not being raised.

      The attached tests pass with MRI, but fail with JRuby:

        1) Failure:
      test_exec_empty(ExecTest) [exec-ex.rb:5]:
      <Errno::ENOENT> exception expected but was
      Class: <SystemExit>
      Message: <"exit">
      ---Backtrace---
      exec-ex.rb:5:in `test_exec_empty'
      ---------------
      
        2) Failure:
      test_exec_non_existing(ExecTest) [exec-ex.rb:11]:
      <Errno::ENOENT> exception expected but was
      Class: <SystemExit>
      Message: <"exit">
      ---Backtrace---
      exec-ex.rb:11:in `test_exec_non_existing'
      ---------------
      

      This also leads to one rubyspec failure:

      1)
      Kernel#exec raises a SystemCallError if cmd cannot execute FAILED
      Expected SystemCallError but got SystemExit (exit):
      /opt/work/rubinius/./mspec/expectations.rb:10:in `fail_with'
      /opt/work/rubinius/./mspec/expectations/should.rb:6:in `should'
      /opt/work/rubinius/./spec/ruby/1.8/core/kernel/exec_spec.rb:10
      /opt/work/rubinius/./mspec/runner/mspec.rb:111:in `call'
      /opt/work/rubinius/./mspec/runner/mspec.rb:111:in `protect'
      /opt/work/rubinius/./mspec/runner/state.rb:46:in `each'
      /opt/work/rubinius/./mspec/runner/state.rb:46:in `protect'
      /opt/work/rubinius/./mspec/runner/state.rb:59:in `process'
      /opt/work/rubinius/./mspec/runner/state.rb:55:in `each'
      /opt/work/rubinius/./mspec/runner/state.rb:55:in `process'
      /opt/work/rubinius/./mspec/runner/mspec.rb:19:in `describe'
      /opt/work/rubinius/./mspec/runner/object.rb:11:in `describe'
      /opt/work/rubinius/./spec/ruby/1.8/core/kernel/exec_spec.rb:4
      /opt/work/rubinius/./mspec/runner/mspec.rb:36:in `load'
      /opt/work/rubinius/./mspec/runner/mspec.rb:36:in `files'
      /opt/work/rubinius/./mspec/runner/mspec.rb:111:in `call'
      /opt/work/rubinius/./mspec/runner/mspec.rb:111:in `protect'
      /opt/work/rubinius/./mspec/runner/mspec.rb:36:in `files'
      /opt/work/rubinius/./mspec/runner/mspec.rb:33:in `each'
      /opt/work/rubinius/./mspec/runner/mspec.rb:33:in `files'
      /opt/work/rubinius/./mspec/runner/mspec.rb:26:in `process'
      mspec/bin/mspec-ci:30
      
      1. 2253_exec.patch
        12 kB
        Riley Lynch
      2. exec-ex.rb
        0.4 kB
        Vladimir Sizikov

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        Well, we're getting there I have a different failure now. Are you able to run "ant test" to completion on your system?

            [junit] Testcase: test_backquote(org.jruby.test.TestUnitTestSuite$ScriptTest):	FAILED
            [junit] Faults encountered running test/test_backquote, complete output follows:
            [junit] Error:
            [junit] test_empty_backquotes(TestBackquote):
            [junit] Errno::ENOENT: No such file or directory - 
            [junit]     <script>:1:in `test_empty_backquotes'
        
        Show
        Charles Oliver Nutter added a comment - Well, we're getting there I have a different failure now. Are you able to run "ant test" to completion on your system? [junit] Testcase: test_backquote(org.jruby.test.TestUnitTestSuite$ScriptTest): FAILED [junit] Faults encountered running test/test_backquote, complete output follows: [junit] Error: [junit] test_empty_backquotes(TestBackquote): [junit] Errno::ENOENT: No such file or directory - [junit] <script>:1:in `test_empty_backquotes'
        Hide
        Riley Lynch added a comment -

        Mea culpa! I didn't run the whole suite, but now that I do, I get the same result that you do. Looks like test/test_load is also broken, but that's due to the shell metacharacter problem. Working on a fix for both issues.

        Show
        Riley Lynch added a comment - Mea culpa! I didn't run the whole suite, but now that I do, I get the same result that you do. Looks like test/test_load is also broken, but that's due to the shell metacharacter problem. Working on a fix for both issues.
        Hide
        Riley Lynch added a comment -

        Updated patch:

        • Added support for shell metacharacter detection – system() and exec() don't attempt path executable search when a shell metacharacter (as defined by MRI) is present in the commandline.
        • Backquote never attempts path executable search.

        I think it's passing all the tests now – but let me know if you find different!

        Show
        Riley Lynch added a comment - Updated patch: Added support for shell metacharacter detection – system() and exec() don't attempt path executable search when a shell metacharacter (as defined by MRI) is present in the commandline. Backquote never attempts path executable search. I think it's passing all the tests now – but let me know if you find different!
        Hide
        Vladimir Sizikov added a comment -

        OK, it's time to fix this, once and for all.

        Show
        Vladimir Sizikov added a comment - OK, it's time to fix this, once and for all.
        Hide
        Vladimir Sizikov added a comment -

        Riley, thank you very much for the patch! It was a great staring point I used to improve upon.

        Lots of new tests been added, all of them pass now on Windows and Linux, ShellLauncher got a major refactoring along the way.

        See cc4b619 and 138e726 on master branch.

        Tests and specs pass too.

        Show
        Vladimir Sizikov added a comment - Riley, thank you very much for the patch! It was a great staring point I used to improve upon. Lots of new tests been added, all of them pass now on Windows and Linux, ShellLauncher got a major refactoring along the way. See cc4b619 and 138e726 on master branch. Tests and specs pass too.

          People

          • Assignee:
            Vladimir Sizikov
            Reporter:
            Vladimir Sizikov
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: