Example #1
0
static int device_make_description(Unit *u, struct udev_device *dev, const char *path) {
        const char *model;

        assert(u);
        assert(dev);
        assert(path);

        model = udev_device_get_property_value(dev, "ID_MODEL_FROM_DATABASE");
        if (!model)
                model = udev_device_get_property_value(dev, "ID_MODEL");

        if (model) {
                const char *label;

                /* Try to concatenate the device model string with a label, if there is one */
                label = udev_device_get_property_value(dev, "ID_FS_LABEL");
                if (!label)
                        label = udev_device_get_property_value(dev, "ID_PART_ENTRY_NAME");
                if (!label)
                        label = udev_device_get_property_value(dev, "ID_PART_ENTRY_NUMBER");

                if (label) {
                        _cleanup_free_ char *j;

                        j = strjoin(model, " ", label, NULL);
                        if (j)
                                return unit_set_description(u, j);
                }

                return unit_set_description(u, model);
        }

        return unit_set_description(u, path);
}
Example #2
0
static int device_update_description(Unit *u, struct udev_device *dev, const char *path) {
        const char *model;
        int r;

        assert(u);
        assert(dev);
        assert(path);

        model = udev_device_get_property_value(dev, "ID_MODEL_FROM_DATABASE");
        if (!model)
                model = udev_device_get_property_value(dev, "ID_MODEL");

        if (model) {
                const char *label;

                /* Try to concatenate the device model string with a label, if there is one */
                label = udev_device_get_property_value(dev, "ID_FS_LABEL");
                if (!label)
                        label = udev_device_get_property_value(dev, "ID_PART_ENTRY_NAME");
                if (!label)
                        label = udev_device_get_property_value(dev, "ID_PART_ENTRY_NUMBER");

                if (label) {
                        _cleanup_free_ char *j;

                        j = strjoin(model, " ", label);
                        if (j)
                                r = unit_set_description(u, j);
                        else
                                r = -ENOMEM;
                } else
                        r = unit_set_description(u, model);
        } else
                r = unit_set_description(u, path);

        if (r < 0)
                log_unit_error_errno(u, r, "Failed to set device description: %m");

        return r;
}
static int busname_add_extras(BusName *n) {
        Unit *u = UNIT(n);
        int r;

        assert(n);

        if (!n->name) {
                n->name = unit_name_to_prefix(u->id);
                if (!n->name)
                        return -ENOMEM;
        }

        if (!u->description) {
                r = unit_set_description(u, n->name);
                if (r < 0)
                        return r;
        }

        if (n->activating) {
                if (!UNIT_DEREF(n->service)) {
                        Unit *x;

                        r = unit_load_related_unit(u, ".service", &x);
                        if (r < 0)
                                return r;

                        unit_ref_set(&n->service, x);
                }

                r = unit_add_two_dependencies(u, UNIT_BEFORE, UNIT_TRIGGERS, UNIT_DEREF(n->service), true);
                if (r < 0)
                        return r;
        }

        if (u->default_dependencies) {
                r = busname_add_default_default_dependencies(n);
                if (r < 0)
                        return r;
        }

        return 0;
}