diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-06 19:43:27 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-06 19:43:27 +0000 |
commit | 93384a07dccabcdf85459dc341d92bdf1d58d60d (patch) | |
tree | 5ee93d2e2f576b03deeb3704cc051a880aedfc3e /src/statistics/gnunet-service-statistics.c | |
parent | 79a1640fc8d082b7f61a0b00ee070c8717009a1f (diff) | |
download | gnunet-93384a07dccabcdf85459dc341d92bdf1d58d60d.tar.gz gnunet-93384a07dccabcdf85459dc341d92bdf1d58d60d.zip |
-vminko: fix for #1930
Diffstat (limited to 'src/statistics/gnunet-service-statistics.c')
-rw-r--r-- | src/statistics/gnunet-service-statistics.c | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c index 24ed08833..ec3492710 100644 --- a/src/statistics/gnunet-service-statistics.c +++ b/src/statistics/gnunet-service-statistics.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2009, 2010 Christian Grothoff (and other contributing authors) | 3 | (C) 2009, 2010, 2012 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -22,11 +22,9 @@ | |||
22 | * @file statistics/gnunet-service-statistics.c | 22 | * @file statistics/gnunet-service-statistics.c |
23 | * @brief program that tracks statistics | 23 | * @brief program that tracks statistics |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | * | ||
26 | * TODO: | ||
27 | * - use BIO for IO operations | ||
28 | */ | 25 | */ |
29 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_bio_lib.h" | ||
30 | #include "gnunet_container_lib.h" | 28 | #include "gnunet_container_lib.h" |
31 | #include "gnunet_disk_lib.h" | 29 | #include "gnunet_disk_lib.h" |
32 | #include "gnunet_getopt_lib.h" | 30 | #include "gnunet_getopt_lib.h" |
@@ -175,11 +173,11 @@ static void | |||
175 | load (struct GNUNET_SERVER_Handle *server) | 173 | load (struct GNUNET_SERVER_Handle *server) |
176 | { | 174 | { |
177 | char *fn; | 175 | char *fn; |
178 | struct GNUNET_DISK_FileHandle *fh; | 176 | struct GNUNET_BIO_ReadHandle *rh; |
179 | struct GNUNET_DISK_MapHandle *mh; | ||
180 | struct stat sb; | 177 | struct stat sb; |
181 | char *buf; | 178 | char *buf; |
182 | struct GNUNET_SERVER_MessageStreamTokenizer *mst; | 179 | struct GNUNET_SERVER_MessageStreamTokenizer *mst; |
180 | char *emsg; | ||
183 | 181 | ||
184 | fn = GNUNET_DISK_get_home_filename (cfg, "statistics", "statistics.data", | 182 | fn = GNUNET_DISK_get_home_filename (cfg, "statistics", "statistics.data", |
185 | NULL); | 183 | NULL); |
@@ -190,17 +188,18 @@ load (struct GNUNET_SERVER_Handle *server) | |||
190 | GNUNET_free (fn); | 188 | GNUNET_free (fn); |
191 | return; | 189 | return; |
192 | } | 190 | } |
193 | fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); | 191 | buf = GNUNET_malloc (sb.st_size); |
194 | if (!fh) | 192 | rh = GNUNET_BIO_read_open (fn); |
193 | if (!rh) | ||
195 | { | 194 | { |
196 | GNUNET_free (fn); | 195 | GNUNET_free (fn); |
197 | return; | 196 | return; |
198 | } | 197 | } |
199 | buf = GNUNET_DISK_file_map (fh, &mh, GNUNET_DISK_MAP_TYPE_READ, sb.st_size); | 198 | if (GNUNET_OK != GNUNET_BIO_read (rh, fn, buf, sb.st_size)) |
200 | if (NULL == buf) | ||
201 | { | 199 | { |
202 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "mmap", fn); | 200 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", fn); |
203 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); | 201 | GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, &emsg)); |
202 | GNUNET_free_non_null (emsg); | ||
204 | GNUNET_free (fn); | 203 | GNUNET_free (fn); |
205 | return; | 204 | return; |
206 | } | 205 | } |
@@ -212,8 +211,9 @@ load (struct GNUNET_SERVER_Handle *server) | |||
212 | GNUNET_SERVER_mst_receive (mst, NULL, buf, sb.st_size, | 211 | GNUNET_SERVER_mst_receive (mst, NULL, buf, sb.st_size, |
213 | GNUNET_YES, GNUNET_NO)); | 212 | GNUNET_YES, GNUNET_NO)); |
214 | GNUNET_SERVER_mst_destroy (mst); | 213 | GNUNET_SERVER_mst_destroy (mst); |
215 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_unmap (mh)); | 214 | GNUNET_free (buf); |
216 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); | 215 | GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, &emsg)); |
216 | GNUNET_free_non_null (emsg); | ||
217 | GNUNET_free (fn); | 217 | GNUNET_free (fn); |
218 | } | 218 | } |
219 | 219 | ||
@@ -225,40 +225,37 @@ save () | |||
225 | { | 225 | { |
226 | struct StatsEntry *pos; | 226 | struct StatsEntry *pos; |
227 | char *fn; | 227 | char *fn; |
228 | struct GNUNET_DISK_FileHandle *fh; | 228 | struct GNUNET_BIO_WriteHandle *wh; |
229 | |||
229 | uint16_t size; | 230 | uint16_t size; |
230 | unsigned long long total; | 231 | unsigned long long total; |
231 | 232 | ||
232 | fh = NULL; | 233 | wh = NULL; |
233 | fn = GNUNET_DISK_get_home_filename (cfg, "statistics", "statistics.data", | 234 | fn = GNUNET_DISK_get_home_filename (cfg, "statistics", "statistics.data", |
234 | NULL); | 235 | NULL); |
235 | if (fn != NULL) | 236 | if (fn != NULL) |
236 | fh = GNUNET_DISK_file_open (fn, | 237 | wh = GNUNET_BIO_write_open (fn); |
237 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | ||
238 | | GNUNET_DISK_OPEN_TRUNCATE, | ||
239 | GNUNET_DISK_PERM_USER_READ | | ||
240 | GNUNET_DISK_PERM_USER_WRITE); | ||
241 | total = 0; | 238 | total = 0; |
242 | while (NULL != (pos = start)) | 239 | while (NULL != (pos = start)) |
243 | { | 240 | { |
244 | start = pos->next; | 241 | start = pos->next; |
245 | if ((pos->persistent) && (NULL != fh)) | 242 | if ((pos->persistent) && (NULL != wh)) |
246 | { | 243 | { |
247 | size = htons (pos->msg->header.size); | 244 | size = htons (pos->msg->header.size); |
248 | if (size != GNUNET_DISK_file_write (fh, pos->msg, size)) | 245 | if (GNUNET_OK != GNUNET_BIO_write (wh, pos->msg, size)) |
249 | { | 246 | { |
250 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); | 247 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); |
251 | GNUNET_DISK_file_close (fh); | 248 | GNUNET_BIO_write_close (wh); |
252 | fh = NULL; | 249 | wh = NULL; |
253 | } | 250 | } |
254 | else | 251 | else |
255 | total += size; | 252 | total += size; |
256 | } | 253 | } |
257 | GNUNET_free (pos); | 254 | GNUNET_free (pos); |
258 | } | 255 | } |
259 | if (NULL != fh) | 256 | if (NULL != wh) |
260 | { | 257 | { |
261 | GNUNET_DISK_file_close (fh); | 258 | GNUNET_BIO_write_close (wh); |
262 | if (total == 0) | 259 | if (total == 0) |
263 | GNUNET_break (0 == UNLINK (fn)); | 260 | GNUNET_break (0 == UNLINK (fn)); |
264 | else | 261 | else |