]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/nspawn/nspawn-network.c
nspawn-network: Split off udev checking from parse_interface.
[thirdparty/systemd.git] / src / nspawn / nspawn-network.c
index fa1ec05b62285df499451fff0870d952d01aeda4..83ce62877a05ddd9b12ab6d7967a3f4d46d657f8 100644 (file)
@@ -395,37 +395,47 @@ int remove_bridge(const char *bridge_name) {
 }
 
 static int parse_interface(const char *name) {
-        _cleanup_(sd_device_unrefp) sd_device *d = NULL;
         int ifi, r;
 
         r = parse_ifindex_or_ifname(name, &ifi);
         if (r < 0)
                 return log_error_errno(r, "Failed to resolve interface %s: %m", name);
 
-        if (path_is_read_only_fs("/sys") <= 0) {
-                char ifi_str[2 + DECIMAL_STR_MAX(int)];
+        return ifi;
+}
 
-                /* udev should be around. */
+int test_network_interface_initialized(const char *name) {
+        _cleanup_(sd_device_unrefp) sd_device *d = NULL;
+        int ifi, r;
+        char ifi_str[2 + DECIMAL_STR_MAX(int)];
 
-                sprintf(ifi_str, "n%i", ifi);
-                r = sd_device_new_from_device_id(&d, ifi_str);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to get device %s: %m", name);
+        if (path_is_read_only_fs("/sys"))
+                return 0;
 
-                r = sd_device_get_is_initialized(d);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to determine whether interface %s is initialized: %m", name);
-                if (r == 0)
-                        return log_error_errno(SYNTHETIC_ERRNO(EBUSY), "Network interface %s is not initialized yet.", name);
+        /* udev should be around. */
 
-                r = device_is_renaming(d);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to determine the interface %s is being renamed: %m", name);
-                if (r > 0)
-                        return log_error_errno(SYNTHETIC_ERRNO(EBUSY), "Interface %s is being renamed.", name);
-        }
+        ifi = parse_interface(name);
+        if (ifi < 0)
+                return ifi;
 
-        return ifi;
+        sprintf(ifi_str, "n%i", ifi);
+        r = sd_device_new_from_device_id(&d, ifi_str);
+        if (r < 0)
+                return log_error_errno(r, "Failed to get device %s: %m", name);
+
+        r = sd_device_get_is_initialized(d);
+        if (r < 0)
+                return log_error_errno(r, "Failed to determine whether interface %s is initialized: %m", name);
+        if (r == 0)
+                return log_error_errno(SYNTHETIC_ERRNO(EBUSY), "Network interface %s is not initialized yet.", name);
+
+        r = device_is_renaming(d);
+        if (r < 0)
+                return log_error_errno(r, "Failed to determine the interface %s is being renamed: %m", name);
+        if (r > 0)
+                return log_error_errno(SYNTHETIC_ERRNO(EBUSY), "Interface %s is being renamed.", name);
+
+        return 0;
 }
 
 int move_network_interfaces(pid_t pid, char **ifaces) {