Added an entry point to the modules init stuff.
authorDave West <davew@uncensored.citadel.org>
Mon, 3 Dec 2007 22:00:48 +0000 (22:00 +0000)
committerDave West <davew@uncensored.citadel.org>
Mon, 3 Dec 2007 22:00:48 +0000 (22:00 +0000)
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.

citadel/Makefile.in
citadel/include/ctdl_module.h
citadel/mk_module_init.sh
citadel/modules/upgrade/serv_upgrade.c
citadel/server_main.c

index e84984809f58d7caf4de035ea6b1cc5b8839003d..75e4a76b59ea80c31d86ded1850db5373b238031 100644 (file)
@@ -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
index eaabb22f418875d1c09d9838d5b0260c9b866cee..6326d5ef7861fd7e86341ae1bc01fd4c7116df99 100644 (file)
 
 #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.
index aaa13f145b7e037b82585f1d4e4fce54211a3c4e..63a23fddc81f3fcd67891f787d6789ca163c498a 100755 (executable)
@@ -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 <<EOF  >$SRC_FILE
 
 EOF
 
+# start the upgrade file
+cat <<EOF  >$U_FILE
+/*
+ * $U_FILE
+ * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
+ */
+
+
+
+#include "sysdep.h"
+#include <stdlib.h>
+#include <time.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+#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 <<EOF  >$C_FILE
 /*
@@ -104,7 +134,7 @@ cat <<EOF > $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 <<EOF  >> $C_FILE
-       lprintf (CTDL_INFO, "%%s\n", CTDL_INIT_CALL($RES_OUT));
+       lprintf (CTDL_INFO, "%s\n", CTDL_INIT_CALL($RES_OUT));
 
 EOF
 cat <<EOF >>$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 <<EOF  >> $U_FILE
+       lprintf (CTDL_INFO, "%s\n", CTDL_UPGRADE_CALL($RES_OUT));
+
+EOF
+cat <<EOF >>$H_FILE
+CTDL_MODULE_UPGRADE($RES_OUT);
 EOF
        fi
 done
@@ -157,6 +199,19 @@ EOF
 # Add this entry point to the .h file
 cat <<EOF >> $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 <<EOF >> $U_FILE
+       lprintf (CTDL_INFO, "%s\n", CTDL_UPGRADE_CALL($RES_OUT));
+EOF
+# Add this entry point to the .h file
+cat <<EOF >> $H_FILE
+       CTDL_MODULE_UPGRADE($RES_OUT);
 EOF
                                        fi
                                fi
@@ -199,6 +254,17 @@ cat <<EOF >> $C_FILE
 EOF
 cat <<EOF >> $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 <<EOF >> $U_FILE
+       lprintf (CTDL_INFO, "%s\n", CTDL_UPGRADE_CALL($RES_OUT));
+EOF
+cat <<EOF >> $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
index 5d52b29d5afaca1ab9540a6a14a9c83d0e346a79..2646009c3dcefe0da675005529f15cdf54ae39c5 100644 (file)
@@ -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$";
index 8758de3b5e466f6e6127f01f0807ee73f7ecbc66..343d0ae13b2daffce1cf72aad7fffe9f32d7c4bd 100644 (file)
@@ -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())