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 2001–3000 of 6,900

                const char *lvalue,
                int ltype,
                const char *rvalue,
                void *data,
                void *userdata) {
 
        ExecContext *c = ASSERT_PTR(data);
        const Unit *u = userdata;
        bool ignore;
        char *k;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                c->smack_process_label = mfree(c->smack_process_label);
                c->smack_process_label_ignore = false;
                return 0;
        }
 
        if (rvalue[0] == '-') {
                ignore = true;
                rvalue++;
        } else
                ignore = false;
 
        r = unit_full_printf(u, rvalue, &k);
        if (r < 0) {
                log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, r,
                           "Failed to resolve unit specifiers in '%s'%s: %m",
                           rvalue, ignore ? ", ignoring" : "");
                return ignore ? 0 : -ENOEXEC;
        }
 
        free_and_replace(c->smack_process_label, k);
        c->smack_process_label_ignore = ignore;
 
        return 0;
}
 
int config_parse_timer(
                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_(calendar_spec_freep) CalendarSpec *c = NULL;
        _cleanup_free_ char *k = NULL;
        const Unit *u = userdata;
        Timer *t = ASSERT_PTR(data);
        usec_t usec = 0;
        TimerValue *v;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                /* Empty assignment resets list */
                timer_free_values(t);
                return 0;
        }
 
        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;
        }
 
        if (ltype == TIMER_CALENDAR) {
                r = calendar_spec_from_string(k, &c);
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse calendar specification, ignoring: %s", k);
                        return 0;
                }
 
                int wday;
                if (calendar_spec_weekday_conflicts(c, &wday))
                        log_syntax(unit, LOG_WARNING, filename, line, 0,
                                   "Weekday constraint does not match the fixed date %04d-%02d-%02d "
                                   "(which is a %s), so this timer will never elapse.",
                                   c->year->start, c->month->start, c->day->start,
                                   weekday_to_string(wday));
        } else {
                r = parse_sec(k, &usec);
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse timer value, ignoring: %s", k);
                        return 0;
                }
        }
 
        v = new(TimerValue, 1);
        if (!v)
                return log_oom();
 
        *v = (TimerValue) {
                .base = ltype,
                .value = usec,
                .calendar_spec = TAKE_PTR(c),
        };
 
        LIST_PREPEND(value, t->values, v);
 
        return 0;
}
 
int config_parse_trigger_unit(
                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;
        Unit *u = ASSERT_PTR(data);
        UnitType type;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (UNIT_TRIGGER(u)) {
                log_syntax(unit, LOG_WARNING, filename, line, 0, "Multiple units to trigger specified, ignoring: %s", rvalue);
                return 0;
        }
 
        r = unit_name_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;
        }
 
        type = unit_name_to_type(p);
        if (type < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, type, "Unit type not valid, ignoring: %s", rvalue);
                return 0;
        }
        if (unit_has_name(u, p)) {
                log_syntax(unit, LOG_WARNING, filename, line, 0, "Units cannot trigger themselves, ignoring: %s", rvalue);
                return 0;
        }
 
        r = unit_add_two_dependencies_by_name(u, UNIT_BEFORE, UNIT_TRIGGERS, p, true, UNIT_DEPENDENCY_FILE);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to add trigger on %s, ignoring: %m", p);
                return 0;
        }
 
        return 0;
}
 
int config_parse_path_spec(
                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) {
 
        Path *p = ASSERT_PTR(data);
        PathSpec *s;
        PathType b;
        _cleanup_free_ char *k = NULL;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                /* Empty assignment clears list */
                path_free_specs(p);
                return 0;
        }
 
        b = path_type_from_string(lvalue);
        if (b < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, b, "Failed to parse path type, ignoring: %s", lvalue);
                return 0;
        }
 
        r = unit_path_printf(UNIT(p), 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 = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
        if (r < 0)
                return 0;
 
        s = new0(PathSpec, 1);
        if (!s)
                return log_oom();
 
        s->unit = UNIT(p);
        s->path = TAKE_PTR(k);
        s->type = b;
        s->inotify_fd = -EBADF;
 
        LIST_PREPEND(spec, p->specs, s);
 
        return 0;
}
 
