HALF ECHO LEARN / REFERENCE COLLECTION
v262.2src/core/load-fragment.c
Git blob: cced46d969833bd05c914c99959caab3cb02b542
Lines 6001–6900 of 6,900
/* Empty assignment resets the list */
c->restrict_network_interfaces = set_free(c->restrict_network_interfaces);
return 0;
}
if (rvalue[0] == '~') {
is_allow_rule = false;
rvalue++;
}
if (set_isempty(c->restrict_network_interfaces))
/* Only initialize this when creating the set */
c->restrict_network_interfaces_is_allow_list = is_allow_rule;
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;
}
if (!ifname_valid_full(word, IFNAME_VALID_ALTERNATIVE)) {
log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid interface name, ignoring: %s", word);
continue;
}
if (c->restrict_network_interfaces_is_allow_list != is_allow_rule)
free(set_remove(c->restrict_network_interfaces, word));
else {
r = set_put_strdup(&c->restrict_network_interfaces, word);
if (r < 0)
return log_oom();
}
}
return 0;
}
int config_parse_mount_node(
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 *resolved = NULL, *path = NULL;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
r = unit_full_printf(u, rvalue, &resolved);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue);
return 0;
}
path = fstab_node_to_udev_node(resolved);
if (!path)
return log_oom();
/* The source passed is not necessarily something we understand, and we pass it as-is to mount/swapon,
* so path_is_valid is not used. But let's check for basic sanity, i.e. if the source is longer than
* PATH_MAX, you're likely doing something wrong. */
if (strlen(path) >= PATH_MAX) {
log_syntax(unit, LOG_WARNING, filename, line, 0, "Resolved mount path '%s' too long, ignoring.", path);
return 0;
}
return config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, path, data, userdata);
}
int config_parse_concurrency_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) {
unsigned *concurrency_max = ASSERT_PTR(data);
if (isempty(rvalue) || streq(rvalue, "infinity")) {
*concurrency_max = UINT_MAX;
return 0;
}
return config_parse_unsigned(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata);
}
int config_parse_bind_network_interface(
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 = ASSERT_PTR(data);
_cleanup_free_ char *k = NULL;
const Unit *u = ASSERT_PTR(userdata);
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
if (isempty(rvalue)) {
c->bind_network_interface = mfree(c->bind_network_interface);
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 (!ifname_valid_full(k, IFNAME_VALID_ALTERNATIVE)) {
log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid interface name, ignoring: %s", k);
return 0;
}
return free_and_strdup_warn(&c->bind_network_interface, k);
}
static int merge_by_names(Unit *u, Set *names, const char *id) {
char *k;
int r;
assert(u);
/* Let's try to add in all names that are aliases of this unit */
while ((k = set_steal_first(names))) {
_cleanup_free_ _unused_ char *free_k = k;
/* First try to merge in the other name into our unit */
r = unit_merge_by_name(u, k);
if (r < 0) {
Unit *other;
/* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
* round. */
other = manager_get_unit(u->manager, k);
if (!other)
return r; /* return previous failure */
r = unit_merge(other, u);
if (r < 0)
return r;
return merge_by_names(other, names, NULL);
}
if (streq_ptr(id, k))
unit_choose_id(u, id);
}
return 0;
}
static const char* builtin_unit_lookup(const char *name) {
assert(name);
FOREACH_ELEMENT(i, builtin_units)
if (streq(i->name, name))
return i->data;
return NULL;
}
int unit_load_fragment(Unit *u) {
int r;
assert(u);
assert(u->load_state == UNIT_STUB);
assert(u->id);
if (u->transient) {
u->access_selinux_context = mfree(u->access_selinux_context);
u->load_state = UNIT_LOADED;
return 0;
}
/* Possibly rebuild the fragment map to catch new units */
r = unit_file_build_name_map(&u->manager->lookup_paths,
&u->manager->unit_cache_timestamp_hash,
&u->manager->unit_id_map,
&u->manager->unit_name_map,
&u->manager->unit_path_cache);
if (r < 0)
return log_error_errno(r, "Failed to rebuild name map: %m");
const char *fragment;
_cleanup_set_free_ Set *names = NULL;
r = unit_file_find_fragment(u->manager->unit_id_map,
u->manager->unit_name_map,
u->id,
&fragment,
&names);
if (r < 0 && r != -ENOENT)
return r;
if (fragment) {
/* Open the file, check if this is a mask, otherwise read. */
_cleanup_fclose_ FILE *f = NULL;
struct stat st;
/* Try to open the file name. A symlink is OK, for example for linked files or masks. We
* expect that all symlinks within the lookup paths have been already resolved, but we don't
* verify this here. */
f = fopen(fragment, "re");
if (!f)
return log_unit_notice_errno(u, errno, "Failed to open %s: %m", fragment);
if (fstat(fileno(f), &st) < 0)
return -errno;
r = free_and_strdup(&u->fragment_path, fragment);
if (r < 0)
return r;
if (null_or_empty(&st)) {
/* Unit file is masked */
u->load_state = u->perpetual ? UNIT_LOADED : UNIT_MASKED; /* don't allow perpetual units to ever be masked */
u->fragment_mtime = 0;
u->access_selinux_context = mfree(u->access_selinux_context);
} else {
#if HAVE_SELINUX
if (mac_selinux_use()) {
_cleanup_freecon_ char *selcon = NULL;
/* Cache the SELinux context of the unit file here. We'll make use of when checking access permissions to loaded units */
r = sym_fgetfilecon_raw(fileno(f), &selcon);
if (r < 0)
log_unit_warning_errno(u, r, "Failed to read SELinux context of '%s', ignoring: %m", fragment);
r = free_and_strdup(&u->access_selinux_context, selcon);
if (r < 0)
return r;
} else
#endif
u->access_selinux_context = mfree(u->access_selinux_context);
u->load_state = UNIT_LOADED;
u->fragment_mtime = timespec_load(&st.st_mtim);
/* Now, parse the file contents */
r = config_parse(u->id, fragment, f,
UNIT_VTABLE(u)->sections,
config_item_perf_lookup, load_fragment_gperf_lookup,
/* flags= */ 0,
/* userdata= */ u,
/* ret_stat= */ NULL);
if (r == -ENOEXEC)
log_unit_notice_errno(u, r, "Unit configuration has fatal error, unit will not be started.");
if (r < 0)
return r;
}
} else if (u->manager->runtime_scope == RUNTIME_SCOPE_SYSTEM) {
/* No fragment found on disk. For system units, fall back to a built-in copy if we have one
* embedded. This way the manager can reach a usable state even if none of these unit files
* are installed. On-disk files always take precedence (including masks), since we only get
* here when nothing was found in the lookup paths. */
const char *data = builtin_unit_lookup(u->id);
if (data) {
_cleanup_fclose_ FILE *f = NULL;
f = fmemopen_unlocked((void*) data, strlen(data), "re");
if (!f)
return log_oom();
log_unit_debug(u, "Loading built-in fragment for %s.", u->id);
u->load_state = UNIT_LOADED;
u->fragment_mtime = 0;
r = config_parse(u->id, u->id, f,
UNIT_VTABLE(u)->sections,
config_item_perf_lookup, load_fragment_gperf_lookup,
/* flags= */ 0,
/* userdata= */ u,
/* ret_stat= */ NULL);
if (r == -ENOEXEC)
log_unit_notice_errno(u, r, "Built-in unit configuration has fatal error, unit will not be started.");
if (r < 0)
return r;
}
}
/* Call merge_by_names with the name derived from the fragment path as the preferred name.
*
* We do the merge dance here because for some unit types, the unit might have aliases which are not
* declared in the file system. In particular, this is true (and frequent) for device and swap units.
*/
const char *id = u->id;
_cleanup_free_ char *filename = NULL, *free_id = NULL;
if (fragment) {
r = path_extract_filename(fragment, &filename);
if (r < 0)
return log_debug_errno(r, "Failed to extract filename from fragment '%s': %m", fragment);
id = filename;
if (unit_name_is_valid(id, UNIT_NAME_TEMPLATE)) {
assert(u->instance); /* If we're not trying to use a template for non-instanced unit,
* this must be set. */
r = unit_name_replace_instance(id, u->instance, &free_id);
if (r < 0)
return log_debug_errno(r, "Failed to build id (%s + %s): %m", id, u->instance);
id = free_id;
}
}
return merge_by_names(u, names, id);
}
void unit_dump_config_items(FILE *f) {
static const struct {
const ConfigParserCallback callback;
const char *rvalue;
} table[] = {
{ config_parse_warn_compat, "NOTSUPPORTED" },
{ config_parse_int, "INTEGER" },
{ config_parse_unsigned, "UNSIGNED" },
{ config_parse_iec_size, "SIZE" },
{ config_parse_iec_uint64, "SIZE" },
{ config_parse_si_uint64, "SIZE" },
{ config_parse_bool, "BOOLEAN" },
{ config_parse_string, "STRING" },
{ config_parse_path, "PATH" },
{ config_parse_unit_path_printf, "PATH" },
{ config_parse_colon_separated_paths, "PATH" },
{ config_parse_strv, "STRING [...]" },
{ config_parse_exec_nice, "NICE" },
{ config_parse_exec_oom_score_adjust, "OOMSCOREADJUST" },
{ config_parse_exec_io_class, "IOCLASS" },
{ config_parse_exec_io_priority, "IOPRIORITY" },
{ config_parse_exec_cpu_sched_policy, "CPUSCHEDPOLICY" },
{ config_parse_exec_cpu_sched_prio, "CPUSCHEDPRIO" },
{ config_parse_exec_cpu_affinity, "CPUAFFINITY" },
{ config_parse_mode, "MODE" },
{ config_parse_unit_env_file, "FILE" },
{ config_parse_exec_output, "OUTPUT" },
{ config_parse_exec_input, "INPUT" },
{ config_parse_log_facility, "FACILITY" },
{ config_parse_log_level, "LEVEL" },
{ config_parse_exec_secure_bits, "SECUREBITS" },
{ config_parse_capability_set, "BOUNDINGSET" },
{ config_parse_rlimit, "LIMIT" },
{ config_parse_unit_deps, "UNIT [...]" },
{ config_parse_exec, "PATH [ARGUMENT [...]]" },
{ config_parse_service_type, "SERVICETYPE" },
{ config_parse_service_exit_type, "SERVICEEXITTYPE" },
{ config_parse_service_restart, "SERVICERESTART" },
{ config_parse_service_restart_mode, "SERVICERESTARTMODE" },
{ config_parse_service_timeout_failure_mode, "TIMEOUTMODE" },
{ config_parse_kill_mode, "KILLMODE" },
{ config_parse_signal, "SIGNAL" },
{ config_parse_socket_listen, "SOCKET [...]" },
{ config_parse_socket_bind, "SOCKETBIND" },
{ config_parse_socket_bindtodevice, "NETWORKINTERFACE" },
{ config_parse_sec, "SECONDS" },
{ config_parse_nsec, "NANOSECONDS" },
{ config_parse_namespace_path_strv, "PATH [...]" },
{ config_parse_bind_paths, "PATH[:PATH[:OPTIONS]] [...]" },
{ config_parse_unit_mounts_for, "PATH [...]" },
{ config_parse_exec_mount_propagation_flag,
"MOUNTFLAG" },
{ config_parse_unit_string_printf, "STRING" },
{ config_parse_trigger_unit, "UNIT" },
{ config_parse_timer, "TIMER" },
{ config_parse_path_spec, "PATH" },
{ config_parse_notify_access, "ACCESS" },
{ config_parse_ip_tos, "TOS" },
{ config_parse_unit_condition_path, "CONDITION" },
{ config_parse_unit_condition_string, "CONDITION" },
{ config_parse_unit_slice, "SLICE" },
{ config_parse_documentation, "URL" },
{ config_parse_service_timeout, "SECONDS" },
{ config_parse_emergency_action, "ACTION" },
{ config_parse_set_status, "STATUS" },
{ config_parse_service_sockets, "SOCKETS" },
{ config_parse_environ, "ENVIRON" },
#if HAVE_SECCOMP
{ config_parse_syscall_filter, "SYSCALLS" },
{ config_parse_syscall_archs, "ARCHS" },
{ config_parse_syscall_errno, "ERRNO" },
{ config_parse_syscall_log, "SYSCALLS" },
{ config_parse_address_families, "FAMILIES" },
#endif
{ config_parse_namespace_flags, "NAMESPACES" },
{ config_parse_restrict_filesystems, "FILESYSTEMS" },
{ config_parse_cg_weight, "WEIGHT" },
{ config_parse_cg_cpu_weight, "CPUWEIGHT" },
{ config_parse_memory_limit, "LIMIT" },
{ config_parse_device_allow, "DEVICE" },
{ config_parse_device_policy, "POLICY" },
{ config_parse_io_limit, "LIMIT" },
{ config_parse_io_device_weight, "DEVICEWEIGHT" },
{ config_parse_io_device_latency, "DEVICELATENCY" },
{ config_parse_long, "LONG" },
{ config_parse_socket_service, "SERVICE" },
#if HAVE_SELINUX
{ config_parse_exec_selinux_context, "LABEL" },
#endif
{ config_parse_job_mode, "MODE" },
{ config_parse_job_mode_isolate, "BOOLEAN" },
{ config_parse_personality, "PERSONALITY" },
{ config_parse_log_filter_patterns, "REGEX" },
{ config_parse_mount_node, "NODE" },
{ config_parse_bpf_delegate_commands, "BPF_DELEGATE_COMMANDS" },
{ config_parse_bpf_delegate_maps, "BPF_DELEGATE_MAPS" },
{ config_parse_bpf_delegate_programs, "BPF_DELEGATE_PROGRAMS" },
{ config_parse_bpf_delegate_attachments, "BPF_DELEGATE_ATTACHMENTS" },
};
const char *prev = NULL;
assert(f);
NULSTR_FOREACH(i, load_fragment_gperf_nulstr) {
const char *rvalue = "OTHER", *lvalue;
const ConfigPerfItem *p;
const char *dot;
assert_se(p = load_fragment_gperf_lookup(i, strlen(i)));
/* Hide legacy settings */
if (p->parse == config_parse_warn_compat &&
p->ltype == DISABLED_LEGACY)
continue;
FOREACH_ELEMENT(j, table)
if (p->parse == j->callback) {
rvalue = j->rvalue;
break;
}
dot = strchr(i, '.');
lvalue = dot ? dot + 1 : i;
if (dot) {
size_t prefix_len = dot - i;
if (!prev || !strneq(prev, i, prefix_len+1)) {
if (prev)
fputc('\n', f);
fprintf(f, "[%.*s]\n", (int) prefix_len, i);
}
}
fprintf(f, "%s=%s\n", lvalue, rvalue);
prev = i;
}
}
int config_parse_show_status(
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) {
int k;
ShowStatus *b = ASSERT_PTR(data);
assert(filename);
assert(lvalue);
assert(rvalue);
k = parse_show_status(rvalue, b);
if (k < 0)
log_syntax(unit, LOG_WARNING, filename, line, k, "Failed to parse show status setting, ignoring: %s", rvalue);
return 0;
}
int config_parse_output_restricted(
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) {
ExecOutput t, *eo = ASSERT_PTR(data);
bool obsolete = false;
assert(filename);
assert(lvalue);
assert(rvalue);
if (streq(rvalue, "syslog")) {
t = EXEC_OUTPUT_JOURNAL;
obsolete = true;
} else if (streq(rvalue, "syslog+console")) {
t = EXEC_OUTPUT_JOURNAL_AND_CONSOLE;
obsolete = true;
} else {
t = exec_output_from_string(rvalue);
if (t < 0) {
log_syntax(unit, LOG_WARNING, filename, line, t, "Failed to parse output type, ignoring: %s", rvalue);
return 0;
}
if (IN_SET(t, EXEC_OUTPUT_SOCKET, EXEC_OUTPUT_NAMED_FD, EXEC_OUTPUT_FILE, EXEC_OUTPUT_FILE_APPEND, EXEC_OUTPUT_FILE_TRUNCATE)) {
log_syntax(unit, LOG_WARNING, filename, line, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue);
return 0;
}
}
if (obsolete)
log_syntax(unit, LOG_NOTICE, filename, line, 0,
"Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
rvalue, exec_output_to_string(t));
*eo = t;
return 0;
}
int config_parse_crash_chvt(
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) {
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
r = parse_crash_chvt(rvalue, data);
if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue);
return 0;
}
int config_parse_swap_priority(
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) {
Swap *s = ASSERT_PTR(userdata);
int r, priority;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
if (isempty(rvalue)) {
s->parameters_fragment.priority = -1;
s->parameters_fragment.priority_set = false;
return 0;
}
r = safe_atoi(rvalue, &priority);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid swap priority '%s', ignoring.", rvalue);
return 0;
}
if (priority < -1) {
log_syntax(unit, LOG_WARNING, filename, line, 0, "Sorry, swap priorities smaller than -1 may only be assigned by the kernel itself, ignoring: %s", rvalue);
return 0;
}
if (priority > 32767) {
log_syntax(unit, LOG_WARNING, filename, line, 0, "Swap priority out of range, ignoring: %s", rvalue);
return 0;
}
s->parameters_fragment.priority = priority;
s->parameters_fragment.priority_set = true;
return 0;
}
int config_parse_watchdog_sec(
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 *usec = data;
assert(filename);
assert(lvalue);
assert(rvalue);
/* This is called for {Runtime,Reboot,KExec}WatchdogSec= where "default" maps to
* USEC_INFINITY internally. */
if (streq(rvalue, "default"))
*usec = USEC_INFINITY;
else if (streq(rvalue, "off"))
*usec = 0;
else
return config_parse_sec(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata);
return 0;
}
int config_parse_tty_size(
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 *sz = data;
assert(filename);
assert(lvalue);
assert(rvalue);
if (isempty(rvalue)) {
*sz = UINT_MAX;
return 0;
}
return config_parse_unsigned(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata);
}
int config_parse_log_filter_patterns(
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 char *pattern = ASSERT_PTR(rvalue);
bool is_allowlist = true;
int r;
assert(filename);
assert(lvalue);
if (isempty(pattern)) {
/* Empty assignment resets the lists. */
c->log_filter_allowed_patterns = set_free(c->log_filter_allowed_patterns);
c->log_filter_denied_patterns = set_free(c->log_filter_denied_patterns);
return 0;
}
if (pattern[0] == '~') {
is_allowlist = false;
pattern++;
if (isempty(pattern))
/* LogFilterPatterns=~ is not considered a valid pattern. */
return log_syntax(unit, LOG_WARNING, filename, line, 0,
"Regex pattern invalid, ignoring: %s=%s", lvalue, rvalue);
}
if (pattern_compile_and_log(pattern, 0, NULL) < 0)
return 0;
r = set_put_strdup(is_allowlist ? &c->log_filter_allowed_patterns : &c->log_filter_denied_patterns,
pattern);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed to store log filtering pattern, ignoring: %s=%s", lvalue, rvalue);
return 0;
}
return 0;
}
int config_parse_open_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) {
_cleanup_(open_file_freep) OpenFile *of = NULL;
OpenFile **head = ASSERT_PTR(data);
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
if (isempty(rvalue)) {
open_file_free_many(head);
return 0;
}
r = open_file_parse(rvalue, &of);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse OpenFile= setting, ignoring: %s", rvalue);
return 0;
}
LIST_APPEND(open_files, *head, TAKE_PTR(of));
return 0;
}
int config_parse_cgroup_nft_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) {
CGroupContext *c = ASSERT_PTR(data);
Unit *u = ASSERT_PTR(userdata);
return config_parse_nft_set(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &c->nft_set_context, u);
}
int config_parse_protect_hostname(
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);
Unit *u = ASSERT_PTR(userdata);
_cleanup_free_ char *h = NULL, *p = NULL;
int r;
if (isempty(rvalue)) {
c->protect_hostname = PROTECT_HOSTNAME_NO;
c->private_hostname = mfree(c->private_hostname);
return 1;
}
const char *colon = strchr(rvalue, ':');
if (colon) {
r = unit_full_printf_full(u, colon + 1, LINUX_HOST_NAME_MAX, &h);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed to resolve unit specifiers in '%s', ignoring: %m", colon + 1);
return 0;
}
if (!hostname_is_valid(h, /* flags= */ 0))
return log_syntax(unit, LOG_WARNING, filename, line, 0,
"Invalid hostname is specified to %s=, ignoring: %s", lvalue, h);
p = strndup(rvalue, colon - rvalue);
if (!p)
return log_oom();
}
ProtectHostname t = protect_hostname_from_string(p ?: rvalue);
if (t < 0 || (t == PROTECT_HOSTNAME_NO && h))
return log_syntax_parse_error(unit, filename, line, 0, lvalue, rvalue);
c->protect_hostname = t;
free_and_replace(c->private_hostname, h);
return 1;
}
int config_parse_luo_sessions(
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 ***sessions = ASSERT_PTR(data);
assert(filename);
assert(lvalue);
assert(rvalue);
if (isempty(rvalue)) {
*sessions = strv_free(*sessions);
return 0;
}
for (const char *p = rvalue;;) {
_cleanup_free_ char *word = NULL;
int r;
r = extract_first_word(&p, &word, /* separators= */ NULL, /* flags= */ 0);
if (r == -ENOMEM)
return log_oom();
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed to parse LUOSession= value, ignoring: %s", rvalue);
return 0;
}
if (r == 0) {
strv_sort(*sessions);
return 0;
}
if (!luo_session_name_is_valid(word)) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"LUO session name contains invalid characters, ignoring: %s", word);
continue;
}
if (strv_contains(*sessions, word)) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Duplicate LUO session name, ignoring: %s", word);
continue;
}
r = strv_extend(sessions, word);
if (r < 0)
return log_oom();
}
}