aboutsummaryrefslogtreecommitdiffstats
path: root/src/fnettrace/tail.c
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@protonmail.com>2023-07-26 08:59:18 -0400
committerLibravatar netblue30 <netblue30@protonmail.com>2023-07-26 08:59:18 -0400
commit1d69791e80cbe583aae3a0f4230d07f721b2932d (patch)
treeb829f0648f604ab74971238de509a3074521ffaf /src/fnettrace/tail.c
parentsplit nettrace executable ^Cto netrace and netlock (diff)
downloadfirejail-1d69791e80cbe583aae3a0f4230d07f721b2932d.tar.gz
firejail-1d69791e80cbe583aae3a0f4230d07f721b2932d.tar.zst
firejail-1d69791e80cbe583aae3a0f4230d07f721b2932d.zip
netlock/nettrace cleanup
Diffstat (limited to 'src/fnettrace/tail.c')
-rw-r--r--src/fnettrace/tail.c63
1 files changed, 0 insertions, 63 deletions
diff --git a/src/fnettrace/tail.c b/src/fnettrace/tail.c
deleted file mode 100644
index 3b1b274f8..000000000
--- a/src/fnettrace/tail.c
+++ /dev/null
@@ -1,63 +0,0 @@
1/*
2 * Copyright (C) 2014-2023 Firejail Authors
3 *
4 * This file is part of firejail project
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/
20#include "fnettrace.h"
21
22void tail(const char *logfile) {
23 assert(logfile);
24
25 // wait for no more than 5 seconds for the logfile to appear in the filesystem
26 int cnt = 5;
27 while (access(logfile, R_OK) && cnt > 0)
28 cnt--;
29 if (cnt == 0)
30 exit(1);
31
32 off_t last_size = 0;
33
34 while (1) {
35 int fd = open(logfile, O_RDONLY);
36 if (fd == -1)
37 return;
38
39 off_t size = lseek(fd, 0, SEEK_END);
40 if (size < 0) {
41 close(fd);
42 return;
43 }
44
45 char *content = NULL;
46 int mmapped = 0;
47 if (size && size != last_size) {
48 content = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
49 close(fd);
50 if (content != MAP_FAILED)
51 mmapped = 1;
52 }
53
54 if (mmapped) {
55 printf("%.*s", (int) (size - last_size), content + last_size);
56 fflush(0);
57 munmap(content, size);
58 last_size = size;
59 }
60
61 sleep(1);
62 }
63}