int config_parse_socket_service(
                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_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
        _cleanup_free_ char *p = NULL;
        Socket *s = ASSERT_PTR(data);
        Unit *x;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        r = unit_name_printf(UNIT(s), 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;
        }
 
        if (!endswith(p, ".service")) {
                log_syntax(unit, LOG_WARNING, filename, line, 0, "Unit must be of type service, ignoring: %s", rvalue);
                return 0;
        }
 
        r = manager_load_unit(UNIT(s)->manager, p, NULL, &error, &x);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to load unit %s, ignoring: %s", rvalue, bus_error_message(&error, r));
                return 0;
        }
 
        unit_ref_set(&s->service, UNIT(s), x);
 
        return 0;
}
 
int config_parse_xattr(
                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) {
 
        char ***lp = ASSERT_PTR(data);
        Unit *u = userdata;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                *lp = strv_free(*lp);
                return 0;
        }
 
        _cleanup_free_ char *name = NULL, *value = NULL;
        r = split_pair(rvalue, "=", &name, &value);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse extended attribute expression, ignoring: %s", rvalue);
                return 0;
        }
 
        _cleanup_free_ char *expanded_name = NULL;
        r = unit_full_printf(u, name, &expanded_name);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to expand specifiers in extended attribute expression, ignoring: %s", name);
                return 0;
        }
 
        if (!startswith(expanded_name, "user.")) {
                log_syntax(unit, LOG_WARNING, filename, line, 0, "Extended attribute name does not begin with 'user.', ignoring: %s", expanded_name);
                return 0;
        }
 
        _cleanup_free_ char *expanded_value = NULL;
        r = unit_full_printf(u, value, &expanded_value);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to expand specifiers in extended attribute expression, ignoring: %s", value);
                return 0;
        }
 
        if (strv_push_pair(lp, expanded_name, expanded_value) < 0)
                return log_oom();
 
        TAKE_PTR(expanded_name);
        TAKE_PTR(expanded_value);
 
        return 0;
}
 
int config_parse_fdname(
                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;
        Socket *s = ASSERT_PTR(data);
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                s->fdname = mfree(s->fdname);
                return 0;
        }
 
        r = unit_fd_printf(UNIT(s), 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;
        }
 
        if (!fdname_is_valid(p)) {
                log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid file descriptor name, ignoring: %s", p);
                return 0;
        }
 
        return free_and_replace(s->fdname, p);
}
 
int config_parse_service_sockets(
                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) {
 
        Service *s = ASSERT_PTR(data);
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        for (const char *p = rvalue;;) {
                _cleanup_free_ char *word = NULL, *k = 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, "Trailing garbage in sockets, ignoring: %s", rvalue);
                        return 0;
                }
                if (r == 0)
                        return 0;
 
                r = unit_name_printf(UNIT(s), word, &k);
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", word);
                        continue;
                }
 
                if (!endswith(k, ".socket")) {
                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Unit must be of type socket, ignoring: %s", k);
                        continue;
                }
 
                r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_WANTS, UNIT_AFTER, k, true, UNIT_DEPENDENCY_FILE);
                if (r < 0)
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to add dependency on %s, ignoring: %m", k);
 
                r = unit_add_dependency_by_name(UNIT(s), UNIT_TRIGGERED_BY, k, true, UNIT_DEPENDENCY_FILE);
                if (r < 0)
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to add dependency on %s, ignoring: %m", k);
        }
}
 
int config_parse_bus_name(
                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;
        const Unit *u = ASSERT_PTR(userdata);
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        r = unit_full_printf_full(u, rvalue, SD_BUS_MAXIMUM_NAME_LENGTH, &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 (!sd_bus_service_name_is_valid(k)) {
                log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid bus name, ignoring: %s", k);
                return 0;
        }
 
        return config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata);
}
 
int config_parse_service_timeout(
                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) {
 
        Service *s = ASSERT_PTR(userdata);
        usec_t usec;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
 
        /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
         * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
         * all other timeouts. */
        r = parse_sec_fix_0(rvalue, &usec);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s= parameter, ignoring: %s", lvalue, rvalue);
                return 0;
        }
 
        s->start_timeout_defined = true;
        s->timeout_start_usec = usec;
 
        if (streq(lvalue, "TimeoutSec"))
                s->timeout_stop_usec = usec;
 
        return 0;
}
 
int config_parse_timeout_abort(
                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) {
 
        usec_t *ret = ASSERT_PTR(data);
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
 
        if (isempty(rvalue)) {
                *ret = 0;
                return 0; /* "not set" */
        }
 
        r = parse_sec(rvalue, ret);
        if (r < 0)
                return log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s= setting, ignoring: %s", lvalue, rvalue);
 
        return 1; /* "set" */
}
 
