1
0
Fork 0
mirror of https://gitlab.com/niansa/commsyfuse.git synced 2025-03-06 20:48:31 +01:00

Catch segmentation fault to print stacktrace

This commit is contained in:
niansa 2020-04-29 16:41:50 +02:00
parent c4d3de6c03
commit ee038d445b

View file

@ -26,6 +26,8 @@ along with pilang. If not, see <https://www.gnu.org/licenses/>.
#include <csignal>
#include <cstdio>
#include <unistd.h>
#include <signal.h>
#include <execinfo.h>
#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
@ -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