diff options
Diffstat (limited to 'src/stats.c')
-rw-r--r-- | src/stats.c | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/src/stats.c b/src/stats.c index 26343b13..663bc382 100644 --- a/src/stats.c +++ b/src/stats.c @@ -227,18 +227,14 @@ static void stats_free(gpointer user_data) munmap(file->addr, file->len); file->addr = NULL; - TFR(close(file->fd)); + close(file->fd); file->fd = -1; - if (file->history_name) { - g_free(file->history_name); - file->history_name = NULL; - } + g_free(file->history_name); + file->history_name = NULL; - if (file->name) { - g_free(file->name); - file->name = NULL; - } + g_free(file->name); + file->name = NULL; g_free(file); } @@ -377,7 +373,8 @@ static int stats_file_setup(struct stats_file *file) connman_error("fstat error %s for %s\n", strerror(errno), file->name); - TFR(close(file->fd)); + close(file->fd); + file->fd = -1; g_free(file->name); file->name = NULL; @@ -392,7 +389,8 @@ static int stats_file_setup(struct stats_file *file) err = stats_file_remap(file, size); if (err < 0) { - TFR(close(file->fd)); + close(file->fd); + file->fd = -1; g_free(file->name); file->name = NULL; @@ -621,7 +619,7 @@ static int stats_file_close_swap(struct stats_file *history_file, stats_file_unmap(history_file); stats_file_unmap(temp_file); - TFR(close(temp_file->fd)); + close(temp_file->fd); unlink(history_file->name); @@ -629,7 +627,7 @@ static int stats_file_close_swap(struct stats_file *history_file, unlink(temp_file->name); - TFR(close(history_file->fd)); + close(history_file->fd); stats_file_cleanup(history_file); stats_file_cleanup(temp_file); @@ -649,6 +647,9 @@ static int stats_file_history_update(struct stats_file *data_file) bzero(history_file, sizeof(struct stats_file)); bzero(temp_file, sizeof(struct stats_file)); + history_file->fd = -1; + temp_file->fd = -1; + err = stats_open(history_file, data_file->history_name); if (err < 0) return err; @@ -676,17 +677,6 @@ int __connman_stats_service_register(struct connman_service *service) DBG("service %p", service); - file = g_hash_table_lookup(stats_hash, service); - if (!file) { - file = g_try_new0(struct stats_file, 1); - if (!file) - return -ENOMEM; - - g_hash_table_insert(stats_hash, service, file); - } else { - return -EALREADY; - } - dir = g_strdup_printf("%s/%s", STORAGEDIR, __connman_service_get_ident(service)); @@ -703,6 +693,18 @@ int __connman_stats_service_register(struct connman_service *service) } g_free(dir); + file = g_hash_table_lookup(stats_hash, service); + if (!file) { + file = g_try_new0(struct stats_file, 1); + if (!file) + return -ENOMEM; + + file->fd = -1; + + g_hash_table_insert(stats_hash, service, file); + } else { + return -EALREADY; + } name = g_strdup_printf("%s/%s/data", STORAGEDIR, __connman_service_get_ident(service)); |