On Tue, 18.03.14 20:29, Umut Tezduyar Lindskog (umut.tezdu...@axis.com) wrote:


> +int net_get_unique_predictable_data(struct udev_device *device, uint64_t 
> *result) {
> +        size_t l, sz = 0;
> +        const char *name;
> +        int r;
> +        uint8_t *v;
> +
> +        /* fetch some persistent data unique (on this machine) to this 
> device */
> +        name = udev_device_get_property_value(device, "ID_NET_NAME_ONBOARD");
> +        if (!name) {
> +                name = udev_device_get_property_value(device, 
> "ID_NET_NAME_SLOT");
> +                if (!name) {
> +                        name = udev_device_get_property_value(device, 
> "ID_NET_NAME_PATH");
> +                        if (!name) {
> +                                name = 
> udev_device_get_property_value(device, "ID_NET_NAME_MAC");
> +                                if (!name)
> +                                        return -ENOENT;
> +                        }
> +                }
> +        }

To make this a bit nicer I have now added code a new FOREACH_STRING()
macro, working like this:

    const char *field, *name = NULL;

    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;
    }

    if (!name)
            return -ENOENT;

Lennart

-- 
Lennart Poettering, Red Hat
_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to