Sha256: b362a1bb9eb98769f9d2317a00293eaf04fd4b61bff40fc617d7a4d4b4feda83

Contents?: true

Size: 1.24 KB

Versions: 34

Compression:

Stored size: 1.24 KB

Contents

module Vagrant
  module Util
    # This module provies a `safe_exec` method which is a drop-in
    # replacement for `Kernel.exec` which addresses a specific issue
    # which manifests on OS X 10.5 (GH-51) and perhaps other operating systems.
    # This issue causes `exec` to fail if there is more than one system
    # thread. In that case, `safe_exec` automatically falls back to
    # forking.
    class SafeExec
      def self.exec(command, *args)
        # Create a list of things to rescue from. Since this is OS
        # specific, we need to do some defined? checks here to make
        # sure they exist.
        rescue_from = []
        rescue_from << Errno::EOPNOTSUPP if defined?(Errno::EOPNOTSUPP)
        rescue_from << Errno::E045 if defined?(Errno::E045)
        rescue_from << SystemCallError

        fork_instead = false
        begin
          pid = nil
          pid = fork if fork_instead
          Kernel.exec(command, *args) if pid.nil?
          Process.wait(pid) if pid
        rescue *rescue_from
          # We retried already, raise the issue and be done
          raise if fork_instead

          # The error manifested itself, retry with a fork.
          fork_instead = true
          retry
        end
      end
    end
  end
end

Version data entries

34 entries across 31 versions & 10 rubygems

Version Path
tamtam-vagrant-reload-1.1.3 vendor/cache/vagrant-0ac2a8738841/lib/vagrant/util/safe_exec.rb
tamtam-vagrant-reload-1.1.2 vendor/cache/vagrant-0ac2a8738841/lib/vagrant/util/safe_exec.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/lib/vagrant/util/safe_exec.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/lib/vagrant/util/safe_exec.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/lib/vagrant/util/safe_exec.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/lib/vagrant/util/safe_exec.rb
vagrant-unbundled-1.8.5.2 lib/vagrant/util/safe_exec.rb
vagrant-unbundled-1.8.5.1 lib/vagrant/util/safe_exec.rb
vagrant-unbundled-1.8.4.2 lib/vagrant/util/safe_exec.rb
vagrant-unbundled-1.8.4.1 lib/vagrant/util/safe_exec.rb
tamtam-vagrant-reload-1.1.1 vendor/cache/vagrant-0ac2a8738841/lib/vagrant/util/safe_exec.rb
tamtam-vagrant-reload-1.1 vendor/cache/vagrant-0ac2a8738841/lib/vagrant/util/safe_exec.rb
vagrant-unbundled-1.8.1.2 lib/vagrant/util/safe_exec.rb
vagrant-unbundled-1.8.1.1 lib/vagrant/util/safe_exec.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-272fb27e0536/lib/vagrant/util/safe_exec.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-1cf2a8db4ccb/lib/vagrant/util/safe_exec.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-309e896975d1/lib/vagrant/util/safe_exec.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-b421af58e8b3/lib/vagrant/util/safe_exec.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/bundler/gems/vagrant-1e28f1ac31e7/lib/vagrant/util/safe_exec.rb
tnargav-1.3.6 lib/vagrant/util/safe_exec.rb