diff --git a/rpmlint/checks/SystemdInstallCheck.py b/rpmlint/checks/SystemdInstallCheck.py index 630390317..125ce547b 100644 --- a/rpmlint/checks/SystemdInstallCheck.py +++ b/rpmlint/checks/SystemdInstallCheck.py @@ -30,20 +30,26 @@ def check(self, pkg): PREUN_PATTERN = re.compile(r'systemctl --no-reload disable .*' + escaped_basename) POSTUN_PATTERN = re.compile(r'(systemctl try-restart .*|# Restart of .*)' + escaped_basename) + # systemd macro expansion using systemd-update-helper + PRE_HELPER_PATTERN = re.compile(r'systemd-update-helper mark-install-system-units .*' + escaped_basename) + POST_HELPER_PATTERN = re.compile(r'systemd-update-helper install-system-units .*' + escaped_basename) + PREUN_HELPER_PATTERN = re.compile(r'systemd-update-helper remove-system-units .*' + escaped_basename) + POSTUN_HELPER_PATTERN = re.compile(r'systemd-update-helper mark-restart-system-units .*' + escaped_basename) + for line in pre.split('\n'): - if PRE_POST_PATTERN.search(line): + if PRE_POST_PATTERN.search(line) or PRE_HELPER_PATTERN.search(line): processed['pre'] = True break for line in post.split('\n'): - if PRE_POST_PATTERN.search(line): + if PRE_POST_PATTERN.search(line) or POST_HELPER_PATTERN.search(line): processed['post'] = True break for line in preun.split('\n'): - if PREUN_PATTERN.search(line): + if PREUN_PATTERN.search(line) or PREUN_HELPER_PATTERN.search(line): processed['preun'] = True break for line in postun.split('\n'): - if POSTUN_PATTERN.search(line): + if POSTUN_PATTERN.search(line) or POSTUN_HELPER_PATTERN.search(line): processed['postun'] = True break diff --git a/test/binary/nvme-cli-2.6-163.3.x86_64.rpm b/test/binary/nvme-cli-2.6-163.3.x86_64.rpm new file mode 100644 index 000000000..bb0111a9a Binary files /dev/null and b/test/binary/nvme-cli-2.6-163.3.x86_64.rpm differ diff --git a/test/binary/sarg-2.4.0-60.1.x86_64.rpm b/test/binary/sarg-2.4.0-60.1.x86_64.rpm new file mode 100644 index 000000000..5328a5577 Binary files /dev/null and b/test/binary/sarg-2.4.0-60.1.x86_64.rpm differ diff --git a/test/test_systemd_install.py b/test/test_systemd_install.py index 12fc8c9d5..43b71c3b1 100644 --- a/test/test_systemd_install.py +++ b/test/test_systemd_install.py @@ -23,3 +23,15 @@ def test_bashisms(tmp_path, package, systemdinstallcheck): for scriptlet_type in ['add_pre', 'add_post', 'del_preun', 'del_postun']: message = f'systemd-service-without-service_{scriptlet_type} dnf-automatic-download.service' assert message in out + + +@pytest.mark.parametrize('package', ['binary/sarg', 'binary/nvme-cli']) +@pytest.mark.skipif(IS_FEDORA_RELEASE, reason='Fedora does not define %{_unitdir} rpm macro') +def test_systemd_service_preun(tmp_path, package, systemdinstallcheck): + output, test = systemdinstallcheck + test.check(get_tested_package(package, tmp_path)) + out = output.print_results(output.results) + + for scriptlet_type in ['add_pre', 'add_post', 'del_preun', 'del_postun']: + message = f'systemd-service-without-service_{scriptlet_type}' + assert message not in out