Mon, 06 May 2013 14:54:40 +0200
improved logging
--- a/src/server/daemon/config.c Mon May 06 13:44:27 2013 +0200 +++ b/src/server/daemon/config.c Mon May 06 14:54:40 2013 +0200 @@ -58,13 +58,13 @@ // TODO: Funktion für ConfigDirective -> directive // TODO: Funktion für UcxList parameter list -> pblock -void load_init_conf(char *file) { +int load_init_conf(char *file) { printf("load_init_conf\n"); InitConfig *cfg = load_init_config(file); UcxMempool *mp = cfg->parser.mp; if(cfg == NULL) { - return; + return 1; } cfg_pool = pool_create(); // one pool for one Configuration @@ -93,17 +93,31 @@ d->func = get_function(func_name); if(d->func == NULL) { free(d); - dirs = dirs->next; - continue; + pblock_free(d->param); + //dirs = dirs->next; + log_ereport( + LOG_MISCONFIG, + "Cannot find Init function %s", + func_name); + return 1; } /* execute init directive */ - d->func->func(d->param, NULL, NULL); + int ret = d->func->func(d->param, NULL, NULL); + if(ret != REQ_PROCEED || ret != REQ_NOACTION) { + log_ereport( + LOG_FAILURE, + "Error running Init function %s", + func_name); + return 1; + } dirs = dirs->next; } free_init_config(cfg); + + return 0; } ServerConfiguration* load_server_conf(ServerConfiguration *old, char *file) {
--- a/src/server/daemon/config.h Mon May 06 13:44:27 2013 +0200 +++ b/src/server/daemon/config.h Mon May 06 14:54:40 2013 +0200 @@ -78,7 +78,7 @@ }; -void load_init_conf(char *file); +int load_init_conf(char *file); void init_server_config_parser();
--- a/src/server/daemon/configmanager.c Mon May 06 13:44:27 2013 +0200 +++ b/src/server/daemon/configmanager.c Mon May 06 14:54:40 2013 +0200 @@ -115,7 +115,7 @@ /* reload the file */ //printf("reload: %s\n", sstrdup(f->file).ptr); log_ereport( - LOG_LEVEL_INFO, + LOG_INFORM, "reload configuration file: %s", f->file.ptr); f->reload(f, current_config);
--- a/src/server/daemon/httplistener.c Mon May 06 13:44:27 2013 +0200 +++ b/src/server/daemon/httplistener.c Mon May 06 14:54:40 2013 +0200 @@ -193,7 +193,7 @@ int http_listener_start(HttpListener *listener) { printf("INFO: start listener\n"); - log_ereport(LOG_LEVEL_INFO, "start listener on port %d", listener->port); + log_ereport(LOG_INFORM, "start listener on port %d", listener->port); if (listen(listener->server_socket, 256) == -1) { perror("Error: http_listener_start: listen");
--- a/src/server/daemon/httprequest.c Mon May 06 13:44:27 2013 +0200 +++ b/src/server/daemon/httprequest.c Mon May 06 14:54:40 2013 +0200 @@ -100,7 +100,7 @@ // init NSAPI request structure if(request_initialize(pool, request, rq) != 0) { - log_ereport(LOG_LEVEL_ERROR, "Cannot initialize request structure"); + log_ereport(LOG_FAILURE, "Cannot initialize request structure"); pool_destroy(pool); return 1; }
--- a/src/server/daemon/log.c Mon May 06 13:44:27 2013 +0200 +++ b/src/server/daemon/log.c Mon May 06 14:54:40 2013 +0200 @@ -59,7 +59,7 @@ static AccessLog *default_access_log; -char *log_date_month[] = { +static char *log_date_month[] = { "Jan", "Feb", "Mar", @@ -74,10 +74,24 @@ "Dec" }; -char *log_levels[] = { - "error", +static char *log_levels[] = { "warning", - "info" + "config", + "security", + "failure", + "catastrophe", + "info", + "verbose" +}; + +static int can_log[] = { + 1, // warning + 1, // config + 1, // security + 1, // failure + 1, // catastrophe + 1, // info + 0 // verbose }; int init_log_file(LogConfig *cfg) { @@ -93,11 +107,12 @@ } if(!strcmp(cfg->level, "ERROR")) { - log_level = LOG_LEVEL_ERROR; + can_log[LOG_WARN] = 0; + can_log[LOG_INFORM] = 0; } else if(!strcmp(cfg->level, "WARNING")) { - log_level = LOG_LEVEL_WARNING; + can_log[LOG_INFORM] = 0; } else if(!strcmp(cfg->level, "INFO")) { - log_level = LOG_LEVEL_INFO; + } if(cfg->log_stdout) { @@ -191,7 +206,10 @@ */ int log_ereport(int degree, const char *format, ...) { - if(degree > log_level) { + if(degree > 6) { + return 0; + } + if(degree > 0 && !can_log[degree]) { return 0; }
--- a/src/server/daemon/log.h Mon May 06 13:44:27 2013 +0200 +++ b/src/server/daemon/log.h Mon May 06 14:54:40 2013 +0200 @@ -38,10 +38,6 @@ extern "C" { #endif -#define LOG_LEVEL_ERROR 0 -#define LOG_LEVEL_WARNING 1 -#define LOG_LEVEL_INFO 2 - typedef struct { char *file; char *level;
--- a/src/server/daemon/main.c Mon May 06 13:44:27 2013 +0200 +++ b/src/server/daemon/main.c Mon May 06 14:54:40 2013 +0200 @@ -58,10 +58,10 @@ * SIGUSR1: reload the configuration files */ void sig_usr1_reload(int sig) { - log_ereport(LOG_LEVEL_INFO, "sig reload"); + log_ereport(LOG_INFORM, "sig reload"); if(cfgmgr_load_config() != 0) { - log_ereport(LOG_LEVEL_ERROR, "cannot reload config"); + log_ereport(LOG_FAILURE, "cannot reload config"); } signal(SIGUSR1, sig_usr1_reload);
--- a/src/server/daemon/sessionhandler.c Mon May 06 13:44:27 2013 +0200 +++ b/src/server/daemon/sessionhandler.c Mon May 06 14:54:40 2013 +0200 @@ -173,7 +173,7 @@ if(ev_pollin(ev, conn->fd, event) != 0) { // TODO: ev_pollin should log, intercept some errors here - log_ereport(LOG_LEVEL_ERROR, "ev_pollin failed: %s", strerror(errno)); + log_ereport(LOG_WARN, "ev_pollin failed: %s", strerror(errno)); close(conn->fd); // TODO: free stuff }
--- a/src/server/daemon/webserver.c Mon May 06 13:44:27 2013 +0200 +++ b/src/server/daemon/webserver.c Mon May 06 14:54:40 2013 +0200 @@ -64,7 +64,9 @@ add_functions(webserver_funcs); // load init.conf - load_init_conf("config/init.conf"); + if(load_init_conf("config/init.conf")) { + return -1; + } // load server.conf init_configuration_manager(); @@ -98,7 +100,7 @@ setpwent(); if(!util_getpwnam(cfg->user.ptr, vars->Vuserpw, pwbuf, DEF_PWBUF)) { log_ereport( - LOG_LEVEL_ERROR, + LOG_MISCONFIG, "user %s does not exist!", cfg->user.ptr); free(vars->Vuserpw); @@ -114,30 +116,29 @@ if(setgid(vars->Vuserpw->pw_gid) != 0) { log_ereport( - LOG_LEVEL_ERROR, + LOG_FAILURE, "setgid(%d) failed", vars->Vuserpw->pw_gid); } else { // setgid was successful // we need to call initgroups to have all group permissions if(initgroups(vars->Vuserpw->pw_name, vars->Vuserpw->pw_gid)!=0) { - log_ereport(LOG_LEVEL_ERROR, "initgroups failed"); + log_ereport(LOG_FAILURE, "initgroups failed"); } } // change the uid if(setuid(vars->Vuserpw->pw_uid)) { log_ereport( - LOG_LEVEL_ERROR, + LOG_FAILURE, "setuid(%d) failed", vars->Vuserpw->pw_uid); } } else if(vars->Vuserpw) { log_ereport( - LOG_LEVEL_INFO, + LOG_WARN, "server must be started as root to change uid"); } - return 0; }
--- a/src/server/safs/common.c Mon May 06 13:44:27 2013 +0200 +++ b/src/server/safs/common.c Mon May 06 14:54:40 2013 +0200 @@ -35,7 +35,7 @@ char *msg = pblock_findval("msg", pb); if(msg) { printf("%s\n", msg); - log_ereport(LOG_LEVEL_INFO, "%s", msg); + log_ereport(LOG_INFORM, "%s", msg); } return REQ_NOACTION;
--- a/src/server/safs/init.c Mon May 06 13:44:27 2013 +0200 +++ b/src/server/safs/init.c Mon May 06 14:54:40 2013 +0200 @@ -38,19 +38,34 @@ } int load_modules(pblock *pb, Session *sn, Request *rq) { - printf("load_modules\n"); - char *shlib = pblock_findval("shlib", pb); char *funcs = pblock_findval("funcs", pb); if(shlib == NULL || funcs == NULL) { fprintf(stderr, "load-modules: missing parameter\n"); + //log_ereport(LOG_MISCONFIG, "load-modules: missing parameters"); + if(!shlib && funcs) { + log_ereport( + LOG_MISCONFIG, + "load-modules: missing shlib parameter"); + } else if(!shlib && !funcs) { + log_ereport( + LOG_MISCONFIG, + "load-modules: missing funcs parameter"); + } else { + log_ereport( + LOG_MISCONFIG, + "load-modules: missing shlib and funcs parameters"); + } } /* load lib */ void *lib = dlopen(shlib, RTLD_GLOBAL | RTLD_NOW); if(lib == NULL) { - fprintf(stderr, "Cannot load library %s %s\n", shlib, dlerror()); + char *dlerr = dlerror(); + fprintf(stderr, "Cannot load library %s %s\n", shlib, dlerr); + + log_ereport(LOG_FAILURE, "Cannot load library %s: %s", shlib, dlerr); return REQ_ABORTED; }