From: Dave West Date: Mon, 3 Dec 2007 22:00:48 +0000 (+0000) Subject: Added an entry point to the modules init stuff. X-Git-Tag: v7.86~2682 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=a5a9ed4eeca2e58a55a0d5dfab2ee2c1afb445de Added an entry point to the modules init stuff. The new entry point is defined by the macro CTDL_MODULE_UPGRADE(module_name). This entry point works in much the same way as the init entry point except it is called before the init entry point. This entry point is intended for use as its name implies. The module should do any upgrade stuff it needs to do before it can initialise. serv_upgrade.c demonstrates the useage. --- diff --git a/citadel/Makefile.in b/citadel/Makefile.in index e84984809..75e4a76b5 100644 --- a/citadel/Makefile.in +++ b/citadel/Makefile.in @@ -86,7 +86,7 @@ SOURCES=aidepost.c auth.c base64.c chkpwd.c chkpw.c citadel.c citadel_ipc.c \ include Make_sources -DEP_FILES=$(SOURCES:.c=.d) modules_init.d +DEP_FILES=$(SOURCES:.c=.d) modules_init.d modules_upgrade.d client: $(CLIENT_TARGETS) @@ -115,6 +115,8 @@ Make_sources: modules_init.c Make_modules: modules_init.c +modules_upgrade.c: modules_init.c + modules_init.c: mk_module_init.sh $(SOURCES) $(srcdir)/mk_module_init.sh @@ -126,7 +128,7 @@ SERV_OBJS = server_main.o \ locate_host.o housekeeping.o html.o \ internet_addressing.o journaling.o \ parsedate.o genstamp.o ecrash.o \ - clientsocket.o modules_init.o $(AUTH) $(SERV_MODULES) + clientsocket.o modules_init.o modules_upgrade.o $(AUTH) $(SERV_MODULES) citserver: $(SERV_OBJS) $(CC) $(SERV_OBJS) $(LDFLAGS) $(SERVER_LDFLAGS) $(LIBS) $(SERVER_LIBS) $(RESOLV) -o citserver @@ -328,7 +330,7 @@ clean: cleaner: clean rm -rf $(CLIENT_TARGETS) $(SERVER_TARGETS) $(UTIL_TARGETS) $(UTILBIN_TARGETS) database_cleanup.sh *.la - rm -rf modules_init.c modules_init.h Make_modules Make_sources + rm -rf modules_upgrade.c modules_init.c modules_init.h Make_modules Make_sources distclean: cleaner find . -name '*~' -o -name '.#*' | xargs rm -f diff --git a/citadel/include/ctdl_module.h b/citadel/include/ctdl_module.h index eaabb22f4..6326d5ef7 100644 --- a/citadel/include/ctdl_module.h +++ b/citadel/include/ctdl_module.h @@ -15,6 +15,10 @@ #define CTDL_INIT_CALL(module_name) ctdl_module_##module_name##_init (threading) +#define CTDL_MODULE_UPGRADE(module_name) char *ctdl_module_##module_name##_upgrade (void) + +#define CTDL_UPGRADE_CALL(module_name) ctdl_module_##module_name##_upgrade () + /* * Prototype for making log entries in Citadel. diff --git a/citadel/mk_module_init.sh b/citadel/mk_module_init.sh index aaa13f145..63a23fddc 100755 --- a/citadel/mk_module_init.sh +++ b/citadel/mk_module_init.sh @@ -25,7 +25,7 @@ C_FILE="$CUR_DIR/modules_init.c" H_FILE="$CUR_DIR/modules_init.h" MOD_FILE="$CUR_DIR/Make_modules" SRC_FILE="$CUR_DIR/Make_sources" - +U_FILE="$CUR_DIR/modules_upgrade.c" /usr/bin/printf "Scanning extension modules for entry points.\n" @@ -53,6 +53,36 @@ cat <$SRC_FILE EOF +# start the upgrade file +cat <$U_FILE +/* + * $U_FILE + * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE + */ + + + +#include "sysdep.h" +#include +#include +#include +#include +#include +#include +#include "citadel.h" +#include "modules_init.h" +#include "sysdep_decls.h" + + + + +void upgrade_modules (void) +{ + + CtdlLogPrintf (CTDL_INFO, "Upgrade modules.\n"); + +EOF + # start the c file cat <$C_FILE /* @@ -104,7 +134,7 @@ cat < $H_FILE #include "ctdl_module.h" extern size_t nSizErrmsg; void initialise_modules (int threading); - +void upgrade_modules(void); EOF for i in serv_*.c @@ -114,11 +144,23 @@ do RES_OUT=`echo $RES | cut -b2-` /usr/bin/printf "Found entry point in file $i\n" cat <> $C_FILE - lprintf (CTDL_INFO, "%%s\n", CTDL_INIT_CALL($RES_OUT)); + lprintf (CTDL_INFO, "%s\n", CTDL_INIT_CALL($RES_OUT)); EOF cat <>$H_FILE CTDL_MODULE_INIT($RES_OUT); +EOF + fi + RES=X`grep CTDL_MODULE_UPGRADE $i | cut -f2 -d\( | cut -f1 -d\)` + if [ $RES != "X" ] ; then + RES_OUT=`echo $RES | cut -b2-` + /usr/bin/printf "Found upgrade point in file $i\n" +cat <> $U_FILE + lprintf (CTDL_INFO, "%s\n", CTDL_UPGRADE_CALL($RES_OUT)); + +EOF +cat <>$H_FILE +CTDL_MODULE_UPGRADE($RES_OUT); EOF fi done @@ -157,6 +199,19 @@ EOF # Add this entry point to the .h file cat <> $H_FILE CTDL_MODULE_INIT($RES_OUT); +EOF + fi + RES=X`grep CTDL_MODULE_UPGRADE $k | cut -f2 -d\( | cut -f1 -d\)` + if [ $RES != "X" ] ; then + RES_OUT=`echo $RES | cut -b2-` + /usr/bin/printf "Found upgrade point in file modules/$j/$k\n" +# Add this entry point to the .c file +cat <> $U_FILE + lprintf (CTDL_INFO, "%s\n", CTDL_UPGRADE_CALL($RES_OUT)); +EOF +# Add this entry point to the .h file +cat <> $H_FILE + CTDL_MODULE_UPGRADE($RES_OUT); EOF fi fi @@ -199,6 +254,17 @@ cat <> $C_FILE EOF cat <> $H_FILE CTDL_MODULE_INIT($RES_OUT); +EOF + fi + RES=X`grep CTDL_MODULE_UPGRADE $k | cut -f2 -d\( | cut -f1 -d\)` + if [ $RES != "X" ] ; then + RES_OUT=`echo $RES | cut -b2-` + /usr/bin/printf "Found upgrade point in file user_modules/$j/$k\n" +cat <> $U_FILE + lprintf (CTDL_INFO, "%s\n", CTDL_UPGRADE_CALL($RES_OUT)); +EOF +cat <> $H_FILE +CTDL_MODULE_UPGRADE($RES_OUT); EOF fi fi @@ -216,5 +282,7 @@ cd $CUR_DIR /usr/bin/printf "\t\t\tLogPrintMessages(filter);\n" >> $C_FILE /usr/bin/printf "}\n" >> $C_FILE +#close the upgrade file +/usr/bin/printf "}\n" >> $U_FILE /usr/bin/printf "\n#endif /* MODULES_INIT_H */\n" >> $H_FILE diff --git a/citadel/modules/upgrade/serv_upgrade.c b/citadel/modules/upgrade/serv_upgrade.c index 5d52b29d5..2646009c3 100644 --- a/citadel/modules/upgrade/serv_upgrade.c +++ b/citadel/modules/upgrade/serv_upgrade.c @@ -231,12 +231,9 @@ void check_server_upgrades(void) { } -CTDL_MODULE_INIT(upgrade) +CTDL_MODULE_UPGRADE(upgrade) { - if (!threading) - { - check_server_upgrades(); - } + check_server_upgrades(); /* return our Subversion id for the Log */ return "$Id$"; diff --git a/citadel/server_main.c b/citadel/server_main.c index 8758de3b5..343d0ae13 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -99,7 +99,7 @@ int main(int argc, char **argv) // eCrashSymbolTable symbol_table; #endif /* initialise semaphores here. Patch by Matt and davew - * its called here as they are needed by lprintf for thread safety + * its called here as they are needed by CtdlLogPrintf for thread safety */ CtdlInitBase64Table(); InitialiseSemaphores(); @@ -157,7 +157,7 @@ int main(int argc, char **argv) /* any other parameter makes it crash and burn */ else { - lprintf(CTDL_EMERG, "citserver: usage: " + CtdlLogPrintf(CTDL_EMERG, "citserver: usage: " "citserver " "[-lLogFacility] " "[-d] [-f] [-D] " @@ -207,22 +207,22 @@ int main(int argc, char **argv) } /* Tell 'em who's in da house */ - lprintf(CTDL_NOTICE, "\n"); - lprintf(CTDL_NOTICE, "\n"); - lprintf(CTDL_NOTICE, + CtdlLogPrintf(CTDL_NOTICE, "\n"); + CtdlLogPrintf(CTDL_NOTICE, "\n"); + CtdlLogPrintf(CTDL_NOTICE, "*** Citadel server engine v%d.%02d ***\n", (REV_LEVEL/100), (REV_LEVEL%100)); - lprintf(CTDL_NOTICE, + CtdlLogPrintf(CTDL_NOTICE, "Copyright (C) 1987-2007 by the Citadel development team.\n"); - lprintf(CTDL_NOTICE, + CtdlLogPrintf(CTDL_NOTICE, "This program is distributed under the terms of the GNU " "General Public License.\n"); - lprintf(CTDL_NOTICE, "\n"); - lprintf(CTDL_DEBUG, "Called as: %s\n", argv[0]); - lprintf(CTDL_INFO, "%s\n", libcitadel_version_string()); + CtdlLogPrintf(CTDL_NOTICE, "\n"); + CtdlLogPrintf(CTDL_DEBUG, "Called as: %s\n", argv[0]); + CtdlLogPrintf(CTDL_INFO, "%s\n", libcitadel_version_string()); /* Load site-specific parameters, and set the ipgm secret */ - lprintf(CTDL_INFO, "Loading citadel.config\n"); + CtdlLogPrintf(CTDL_INFO, "Loading citadel.config\n"); get_config(); config.c_ipgm_secret = rand(); put_config(); @@ -251,7 +251,7 @@ int main(int argc, char **argv) */ master_startup(); - lprintf(CTDL_INFO, "Acquiring control record\n"); + CtdlLogPrintf(CTDL_INFO, "Acquiring control record\n"); get_control(); /* @@ -274,10 +274,18 @@ int main(int argc, char **argv) do_async_loop, CitadelServiceTCP); + + /* + * Run any upgrade entry points + */ + CtdlLogPrintf(CTDL_INFO, "Upgrading modules.\n"); + upgrade_modules(); + + /* * Load any server-side extensions available here. */ - lprintf(CTDL_INFO, "Initializing server extensions\n"); + CtdlLogPrintf(CTDL_INFO, "Initializing server extensions\n"); size = strlen(ctdl_home_directory) + 9; initialise_modules(0); @@ -304,18 +312,18 @@ int main(int argc, char **argv) getpwuid_r(config.c_ctdluid, &pw, pwbuf, sizeof(pwbuf), &pwp); #endif if (pwp == NULL) - lprintf(CTDL_CRIT, "WARNING: getpwuid(%ld): %s\n" + CtdlLogPrintf(CTDL_CRIT, "WARNING: getpwuid(%ld): %s\n" "Group IDs will be incorrect.\n", (long)CTDLUID, strerror(errno)); else { initgroups(pw.pw_name, pw.pw_gid); if (setgid(pw.pw_gid)) - lprintf(CTDL_CRIT, "setgid(%ld): %s\n", (long)pw.pw_gid, + CtdlLogPrintf(CTDL_CRIT, "setgid(%ld): %s\n", (long)pw.pw_gid, strerror(errno)); } - lprintf(CTDL_INFO, "Changing uid to %ld\n", (long)CTDLUID); + CtdlLogPrintf(CTDL_INFO, "Changing uid to %ld\n", (long)CTDLUID); if (setuid(CTDLUID) != 0) { - lprintf(CTDL_CRIT, "setuid() failed: %s\n", strerror(errno)); + CtdlLogPrintf(CTDL_CRIT, "setuid() failed: %s\n", strerror(errno)); } #if defined (HAVE_SYS_PRCTL_H) && defined (PR_SET_DUMPABLE) prctl(PR_SET_DUMPABLE, 1); @@ -439,11 +447,11 @@ void go_threading(void) } } - CtdlThreadGC(); + CtdlThreadGC(); if (CtdlThreadGetCount() <= 1) // Shutting down clean up the garbage collector { - CtdlThreadGC(); + CtdlThreadGC(); } if (CtdlThreadGetCount())