You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2017/05/17 21:05:16 UTC

[trafficserver] branch master updated: Various Coverity fixes for logstats

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

The following commit(s) were added to refs/heads/master by this push:
       new  430993b   Various Coverity fixes for logstats
430993b is described below

commit 430993be0d97c912135e8b82fa01f4c28b884959
Author: Leif Hedstrom <zw...@apache.org>
AuthorDate: Wed May 17 13:06:42 2017 -0600

    Various Coverity fixes for logstats
    
    	Coverity 1199997
    	Coverity 1200000
    	Coverity 1200003
    	Coverity 1200012
---
 proxy/hdrs/HTTP.h |  3 ++-
 proxy/logstats.cc | 71 +++++++++++++++++++++++++++++--------------------------
 2 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/proxy/hdrs/HTTP.h b/proxy/hdrs/HTTP.h
index e32704e..b4eb236 100644
--- a/proxy/hdrs/HTTP.h
+++ b/proxy/hdrs/HTTP.h
@@ -103,7 +103,8 @@ enum HTTPWarningCode {
   HTTP_WARNING_CODE_MISC_WARNING           = 199
 };
 
-/* squild log codes */
+/* squild log codes
+   There is code (e.g. logstats) that depends on these errors coming at the end of this enum */
 enum SquidLogCode {
   SQUID_LOG_EMPTY                     = '0',
   SQUID_LOG_TCP_HIT                   = '1',
diff --git a/proxy/logstats.cc b/proxy/logstats.cc
index f2f31c7..d95dccf 100644
--- a/proxy/logstats.cc
+++ b/proxy/logstats.cc
@@ -904,22 +904,6 @@ update_results_elapsed(OriginStats *stat, int result, int elapsed, int size)
     update_elapsed(stat->elapsed.misses.refresh, elapsed, stat->results.misses.refresh);
     update_elapsed(stat->elapsed.misses.total, elapsed, stat->results.misses.total);
     break;
-  case SQUID_LOG_ERR_CLIENT_ABORT:
-    update_counter(stat->results.errors.client_abort, size);
-    update_counter(stat->results.errors.total, size);
-    break;
-  case SQUID_LOG_ERR_CONNECT_FAIL:
-    update_counter(stat->results.errors.connect_fail, size);
-    update_counter(stat->results.errors.total, size);
-    break;
-  case SQUID_LOG_ERR_INVALID_REQ:
-    update_counter(stat->results.errors.invalid_req, size);
-    update_counter(stat->results.errors.total, size);
-    break;
-  case SQUID_LOG_ERR_UNKNOWN:
-    update_counter(stat->results.errors.unknown, size);
-    update_counter(stat->results.errors.total, size);
-    break;
   case SQUID_LOG_TCP_DISK_HIT:
   case SQUID_LOG_TCP_REF_FAIL_HIT:
   case SQUID_LOG_UDP_HIT:
@@ -938,12 +922,29 @@ update_results_elapsed(OriginStats *stat, int result, int elapsed, int size)
     update_elapsed(stat->elapsed.misses.other, elapsed, stat->results.misses.other);
     update_elapsed(stat->elapsed.misses.total, elapsed, stat->results.misses.total);
     break;
+  case SQUID_LOG_ERR_CLIENT_ABORT:
+    update_counter(stat->results.errors.client_abort, size);
+    update_counter(stat->results.errors.total, size);
+    break;
+  case SQUID_LOG_ERR_CONNECT_FAIL:
+    update_counter(stat->results.errors.connect_fail, size);
+    update_counter(stat->results.errors.total, size);
+    break;
+  case SQUID_LOG_ERR_INVALID_REQ:
+    update_counter(stat->results.errors.invalid_req, size);
+    update_counter(stat->results.errors.total, size);
+    break;
+  case SQUID_LOG_ERR_UNKNOWN:
+    update_counter(stat->results.errors.unknown, size);
+    update_counter(stat->results.errors.total, size);
+    break;
   default:
-    if ((result >= SQUID_LOG_ERR_READ_TIMEOUT) && (result <= SQUID_LOG_ERR_UNKNOWN)) {
+    // This depends on all errors being at the end of the enum ... Which is the case right now.
+    if (result < SQUID_LOG_ERR_READ_TIMEOUT) {
+      update_counter(stat->results.other, size);
+    } else {
       update_counter(stat->results.errors.other, size);
       update_counter(stat->results.errors.total, size);
-    } else {
-      update_counter(stat->results.other, size);
     }
     break;
   }
@@ -2358,7 +2359,9 @@ open_main_log(ExitStatus &status)
     return -1;
   }
 #if HAVE_POSIX_FADVISE
-  posix_fadvise(main_fd, 0, 0, POSIX_FADV_DONTNEED);
+  if (0 != posix_fadvise(main_fd, 0, 0, POSIX_FADV_DONTNEED)) {
+    status.append(" posix_fadvise() failed");
+  }
 #endif
   return main_fd;
 }
@@ -2629,7 +2632,9 @@ main(int /* argc ATS_UNUSED */, const char *argv[])
     }
     // flock(state_fd, LOCK_UN);
     lck.l_type = F_UNLCK;
-    fcntl(state_fd, F_SETLK, &lck);
+    if (fcntl(state_fd, F_SETLK, &lck) < 0) {
+      exit_status.set(EXIT_WARNING, " can't unlock state_fd ");
+    }
     close(main_fd);
     close(state_fd);
   } else {
@@ -2638,23 +2643,23 @@ main(int /* argc ATS_UNUSED */, const char *argv[])
       exit_status.set(EXIT_CRITICAL, " can't open log file ");
       exit_status.append(cl.log_file);
       my_exit(exit_status);
-    }
+    } else {
+      if (cl.tail > 0) {
+        if (lseek(main_fd, 0, SEEK_END) < 0) {
+          exit_status.set(EXIT_CRITICAL, " can't lseek squid.blog");
+          my_exit(exit_status);
+        }
+        sleep(cl.tail);
+      }
 
-    if (cl.tail > 0) {
-      if (lseek(main_fd, 0, SEEK_END) < 0) {
-        exit_status.set(EXIT_CRITICAL, " can't lseek squid.blog");
+      if (process_file(main_fd, 0, max_age) != 0) {
+        close(main_fd);
+        exit_status.set(EXIT_CRITICAL, " can't parse log file ");
+        exit_status.append(cl.log_file);
         my_exit(exit_status);
       }
-      sleep(cl.tail);
-    }
-
-    if (process_file(main_fd, 0, max_age) != 0) {
       close(main_fd);
-      exit_status.set(EXIT_CRITICAL, " can't parse log file ");
-      exit_status.append(cl.log_file);
-      my_exit(exit_status);
     }
-    close(main_fd);
   }
 
   // All done.

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].