Fix non-static instances of "struct vlog_rate_limit" and add check.
authorBen Pfaff <blp@nicira.com>
Wed, 12 Jan 2011 17:22:12 +0000 (09:22 -0800)
committerBen Pfaff <blp@nicira.com>
Wed, 12 Jan 2011 17:22:12 +0000 (09:22 -0800)
A non-static vlog_rate_limit is not actually going to rate-limit anything.

Makefile.am
lib/dpif-netdev.c
lib/socket-util.c
ofproto/ofproto.c
vswitchd/ovs-brcompatd.c

index 689fd6c..deae512 100644 (file)
@@ -124,6 +124,17 @@ distfiles: Makefile
              -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t" | sort -u > $@
 CLEANFILES += distfiles
 
+# Check that "struct vlog_ratelimit" is always declared "static".
+ALL_LOCAL += rate-limit-check
+rate-limit-check:
+       @if test -e $(srcdir)/.git && (git --version) >/dev/null 2>&1 && \
+           git --no-pager grep -n -E '^[       ]+struct vlog_rate_limit.*=' $(srcdir); \
+         then \
+           echo "See above for list of violations of the rule that "; \
+           echo "'struct vlog_rate_limit' must always be 'static'"; \
+           exit 1; \
+        fi
+
 dist-hook: $(DIST_HOOKS)
 all-local: $(ALL_LOCAL)
 clean-local: $(CLEAN_LOCAL)
index a52accc..82d7d74 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010 Nicira Networks.
+ * Copyright (c) 2009, 2010, 2011 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -966,7 +966,7 @@ dp_netdev_run(void)
             if (!error) {
                 dp_netdev_port_input(dp, port, &packet);
             } else if (error != EAGAIN && error != EOPNOTSUPP) {
-                struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
+                static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
                 VLOG_ERR_RL(&rl, "error receiving data from %s: %s",
                             netdev_get_name(port->netdev), strerror(error));
             }
index f74e43b..e97e7c9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -114,7 +114,7 @@ int
 lookup_ip(const char *host_name, struct in_addr *addr)
 {
     if (!inet_aton(host_name, addr)) {
-        struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
+        static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
         VLOG_ERR_RL(&rl, "\"%s\" is not a valid IP address", host_name);
         return ENOENT;
     }
@@ -129,7 +129,7 @@ get_socket_error(int fd)
     int error;
     socklen_t len = sizeof(error);
     if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
-        struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 10);
+        static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 10);
         error = errno;
         VLOG_ERR_RL(&rl, "getsockopt(SO_ERROR): %s", strerror(error));
     }
index 6ebda01..52a1964 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010 Nicira Networks.
+ * Copyright (c) 2009, 2010, 2011 Nicira Networks.
  * Copyright (c) 2010 Jean Tourrilhes - HP-Labs.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -2681,7 +2681,7 @@ xlate_table_action(struct action_xlate_ctx *ctx, uint16_t in_port)
             ctx->recurse--;
         }
     } else {
-        struct vlog_rate_limit recurse_rl = VLOG_RATE_LIMIT_INIT(1, 1);
+        static struct vlog_rate_limit recurse_rl = VLOG_RATE_LIMIT_INIT(1, 1);
 
         VLOG_ERR_RL(&recurse_rl, "NXAST_RESUBMIT recursed over %d times",
                     MAX_RESUBMIT_RECURSION);
index bed2747..24b28a2 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008, 2009, 2010 Nicira Networks
+/* Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -917,7 +917,7 @@ handle_fdb_query_cmd(const struct ovsrec_open_vswitch *ovs,
         if (sscanf(line, "%d %d "ETH_ADDR_SCAN_FMT" %d",
                    &port, &vlan, ETH_ADDR_SCAN_ARGS(mac), &age)
             != 2 + ETH_ADDR_SCAN_COUNT + 1) {
-            struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
+            static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
             VLOG_INFO_RL(&rl, "fdb/show output has invalid format: %s", line);
             continue;
         }