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 1–1000 of 6,900

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/***
  Copyright © 2012 Holger Hans Peter Freyther
***/
 
#include <fcntl.h>
#include <sched.h>
#include <unistd.h>
 
#include "sd-bus.h"
#include "sd-messages.h"
 
#include "all-units.h"
#include "alloc-util.h"
#include "bpf-program.h"
#include "bpf-restrict-fs.h"
#include "bus-error.h"
#include "calendarspec.h"
#include "capability-util.h"
#include "cgroup-setup.h"
#include "condition.h"
#include "conf-parser.h"
#include "coredump-util.h"
#include "cpu-set-util.h"
#include "creds-util.h"
#include "dissect-image.h"
#include "env-util.h"
#include "escape.h"
#include "exec-credential.h"
#include "execute.h"
#include "extract-word.h"
#include "fd-util.h"
#include "fileio.h"
#include "fstab-util.h"
#include "hashmap.h"
#include "hexdecoct.h"
#include "hostname-util.h"
#include "ioprio-util.h"
#include "iovec-util.h"
#include "ip-protocol-list.h"
#include "journal-file.h"
#include "limits-util.h"
#include "load-fragment.h"
#include "log.h"
#include "luo-util.h"
#include "manager.h"
#include "mountpoint-util.h"
#include "nsflags.h"
#include "nulstr-util.h"
#include "open-file.h"
#include "ordered-set.h"
#include "parse-helpers.h"
#include "parse-util.h"
#include "path-util.h"
#include "pcre2-util.h"
#include "percent-util.h"
#include "process-util.h"
#include "reboot-util.h"
#include "seccomp-util.h"
#include "securebits-util.h"
#include "selinux-util.h"               /* IWYU pragma: keep */
#include "set.h"
#include "show-status.h"
#include "signal-util.h"
#include "socket-netlink.h"
#include "specifier.h"
#include "stat-util.h"
#include "string-util.h"
#include "strv.h"
#include "syslog-util.h"
#include "time-util.h"
#include "unit-name.h"
#include "unit-printf.h"
#include "user-util.h"
#include "web-util.h"
 
/* Built-in copies of a few essential unit files, embedded at build time. They are used as a fallback
 * when no fragment for the unit is found on disk, so that the manager can reach a usable state even on
 * a system that ships none of these unit files. */
static const struct {
        const char *name;
        const char *data;
} builtin_units[] = {
#  include "builtin-units.inc"
};
 
static int parse_socket_protocol(const char *s) {
        int r;
 
        r = parse_ip_protocol(s);
        if (r < 0)
                return r;
        if (!IN_SET(r, IPPROTO_UDPLITE, IPPROTO_SCTP, IPPROTO_MPTCP))
                return -EPROTONOSUPPORT;
 
        return r;
}
 
int parse_crash_chvt(const char *value, int *data) {
        int b;
 
        assert(data);
 
        if (safe_atoi(value, data) >= 0)
                return 0;
 
        b = parse_boolean(value);
        if (b < 0)
                return b;
 
        if (b > 0)
                *data = 0; /* switch to where kmsg goes */
        else
                *data = -1; /* turn off switching */
 
        return 0;
}
 
int parse_confirm_spawn(const char *value, char **console) {
        char *s;
        int r;
 
        assert(console);
 
        r = value ? parse_boolean(value) : 1;
        if (r == 0) {
                *console = NULL;
                return 0;
        } else if (r > 0) /* on with default tty */
                s = strdup("/dev/console");
        else if (is_path(value)) /* on with fully qualified path */
                s = strdup(value);
        else /* on with only a tty file name, not a fully qualified path */
                s = path_join("/dev/", value);
        if (!s)
                return -ENOMEM;
 
        *console = s;
        return 0;
}
 