int config_parse_service_timeout_abort(
                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) {
 
        Service *s = ASSERT_PTR(userdata);
        int r;
 
        r = config_parse_timeout_abort(unit, filename, line, section, section_line, lvalue, ltype, rvalue,
                                       &s->timeout_abort_usec, s);
        if (r >= 0)
                s->timeout_abort_set = r;
        return 0;
}
 
int config_parse_user_group_compat(
                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;
        char **user = data;
        const Unit *u = ASSERT_PTR(userdata);
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                *user = mfree(*user);
                return 0;
        }
 
        r = unit_full_printf(u, rvalue, &k);
        if (r < 0) {
                log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", rvalue);
                return -ENOEXEC;
        }
 
        if (!valid_user_group_name(k, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN)) {
                log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid user/group name or numeric ID: %s", k);
                return -ENOEXEC;
        }
 
        if (strstr(lvalue, "User") && streq(k, NOBODY_USER_NAME))
                log_struct(LOG_NOTICE,
                           LOG_MESSAGE("%s:%u: Special user %s configured, this is not safe!", filename, line, k),
                           LOG_MESSAGE_ID(SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR),
                           LOG_ITEM("UNIT=%s", unit),
                           LOG_ITEM("OFFENDING_USER=%s", k),
                           LOG_ITEM("CONFIG_FILE=%s", filename),
                           LOG_ITEM("CONFIG_LINE=%u", line));
 
        return free_and_replace(*user, k);
}
 
int config_parse_user_group_strv_compat(
                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) {
 
        char ***users = data;
        const Unit *u = ASSERT_PTR(userdata);
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                *users = strv_free(*users);
                return 0;
        }
 
        for (const char *p = rvalue;;) {
                _cleanup_free_ char *word = NULL, *k = NULL;
 
                r = extract_first_word(&p, &word, NULL, 0);
                if (r == -ENOMEM)
                        return log_oom();
                if (r < 0) {
                        log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax: %s", rvalue);
                        return -ENOEXEC;
                }
                if (r == 0)
                        return 0;
 
                r = unit_full_printf(u, word, &k);
                if (r < 0) {
                        log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", word);
                        return -ENOEXEC;
                }
 
                if (!valid_user_group_name(k, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN)) {
                        log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid user/group name or numeric ID: %s", k);
                        return -ENOEXEC;
                }
 
                r = strv_push(users, k);
                if (r < 0)
                        return log_oom();
 
                k = NULL;
        }
}
 
int config_parse_working_directory(
                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);
        const Unit *u = ASSERT_PTR(userdata);
        bool missing_ok;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                c->working_directory_missing_ok = false;
                c->working_directory_home = false;
                c->working_directory = mfree(c->working_directory);
                return 0;
        }
 
        if (rvalue[0] == '-') {
                missing_ok = true;
                rvalue++;
        } else
                missing_ok = false;
 
        if (streq(rvalue, "~")) {
                c->working_directory_home = true;
                c->working_directory = mfree(c->working_directory);
        } else {
                _cleanup_free_ char *k = NULL;
 
                r = unit_path_printf(u, rvalue, &k);
                if (r < 0) {
                        log_syntax(unit, missing_ok ? LOG_WARNING : LOG_ERR, filename, line, r,
                                   "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
                                   rvalue, missing_ok ? ", ignoring" : "");
                        return missing_ok ? 0 : -ENOEXEC;
                }
 
                r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE|(missing_ok ? 0 : PATH_CHECK_FATAL),
                                           unit, filename, line, lvalue);
                if (r < 0)
                        return missing_ok ? 0 : -ENOEXEC;
 
                c->working_directory_home = false;
                free_and_replace(c->working_directory, k);
        }
 
        c->working_directory_missing_ok = missing_ok;
        return 0;
}
 
int config_parse_unit_env_file(
                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) {
 
        char ***env = ASSERT_PTR(data);
        const Unit *u = userdata;
        _cleanup_free_ char *n = NULL;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                /* Empty assignment frees the list */
                *env = strv_free(*env);
                return 0;
        }
 
        r = unit_path_printf(u, rvalue, &n);
        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(n[0] == '-' ? n + 1 : n, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
        if (r < 0)
                return 0;
 
        r = strv_push(env, n);
        if (r < 0)
                return log_oom();
 
        n = NULL;
 
        return 0;
}
 
