Wrap at_exit block to correct exit codes being reset to 0

Ruby 1.9.3 with patchlevel lower then 382 does not deal with nested at_exit codes