DEFINE_CONFIG_PARSE(config_parse_socket_protocol, parse_socket_protocol);
DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits, secure_bits_from_string);
DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode, collect_mode, CollectMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy, cgroup_device_policy, CGroupDevicePolicy);
DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_cpuset_partition, cpuset_partition, CPUSetPartition, _CPUSET_PARTITION_INVALID);
DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode, exec_keyring_mode, ExecKeyringMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc, protect_proc, ProtectProc);
DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset, proc_subset, ProcSubset);
DEFINE_CONFIG_PARSE_ENUM(config_parse_private_bpf, private_bpf, PrivateBPF);
DEFINE_CONFIG_PARSE_ENUM(config_parse_private_tmp, private_tmp, PrivateTmp);
DEFINE_CONFIG_PARSE_ENUM(config_parse_private_users, private_users, PrivateUsers);
DEFINE_CONFIG_PARSE_ENUM(config_parse_private_pids, private_pids, PrivatePIDs);
DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_control_groups, protect_control_groups, ProtectControlGroups);
DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode, job_mode, JobMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess);
DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home, protect_home, ProtectHome);
DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system, protect_system, ProtectSystem);
DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_preserve_mode, exec_preserve_mode, ExecPreserveMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType);
DEFINE_CONFIG_PARSE_ENUM(config_parse_service_exit_type, service_exit_type, ServiceExitType);
DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart);
DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart_mode, service_restart_mode, ServiceRestartMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode, service_timeout_failure_mode, ServiceTimeoutFailureMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind, socket_address_bind_ipv6_only_or_bool, SocketAddressBindIPv6Only);
DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy, oom_policy, OOMPolicy);
DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference, managed_oom_preference, ManagedOOMPreference);
DEFINE_CONFIG_PARSE_ENUM(config_parse_pressure_watch, cgroup_pressure_watch, CGroupPressureWatch);
DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos, ip_tos, int, -1);
DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight, cg_weight_parse, uint64_t);
DEFINE_CONFIG_PARSE_PTR(config_parse_cg_cpu_weight, cg_cpu_weight_parse, uint64_t);
DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_propagation_flag, mount_propagation_flag_from_string, unsigned long);
DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy, mpol, int, -1);
DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format, status_unit_format, StatusUnitFormat);
DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping, socket_timestamping_from_string_harder, SocketTimestamping);
DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_defer_trigger, socket_defer_trigger, SocketDeferTrigger);
DEFINE_CONFIG_PARSE_PTR(config_parse_bpf_delegate_commands, bpf_delegate_commands_from_string, uint64_t);
DEFINE_CONFIG_PARSE_PTR(config_parse_bpf_delegate_maps, bpf_delegate_maps_from_string, uint64_t);
DEFINE_CONFIG_PARSE_PTR(config_parse_bpf_delegate_programs, bpf_delegate_programs_from_string, uint64_t);
DEFINE_CONFIG_PARSE_PTR(config_parse_bpf_delegate_attachments, bpf_delegate_attachments_from_string, uint64_t);
DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_memory_thp, exec_memory_thp, ExecMemoryTHP);
 
bool contains_instance_specifier_superset(const char *s) {
        const char *p, *q;
        bool percent = false;
 
        assert(s);
 
        p = strchr(s, '@');
        if (!p)
                return false;
 
        p++; /* Skip '@' */
 
        q = strrchr(p, '.');
        if (!q)
                q = p + strlen(p);
 
        /* If the string is just the instance specifier, it's not a superset of the instance. */
        if (memcmp_nn(p, q - p, "%i", strlen("%i")) == 0)
                return false;
 
        /* %i, %n and %N all expand to the instance or a superset of it. */
        for (; p < q; p++)
                if (*p == '%')
                        percent = !percent;
                else if (percent) {
                        if (IN_SET(*p, 'n', 'N', 'i'))
                                return true;
                        percent = false;
                }
 
        return false;
}
 
