Sha256: eaedbdeedd0acee4ab37cbbd1356336b8fe72d01186e12cf589df60431d74f23

Contents?: true

Size: 884 Bytes

Versions: 5

Compression:

Stored size: 884 Bytes

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 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.
    module SafeExec
      def safe_exec(command)
        fork_instead = false
        begin
          pid = nil
          pid = fork if fork_instead
          Kernel.exec(command) if pid.nil?
          Process.wait(pid) if pid
        rescue Errno::E045
          # 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

5 entries across 5 versions & 2 rubygems

Version Path
vagrantup-0.8.2 lib/vagrant/util/safe_exec.rb
vagrantup-0.8.1 lib/vagrant/util/safe_exec.rb
vagrantup-0.8.0 lib/vagrant/util/safe_exec.rb
vagrant-0.8.2 lib/vagrant/util/safe_exec.rb
vagrant-0.8.1 lib/vagrant/util/safe_exec.rb