Example #1
0
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;
        }
Example #2
0
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");
        }
}
Example #3
0
static void test_u_n_m_one(const char *pattern, const char *expect, int ret) {
        _cleanup_free_ char *t = NULL;

        assert_se(unit_name_mangle(pattern, UNIT_NAME_NOGLOB, &t) == ret);
        puts(strna(t));
        assert_se(streq_ptr(t, expect));

        if (t) {
                _cleanup_free_ char *k = NULL;

                assert_se(unit_name_is_valid(t, UNIT_NAME_ANY));

                assert_se(unit_name_mangle(t, UNIT_NAME_NOGLOB, &k) == 0);
                assert_se(streq_ptr(t, k));
        }
}
Example #4
0
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");
        }
Example #5
0
static void test_unit_name_mangle_one(UnitNameMangle allow_globs, const char *pattern, const char *expect, int ret) {
        _cleanup_free_ char *t = NULL;

        assert_se(unit_name_mangle(pattern, allow_globs, &t) == ret);
        puts(strna(t));
        assert_se(streq_ptr(t, expect));

        if (t) {
                _cleanup_free_ char *k = NULL;

                assert_se(unit_name_is_valid(t, UNIT_NAME_ANY) ||
                          (allow_globs == UNIT_NAME_GLOB && string_is_glob(t)));

                assert_se(unit_name_mangle(t, allow_globs, &k) == 0);
                assert_se(streq_ptr(t, k));
        }
}
Example #6
0
static int parse_proc_cmdline_item(const char *key, const char *value) {
        int r;

        assert(key);

        if (streq(key, "systemd.mask")) {

                if (!value)
                        log_error("Missing argument for systemd.mask= kernel command line parameter.");
                else {
                        char *n;

                        r = unit_name_mangle(value, UNIT_NAME_NOGLOB, &n);
                        if (r < 0)
                                return log_error_errno(r, "Failed to glob unit name: %m");

                        r = strv_consume(&arg_mask, n);
                        if (r < 0)
                                return log_oom();
                }

        } else if (streq(key, "systemd.wants")) {

                if (!value)
                        log_error("Missing argument for systemd.want= kernel command line parameter.");
                else {
                        char *n;

                        r = unit_name_mangle(value, UNIT_NAME_NOGLOB, &n);
                        if (r < 0)
                                return log_error_errno(r, "Failed to glob unit name: %m");

                        r = strv_consume(&arg_wants, n);
                        if (r < 0)
                                return log_oom();
                }

        } else if (streq(key, "systemd.debug-shell")) {

                if (value) {
                        r = parse_boolean(value);
                        if (r < 0)
                                log_error("Failed to parse systemd.debug-shell= argument '%s', ignoring.", value);
                        else
                                arg_debug_shell = r;
                } else
                        arg_debug_shell = true;
        } else if (streq(key, "systemd.unit")) {

                if (!value)
                        log_error("Missing argument for systemd.unit= kernel command line parameter.");
                else {
                        r = free_and_strdup(&arg_default_unit, value);
                        if (r < 0)
                                return log_error_errno(r, "Failed to set default unit %s: %m", value);
                }
        } else if (!value) {
                const char *target;

                target = runlevel_to_target(key);
                if (target) {
                        r = free_and_strdup(&arg_default_unit, target);
                        if (r < 0)
                                return log_error_errno(r, "Failed to set default unit %s: %m", target);
                }
        }

        return 0;
}