]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
utils: add lxc_nic_exists()
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 3 Sep 2017 14:35:48 +0000 (16:35 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 4 Sep 2017 16:37:59 +0000 (18:37 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/lxc_user_nic.c
src/lxc/utils.c
src/lxc/utils.h

index c4388a74135593ce362dfaf50f25219c209f3b8e..a2ad03080c8a89c4dd576d244824664aaacd36fa 100644 (file)
@@ -397,26 +397,6 @@ static char *find_line(char *p, char *e, char *u, char *t, char *l)
        return NULL;
 }
 
-static bool nic_exists(char *nic)
-{
-       char path[MAXPATHLEN];
-       int ret;
-       struct stat sb;
-
-       if (!strcmp(nic, "none"))
-               return true;
-
-       ret = snprintf(path, MAXPATHLEN, "/sys/class/net/%s", nic);
-       if (ret < 0 || (size_t)ret >= MAXPATHLEN)
-               return false;
-
-       ret = stat(path, &sb);
-       if (ret < 0)
-               return false;
-
-       return true;
-}
-
 static int instantiate_veth(char *n1, char **n2)
 {
        int err;
@@ -625,7 +605,7 @@ static bool cull_entries(int fd, char *me, char *t, char *br, char *nicname,
                        continue;
 
                if (nic[0] != '\0')
-                       exists = nic_exists(nic);
+                       exists = lxc_nic_exists(nic);
 
                if (!exists)
                        entry_lines[n - 1].keep = false;
index d36107020397db9524b81113f192a724c89c9949..959481ee20fcea582d76cdb3d1835e16cabf476a 100644 (file)
@@ -2406,3 +2406,24 @@ bool has_fs_type(const char *path, fs_type_magic magic_val)
 
        return has_type;
 }
+
+bool lxc_nic_exists(char *nic)
+{
+#define __LXC_SYS_CLASS_NET_LEN 15 + IFNAMSIZ + 1
+       char path[__LXC_SYS_CLASS_NET_LEN];
+       int ret;
+       struct stat sb;
+
+       if (!strcmp(nic, "none"))
+               return true;
+
+       ret = snprintf(path, __LXC_SYS_CLASS_NET_LEN, "/sys/class/net/%s", nic);
+       if (ret < 0 || (size_t)ret >= __LXC_SYS_CLASS_NET_LEN)
+               return false;
+
+       ret = stat(path, &sb);
+       if (ret < 0)
+               return false;
+
+       return true;
+}
index 4408c6d6925d2d52fcd15a7595555ca039c70461..3f4d9047926361134c75d1b38a001396715d4afe 100644 (file)
@@ -390,7 +390,8 @@ void *must_realloc(void *orig, size_t sz);
 
 /* __typeof__ should be safe to use with all compilers. */
 typedef __typeof__(((struct statfs *)NULL)->f_type) fs_type_magic;
-bool has_fs_type(const char *path, fs_type_magic magic_val);
-bool is_fs_type(const struct statfs *fs, fs_type_magic magic_val);
+extern bool has_fs_type(const char *path, fs_type_magic magic_val);
+extern bool is_fs_type(const struct statfs *fs, fs_type_magic magic_val);
+extern bool lxc_nic_exists(char *nic);
 
 #endif /* __LXC_UTILS_H */