ctdb-daemon: Consolidate interface checking with interface parsing
authorMartin Schwenke <martin@meltin.net>
Sat, 20 Aug 2016 10:34:33 +0000 (20:34 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 8 Sep 2016 04:57:20 +0000 (06:57 +0200)
There's no point parsing the interfaces twice, especially since it
doesn't improve error handling.

This also removes a use of strdup(3)/free(3), which is not generally
used in our code.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdb_takeover.c

index 0dbef03660cbedccf5654408eb0335818bcda366..3b2488bd4fae6e835154d56ce1acf605d5326972 100644 (file)
@@ -1058,17 +1058,7 @@ static int ctdb_add_public_address(struct ctdb_context *ctdb,
                }
        }
 
-       tmp = strdup(ifaces);
-       for (iface = strtok(tmp, ","); iface; iface = strtok(NULL, ",")) {
-               if (!ctdb_sys_check_iface_exists(iface)) {
-                       DEBUG(DEBUG_CRIT,("Interface %s does not exist. Can not add public-address : %s\n", iface, ctdb_addr_to_str(addr)));
-                       free(tmp);
-                       return -1;
-               }
-       }
-       free(tmp);
-
-       /* create a new vnn structure for this ip address */
+       /* Create a new VNN structure for this IP address */
        vnn = talloc_zero(ctdb, struct ctdb_vnn);
        if (vnn == NULL) {
                DEBUG(DEBUG_ERR, (__location__ " out of memory\n"));
@@ -1087,6 +1077,13 @@ static int ctdb_add_public_address(struct ctdb_context *ctdb,
                return -1;
        }
        for (iface = strtok(tmp, ","); iface; iface = strtok(NULL, ",")) {
+               if (!ctdb_sys_check_iface_exists(iface)) {
+                       DEBUG(DEBUG_ERR,
+                             ("Unknown interface %s for public address %s\n",
+                              iface, ctdb_addr_to_str(addr)));
+                       talloc_free(vnn);
+                       return -1;
+               }
                vnn->ifaces = talloc_realloc(vnn, vnn->ifaces, const char *, num + 2);
                if (vnn->ifaces == NULL) {
                        DEBUG(DEBUG_ERR, (__location__ " out of memory\n"));