summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-03-05 21:09:05 +0000
committerChristian Breunig <christian@breunig.cc>2026-03-05 22:18:56 +0100
commit8e9e278750ee52a0d7e057c0666555b03880ced0 (patch)
tree3ea2d67553fc71a750b68b2bed32eaa70a4d36cc /python
parent838cf65b1c181b7b4f00ae712166065bad0fbf54 (diff)
downloadvyos-1x-8e9e278750ee52a0d7e057c0666555b03880ced0.tar.gz
vyos-1x-8e9e278750ee52a0d7e057c0666555b03880ced0.zip
vyos.debug: T8347: fix UnboundLocalError in try/finally statement
Pylint warns about mask being used before assignment because mask is created inside the try block. While os.umask() itself is highly unlikely to fail, Python can raise asynchronous exceptions like KeyboardInterrupt or MemoryError at any given moment. If one of those exceptions occurs precisely after the try: statement but before "mask = os.umask(0o111)" completes, Python calls finally with "os.umask(mask)" causing UnboundLocalError.
Diffstat (limited to 'python')
-rw-r--r--python/vyos/debug.py3
1 files changed, 1 insertions, 2 deletions
diff --git a/python/vyos/debug.py b/python/vyos/debug.py
index 5b6e8172e..1a6924ef5 100644
--- a/python/vyos/debug.py
+++ b/python/vyos/debug.py
@@ -38,13 +38,12 @@ def message(message, flag='', destination=sys.stdout):
if not logfile:
return enable
+ mask = os.umask(0o111)
try:
# at boot the file is created as root:vyattacfg
# at runtime the file is created as user:vyattacfg
# but the helper scripts are not run as this so it
# need the default permission to be 666 (an not 660)
- mask = os.umask(0o111)
-
with open(logfile, 'a') as f:
f.write(_timed(_format('log', message)))
finally: