code cleanup
[psensor.git] / src / server / server.c
index f4557d8..8a6e578 100644 (file)
@@ -42,8 +42,9 @@
 #include "cpu.h"
 #endif
 
-#include "log.h"
+#include <plog.h>
 #include "psensor_json.h"
+#include <pmutex.h>
 #include "url.h"
 #include "server.h"
 #include "slog.h"
@@ -74,7 +75,7 @@ static struct option long_options[] = {
 
 static struct server_data server_data;
 
-static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t mutex;
 
 static int server_stop_requested;
 
@@ -254,15 +255,16 @@ create_response(const char *nurl, const char *method, unsigned int *rp_code)
                free(fpath);
        }
 
-       if (resp) {
+       if (resp)
                return resp;
-       } else {
-               char *page = strdup(PAGE_NOT_FOUND);
-               *rp_code = MHD_HTTP_NOT_FOUND;
 
-               return MHD_create_response_from_data
-                       (strlen(page), page, MHD_YES, MHD_NO);
-       }
+       char *page = strdup(PAGE_NOT_FOUND);
+       *rp_code = MHD_HTTP_NOT_FOUND;
+
+       return MHD_create_response_from_data(strlen(page),
+                                            page,
+                                            MHD_YES,
+                                            MHD_NO);
 }
 
 static int cbk_http_request(void *cls,
@@ -298,9 +300,9 @@ static int cbk_http_request(void *cls,
 
        nurl = url_normalize(url);
 
-       pthread_mutex_lock(&mutex);
+       pmutex_lock(&mutex);
        response = create_response(nurl, method, &resp_code);
-       pthread_mutex_unlock(&mutex);
+       pmutex_unlock(&mutex);
 
        ret = MHD_queue_response(connection, resp_code, response);
        MHD_destroy_response(response);
@@ -388,6 +390,8 @@ int main(int argc, char *argv[])
        if (!log_file)
                log_file = strdup(DEFAULT_LOG_FILE);
 
+       pmutex_init(&mutex);
+
        log_open(log_file);
 
        psensor_init();
@@ -426,7 +430,7 @@ int main(int argc, char *argv[])
        }
 
        while (!server_stop_requested) {
-               pthread_mutex_lock(&mutex);
+               pmutex_lock(&mutex);
 
 #ifdef HAVE_GTOP
                sysinfo_update(&server_data.psysinfo);
@@ -436,7 +440,7 @@ int main(int argc, char *argv[])
 
                psensor_log_measures(server_data.sensors);
 
-               pthread_mutex_unlock(&mutex);
+               pmutex_unlock(&mutex);
                sleep(5);
        }
 
@@ -454,7 +458,6 @@ int main(int argc, char *argv[])
 
 #ifdef HAVE_GTOP
        sysinfo_cleanup();
-       cpu_cleanup();
 #endif
 
        if (log_file != DEFAULT_LOG_FILE)