File: 0002-Direct_check_if_seek_can_be_called.patch

package info (click to toggle)
syslog-ng 4.8.1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,572 kB
  • sloc: ansic: 177,639; python: 13,035; cpp: 11,611; makefile: 7,012; sh: 5,147; java: 3,651; xml: 3,344; yacc: 1,377; lex: 599; perl: 193; awk: 190; objc: 162
file content (52 lines) | stat: -rw-r--r-- 1,529 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
From: Hofi <hofione@gmail.com>
Date: Fri, 8 Nov 2024 15:46:00 +0100
Subject: [PATCH] file-reader: added a more detailed,
 direct check if seek can be called on the file descriptor

Signed-off-by: Hofi <hofione@gmail.com>
---
 modules/affile/file-reader.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/modules/affile/file-reader.c b/modules/affile/file-reader.c
index 712bac5..203c208 100644
--- a/modules/affile/file-reader.c
+++ b/modules/affile/file-reader.c
@@ -163,10 +163,26 @@ _recover_state(LogPipe *s, GlobalConfig *cfg, LogProtoServer *proto)
 }
 
 static gboolean
-_can_check_eof(gint fd)
+_can_check_eof(FileReader *self, gint fd)
 {
   struct stat st;
-  return fstat(fd, &st) == 0 && S_ISFIFO(st.st_mode) == 0;
+
+  if (fstat(fd, &st) == -1 || S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode) || S_ISCHR(st.st_mode))
+    return FALSE;
+
+  off_t pos = lseek(fd, 0, SEEK_CUR);
+  if (pos == -1)
+    return FALSE;
+
+  off_t reset = lseek(fd, pos, SEEK_SET);
+  if (reset != pos)
+    {
+      msg_trace("File seek pos is different after testing if seekable",
+                evt_tag_str("follow_filename", self->filename->str),
+                evt_tag_int("fn", fd));
+    }
+
+  return TRUE;
 }
 
 static gboolean
@@ -263,7 +279,7 @@ _construct_poll_events(FileReader *self, gint fd)
       return NULL;
     }
 
-  if (_can_check_eof(fd))
+  if (_can_check_eof(self, fd))
     poll_events_set_checker(poll_events, _reader_check_watches, self);
 
   return poll_events;