src/server/daemon/configmanager.c

changeset 36
450d2d5f4735
parent 31
280250e45ba6
child 37
360b9aabe17e
--- a/src/server/daemon/configmanager.c	Sat Aug 18 11:39:34 2012 +0200
+++ b/src/server/daemon/configmanager.c	Sat Oct 06 13:00:07 2012 +0200
@@ -31,6 +31,10 @@
 
 #include "../public/nsapi.h"
 
+#include "../ucx/string.h"
+
+#include "httplistener.h"
+#include "log.h"
 #include "configmanager.h"
 
 ServerConfiguration *current_config = NULL;
@@ -53,12 +57,44 @@
     return ucx_map_sstr_get(config_files, name);
 }
 
+// copy functions
+static void* copy_listener(HttpListener *ls, ServerConfiguration *cfg) {
+    /*
+     * we reuse the old listener, but change the
+     * ServerConfiguration and VirtualServer
+     */
+    http_listener_ref(ls);
+    ls->cfg = cfg;
+    
+    sstr_t vsname = ls->default_vs.vs->name;
+    ls->default_vs.vs = ucx_map_sstr_get(cfg->host_vs, vsname);
+    
+    return ls;
+}
+
+static void* copy_vs(void *vserver, void *pool) {
+    VirtualServer *vs = vs_copy(vserver, pool);
+    
+    /*
+     * this function is executed on configuration reload, so some
+     * VS configs may be changed
+     * 
+     * vs
+     *    objects
+     */
+    ConfigFile *objectfile = cfgmgr_get_file(vs->objectfile);
+    vs->objects = objectfile->data;
+    return vs;
+}
+
+
 int cfgmgr_load_config() {
     int cfgreload = 0;
     
     /* check config files */  
     UcxMapIterator iter = ucx_map_iterator(config_files);
-    UCX_MAP_FOREACH(ConfigFile*, f, config_files, iter) {
+    ConfigFile *f;
+    UCX_MAP_FOREACH(f, iter) {
         struct stat s;
         if(stat(f->file.ptr, &s) != 0) {
             fprintf(
@@ -70,6 +106,11 @@
 
         if(f->last_modified != s.st_mtim.tv_sec) {
             /* reload the file */
+            //printf("reload: %s\n", sstrdup(f->file).ptr);
+            log_ereport(
+                    LOG_LEVEL_INFO,
+                    "reload configuration file: %s",
+                    f->file.ptr);
             f->reload(f, current_config);
             cfgreload = 1;
         }
@@ -83,6 +124,7 @@
 
     ServerConfiguration *config;
     if(sc_last_modified != s.st_mtim.tv_sec) {
+        printf("cfgmgr load server.conf\n");
         config = load_server_conf(
             current_config,
             "conf/server.conf");
@@ -91,13 +133,35 @@
             fprintf(stderr, "Cannot load server.conf\n");
             return -1;
         }
+        
+        sc_last_modified = s.st_mtim.tv_sec;
     } else if(cfgreload) {
         /* copy configuration */
-
+        printf("cfgmgr copy server.conf\n");
+        
         /* TODO: copy */
+        /*
         config = load_server_conf(
             current_config,
             "conf/server.conf");
+        */
+        config = malloc(sizeof(ServerConfiguration));
+        config->ref = 1;
+        config->pool = pool_create();
+        config->user = sstrdup_pool(config->pool, current_config->user);
+        config->tmp = sstrdup_pool(config->pool, current_config->tmp);
+        
+        // copy configuration       
+        config->host_vs = ucx_map_clone(
+                current_config->host_vs,
+                copy_vs,
+                config->pool);
+        
+        config->listeners = ucx_list_clone(
+                current_config->listeners,
+                (copy_func)copy_listener,
+                config);
+        
 
         if(config == NULL) {
             fprintf(stderr, "Cannot load server.conf\n");
@@ -105,10 +169,11 @@
         }
 
     } else {
+        printf("no reconfig required!\n");
         config = current_config;
     }
 
-
+    
     current_config = config;
     return 0;
 }

mercurial