capture and return exit status on at_exit hook