blob: 89580e9a951ad3bdc06f340e9f243b8f90c175f4 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001--- a/src/daemon.c
2+++ b/src/daemon.c
3@@ -252,6 +252,7 @@ void initdstate(DSTATE *s)
4 s->sync = 0;
5 s->forcesave = 0;
6 s->noadd = 0;
7+ s->noexit = 0;
8 s->initdb = 0;
9 s->iflisthash = 0;
10 s->cfgfile[0] = '\0';
11@@ -282,6 +283,9 @@ void preparedatabase(DSTATE *s)
12 }
13
14 if (s->noadd) {
15+ if (s->noexit) {
16+ return;
17+ }
18 printf("No interfaces found in database, exiting.\n");
19 exit(EXIT_FAILURE);
20 }
21@@ -300,6 +304,9 @@ void preparedatabase(DSTATE *s)
22 }
23
24 if (!addinterfaces(s) && s->dbifcount == 0) {
25+ if (s->noexit) {
26+ return;
27+ }
28 printf("Nothing to do, exiting.\n");
29 exit(EXIT_FAILURE);
30 }
31--- a/src/daemon.h
32+++ b/src/daemon.h
33@@ -4,7 +4,7 @@
34 typedef struct {
35 int updateinterval, saveinterval;
36 short running, dodbsave, rundaemon;
37- short dbsaved, showhelp, sync, forcesave, noadd, initdb;
38+ short dbsaved, showhelp, sync, forcesave, noadd, noexit, initdb;
39 short bootdetected, cleanuphour, dbretrycount;
40 uint32_t iflisthash;
41 uint64_t dbifcount;
42--- a/src/vnstatd.c
43+++ b/src/vnstatd.c
44@@ -249,6 +249,7 @@ void showhelp(void)
45 printf(" --config <config file> select used config file\n");
46 printf(" --noadd prevent startup if database has no interfaces\n");
47 printf(" --alwaysadd [mode] automatically start monitoring all new interfaces\n");
48+ printf(" --noexit keep running even when database has no interfaces\n");
49 printf(" --initdb create empty database and exit\n\n");
50
51 printf("See also \"man vnstatd\".\n");
52@@ -322,6 +323,8 @@ void parseargs(DSTATE *s, int argc, char
53 } else {
54 cfg.alwaysadd = 1;
55 }
56+ } else if (strcmp(argv[currentarg], "--noexit") == 0) {
57+ s->noexit = 1;
58 } else if (strcmp(argv[currentarg], "--initdb") == 0) {
59 s->initdb = 1;
60 s->showhelp = 0;