Hi,

At Sun, 27 May 2007 08:19:53 +0900,
Johan Holmberg wrote in [ruby-core:11263]:
> If an exception occurs in an at_exit block, the Ruby process
> still exits with a zero exit status. This seems
> wrong. Example code:
> 
>   $ ruby -e 'at_exit { raise "an error" }' ; echo $?
>   -e:1: an error (RuntimeError)
>           from -e:1
>   0
> 
> All Ruby version I have tested work this way:

I'm not sure if this is a bug or a feature.


Index: eval.c =================================================================== --- eval.c (revision 12393) +++ eval.c (working copy) @@ -193,4 +193,7 @@ ruby_cleanup(int ex) ruby_default_signal(NUM2INT(sig)); } + else if (ex == 0) { + ex = 1; + } } @@ -226,8 +229,22 @@ ruby_exec(void) } +#if EXIT_SUCCESS == 0 && EXIT_FAILURE == 1 +#define state_to_exitcode(ex) (ex) +#else +static int +state_to_exitcode(int ex) +{ + switch (ex) { + case 0: return EXIT_SUCCESS; + case 1: return EXIT_FAILURE; + } + return ex; +} +#endif + void ruby_stop(int ex) { - exit(ruby_cleanup(ex)); + exit(state_to_exitcode(ruby_cleanup(ex))); }
-- Nobu Nakada