HALF ECHO LEARN / REFERENCE COLLECTION

v262.2

src/core/load-fragment.c

243,452 bytesGit mode 100644Download original fileLGPL-2.1-or-later

Git blob: cced46d969833bd05c914c99959caab3cb02b542

Lines 3001–4000 of 6,900

                const char *eq;
 
                r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
                if (r == -ENOMEM)
                        return log_oom();
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
                        return 0;
                }
                if (r == 0)
                        return 0;
 
                r = unit_full_printf(u, word, &k);
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", word);
                        continue;
                }
 
                eq = strchr(k, '=');
                if (!eq) {
                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Log field lacks '=' character, ignoring: %s", k);
                        continue;
                }
 
                if (!journal_field_valid(k, eq-k, false)) {
                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Log field name is invalid, ignoring: %s", k);
                        continue;
                }
 
                if (c->n_log_extra_fields >= LOG_EXTRA_FIELDS_MAX) {
                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Too many extra log fields, ignoring some.");
                        return 0;
                }
 
                if (!GREEDY_REALLOC(c->log_extra_fields, c->n_log_extra_fields + 1))
                        return log_oom();
 
                c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE_STRING(k);
                TAKE_PTR(k);
        }
}
 
int config_parse_log_namespace(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        _cleanup_free_ char *k = NULL;
        ExecContext *c = ASSERT_PTR(data);
        const Unit *u = userdata;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                c->log_namespace = mfree(c->log_namespace);
                return 0;
        }
 
        r = unit_full_printf_full(u, rvalue, NAME_MAX, &k);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue);
                return 0;
        }
 
        if (!log_namespace_name_valid(k)) {
                log_syntax(unit, LOG_WARNING, filename, line, 0, "Specified log namespace name is not valid, ignoring: %s", k);
                return 0;
        }
 
        free_and_replace(c->log_namespace, k);
        return 0;
}
 
int config_parse_unit_condition_path(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        _cleanup_free_ char *p = NULL;
        Condition **list = ASSERT_PTR(data), *c;
        ConditionType t = ltype;
        bool trigger, negate;
        const Unit *u = userdata;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                /* Empty assignment resets the list */
                *list = condition_free_list(*list);
                return 0;
        }
 
        trigger = rvalue[0] == '|';
        if (trigger)
                rvalue++;
 
        negate = rvalue[0] == '!';
        if (negate)
                rvalue++;
 
        r = unit_path_printf(u, rvalue, &p);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue);
                return 0;
        }
 
        r = path_simplify_and_warn(p, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
        if (r < 0)
                return 0;
 
        c = condition_new(t, p, trigger, negate);
        if (!c)
                return log_oom();
 
        LIST_PREPEND(conditions, *list, c);
        return 0;
}
 
int config_parse_unit_condition_string(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        _cleanup_free_ char *s = NULL;
        Condition **list = ASSERT_PTR(data), *c;
        ConditionType t = ltype;
        bool trigger, negate;
        const Unit *u = userdata;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                /* Empty assignment resets the list */
                *list = condition_free_list(*list);
                return 0;
        }
 
        trigger = *rvalue == '|';
        if (trigger)
                rvalue += 1 + strspn(rvalue + 1, WHITESPACE);
 
        negate = *rvalue == '!';
        if (negate)
                rvalue += 1 + strspn(rvalue + 1, WHITESPACE);
 
        r = unit_full_printf(u, rvalue, &s);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r,
                           "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue);
                return 0;
        }
 
        c = condition_new(t, s, trigger, negate);
        if (!c)
                return log_oom();
 
        LIST_PREPEND(conditions, *list, c);
        return 0;
}
 
int config_parse_unit_mounts_for(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        Unit *u = userdata;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);
        assert(STR_IN_SET(lvalue, "RequiresMountsFor", "WantsMountsFor"));
 
        for (const char *p = rvalue;;) {
                _cleanup_free_ char *word = NULL, *resolved = NULL;
 
                r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
                if (r == -ENOMEM)
                        return log_oom();
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r,
                                   "Invalid syntax, ignoring: %s", rvalue);
                        return 0;
                }
                if (r == 0)
                        return 0;
 
                r = unit_path_printf(u, word, &resolved);
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", word);
                        continue;
                }
 
                r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
                if (r < 0)
                        continue;
 
                r = unit_add_mounts_for(u, resolved, UNIT_DEPENDENCY_FILE, unit_mount_dependency_type_from_string(lvalue));
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to add requested mount '%s', ignoring: %m", resolved);
                        continue;
                }
        }
}
 
int config_parse_documentation(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        Unit *u = ASSERT_PTR(userdata);
        int r;
        char **a, **b;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                /* Empty assignment resets the list */
                u->documentation = strv_free(u->documentation);
                return 0;
        }
 
        r = config_parse_unit_strv_printf(unit, filename, line, section, section_line, lvalue, ltype,
                                          rvalue, data, userdata);
        if (r < 0)
                return r;
 
        for (a = b = u->documentation; a && *a; a++) {
 
                if (documentation_url_is_valid(*a))
                        *(b++) = *a;
                else {
                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid URL, ignoring: %s", *a);
                        free(*a);
                }
        }
        if (b)
                *b = NULL;
 
        return 0;
}
 
#if HAVE_SECCOMP
int config_parse_syscall_filter(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        ExecContext *c = data;
        _unused_ const Unit *u = ASSERT_PTR(userdata);
        bool invert = false;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                /* Empty assignment resets the list */
                c->syscall_filter = hashmap_free(c->syscall_filter);
                c->syscall_allow_list = false;
                return 0;
        }
 
        if (rvalue[0] == '~') {
                invert = true;
                rvalue++;
        }
 
        if (!c->syscall_filter) {
                c->syscall_filter = hashmap_new(NULL);
                if (!c->syscall_filter)
                        return log_oom();
 
                if (invert)
                        /* Allow everything but the ones listed */
                        c->syscall_allow_list = false;
                else {
                        /* Allow nothing but the ones listed */
                        c->syscall_allow_list = true;
 
                        /* Accept default syscalls if we are on an allow_list */
                        r = seccomp_parse_syscall_filter(
                                        "@default", -1, c->syscall_filter,
                                        SECCOMP_PARSE_PERMISSIVE|SECCOMP_PARSE_ALLOW_LIST,
                                        unit,
                                        NULL, 0);
                        if (r < 0)
                                return r;
                }
        }
 
        for (const char *p = rvalue;;) {
                _cleanup_free_ char *word = NULL, *name = NULL;
                int num;
 
                r = extract_first_word(&p, &word, NULL, 0);
                if (r == -ENOMEM)
                        return log_oom();
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r,
                                   "Invalid syntax, ignoring: %s", rvalue);
                        return 0;
                }
                if (r == 0)
                        return 0;
 
                r = parse_syscall_and_errno(word, &name, &num);
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r,
                                   "Failed to parse syscall:errno, ignoring: %s", word);
                        continue;
                }
                if (!invert && num >= 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, 0,
                                   "Allow-listed system calls cannot take error number, ignoring: %s", word);
                        continue;
                }
 
                r = seccomp_parse_syscall_filter(
                                name, num, c->syscall_filter,
                                SECCOMP_PARSE_LOG|SECCOMP_PARSE_PERMISSIVE|
                                (invert ? SECCOMP_PARSE_INVERT : 0)|
                                (c->syscall_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0),
                                unit, filename, line);
                if (r < 0)
                        return r;
        }
}
 
int config_parse_syscall_log(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        ExecContext *c = data;
        _unused_ const Unit *u = ASSERT_PTR(userdata);
        bool invert = false;
        const char *p;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                /* Empty assignment resets the list */
                c->syscall_log = hashmap_free(c->syscall_log);
                c->syscall_log_allow_list = false;
                return 0;
        }
 
        if (rvalue[0] == '~') {
                invert = true;
                rvalue++;
        }
 
        if (!c->syscall_log) {
                c->syscall_log = hashmap_new(NULL);
                if (!c->syscall_log)
                        return log_oom();
 
                if (invert)
                        /* Log everything but the ones listed */
                        c->syscall_log_allow_list = false;
                else
                        /* Log nothing but the ones listed */
                        c->syscall_log_allow_list = true;
        }
 
        p = rvalue;
        for (;;) {
                _cleanup_free_ char *word = NULL;
 
                r = extract_first_word(&p, &word, NULL, 0);
                if (r == -ENOMEM)
                        return log_oom();
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
                        return 0;
                }
                if (r == 0)
                        return 0;
 
                r = seccomp_parse_syscall_filter(
                                word, -1, c->syscall_log,
                                SECCOMP_PARSE_LOG|SECCOMP_PARSE_PERMISSIVE|
                                (invert ? SECCOMP_PARSE_INVERT : 0)|
                                (c->syscall_log_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0),
                                unit, filename, line);
                if (r < 0)
                        return r;
        }
}
 
int config_parse_syscall_archs(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        Set **archs = data;
        int r;
 
        if (isempty(rvalue)) {
                *archs = set_free(*archs);
                return 0;
        }
 
        for (const char *p = rvalue;;) {
                _cleanup_free_ char *word = NULL;
                uint32_t a;
 
                r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
                if (r == -ENOMEM)
                        return log_oom();
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r,
                                   "Invalid syntax, ignoring: %s", rvalue);
                        return 0;
                }
                if (r == 0)
                        return 0;
 
                r = seccomp_arch_from_string(word, &a);
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r,
                                   "Failed to parse system call architecture \"%s\", ignoring: %m", word);
                        continue;
                }
 
                r = set_ensure_put(archs, NULL, UINT32_TO_PTR(a + 1));
                if (r < 0)
                        return log_oom();
        }
}
 
int config_parse_syscall_errno(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        ExecContext *c = data;
        int e;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue) || streq(rvalue, "kill")) {
                /* Empty assignment resets to KILL */
                c->syscall_errno = SECCOMP_ERROR_NUMBER_KILL;
                return 0;
        }
 
        e = parse_errno(rvalue);
        if (e < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, e, "Failed to parse error number, ignoring: %s", rvalue);
                return 0;
        }
        if (e == 0) {
                log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid error number, ignoring: %s", rvalue);
                return 0;
        }
 
        c->syscall_errno = e;
        return 0;
}
 
int config_parse_address_families(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        ExecContext *c = data;
        bool is_allowlist = c->address_families_allow_list;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        r = parse_address_families(rvalue, &c->address_families, &is_allowlist);
        /* Copy back unconditionally: parse_address_families() may have partially populated
         * c->address_families before failing, so keep is_allowlist in sync with that state. */
        c->address_families_allow_list = is_allowlist;
        if (r == -ENOMEM)
                return log_oom();
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r,
                           "Failed to parse address family, ignoring: %s", rvalue);
                return 0;
        }
 
        return 0;
}
#endif
 
int config_parse_namespace_flags(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        unsigned long *flags = data;
        unsigned long all = UPDATE_FLAG(NAMESPACE_FLAGS_ALL, CLONE_NEWUSER, !streq(lvalue, "DelegateNamespaces"));
        unsigned long f;
        bool invert = false;
        int r;
 
        if (isempty(rvalue)) {
                /* Reset to the default. */
                *flags = NAMESPACE_FLAGS_INITIAL;
                return 0;
        }
 
        /* Boolean parameter ignores the previous settings */
        r = parse_boolean(rvalue);
        if (r > 0) {
                /* RestrictNamespaces= value gets stored into a field with reverse semantics (the namespaces
                 * which are retained), so RestrictNamespaces=true means we retain no access to any
                 * namespaces and vice-versa. */
                *flags = streq(lvalue, "RestrictNamespaces") ? 0 : all;
                return 0;
        } else if (r == 0) {
                *flags = streq(lvalue, "RestrictNamespaces") ? all : 0;
                return 0;
        }
 
        if (rvalue[0] == '~') {
                invert = true;
                rvalue++;
        }
 
        /* Not a boolean argument, in this case it's a list of namespace types. */
        r = namespace_flags_from_string(rvalue, &f);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse namespace type string, ignoring: %s", rvalue);
                return 0;
        }
 
        if (*flags == NAMESPACE_FLAGS_INITIAL)
                /* Initial assignment. Just set the value. */
                f = invert ? (~f) & all : f;
        else
                /* Merge the value with the previous one. */
                f = UPDATE_FLAG(*flags, f, !invert);
 
        if (FLAGS_SET(f, CLONE_NEWUSER) && streq(lvalue, "DelegateNamespaces")) {
                log_syntax(unit, LOG_WARNING, filename, line, r, "The user namespace cannot be delegated with DelegateNamespaces=, ignoring: %s", rvalue);
                return 0;
        }
 
        *flags = f;
 
        return 0;
}
 
