aboutsummaryrefslogtreecommitdiff
path: root/src/os_unix.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2018-03-26 20:43:05 +0000
committerdrh <drh@noemail.net>2018-03-26 20:43:05 +0000
commitfd72563d0aaf09857ab37c38ff4ac0d3b5df92e6 (patch)
tree99eb2843aa103efa825b5328812214340f3872a2 /src/os_unix.c
parentf0119b2e1bfc0457b61d4b00d73bafef9274cf17 (diff)
downloadsqlite-fd72563d0aaf09857ab37c38ff4ac0d3b5df92e6.tar.gz
sqlite-fd72563d0aaf09857ab37c38ff4ac0d3b5df92e6.zip
Avoid a race condition that might cause a busy_timeout to last longer than
it should. FossilOrigin-Name: b81960561b47a1b49646f2f8870dd0684dc4ca7c0b9e11076fd713de66b75972
Diffstat (limited to 'src/os_unix.c')
-rw-r--r--src/os_unix.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index ac4ec2f2f..2b9c117e3 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -1490,18 +1490,15 @@ static int osSetPosixAdvisoryLock(
unixFile *pFile /* Structure holding timeout value */
){
int rc = osFcntl(h,F_SETLK,pLock);
- if( rc<0 && pFile->iBusyTimeout>0 ){
+ while( rc<0 && pFile->iBusyTimeout>0 ){
/* On systems that support some kind of blocking file lock with a timeout,
** make appropriate changes here to invoke that blocking file lock. On
** generic posix, however, there is no such API. So we simply try the
** lock once every millisecond until either the timeout expires, or until
** the lock is obtained. */
- do{
- usleep(1000);
- rc = osFcntl(h,F_SETLK,pLock);
- pFile->iBusyTimeout--;
- }while( rc<0 && pFile->iBusyTimeout>0 );
- pFile->iBusyTimeout = 0;
+ usleep(1000);
+ rc = osFcntl(h,F_SETLK,pLock);
+ pFile->iBusyTimeout--;
}
return rc;
}