/* main loop */
while (s.running) {
- /* keep track of time */
s.current = time(NULL);
/* track interface status only if at least one database exists */
s.prevdbupdate = s.current;
s.datalist = dataptr;
- /* modify active save interval if all interfaces are unavailable */
- if (cacheactivecount()) {
- s.saveinterval = cfg.saveinterval*60;
- } else {
- s.saveinterval = cfg.offsaveinterval*60;
- }
+ adjustsaveinterval(&s);
+ checkdbsaveneed(&s);
- if ((s.current - s.prevdbsave) >= (s.saveinterval) || s.forcesave) {
- s.dodbsave = 1;
- s.forcesave = 0;
- s.prevdbsave = s.current;
- } else {
- s.dodbsave = 0;
- }
-
- /* check all datalist entries*/
processdatalist(&s);
if (debug) {
sleep(cfg.pollinterval);
}
- /* take actions from signals */
if (intsignal) {
handleintsignals(&s);
}
cacheflush(s.dirname);
ibwflush();
- /* clean daemon stuff */
if (s.rundaemon && !debug) {
close(pidfile);
unlink(cfg.pidfile);
{
noexit = 1; /* disable exits in functions */
debug = 0; /* debug disabled by default */
- s->rundaemon = 0; /* daemon disabled by default */
+ s->rundaemon = 0; /* daemon disabled by default */
s->running = 1;
s->dbsaved = 1;
printf("Make sure it exists and is at least read enabled for current user.\n");
printf("Exiting...\n");
exit(EXIT_FAILURE);
- } else {
- /* check if there's something to work with */
- s->dbcount = 0;
- while ((di=readdir(dir))) {
- if (di->d_name[0]!='.') {
- s->dbcount++;
- }
+ }
+
+ /* check if there's something to work with */
+ s->dbcount = 0;
+ while ((di=readdir(dir))) {
+ if (di->d_name[0]!='.') {
+ s->dbcount++;
}
- closedir(dir);
- if (s->dbcount==0) {
- if (s->noadd) {
- printf("Zero database found, exiting.\n");
- exit(EXIT_FAILURE);
- } else {
- if (!spacecheck(s->dirname)) {
- printf("Error: Not enough free diskspace available, exiting.\n");
- exit(EXIT_FAILURE);
- }
- printf("Zero database found, adding available interfaces...\n");
- if (!addinterfaces(s->dirname)) {
- printf("Nothing to do, exiting.\n");
- exit(EXIT_FAILURE);
- }
- s->dbcount = 0;
- }
- } else {
- /* set counter back to zero so that dbs will be cached later */
- s->dbcount = 0;
+ }
+ closedir(dir);
+ if (s->dbcount==0) {
+ if (s->noadd) {
+ printf("Zero database found, exiting.\n");
+ exit(EXIT_FAILURE);
+ }
+ if (!spacecheck(s->dirname)) {
+ printf("Error: Not enough free diskspace available, exiting.\n");
+ exit(EXIT_FAILURE);
+ }
+ printf("Zero database found, adding available interfaces...\n");
+ if (!addinterfaces(s->dirname)) {
+ printf("Nothing to do, exiting.\n");
+ exit(EXIT_FAILURE);
}
+ /* set counter back to zero so that dbs will be cached later */
+ s->dbcount = 0;
}
}
}
while ((di=readdir(dir))) {
- if (di->d_name[0]!='.') {
- if (debug) {
- printf("\nProcessing file \"%s/%s\"...\n", s->dirname, di->d_name);
- }
+ if (di->d_name[0]=='.') {
+ continue;
+ }
- if (!cacheadd(di->d_name, s->sync)) {
- snprintf(errorstring, 512, "Cache memory allocation failed, exiting.");
- printe(PT_Error);
+ if (debug) {
+ printf("\nProcessing file \"%s/%s\"...\n", s->dirname, di->d_name);
+ }
- /* clean daemon stuff before exit */
- if (s->rundaemon && !debug) {
- close(pidfile);
- unlink(cfg.pidfile);
- }
- ibwflush();
- exit(EXIT_FAILURE);
- }
+ if (!cacheadd(di->d_name, s->sync)) {
+ snprintf(errorstring, 512, "Cache memory allocation failed, exiting.");
+ printe(PT_Error);
- s->dbcount++;
+ /* clean daemon stuff before exit */
+ if (s->rundaemon && !debug) {
+ close(pidfile);
+ unlink(cfg.pidfile);
+ }
+ ibwflush();
+ exit(EXIT_FAILURE);
}
+ s->dbcount++;
}
closedir(dir);
}
}
+void adjustsaveinterval(DSTATE *s)
+{
+ /* modify active save interval if all interfaces are unavailable */
+ if (cacheactivecount() > 0) {
+ s->saveinterval = cfg.saveinterval * 60;
+ } else {
+ s->saveinterval = cfg.offsaveinterval * 60;
+ }
+}
+
+void checkdbsaveneed(DSTATE *s)
+{
+ if ((s->current - s->prevdbsave) >= (s->saveinterval) || s->forcesave) {
+ s->dodbsave = 1;
+ s->forcesave = 0;
+ s->prevdbsave = s->current;
+ } else {
+ s->dodbsave = 0;
+ }
+}
+
void processdatalist(DSTATE *s)
{
while (s->datalist!=NULL) {