rubinius/rubinius — pull request #1904 by lmars (2012-09-16 17:30:20+00:00)
Title: Close open file descriptors when calling Process.spawn

I based the change broadly on the changes in [this commit](https://github.com/ruby/ruby/commit/278b63a3) from MRI.

However, I wasnt sure if changes similar to [these](https://github.com/ruby/ruby/commit/fdcac098) (which extend the "update max fd" calls to pretty much everywhere `open(2)` or `pipe(2)` are called) where necessary (e.g. [here](https://github.com/rubinius/rubinius/blob/master/vm/util/dlmalloc.c#L170))?

I attempted to do something similar to [`closefrom`](http://www.unix.com/man-page/All/3c/closefrom/):

```ruby
3.upto(255) do |fd|
begin
fd_to_io(fd).close_on_exec = true
rescue Errno::EBADF
end
end
```

but the process locked up, and I didnt investigate further.