Sat, 22 Oct 2016 11:27:39 +0200
improves logging
replaces some printf calls with log_ereport
in non-daemon mode, log output is also written to stdout
--- a/src/server/admin/admin.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/admin/admin.c Sat Oct 22 11:27:39 2016 +0200 @@ -40,7 +40,7 @@ static Page *root_page; int admin_init(pblock *pb, Session *sn, Request *rq) { - printf("admin-init\n"); + log_ereport(LOG_VERBOSE, "admin-init"); pool_handle_t *pool = pool_create(); root_page = admin_page_create(pool, NULL, admin_root);
--- a/src/server/config/acl.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/config/acl.c Sat Oct 22 11:27:39 2016 +0200 @@ -113,7 +113,7 @@ ssize_t tkn = 0; sstr_t *tk = sstrsplit(line, sstr(":"), &tkn); if(!tk || tkn < 3) { - fprintf(stderr, "parse_ace: to few tokens\n"); + log_ereport(LOG_FAILURE, "parse_ace: to few tokens"); return 1; } @@ -156,7 +156,7 @@ if(n >= tkn) { // to few tokens - fprintf(stderr, "parse_ace: ace incomplete\n"); + log_ereport(LOG_FAILURE, "parse_ace: ace incomplete"); return 1; } s = tk[n]; @@ -212,7 +212,7 @@ } if(!complete) { - fprintf(stderr, "parse_ace: ace incomplete\n"); + log_ereport(LOG_FAILURE, "parse_ace: ace incomplete"); return 1; }
--- a/src/server/config/conf.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/config/conf.c Sat Oct 22 11:27:39 2016 +0200 @@ -279,7 +279,7 @@ */ ConfigDirective* cfg_parse_directive(sstr_t line, UcxAllocator *mp) { if(line.length < 6) { - printf("line too short\n"); + log_ereport(LOG_FAILURE, "cfg_parse_directive: line too short"); return NULL; // line too short }
--- a/src/server/config/initconf.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/config/initconf.c Sat Oct 22 11:27:39 2016 +0200 @@ -64,7 +64,7 @@ // parse directive ConfigDirective *d = cfg_parse_directive(line, conf->parser.mp); if(d == NULL) { - fprintf(stderr, "Error: initconf_parse: directive is null\n"); + log_ereport(LOG_FAILURE, "initconf_parse: directive is null"); return 0; } d->begin = begin; @@ -72,7 +72,7 @@ if(d->type_num == INIT_DIRECTIVE) { conf->directives = ucx_list_append(conf->directives, d); } else { - fprintf(stderr, "Warning: Non Init directive in init.conf\n"); + log_ereport(LOG_WARN, "Non Init directive in init.conf"); } return 0;
--- a/src/server/config/keyfile.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/config/keyfile.c Sat Oct 22 11:27:39 2016 +0200 @@ -106,7 +106,10 @@ entry->hashtype = KEYFILE_SSHA; } else { // unkown hash type - fprintf(stderr, "unknown hash type: %s\n", sstrdup_a(mp, hash_type).ptr); + log_ereport( + LOG_FAILURE, + "keyfile_parse: unknown hash type: %s", + sstrdup_a(mp, hash_type).ptr); return 1; }
--- a/src/server/config/objconf.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/config/objconf.c Sat Oct 22 11:27:39 2016 +0200 @@ -84,7 +84,7 @@ case LINE_BEGIN_TAG: { ConfigTag *tag = cfg_parse_begin_tag(line, conf->parser.mp); if(tag == NULL) { - fprintf(stderr, "Parse error!\n"); + log_ereport(LOG_FAILURE, "Parse error in %s", conf->file); exit(-1); // TODO: better error handling } tag->begin = begin; @@ -192,7 +192,7 @@ break; } default: { - printf("unknown tag\n"); + log_ereport(LOG_FAILURE, "objconf: unknown tag"); return 1; } } @@ -203,7 +203,7 @@ int objconf_on_end_tag(ObjectConfig *conf, sstr_t tagname) { int type = cfg_get_tag_type(tagname); if(type == -1) { - fprintf(stderr, "unknown tag\n"); + log_ereport(LOG_FAILURE, "objconf: unknown tag"); return 1; } else { if(type == TAG_OBJECT) {
--- a/src/server/config/serverconf.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/config/serverconf.c Sat Oct 22 11:27:39 2016 +0200 @@ -90,8 +90,8 @@ case LINE_END_TAG: { sstr_t tag = cfg_get_end_tag_name(line); if(sstrcmp(tag, conf->obj->type) != 0) { - fprintf(stderr, "syntax error: wrong close tag\n"); - fprintf(stderr, "open tag: %s close tag: %s\n", sstrdup(tag).ptr, sstrdup(conf->obj->type).ptr); + log_ereport(LOG_FAILURE, "server.conf: syntax error: wrong close tag"); + log_ereport(LOG_FAILURE, "open tag: %s close tag: %s", sstrdup(tag).ptr, sstrdup(conf->obj->type).ptr); exit(-1); } conf->obj = NULL; @@ -100,7 +100,7 @@ } case LINE_DIRECTIVE: { if(conf->obj == NULL) { - fprintf(stderr, "syntax error: directive outside of object\n"); + log_ereport(LOG_FAILURE, "server.conf: directive outside of object"); exit(-1); }
--- a/src/server/daemon/auth.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/daemon/auth.c Sat Oct 22 11:27:39 2016 +0200 @@ -33,6 +33,7 @@ #include <ucx/map.h> +#include "../public/nsapi.h" #include "../util/atomic.h" #include "auth.h" @@ -40,7 +41,7 @@ static UserCache cache; void auth_cache_init() { - printf("auth_cache_init\n"); + log_ereport(LOG_VERBOSE, "auth_cache_init"); // TODO: config parameters //pthread_mutex_init(&auth_cache_mutex, NULL); cache.map = calloc(80, sizeof(UserCacheElm));
--- a/src/server/daemon/config.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/daemon/config.c Sat Oct 22 11:27:39 2016 +0200 @@ -61,11 +61,11 @@ // TODO: Funktion für UcxList parameter list -> pblock int load_init_conf(char *file) { - printf("load_init_conf\n"); + log_ereport(LOG_VERBOSE, "load_init_conf"); InitConfig *cfg = load_init_config(file); if(cfg == NULL) { - fprintf(stderr, "Cannot load init.conf\n"); + log_ereport(LOG_FAILURE, "Cannot load init.conf"); return 1; } UcxAllocator *mp = cfg->parser.mp; @@ -128,11 +128,11 @@ } ServerConfiguration* load_server_conf(ServerConfiguration *old, char *file) { - printf("load_server_conf\n"); + log_ereport(LOG_VERBOSE, "load_server_conf"); ServerConfig *serverconf = load_server_config(file); if(serverconf == NULL) { - fprintf(stderr, "Cannot load server.conf\n"); + log_ereport(LOG_FAILURE, "Cannot load server.conf"); } ServerConfiguration *serverconfig = calloc(1, sizeof(ServerConfiguration)); serverconfig->ref = 1; @@ -504,7 +504,6 @@ name = sstrdup(name); AuthDB *authdb = create_ldap_authdb(name.ptr, &conf); - printf("authdb: %"PRIxPTR"\n", (intptr_t)authdb); ucx_map_sstr_put(cfg->authdbs, name, authdb); // TODO: create_ldap_authdb should copy the strings @@ -549,7 +548,6 @@ // add keyfile authdb Keyfile *keyfile = f->data; keyfile->authdb.name = sstrdup(name).ptr; - printf("authdb: %"PRIxPTR"\n", (intptr_t)keyfile); ucx_map_sstr_put(cfg->authdbs, name, keyfile); } @@ -716,7 +714,7 @@ } HTTPObjectConfig* load_obj_conf(char *file) { - printf("load_obj_conf\n"); + log_ereport(LOG_VERBOSE, "load_obj_conf"); // new conf function test ObjectConfig *cfg = load_object_config(file); @@ -863,7 +861,7 @@ UCX_FOREACH(elm, aclfile->namedACLs) { ACLConfig *ac = elm->data; ACLList *acl = acl_config_convert(cfg, ac); - printf("put acl: %s\n", ac->id.ptr); + log_ereport(LOG_VERBOSE, "add acl: %.*s", (int)ac->id.length, ac->id.ptr); ucx_map_sstr_put(acldata->namedACLs, ac->id, acl); } free_acl_file(aclfile); @@ -887,7 +885,6 @@ acllist->ece = NULL; if(acl->type.ptr && !sstrcmp(acl->type, sstr("fs"))) { - printf("set acl to extern\n"); acllist->acl.isextern = 1; }
--- a/src/server/daemon/configmanager.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/daemon/configmanager.c Sat Oct 22 11:27:39 2016 +0200 @@ -76,7 +76,6 @@ //printf("1 time: %d - %d\n", f->last_modified, s.st_mtim.tv_sec); if(f->last_modified != s.st_mtime) { /* reload the file */ - printf("reload: %s\n", f->file.ptr); if(f->last_modified != 0) { log_ereport( LOG_INFORM, @@ -112,19 +111,17 @@ ServerConfiguration *config; if(cfgreload || !current_config || sc_last_modified != s.st_mtime) { - printf("cfgmgr load server.conf\n"); config = load_server_conf( current_config, "config/server.conf"); if(config == NULL) { - fprintf(stderr, "Cannot load server.conf\n"); return -1; } sc_last_modified = s.st_mtime; } else { - printf("no reconfig required!\n"); + log_ereport(LOG_VERBOSE, "no reconfig required"); config = current_config; }
--- a/src/server/daemon/func.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/daemon/func.c Sat Oct 22 11:27:39 2016 +0200 @@ -51,7 +51,7 @@ } } f->name = name; - printf("add_function %s\n", f->name); + log_ereport(LOG_VERBOSE, "add_function %s", f->name); ucx_map_cstr_put(function_map, (char*)f->name, f); }
--- a/src/server/daemon/httplistener.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/daemon/httplistener.c Sat Oct 22 11:27:39 2016 +0200 @@ -212,8 +212,7 @@ /* bind server socket to address */ if(bind(listener->server_socket, (struct sockaddr*)&servaddr, sizeof(servaddr))){ - perror("Error: http_listener_new: bind"); - printf("port: %d\n", conf->port); + log_ereport(LOG_FAILURE, "http_listener_new: bind failed. Port: %d", conf->port); return NULL; } @@ -230,11 +229,10 @@ if(listener->running) { return 0; } - printf("INFO: start listener\n"); log_ereport(LOG_INFORM, "start listener on port %d", listener->port); if (listen(listener->server_socket, 256) == -1) { - perror("Error: http_listener_start: listen"); + log_ereport(LOG_FAILURE, "http_listener_start: listen failed"); return -1; }
--- a/src/server/daemon/httprequest.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/daemon/httprequest.c Sat Oct 22 11:27:39 2016 +0200 @@ -293,7 +293,7 @@ if(ctlen_str) { int ctlen = atoi(ctlen_str); - printf("request body length: %d\n", ctlen); + //printf("request body length: %d\n", ctlen); netbuf *nb = request->netbuf; @@ -565,7 +565,7 @@ // add additional objects to the objset if(add_objects(objconf, objset, sn, rq, name, ppath) == REQ_ABORTED) { - fprintf(stderr, "add_objects failed\n"); + log_ereport(LOG_FAILURE, "add_objects failed"); return REQ_ABORTED; }
--- a/src/server/daemon/log.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/daemon/log.c Sat Oct 22 11:27:39 2016 +0200 @@ -49,6 +49,8 @@ static int log_file_fd; static int log_level = 0; +WSBool main_is_daemon(void); + /* * if the log file is uninitialized, output is written to the ui_buffer */ @@ -168,6 +170,9 @@ }; writev(log_file_fd, io, 2); /* TODO: aio */ + if(!main_is_daemon()) { + writev(STDOUT_FILENO, io, 2); + } } sstr_t log_get_prefix(int level) {
--- a/src/server/daemon/main.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/daemon/main.c Sat Oct 22 11:27:39 2016 +0200 @@ -46,7 +46,8 @@ #include "configmanager.h" -int std_pipe_fds[2]; +static int std_pipe_fds[2]; +static WSBool is_daemon; void test() { time_t t = time(NULL); @@ -55,6 +56,11 @@ printf("%s\n", date.ptr); } + +WSBool main_is_daemon(void) { + return is_daemon; +} + /* * SIGUSR1: reload the configuration files */ @@ -97,15 +103,15 @@ //test(); /* if the -c parameter is specified, we don't create a daemon */ - int d = 1; + is_daemon = 1; for(int i=0;i<argc;i++) { char *p = argv[i]; if(p[0] == '-' && p[1] == 'c') { - d = 0; + is_daemon = 0; break; } } - if(d) { + if(is_daemon) { /* create daemon */ pid_t pid = fork(); if(pid < 0) { @@ -163,7 +169,7 @@ /* TODO: join threads (or not?) */ while(1) { - if(d) { + if(is_daemon) { fflush(stdout); fflush(stderr); }
--- a/src/server/daemon/webserver.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/daemon/webserver.c Sat Oct 22 11:27:39 2016 +0200 @@ -182,18 +182,20 @@ } int webserver_run() { - printf("webserver_run\n"); + log_ereport(LOG_VERBOSE, "webserver_run"); // start all http listener if(start_all_listener() != 0) { fprintf(stderr, "Error: Cannot start http listener\n"); } + + log_ereport(LOG_INFORM, "webserver started"); return 0; } void webserver_shutdown() { - printf("webserver_shutdown\n"); + log_ereport(LOG_INFORM, "webserver shutdown"); // execute restart callbacks RestartCallback *re = atrestart;
--- a/src/server/util/LinkedList.hh Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/util/LinkedList.hh Sat Oct 22 11:27:39 2016 +0200 @@ -112,8 +112,10 @@ _numElts--; delete elmtP; }; - if ( (1==autoDestroy) && recP) + if ( (1==autoDestroy) && recP) { delete recP; + recP = NULL; + } return(recP); };
--- a/src/server/util/thrpool.c Wed Feb 10 12:19:56 2016 +0100 +++ b/src/server/util/thrpool.c Sat Oct 22 11:27:39 2016 +0200 @@ -36,7 +36,7 @@ static threadpool_job kill_job; threadpool_t* threadpool_new(int min, int max) { - printf("threadpool(%d, %d)\n", min, max); + log_ereport(LOG_VERBOSE, "new threadpool (min: %d, max: %d)", min, max); threadpool_t *pool = malloc(sizeof(threadpool_t)); pool->queue = NULL; pool->queue_len = 0;