summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjongmun.woo <jongmun.woo@samsung.com>2016-03-21 22:15:44 +0900
committerjongmun.woo <jongmun.woo@samsung.com>2016-03-22 09:55:39 +0900
commitcacbc689a1e92ee10e6958dbdcbecd865f6bb487 (patch)
tree9dcbfabdef416aee5ff32c84b3d9b8aef61a98fc
parent1eb49e8fedef91361fd4c64a271e49d62700ef9c (diff)
downloadgeofence-server-cacbc689a1e92ee10e6958dbdcbecd865f6bb487.tar.gz
geofence-server-cacbc689a1e92ee10e6958dbdcbecd865f6bb487.tar.bz2
geofence-server-cacbc689a1e92ee10e6958dbdcbecd865f6bb487.zip
Signed-off-by: jongmun.woo <jongmun.woo@samsung.com> Change-Id: Iab406295a744c7bc12846b1bc4294d597e008e50
-rw-r--r--geofence-server/src/geofence_server.c2
-rw-r--r--geofence-server/src/geofence_server_log.c33
-rw-r--r--geofence-server/src/geofence_server_log.h6
3 files changed, 15 insertions, 26 deletions
diff --git a/geofence-server/src/geofence_server.c b/geofence-server/src/geofence_server.c
index eafbcc5..61f3562 100644
--- a/geofence-server/src/geofence_server.c
+++ b/geofence-server/src/geofence_server.c
@@ -123,7 +123,7 @@ static const char *__convert_wifi_error_to_string(wifi_error_e err_type)
void emit_proximity_using_ble(GeofenceServer *geofence_server, int fence_id, geofence_proximity_state_e state)
{
FUNC_ENTRANCE_SERVER;
- g_return_val_if_fail(geofence_server, -1);
+ g_return_if_fail(geofence_server);
GeofenceItemData *item_data = __get_item_by_fence_id(fence_id, geofence_server);
if (item_data) {
if (item_data->common_info.proximity_status != state) {
diff --git a/geofence-server/src/geofence_server_log.c b/geofence-server/src/geofence_server_log.c
index c28179a..0439fa3 100644
--- a/geofence-server/src/geofence_server_log.c
+++ b/geofence-server/src/geofence_server_log.c
@@ -26,42 +26,33 @@
int fd = -1;
-struct tm *__get_current_time()
+void __get_current_time(struct tm *cur_time)
{
time_t now;
- struct tm *cur_time;
time(&now);
- cur_time = localtime(&now);
- return cur_time;
+ localtime_r(&now, cur_time);
}
void _init_log()
{
- struct tm *cur_time = __get_current_time();
+ struct tm cur_time;
char buf[256] = { 0, };
- /*fd = open(__GEOFENCE_LOG_FILE__, O_RDWR | O_APPEND | O_CREAT, 0644);
- * if (fd < 0) {
- * LOGI_GEOFENCE("Fail to open file[%s]", __GEOFENCE_LOG_FILE__);
- * return;
- * } */
- if (cur_time != NULL)
- sprintf(buf, "[%02d:%02d:%02d] -- START -- \n", cur_time->tm_hour, cur_time->tm_min, cur_time->tm_sec);
+ __get_current_time(&cur_time);
+ snprintf(buf, 256, "[%02d:%02d:%02d] -- START -- \n", cur_time.tm_hour, cur_time.tm_min, cur_time.tm_sec);
LOGI_GEOFENCE("BUF[%s]", buf);
- /* write(fd, buf, strlen(buf));*/
}
void _deinit_log()
{
if (fd < 0)
return;
- struct tm *cur_time = __get_current_time();
+ struct tm cur_time;
char buf[256] = { 0, };
- if (cur_time != NULL)
- sprintf(buf, "[%02d:%02d:%02d] -- END -- \n", cur_time->tm_hour, cur_time->tm_min, cur_time->tm_sec);
+ __get_current_time(&cur_time);
+ snprintf(buf, 256, "[%02d:%02d:%02d] -- END -- \n", cur_time.tm_hour, cur_time.tm_min, cur_time.tm_sec);
LOGI_GEOFENCE("BUF[%s]", buf);
- /* write(fd, buf, strlen(buf));*/
close(fd);
fd = -1;
@@ -72,12 +63,10 @@ void _print_log(const char *str)
if (fd < 0)
return;
char buf[256] = { 0, };
- struct tm *cur_time = __get_current_time();
-
- if (cur_time != NULL)
- sprintf(buf, "[%02d:%02d:%02d] %s\n", cur_time->tm_hour, cur_time->tm_min, cur_time->tm_sec, str);
+ struct tm cur_time;
+ __get_current_time(&cur_time);
+ snprintf(buf, 256, "[%02d:%02d:%02d] %s\n", cur_time.tm_hour, cur_time.tm_min, cur_time.tm_sec, str);
LOGI_GEOFENCE("BUF %s", buf);
- /* write(fd, buf, strlen(buf));*/
}
diff --git a/geofence-server/src/geofence_server_log.h b/geofence-server/src/geofence_server_log.h
index 592fe66..e0c97a1 100644
--- a/geofence-server/src/geofence_server_log.h
+++ b/geofence-server/src/geofence_server_log.h
@@ -21,16 +21,16 @@
void _init_log();
void _deinit_log();
void _print_log(const char *str);
-struct tm *__get_current_time();
+void __get_current_time(struct tm *cur_time);
#define GEOFENCE_PRINT_LOG(state) { \
char buf[256] = {0, }; \
- sprintf(buf, " [%s:%d] Status[%s]", __func__, __LINE__, #state); \
+ snprintf(buf, 256, " [%s:%d] Status[%s]", __func__, __LINE__, #state); \
_print_log(buf); \
}
#define GEOFENCE_PRINT_LOG_WITH_ID(state, id) { \
char buf[256] = {0, }; \
- sprintf(buf, " [%s:%d] Status[%s]. ID[%d]", __func__, __LINE__, #state, id); \
+ snprintf(buf, 256, " [%s:%d] Status[%s]. ID[%d]", __func__, __LINE__, #state, id); \
_print_log(buf); \
}