Skip to content

Commit

Permalink
Merge pull request #111 from martinRenou/handle_kill_sig
Browse files Browse the repository at this point in the history
  • Loading branch information
marimeireles committed Oct 6, 2021
2 parents 3ef4671 + 2cfcfba commit a50d807
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main.cpp
Expand Up @@ -9,6 +9,14 @@

#include <memory>
#include <iostream>
#include <signal.h>

#ifdef __GNUC__
#include <stdio.h>
#include <execinfo.h>
#include <stdlib.h>
#include <unistd.h>
#endif

#include "xeus/xkernel.hpp"
#include "xeus/xkernel_configuration.hpp"
Expand All @@ -17,6 +25,26 @@
#include "xeus-sqlite/xeus_sqlite_interpreter.hpp"
#include "xeus-sqlite/xeus_sqlite_config.hpp"

#ifdef __GNUC__
void handler(int sig)
{
void* array[10];

// get void*'s for all entries on the stack
size_t size = backtrace(array, 10);

// print out all the frames to stderr
fprintf(stderr, "Error: signal %d:\n", sig);
backtrace_symbols_fd(array, size, STDERR_FILENO);
exit(1);
}
#endif

void stop_handler(int /*sig*/)
{
exit(0);
}

bool should_print_version(int argc, char* argv[])
{
for (int i = 0; i < argc; ++i)
Expand Down Expand Up @@ -56,6 +84,16 @@ int main(int argc, char* argv[])
return 0;
}

// Registering SIGSEGV handler
#ifdef __GNUC__
std::clog << "registering handler for SIGSEGV" << std::endl;
signal(SIGSEGV, handler);

// Registering SIGINT and SIGKILL handlers
signal(SIGKILL, stop_handler);
#endif
signal(SIGINT, stop_handler);

// Load configuration file
std::string file_name = extract_filename(argc, argv);

Expand Down

0 comments on commit a50d807

Please sign in to comment.