New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling exit in at_exit callback results in infinite loop. #7178
Comments
Comment author: @mshinwell According to "man atexit" on my system, the POSIX.1-2001 behaviour of calling exit within an atexit handler is undefined. Indeed it suggests an infinite loop is a possible outcome. I think the correct way of exiting from an atexit function is probably to call _exit. |
Comment author: @dbuenzli Indeed http://pubs.opengroup.org/onlinepubs/9699919799/functions/atexit.html requires from an atexit function either to return or to call _exit or "a function that causes abnormal termination". So a binding to _exit or abort (preferably the former) would be nice. |
Comment author: @dbuenzli Note that this is not a binding issue since everything is handled in OCaml land. If we leave threading issues aside, the at_exit function here: Lines 519 to 521 in 393f068
let exit retcode = Could be replaced by: let exit_code = ref None to solve the problem. The semantics is that the last non-zero [exit] call gives the final exit code of the program. |
Comment author: @xavierleroy The merge of #1790 fixes this issue, even if I didn't realize when I committed it. Marking this MPR as resolved in 4.07. |
Original bug ID: 7178
Reporter: @dbuenzli
Assigned to: @xavierleroy
Status: resolved (set by @xavierleroy on 2018-05-23T18:00:20Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.02.3
Fixed in version: 4.07.0+dev/beta2/rc1/rc2
Category: standard library
Related to: #7796
Monitored by: @gasche @diml @hcarty @dbuenzli
Bug description
E.g. in C the following program will exit with 1.
#include <stdio.h>
#include <stdlib.h>
void do_exit (void)
{
puts ("Goodbye, world!\n");
exit (1);
}
int main (int argc, char *argv[])
{
atexit (do_exit);
puts ("Hello, world!\n");
return 0;
}
Steps to reproduce
ocaml
at_exit (fun () -> exit 1);;
^D
Fatal error: exception Stack overflow
Raised by primitive operation at file "pervasives.ml", line 515, characters 30-3
The text was updated successfully, but these errors were encountered: