]> git.treefish.org Git - logalert.git/commitdiff
refined file following
authorAlexander Schmidt <alex@treefish.org>
Tue, 6 Oct 2020 18:07:39 +0000 (20:07 +0200)
committerAlexander Schmidt <alex@treefish.org>
Tue, 6 Oct 2020 18:07:39 +0000 (20:07 +0200)
src/logalert.py

index 972201434dc2011b4b571ac796fbafc64a2c160c..df9de076eb4e701577f7af5ebc83711ce6c8be2c 100755 (executable)
@@ -10,16 +10,19 @@ import time
 MAX_LINES = 10
 ALERT_INTERVAL = 86400
 
-def follow(filename):
+def follow(path):
     while True:
         try:
-            with open(filename, "r") as f:
+            fd = os.open(path, os.O_RDONLY)
+            current_ino = os.fstat(fd).st_ino
+            with os.fdopen(fd, "r") as f:
                 logging.info("Re-attached to log file.")
                 for line in f: pass
                 while True:
                     line = f.readline()
                     if not line:
-                        if not os.path.exists(filename):
+                        if os.stat(path).st_ino != current_ino or \
+                           os.stat(path).st_size < f.tell():
                             break
                         else:
                             time.sleep(1.0)