Hi Daniel, > Use stat before open the file to find out if the > file already exists. Only if file exists and > the header is invalid trigger connman_error > --- > src/stats.c | 30 +++++++++++++++++++++--------- > 1 files changed, 21 insertions(+), 9 deletions(-)
I applied that patch as it is ... > diff --git a/src/stats.c b/src/stats.c > index 6f6e2c7..b290c13 100644 > --- a/src/stats.c > +++ b/src/stats.c > @@ -250,11 +250,12 @@ static int stats_open_file(struct connman_service > *service, > struct stats_file *file, > connman_bool_t roaming) > { > - struct stat stat; > + struct stat st; > char *name; > int err; > size_t size; > struct stats_file_header *hdr; > + connman_bool_t new_file = FALSE; > > if (roaming == FALSE) { > name = g_strdup_printf("%s/stats/%s.data", STORAGEDIR, > @@ -265,9 +266,16 @@ static int stats_open_file(struct connman_service > *service, > } > > file->name = name; > + > + err = stat(file->name, &st); > + if (err < 0) { > + /* according documentation the only possible error is ENOENT */ > + new_file = TRUE; > + } > + ... however using err variable here is rather pointless. Something like if (stat(...) < 0) new_file = TRUE; would have done the same trick here. Regards Marcel _______________________________________________ connman mailing list connman@connman.net http://lists.connman.net/listinfo/connman