Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detecting a failure to execute the process #18

Closed
mitchellh opened this issue Dec 19, 2011 · 5 comments
Closed

Detecting a failure to execute the process #18

mitchellh opened this issue Dec 19, 2011 · 5 comments

Comments

@mitchellh
Copy link
Contributor

ChildProcess currently doesn't provide a uniform way to detect that there was a failure to execute the given process. Java differs from Linux which differs from Windows.

It would be nice if there was a uniform error I could catch that would signal that ChildProcess wasn't able to start the childprocess... though I'm not sure how to do that easily portably.

In the mean time, I'm building it in to a helper to catch the various exit cases...

For example, executing foo bar baz...

On Linux

The following comes through via the stderr of the child process:

/Users/mitchellh/.rvm/gems/ruby-1.9.3-p0/gems/childprocess-0.2.3/lib/childprocess/unix/process.rb:94:in `exec': No such file or directory - foo (Errno::ENOENT)
    from /Users/mitchellh/.rvm/gems/ruby-1.9.3-p0/gems/childprocess-0.2.3/lib/childprocess/unix/process.rb:94:in `block in launch_process'
    from /Users/mitchellh/.rvm/gems/ruby-1.9.3-p0/gems/childprocess-0.2.3/lib/childprocess/unix/process.rb:83:in `fork'
    from /Users/mitchellh/.rvm/gems/ruby-1.9.3-p0/gems/childprocess-0.2.3/lib/childprocess/unix/process.rb:83:in `launch_process'
    from /Users/mitchellh/.rvm/gems/ruby-1.9.3-p0/gems/childprocess-0.2.3/lib/childprocess/abstract_process.rb:58:in `start'
    from /Users/mitchellh/code/personal/ruby/vagrant/lib/vagrant/util/subprocess.rb:37:in `execute'
    from /Users/mitchellh/code/personal/ruby/vagrant/lib/vagrant/util/subprocess.rb:15:in `execute'
    from test.rb:7:in `<main>'

On Java

The following exception is raised directly in the parent process:

NativeException: java.io.IOException: Cannot run program "foo" (in directory "/Users/mitchellh/code/personal/ruby/vagrant"): error=2, No such file or directory
  launch_process at /Users/mitchellh/.rvm/gems/jruby-1.6.5/gems/childprocess-0.2.3/lib/childprocess/jruby/process.rb:59
           start at /Users/mitchellh/.rvm/gems/jruby-1.6.5/gems/childprocess-0.2.3/lib/childprocess/abstract_process.rb:58
         execute at /Users/mitchellh/code/personal/ruby/vagrant/lib/vagrant/util/subprocess.rb:37
         execute at /Users/mitchellh/code/personal/ruby/vagrant/lib/vagrant/util/subprocess.rb:15
          (root) at test.rb:7

On Windows

(I haven't tested on Windows, sorry, but I imagine it will be different)

@jarib
Copy link
Collaborator

jarib commented Dec 20, 2011

Yes, this seems like something we should handle uniformly. I'm not sure exactly how, e.g. on Unix we would need to somehow communicate back to the parent process that the exec() call failed. I may take a look at how OpenJDK does this and adopt that technique.

@jarib
Copy link
Collaborator

jarib commented Dec 20, 2011

Setting up a pipe with FD_CLOEXEC and then wait for it to be closed in the parent, or optionally write the error back is probably the right approach for this.

@jarib jarib closed this as completed in 5488ed4 Dec 20, 2011
@jarib
Copy link
Collaborator

jarib commented Dec 27, 2011

Now released in the 0.2.4 gem.

@mitchellh
Copy link
Contributor Author

Amazing. I'll put it to use right NOW.

ZOMG

@mitchellh
Copy link
Contributor Author

Ballin': hashicorp/vagrant@0d2cf4b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants