summaryrefslogtreecommitdiff
path: root/net/vnstat2/patches/100-noexit.patch
blob: 9940e814f4873e9374c1b2f9b7328dde566ebb8a (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -277,6 +277,7 @@ void initdstate(DSTATE *s)
 	s->sync = 0;
 	s->forcesave = 0;
 	s->noadd = 0;
+	s->noexit = 0;
 	s->initdb = 0;
 	s->iflisthash = 0;
 	s->cfgfile[0] = '\0';
@@ -310,6 +311,9 @@ void preparedatabase(DSTATE *s)
 	}
 
 	if (s->noadd) {
+		if (s->noexit) {
+			return;
+		}
 		printf("No interfaces found in database, exiting.\n");
 		exit(EXIT_FAILURE);
 	}
@@ -328,6 +332,9 @@ void preparedatabase(DSTATE *s)
 	}
 
 	if (!addinterfaces(s) && s->dbifcount == 0) {
+		if (s->noexit) {
+			return;
+		}
 		printf("Nothing to do, exiting.\n");
 		exit(EXIT_FAILURE);
 	}
--- a/src/daemon.h
+++ b/src/daemon.h
@@ -4,7 +4,7 @@
 typedef struct {
 	int updateinterval, saveinterval;
 	short running, dodbsave, rundaemon;
-	short dbsaved, showhelp, sync, forcesave, noadd, initdb;
+	short dbsaved, showhelp, sync, forcesave, noadd, noexit, initdb;
 	short bootdetected, cleanuphour, dbretrycount;
 	uint32_t iflisthash;
 	uint64_t dbifcount;
--- a/src/vnstatd.c
+++ b/src/vnstatd.c
@@ -259,6 +259,7 @@ void showhelp(void)
 	printf("      --config <config file>   select used config file\n");
 	printf("      --noadd                  prevent startup if database has no interfaces\n");
 	printf("      --alwaysadd [mode]       automatically start monitoring all new interfaces\n");
+	printf("      --noexit                 keep running even when database has no interfaces\n");
 	printf("      --initdb                 create empty database and exit\n\n");
 
 	printf("See also \"man vnstatd\".\n");
@@ -332,6 +333,8 @@ void parseargs(DSTATE *s, int argc, char
 			} else {
 				cfg.alwaysadd = 1;
 			}
+		} else if (strcmp(argv[currentarg], "--noexit") == 0) {
+			s->noexit = 1;
 		} else if (strcmp(argv[currentarg], "--initdb") == 0) {
 			s->initdb = 1;
 			s->showhelp = 0;
--- a/src/dbsql.c
+++ b/src/dbsql.c
@@ -976,7 +976,7 @@ int db_insertdata(const char *table, con
 
 int db_removeoldentries(void)
 {
-	int rc, i;
+	int rc, i, dbifcount;
 	char sql[256];
 	const char *datatables[] = {"fiveminute", "hour", "day", "month", "year"};
 	const int32_t entrylimits[] = {cfg.fiveminutehours * 12, cfg.hourlydays * 24, cfg.dailydays, cfg.monthlymonths, cfg.yearlyyears};
@@ -987,8 +987,11 @@ int db_removeoldentries(void)
 		printf("db: removing old entries\n");
 	}
 
-	if (db_getiflist(&dbifl) <= 0) {
+	dbifcount = db_getiflist(&dbifl);
+	if (dbifcount < 0) {
 		return 0;
+	} else if (dbifcount == 0) {
+		return 1;
 	} else {
 		dbifl_i = dbifl;
 	}