From 7988e020b85a74fbeb22970d6b541e8e59a34d15 Mon Sep 17 00:00:00 2001 From: aajwy-gitee <13051180828@163.com> Date: Thu, 14 Oct 2021 02:54:16 +0000 Subject: [PATCH] =?UTF-8?q?=E8=90=BD=E7=9B=98=E8=B7=AF=E5=BE=84=E5=A6=82?= =?UTF-8?q?=E8=A2=AB=E5=88=A0=E9=99=A4=EF=BC=8C=E6=8F=90=E7=A4=BA=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=B7=AF=E5=BE=84=E4=B8=8D=E5=AD=98=E5=9C=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: aajwy <13051180828@163.com> --- services/hilogd/include/log_persister.h | 1 - services/hilogd/log_persister.cpp | 13 ++----------- services/hilogd/log_querier.cpp | 16 ++++++++++------ services/hilogtool/log_display.cpp | 2 +- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/services/hilogd/include/log_persister.h b/services/hilogd/include/log_persister.h index b8fcd42..8912bad 100644 --- a/services/hilogd/include/log_persister.h +++ b/services/hilogd/include/log_persister.h @@ -48,7 +48,6 @@ public: void Start(); bool Identify(uint32_t id); void FillInfo(LogPersistQueryResult *response); - int MkDirPath(const char *p_cMkdir); bool writeUnCompressedBuffer(HilogData *data); uint8_t GetType() const; std::string getPath(); diff --git a/services/hilogd/log_persister.cpp b/services/hilogd/log_persister.cpp index 93929f6..3c317da 100644 --- a/services/hilogd/log_persister.cpp +++ b/services/hilogd/log_persister.cpp @@ -101,9 +101,8 @@ int LogPersister::Init() } mmapPath = path.substr(0, nPos) + "/." + ANXILLARY_FILE_NAME + to_string(id); if (access(path.substr(0, nPos).c_str(), F_OK) != 0) { - if (errno == ENOENT) { - MkDirPath(path.substr(0, nPos).c_str()); - } + perror("persister directory does not exist."); + return ERR_LOG_PERSIST_FILE_PATH_INVALID; } bool hit = false; const lock_guard lock(g_listMutex); @@ -165,14 +164,6 @@ void LogPersister::NotifyForNewData() isNotified = true; } -int LogPersister::MkDirPath(const char *pMkdir) -{ - int isCreate = mkdir(pMkdir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRWXG | S_IRWXO); - if (!isCreate) - cout << "create path:" << pMkdir << endl; - return isCreate; -} - void LogPersister::SetBufferOffset(int off) { buffer->offset = off; diff --git a/services/hilogd/log_querier.cpp b/services/hilogd/log_querier.cpp index 2a604e1..a3fee3f 100644 --- a/services/hilogd/log_querier.cpp +++ b/services/hilogd/log_querier.cpp @@ -101,15 +101,19 @@ int JobLauncher(const LogPersistStartMsg& pMsg, const HilogBuffer& buffer, bool int rotatorRes = rotator->Init(); int saveInfoRes = rotator->SaveInfo(pMsg, persister->queryCondition); int persistRes = persister->Init(); - if (persistRes != 0 || saveInfoRes == RET_FAIL || rotatorRes == RET_FAIL) { + if (persistRes != 0) { cout << "LogPersister failed to initialize!" << endl; persister.reset(); - return RET_FAIL; - } else { - if (!restore) rotator->WriteRecoveryInfo(); - persister->Start(); - return RET_SUCCESS; + return persistRes; } + if (saveInfoRes == RET_FAIL || rotatorRes == RET_FAIL) { + cout << "LogPersister failed to initialize!" << endl; + persister.reset(); + return RET_FAIL; + } + if (!restore) rotator->WriteRecoveryInfo(); + persister->Start(); + return RET_SUCCESS; } void HandleLogQueryRequest(std::shared_ptr logReader, HilogBuffer& buffer) diff --git a/services/hilogtool/log_display.cpp b/services/hilogtool/log_display.cpp index 1b19a39..1b956f0 100644 --- a/services/hilogtool/log_display.cpp +++ b/services/hilogtool/log_display.cpp @@ -50,7 +50,7 @@ unordered_map errorMsg + to_string(MAX_PERSISTER_BUFFER_SIZE)}, {ERR_LOG_PERSIST_FILE_NAME_INVALID, "Invalid log persist file name, file name should not contain [\\/:*?\"<>|]"}, {ERR_LOG_PERSIST_COMPRESS_BUFFER_EXP, "Invalid Log persist compression buffer"}, - {ERR_LOG_PERSIST_FILE_PATH_INVALID, "Invalid persister file path"}, + {ERR_LOG_PERSIST_FILE_PATH_INVALID, "Invalid persister file path or persister directory does not exist"}, {ERR_LOG_PERSIST_COMPRESS_INIT_FAIL, "Log persist compression initialization failed"}, {ERR_LOG_PERSIST_FILE_OPEN_FAIL, "Log persist open file failed"}, {ERR_LOG_PERSIST_MMAP_FAIL, "Log persist mmap failed"}, -- Gitee