[erlang-bugs] Wrong EXIT status when shell startup fails

Matthias Lang matthias@REDACTED
Thu Jan 5 11:13:11 CET 2012


Here's a simpler test case:

   otp_src_R15B >bin/erl < /dev/null
   Eshell V5.9  (abort with ^G)
   1> *** Terminating erlang (nonode@REDACTED)
   otp_src_R15B >echo $?
   0

but that's expected: the shell is not failing, it's reaching eof and
exiting normally since there isn't any more input to read, compare:

   > cat < /dev/null
   > echo $?
   0

(The code which does the normal exit is shell.erl:server_loop())

The usual way to run Erlang with nothing connected to stdin is to pass
the -noinput flag.

Matt

--------------------

On Thursday, December 08, Thomas Lange wrote:
> There is a bug that occurs when Erlang is started with shell activated
> but shell cannot be launched. When this happens, erlang terminates
> with exit status 0, which is incorrect behavior.
> 
> A typical example is when Erlang is started via a cron job.
> 
> How to trigger bug:
> 
> * Put both attached files in /tmp
> * update crontest with path to your otp release
> * compile crontest.erl
> * run /tmp/crontest via cron
> * cronjob should fail
> 
> Example on system running debian squeeze and otp git HEAD:
> ------------------------------------------
> k4:/tmp$ chmod +x crontest
> k4:/tmp$ /u1/otp/bin/erlc crontest.erl
> k4:/tmp$ ls -l crontest*
> -rwxr-xr-x 1 tle tle 681 Dec  8 14:42 crontest
> -rw-r--r-- 1 tle tle 536 Dec  8 14:45 crontest.beam
> -rw-r--r-- 1 tle tle  83 Dec  8 14:42 crontest.erl
> k4:/tmp$ ./crontest
> Erlang R15B (erts-5.9) [source] [64-bit] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]
> 
> Eshell V5.9  (abort with ^G)
> 1> Erlang exit status 100. Normal result when everything is started ok.
> 
> k4:/tmp$ crontab -e
> crontab: installing new crontab
> k4:/tmp$ crontab -l
> # m h  dom mon dow   command
> 47 14 * * * /tmp/crontest
> 
> Syslog:
> Dec  8 14:47:02 k4 /USR/SBIN/CRON[27923]: (CRON) error (grandchild #27924 failed with exit status 1)
> 
> Cron daemon error mail contains:
> ----------------
> Eshell V5.9  (abort with ^G)
> 1> *** Terminating erlang (nonode@REDACTED)
> Erlang exit status 0. Should never happen!
> ----------------
> 
> /Thomas

> -module(crontest).
> 
> -export([go/0]).
> 
> go() ->
>     timer:sleep(500),
>     halt(100).

> #!/bin/sh
> # Author: thomas@REDACTED
> # Exercises an erlang bug when running this script via cron:
> #
> # When cron is starting erlang with shell activated, erlang dies
> # with "*** Terminating erlang (nonode@REDACTED)"
> # This is fine, but exit status is 0! This is wrong.
> 
> # Replace with path to wanted otp version
> OTP=/u1/otp
> 
> # Start with shell activated
> $OTP/bin/erl -s crontest go -pz /tmp
> 
> # Copy exit value
> exit_status=$?
> 
> case $exit_status in
>     100)
> 	echo "Erlang exit status 100. Normal result when everything is started ok."
> 	exit 0
> 	;;
>     0)
> 	echo "Erlang exit status 0. Should never happen!"
> 	exit 1;
> 	;;
>     *)
> 	echo "Exit status $exit_status."
> 	exit $exit_status
> esac

> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://erlang.org/mailman/listinfo/erlang-bugs




More information about the erlang-bugs mailing list