/* `name` is the rendered version of `format` via `unit_printf` or similar functions. */
int unit_is_likely_recursive_template_dependency(Unit *u, const char *name, const char *format) {
        const char *fragment_path;
        int r;
 
        assert(u);
        assert(name);
 
        /* If a template unit has a direct dependency on itself that includes the unit instance as part of
         * the template instance via a unit specifier (%i, %n or %N), this will almost certainly lead to
         * infinite recursion as systemd will keep instantiating new instances of the template unit.
         * https://github.com/systemd/systemd/issues/17602 shows a good example of how this can happen in
         * practice. To guard against this, we check for templates that depend on themselves and have the
         * instantiated unit instance included as part of the template instance of the dependency via a
         * specifier.
         *
         * For example, if systemd-notify@.service depends on systemd-notify@%n.service, this will result in
         * infinite recursion.
         */
 
        if (!unit_name_is_valid(name, UNIT_NAME_INSTANCE))
                return false;
 
        if (!unit_name_prefix_equal(u->id, name))
                return false;
 
        if (u->type != unit_name_to_type(name))
                return false;
 
        r = unit_file_find_fragment(u->manager->unit_id_map, u->manager->unit_name_map, name, &fragment_path, NULL);
        if (r < 0)
                return r;
 
        /* Fragment paths should also be equal as a custom fragment for a specific template instance
         * wouldn't necessarily lead to infinite recursion. */
        if (!path_equal(u->fragment_path, fragment_path))
                return false;
 
        if (!contains_instance_specifier_superset(format))
                return false;
 
        return true;
}
 
int config_parse_unit_deps(
                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) {
 
        UnitDependency d = ltype;
        Unit *u = userdata;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        for (const char *p = rvalue;;) {
                _cleanup_free_ char *word = NULL, *k = NULL;
                int r;
 
                r = extract_first_word(&p, &word, NULL, EXTRACT_RETAIN_ESCAPE);
                if (r == 0)
                        return 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;
                }
 
                r = unit_name_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;
                }
 
                r = unit_is_likely_recursive_template_dependency(u, k, word);
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to determine if '%s' is a recursive dependency, ignoring: %m", k);
                        continue;
                }
                if (r > 0) {
                        log_syntax(unit, LOG_DEBUG, filename, line, 0,
                                   "Dropping dependency %s=%s that likely leads to infinite recursion.",
                                   unit_dependency_to_string(d), word);
                        continue;
                }
 
                r = unit_add_dependency_by_name(u, d, 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_obsolete_unit_deps(
                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) {
 
        log_syntax(unit, LOG_WARNING, filename, line, 0,
                   "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue, unit_dependency_to_string(ltype));
 
        return config_parse_unit_deps(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata);
}
 
int config_parse_unit_string_printf(
                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(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_string(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata);
}
 
int config_parse_reboot_parameter(
                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(line);
        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;
        }
 
        if (!reboot_parameter_is_valid(k)) {
                log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid reboot parameter '%s', ignoring.", k);
                return 0;
        }
 
        return config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata);
}
 
int config_parse_unit_strv_printf(
                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_strv(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata);
}
 
int config_parse_unit_path_printf(
                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;
        bool fatal = ltype;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        r = unit_path_printf(u, rvalue, &k);
        if (r < 0) {
                log_syntax(unit, fatal ? LOG_ERR : LOG_WARNING, filename, line, r,
                           "Failed to resolve unit specifiers in '%s'%s: %m",
                           rvalue, fatal ? "" : ", ignoring");
                return fatal ? -ENOEXEC : 0;
        }
 
        return config_parse_path(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata);
}
 
int config_parse_colon_separated_paths(
                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 ***sv = ASSERT_PTR(data);
        const Unit *u = ASSERT_PTR(userdata);
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                /* Empty assignment resets the list */
                *sv = strv_free(*sv);
                return 0;
        }
 
        for (const char *p = rvalue;;) {
                _cleanup_free_ char *word = NULL, *k = NULL;
 
                r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
                if (r == -ENOMEM)
                        return log_oom();
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract first word, ignoring: %s", rvalue);
                        return 0;
                }
                if (r == 0)
                        break;
 
                r = unit_path_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);
                        return 0;
                }
 
                r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
                if (r < 0)
                        return 0;
 
                r = strv_consume(sv, TAKE_PTR(k));
                if (r < 0)
                        return log_oom();
        }
 
        return 0;
}
 
