Do not invoke usleep() for more than 999999 microseconds.

FossilOrigin-Name: 1f5ed852f25515bbc0a7aaf236fdef40fa7e31805eee1249277fde4e68f95130
This commit is contained in:
drh 2020-09-15 12:29:35 +00:00
parent 86f477edaa
commit ddcfe92105
4 changed files with 32 additions and 13 deletions

View File

@ -1,5 +1,5 @@
C Catch\sfts5\sindex\scorruption\scaused\sby\sissuing\s'delete'\scommands\swith\sincorrect\sdata\searlier\sin\ssome\scases.\sAlso\sfix\sa\scouple\sof\stest\sscript\sproblems.
D 2020-09-11T15:01:49.870
C Do\snot\sinvoke\susleep()\sfor\smore\sthan\s999999\smicroseconds.
D 2020-09-15T12:29:35.316
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -519,7 +519,7 @@ F src/os.c 80e4cf3e5da06be03ca641661e331ce60eeeeabf0d7354dbb1c0e166d0eedbbe
F src/os.h 48388821692e87da174ea198bf96b1b2d9d83be5dfc908f673ee21fafbe0d432
F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85
F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586
F src/os_unix.c 99a6ace048b97b0fa6cab3b9216b9e65c3f876095f2adb5adbce41fa1664bc92
F src/os_unix.c b16ae8f19de9fb91836164b8ff122c069d0b177179df7bb632cf41bf61308d89
F src/os_win.c a2149ff0a85c1c3f9cc102a46c673ce87e992396ba3411bfb53db66813b32f1d
F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
F src/pager.c 3700a1c55427a3d4168ad1f1b8a8b0cb9ace1d107e4506e30a8f1e66d8a1195e
@ -536,7 +536,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
F src/resolve.c 97b91fb25d86881ff20c9ad2ad98412c6c1bb5f7d6c9bb044db250cbc9cfcd4b
F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
F src/select.c 233e884d7da6601486c7b93aedb97fd29302ae5c03742d0e0eccb4790638bb77
F src/shell.c.in a53743f2f44c59675baa9d7b2e1398e80b2913c752686a40d9c172372368113b
F src/shell.c.in 0fd9eca42731d94a293d7b12a76c6614976f8bdbb2874768ad2e6ddbb86dffd8
F src/sqlite.h.in 11896ccb28f85b0aa52f0d4169aaca0ed7cf3f9b3e0c544aecee0032ae2b3c2e
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 2d1af80082edffd71c6f96f70ad1ce6a4fb46615ad10291fc77fe0dea9ff0197
@ -1880,7 +1880,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 6d1ab0403c2855b595f5d294305f41f56a7a93503f2a58d1b1d12431d480704e
R a38b48cd74aa4d6bef7f94508a082c8f
U dan
Z 193f568f2cae72499a3bb6bc16e95901
P b79f19edfd33c2a75f936c352668e14e81f35acf4f07edc27a21f941a7304b38
R 02ff44ae0857613afbe5632caeb73c7f
U drh
Z dea6a3dde210fb6493351086dc86d60e

View File

@ -1 +1 @@
b79f19edfd33c2a75f936c352668e14e81f35acf4f07edc27a21f941a7304b38
1f5ed852f25515bbc0a7aaf236fdef40fa7e31805eee1249277fde4e68f95130

View File

@ -1545,6 +1545,9 @@ static int unixCheckReservedLock(sqlite3_file *id, int *pResOut){
return rc;
}
/* Forward declaration*/
static int unixSleep(sqlite3_vfs*,int);
/*
** Set a posix-advisory-lock.
**
@ -1574,7 +1577,7 @@ static int osSetPosixAdvisoryLock(
** 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. */
usleep(1000);
unixSleep(0,1000);
rc = osFcntl(h,F_SETLK,pLock);
tm--;
}
@ -6576,7 +6579,8 @@ static int unixSleep(sqlite3_vfs *NotUsed, int microseconds){
UNUSED_PARAMETER(NotUsed);
return microseconds;
#elif defined(HAVE_USLEEP) && HAVE_USLEEP
usleep(microseconds);
if( microseconds>=1000000 ) sleep(microseconds/1000000);
if( microseconds%1000000 ) usleep(microseconds%1000000);
UNUSED_PARAMETER(NotUsed);
return microseconds;
#else
@ -7149,7 +7153,7 @@ static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){
if( nTries==1 ){
conchModTime = buf.st_mtimespec;
usleep(500000); /* wait 0.5 sec and try the lock again*/
unixSleep(0,500000); /* wait 0.5 sec and try the lock again*/
continue;
}
@ -7175,7 +7179,7 @@ static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){
/* don't break the lock on short read or a version mismatch */
return SQLITE_BUSY;
}
usleep(10000000); /* wait 10 sec and try the lock again */
unixSleep(0,10000000); /* wait 10 sec and try the lock again */
continue;
}

View File

@ -4425,6 +4425,19 @@ static void shellIdQuote(
}
}
/*
** Scalar function "usleep(X)" invokes sqlite3_sleep(X) and returns X.
*/
static void shellUSleepFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
int sleep = sqlite3_value_int(argv[0]);
sqlite3_sleep(sleep/1000);
sqlite3_result_int(context, sleep);
}
/*
** Scalar function "shell_escape_crnl" used by the .recover command.
** The argument passed to this function is the output of built-in
@ -4609,6 +4622,8 @@ static void open_db(ShellState *p, int openFlags){
shellInt32, 0, 0);
sqlite3_create_function(p->db, "shell_idquote", 1, SQLITE_UTF8, 0,
shellIdQuote, 0, 0);
sqlite3_create_function(p->db, "usleep",1,SQLITE_UTF8,0,
shellUSleepFunc, 0, 0);
#ifndef SQLITE_NOHAVE_SYSTEM
sqlite3_create_function(p->db, "edit", 1, SQLITE_UTF8, 0,
editFunc, 0, 0);