Skip to content

Commit 59fc41c

Browse files
committed
add a check for deprectated cmdline args
Signed-off-by: Zen <[email protected]>
1 parent 0be4c06 commit 59fc41c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/ugrd/base/cmdline.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
__version__ = "4.2.0"
33

44
from importlib.metadata import PackageNotFoundError, version
5+
from pathlib import Path
6+
from re import search
57

68
from ugrd.exceptions import ValidationError
79
from zenlib.util import colorize as c_
810

911
# Some arguments absolutely must be namespaced and should only be used by the kernel
1012
FORCE_NAMESPACE = ["debug"]
1113

14+
# Check for old args being used
15+
DEPRECATED_ARGS = ["debug", "recovery"]
16+
1217
def _check_namespaced_arg(self, arg: str) -> bool:
1318
"""Checks if the argument is namespaced or not.
1419
Unless explicitly allowed, all arguments should be namespaced.
@@ -152,3 +157,14 @@ def export_exports(self) -> list[str]:
152157
export_lines = [f'setvar "{key}" "{value}"' for key, value in self["exports"].items()]
153158

154159
return check_lines + export_lines + ["setvar exported 1"]
160+
161+
def check_proc_cmdline(self):
162+
""" Checks for possible invalid cmdline args in /proc/cmdline. """
163+
cmdline = Path("/proc/cmdline").read_text().strip()
164+
self.logger.debug(f"Current cmdline: {c_(cmdline, 'green')}")
165+
166+
for arg in DEPRECATED_ARGS:
167+
if search(rf"\b{arg}(\b|=)", cmdline):
168+
self.logger.warning(f"Detected deprecated cmdline arg: {c_(arg, 'red')}")
169+
self.logger.warning("Please check the documentation for the updated usage.")
170+

src/ugrd/base/cmdline.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ _non_namespaced_cmdline_args = ["init", "resume", "root", "rootdelay", "rootflag
1010
[imports.init_pre]
1111
"ugrd.base.cmdline" = [ "export_exports", "parse_cmdline" ]
1212

13+
[imports.checks]
14+
"ugrd.base.cmdline" = [ "check_proc_cmdline" ]
15+
1316
[imports.functions]
1417
"ugrd.base.cmdline" = [ "parse_cmdline_bool", "parse_cmdline_str" ]
1518

0 commit comments

Comments
 (0)