diff --git a/hiview_file.c b/hiview_file.c index 438f6cde67368759556a33f194559eefbe282f16..00b6aa5872846e2ca396887510647107c2f16826 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 a5e39c9155a54bbc26c4c13315a9758505163ca9..bfcbf3ba279d44cc1baf91d9cf425a0153fa8b13 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); }