From 43ec064fb940d951cab124302b0ac6a226ae09a4 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sun, 14 Jul 2019 18:20:51 -0700 Subject: [PATCH] Expand error checking to all pthread_mutex_t --- src/curl.cpp | 25 ++++++++++++++++++++----- src/fdcache.cpp | 11 ++++++++--- src/openssl_auth.cpp | 14 ++++++++++++-- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/curl.cpp b/src/curl.cpp index 4a05ebf..f776490 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -236,7 +236,12 @@ const char* BodyData::str() const //------------------------------------------------------------------- bool CurlHandlerPool::Init() { - if (0 != pthread_mutex_init(&mLock, NULL)) { + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); +#if S3FS_PTHREAD_ERRORCHECK + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); +#endif + if (0 != pthread_mutex_init(&mLock, &attr)) { S3FS_PRN_ERR("Init curl handlers lock failed"); return false; } @@ -388,13 +393,18 @@ bool S3fsCurl::is_use_session_token = false; // default //------------------------------------------------------------------- bool S3fsCurl::InitS3fsCurl(const char* MimeFile) { - if(0 != pthread_mutex_init(&S3fsCurl::curl_handles_lock, NULL)){ + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); +#if S3FS_PTHREAD_ERRORCHECK + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); +#endif + if(0 != pthread_mutex_init(&S3fsCurl::curl_handles_lock, &attr)){ return false; } - if(0 != pthread_mutex_init(&S3fsCurl::curl_share_lock[SHARE_MUTEX_DNS], NULL)){ + if(0 != pthread_mutex_init(&S3fsCurl::curl_share_lock[SHARE_MUTEX_DNS], &attr)){ return false; } - if(0 != pthread_mutex_init(&S3fsCurl::curl_share_lock[SHARE_MUTEX_SSL_SESSION], NULL)){ + if(0 != pthread_mutex_init(&S3fsCurl::curl_share_lock[SHARE_MUTEX_SSL_SESSION], &attr)){ return false; } if(!S3fsCurl::InitMimeType(MimeFile)){ @@ -3982,7 +3992,12 @@ S3fsMultiCurl::S3fsMultiCurl(int maxParallelism) , RetryCallback(NULL) { int res; - if (0 != (res = pthread_mutex_init(&completed_tids_lock, NULL))) { + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); +#if S3FS_PTHREAD_ERRORCHECK + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); +#endif + if (0 != (res = pthread_mutex_init(&completed_tids_lock, &attr))) { S3FS_PRN_ERR("could not initialize completed_tids_lock: %i", res); } } diff --git a/src/fdcache.cpp b/src/fdcache.cpp index f9483df..8696aad 100644 --- a/src/fdcache.cpp +++ b/src/fdcache.cpp @@ -2046,10 +2046,15 @@ bool FdManager::IsSafeDiskSpace(const char* path, off_t size) FdManager::FdManager() { if(this == FdManager::get()){ + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); +#if S3FS_PTHREAD_ERRORCHECK + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); +#endif try{ - pthread_mutex_init(&FdManager::fd_manager_lock, NULL); - pthread_mutex_init(&FdManager::cache_cleanup_lock, NULL); - pthread_mutex_init(&FdManager::reserved_diskspace_lock, NULL); + pthread_mutex_init(&FdManager::fd_manager_lock, &attr); + pthread_mutex_init(&FdManager::cache_cleanup_lock, &attr); + pthread_mutex_init(&FdManager::reserved_diskspace_lock, &attr); FdManager::is_lock_init = true; }catch(exception& e){ FdManager::is_lock_init = false; diff --git a/src/openssl_auth.cpp b/src/openssl_auth.cpp index 92595ce..6e7be01 100644 --- a/src/openssl_auth.cpp +++ b/src/openssl_auth.cpp @@ -106,7 +106,12 @@ static struct CRYPTO_dynlock_value* s3fs_dyn_crypt_mutex(const char* file, int l static struct CRYPTO_dynlock_value* s3fs_dyn_crypt_mutex(const char* file, int line) { struct CRYPTO_dynlock_value* dyndata = new CRYPTO_dynlock_value(); - pthread_mutex_init(&(dyndata->dyn_mutex), NULL); + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); +#if S3FS_PTHREAD_ERRORCHECK + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); +#endif + pthread_mutex_init(&(dyndata->dyn_mutex), &attr); return dyndata; } @@ -141,8 +146,13 @@ bool s3fs_init_crypt_mutex() } } s3fs_crypt_mutex = new pthread_mutex_t[CRYPTO_num_locks()]; + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); +#if S3FS_PTHREAD_ERRORCHECK + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); +#endif for(int cnt = 0; cnt < CRYPTO_num_locks(); cnt++){ - pthread_mutex_init(&s3fs_crypt_mutex[cnt], NULL); + pthread_mutex_init(&s3fs_crypt_mutex[cnt], &attr); } // static lock CRYPTO_set_locking_callback(s3fs_crypt_mutex_lock);