]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxccontainer: cleanup do_lxcapi_get_interfaces()
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 29 Jul 2018 21:09:13 +0000 (23:09 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 10 Dec 2018 15:02:29 +0000 (16:02 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/lxccontainer.c

index 3685dc42a347054aebda6511ce2a4088ca483302..5464bd0aed9dd50373a25b90d82edfb3aabbdb50 100644 (file)
@@ -2043,21 +2043,19 @@ static bool remove_from_array(char ***names, char *cname, int size)
        return false;
 }
 
-static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
+static char **do_lxcapi_get_interfaces(struct lxc_container *c)
 {
        pid_t pid;
        int i, count = 0, pipefd[2];
        char **interfaces = NULL;
        char interface[IFNAMSIZ];
 
-       if(pipe(pipefd) < 0) {
-               SYSERROR("pipe failed");
+       if (pipe(pipefd) < 0)
                return NULL;
-       }
 
        pid = fork();
        if (pid < 0) {
-               SYSERROR("failed to fork task to get interfaces information");
+               SYSERROR("Failed to fork task to get interfaces information");
                close(pipefd[0]);
                close(pipefd[1]);
                return NULL;
@@ -2071,23 +2069,23 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
                close(pipefd[0]);
 
                if (!enter_net_ns(c)) {
-                       SYSERROR("failed to enter namespace");
+                       SYSERROR("Failed to enter network namespace");
                        goto out;
                }
 
                /* Grab the list of interfaces */
                if (getifaddrs(&interfaceArray)) {
-                       SYSERROR("failed to get interfaces list");
+                       SYSERROR("Failed to get interfaces list");
                        goto out;
                }
 
                /* Iterate through the interfaces */
-               for (tempIfAddr = interfaceArray; tempIfAddr != NULL; tempIfAddr = tempIfAddr->ifa_next) {
+               for (tempIfAddr = interfaceArray; tempIfAddr != NULL;
+                    tempIfAddr = tempIfAddr->ifa_next) {
                        nbytes = write(pipefd[1], tempIfAddr->ifa_name, IFNAMSIZ);
-                       if (nbytes < 0) {
-                               ERROR("write failed");
+                       if (nbytes < 0)
                                goto out;
-                       }
+
                        count++;
                }
                ret = 0;
@@ -2108,16 +2106,16 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
                interface[IFNAMSIZ - 1] = '\0';
 
                if (array_contains(&interfaces, interface, count))
-                               continue;
+                       continue;
 
-               if(!add_to_array(&interfaces, interface, count))
+               if (!add_to_array(&interfaces, interface, count))
                        ERROR("Failed to add \"%s\" to array", interface);
 
                count++;
        }
 
        if (wait_for_pid(pid) != 0) {
-               for(i=0;i<count;i++)
+               for (i = 0; i < count; i++)
                        free(interfaces[i]);
                free(interfaces);
                interfaces = NULL;
@@ -2127,7 +2125,7 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
        close(pipefd[0]);
 
        /* Append NULL to the array */
-       if(interfaces)
+       if (interfaces)
                interfaces = (char **)lxc_append_null_to_array((void **)interfaces, count);
 
        return interfaces;