From 6e0b9660855f73b5eb9be28e8d37c02144efaf43 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sun, 5 Mar 2023 15:57:21 -0500 Subject: [PATCH] Be a little less enthusiastic about calling abort() --- citadel/server/citadel_defs.h | 16 +++++++++++----- citadel/server/control.c | 2 +- citadel/server/internet_addressing.c | 4 ++-- citadel/server/msgbase.c | 2 +- citadel/server/sysdep.c | 6 +++--- citadel/server/user_ops.c | 11 +++++------ citadel/utils/chkpw.c | 11 +++++------ 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/citadel/server/citadel_defs.h b/citadel/server/citadel_defs.h index ff890bcaf..b3414e70c 100644 --- a/citadel/server/citadel_defs.h +++ b/citadel/server/citadel_defs.h @@ -91,18 +91,24 @@ #define CTDLEXIT_SHUTDOWN 0 // Normal shutdown; do NOT auto-restart -// Exit codes 101 through 109 are used for conditions in which -// we deliberately do NOT want the service to automatically -// restart. +// Exit codes 101-109 are used for conditions in which we +// deliberately do NOT want the service to automatically restart. #define CTDLEXIT_CONFIG 101 // Could not read system configuration +#define CTDLEXIT_SANITY 102 // Internal sanity check failed #define CTDLEXIT_HOME 103 // Citadel home directory not found #define CTDLEXIT_DB 105 // Unable to initialize database #define CTDLEXIT_LIBCITADEL 106 // Incorrect version of libcitadel #define CTDL_EXIT_UNSUP_AUTH 107 // Unsupported auth mode configured #define CTDLEXIT_UNUSER 108 // Could not determine uid to run as #define CTDLEXIT_CRYPTO 109 // Problem initializing SSL or TLS -// Any other exit is likely to be from an unexpected abort (segfault etc) -// and we want to try restarting. + +// Other exit codes are probably ok to try starting the server again. +#define CTDLEXIT_REDIRECT 110 // Redirect buffer failure +#define CTDLEXIT_CHKPWD 111 // chkpwd daemon failed +#define CTDLEXIT_THREAD 112 // Problem setting up multithreading +#define CTDLEXIT_BAD_MAGIC 113 // internet_addressing() magic number is wrong + +// Any other exit is likely to be from an unexpected abort (segfault etc) and we want to try restarting. // Reasons why a session would be terminated (set CC->kill_me to these values) diff --git a/citadel/server/control.c b/citadel/server/control.c index 3db2459c0..27bc05b01 100644 --- a/citadel/server/control.c +++ b/citadel/server/control.c @@ -155,7 +155,7 @@ void check_control(void) { if (sanity_diag_mode == 1) { syslog(LOG_INFO, "control: sanity check diagnostic mode is active - exiting now"); - abort(); + exit(CTDLEXIT_SANITY); } } diff --git a/citadel/server/internet_addressing.c b/citadel/server/internet_addressing.c index 9cfbe3b8a..4b78eba24 100644 --- a/citadel/server/internet_addressing.c +++ b/citadel/server/internet_addressing.c @@ -1,7 +1,7 @@ // This file contains functions which handle the mapping of Internet addresses // to users on the Citadel system. // -// Copyright (c) 1987-2022 by the citadel.org team +// Copyright (c) 1987-2023 by the citadel.org team // // This program is open source software. Use, duplication, or disclosure // is subject to the terms of the GNU General Public License, version 3. @@ -527,7 +527,7 @@ void free_recipients(struct recptypes *valid) { if (valid->recptypes_magic != RECPTYPES_MAGIC) { syslog(LOG_ERR, "internet_addressing: attempt to call free_recipients() on some other data type!"); - abort(); + exit(CTDLEXIT_BAD_MAGIC); } if (valid->errormsg != NULL) free(valid->errormsg); diff --git a/citadel/server/msgbase.c b/citadel/server/msgbase.c index 3858d5a49..892c6941e 100644 --- a/citadel/server/msgbase.c +++ b/citadel/server/msgbase.c @@ -2748,7 +2748,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ */ if (CC->redirect_buffer != NULL) { syslog(LOG_ALERT, "msgbase: CC->redirect_buffer is not NULL during message submission!"); - abort(); + exit(CTDLEXIT_REDIRECT); } CC->redirect_buffer = NewStrBufPlain(NULL, SIZ); CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ALL, 0, 1, QP_EADDR); diff --git a/citadel/server/sysdep.c b/citadel/server/sysdep.c index 9f1193a5f..702cc2a90 100644 --- a/citadel/server/sysdep.c +++ b/citadel/server/sysdep.c @@ -3,7 +3,7 @@ // Here's where we (hopefully) have most parts of the Citadel server that // might need tweaking when run on different operating system variants. // -// Copyright (c) 1987-2022 by the citadel.org team +// Copyright (c) 1987-2023 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. @@ -72,12 +72,12 @@ void init_sysdep(void) { if (pthread_key_create(&ThreadKey, NULL) != 0) { // TSD for threads syslog(LOG_ERR, "pthread_key_create() : %m"); - abort(); + exit(CTDLEXIT_THREAD); } if (pthread_key_create(&MyConKey, NULL) != 0) { // TSD for sessions syslog(LOG_CRIT, "sysdep: can't create TSD key: %m"); - abort(); + exit(CTDLEXIT_THREAD); } // Interript, hangup, and terminate signals should cause the server to shut down. diff --git a/citadel/server/user_ops.c b/citadel/server/user_ops.c index 84cc69023..fc21caf46 100644 --- a/citadel/server/user_ops.c +++ b/citadel/server/user_ops.c @@ -1,6 +1,6 @@ // Server functions which perform operations on user objects. // -// Copyright (c) 1987-2022 by the citadel.org team +// Copyright (c) 1987-2023 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. @@ -739,21 +739,21 @@ void start_chkpwd_daemon(void) { if ((stat(file_chkpwd, &filestats)==-1) || (filestats.st_size==0)) { syslog(LOG_ERR, "user_ops: %s: %m", file_chkpwd); - abort(); + exit(CTDLEXIT_CHKPWD); } if (pipe(chkpwd_write_pipe) != 0) { syslog(LOG_ERR, "user_ops: unable to create pipe for chkpwd daemon: %m"); - abort(); + exit(CTDLEXIT_CHKPWD); } if (pipe(chkpwd_read_pipe) != 0) { syslog(LOG_ERR, "user_ops: unable to create pipe for chkpwd daemon: %m"); - abort(); + exit(CTDLEXIT_CHKPWD); } chkpwd_pid = fork(); if (chkpwd_pid < 0) { syslog(LOG_ERR, "user_ops: unable to fork chkpwd daemon: %m"); - abort(); + exit(CTDLEXIT_CHKPWD); } if (chkpwd_pid == 0) { dup2(chkpwd_write_pipe[0], 0); @@ -761,7 +761,6 @@ void start_chkpwd_daemon(void) { for (i=2; i<256; ++i) close(i); execl(file_chkpwd, file_chkpwd, NULL); syslog(LOG_ERR, "user_ops: unable to exec chkpwd daemon: %m"); - abort(); exit(errno); } } diff --git a/citadel/utils/chkpw.c b/citadel/utils/chkpw.c index 2db604e17..c90049d91 100644 --- a/citadel/utils/chkpw.c +++ b/citadel/utils/chkpw.c @@ -1,4 +1,4 @@ -// Copyright (c) 1987-2022 by the citadel.org team +// Copyright (c) 1987-2023 by the citadel.org team // // This program is open source software. Use, duplication, or disclosure // is subject to the terms of the GNU General Public License, version 3. @@ -68,21 +68,21 @@ void start_chkpwd_daemon(void) { if ((stat(file_chkpwd, &filestats)==-1) || (filestats.st_size==0)){ printf("didn't find chkpwd daemon in %s: %s\n", file_chkpwd, strerror(errno)); - abort(); + exit(1); } if (pipe(chkpwd_write_pipe) != 0) { printf("Unable to create pipe for chkpwd daemon: %s\n", strerror(errno)); - abort(); + exit(2); } if (pipe(chkpwd_read_pipe) != 0) { printf("Unable to create pipe for chkpwd daemon: %s\n", strerror(errno)); - abort(); + exit(3); } chkpwd_pid = fork(); if (chkpwd_pid < 0) { printf("Unable to fork chkpwd daemon: %s\n", strerror(errno)); - abort(); + exit(4); } if (chkpwd_pid == 0) { dup2(chkpwd_write_pipe[0], 0); @@ -90,7 +90,6 @@ void start_chkpwd_daemon(void) { for (i=2; i<256; ++i) close(i); execl(file_chkpwd, file_chkpwd, NULL); printf("Unable to exec chkpwd daemon: %s\n", strerror(errno)); - abort(); exit(errno); } } -- 2.39.2