master_cleanup() is now the global shutdown/exit function
authorArt Cancro <ajc@citadel.org>
Fri, 25 Aug 2023 21:08:53 +0000 (12:08 -0900)
committerArt Cancro <ajc@citadel.org>
Fri, 25 Aug 2023 21:08:53 +0000 (12:08 -0900)
citadel/server/backends/berkeley_db/berkeley_db.c
citadel/server/citadel_defs.h
citadel/server/citserver.c
citadel/server/citserver.h
citadel/server/server_main.c
citadel/server/sysdep.c
citadel/server/sysdep_decls.h

index 3d1a0261b1b5bbfb413ceef0226471e4b125d2ae..147446f6e0038452b74e885d537ed53bbdd0392f 100644 (file)
@@ -244,7 +244,7 @@ void bdb_open_databases(void) {
                //exit(CTDLEXIT_DB);
        //}
 
-       flags = DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE | DB_INIT_TXN | DB_INIT_LOCK | DB_THREAD | DB_INIT_LOG;
+       flags = DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE | DB_INIT_TXN | /*DB_INIT_LOCK |*/ DB_THREAD | DB_INIT_LOG;
        syslog(LOG_DEBUG, "bdb: bdb_env->open(bdb_env, %s, %d, 0)", ctdl_db_dir, flags);
        ret = bdb_env->open(bdb_env, ctdl_db_dir, flags, 0);                            // try opening the database cleanly
        if (ret == DB_RUNRECOVERY) {
@@ -322,10 +322,13 @@ void bdb_close_databases(void) {
        }
 
        // Close the handle.
+       syslog(LOG_INFO, "bdb: closing environment");
        ret = bdb_env->close(bdb_env, DB_FORCESYNC);
        if (ret) {
                syslog(LOG_ERR, "bdb: DBENV->close: %s", db_strerror(ret));
        }
+
+       syslog(LOG_INFO, "bdb: shutdown completed");
 }
 
 
index d39571f905fe2a502e5fc1d3cf491f8fa0818e72..48fe0760ad91c23ddf099611fcaf6fae1e221aae 100644 (file)
@@ -87,7 +87,7 @@
 #define EXPIRE_NUMMSGS         2       // Keep only latest n messages
 #define EXPIRE_AGE             3       // Expire messages after n days
 
-#define RECPTYPES_MAGIC 0xfeeb
+#define RECPTYPES_MAGIC                0xfeeb
 
 #define CTDLEXIT_SHUTDOWN      0       // Normal shutdown; do NOT auto-restart
 
index 73ca220b5045eb1b0df5519f318da77429ed1a58..aa7e19139b22c991f94ce8631cae33b7c0601516 100644 (file)
@@ -121,7 +121,7 @@ void master_startup(void) {
 
 
 // Cleanup routine to be called when the server is shutting down.  Returns the needed exit code.
-int master_cleanup(int exitcode) {
+void master_cleanup(int exitcode) {
        static int already_cleaning_up = 0;
 
        if (already_cleaning_up) {
@@ -131,8 +131,8 @@ int master_cleanup(int exitcode) {
        }
        already_cleaning_up = 1;
 
-       // Do system-dependent stuff
-       sysdep_master_cleanup();
+       // Close the sockets
+       context_cleanup();
 
        // Close the configuration system
        shutdown_config_system();
@@ -156,13 +156,12 @@ int master_cleanup(int exitcode) {
        fflush(stdout);
        fflush(stderr);
 
-       if (restart_server != 0) {
-               exitcode = 1;
-       }
-       else if ((running_as_daemon != 0) && ((exitcode == 0))) {
+       if ((running_as_daemon != 0) && ((exitcode == 0))) {
                exitcode = CTDLEXIT_SHUTDOWN;
        }
-       return (exitcode);
+
+       ctdl_lockfile(0);
+       exit(exitcode);
 }
 
 
index 09412b0524364d09d502bbff7a13b5c607c8ed70..569aeeba17b7ba3892f133f1b3d5b3f8b7e3995f 100644 (file)
@@ -26,7 +26,7 @@ struct UserProcList {
 #define CTDLUSERIP      (IsEmptyStr(CC->cs_addr) ?  CC->cs_clientinfo: CC->cs_addr)
 
 void master_startup (void);
-int master_cleanup (int exitcode);
+void master_cleanup (int exitcode);
 void set_wtmpsupp (char *newtext);
 void set_wtmpsupp_to_current_room(void);
 void do_command_loop(void);
@@ -37,6 +37,7 @@ void citproto_begin_admin_session(void);
 void help_subst (char *strbuf, char *source, char *dest);
 char CtdlCheckExpress(void);
 int CheckIfAlreadySeen(StrBuf *guid);
+void ctdl_lockfile(int);
 
 extern int panic_fd;
 extern time_t server_startup_time;
index a90ddd02d748189115fe85efee7c2e45e975df88..b5b3c3a575c62f6904efac0931402f47341262f5 100644 (file)
@@ -316,11 +316,5 @@ int main(int argc, char **argv) {
        }
        
        // Get ready to shut down the server.
-       int exit_code = master_cleanup(exit_signal);
-       ctdl_lockfile(0);
-       if (restart_server) {
-               syslog(LOG_INFO, "main: *** CITADEL SERVER IS RESTARTING ***");
-               execv(argv[0], argv);
-       }
-       return(exit_code);
+       master_cleanup(exit_signal);
 }
index 668b50bd023d4e8c1a402f2f273c7de9240bcd79..f6e34a3dd00b766ceef337fcc540c5a9f33c5bfd 100644 (file)
@@ -1,12 +1,10 @@
-// Citadel "system dependent" stuff.
-//
-// Here's where we (hopefully) have most parts of the Citadel server that
-// might need tweaking when run on different operating system variants.
+// This started as a portability layer, but then everything got more standard.
+// Most of it handles network communication.
 //
 // 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.
+// This program is open source software.  Use, duplication, or disclosure
+// is subject to the terms of the GNU General Public License, version 3.
 
 #include "sysdep.h"
 #include <stdlib.h>
@@ -121,6 +119,7 @@ int ctdl_tcp_server(char *ip_addr, int port_number, int queue_len) {
        if (    (ip_addr == NULL)                                                       // any IPv6
                || (IsEmptyStr(ip_addr))
                || (!strcmp(ip_addr, "*"))
+               || (!strcmp(ip_addr, "::"))
        ) {
                ip_version = 6;
                sin6.sin6_addr = in6addr_any;
@@ -567,13 +566,6 @@ int client_getln(char *buf, int bufsize) {
 }
 
 
-// The system-dependent part of master_cleanup() - close the master socket.
-void sysdep_master_cleanup(void) {
-       context_cleanup();
-}
-
-
-
 pid_t current_child;
 void supervisor_process_shutdown(int signum) {
        kill(current_child, signum);
@@ -937,7 +929,7 @@ do_select:  force_purge = 0;
                begin_critical_section(S_SESSION_TABLE);
                for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
                        int checkfd = ptr->client_socket;
-                       if ((checkfd != -1) && (ptr->state == CON_IDLE) ){
+                       if ((checkfd != -1) && (ptr->state == CON_IDLE)){
                                if (FD_ISSET(checkfd, &readfds)) {
                                        ptr->input_waiting = 1;
                                        if (!bind_me) {
@@ -947,7 +939,8 @@ do_select:  force_purge = 0;
                                        else {
                                                ptr->state = CON_READY;
                                        }
-                               } else if ((ptr->is_async) && (ptr->async_waiting) && (ptr->h_async_function)) {
+                               }
+                               else if ((ptr->is_async) && (ptr->async_waiting) && (ptr->h_async_function)) {
                                        if (!bind_me) {
                                                bind_me = ptr;  // I choose you!
                                                bind_me->state = CON_EXECUTING;
@@ -1000,9 +993,9 @@ SKIP_SELECT:
 
                pthread_mutex_lock(&ThreadCountMutex);
                --active_workers;
-               if ((active_workers + CtdlGetConfigInt("c_min_workers") < num_workers) &&
-                   (num_workers > CtdlGetConfigInt("c_min_workers")))
-               {
+               if (    (active_workers + CtdlGetConfigInt("c_min_workers") < num_workers)
+                       && (num_workers > CtdlGetConfigInt("c_min_workers"))
+               {
                        num_workers--;
                        pthread_mutex_unlock(&ThreadCountMutex);
                        return (NULL);
@@ -1020,11 +1013,9 @@ SKIP_SELECT:
 
 // SyslogFacility()
 // Translate text facility name to syslog.h defined value.
-int SyslogFacility(char *name)
-{
+int SyslogFacility(char *name) {
        int i;
-       struct
-       {
+       struct {
                int facility;
                char *name;
        }   facTbl[] =
index 221640fdd59e8c1fb961c9c8719944eff90f7146..4134350f2a495f7c4246412f23f34e2c21760a98 100644 (file)
@@ -9,12 +9,6 @@
 #include <pthread.h>
 #endif
 
-#include <db.h>
-
-#if DB_VERSION_MAJOR < 5
-#error Citadel requires Berkeley DB v5 or newer.  Please upgrade.
-#endif
-
 #include "server.h"
 #include "database.h"
 
@@ -53,7 +47,6 @@ int client_read_blob(StrBuf *Target, int bytes, int timeout);
 void client_set_inbound_buf(long N);
 int client_read_random_blob(StrBuf *Target, int timeout);
 void client_close(void);
-void sysdep_master_cleanup (void);
 void kill_session (int session_to_kill);
 void start_daemon (int do_close_stdio);
 void checkcrash(void);
@@ -69,7 +62,6 @@ extern volatile int restart_server;
 extern int verbosity;
 extern int rescan[];
 
-
 extern int SyslogFacility(char *name);
 
 #endif /* SYSDEP_DECLS_H */