chiark / gitweb /
sd-network: add _get_network_file api
[elogind.git] / src / libsystemd / sd-network / sd-network.c
index 3a3f53576f365cf68f264103bae7baef22b8459e..d63e6f9dfa8bb990aada6332f9348d251c2f9a59 100644 (file)
@@ -120,6 +120,30 @@ _public_ int sd_network_link_get_setup_state(int ifindex, char **state) {
         return 0;
 }
 
+_public_ int sd_network_link_get_network_file(int ifindex, char **filename) {
+        _cleanup_free_ char *s = NULL, *p = NULL;
+        int r;
+
+        assert_return(ifindex > 0, -EINVAL);
+        assert_return(filename, -EINVAL);
+
+        if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
+                return -ENOMEM;
+
+        r = parse_env_file(p, NEWLINE, "NETWORK_FILE", &s, NULL);
+        if (r == -ENOENT)
+                return -ENODATA;
+        if (r < 0)
+                return r;
+        if (isempty(s))
+                return -ENODATA;
+
+        *filename = s;
+        s = NULL;
+
+        return 0;
+}
+
 _public_ int sd_network_link_get_operational_state(int ifindex, char **state) {
         _cleanup_free_ char *s = NULL, *p = NULL;
         int r;