mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-06-05 02:20:51 +00:00
Replace miscellaneous pointers with unique_ptr
This commit is contained in:
parent
e3b50ad3e1
commit
24014bd1db
|
@ -36,7 +36,7 @@ constexpr char S3fsLog::MSGTIMESTAMP[];
|
|||
S3fsLog* S3fsLog::pSingleton = nullptr;
|
||||
S3fsLog::s3fs_log_level S3fsLog::debug_level = S3fsLog::LEVEL_CRIT;
|
||||
FILE* S3fsLog::logfp = nullptr;
|
||||
std::string* S3fsLog::plogfile = nullptr;
|
||||
std::string S3fsLog::logfile;
|
||||
bool S3fsLog::time_stamp = true;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
@ -86,11 +86,11 @@ bool S3fsLog::ReopenLogfile()
|
|||
S3FS_PRN_INFO("Currently the log file is output to stdout/stderr.");
|
||||
return true;
|
||||
}
|
||||
if(!S3fsLog::plogfile){
|
||||
S3FS_PRN_ERR("There is a problem with the path to the log file being nullptr.");
|
||||
if(!S3fsLog::logfile.empty()){
|
||||
S3FS_PRN_ERR("There is a problem with the path to the log file being empty.");
|
||||
return false;
|
||||
}
|
||||
std::string tmp = *(S3fsLog::plogfile);
|
||||
std::string tmp = S3fsLog::logfile;
|
||||
return S3fsLog::pSingleton->LowSetLogfile(tmp.c_str());
|
||||
}
|
||||
|
||||
|
@ -141,12 +141,9 @@ S3fsLog::~S3fsLog()
|
|||
FILE* oldfp = S3fsLog::logfp;
|
||||
S3fsLog::logfp = nullptr;
|
||||
if(oldfp && 0 != fclose(oldfp)){
|
||||
S3FS_PRN_ERR("Could not close old log file(%s), but continue...", (S3fsLog::plogfile ? S3fsLog::plogfile->c_str() : "null"));
|
||||
}
|
||||
if(S3fsLog::plogfile){
|
||||
delete S3fsLog::plogfile;
|
||||
S3fsLog::plogfile = nullptr;
|
||||
S3FS_PRN_ERR("Could not close old log file(%s), but continue...", (S3fsLog::logfile.empty() ? S3fsLog::logfile.c_str() : "null"));
|
||||
}
|
||||
S3fsLog::logfile.clear();
|
||||
S3fsLog::pSingleton = nullptr;
|
||||
S3fsLog::debug_level = S3fsLog::LEVEL_CRIT;
|
||||
|
||||
|
@ -190,14 +187,11 @@ bool S3fsLog::LowSetLogfile(const char* pfile)
|
|||
if(!pfile){
|
||||
// close log file if it is opened
|
||||
if(S3fsLog::logfp && 0 != fclose(S3fsLog::logfp)){
|
||||
S3FS_PRN_ERR("Could not close log file(%s).", (S3fsLog::plogfile ? S3fsLog::plogfile->c_str() : "null"));
|
||||
S3FS_PRN_ERR("Could not close log file(%s).", (S3fsLog::logfile.empty() ? S3fsLog::logfile.c_str() : "null"));
|
||||
return false;
|
||||
}
|
||||
S3fsLog::logfp = nullptr;
|
||||
if(S3fsLog::plogfile){
|
||||
delete S3fsLog::plogfile;
|
||||
S3fsLog::plogfile = nullptr;
|
||||
}
|
||||
S3fsLog::logfile.clear();
|
||||
}else{
|
||||
// open new log file
|
||||
//
|
||||
|
@ -213,13 +207,12 @@ bool S3fsLog::LowSetLogfile(const char* pfile)
|
|||
// switch new log file and close old log file if it is opened
|
||||
FILE* oldfp = S3fsLog::logfp;
|
||||
if(oldfp && 0 != fclose(oldfp)){
|
||||
S3FS_PRN_ERR("Could not close old log file(%s).", (S3fsLog::plogfile ? S3fsLog::plogfile->c_str() : "null"));
|
||||
S3FS_PRN_ERR("Could not close old log file(%s).", (!S3fsLog::logfile.empty() ? S3fsLog::logfile.c_str() : "null"));
|
||||
fclose(newfp);
|
||||
return false;
|
||||
}
|
||||
S3fsLog::logfp = newfp;
|
||||
delete S3fsLog::plogfile;
|
||||
S3fsLog::plogfile = new std::string(pfile);
|
||||
S3fsLog::logfile = pfile;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ class S3fsLog
|
|||
static S3fsLog* pSingleton;
|
||||
static s3fs_log_level debug_level;
|
||||
static FILE* logfp;
|
||||
static std::string* plogfile;
|
||||
static std::string logfile;
|
||||
static bool time_stamp;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
//-------------------------------------------------------------------
|
||||
// Class S3fsSignals
|
||||
//-------------------------------------------------------------------
|
||||
S3fsSignals* S3fsSignals::pSingleton = nullptr;
|
||||
std::unique_ptr<S3fsSignals> S3fsSignals::pSingleton;
|
||||
bool S3fsSignals::enableUsr1 = false;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
@ -38,15 +38,14 @@ bool S3fsSignals::enableUsr1 = false;
|
|||
bool S3fsSignals::Initialize()
|
||||
{
|
||||
if(!S3fsSignals::pSingleton){
|
||||
S3fsSignals::pSingleton = new S3fsSignals;
|
||||
S3fsSignals::pSingleton.reset(new S3fsSignals);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool S3fsSignals::Destroy()
|
||||
{
|
||||
delete S3fsSignals::pSingleton;
|
||||
S3fsSignals::pSingleton = nullptr;
|
||||
S3fsSignals::pSingleton.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -168,7 +167,7 @@ bool S3fsSignals::InitHupHandler()
|
|||
//-------------------------------------------------------------------
|
||||
// Methods
|
||||
//-------------------------------------------------------------------
|
||||
S3fsSignals::S3fsSignals() : pThreadUsr1(nullptr), pSemUsr1(nullptr)
|
||||
S3fsSignals::S3fsSignals()
|
||||
{
|
||||
if(S3fsSignals::enableUsr1){
|
||||
if(!InitUsr1Handler()){
|
||||
|
@ -201,16 +200,14 @@ bool S3fsSignals::InitUsr1Handler()
|
|||
|
||||
// create thread
|
||||
int result;
|
||||
pSemUsr1 = new Semaphore(0);
|
||||
pThreadUsr1 = new pthread_t;
|
||||
if(0 != (result = pthread_create(pThreadUsr1, nullptr, S3fsSignals::CheckCacheWorker, static_cast<void*>(pSemUsr1)))){
|
||||
std::unique_ptr<Semaphore> pSemUsr1_tmp(new Semaphore(0));
|
||||
std::unique_ptr<pthread_t> pThreadUsr1_tmp(new pthread_t);
|
||||
if(0 != (result = pthread_create(pThreadUsr1.get(), nullptr, S3fsSignals::CheckCacheWorker, static_cast<void*>(pSemUsr1_tmp.get())))){
|
||||
S3FS_PRN_ERR("Could not create thread for SIGUSR1 by %d", result);
|
||||
delete pSemUsr1;
|
||||
delete pThreadUsr1;
|
||||
pSemUsr1 = nullptr;
|
||||
pThreadUsr1 = nullptr;
|
||||
return false;
|
||||
}
|
||||
pSemUsr1 = std::move(pSemUsr1_tmp);
|
||||
pThreadUsr1 = std::move(pThreadUsr1_tmp);
|
||||
|
||||
// set handler
|
||||
struct sigaction sa;
|
||||
|
@ -244,10 +241,8 @@ bool S3fsSignals::DestroyUsr1Handler()
|
|||
S3FS_PRN_ERR("Could not stop thread for SIGUSR1 by %d", result);
|
||||
return false;
|
||||
}
|
||||
delete pSemUsr1;
|
||||
delete pThreadUsr1;
|
||||
pSemUsr1 = nullptr;
|
||||
pThreadUsr1 = nullptr;
|
||||
pSemUsr1.reset();
|
||||
pThreadUsr1.reset();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#ifndef S3FS_SIGHANDLERS_H_
|
||||
#define S3FS_SIGHANDLERS_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
class Semaphore;
|
||||
|
||||
//----------------------------------------------
|
||||
|
@ -29,14 +31,14 @@ class Semaphore;
|
|||
class S3fsSignals
|
||||
{
|
||||
private:
|
||||
static S3fsSignals* pSingleton;
|
||||
static std::unique_ptr<S3fsSignals> pSingleton;
|
||||
static bool enableUsr1;
|
||||
|
||||
pthread_t* pThreadUsr1;
|
||||
Semaphore* pSemUsr1;
|
||||
std::unique_ptr<pthread_t> pThreadUsr1;
|
||||
std::unique_ptr<Semaphore> pSemUsr1;
|
||||
|
||||
protected:
|
||||
static S3fsSignals* get() { return pSingleton; }
|
||||
static S3fsSignals* get() { return pSingleton.get(); }
|
||||
|
||||
static void HandlerUSR1(int sig);
|
||||
static void* CheckCacheWorker(void* arg);
|
||||
|
@ -48,7 +50,6 @@ class S3fsSignals
|
|||
static bool InitHupHandler();
|
||||
|
||||
S3fsSignals();
|
||||
~S3fsSignals();
|
||||
S3fsSignals(const S3fsSignals&) = delete;
|
||||
S3fsSignals(S3fsSignals&&) = delete;
|
||||
S3fsSignals& operator=(const S3fsSignals&) = delete;
|
||||
|
@ -59,6 +60,7 @@ class S3fsSignals
|
|||
bool WakeupUsr1Thread();
|
||||
|
||||
public:
|
||||
~S3fsSignals();
|
||||
static bool Initialize();
|
||||
static bool Destroy();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user