diff --git a/services/hilogd/include/log_persister.h b/services/hilogd/include/log_persister.h index b8fcd421bb3ce72e844fed729c918ba3cdfd569c..8912badf8928cd94fd72fb19e8c472caed94d969 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 93929f6c42943776845d7fc059ff0dfcecb9bcdd..3c317daf8627a3417cfac4536f42840d1f0d1433 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 2a604e1ebdf2131a9edfe4a5bcdb889c7e85ee50..a3fee3fc1496e7fae5671ae1da1fe3a2ac346eba 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 1b19a39bda8611af5fef544e2fbd4a40c25016c4..1b956f03ded8f0eca425302486bb4f9b3d2916e0 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"},