summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Brown <jeffbrown@android.com>2013-02-07 03:45:18 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2013-02-07 03:45:18 +0000
commit6bbf67c11ea1b7e8e9769113072c167e822fe73f (patch)
tree7183ee85002554d3e51755622e63b8c6c3026863
parent88d4c1f4ff598414ed48fda264178a2865b352b3 (diff)
parent6ab557bdc070f11db30ede0696888efd19800475 (diff)
downloadsqlite-jb-mr1-dev-plus-aosp.tar.gz
Merge changes Ieecda65d,Idf3cbdabjb-mr1-dev-plus-aosp
* changes: Fix bugs of database corruption following IO error on systems supporting atomic-write Fix bugs of sqlite that returns SIGBUS on disk full in WAL mode
-rw-r--r--dist/sqlite3.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/dist/sqlite3.c b/dist/sqlite3.c
index 8cdf8de..a43031b 100644
--- a/dist/sqlite3.c
+++ b/dist/sqlite3.c
@@ -24853,6 +24853,13 @@ SQLITE_API int sqlite3_os_end(void){
*/
#if SQLITE_OS_UNIX /* This file is used on unix only */
+/* Use posix_fallocate() if it is available
+*/
+#if !defined(HAVE_POSIX_FALLOCATE) \
+ && (_XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L)
+# define HAVE_POSIX_FALLOCATE 1
+#endif
+
/*
** There are various methods for file locking used for concurrency
** control:
@@ -29091,11 +29098,19 @@ static int unixShmMap(
** the requested memory region.
*/
if( !bExtend ) goto shmpage_out;
+#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
+ if( osFallocate(pShmNode->h, sStat.st_size, nByte)!=0 ){
+ rc = unixLogError(SQLITE_FULL, "fallocate",
+ pShmNode->zFilename);
+ goto shmpage_out;
+ }
+#else
if( robust_ftruncate(pShmNode->h, nByte) ){
rc = unixLogError(SQLITE_IOERR_SHMSIZE, "ftruncate",
pShmNode->zFilename);
goto shmpage_out;
}
+#endif
}
}
@@ -72599,6 +72614,14 @@ static int createFile(JournalFile *p){
assert(p->iSize<=p->nBuf);
rc = sqlite3OsWrite(p->pReal, p->zBuf, p->iSize, 0);
}
+ if( rc!=SQLITE_OK ){
+ /* If an error occurred while writing to the file, close it before
+ ** returning. This way, SQLite uses the in-memory journal data to
+ ** roll back changes made to the internal page-cache before this
+ ** function was called. */
+ sqlite3OsClose(pReal);
+ p->pReal = 0;
+ }
}
}
return rc;