int config_parse_restrict_filesystems(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
        ExecContext *c = ASSERT_PTR(data);
        bool invert = false;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                /* Empty assignment resets the list */
                c->restrict_filesystems = set_free(c->restrict_filesystems);
                c->restrict_filesystems_allow_list = false;
                return 0;
        }
 
        if (rvalue[0] == '~') {
                invert = true;
                rvalue++;
        }
 
        if (!c->restrict_filesystems) {
                if (invert)
                        /* Allow everything but the ones listed */
                        c->restrict_filesystems_allow_list = false;
                else
                        /* Allow nothing but the ones listed */
                        c->restrict_filesystems_allow_list = true;
        }
 
        for (const char *p = rvalue;;) {
                _cleanup_free_ char *word = NULL;
 
                r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
                if (r == 0)
                        break;
                if (r == -ENOMEM)
                        return log_oom();
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r,
                                   "Trailing garbage in %s, ignoring: %s", lvalue, rvalue);
                        break;
                }
 
                r = bpf_restrict_fs_parse_filesystem(
                              word,
                              &c->restrict_filesystems,
                              FILESYSTEM_PARSE_LOG|
                              (invert ? FILESYSTEM_PARSE_INVERT : 0)|
                              (c->restrict_filesystems_allow_list ? FILESYSTEM_PARSE_ALLOW_LIST : 0),
                              unit, filename, line);
 
                if (r < 0)
                        return r;
        }
 
        return 0;
}
 
int config_parse_unit_slice(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        Unit *u = ASSERT_PTR(userdata), *slice;
        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
        _cleanup_free_ char *k = NULL;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        r = unit_name_printf(u, rvalue, &k);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue);
                return 0;
        }
 
        r = manager_load_unit(u->manager, k, NULL, &error, &slice);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to load slice unit %s, ignoring: %s", k, bus_error_message(&error, r));
                return 0;
        }
 
        r = unit_set_slice(u, slice);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to assign slice %s to unit %s, ignoring: %m", slice->id, u->id);
                return 0;
        }
 
        return 0;
}
 
int config_parse_cpu_quota(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        CGroupContext *c = data;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                c->cpu_quota_per_sec_usec = USEC_INFINITY;
                return 0;
        }
 
        r = parse_permyriad_unbounded(rvalue);
        if (r <= 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid CPU quota '%s', ignoring.", rvalue);
                return 0;
        }
 
        c->cpu_quota_per_sec_usec = ((usec_t) r * USEC_PER_SEC) / 10000U;
        return 0;
}
 
int config_parse_unit_cpu_set(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        const Unit *u = ASSERT_PTR(userdata);
        _cleanup_free_ char *k = NULL;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        r = unit_full_printf(u, rvalue, &k);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r,
                           "Failed to resolve unit specifiers in '%s', ignoring: %m",
                           rvalue);
                return 0;
        }
 
        return config_parse_cpu_set(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata);
}
 
