bin: add support for SPOT_OOM_ABORT

* bin/common_setup.cc: Here.
* NEWS, bin/man/spot-x.x: Document it.
This commit is contained in:
Alexandre Duret-Lutz 2017-11-15 14:38:07 +01:00
parent b20687630b
commit 42a94c4dbe
3 changed files with 28 additions and 0 deletions

View file

@ -79,6 +79,14 @@ static void setup_sig_handler()
# define setup_sig_handler() while (0);
#endif
static void bad_alloc_handler()
{
std::set_new_handler(nullptr);
std::cerr << "not enough memory\n";
abort();
}
void
setup(char** argv)
{
@ -91,6 +99,9 @@ setup(char** argv)
argp_err_exit_status = 2;
if (getenv("SPOT_OOM_ABORT"))
std::set_new_handler(bad_alloc_handler);
std::ios_base::sync_with_stdio(false);
// Do not flush std::cout every time we read from std::cin, unless
// we are reading from a terminal. Note that we do flush regularly