From: Art Cancro Date: Sun, 2 May 2021 20:25:21 +0000 (-0400) Subject: New server option -b to specify the name of a file to which backtrace should be writt... X-Git-Tag: v939~62 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=6e9fd5f635b9eccd27c91f22b4d8690279e6c20d New server option -b to specify the name of a file to which backtrace should be written if the server crashes. --- diff --git a/citadel/citserver.c b/citadel/citserver.c index cde79e0f6..48c4f5ac2 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -33,6 +33,7 @@ int ScheduledShutdown = 0; time_t server_startup_time; int panic_fd; int openid_level_supported = 0; +char *backtrace_filename = NULL; /* diff --git a/citadel/citserver.h b/citadel/citserver.h index adfe476c1..a702e089e 100644 --- a/citadel/citserver.h +++ b/citadel/citserver.h @@ -51,3 +51,4 @@ extern int panic_fd; char CtdlCheckExpress(void); extern time_t server_startup_time; extern int openid_level_supported; +extern char *backtrace_filename; diff --git a/citadel/server_main.c b/citadel/server_main.c index 9dad4d756..33fdc33bc 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -1,16 +1,15 @@ -/* - * citserver's main() function lives here. - * - * Copyright (c) 1987-2021 by the citadel.org team - * - * This program is open source software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ +// citserver's main() function lives here. +// +// Copyright (c) 1987-2021 by the citadel.org team +// +// This program is open source software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 3. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + #include #include #include @@ -70,7 +69,7 @@ void ctdl_lockfile(int op) { int main(int argc, char **argv) { char facility[32]; - int a; /* General-purpose variables */ + int a; // General-purpose variables struct passwd pw, *pwp = NULL; char pwbuf[SIZ]; int drop_root_perms = 1; @@ -101,7 +100,7 @@ int main(int argc, char **argv) { syslog(LOG_INFO, "%s", libcitadel_version_string()); /* parse command-line arguments */ - while ((a=getopt(argc, argv, "cl:dh:x:t:B:Dru:s:")) != EOF) switch(a) { + while ((a=getopt(argc, argv, "cl:dh:x:t:B:Dru:s:b:")) != EOF) switch(a) { // test this binary for compatibility and exit case 'c': @@ -170,6 +169,10 @@ int main(int argc, char **argv) { sanity_diag_mode = atoi(optarg); break; + case 'b': + backtrace_filename = strdup(optarg); + break; + // any other parameter makes it crash and burn default: fprintf(stderr, "citserver: usage: " diff --git a/citadel/sysdep.c b/citadel/sysdep.c index fd7441c45..3caa2dcfc 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -55,14 +55,26 @@ static RETSIGTYPE signal_cleanup(int signum) { int bt_size; char **bt_syms; int i; + FILE *backtrace_fp = NULL; + + if (backtrace_filename != NULL) { + backtrace_fp = fopen(backtrace_filename, "w"); + } bt_size = backtrace(bt, 1024); bt_syms = backtrace_symbols(bt, bt_size); for (i = 1; i < bt_size; i++) { syslog(LOG_DEBUG, "%s", bt_syms[i]); + if (backtrace_fp) { + fprintf(backtrace_fp, "%s\n", bt_syms[i]); + } } free(bt_syms); + if (backtrace_fp) { + fclose(backtrace_fp); + } + exit_signal = signum; server_shutting_down = 1; }