Be a little less enthusiastic about calling abort()
authorArt Cancro <ajc@citadel.org>
Sun, 5 Mar 2023 20:57:21 +0000 (15:57 -0500)
committerArt Cancro <ajc@citadel.org>
Sun, 5 Mar 2023 20:57:21 +0000 (15:57 -0500)
citadel/server/citadel_defs.h
citadel/server/control.c
citadel/server/internet_addressing.c
citadel/server/msgbase.c
citadel/server/sysdep.c
citadel/server/user_ops.c
citadel/utils/chkpw.c

index ff890bcaf267aecfc52a02dd073f9ca4e6661b17..b3414e70cc21933756d4761dea6f12119192d8dd 100644 (file)
 
 #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)
index 3db2459c059e131f685fa16399331965452dd892..27bc05b01e52ceded4715719327b59281520ecdd 100644 (file)
@@ -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);
        }
 }
 
index 9cfbe3b8ad1f32077870904c793ef239fcb4ac7c..4b78eba24282422857bfad0a03411d9058c30272 100644 (file)
@@ -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);
index 3858d5a491ae5771493c37a9393d142c8667208e..892c6941e7892f3056a388544d7dcfdf1a5d4632 100644 (file)
@@ -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);
index 9f1193a5f15c4f30ce7a4d81a761169b4166f285..702cc2a90299c2fb11cda206697738626e69ccfd 100644 (file)
@@ -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.
index 84cc69023bfb8c077f0370c3d15b121a9c453fc2..fc21caf462fd63384f716c7f42ce47f06fb07ed3 100644 (file)
@@ -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);
        }
 }
index 2db604e17f87e823fe48ba73efb7ef15cf240d3e..c90049d91a8c7c5fc36590724b89935501fd6c62 100644 (file)
@@ -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);
        }
 }