backend systemd: fixes error "local variable 'line' referenced before assignment", introduced in 55d7d9e214f72bbe4f39a2d17aa004d80bfc7299;

don't update database too often (every 10 ticks or ~ 10 seconds in production);
closes gh-3097
pull/3117/head
sebres 2021-09-08 19:42:08 +02:00
parent 1e4a14fb25
commit e323c148e1
1 changed files with 10 additions and 1 deletions

View File

@ -61,6 +61,7 @@ class FilterSystemd(JournalFilter): # pragma: systemd no cover
# Initialise systemd-journal connection
self.__journal = journal.Reader(**jrnlargs)
self.__matches = []
self.__nextUpdateTM = 0
self.setDatePattern(None)
logSys.debug("Created FilterSystemd")
@ -285,6 +286,7 @@ class FilterSystemd(JournalFilter): # pragma: systemd no cover
except OSError:
pass # Reading failure, so safe to ignore
line = None
while self.active:
# wait for records (or for timeout in sleeptime seconds):
try:
@ -326,8 +328,15 @@ class FilterSystemd(JournalFilter): # pragma: systemd no cover
if self.ticks % 10 == 0:
self.performSvc()
# update position in log (time and iso string):
if self.jail.database is not None:
if (line and self.jail.database and (
self.ticks % 10 == 0
or MyTime.time() >= self.__nextUpdateTM
or not self.active
)
):
self.jail.database.updateJournal(self.jail, 'systemd-journal', line[1], line[0][1])
self.__nextUpdateTM = MyTime.time() + Utils.DEFAULT_SLEEP_TIME * 5
line = None
except Exception as e: # pragma: no cover
if not self.active: # if not active - error by stop...
break