"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/daemon.c" between
vnstat-2.7.tar.gz and vnstat-2.8.tar.gz

About: vnStat is a console-based network traffic monitor (using the /proc filesystem).

daemon.c  (vnstat-2.7):daemon.c  (vnstat-2.8)
skipping to change at line 255 skipping to change at line 255
debug = 0; /* debug disabled by default */ debug = 0; /* debug disabled by default */
disableprints = 0; /* let prints be visible */ disableprints = 0; /* let prints be visible */
s->rundaemon = 0; /* daemon disabled by default */ s->rundaemon = 0; /* daemon disabled by default */
s->running = 0; s->running = 0;
s->dbsaved = 1; s->dbsaved = 1;
s->showhelp = 1; s->showhelp = 1;
s->sync = 0; s->sync = 0;
s->forcesave = 0; s->forcesave = 0;
s->noadd = 0; s->noadd = 0;
s->alwaysadd = 0;
s->initdb = 0; s->initdb = 0;
s->iflisthash = 0; s->iflisthash = 0;
s->cfgfile[0] = '\0'; s->cfgfile[0] = '\0';
s->user[0] = '\0'; s->user[0] = '\0';
s->group[0] = '\0'; s->group[0] = '\0';
s->prevdbupdate = 0; s->prevdbupdate = 0;
s->prevdbsave = 0; s->prevdbsave = 0;
s->dbifcount = 0; s->dbifcount = 0;
s->dodbsave = 0; s->dodbsave = 0;
s->bootdetected = 0; s->bootdetected = 0;
s->cleanuphour = getcurrenthour(); s->cleanuphour = getcurrenthour();
s->dbretrycount = 0; s->dbretrycount = 0;
s->dcache = NULL; s->dcache = NULL;
s->prevwaldbcheckpoint = time(NULL); s->prevwaldbcheckpoint = time(NULL);
} }
void preparedatabase(DSTATE *s) void preparedatabase(DSTATE *s)
{ {
s->dbifcount = db_getinterfacecount(); s->dbifcount = db_getinterfacecount();
if (s->dbifcount > 0 && !s->alwaysadd) { if (s->dbifcount > 0 && !cfg.alwaysadd) {
s->dbifcount = 0; s->dbifcount = 0;
return; return;
} }
if (debug) { if (debug) {
printf("db if count: %" PRIu64 "\n", s->dbifcount); printf("db if count: %" PRIu64 "\n", s->dbifcount);
} }
if (s->noadd) { if (s->noadd) {
printf("No interfaces found in database, exiting.\n"); printf("No interfaces found in database, exiting.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!spacecheck(cfg.dbdir)) { if (!spacecheck(cfg.dbdir)) {
printf("Error: Not enough free diskspace available, exiting.\n"); printf("Error: Not enough free diskspace available, exiting.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (s->dbifcount == 0) { if (s->dbifcount == 0) {
if (importlegacydbs(s) && !s->alwaysadd) { if (importlegacydbs(s) && !cfg.alwaysadd) {
s->dbifcount = 0; s->dbifcount = 0;
return; return;
} }
printf("No interfaces found in database, adding available interfa ces...\n"); printf("No interfaces found in database, adding available interfa ces...\n");
} }
if (!addinterfaces(s) && s->dbifcount == 0) { if (!addinterfaces(s) && s->dbifcount == 0) {
printf("Nothing to do, exiting.\n"); printf("Nothing to do, exiting.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
skipping to change at line 475 skipping to change at line 474
} }
timeused_debug(__func__, 0); timeused_debug(__func__, 0);
if (s->dodbsave) { if (s->dodbsave) {
flushcachetodisk(s); flushcachetodisk(s);
cleanremovedinterfaces(s); cleanremovedinterfaces(s);
if (s->cleanuphour != getcurrenthour()) { if (s->cleanuphour != getcurrenthour()) {
db_removeoldentries(); db_removeoldentries();
s->cleanuphour = getcurrenthour(); s->cleanuphour = getcurrenthour();
} }
if (cfg.rescanonsave) {
rescandatabaseforinterfaces(s);
}
s->dodbsave = 0; s->dodbsave = 0;
} }
} }
int initcachevalues(DSTATE *s, datacache **dc) int initcachevalues(DSTATE *s, datacache **dc)
{ {
interfaceinfo info; interfaceinfo info;
if (!db_getinterfaceinfo((*dc)->interface, &info)) { if (!db_getinterfaceinfo((*dc)->interface, &info)) {
return 0; return 0;
skipping to change at line 724 skipping to change at line 726
while (iterator != NULL) { while (iterator != NULL) {
if (!db_getinterfacecountbyname(iterator->interface)) { if (!db_getinterfacecountbyname(iterator->interface)) {
iflistadd(&dbifl, iterator->interface, 0); iflistadd(&dbifl, iterator->interface, 0);
} }
iterator = iterator->next; iterator = iterator->next;
} }
if (dbifl != NULL) { if (dbifl != NULL) {
dbifl_iterator = dbifl; dbifl_iterator = dbifl;
while (dbifl_iterator != NULL) { while (dbifl_iterator != NULL) {
snprintf(errorstring, 1024, "Removing interface \"%s\" fr om update list.", dbifl_iterator->interface); snprintf(errorstring, 1024, "Interface \"%s\" no longer i n database, stopping monitoring.", dbifl_iterator->interface);
printe(PT_Info); printe(PT_Info);
datacache_remove(&s->dcache, dbifl_iterator->interface); datacache_remove(&s->dcache, dbifl_iterator->interface);
if (s->dbifcount > 0) { if (s->dbifcount > 0) {
s->dbifcount--; s->dbifcount--;
} }
dbifl_iterator = dbifl_iterator->next; dbifl_iterator = dbifl_iterator->next;
} }
datacache_status(&s->dcache); datacache_status(&s->dcache);
iflistfree(&dbifl); iflistfree(&dbifl);
} }
timeused_debug(__func__, 0); timeused_debug(__func__, 0);
} }
void rescandatabaseforinterfaces(DSTATE *s)
{
short interface_already_monitored = 0;
uint64_t dbifcount = s->dbifcount;
datacache *iterator = NULL;
iflist *dbifl = NULL, *dbifl_iterator = NULL;
timeused_debug(__func__, 1);
if (db_getiflist(&dbifl) > 0 && dbifl != NULL) {
dbifl_iterator = dbifl;
while (dbifl_iterator != NULL) {
iterator = s->dcache;
interface_already_monitored = 0;
while (iterator != NULL) {
if (strcmp(iterator->interface, dbifl_iterator->i
nterface) == 0) {
interface_already_monitored = 1;
break;
}
iterator = iterator->next;
}
if (!interface_already_monitored) {
snprintf(errorstring, 1024, "Interface \"%s\" fou
nd from database, starting monitoring.", dbifl_iterator->interface);
printe(PT_Info);
if (!datacache_add(&s->dcache, dbifl_iterator->in
terface, 1)) {
snprintf(errorstring, 1024, "Cache memory
allocation failed (%s), exiting.", strerror(errno));
printe(PT_Error);
errorexitdaemon(s, 1);
}
s->dbifcount++;
}
dbifl_iterator = dbifl_iterator->next;
}
if (s->dbifcount != dbifcount) {
datacache_status(&s->dcache);
}
iflistfree(&dbifl);
}
timeused_debug(__func__, 0);
}
void handleintsignals(DSTATE *s) void handleintsignals(DSTATE *s)
{ {
switch (intsignal) { switch (intsignal) {
case SIGHUP: case SIGHUP:
snprintf(errorstring, 1024, "SIGHUP received, flushing da ta to disk and reloading config."); snprintf(errorstring, 1024, "SIGHUP received, flushing da ta to disk and reloading config.");
printe(PT_Info); printe(PT_Info);
flushcachetodisk(s); flushcachetodisk(s);
datacache_clear(&s->dcache); datacache_clear(&s->dcache);
s->dbifcount = 0; s->dbifcount = 0;
ibwflush(); ibwflush();
db_close(); db_close();
loadcfg(s->cfgfile); loadcfg(s->cfgfile, CT_Daemon);
ibwloadcfg(s->cfgfile); ibwloadcfg(s->cfgfile);
if (!db_open_rw(1)) { if (!db_open_rw(1)) {
snprintf(errorstring, 1024, "Opening database aft er SIGHUP failed (%s), exiting.", strerror(errno)); snprintf(errorstring, 1024, "Opening database aft er SIGHUP failed (%s), exiting.", strerror(errno));
printe(PT_Error); printe(PT_Error);
if (s->rundaemon && !debug) { if (s->rundaemon && !debug) {
close(pidfile); close(pidfile);
unlink(cfg.pidfile); unlink(cfg.pidfile);
} }
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
skipping to change at line 811 skipping to change at line 855
/* possible pid/lock and log directory */ /* possible pid/lock and log directory */
preparevnstatdir(cfg.pidfile, s->user, s->group); preparevnstatdir(cfg.pidfile, s->user, s->group);
if (cfg.uselogging == 1) { if (cfg.uselogging == 1) {
preparevnstatdir(cfg.logfile, s->user, s->group); preparevnstatdir(cfg.logfile, s->user, s->group);
} }
} }
void datacache_status(datacache **dc) void datacache_status(datacache **dc)
{ {
char buffer[1024], bwtemp[16]; char buffer[1024], bwtemp[32];
unsigned int b = 0, count = 0; unsigned int b = 0, count = 0;
uint32_t bwlimit = 0; uint32_t bwlimit = 0;
datacache *iterator = *dc; datacache *iterator = *dc;
timeused_debug(__func__, 1); timeused_debug(__func__, 1);
snprintf(buffer, 1024, "Monitoring (%d): ", datacache_count(dc)); snprintf(buffer, 1024, "Monitoring (%d): ", datacache_count(dc));
b = (unsigned int)strlen(buffer) + 1; b = (unsigned int)strlen(buffer) + 1;
while (iterator != NULL) { while (iterator != NULL) {
if ((b + strlen(iterator->interface) + 16) < 1020) { if ((b + strlen(iterator->interface) + 32) < 1020) {
if (!ibwget(iterator->interface, &bwlimit) || bwlimit == 0) { if (!ibwget(iterator->interface, &bwlimit) || bwlimit == 0) {
snprintf(bwtemp, 16, " (no limit) "); snprintf(bwtemp, 32, " (no limit) ");
} else { } else {
snprintf(bwtemp, 16, " (%" PRIu32 " Mbit) ", bwli mit); snprintf(bwtemp, 32, " (%" PRIu32 " Mbit) ", bwli mit);
} }
strcat(buffer, iterator->interface); strcat(buffer, iterator->interface);
strcat(buffer, bwtemp); strcat(buffer, bwtemp);
b += strlen(iterator->interface) + strlen(bwtemp); b += strlen(iterator->interface) + strlen(bwtemp);
} else { } else {
strcat(buffer, "..."); strcat(buffer, "...");
break; break;
} }
count++; count++;
iterator = iterator->next; iterator = iterator->next;
 End of changes. 11 change blocks. 
9 lines changed or deleted 57 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)