src/server/daemon/log.c

changeset 77
f1cff81e425a
parent 60
feb2f1e115c6
child 79
f48cea237ec3
--- a/src/server/daemon/log.c	Mon Jun 24 14:41:32 2013 +0200
+++ b/src/server/daemon/log.c	Tue Jun 25 15:45:13 2013 +0200
@@ -41,6 +41,7 @@
 #include "../util/strbuf.h"
 #include "../util/io.h"
 #include "../ucx/map.h"
+#include "../util/atomic.h"
 
 static int is_initialized = 0;
 
@@ -53,10 +54,9 @@
 static sbuf_t *ui_buffer = NULL;
 
 /*
- * access logfile map
+ * access log file map
  */
-static UcxMap    *access_log_files; // map of AccessLog*
-static AccessLog *default_access_log;
+static UcxMap *access_log_files; // map of LogFile*
 
 
 static char *log_date_month[] = {
@@ -248,7 +248,7 @@
  * This source file only manages access log files. IO is performed directly
  * by AddLog safs. 
  */
-AccessLog* get_access_log(sstr_t file, sstr_t format) {
+LogFile* get_access_log_file(sstr_t file) {
     if(!access_log_files) {
         access_log_files = ucx_map_new(4);
     }
@@ -257,41 +257,27 @@
         return NULL;
     }
     
-    AccessLog *log = ucx_map_sstr_get(access_log_files, file);
+    LogFile *log = ucx_map_sstr_get(access_log_files, file);
     if(log != NULL) {
-        // TODO: ref
+        ws_atomic_inc32(&log->ref);
         return log;
     }
     
     // the log file is not opened
     // check first if we can open it
-    sstr_t path = sstrdup(file);
-    FILE *out = fopen(path.ptr, "a");
+    FILE *out = fopen(file.ptr, "a");
     if(out == NULL) {
-        free(path.ptr);
         return NULL;
     }
     
-    // create access log object
-    log = calloc(1, sizeof(AccessLog));
-    log->file = path;
-    if(format.ptr != NULL) {
-        log->format = sstrdup(format);
-    }
-    log->log = out;
-    // TODO: log->ref = 1;
+    // create LogFile object
+    log = calloc(1, sizeof(LogFile));
+    log->file = out;
+    log->ref = 1;
     
     // add access log to the map
     ucx_map_sstr_put(access_log_files, file, log);
     
-    if(!default_access_log) {
-        default_access_log = log;
-    }
-    
     return log;
 }
 
-AccessLog* get_default_access_log() {
-    // TODO: ref
-    return default_access_log;
-}

mercurial