chiark / gitweb /
sd-dhcp6-client: return NULL from _unref() like the other sd-* libraries
[elogind.git] / src / libsystemd-network / network-internal.c
index 261603f841df2861fcc65f865f2d65381252a690..97217c12e5b626167529bc7d7ac220255fd3e60f 100644 (file)
 #include "conf-parser.h"
 #include "condition.h"
 
-#define HASH_KEY SD_ID128_MAKE(d3,1e,48,fa,90,fe,4b,4c,9d,af,d5,d7,a1,b1,2e,8a)
-
-int net_get_unique_predictable_data(struct udev_device *device, uint8_t result[8]) {
-        size_t l, sz = 0;
+const char *net_get_name(struct udev_device *device) {
         const char *name = NULL, *field = NULL;
-        int r;
-        uint8_t *v;
+
+        assert(device);
 
         /* fetch some persistent data unique (on this machine) to this device */
-        FOREACH_STRING(field, "ID_NET_NAME_ONBOARD", "ID_NET_NAME_SLOT", "ID_NET_NAME_PATH", "ID_NET_NAME_MAC") {
+        FOREACH_STRING(field, "ID_NET_NAME_ONBOARD", "ID_NET_NAME_SLOT",
+                       "ID_NET_NAME_PATH", "ID_NET_NAME_MAC") {
                 name = udev_device_get_property_value(device, field);
                 if (name)
                         break;
         }
 
+        return name;
+}
+
+#define HASH_KEY SD_ID128_MAKE(d3,1e,48,fa,90,fe,4b,4c,9d,af,d5,d7,a1,b1,2e,8a)
+
+int net_get_unique_predictable_data(struct udev_device *device, uint8_t result[8]) {
+        size_t l, sz = 0;
+        const char *name = NULL;
+        int r;
+        uint8_t *v;
+
+        assert(device);
+
+        name = net_get_name(device);
         if (!name)
                 return -ENOENT;
 
@@ -179,7 +191,7 @@ int config_parse_ifname(const char *unit,
                         void *userdata) {
 
         char **s = data;
-        char *n;
+        _cleanup_free_ char *n = NULL;
 
         assert(filename);
         assert(lvalue);
@@ -198,12 +210,11 @@ int config_parse_ifname(const char *unit,
         }
 
         free(*s);
-        if (*n)
+        if (*n) {
                 *s = n;
-        else {
-                free(n);
+                n = NULL;
+        } else
                 *s = NULL;
-        }
 
         return 0;
 }
@@ -327,41 +338,6 @@ int net_parse_inaddr(const char *address, unsigned char *family, void *dst) {
         return 0;
 }
 
-int load_module(struct kmod_ctx *ctx, const char *mod_name) {
-        struct kmod_list *modlist = NULL, *l;
-        int r;
-
-        assert(ctx);
-        assert(mod_name);
-
-        r = kmod_module_new_from_lookup(ctx, mod_name, &modlist);
-        if (r < 0)
-                return r;
-
-        if (!modlist) {
-                log_error("Failed to find module '%s'", mod_name);
-                return -ENOENT;
-        }
-
-        kmod_list_foreach(l, modlist) {
-                struct kmod_module *mod = kmod_module_get_module(l);
-
-                r = kmod_module_probe_insert_module(mod, 0, NULL, NULL, NULL, NULL);
-                if (r == 0)
-                        log_info("Inserted module '%s'", kmod_module_get_name(mod));
-                else {
-                        log_error("Failed to insert '%s': %s", kmod_module_get_name(mod),
-                                  strerror(-r));
-                }
-
-                kmod_module_unref(mod);
-        }
-
-        kmod_module_unref_list(modlist);
-
-        return r;
-}
-
 void serialize_in_addrs(FILE *f, const char *key, struct in_addr *addresses, size_t size) {
         unsigned i;