示例#1
0
文件: device.c 项目: g33s3/systemmd
static int device_add_udev_wants(Unit *u, struct udev_device *dev) {
        const char *wants;
        const char *word, *state;
        size_t l;
        int r;
        const char *property;

        assert(u);
        assert(dev);

        property = u->manager->running_as == SYSTEMD_USER ? "SYSTEMD_USER_WANTS" : "SYSTEMD_WANTS";
        wants = udev_device_get_property_value(dev, property);
        if (!wants)
                return 0;

        FOREACH_WORD_QUOTED(word, l, wants, state) {
                _cleanup_free_ char *n = NULL;
                char e[l+1];

                memcpy(e, word, l);
                e[l] = 0;

                n = unit_name_mangle(e, MANGLE_NOGLOB);
                if (!n)
                        return -ENOMEM;

                r = unit_add_dependency_by_name(u, UNIT_WANTS, n, NULL, true);
                if (r < 0)
                        return r;
        }
示例#2
0
文件: device.c 项目: swem/systemd
static int device_add_udev_wants(Unit *u, struct udev_device *dev) {
        const char *wants;
        const char *word, *state;
        size_t l;
        int r;
        const char *property;

        assert(u);
        assert(dev);

        property = u->manager->running_as == MANAGER_USER ? "MANAGER_USER_WANTS" : "SYSTEMD_WANTS";
        wants = udev_device_get_property_value(dev, property);
        if (!wants)
                return 0;

        FOREACH_WORD_QUOTED(word, l, wants, state) {
                _cleanup_free_ char *n = NULL;
                char e[l+1];

                memcpy(e, word, l);
                e[l] = 0;

                r = unit_name_mangle(e, UNIT_NAME_NOGLOB, &n);
                if (r < 0)
                        return log_unit_error_errno(u, r, "Failed to mangle unit name: %m");

                r = unit_add_dependency_by_name(u, UNIT_WANTS, n, NULL, true);
                if (r < 0)
                        return log_unit_error_errno(u, r, "Failed to add wants dependency: %m");
        }
示例#3
0
文件: device.c 项目: aulanov/systemd
static int device_add_udev_wants(Unit *u, struct udev_device *dev) {
        const char *wants, *property, *p;
        int r;

        assert(u);
        assert(dev);

        property = MANAGER_IS_USER(u->manager) ? "SYSTEMD_USER_WANTS" : "SYSTEMD_WANTS";
        wants = udev_device_get_property_value(dev, property);
        for (p = wants;;) {
                _cleanup_free_ char *word = NULL, *k = NULL;

                r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES);
                if (r == 0)
                        return 0;
                if (r == -ENOMEM)
                        return log_oom();
                if (r < 0)
                        return log_unit_error_errno(u, r, "Failed to add parse %s: %m", property);

                r = unit_name_mangle(word, UNIT_NAME_NOGLOB, &k);
                if (r < 0)
                        return log_unit_error_errno(u, r, "Failed to mangle unit name \"%s\": %m", word);

                r = unit_add_dependency_by_name(u, UNIT_WANTS, k, NULL, true);
                if (r < 0)
                        return log_unit_error_errno(u, r, "Failed to add wants dependency: %m");
        }
}
示例#4
0
文件: target.c 项目: adsr/systemd
static int target_add_default_dependencies(Target *t) {
        static const UnitDependency deps[] = {
                UNIT_REQUIRES,
                UNIT_REQUIRES_OVERRIDABLE,
                UNIT_REQUISITE,
                UNIT_REQUISITE_OVERRIDABLE,
                UNIT_WANTS,
                UNIT_BINDS_TO
        };

        Iterator i;
        Unit *other;
        int r;
        unsigned k;

        assert(t);

        /* Imply ordering for requirement dependencies on target
         * units. Note that when the user created a contradicting
         * ordering manually we won't add anything in here to make
         * sure we don't create a loop. */

        for (k = 0; k < ELEMENTSOF(deps); k++)
                SET_FOREACH(other, UNIT(t)->dependencies[deps[k]], i)
                        if ((r = unit_add_default_target_dependency(other, UNIT(t))) < 0)
                                return r;

        /* Make sure targets are unloaded on shutdown */
        return unit_add_dependency_by_name(UNIT(t), UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
}
static int busname_add_default_default_dependencies(BusName *n) {
        int r;

        assert(n);

        r = unit_add_dependency_by_name(UNIT(n), UNIT_BEFORE, SPECIAL_BUSNAMES_TARGET, NULL, true);
        if (r < 0)
                return r;

        if (UNIT(n)->manager->running_as == SYSTEMD_SYSTEM) {
                r = unit_add_two_dependencies_by_name(UNIT(n), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true);
                if (r < 0)
                        return r;
        }

        return unit_add_two_dependencies_by_name(UNIT(n), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
}