int config_parse_environ(
                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 = userdata;
        char ***env = ASSERT_PTR(data);
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                /* Empty assignment resets the list */
                *env = strv_free(*env);
                return 0;
        }
 
        /* If 'u' is set, we operate on the regular unit specifier table. Otherwise we use a manager-specific
         * specifier table (in which case ltype must contain the runtime scope). */
        const Specifier *table = u ? NULL : (const Specifier[]) {
                COMMON_SYSTEM_SPECIFIERS,
                COMMON_TMP_SPECIFIERS,
                COMMON_CREDS_SPECIFIERS(ltype),
                { 'h', specifier_user_home,  NULL },
                { 's', specifier_user_shell, NULL },
                {}
        };
 
        for (const char *p = rvalue;; ) {
                _cleanup_free_ char *word = NULL, *resolved = NULL;
 
                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;
 
                if (table)
                        r = specifier_printf(word, sc_arg_max(), table, NULL, NULL, &resolved);
                else
                        r = unit_env_printf(u, word, &resolved);
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r,
                                   "Failed to resolve specifiers in %s, ignoring: %m", word);
                        continue;
                }
 
                if (!env_assignment_is_valid(resolved)) {
                        log_syntax(unit, LOG_WARNING, filename, line, 0,
                                   "Invalid environment assignment, ignoring: %s", resolved);
                        continue;
                }
 
                r = strv_env_replace_consume(env, TAKE_PTR(resolved));
                if (r < 0)
                        return log_error_errno(r, "Failed to update environment: %m");
        }
}
 
int config_parse_pass_environ(
                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) {
 
        char ***passenv = ASSERT_PTR(data);
        const Unit *u = userdata;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                /* Empty assignment resets the list */
                *passenv = strv_free(*passenv);
                return 0;
        }
 
        _cleanup_strv_free_ char **n = NULL;
 
        for (const char *p = rvalue;;) {
                _cleanup_free_ char *word = NULL, *k = 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,
                                   "Trailing garbage in %s, ignoring: %s", lvalue, rvalue);
                        break;
                }
                if (r == 0)
                        break;
 
                if (u) {
                        r = unit_env_printf(u, word, &k);
                        if (r < 0) {
                                log_syntax(unit, LOG_WARNING, filename, line, r,
                                           "Failed to resolve specifiers in %s, ignoring: %m", word);
                                continue;
                        }
                } else
                        k = TAKE_PTR(word);
 
                if (!env_name_is_valid(k)) {
                        log_syntax(unit, LOG_WARNING, filename, line, 0,
                                   "Invalid environment name for %s, ignoring: %s", lvalue, k);
                        continue;
                }
 
                if (strv_consume(&n, TAKE_PTR(k)) < 0)
                        return log_oom();
        }
 
        r = strv_extend_strv_consume(passenv, TAKE_PTR(n), /* filter_duplicates= */ true);
        if (r < 0)
                return log_oom();
 
        return 0;
}
 
int config_parse_unset_environ(
                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) {
 
        char ***unsetenv = ASSERT_PTR(data);
        const Unit *u = userdata;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                /* Empty assignment resets the list */
                *unsetenv = strv_free(*unsetenv);
                return 0;
        }
 
        _cleanup_strv_free_ char **n = NULL;
 
        for (const char *p = rvalue;;) {
                _cleanup_free_ char *word = NULL, *k = NULL;
 
                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,
                                   "Trailing garbage in %s, ignoring: %s", lvalue, rvalue);
                        break;
                }
                if (r == 0)
                        break;
 
                if (u) {
                        r = unit_env_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;
                        }
                } else
                        k = TAKE_PTR(word);
 
                if (!env_assignment_is_valid(k) && !env_name_is_valid(k)) {
                        log_syntax(unit, LOG_WARNING, filename, line, 0,
                                   "Invalid environment name or assignment %s, ignoring: %s", lvalue, k);
                        continue;
                }
 
                if (strv_consume(&n, TAKE_PTR(k)) < 0)
                        return log_oom();
        }
 
        r = strv_extend_strv_consume(unsetenv, TAKE_PTR(n), /* filter_duplicates= */ true);
        if (r < 0)
                return log_oom();
 
        return 0;
}
 
int config_parse_log_extra_fields(
                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);
        const Unit *u = userdata;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                exec_context_free_log_extra_fields(c);
                return 0;
        }
 
        for (const char *p = rvalue;;) {
                _cleanup_free_ char *word = NULL, *k = NULL;