From 8e944083763c9ddcb32d763cf8f19c966d01f873 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sat, 23 Jan 2021 19:55:49 -0500 Subject: [PATCH] No more cleanup hooks. The OS can reclaim memory better than we can. We want to get to the database close as soon as possible. --- citadel/citserver.c | 10 +-- citadel/control.c | 8 +- citadel/database.c | 15 ++-- citadel/modules/calendar/serv_calendar.c | 8 +- citadel/modules/fulltext/ft_wordbreaker.c | 20 ----- citadel/modules/fulltext/serv_fulltext.c | 3 +- citadel/modules/imap/serv_imap.c | 7 +- citadel/modules/inetcfg/serv_inetcfg.c | 12 +-- citadel/modules/network/serv_network.c | 10 +-- citadel/modules/nntp/serv_nntp.c | 10 --- citadel/modules/smtp/serv_smtp.c | 8 +- citadel/modules/xmpp/serv_xmpp.c | 4 +- citadel/modules/xmpp/xmpp_queue.c | 18 +---- citadel/serv_extensions.c | 93 +---------------------- citadel/serv_extensions.h | 7 -- citadel/sysdep.c | 2 - 16 files changed, 20 insertions(+), 215 deletions(-) diff --git a/citadel/citserver.c b/citadel/citserver.c index b9648f6f7..a071b2b72 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -1,7 +1,7 @@ /* * Main source module for the Citadel server * - * Copyright (c) 1987-2020 by the citadel.org team + * 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. @@ -123,7 +123,6 @@ void master_startup(void) */ int master_cleanup(int exitcode) { - struct CleanupFunctionHook *fcn; static int already_cleaning_up = 0; if (already_cleaning_up) { @@ -133,11 +132,6 @@ int master_cleanup(int exitcode) } already_cleaning_up = 1; - /* Run any cleanup routines registered by loadable modules */ - for (fcn = CleanupHookTable; fcn != NULL; fcn = fcn->next) { - (*fcn->h_function_pointer) (); - } - /* Do system-dependent stuff */ sysdep_master_cleanup(); @@ -145,7 +139,7 @@ int master_cleanup(int exitcode) shutdown_config_system(); /* Close databases */ - syslog(LOG_INFO, "Closing databases\n"); + syslog(LOG_INFO, "citserver: closing databases"); close_databases(); /* If the operator requested a halt but not an exit, halt here. */ diff --git a/citadel/control.c b/citadel/control.c index 936deae33..3ab6ac84f 100644 --- a/citadel/control.c +++ b/citadel/control.c @@ -1,7 +1,7 @@ /* * This module handles states which are global to the entire server. * - * Copyright (c) 1987-2020 by the citadel.org team + * 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. @@ -791,10 +791,6 @@ void cmd_gvdn(char *argbuf) /* MODULE INITIALIZATION STUFF */ /*****************************************************************************/ -void control_cleanup(void) -{ - DeleteHash(&CfgNameHash); -} CTDL_MODULE_INIT(control) { if (!threading) { @@ -806,8 +802,6 @@ CTDL_MODULE_INIT(control) CtdlRegisterProtoHook(cmd_gvdn, "GVDN", "get valid domain names"); CtdlRegisterProtoHook(cmd_conf, "CONF", "get/set system configuration"); - CtdlRegisterCleanupHook(control_cleanup); - } /* return our id for the Log */ return "control"; diff --git a/citadel/database.c b/citadel/database.c index 0f6121e1f..2f6a5b5ce 100644 --- a/citadel/database.c +++ b/citadel/database.c @@ -1,7 +1,7 @@ /* * This is a data store backend for the Citadel server which uses Berkeley DB. * - * Copyright (c) 1987-2020 by the citadel.org team + * 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. @@ -317,7 +317,7 @@ void close_databases(void) { syslog(LOG_INFO, "db: performing final checkpoint"); if ((ret = dbenv->txn_checkpoint(dbenv, 0, 0, 0))) { - syslog(LOG_ERR, "txn_checkpoint: %s", db_strerror(ret)); + syslog(LOG_ERR, "db: txn_checkpoint: %s", db_strerror(ret)); } syslog(LOG_INFO, "db: flushing the database logs"); @@ -325,11 +325,6 @@ void close_databases(void) { syslog(LOG_ERR, "db: log_flush: %s", db_strerror(ret)); } -#ifdef DB_STAT_ALL - /* print some statistics... */ - dbenv->lock_stat_print(dbenv, DB_STAT_ALL); -#endif - /* close the tables */ syslog(LOG_INFO, "db: closing databases"); for (i = 0; i < MAXCDB; ++i) { @@ -341,6 +336,12 @@ void close_databases(void) { } + // This seemed nifty at the time but did anyone really look at it? + // #ifdef DB_STAT_ALL + // /* print some statistics... */ + // dbenv->lock_stat_print(dbenv, DB_STAT_ALL); + // #endif + /* Close the handle. */ ret = dbenv->close(dbenv, 0); if (ret) { diff --git a/citadel/modules/calendar/serv_calendar.c b/citadel/modules/calendar/serv_calendar.c index 83afa539b..941806393 100644 --- a/citadel/modules/calendar/serv_calendar.c +++ b/citadel/modules/calendar/serv_calendar.c @@ -3,7 +3,7 @@ * room on a Citadel server. It handles iCalendar objects using the * iTIP protocol. See RFCs 2445 and 2446. * - * Copyright (c) 1987-2020 by the citadel.org team + * 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. @@ -2532,11 +2532,6 @@ void ical_fixed_output(char *ptr, int len) { } -void serv_calendar_destroy(void) { - icaltimezone_free_builtin_timezones(); -} - - /* * Register this module with the Citadel server. */ @@ -2565,7 +2560,6 @@ CTDL_MODULE_INIT(calendar) CtdlRegisterSessionHook(ical_session_shutdown, EVT_STOP, PRIO_STOP + 80); CtdlRegisterFixedOutputHook("text/calendar", ical_fixed_output); CtdlRegisterFixedOutputHook("application/ics", ical_fixed_output); - CtdlRegisterCleanupHook(serv_calendar_destroy); } /* return our module name for the log */ diff --git a/citadel/modules/fulltext/ft_wordbreaker.c b/citadel/modules/fulltext/ft_wordbreaker.c index b2ba828bb..968fa9f02 100644 --- a/citadel/modules/fulltext/ft_wordbreaker.c +++ b/citadel/modules/fulltext/ft_wordbreaker.c @@ -147,26 +147,6 @@ void initialize_noise_words(void) } -void noise_word_cleanup(void) -{ - int i; - noise_word *cur, *next; - - syslog(LOG_INFO, "wordbreaker: cleaning up fulltext noise words"); - - for (i = 0 ; i < 26 ; i++) - { - cur = noise_words[i]; - while (cur) - { - next = cur->next; - free(cur->word); - free(cur); - cur = next; - } - } -} - /* * Compare function */ diff --git a/citadel/modules/fulltext/serv_fulltext.c b/citadel/modules/fulltext/serv_fulltext.c index 1d684111a..90c3e3685 100644 --- a/citadel/modules/fulltext/serv_fulltext.c +++ b/citadel/modules/fulltext/serv_fulltext.c @@ -1,6 +1,6 @@ /* * This module handles fulltext indexing of the message base. - * Copyright (c) 2005-2020 by the citadel.org team + * Copyright (c) 2005-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 as published @@ -483,7 +483,6 @@ CTDL_MODULE_INIT(fulltext) CtdlRegisterProtoHook(cmd_srch, "SRCH", "Full text search"); CtdlRegisterDeleteHook(ft_delete_remove); CtdlRegisterSearchFuncHook(ft_search, "fulltext"); - CtdlRegisterCleanupHook(noise_word_cleanup); CtdlRegisterSessionHook(do_fulltext_indexing, EVT_TIMER, PRIO_CLEANUP + 300); } /* return our module name for the log */ diff --git a/citadel/modules/imap/serv_imap.c b/citadel/modules/imap/serv_imap.c index 7bc97b6ed..3bc08c213 100644 --- a/citadel/modules/imap/serv_imap.c +++ b/citadel/modules/imap/serv_imap.c @@ -1,7 +1,7 @@ /* * IMAP server for the Citadel system * - * Copyright (C) 2000-2018 by Art Cancro and others. + * Copyright (C) 2000-2021 by Art Cancro and others. * This code is released under the terms of the GNU General Public License. * * WARNING: the IMAP protocol is badly designed. No implementation of it @@ -90,10 +90,6 @@ void registerImapCMD(const char *First, long FLen, } } -void imap_cleanup(void) -{ - DeleteHash(&ImapCmds); -} const imap_handler_hook *imap_lookup(int num_parms, ConstStr *Params) { @@ -1738,7 +1734,6 @@ CTDL_MODULE_INIT(imap) NULL, imaps_greeting, imap_command_loop, NULL, CitadelServiceIMAPS); #endif CtdlRegisterSessionHook(imap_cleanup_function, EVT_STOP, PRIO_STOP + 30); - CtdlRegisterCleanupHook(imap_cleanup); } /* return our module name for the log */ diff --git a/citadel/modules/inetcfg/serv_inetcfg.c b/citadel/modules/inetcfg/serv_inetcfg.c index 971c672cf..89e8e5633 100644 --- a/citadel/modules/inetcfg/serv_inetcfg.c +++ b/citadel/modules/inetcfg/serv_inetcfg.c @@ -4,7 +4,7 @@ * wrote it as a module merely to keep things as clean and loosely coupled * as possible. * - * Copyright (c) 1987-2020 by the citadel.org team + * 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. @@ -136,15 +136,6 @@ void inetcfg_init(void) { /*****************************************************************************/ /* MODULE INITIALIZATION STUFF */ /*****************************************************************************/ -void cleanup_inetcfg(void) -{ - char *buf; - buf = inetcfg; - inetcfg = NULL; - if (buf != NULL) { - free(buf); - } -} CTDL_MODULE_INIT(inetcfg) @@ -153,7 +144,6 @@ CTDL_MODULE_INIT(inetcfg) { CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE); inetcfg_init(); - CtdlRegisterCleanupHook(cleanup_inetcfg); } /* return our module name for the log */ diff --git a/citadel/modules/network/serv_network.c b/citadel/modules/network/serv_network.c index 1f610f258..eeca28afc 100644 --- a/citadel/modules/network/serv_network.c +++ b/citadel/modules/network/serv_network.c @@ -1,7 +1,7 @@ /* * This module handles network mail and mailing list processing. * - * Copyright (c) 2000-2019 by the citadel.org team + * Copyright (c) 2000-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. @@ -191,13 +191,6 @@ void destroy_network_queue_room(RoomProcList *rplist) } } -void destroy_network_queue_room_locked (void) -{ - begin_critical_section(S_RPLIST); - destroy_network_queue_room(rplist); - end_critical_section(S_RPLIST); -} - /* * network_do_queue() @@ -322,7 +315,6 @@ CTDL_MODULE_INIT(network) if (!threading) { CtdlRegisterRoomHook(network_room_handler); - CtdlRegisterCleanupHook(destroy_network_queue_room_locked); CtdlRegisterSessionHook(network_do_queue, EVT_TIMER, PRIO_QUEUE + 10); } return "network"; diff --git a/citadel/modules/nntp/serv_nntp.c b/citadel/modules/nntp/serv_nntp.c index 93f65da0a..ef923bb62 100644 --- a/citadel/modules/nntp/serv_nntp.c +++ b/citadel/modules/nntp/serv_nntp.c @@ -264,15 +264,6 @@ void nntp_quit(void) } -// -// Cleanup hook for this module -// -void nntp_cleanup(void) -{ - /* nothing here yet */ -} - - // // Implements the AUTHINFO USER command (RFC 4643) // @@ -1194,7 +1185,6 @@ CTDL_MODULE_INIT(nntp) CitadelServiceNNTPS); #endif - CtdlRegisterCleanupHook(nntp_cleanup); CtdlRegisterSessionHook(nntp_cleanup_function, EVT_STOP, PRIO_STOP + 250); } diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index 8b03cfca6..7847eccc3 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -20,7 +20,7 @@ * The VRFY and EXPN commands have been removed from this implementation * because nobody uses these commands anymore, except for spammers. * - * Copyright (c) 1998-2020 by the citadel.org team + * Copyright (c) 1998-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. @@ -129,11 +129,6 @@ void registerSmtpCMD(const char *First, long FLen, } -void smtp_cleanup(void) -{ - DeleteHash(&SMTPCmds); -} - /* * Here's where our SMTP session begins its happy day. */ @@ -1190,7 +1185,6 @@ CTDL_MODULE_INIT(smtp) NULL, CitadelServiceSMTP_LMTP_UNF); - CtdlRegisterCleanupHook(smtp_cleanup); CtdlRegisterSessionHook(smtp_cleanup_function, EVT_STOP, PRIO_STOP + 250); } diff --git a/citadel/modules/xmpp/serv_xmpp.c b/citadel/modules/xmpp/serv_xmpp.c index 84aa4ba38..1b4d78424 100644 --- a/citadel/modules/xmpp/serv_xmpp.c +++ b/citadel/modules/xmpp/serv_xmpp.c @@ -1,6 +1,6 @@ /* * XMPP (Jabber) service for the Citadel system - * Copyright (c) 2007-2019 by Art Cancro and citadel.org + * Copyright (c) 2007-2021 by Art Cancro and citadel.org * * This program is open source software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -662,7 +662,6 @@ void xmpp_logout_hook(void) { const char *CitadelServiceXMPP="XMPP"; -extern void xmpp_cleanup_events(void); CTDL_MODULE_INIT(xmpp) { if (!threading) { @@ -678,7 +677,6 @@ CTDL_MODULE_INIT(xmpp) CtdlRegisterSessionHook(xmpp_logout_hook, EVT_LOGOUT, PRIO_LOGOUT + 90); CtdlRegisterSessionHook(xmpp_login_hook, EVT_UNSTEALTH, PRIO_UNSTEALTH + 1); CtdlRegisterSessionHook(xmpp_logout_hook, EVT_STEALTH, PRIO_STEALTH + 1); - CtdlRegisterCleanupHook(xmpp_cleanup_events); } diff --git a/citadel/modules/xmpp/xmpp_queue.c b/citadel/modules/xmpp/xmpp_queue.c index 4e62aece9..da323455f 100644 --- a/citadel/modules/xmpp/xmpp_queue.c +++ b/citadel/modules/xmpp/xmpp_queue.c @@ -1,7 +1,7 @@ /* * XMPP event queue * - * Copyright (c) 2007-2017 by Art Cancro + * Copyright (c) 2007-2021 by Art Cancro * * 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. @@ -138,19 +138,3 @@ void xmpp_process_events(void) { XMPP->last_event_processed = highest_event; } - - -void xmpp_cleanup_events(void) -{ - struct xmpp_event *ptr, *ptr2; - begin_critical_section(S_XMPP_QUEUE); - ptr = xmpp_queue; - xmpp_queue = NULL; - while (ptr != NULL) { - ptr2 = ptr->next; - free(ptr); - ptr = ptr2; - } - end_critical_section(S_XMPP_QUEUE); - -} diff --git a/citadel/serv_extensions.c b/citadel/serv_extensions.c index 3c62694c0..cc594ce65 100644 --- a/citadel/serv_extensions.c +++ b/citadel/serv_extensions.c @@ -2,7 +2,7 @@ * Citadel Extension Loader * Originally written by Brian Costello * - * Copyright (c) 1987-2020 by the citadel.org team + * 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. @@ -128,9 +128,6 @@ struct SearchFunctionHook { }; SearchFunctionHook *SearchFunctionHookTable = NULL; -CleanupFunctionHook *CleanupHookTable = NULL; -CleanupFunctionHook *EVCleanupHookTable = NULL; - ServiceFunctionHook *ServiceHookTable = NULL; typedef struct ProtoFunctionHook ProtoFunctionHook; @@ -278,94 +275,6 @@ void CtdlRegisterProtoHook(void (*handler) (char *), char *cmd, char *desc) } -void CtdlRegisterCleanupHook(void (*fcn_ptr) (void)) -{ - - CleanupFunctionHook *newfcn; - - newfcn = (CleanupFunctionHook *) - malloc(sizeof(CleanupFunctionHook)); - newfcn->next = CleanupHookTable; - newfcn->h_function_pointer = fcn_ptr; - CleanupHookTable = newfcn; - - syslog(LOG_DEBUG, "extensions: registered a new cleanup function"); -} - - -void CtdlUnregisterCleanupHook(void (*fcn_ptr) (void)) -{ - CleanupFunctionHook *cur, *p, *last; - last = NULL; - cur = CleanupHookTable; - while (cur != NULL) - { - if (fcn_ptr == cur->h_function_pointer) - { - syslog(LOG_DEBUG, "extensions: unregistered cleanup function"); - p = cur->next; - - free(cur); - cur = NULL; - - if (last != NULL) - last->next = p; - else - CleanupHookTable = p; - cur = p; - } - else { - last = cur; - cur = cur->next; - } - } -} - - -void CtdlRegisterEVCleanupHook(void (*fcn_ptr) (void)) -{ - - CleanupFunctionHook *newfcn; - - newfcn = (CleanupFunctionHook *) - malloc(sizeof(CleanupFunctionHook)); - newfcn->next = EVCleanupHookTable; - newfcn->h_function_pointer = fcn_ptr; - EVCleanupHookTable = newfcn; - - syslog(LOG_DEBUG, "extensions: registered a new cleanup function"); -} - - -void CtdlUnregisterEVCleanupHook(void (*fcn_ptr) (void)) -{ - CleanupFunctionHook *cur, *p, *last; - last = NULL; - cur = EVCleanupHookTable; - while (cur != NULL) - { - if (fcn_ptr == cur->h_function_pointer) - { - syslog(LOG_DEBUG, "extensions: unregistered cleanup function"); - p = cur->next; - - free(cur); - cur = NULL; - - if (last != NULL) - last->next = p; - else - EVCleanupHookTable = p; - cur = p; - } - else { - last = cur; - cur = cur->next; - } - } -} - - void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType, int Priority) { SessionFunctionHook *newfcn; diff --git a/citadel/serv_extensions.h b/citadel/serv_extensions.h index cd39831ca..677f4f72b 100644 --- a/citadel/serv_extensions.h +++ b/citadel/serv_extensions.h @@ -21,13 +21,6 @@ struct ServiceFunctionHook { }; extern ServiceFunctionHook *ServiceHookTable; -typedef struct CleanupFunctionHook CleanupFunctionHook; -struct CleanupFunctionHook { - CleanupFunctionHook *next; - void (*h_function_pointer) (void); -}; -extern CleanupFunctionHook *CleanupHookTable; - void initialize_server_extensions(void); int DLoader_Exec_Cmd(char *cmdbuf); char *Dynamic_Module_Init(void); diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 6da2bb443..61fc7a2c2 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -634,8 +634,6 @@ int client_getln(char *buf, int bufsize) /* * Cleanup any contexts that are left lying around */ - - void close_masters (void) { struct ServiceFunctionHook *serviceptr; -- 2.30.2