How to remove space occupied errors in ruby under cygwin

When you install custom ruby versions using a tool like ruby-build you might run into address space occupied problems.

After successfully installing ruby 2.0.0-p247 in cygwin with ruby-build as a rbenv plugin. I was getting weird child_info_fork::abort: errors that caused my call to gem install bundler to fail.

The error messages looked like this:

child_info_fork::abort: address space needed by '...' (...) is already occupied

I found this mailing list entry that included a rubyrebase script and a post describing a solution for rvm which was similiar to this.

Since these solutions lacked a single script that could be executed using ash I have created my own. You have to run the script using

ash -c '/path/to/rubyrebase'

Make sure you have closed all cygwin processes.

#!/bin/ash

# Define constants
PATH=$(cd $tp2 && pwd):/usr/bin:/bin

# Define functions
cleanup()
{
    rm -f "${TmpFile}"
    exit ${ExitCode}
}

# Set temp directory
TmpDir="${TMP:-${TEMP:-/tmp}}"

TmpFile="$TmpDir/rubyrebase.lst"

find ~/.rbenv/versions/ -iname "*.dll" -print > "${TmpFile}"
find ~/.rbenv/versions/ -iname "*.so" -print >> "${TmpFile}"

rebaseall -v -T "${TmpFile}"

ExitCode=$?

cleanup