From 1f8cb72734bdd82749ce8c8e5b8876f559607722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Tue, 3 Mar 2026 20:24:50 +0100 Subject: [PATCH] commands: better error msgs when creating directory and hardened dir mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The directory mode should be already hardened with the umask on most systems, so it shouldn't be the default 0x777, but rather be explicit with the saner 0x755. Signed-off-by: Jaroslav Škarvada --- tuned/utils/commands.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tuned/utils/commands.py b/tuned/utils/commands.py index e79a190..f7430a4 100644 --- a/tuned/utils/commands.py +++ b/tuned/utils/commands.py @@ -108,9 +108,15 @@ class commands: d = os.path.dirname(f) if os.path.isdir(d): makedir = False + if makedir: + try: + os.makedirs(d, mode=0o755) + except (OSError, IOError) as e: + if isinstance(no_error, bool) and not no_error or \ + isinstance(no_error, list) and e.errno not in no_error: + self._error("Unable to create directory '%s', error: '%s'" % (d, e)) + return False try: - if makedir: - os.makedirs(d) if ignore_same and self.read_file(f, no_error=True).strip() == str(data): self._debug("Skipping the write to file '%s', the content would not change" % f) return True