Skip to content

Commit

Permalink
ncm-systemd: Only validate units if they are present
Browse files Browse the repository at this point in the history
  • Loading branch information
jrha authored and jouvin committed Dec 12, 2024
1 parent ec20d0d commit fa787fa
Showing 1 changed file with 39 additions and 21 deletions.
60 changes: 39 additions & 21 deletions ncm-systemd/src/main/pan/components/systemd/schema.pan
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ type hwloc_location = string with match(SELF, '^[\w:.]+$');
@documentation{
syslog facility to use when logging to syslog
}
type syslog_facility = string with match(SELF,
'^(kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|authpriv|ftp|local[0-7])$');
type syslog_facility = string with match(
SELF,
'^(kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|authpriv|ftp|local[0-7])$'
);

@documentation{
syslog level to use when logging to syslog or the kernel log buffer
Expand All @@ -28,15 +30,19 @@ type ${project.artifactId}_skip = {
"service" : boolean = false
} = dict();

type ${project.artifactId}_unit_architecture = string with match(SELF,
type ${project.artifactId}_unit_architecture = string with match(
SELF,
'^(native|x86(-64)?|ppc(64)?(-le)?|ia64|parisc(64)?|s390x?|sparc(64)?)' +
'|mips(-le)?|alpha|arm(64)?(-be)?|sh(64)?|m86k|tilegx|cris$');
'|mips(-le)?|alpha|arm(64)?(-be)?|sh(64)?|m86k|tilegx|cris$'
);

type ${project.artifactId}_unit_security = string with match(SELF, '^!?(selinux|apparmor|ima|smack|audit)$');

type ${project.artifactId}_unit_virtualization = string with match(SELF,
type ${project.artifactId}_unit_virtualization = string with match(
SELF,
'^(0|1|vm|container|qemu|kvm|zvm|vmware|microsoft|oracle|xen' +
'|bochs|uml|openvz|lxc(-libvirt)?|systemd-nspawn|docker)$');
'|bochs|uml|openvz|lxc(-libvirt)?|systemd-nspawn|docker)$'
);

# TODO: https://github.com/quattor/configuration-modules-core/issues/646:
# make this more finegrained, e.g. has to be existing unit; or check types
Expand Down Expand Up @@ -119,8 +125,10 @@ type ${project.artifactId}_unitfile_config_unit = {
'JoinsNamespaceOf' ? ${project.artifactId}_valid_unit[]
'NetClass' ? string
'OnFailure' ? string[]
'OnFailureJobMode' ? string with match(SELF,
'^(fail|replace(-irreversibly)?|isolate|flush|ignore-(dependencies|requirements))$')
'OnFailureJobMode' ? string with match(
SELF,
'^(fail|replace(-irreversibly)?|isolate|flush|ignore-(dependencies|requirements))$'
)
'PartOf' ? ${project.artifactId}_valid_unit[]
'PropagatesReloadTo' ? string[]
'RefuseManualStart' ? boolean
Expand Down Expand Up @@ -148,8 +156,10 @@ type ${project.artifactId}_unitfile_config_install = {
'WantedBy' ? ${project.artifactId}_valid_unit[]
};

type ${project.artifactId}_unitfile_config_systemd_exec_stdouterr = string with match(SELF,
'^(inherit|null|tty|journal|syslog|kmsg|journal+console|syslog+console|kmsg+console|socket)$');
type ${project.artifactId}_unitfile_config_systemd_exec_stdouterr = string with match(
SELF,
'^(inherit|null|tty|journal|syslog|kmsg|journal+console|syslog+console|kmsg+console|socket)$'
);

@documentation{
systemd.kill directives
Expand All @@ -158,8 +168,10 @@ valid for [Service], [Socket], [Mount], or [Swap] sections
}
type ${project.artifactId}_unitfile_config_systemd_kill = {
'KillMode' ? string with match(SELF, '^(control-group|process|mixed|none)$')
'KillSignal' ? string with match(SELF,
'^SIG(HUP|INT|QUIT|ILL|ABRT|FPE|KILL|SEGV|PIPE|ALRM|TERM|USR[12]|CHLD|CONT|STOP|T(STP|TIN|TOU))$')
'KillSignal' ? string with match(
SELF,
'^SIG(HUP|INT|QUIT|ILL|ABRT|FPE|KILL|SEGV|PIPE|ALRM|TERM|USR[12]|CHLD|CONT|STOP|T(STP|TIN|TOU))$'
)
'SendSIGHUP' ? boolean
'SendSIGKILL' ? boolean
};
Expand Down Expand Up @@ -228,11 +240,15 @@ type ${project.artifactId}_unitfile_config_systemd_exec = {
'WorkingDirectory' ? string
};

type ${project.artifactId}_unitfile_config_systemd_resource_control_devicelist = string[] with length(SELF) == 2 &&
match(SELF[0], '^(char-|block-|/dev/)') && match(SELF[1], '^[rwm]{1,3}$');
type ${project.artifactId}_unitfile_config_systemd_resource_control_devicelist = string[] with (
length(SELF) == 2 &&
match(SELF[0], '^(char-|block-|/dev/)') && match(SELF[1], '^[rwm]{1,3}$')
);

type ${project.artifactId}_unitfile_config_systemd_resource_control_block_weight = string[] with length(SELF) == 2 &&
match(SELF[0], '^/') && match(SELF[1], '^[0-9]+$');
type ${project.artifactId}_unitfile_config_systemd_resource_control_block_weight = string[] with (
length(SELF) == 2 &&
match(SELF[0], '^/') && match(SELF[1], '^[0-9]+$')
);

@documentation{
systemd.resource-control directives
Expand Down Expand Up @@ -537,11 +553,13 @@ type ${project.artifactId}_component = {
# escaped full unitnames are allowed (or use shortnames and type)
"unit" ? ${project.artifactId}_unit_type{}
} with {
foreach(name; unit; SELF["unit"]) {
if (unit["type"] == "mount" && exists(unit["file"]) && exists(unit["file"]["config"]["mount"])) {
goodname = systemd_make_mountunit(unit["file"]["config"]["mount"]["Where"]);
if(goodname != name) {
error('Incorrect name for mount unit, the name must match Where: %s vs %s', name, goodname);
if (is_defined(SELF["unit"])) {
foreach(name; unit; SELF["unit"]) {
if (unit["type"] == "mount" && exists(unit["file"]) && exists(unit["file"]["config"]["mount"])) {
goodname = systemd_make_mountunit(unit["file"]["config"]["mount"]["Where"]);
if(goodname != name) {
error('Incorrect name for mount unit, the name must match Where: %s vs %s', name, goodname);
};
};
};
};
Expand Down

0 comments on commit fa787fa

Please sign in to comment.