# File src/ruby_supportlib/phusion_passenger/platform_info.rb, line 255
    def self.tmpexedir
      basename = "test-exe.#{Process.pid}.#{Thread.current.object_id}"
      attempts = []

      dir = tmpdir
      filename = "#{dir}/#{basename}"
      begin
        File.open(filename, 'w') do |f|
          f.puts("#!/bin/sh")
        end
        File.chmod(0700, filename)
        if system(filename)
          return dir
        else
          attempts << { :dir => dir,
            :error => "This directory's filesystem is mounted with the 'noexec' option." }
        end
      rescue Errno::ENOENT
        attempts << { :dir => dir, :error => "This directory doesn't exist." }
      rescue Errno::EACCES
        attempts << { :dir => dir, :error => "This program doesn't have permission to write to this directory." }
      rescue SystemCallError => e
        attempts << { :dir => dir, :error => e.message }
      ensure
        File.unlink(filename) rescue nil
      end

      dir = Dir.pwd
      filename = "#{dir}/#{basename}"
      begin
        File.open(filename, 'w') do |f|
          f.puts("#!/bin/sh")
        end
        File.chmod(0700, filename)
        if system(filename)
          return dir
        else
          attempts << { :dir => dir,
            :error => "This directory's filesystem is mounted with the 'noexec' option." }
        end
      rescue Errno::ENOENT
        attempts << { :dir => dir, :error => "This directory doesn't exist." }
      rescue Errno::EACCES
        attempts << { :dir => dir, :error => "This program doesn't have permission to write to this directory." }
      rescue SystemCallError => e
        attempts << { :dir => dir, :error => e.message }
      ensure
        File.unlink(filename) rescue nil
      end

      message = "ERROR: Cannot find suitable temporary directory\n" +
        "In order to run certain tests, this program " +
        "must be able to write temporary\n" +
        "executable files to some directory. However no such " +
        "directory can be found. \n" +
        "The following directories have been tried:\n\n"
      attempts.each do |attempt|
        message << " * #{attempt[:dir]}\n"
        message << "   #{attempt[:error]}\n"
      end
      message << "\nYou can solve this problem by telling this program what directory to write\n" <<
        "temporary executable files to, as follows:\n" <<
        "\n" <<
        "  Set the $TMPDIR environment variable to the desired directory's filename and\n" <<
        "  re-run this program.\n" <<
        "\n" <<
        "Notes:\n" <<
        "\n" <<
        " * If you're using 'sudo'/'rvmsudo', remember that 'sudo'/'rvmsudo' unsets all\n" <<
        "   environment variables, so you must set the environment variable *after*\n" <<
        "   having gained root privileges.\n" <<
        " * The directory you choose must writeable and must not be mounted with the\n" <<
        "   'noexec' option."
      raise RuntimeError, message
    end