]> git.proxmox.com Git - mirror_lxc.git/blobdiff - src/lxc/network.c
network: do not log false friends
[mirror_lxc.git] / src / lxc / network.c
index d7cc0f6d047d6b5159baf9a2e3a319c5a70a17fe..fd7d867fc58a74edafac5bc5026432c519244a56 100644 (file)
@@ -54,6 +54,7 @@
 #include "file_utils.h"
 #include "log.h"
 #include "macro.h"
+#include "memory_utils.h"
 #include "network.h"
 #include "nl.h"
 #include "raw_syscalls.h"
@@ -549,15 +550,15 @@ out:
 #define PHYSNAME "/sys/class/net/%s/phy80211/name"
 static char *is_wlan(const char *ifname)
 {
+       __do_free char *path;
        int i, ret;
        long physlen;
        size_t len;
-       char *path;
        FILE *f;
        char *physname = NULL;
 
        len = strlen(ifname) + strlen(PHYSNAME) - 1;
-       path = alloca(len + 1);
+       path = must_realloc(NULL, len + 1);
        ret = snprintf(path, len, PHYSNAME, ifname);
        if (ret < 0 || (size_t)ret >= len)
                goto bad;
@@ -1973,7 +1974,7 @@ char *lxc_mkifname(char *template)
        }
 
        /* Generate random names until we find one that doesn't exist. */
-       while (true) {
+       for (;;) {
                name[0] = '\0';
                (void)strlcpy(name, template, IFNAMSIZ);
 
@@ -1982,9 +1983,9 @@ char *lxc_mkifname(char *template)
                for (i = 0; i < strlen(name); i++) {
                        if (name[i] == 'X') {
 #ifdef HAVE_RAND_R
-                               name[i] = padchar[rand_r(&seed) % (strlen(padchar) - 1)];
+                               name[i] = padchar[rand_r(&seed) % strlen(padchar)];
 #else
-                               name[i] = padchar[rand() % (strlen(padchar) - 1)];
+                               name[i] = padchar[rand() % strlen(padchar)];
 #endif
                        }
                }
@@ -2116,8 +2117,6 @@ static int lxc_create_network_unpriv_exec(const char *lxcpath, const char *lxcna
        }
 
        if (child == 0) {
-               int ret;
-               size_t retlen;
                char pidstr[INTTYPE_TO_STRLEN(pid_t)];
 
                close(pipefd[0]);
@@ -2280,7 +2279,6 @@ static int lxc_delete_network_unpriv_exec(const char *lxcpath, const char *lxcna
 
        if (child == 0) {
                char *hostveth;
-               int ret;
 
                close(pipefd[0]);
 
@@ -2421,7 +2419,7 @@ bool lxc_delete_network_unpriv(struct lxc_handler *handler)
                     netdev->link);
 
 clear_ifindices:
-               /* We need to clear any ifindeces we recorded so liblxc won't
+               /* We need to clear any ifindices we recorded so liblxc won't
                 * have cached stale data which would cause it to fail on reboot
                 * we're we don't re-read the on-disk config file.
                 */
@@ -2583,10 +2581,9 @@ bool lxc_delete_network_priv(struct lxc_handler *handler)
                             netdev->name[0] != '\0' ? netdev->name : "(null)",
                             netdev->ifindex);
                } else if (ret < 0) {
-                       errno = -ret;
-                       SYSWARN("Failed to remove interface \"%s\" with index %d",
-                               netdev->name[0] != '\0' ? netdev->name : "(null)",
-                               netdev->ifindex);
+                       WARN("Failed to remove interface \"%s\" with index %d",
+                            netdev->name[0] != '\0' ? netdev->name : "(null)",
+                            netdev->ifindex);
                        goto clear_ifindices;
                }
                INFO("Removed interface \"%s\" with index %d",
@@ -2608,9 +2605,8 @@ bool lxc_delete_network_priv(struct lxc_handler *handler)
 
                ret = lxc_netdev_delete_by_name(hostveth);
                if (ret < 0) {
-                       errno = -ret;
-                       SYSWARN("Failed to remove interface \"%s\" from \"%s\"",
-                               hostveth, netdev->link);
+                       WARN("Failed to remove interface \"%s\" from \"%s\"",
+                            hostveth, netdev->link);
                        goto clear_ifindices;
                }
                INFO("Removed interface \"%s\" from \"%s\"", hostveth, netdev->link);
@@ -2632,7 +2628,7 @@ bool lxc_delete_network_priv(struct lxc_handler *handler)
                             hostveth, netdev->link);
 
 clear_ifindices:
-               /* We need to clear any ifindeces we recorded so liblxc won't
+               /* We need to clear any ifindices we recorded so liblxc won't
                 * have cached stale data which would cause it to fail on reboot
                 * we're we don't re-read the on-disk config file.
                 */
@@ -2925,8 +2921,6 @@ static int lxc_setup_netdev_in_child_namespaces(struct lxc_netdev *netdev)
 
        /* set the network device up */
        if (netdev->flags & IFF_UP) {
-               int err;
-
                err = lxc_netdev_up(current_ifname);
                if (err) {
                        errno = -err;
@@ -3131,7 +3125,7 @@ int lxc_network_send_name_and_ifindex_to_parent(struct lxc_handler *handler)
                        return -1;
        }
 
-       TRACE("Sent network device names and ifindeces to parent");
+       TRACE("Sent network device names and ifindices to parent");
        return 0;
 }