mirror of
https://github.com/systemd/systemd.git
synced 2025-02-09 13:57:42 +03:00
shared/install: ignore Alias in [Install] of units which don't allow aliases
A downside is that a warning about missing [Install] is printed: $ systemctl --root=/ enable mnt-test.mount [/etc/systemd/system/mnt-test.mount:5] Aliases are not allowed for mount units, ignoring. The unit files have no installation config (WantedBy, RequiredBy, Also, Alias settings in the [Install] section, and DefaultInstance for template units). This means they are not meant to be enabled using systemctl. Possible reasons for having this kind of units are: 1) A unit may be statically enabled by being symlinked from another unit's .wants/ or .requires/ directory. 2) A unit's purpose may be to act as a helper for some other unit which has a requirement dependency on it. 3) A unit may be started when needed via activation (socket, path, timer, D-Bus, udev, scripted systemctl call, ...). 4) In case of template units, the unit is meant to be enabled with some instance name specified. That's a bit misleading, but I don't see an easy way to fix this. But the situation is similar for many other parsing errors, so maybe that's OK.
This commit is contained in:
parent
8a993b61d1
commit
a772458901
@ -908,6 +908,36 @@ fail:
|
||||
return r;
|
||||
}
|
||||
|
||||
static int config_parse_alias(
|
||||
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 char *name;
|
||||
UnitType type;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
|
||||
name = basename(filename);
|
||||
type = unit_name_to_type(name);
|
||||
if (!unit_type_may_alias(type))
|
||||
return log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"Aliases are not allowed for %s units, ignoring.",
|
||||
unit_type_to_string(type));
|
||||
|
||||
return config_parse_strv(unit, filename, line, section, section_line,
|
||||
lvalue, ltype, rvalue, data, userdata);
|
||||
}
|
||||
|
||||
static int config_parse_also(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
@ -993,7 +1023,7 @@ static int unit_file_load(
|
||||
SearchFlags flags) {
|
||||
|
||||
const ConfigTableItem items[] = {
|
||||
{ "Install", "Alias", config_parse_strv, 0, &info->aliases },
|
||||
{ "Install", "Alias", config_parse_alias, 0, &info->aliases },
|
||||
{ "Install", "WantedBy", config_parse_strv, 0, &info->wanted_by },
|
||||
{ "Install", "RequiredBy", config_parse_strv, 0, &info->required_by },
|
||||
{ "Install", "DefaultInstance", config_parse_default_instance, 0, info },
|
||||
|
Loading…
x
Reference in New Issue
Block a user