some fixes

Sat, 22 Jun 2013 13:08:36 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 22 Jun 2013 13:08:36 +0200
changeset 72
9b888965f3ee
parent 71
069c152f6272
child 73
79fa26ecd135

some fixes

src/server/daemon/config.c file | annotate | diff | comparison | revisions
src/server/daemon/vfs.c file | annotate | diff | comparison | revisions
--- a/src/server/daemon/config.c	Fri Jun 21 12:10:44 2013 +0200
+++ b/src/server/daemon/config.c	Sat Jun 22 13:08:36 2013 +0200
@@ -64,6 +64,7 @@
     InitConfig *cfg = load_init_config(file);
     UcxMempool *mp = cfg->parser.mp;
     if(cfg == NULL) {
+        fprintf(stderr, "Cannot load init.conf\n");
         return 1;
     }
 
@@ -149,34 +150,39 @@
      * VirtualServer (dependencies: Listener)
      */
     
-    /* init logfile first */
+    // init logfile first
     UcxList *lfl = ucx_map_sstr_get(serverconf->objects, sstrn("LogFile", 7));
     if(lfl != NULL) {
         ServerConfigObject *logobj = lfl->data;
         if(logobj == NULL) {
-            /* error */
+            // error
             return NULL;
         }
         
         int ret = cfg_handle_logfile(serverconfig, logobj);
         if(ret != 0) {
-            /* cannot initialize log file */
+            // cannot initialize log file
             return NULL;
         }
     } else {
-        /* horrible error */
+        // horrible error
         return NULL;
     }
      
     UcxList *list = ucx_map_sstr_get(serverconf->objects, sstrn("Runtime", 7));
     UCX_FOREACH(UcxList*, list, elm) {
         ServerConfigObject *scfgobj = elm->data;
-        cfg_handle_runtime(serverconfig, scfgobj);
+        if(cfg_handle_runtime(serverconfig, scfgobj)) {
+            // error
+            return NULL;
+        }
     }
     
     list = ucx_map_sstr_get(serverconf->objects, sstrn("Threadpool", 10));
     UCX_FOREACH(UcxList*, list, elm) {
-        cfg_handle_threadpool(serverconfig, elm->data);
+        if(cfg_handle_threadpool(serverconfig, elm->data)) {
+            return NULL;
+        }
     }
     // check thread pool config
     if(check_thread_pool_cfg() != 0) {
@@ -186,7 +192,11 @@
     
     list = ucx_map_sstr_get(serverconf->objects, sstrn("EventHandler", 12));
     UCX_FOREACH(UcxList*, list, elm) {
-        cfg_handle_eventhandler(serverconfig, (ServerConfigObject*)elm->data);
+        if(cfg_handle_eventhandler(
+                serverconfig, (ServerConfigObject*)elm->data)) {
+            // error            
+            return NULL;
+        }
     }
     // check event handler config
     if(check_event_handler_cfg() != 0) {
@@ -197,25 +207,33 @@
     list = ucx_map_sstr_get(serverconf->objects, sstrn("AccessLog", 9));
     UCX_FOREACH(UcxList*, list, elm) {
         ServerConfigObject *scfgobj = elm->data;
-        cfg_handle_accesslog(serverconfig, scfgobj);
+        if(cfg_handle_accesslog(serverconfig, scfgobj)) {
+            return NULL;
+        }
     }
     
     list = ucx_map_sstr_get(serverconf->objects, sstrn("AuthDB", 6));
     UCX_FOREACH(UcxList*, list, elm) {
         ServerConfigObject *scfgobj = elm->data;
-        cfg_handle_authdb(serverconfig, scfgobj);
+        if(cfg_handle_authdb(serverconfig, scfgobj)) {
+            return NULL;
+        }
     }
     
     list = ucx_map_sstr_get(serverconf->objects, sstrn("Listener", 8));
     UCX_FOREACH(UcxList*, list, elm) {
         ServerConfigObject *scfgobj = elm->data;
-        cfg_handle_listener(serverconfig, scfgobj);
+        if(cfg_handle_listener(serverconfig, scfgobj)) {
+            return NULL;
+        }
     }
     
     list = ucx_map_sstr_get(serverconf->objects, sstrn("VirtualServer", 13));
     UCX_FOREACH(UcxList*, list, elm) {
         ServerConfigObject *scfgobj = elm->data;
-        cfg_handle_vs(serverconfig, scfgobj);
+        if(cfg_handle_vs(serverconfig, scfgobj)) {
+            return NULL;
+        }
     }
     
 
@@ -261,12 +279,17 @@
 }
 
 int cfg_handle_runtime(ServerConfiguration *cfg, ServerConfigObject *obj) {
-    cfg->user = sstrdup(cfg_directivelist_get_str(
-            obj->directives,
-            sstr("User")));
-    cfg->tmp = sstrdup(cfg_directivelist_get_str(
-            obj->directives,
-            sstr("Temp")));
+    sstr_t user = cfg_directivelist_get_str(obj->directives, sstr("User"));
+    if(user.ptr) {
+        cfg->user = sstrdup_pool(cfg->pool, user);
+    }
+    sstr_t tmp = cfg_directivelist_get_str(obj->directives, sstr("Temp"));
+    if(tmp.ptr) {
+        cfg->tmp = sstrdup_pool(cfg->pool, tmp);
+    } else {
+        log_ereport(LOG_MISCONFIG, "no temporary directory specified");
+        return -1;
+    }
     
     // mime file
     sstr_t mf = cfg_directivelist_get_str(obj->directives, sstr("MimeFile"));
@@ -400,9 +423,7 @@
     
     evcfg.isdefault = util_getboolean(isdefault.ptr, 0);
     
-    int ret = create_event_handler(&evcfg);
-    
-    return ret;
+    return create_event_handler(&evcfg);
 }
 
 int cfg_handle_accesslog(ServerConfiguration *cfg, ServerConfigObject *obj) {
--- a/src/server/daemon/vfs.c	Fri Jun 21 12:10:44 2013 +0200
+++ b/src/server/daemon/vfs.c	Sat Jun 22 13:08:36 2013 +0200
@@ -292,8 +292,23 @@
         }
     }
     
-    // open file  
+    // open directory
+#ifdef BSD
     DIR *sys_dir = opendir(path);
+    if(sys_dir) {
+        int dir_fd = dirfd(sys_dir);
+    }
+#else
+    int dir_fd = open(path, O_RDONLY);
+    if(dir_fd == -1) {
+        if(ctx) {
+            ctx->vfs_errno = errno;
+            sys_set_error_status(ctx);
+        }
+        return NULL;
+    }
+    DIR *sys_dir = fdopendir(dir_fd);
+#endif
     if(!sys_dir) {
         if(ctx) {
             ctx->vfs_errno = errno;
@@ -310,7 +325,7 @@
     }
     dir->ctx = ctx;
     dir->data = sys_dir;
-    dir->fd = dirfd(sys_dir);
+    dir->fd = dir_fd;
     dir->io = &sys_dir_io;
     return dir;
 }

mercurial