From e61947e9292f6a0d7c50762c367e8a770974089e Mon Sep 17 00:00:00 2001 From: tianbin <418940240@qq.com> Date: Wed, 16 Apr 2025 20:29:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A5=E5=BF=97=E5=8E=8B?= =?UTF-8?q?=E7=BC=A9=E6=96=87=E4=BB=B6=E6=9D=83=E9=99=90=E4=B8=8E=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=9D=83=E9=99=90=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cm_agent/cma_log_management.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/cm_agent/cma_log_management.cpp b/src/cm_agent/cma_log_management.cpp index 12bbdb8..e5e7206 100644 --- a/src/cm_agent/cma_log_management.cpp +++ b/src/cm_agent/cma_log_management.cpp @@ -282,11 +282,22 @@ void groupByDirectoryAndPattern(LogFile* logFile, LogFile* sortLogFile, const ch for (uint32 jj = 0; jj < (uint32)(cnt - 1); jj++) { rc = snprintf_s(outpath, MAX_PATH_LEN, MAX_PATH_LEN - 1, "%s%s", sortLogFile[jj].fileName, ".gz"); securec_check_intval(rc, (void)rc); + + struct stat orig_stat; + mode_t orig_mode = 0; + if (stat(sortLogFile[jj].fileName, &orig_stat) == 0) { + // Get original file permissions + orig_mode = orig_stat.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); + } else { + write_runlog(WARNING, "Cannot get file mode for %s, use default\n", sortLogFile[jj].fileName); + // Default permissions: 644 + orig_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; + } if (GZCompress(sortLogFile[jj].fileName, MAX_PATH_LEN, outpath, MAX_PATH_LEN) == 0) { write_runlog(LOG, "Compressed log file, file name: %s\n", sortLogFile[jj].fileName); ++numCompressed; - /* Compress successful then remove the source trace, and chmod */ - (void)chmod(outpath, S_IRUSR); + /* Compress successful then remove the source trace, and change the file permissions */ + (void)chmod(outpath, orig_mode); delLogFile(sortLogFile[jj].fileName); } } -- Gitee