From a93846e9008e016257e3a8c7d4a755a5e6b30081 Mon Sep 17 00:00:00 2001 From: shenchenkai Date: Sat, 18 Dec 2021 16:31:43 +0800 Subject: [PATCH] Description:[feature] enhance recoverability Change-Id: I575c0ed7d250e0f6893b7980a6eba7a7a9b1b107 Signed-off-by: shenchenkai --- hiview_file.c | 19 ++++--------------- hiview_util.c | 25 ++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/hiview_file.c b/hiview_file.c index 438f6cd..00b6aa5 100755 --- a/hiview_file.c +++ b/hiview_file.c @@ -16,6 +16,7 @@ #include "hiview_config.h" #include "hiview_def.h" #include "hiview_file.h" +#include "hiview_log.h" #include "hiview_util.h" #include "ohos_types.h" #include "securec.h" @@ -82,7 +83,7 @@ boolean InitHiviewFile(HiviewFile *fp, HiviewFileType type, uint32 size) pCommon->codeSubVersion = HIVIEW_FILE_HEADER_SUB_VERSION; pCommon->defineFileVersion = GetDefineFileVersion(pCommon->type); } - + HILOG_INFO(HILOG_MODULE_HIVIEW, "InitHiviewFile for type %d success", (int32)type); return TRUE; } @@ -207,21 +208,9 @@ uint32 GetFileFreeSize(HiviewFile *fp) int32 CloseHiviewFile(HiviewFile *fp) { if (fp != NULL && fp->fhandle > 0) { - if (strcmp(fp->outPath, HIVIEW_FILE_OUT_PATH_LOG) != 0) { - HIVIEW_MemFree(MEM_POOL_HIVIEW_ID, fp->outPath); - fp->outPath = HIVIEW_FILE_OUT_PATH_LOG; - } else if (strcmp(fp->outPath, HIVIEW_FILE_OUT_PATH_UE_EVENT) != 0) { - HIVIEW_MemFree(MEM_POOL_HIVIEW_ID, fp->outPath); - fp->outPath = HIVIEW_FILE_OUT_PATH_UE_EVENT; - } else if (strcmp(fp->outPath, HIVIEW_FILE_OUT_PATH_FAULT_EVENT) != 0) { - HIVIEW_MemFree(MEM_POOL_HIVIEW_ID, fp->outPath); - fp->outPath = HIVIEW_FILE_OUT_PATH_FAULT_EVENT; - } else if (strcmp(fp->outPath, HIVIEW_FILE_OUT_PATH_STAT_EVENT) != 0) { - HIVIEW_MemFree(MEM_POOL_HIVIEW_ID, fp->outPath); - fp->outPath = HIVIEW_FILE_OUT_PATH_STAT_EVENT; - } int32 ret = HIVIEW_FileClose(fp->fhandle); fp->fhandle = -1; + UnRegisterFileWatcher(fp, NULL); return ret; } return -1; @@ -287,7 +276,7 @@ int IsValidPath(const char *path) void RegisterFileWatcher(HiviewFile *fp, FileProc func, const char *path) { - if (fp == NULL || func == NULL || path == NULL) { + if (fp == NULL || func == NULL) { return; } fp->pFunc = func; diff --git a/hiview_util.c b/hiview_util.c index a5e39c9..bfcbf3b 100755 --- a/hiview_util.c +++ b/hiview_util.c @@ -15,6 +15,7 @@ #include "hiview_util.h" +#include #include #include #include @@ -129,36 +130,58 @@ void HIVIEW_Sleep(uint32 ms) int32 HIVIEW_FileOpen(const char *path) { - return open(path, O_RDWR | O_CREAT, 0); + int32 handle = open(path, O_RDWR | O_CREAT, 0); + if (handle < 0) { + printf("HIVIEW_FileOpen %s fail, errno:%d\n", path, errno); + } + return handle; } int32 HIVIEW_FileClose(int32 handle) { + if (handle < 0) { + return -1; + } return close(handle); } int32 HIVIEW_FileRead(int32 handle, uint8 *buf, uint32 len) { + if (handle < 0) { + return -1; + } return read(handle, (char *)buf, len); } int32 HIVIEW_FileWrite(int32 handle, const uint8 *buf, uint32 len) { + if (handle < 0) { + return -1; + } return write(handle, (const char *)buf, len); } int32 HIVIEW_FileSeek(int32 handle, int32 offset, int32 whence) { + if (handle < 0) { + return -1; + } return lseek(handle, (off_t)offset, whence); } int32 HIVIEW_FileSize(int32 handle) { + if (handle < 0) { + return -1; + } return lseek(handle, 0, SEEK_END); } int32 HIVIEW_FileSync(int32 handle) { + if (handle < 0) { + return -1; + } return fsync(handle); } -- Gitee