print error in case the log file config doesn't work

Sun, 25 Sep 2022 11:56:47 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 25 Sep 2022 11:56:47 +0200
changeset 392
0aef555055ee
parent 391
80ee93a7d257
child 393
79e542cc20a9

print error in case the log file config doesn't work

src/server/config/mimeconf.c file | annotate | diff | comparison | revisions
src/server/daemon/config.c file | annotate | diff | comparison | revisions
src/server/daemon/configmanager.c file | annotate | diff | comparison | revisions
src/server/daemon/log.c file | annotate | diff | comparison | revisions
src/server/daemon/webserver.c file | annotate | diff | comparison | revisions
--- a/src/server/config/mimeconf.c	Sun Sep 25 11:00:38 2022 +0200
+++ b/src/server/config/mimeconf.c	Sun Sep 25 11:56:47 2022 +0200
@@ -41,6 +41,7 @@
 MimeConfig *load_mime_config(const char *file) {
     FILE *in = fopen(file, "r");
     if(in == NULL) {
+        log_ereport(LOG_FAILURE, "Cannot load mime config file %s: %s", file, strerror(errno));
         return NULL;
     }
     
@@ -50,6 +51,7 @@
     conf->ntypes = 0;
     int r = cfg_parse_basic_file((ConfigParser*)conf, in);
     if(r != 0) {
+        log_ereport(LOG_FAILURE, "Cannot parse mime config file %s", file);
         fclose(in);
         free(conf);
         // TODO: free
--- a/src/server/daemon/config.c	Sun Sep 25 11:00:38 2022 +0200
+++ b/src/server/daemon/config.c	Sun Sep 25 11:56:47 2022 +0200
@@ -195,6 +195,7 @@
     // init logfile first
     UcxList *list;
     
+    log_ereport(LOG_DEBUG, "apply config: LogFile");
     list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("LogFile"));
     if(list) {
         ConfigNode *logobj = list->data;
@@ -215,7 +216,7 @@
     ucx_list_free(list);
      
     
-    
+    log_ereport(LOG_DEBUG, "apply config: Threadpool");
     list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("Threadpool"));
     UCX_FOREACH(elm, list) {
         if(cfg_handle_threadpool(serverconfig, elm->data)) {
@@ -229,6 +230,7 @@
         return NULL;
     }
     
+    log_ereport(LOG_DEBUG, "apply config: EventHandler");
     list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("EventHandler"));
     UCX_FOREACH(elm, list) {
         if(cfg_handle_eventhandler(
@@ -244,6 +246,7 @@
     }
     ucx_list_free(list);
     
+    log_ereport(LOG_DEBUG, "apply config: AccessLog");
     list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("AccessLog"));
     UCX_FOREACH(elm, list) {
         ConfigNode *scfgobj = elm->data;
@@ -253,6 +256,7 @@
     }
     ucx_list_free(list);
     
+    log_ereport(LOG_DEBUG, "apply config: AuthDB");
     list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("AuthDB"));
     UCX_FOREACH(elm, list) {
         ConfigNode *scfgobj = elm->data;
@@ -262,6 +266,7 @@
     }
     ucx_list_free(list);
     
+    log_ereport(LOG_DEBUG, "apply config: Listener");
     list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("Listener"));
     UCX_FOREACH(elm, list) {
         ConfigNode *scfgobj = elm->data;
@@ -271,6 +276,7 @@
     }
     ucx_list_free(list);
     
+    log_ereport(LOG_DEBUG, "apply config: VirtualServer");
     list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("VirtualServer"));
     UCX_FOREACH(elm, list) {
         ConfigNode *scfgobj = elm->data;
@@ -280,6 +286,7 @@
     }
     ucx_list_free(list);
     
+    log_ereport(LOG_DEBUG, "apply config: ResourcePool");
     list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("ResourcePool"));
     UCX_FOREACH(elm, list) {
         ConfigNode *scfgobj = elm->data;
@@ -288,6 +295,7 @@
         }
     }
     