int config_parse_unit_path_strv_printf(
                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 ***x = data;
        const Unit *u = ASSERT_PTR(userdata);
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                *x = strv_free(*x);
                return 0;
        }
 
        for (const char *p = rvalue;;) {
                _cleanup_free_ char *word = NULL, *k = NULL;
 
                r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
                if (r == 0)
                        return 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;
                }
 
                r = unit_path_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);
                        return 0;
                }
 
                r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
                if (r < 0)
                        return 0;
 
                r = strv_consume(x, TAKE_PTR(k));
                if (r < 0)
                        return log_oom();
        }
}
 
static int patch_var_run(
                const char *unit,
                const char *filename,
                unsigned line,
                const char *lvalue,
                char **path) {
 
        const char *e;
        char *z;
 
        assert(path);
 
        e = path_startswith(*path, "/var/run/");
        if (!e)
                return 0;
 
        z = path_join("/run/", e);
        if (!z)
                return log_oom();
 
        log_syntax(unit, LOG_NOTICE, filename, line, 0,
                   "%s= references a path below legacy directory /var/run/, updating %s → %s; "
                   "please update the unit file accordingly.", lvalue, *path, z);
 
        free_and_replace(*path, z);
 
        return 1;
}
 
int config_parse_socket_listen(
                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) {
 
        Socket *s = ASSERT_PTR(SOCKET(data));
        _cleanup_free_ SocketPort *p = NULL;
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                /* An empty assignment removes all ports */
                socket_free_ports(s);
                return 0;
        }
 
        p = new(SocketPort, 1);
        if (!p)
                return log_oom();
 
        *p = (SocketPort) {
                .socket = s,
                .fd = -EBADF,
        };
 
        if (ltype != SOCKET_SOCKET) {
                _cleanup_free_ char *k = NULL;
 
                r = unit_path_printf(UNIT(s), 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;
                }
 
                PathSimplifyWarnFlags flags = PATH_CHECK_ABSOLUTE;
                if (ltype != SOCKET_SPECIAL)
                        flags |= PATH_CHECK_NON_API_VFS;
 
                r = path_simplify_and_warn(k, flags, unit, filename, line, lvalue);
                if (r < 0)
                        return 0;
 
                if (ltype == SOCKET_FIFO) {
                        r = patch_var_run(unit, filename, line, lvalue, &k);
                        if (r < 0)
                                return r;
                }
 
                free_and_replace(p->path, k);
                p->type = ltype;
 
        } else if (streq(lvalue, "ListenNetlink")) {
                _cleanup_free_ char *k = NULL;
 
                r = unit_path_printf(UNIT(s), 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 = socket_address_parse_netlink(&p->address, k);
                if (r < 0) {
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse address value in '%s', ignoring: %m", k);
                        return 0;
                }
 
                p->type = SOCKET_SOCKET;
 
        } else {
                _cleanup_free_ char *k = NULL;
 
                r = unit_path_printf(UNIT(s), 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 (path_is_absolute(k)) { /* Only for AF_UNIX file system sockets… */
                        r = patch_var_run(unit, filename, line, lvalue, &k);
                        if (r < 0)
                                return r;
                }
 
                r = socket_address_parse_and_warn(&p->address, k);
                if (r < 0) {
                        if (r != -EAFNOSUPPORT)
                                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse address value in '%s', ignoring: %m", k);
                        return 0;
                }
 
                if (streq(lvalue, "ListenStream"))
                        p->address.type = SOCK_STREAM;
                else if (streq(lvalue, "ListenDatagram"))
                        p->address.type = SOCK_DGRAM;
                else {
                        assert(streq(lvalue, "ListenSequentialPacket"));
                        p->address.type = SOCK_SEQPACKET;
                }
 
                if (socket_address_family(&p->address) != AF_UNIX && p->address.type == SOCK_SEQPACKET) {
                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Address family not supported, ignoring: %s", rvalue);
                        return 0;
                }
 
                p->type = SOCKET_SOCKET;
        }
 
        LIST_APPEND(port, s->ports, TAKE_PTR(p));
        return 0;
}
 
int config_parse_exec_nice(
                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);
        int priority, r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                c->nice_set = false;
                return 0;
        }
 
        r = parse_nice(rvalue, &priority);
        if (r < 0) {
                if (r == -ERANGE)
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Nice priority out of range, ignoring: %s", rvalue);
                else
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse nice priority '%s', ignoring: %m", rvalue);
                return 0;
        }
 
        c->nice = priority;
        c->nice_set = true;
 
        return 0;
}
 
