From 785dafc3bcafa24e55eca2e1f9c7e3de47c1fafa Mon Sep 17 00:00:00 2001 From: Henrik Muehe Date: Sun, 3 May 2026 14:03:58 +0200 Subject: [PATCH] Log: tolerate missing rotated log files on startup Recursive _rotate() may have already moved or unlinked the source path by the time we try to rename it (also tolerates concurrent logrotate runs from /etc/cron.reboot). Catch FileNotFoundError instead of crashing bbctrl on startup. --- src/py/bbctrl/Log.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/py/bbctrl/Log.py b/src/py/bbctrl/Log.py index 87f694f..6fed9f7 100644 --- a/src/py/bbctrl/Log.py +++ b/src/py/bbctrl/Log.py @@ -182,4 +182,11 @@ class Log(object): if n == 16: os.unlink(fullpath) else: self._rotate(path, nextN) - os.rename(fullpath, '%s.%d' % (path, nextN)) + # The recursive call may have unlinked or rotated this + # path; tolerate a missing source rather than crashing + # bbctrl on startup. This also tolerates concurrent + # logrotate runs from /etc/cron.reboot. + try: + os.rename(fullpath, '%s.%d' % (path, nextN)) + except FileNotFoundError: + pass