Fix static analysis issue 13/271813/1
authorJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 2 Mar 2022 01:38:44 +0000 (10:38 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 2 Mar 2022 01:38:44 +0000 (10:38 +0900)
Change-Id: I23eec4277dcdd6519f9dd0b05b16f24dddb9b857
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/utils/file_logbackend.cc

index 279e7f5..b4f0222 100644 (file)
@@ -62,13 +62,15 @@ void FileLogBackend::WriteLogToFile() {
 bool FileLogBackend::Rotate() {
   std::string logdir = GetLogDir();
   int dirfd = open(logdir.c_str(), O_DIRECTORY);
+
+  if (dirfd < 0) {
+    LOG(ERROR) << "Failed to open dir(" << logdir << "), errno : " << errno;
+    return false;
+  }
+
   for (int i = max_rotation_; i > 0; i--) {
     std::string old_log = GetFileName() + "." + std::to_string(i);
 
-    if (dirfd < 0) {
-      LOG(ERROR) << "Failed to open dir(" << logdir << "), errno : " << errno;
-      return false;
-    }
     struct stat tmp_buffer;
     if (fstatat(dirfd, old_log.c_str(), &tmp_buffer, 0) != 0)
       continue;