int config_parse_memory_limit(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        CGroupContext *c = data;
        uint64_t bytes = CGROUP_LIMIT_MAX;
        int r;
 
        if (isempty(rvalue) && STR_IN_SET(lvalue, "MemoryLow",
                                                  "StartupMemoryLow",
                                                  "MemoryMin"))
                bytes = CGROUP_LIMIT_MIN;
        else if (!isempty(rvalue) && !streq(rvalue, "infinity")) {
 
                r = parse_permyriad(rvalue);
                if (r < 0) {
                        r = parse_size(rvalue, 1024, &bytes);
                        if (r < 0) {
                                log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid memory limit '%s', ignoring: %m", rvalue);
                                return 0;
                        }
                } else
                        bytes = physical_memory_scale(r, 10000U);
 
                if (bytes >= UINT64_MAX ||
                    (bytes <= 0 && !STR_IN_SET(lvalue,
                                               "MemorySwapMax",
                                               "StartupMemorySwapMax",
                                               "MemoryZSwapMax",
                                               "StartupMemoryZSwapMax",
                                               "MemoryLow",
                                               "StartupMemoryLow",
                                               "MemoryMin"))) {
                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Memory limit '%s' out of range, ignoring.", rvalue);
                        return 0;
                }
        }
 
        if (streq(lvalue, "MemoryMin"))
                c->memory_min = bytes;
        else if (streq(lvalue, "MemoryLow"))
                c->memory_low = bytes;
        else if (streq(lvalue, "StartupMemoryLow")) {
                c->startup_memory_low = bytes;
                c->startup_memory_low_set = true;
        } else if (streq(lvalue, "MemoryHigh"))
                c->memory_high = bytes;
        else if (streq(lvalue, "StartupMemoryHigh")) {
                c->startup_memory_high = bytes;
                c->startup_memory_high_set = true;
        } else if (streq(lvalue, "MemoryMax"))
                c->memory_max = bytes;
        else if (streq(lvalue, "StartupMemoryMax")) {
                c->startup_memory_max = bytes;
                c->startup_memory_max_set = true;
        } else if (streq(lvalue, "MemorySwapMax"))
                c->memory_swap_max = bytes;
        else if (streq(lvalue, "StartupMemorySwapMax")) {
                c->startup_memory_swap_max = bytes;
                c->startup_memory_swap_max_set = true;
        } else if (streq(lvalue, "MemoryZSwapMax"))
                c->memory_zswap_max = bytes;
        else if (streq(lvalue, "StartupMemoryZSwapMax")) {
                c->startup_memory_zswap_max = bytes;
                c->startup_memory_zswap_max_set = true;
        } else
                return -EINVAL;
 
        return 0;
}
 
int config_parse_tasks_max(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        CGroupTasksMax *tasks_max = ASSERT_PTR(data);
        const Unit *u = userdata;
        uint64_t v;
        int r;
 
        if (isempty(rvalue)) {
                *tasks_max = u ? u->manager->defaults.tasks_max : CGROUP_TASKS_MAX_UNSET;
                return 0;
        }
 
        if (streq(rvalue, "infinity")) {
                *tasks_max = CGROUP_TASKS_MAX_UNSET;
                return 0;
        }
 
        r = parse_permyriad(rvalue);
        if (r >= 0)
                *tasks_max = (CGroupTasksMax) { r, 10000U }; /* r‱ */
        else {
                r = safe_atou64(rvalue, &v);
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid maximum tasks value '%s', ignoring: %m", rvalue);
                        return 0;
                }
 
                if (v <= 0 || v >= UINT64_MAX) {
                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue);
                        return 0;
                }
 
                *tasks_max = (CGroupTasksMax) { v };
        }
 
        return 0;
}
 
int config_parse_delegate(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *section,
                unsigned section_line,
                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        CGroupContext *c = data;
        UnitType t;
        int r;
 
        t = unit_name_to_type(unit);
        assert(t != _UNIT_TYPE_INVALID);
 
        if (!unit_vtable[t]->can_delegate) {
                log_syntax(unit, LOG_WARNING, filename, line, 0, "Delegate= setting not supported for this unit type, ignoring.");
                return 0;
        }
 
        /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or
         * turn it off for all. Or it takes a list of controller names, in which case we add the specified
         * controllers to the mask to delegate. Delegate= enables delegation without any controllers. */
 
        if (isempty(rvalue)) {
                /* An empty string resets controllers and sets Delegate=yes. */
                c->delegate = true;
                c->delegate_controllers = 0;
                return 0;
        }
 
        r = parse_boolean(rvalue);
        if (r < 0) {
                CGroupMask mask = 0;
 
                for (const char *p = rvalue;;) {
                        _cleanup_free_ char *word = NULL;
                        CGroupController cc;
 
                        r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
                        if (r == -ENOMEM)
                                return log_oom();
                        if (r < 0) {
                                log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
                                return 0;
                        }
                        if (r == 0)
                                break;