X-Git-Url: http://wpitchoune.net/gitweb/?p=psensor-pkg-debian.git;a=blobdiff_plain;f=src%2Flib%2Fslog.c;h=d6c4bc2e305cef23e1833857e4f1abc709568e15;hp=d3e646db778dc90c2aaeeb3ac517dad4d9c7f782;hb=3361fda8735c65887a859c9faf287cb105ae6bc8;hpb=1438bc505641cd98fe3af323fb2329c3284e157f diff --git a/src/lib/slog.c b/src/lib/slog.c index d3e646d..d6c4bc2 100644 --- a/src/lib/slog.c +++ b/src/lib/slog.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2013 jeanfi@gmail.com + * Copyright (C) 2010-2014 jeanfi@gmail.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -33,7 +33,8 @@ #include "bool.h" #include "config.h" -#include "log.h" +#include +#include #include "ptime.h" #include "slog.h" @@ -47,7 +48,24 @@ static time_t st; static const char *DEFAULT_FILENAME = "sensors.log"; -static char *get_default_path() +static char *time_to_str(time_t *t) +{ + struct tm lt; + char *str; + + if (!localtime_r(t, <)) + return NULL; + + str = malloc(64); + + if (strftime(str, 64, "%s", <)) + return str; + + free(str); + return NULL; +} + +static char *get_default_path(void) { char *home, *path, *dir; @@ -64,10 +82,10 @@ static char *get_default_path() free(dir); return path; - } else { - log_warn(_("HOME variable not set.")); - return strdup(DEFAULT_FILENAME); } + + log_warn(_("HOME variable not set.")); + return strdup(DEFAULT_FILENAME); } static bool slog_open(const char *path, struct psensor **sensors) @@ -115,8 +133,8 @@ static void slog_write_sensors(struct psensor **sensors) bool first_call; if (!file) { - log_err(_("Sensor log file not open.")); - return ; + log_debug(_("Sensor log file not open.")); + return; } gettimeofday(&tv, NULL); @@ -151,17 +169,17 @@ static void *slog_routine(void *data) { while (1) { pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); - pthread_mutex_lock(sensors_mutex); + pmutex_lock(sensors_mutex); slog_write_sensors(sensors); - pthread_mutex_unlock(sensors_mutex); + pmutex_unlock(sensors_mutex); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); sleep(period); } - pthread_exit(0); + pthread_exit(NULL); } -void slog_close() +void slog_close(void) { if (file) { pthread_cancel(thread);