int config_parse_exec_oom_score_adjust(
                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);
        int oa, r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                c->oom_score_adjust_set = false;
                return 0;
        }
 
        r = parse_oom_score_adjust(rvalue, &oa);
        if (r < 0) {
                if (r == -ERANGE)
                        log_syntax(unit, LOG_WARNING, filename, line, r, "OOM score adjust value out of range, ignoring: %s", rvalue);
                else
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue);
                return 0;
        }
 
        c->oom_score_adjust = oa;
        c->oom_score_adjust_set = true;
 
        return 0;
}
 
int config_parse_exec_coredump_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 = ASSERT_PTR(data);
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        if (isempty(rvalue)) {
                c->coredump_filter = 0;
                c->coredump_filter_set = false;
                return 0;
        }
 
        uint64_t f;
        r = coredump_filter_mask_from_string(rvalue, &f);
        if (r < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, r,
                           "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue);
                return 0;
        }
 
        c->coredump_filter |= f;
        c->coredump_filter_set = true;
        return 0;
}
 
int config_parse_kill_mode(
                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) {
 
        KillMode *k = data, m;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
        assert(data);
 
        if (isempty(rvalue)) {
                *k = KILL_CONTROL_GROUP;
                return 0;
        }
 
        m = kill_mode_from_string(rvalue);
        if (m < 0) {
                log_syntax(unit, LOG_WARNING, filename, line, m,
                           "Failed to parse kill mode specification, ignoring: %s", rvalue);
                return 0;
        }
 
        if (m == KILL_NONE)
                log_syntax(unit, LOG_WARNING, filename, line, 0,
                           "Unit uses KillMode=none. "
                           "This is unsafe, as it disables systemd's process lifecycle management for the service. "
                           "Please update the service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
                           "Support for KillMode=none is deprecated and will eventually be removed.");
 
        *k = m;
        return 0;
}
 
