Skip to content

Commit

Permalink
SystemdInstallCheck: Support systemd-update-helper
Browse files Browse the repository at this point in the history
systemd macros expands to a script using systemd-update-helper, this
patch add some regular expressions to detect the usage of this macro in
pre, post, preun and postun, to avoid false possitive when using this
macro.

See https://bugzilla.suse.com/show_bug.cgi?id=1091680
  • Loading branch information
danigm committed Oct 27, 2023
1 parent 2713543 commit 2b18eaf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
14 changes: 10 additions & 4 deletions rpmlint/checks/SystemdInstallCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Binary file added test/binary/nvme-cli-2.6-163.3.x86_64.rpm
Binary file not shown.
Binary file added test/binary/sarg-2.4.0-60.1.x86_64.rpm
Binary file not shown.
12 changes: 12 additions & 0 deletions test/test_systemd_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2b18eaf

Please sign in to comment.