aboutsummaryrefslogtreecommitdiff
path: root/src/os_unix.c
diff options
context:
space:
mode:
authordan <Dan Kennedy>2021-11-19 14:02:43 +0000
committerdan <Dan Kennedy>2021-11-19 14:02:43 +0000
commitd9137e3be0321774dd759340edd3d5d552b4f7ea (patch)
treefc7f356d627d230c978a0032c72fb29c3d3c37d5 /src/os_unix.c
parent5e90794b67e8c683d6b4c7175240dcfd4379829e (diff)
downloadsqlite-d9137e3be0321774dd759340edd3d5d552b4f7ea.tar.gz
sqlite-d9137e3be0321774dd759340edd3d5d552b4f7ea.zip
Fix a benign data race in os_unix.c that might trouble tsan and similar tools.
FossilOrigin-Name: 95806ac1dabe4598170061d903ae30f09bafac149ff6696963a7e056ac846cdb
Diffstat (limited to 'src/os_unix.c')
-rw-r--r--src/os_unix.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index 0e184af3c..cd619f5c0 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -5799,24 +5799,34 @@ static int fillInUnixFile(
}
/*
+** Directories to consider for temp files.
+*/
+static const char *azTempDirs[] = {
+ 0,
+ 0,
+ "/var/tmp",
+ "/usr/tmp",
+ "/tmp",
+ "."
+};
+
+/*
+** Initialize first two members of azTempDirs[] array.
+*/
+static void unixTempFileInit(void){
+ azTempDirs[0] = getenv("SQLITE_TMPDIR");
+ azTempDirs[1] = getenv("TMPDIR");
+}
+
+/*
** Return the name of a directory in which to put temporary files.
** If no suitable temporary file directory can be found, return NULL.
*/
static const char *unixTempFileDir(void){
- static const char *azDirs[] = {
- 0,
- 0,
- "/var/tmp",
- "/usr/tmp",
- "/tmp",
- "."
- };
unsigned int i = 0;
struct stat buf;
const char *zDir = sqlite3_temp_directory;
- if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
- if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
while(1){
if( zDir!=0
&& osStat(zDir, &buf)==0
@@ -5825,8 +5835,8 @@ static const char *unixTempFileDir(void){
){
return zDir;
}
- if( i>=sizeof(azDirs)/sizeof(azDirs[0]) ) break;
- zDir = azDirs[i++];
+ if( i>=sizeof(azTempDirs)/sizeof(azTempDirs[0]) ) break;
+ zDir = azTempDirs[i++];
}
return 0;
}
@@ -8098,6 +8108,9 @@ int sqlite3_os_init(void){
assert( UNIX_SHM_DMS==128 ); /* Byte offset of the deadman-switch */
#endif
+ /* Initialize temp file dir array. */
+ unixTempFileInit();
+
return SQLITE_OK;
}