+    log_ereport(LOG_DEBUG, "apply config: Dav");
     list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("Dav"));
     UCX_FOREACH(elm, list) {
         ConfigNode *scfgobj = elm->data;
@@ -369,8 +377,16 @@
     scstr_t file = serverconfig_directive_value(obj, SC("File"));
     scstr_t lvl = serverconfig_directive_value(obj, SC("Level"));
     
-    if(file.ptr == NULL || lvl.ptr == NULL) {
-        /* missing log file parameters */
+    int err = 0;
+    if(file.ptr == NULL) {
+        err = 1;
+        log_ereport(LOG_MISCONFIG, "LogFile: parameter missing: File");
+    }
+    if(lvl.ptr == NULL) {
+        err = 1;
+        log_ereport(LOG_MISCONFIG, "LogFile: parameter missing: Level");
+    }
+    if(err) {
         return -1;
     }
     
@@ -950,6 +966,7 @@
                 sstr_t ext = sstr(xl->data);
                 sstr_t value = sstrdup(d->type);
                 if(ucx_map_sstr_put(map, ext, value.ptr)) {
+                    log_ereport(LOG_CATASTROPHE, "OOM");
                     ret = -1;
                     break;
                 }
@@ -961,6 +978,7 @@
         
         cfg->mimetypes = mimemap;
     } else {
+        log_ereport(LOG_CATASTROPHE, "OOM");
         ret = -1;
     }
     
--- a/src/server/daemon/configmanager.c	Sun Sep 25 11:00:38 2022 +0200
+++ b/src/server/daemon/configmanager.c	Sun Sep 25 11:56:47 2022 +0200
@@ -70,13 +70,14 @@
 }
 
 int cfgmgr_apply_config(CfgManager *mgr) {
-    int err = 1;
+    int err = 0;
     if(apply_server_conf(mgr)) {
-        err = 0;
         if(current_config) {
             cfg_unref(current_config);
         }
         current_config = mgr->cfg;
+    } else {
+        err = 1;
     }
     
     return err;
--- a/src/server/daemon/log.c	Sun Sep 25 11:00:38 2022 +0200
+++ b/src/server/daemon/log.c	Sun Sep 25 11:56:47 2022 +0200
@@ -114,6 +114,7 @@
     mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
     log_file_fd = open(cfg->file, O_WRONLY | O_CREAT | O_APPEND, mode);
     if(log_file_fd == -1) {
+        log_ereport(LOG_FAILURE, "Cannot open log file %s: %s", cfg->file, strerror(errno));
         return -1;
     }
     
--- a/src/server/daemon/webserver.c	Sun Sep 25 11:00:38 2022 +0200
+++ b/src/server/daemon/webserver.c	Sun Sep 25 11:56:47 2022 +0200
@@ -69,8 +69,11 @@
     // init NSPR
     systhread_init("webserver");
     
+    log_ereport(LOG_VERBOSE, "webserver_init");
+    
     // init ssl
     if(ws_init_ssl()) {
+        log_ereport(LOG_FAILURE, "ssl init failed");
         return -1;
     }
     
@@ -82,6 +85,7 @@
     
     // init resource pools
     if(init_resource_pools()) {
+        log_ereport(LOG_FAILURE, "resource pool init failed");
         return -1;
     }
     
@@ -99,6 +103,7 @@
     if(cfgmgr_load_config(&mgr) != 0) {
         return -1;
     }
+    log_ereport(LOG_VERBOSE, "cfgmgr_load_config stage 1 successful");
     ServerConfiguration *cfg = mgr.cfg;
     
     // init caches
@@ -175,6 +180,7 @@
     // now that the process is running as the correct user, we can load
     // the remaining config
     if(cfgmgr_apply_config(&mgr)) {
+        log_ereport(LOG_FAILURE, "load config stage 2 failed");
         return -1;
     }
     
@@ -204,7 +210,7 @@
                         "cannot change permissions of tmp dir %s:",
                         tmp_priv.ptr,
                         strerror(errno));
-                return 0;
+                return -1;
             }
         } else {
             log_ereport(

mercurial