int config_parse_exec(
                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) {
 
        ExecCommand **e = ASSERT_PTR(data);
        const Unit *u = ASSERT_PTR(userdata);
        int r;
 
        assert(filename);
        assert(lvalue);
        assert(rvalue);
 
        e += ltype;
 
        if (isempty(rvalue)) {
                /* An empty assignment resets the list */
                *e = exec_command_free_list(*e);
                return 0;
        }
 
        const char *p = rvalue;
        bool semicolon;
 
        do {
                _cleanup_free_ char *firstword = NULL;
 
                semicolon = false;
 
                r = extract_first_word_and_warn(&p, &firstword, NULL, EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE, unit, filename, line, rvalue);
                if (r <= 0)
                        return 0;
 
                /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name.
                 *
                 * SOFT DEPRECATION: We support multiple command lines in one ExecStart= line for
                 * compatibility with older versions, but we no longer document this exists, it's deprecated
                 * in a soft way. New unit files, should not use this feature. */
                if (streq(firstword, ";")) {
                        semicolon = true;
                        continue;
                }
 
                const char *f = firstword;
                bool ignore, separate_argv0 = false, ambient_hack = false;
                ExecCommandFlags flags = 0;
 
                for (;; f++) {
                        /* We accept an absolute path as first argument. Valid prefixes and their effect:
                         *
                         * "-":  Ignore if the path doesn't exist
                         * "@":  Allow overriding argv[0] (supplied as a separate argument)
                         * "|":  Prefix the cmdline with target user's shell (when combined with "@" invoke
                         *       login shell semantics)
                         * ":":  Disable environment variable substitution
                         * "+":  Run with full privileges and no sandboxing
                         * "!":  Apply sandboxing except for user/group credentials
                         */
 
                        if (*f == '-' && !FLAGS_SET(flags, EXEC_COMMAND_IGNORE_FAILURE))
                                flags |= EXEC_COMMAND_IGNORE_FAILURE;
                        else if (*f == '@' && !separate_argv0)
                                separate_argv0 = true;
                        else if (*f == ':' && !FLAGS_SET(flags, EXEC_COMMAND_NO_ENV_EXPAND))
                                flags |= EXEC_COMMAND_NO_ENV_EXPAND;
                        else if (*f == '|' && !FLAGS_SET(flags, EXEC_COMMAND_VIA_SHELL))
                                flags |= EXEC_COMMAND_VIA_SHELL;
                        else if (*f == '+' && !(flags & (EXEC_COMMAND_FULLY_PRIVILEGED|EXEC_COMMAND_NO_SETUID)) && !ambient_hack)
                                flags |= EXEC_COMMAND_FULLY_PRIVILEGED;
                        else if (*f == '!' && !(flags & (EXEC_COMMAND_FULLY_PRIVILEGED|EXEC_COMMAND_NO_SETUID)) && !ambient_hack)
                                flags |= EXEC_COMMAND_NO_SETUID;
                        else if (*f == '!' && !FLAGS_SET(flags, EXEC_COMMAND_FULLY_PRIVILEGED) && !ambient_hack) {
                                /* Compatibility with the old !! ambient caps hack (removed in v258). Since
                                 * we don't support that anymore and !! was a noop on non-supporting systems,
                                 * we'll just turn off the EXEC_COMMAND_NO_SETUID flag again and be done with
                                 * it. */
                                flags &= ~EXEC_COMMAND_NO_SETUID;
                                ambient_hack = true;
 
                                log_syntax(unit, LOG_NOTICE, filename, line, 0,
                                           "The !! modifier for %s= lines is no longer supported and is now ignored. "
                                           "Please update your unit files and remove the modifier.", lvalue);
                        } else
                                break;
                }
 
                ignore = FLAGS_SET(flags, EXEC_COMMAND_IGNORE_FAILURE);
 
                _cleanup_strv_free_ char **args = NULL;
                _cleanup_free_ char *path = NULL;
 
                if (FLAGS_SET(flags, EXEC_COMMAND_VIA_SHELL)) {
                        /* Use _PATH_BSHELL as placeholder since we can't do NSS lookups in pid1. This would
                         * be exported to various dbus properties and is used to determine SELinux label -
                         * which isn't accurate, but is a best-effort thing to assume all shells have more
                         * or less the same label. */
                        path = strdup(_PATH_BSHELL);
                        if (!path)
                                return log_oom();
 
                        if (strv_extend_many(&args, separate_argv0 ? "-sh" : "sh", empty_to_null(f)) < 0)
                                return log_oom();
                } else {
                        r = unit_path_printf(u, f, &path);
                        if (r < 0) {
                                log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, r,
                                           "Failed to resolve unit specifiers in '%s'%s: %m",
                                           f, ignore ? ", ignoring" : "");
                                return ignore ? 0 : -ENOEXEC;
                        }
 
                        if (isempty(path)) {