Correctly handle masked systemd units in distro validation script (#12494)
Blue committed
Jan 24, 2025 at 11:39 UTC
235561efb9a1fd3e1a582f98c15d8abefba60c56
1 file changed
+17
-2
distributions/validate-modern.py
+17
-2
@@ -209,7 +209,10 @@ def read_systemd_enabled_units(flavor: str, name: str, tar) -> dict:
209
if not info.issym():
210
return unit_path
211
else:
212
- return info.linkpath
212
+ if info.linkpath.startswith('/'):
213
+ return get_tar_file(tar, linux_real_path(info.linkpath), follow_symlink=True)[1]
214
+ else:
215
+ return get_tar_file(tar, linux_real_path(os.path.dirname(unit_path) + '/' + info.linkpath), follow_symlink=True)[1]
216
217
def list_directory(path: str):
218
files = []
@@ -221,6 +224,17 @@ def read_systemd_enabled_units(flavor: str, name: str, tar) -> dict:
224
225
return files
226
227
+ def is_dev_null(path: str) -> bool:
228
+ return path == './dev/null' or path == '/dev/null'
229
+
230
+ def is_masked(unit: str):
231
+ try:
232
+ target = link_target(f'/etc/systemd/system/{unit}')
233
+ except KeyError:
234
+ return False # No symlink found, unit is not masked
235
+
236
+ return is_dev_null(target)
237
+
238
units = {}
239
for config_dir in config_dirs:
240
targets = [e for e in list_directory(config_dir) if e.endswith('.target.wants')]
@@ -228,9 +242,10 @@ def read_systemd_enabled_units(flavor: str, name: str, tar) -> dict:
242
for target in targets:
243
for e in list_directory(f'{config_dir}/{target}'):
244
fullpath = f'{config_dir}/{target}/{e}'
245
+
246
unit_target = link_target(fullpath)
247
233
- if unit_target != '/dev/null':
248
+ if is_dev_null(unit_target) and not is_masked(e):
249
units[e] = fullpath
250
251
return units