//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) {
}
// 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");
}
#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
// 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) {
}
already_cleaning_up = 1;
- // Do system-dependent stuff
- sysdep_master_cleanup();
+ // Close the sockets
+ context_cleanup();
// Close the configuration system
shutdown_config_system();
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);
}
#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);
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;
}
// 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);
}
-// 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>
if ( (ip_addr == NULL) // any IPv6
|| (IsEmptyStr(ip_addr))
|| (!strcmp(ip_addr, "*"))
+ || (!strcmp(ip_addr, "::"))
) {
ip_version = 6;
sin6.sin6_addr = in6addr_any;
}
-// 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);
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) {
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;
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);
// 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[] =
#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"
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);
extern int verbosity;
extern int rescan[];
-
extern int SyslogFacility(char *name);
#endif /* SYSDEP_DECLS_H */