aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMitchell Wills <mwills@google.com>2015-08-25 00:24:30 (GMT)
committerJouni Malinen <j@w1.fi>2015-08-27 15:06:05 (GMT)
commita218e1ded44cc88072f4e1896fdd8bd24f1829ac (patch)
tree607da96fae809f1fa2b9dc719dc1c432e1bb8a87 /src
parent6aaa661af1acc65403ad6f5557f356bd623ba97b (diff)
downloadhostap-a218e1ded44cc88072f4e1896fdd8bd24f1829ac.zip
hostap-a218e1ded44cc88072f4e1896fdd8bd24f1829ac.tar.gz
hostap-a218e1ded44cc88072f4e1896fdd8bd24f1829ac.tar.bz2
Make sure configuration is saved to storage device
Config file is written to a temp file and then it is renamed to the original config file. However, it is possible that the rename operation will be commited to storage while file data will be still in cache causing original config file to be empty or partially written in case of a system reboot without a clean shutdown. Make this less likely to occur by forcing the data to be written to the storage device before renaming the file. Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/utils/os.h7
-rw-r--r--src/utils/os_internal.c6
-rw-r--r--src/utils/os_none.c6
-rw-r--r--src/utils/os_unix.c8
-rw-r--r--src/utils/os_win32.c18
5 files changed, 45 insertions, 0 deletions
diff --git a/src/utils/os.h b/src/utils/os.h
index 2c24631..9e496fb 100644
--- a/src/utils/os.h
+++ b/src/utils/os.h
@@ -247,6 +247,13 @@ char * os_readfile(const char *name, size_t *len);
int os_file_exists(const char *fname);
/**
+ * os_fdatasync - Sync a file's (for a given stream) state with storage device
+ * @stream: the stream to be flushed
+ * Returns: 0 if the operation succeeded or -1 on failure
+ */
+int os_fdatasync(FILE *stream);
+
+/**
* os_zalloc - Allocate and zero memory
* @size: Number of bytes to allocate
* Returns: Pointer to allocated and zeroed memory or %NULL on failure
diff --git a/src/utils/os_internal.c b/src/utils/os_internal.c
index 77733ad..ed6eb3c 100644
--- a/src/utils/os_internal.c
+++ b/src/utils/os_internal.c
@@ -243,6 +243,12 @@ char * os_readfile(const char *name, size_t *len)
}
+int os_fdatasync(FILE *stream)
+{
+ return 0;
+}
+
+
void * os_zalloc(size_t size)
{
void *n = os_malloc(size);
diff --git a/src/utils/os_none.c b/src/utils/os_none.c
index 83fe025..0c3214d 100644
--- a/src/utils/os_none.c
+++ b/src/utils/os_none.c
@@ -102,6 +102,12 @@ char * os_readfile(const char *name, size_t *len)
}
+int os_fdatasync(FILE *stream)
+{
+ return 0;
+}
+
+
void * os_zalloc(size_t size)
{
return NULL;
diff --git a/src/utils/os_unix.c b/src/utils/os_unix.c
index 089b880..4754dd7 100644
--- a/src/utils/os_unix.c
+++ b/src/utils/os_unix.c
@@ -418,6 +418,14 @@ int os_file_exists(const char *fname)
}
+int os_fdatasync(FILE *stream)
+{
+ if (!fflush(stream))
+ return fdatasync(fileno(stream));
+ return -1;
+}
+
+
#ifndef WPA_TRACE
void * os_zalloc(size_t size)
{
diff --git a/src/utils/os_win32.c b/src/utils/os_win32.c
index 296ea13..dea27b9 100644
--- a/src/utils/os_win32.c
+++ b/src/utils/os_win32.c
@@ -216,6 +216,24 @@ char * os_readfile(const char *name, size_t *len)
}
+int os_fdatasync(FILE *stream)
+{
+ HANDLE h;
+
+ if (stream == NULL)
+ return -1;
+
+ h = (HANDLE) _get_osfhandle(_fileno(stream));
+ if (h == INVALID_HANDLE_VALUE)
+ return -1;
+
+ if (!FlushFileBuffers(h))
+ return -1;
+
+ return 0;
+}
+
+
void * os_zalloc(size_t size)
{
return calloc(1, size);