diff --git a/main.cpp b/main.cpp index e41e332..f8abdb9 100644 --- a/main.cpp +++ b/main.cpp @@ -26,6 +26,8 @@ along with pilang. If not, see . #include #include #include +#include +#include #include #include @@ -41,9 +43,19 @@ static std::string room; void panic(std::string message) { + // Print message std::cerr << std::endl << "An unhandled exception occured:" << std::endl << message << std::endl; + // Print stacktrace + void *array[10]; + int size = backtrace(array, 10); + std::cerr << std::endl << "Stacktrace:" << std::endl; + backtrace_symbols_fd(array, size, STDERR_FILENO); + // Abort abort(); } +void sigsegv_panic(int) { + panic("Segmentation fault received!"); +} std::string ltrim(const std::string &s) { @@ -303,6 +315,8 @@ std::string get_rss_url(GumboNode *node) { // Currently unused int main(int argc, char *argv[]) { + // Catch SIGSEGV + signal(SIGSEGV, sigsegv_panic); // Show license note if --license was given as first argument if (argc > 1 and !strncmp(argv[1], "--license", 9)) { std::cout << "CommSyFuse Copyright (C) 2020 niansa" << std::endl; @@ -379,8 +393,10 @@ int main(int argc, char *argv[]) { // Await user input std::cout << "? " << std::flush; std::getline (std::cin,userinstr); - // Check string input options first5 - if (userinstr == "r") { + // Check string input options first + if (userinstr == "") { + continue; + } else if (userinstr == "r") { execve(argv[0], argv, nullptr); } // Try to convert input to unsigned long