From 6c8befa26fdb2b249c3c1947adc339286a0c6497 Mon Sep 17 00:00:00 2001 From: Teemu Toivola Date: Wed, 4 Jan 2017 23:07:57 +0200 Subject: [PATCH] remove no longer used dbcache implementation --- Makefile.am | 2 - Makefile.in | 55 +++-------- src/dbcache.c | 266 -------------------------------------------------- src/dbcache.h | 24 ----- 4 files changed, 15 insertions(+), 332 deletions(-) delete mode 100644 src/dbcache.c delete mode 100644 src/dbcache.h diff --git a/Makefile.am b/Makefile.am index 54e2360..dc75148 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,7 +31,6 @@ vnstatd_SOURCES = src/vnstatd.c src/vnstatd.h \ src/ifinfo.c src/ifinfo.h \ src/dbsql.c src/dbsql.h \ src/dbaccess.c src/dbaccess.h \ - src/dbcache.c src/dbcache.h \ src/datacache.c src/datacache.h \ src/common.c src/common.h \ src/misc.c src/misc.h \ @@ -87,7 +86,6 @@ check_vnstat_SOURCES += src/cfg.c src/cfg.h \ src/daemon.c src/daemon.h \ src/dbsql.c src/dbsql.h \ src/dbaccess.c src/dbaccess.h \ - src/dbcache.c src/dbcache.h \ src/datacache.c src/datacache.h \ src/dbjson.c src/dbjson.h \ src/dbmerge.c src/dbmerge.h \ diff --git a/Makefile.in b/Makefile.in index f3330a6..36cce48 100644 --- a/Makefile.in +++ b/Makefile.in @@ -106,12 +106,11 @@ am__check_vnstat_SOURCES_DIST = tests/vnstat_tests.c \ tests/daemon_tests.c tests/daemon_tests.h src/cfg.c src/cfg.h \ src/common.c src/common.h src/daemon.c src/daemon.h \ src/dbsql.c src/dbsql.h src/dbaccess.c src/dbaccess.h \ - src/dbcache.c src/dbcache.h src/datacache.c src/datacache.h \ - src/dbjson.c src/dbjson.h src/dbmerge.c src/dbmerge.h \ - src/dbshow.c src/dbshow.h src/dbxml.c src/dbxml.h src/ibw.c \ - src/ibw.h src/ifinfo.c src/ifinfo.h src/misc.c src/misc.h \ - src/fs.c src/fs.h src/id.c src/id.h src/traffic.c \ - src/traffic.h + src/datacache.c src/datacache.h src/dbjson.c src/dbjson.h \ + src/dbmerge.c src/dbmerge.h src/dbshow.c src/dbshow.h \ + src/dbxml.c src/dbxml.h src/ibw.c src/ibw.h src/ifinfo.c \ + src/ifinfo.h src/misc.c src/misc.h src/fs.c src/fs.h src/id.c \ + src/id.h src/traffic.c src/traffic.h am__dirstamp = $(am__leading_dot)dirstamp @HAVE_CHECK_TRUE@am_check_vnstat_OBJECTS = \ @HAVE_CHECK_TRUE@ tests/check_vnstat-vnstat_tests.$(OBJEXT) \ @@ -127,7 +126,6 @@ am__dirstamp = $(am__leading_dot)dirstamp @HAVE_CHECK_TRUE@ src/check_vnstat-daemon.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-dbsql.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-dbaccess.$(OBJEXT) \ -@HAVE_CHECK_TRUE@ src/check_vnstat-dbcache.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-datacache.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-dbjson.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-dbmerge.$(OBJEXT) \ @@ -145,10 +143,9 @@ check_vnstat_LINK = $(CCLD) $(check_vnstat_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ am_vnstatd_OBJECTS = src/vnstatd.$(OBJEXT) src/ifinfo.$(OBJEXT) \ src/dbsql.$(OBJEXT) src/dbaccess.$(OBJEXT) \ - src/dbcache.$(OBJEXT) src/datacache.$(OBJEXT) \ - src/common.$(OBJEXT) src/misc.$(OBJEXT) src/cfg.$(OBJEXT) \ - src/ibw.$(OBJEXT) src/fs.$(OBJEXT) src/id.$(OBJEXT) \ - src/daemon.$(OBJEXT) + src/datacache.$(OBJEXT) src/common.$(OBJEXT) \ + src/misc.$(OBJEXT) src/cfg.$(OBJEXT) src/ibw.$(OBJEXT) \ + src/fs.$(OBJEXT) src/id.$(OBJEXT) src/daemon.$(OBJEXT) vnstatd_OBJECTS = $(am_vnstatd_OBJECTS) vnstatd_LDADD = $(LDADD) AM_V_P = $(am__v_P_@AM_V@) @@ -597,7 +594,6 @@ vnstatd_SOURCES = src/vnstatd.c src/vnstatd.h \ src/ifinfo.c src/ifinfo.h \ src/dbsql.c src/dbsql.h \ src/dbaccess.c src/dbaccess.h \ - src/dbcache.c src/dbcache.h \ src/datacache.c src/datacache.h \ src/common.c src/common.h \ src/misc.c src/misc.h \ @@ -636,14 +632,13 @@ vnstatd_SOURCES = src/vnstatd.c src/vnstatd.h \ @HAVE_CHECK_TRUE@ tests/daemon_tests.h src/cfg.c src/cfg.h \ @HAVE_CHECK_TRUE@ src/common.c src/common.h src/daemon.c \ @HAVE_CHECK_TRUE@ src/daemon.h src/dbsql.c src/dbsql.h \ -@HAVE_CHECK_TRUE@ src/dbaccess.c src/dbaccess.h src/dbcache.c \ -@HAVE_CHECK_TRUE@ src/dbcache.h src/datacache.c src/datacache.h \ -@HAVE_CHECK_TRUE@ src/dbjson.c src/dbjson.h src/dbmerge.c \ -@HAVE_CHECK_TRUE@ src/dbmerge.h src/dbshow.c src/dbshow.h \ -@HAVE_CHECK_TRUE@ src/dbxml.c src/dbxml.h src/ibw.c src/ibw.h \ -@HAVE_CHECK_TRUE@ src/ifinfo.c src/ifinfo.h src/misc.c \ -@HAVE_CHECK_TRUE@ src/misc.h src/fs.c src/fs.h src/id.c \ -@HAVE_CHECK_TRUE@ src/id.h src/traffic.c src/traffic.h +@HAVE_CHECK_TRUE@ src/dbaccess.c src/dbaccess.h src/datacache.c \ +@HAVE_CHECK_TRUE@ src/datacache.h src/dbjson.c src/dbjson.h \ +@HAVE_CHECK_TRUE@ src/dbmerge.c src/dbmerge.h src/dbshow.c \ +@HAVE_CHECK_TRUE@ src/dbshow.h src/dbxml.c src/dbxml.h \ +@HAVE_CHECK_TRUE@ src/ibw.c src/ibw.h src/ifinfo.c src/ifinfo.h \ +@HAVE_CHECK_TRUE@ src/misc.c src/misc.h src/fs.c src/fs.h \ +@HAVE_CHECK_TRUE@ src/id.c src/id.h src/traffic.c src/traffic.h all: all-recursive .SUFFIXES: @@ -796,8 +791,6 @@ src/check_vnstat-dbsql.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-dbaccess.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) -src/check_vnstat-dbcache.$(OBJEXT): src/$(am__dirstamp) \ - src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-datacache.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-dbjson.$(OBJEXT): src/$(am__dirstamp) \ @@ -831,8 +824,6 @@ src/ifinfo.$(OBJEXT): src/$(am__dirstamp) \ src/dbsql.$(OBJEXT): src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/dbaccess.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) -src/dbcache.$(OBJEXT): src/$(am__dirstamp) \ - src/$(DEPDIR)/$(am__dirstamp) src/datacache.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/common.$(OBJEXT): src/$(am__dirstamp) \ @@ -863,7 +854,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-daemon.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-datacache.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-dbaccess.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-dbcache.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-dbjson.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-dbmerge.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-dbshow.Po@am__quote@ @@ -879,7 +869,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/daemon.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/datacache.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dbaccess.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dbcache.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dbsql.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/fs.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/ibw.Po@am__quote@ @@ -1094,20 +1083,6 @@ src/check_vnstat-dbaccess.obj: src/dbaccess.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbaccess.obj `if test -f 'src/dbaccess.c'; then $(CYGPATH_W) 'src/dbaccess.c'; else $(CYGPATH_W) '$(srcdir)/src/dbaccess.c'; fi` -src/check_vnstat-dbcache.o: src/dbcache.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbcache.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbcache.Tpo -c -o src/check_vnstat-dbcache.o `test -f 'src/dbcache.c' || echo '$(srcdir)/'`src/dbcache.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbcache.Tpo src/$(DEPDIR)/check_vnstat-dbcache.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbcache.c' object='src/check_vnstat-dbcache.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbcache.o `test -f 'src/dbcache.c' || echo '$(srcdir)/'`src/dbcache.c - -src/check_vnstat-dbcache.obj: src/dbcache.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbcache.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbcache.Tpo -c -o src/check_vnstat-dbcache.obj `if test -f 'src/dbcache.c'; then $(CYGPATH_W) 'src/dbcache.c'; else $(CYGPATH_W) '$(srcdir)/src/dbcache.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbcache.Tpo src/$(DEPDIR)/check_vnstat-dbcache.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbcache.c' object='src/check_vnstat-dbcache.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbcache.obj `if test -f 'src/dbcache.c'; then $(CYGPATH_W) 'src/dbcache.c'; else $(CYGPATH_W) '$(srcdir)/src/dbcache.c'; fi` - src/check_vnstat-datacache.o: src/datacache.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-datacache.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-datacache.Tpo -c -o src/check_vnstat-datacache.o `test -f 'src/datacache.c' || echo '$(srcdir)/'`src/datacache.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-datacache.Tpo src/$(DEPDIR)/check_vnstat-datacache.Po diff --git a/src/dbcache.c b/src/dbcache.c deleted file mode 100644 index fa37b20..0000000 --- a/src/dbcache.c +++ /dev/null @@ -1,266 +0,0 @@ -#include "common.h" -#include "ifinfo.h" -#include "dbaccess.h" -#include "dbcache.h" -#include "cfg.h" -#include "ibw.h" - -int cacheadd(const char *iface, int sync) -{ - datanode *p, *n; - - p = dataptr; - - /* skip if already in list */ - while (p != NULL) { - if (strcmp(p->data.interface, iface)==0) { - if (debug) { - printf("cache: %s already cached\n", iface); - } - return 1; - } - p = p->next; - } - - /* add new node if not in list */ - n = malloc(sizeof(datanode)); - - if (n == NULL) { - return 0; - } - - n->next = dataptr; - dataptr = n; - strncpy_nt(n->data.interface, iface, 32); - n->data.interface[31] = '\0'; - n->data.active = 1; - n->filled = 0; - n->sync = sync; - - if (debug) { - printf("cache: %s added\n", iface); - } - - return 1; -} - -datanode *cacheremove(const char *iface) -{ - datanode *p, *o; - - p = dataptr; - - if (p == NULL) { - return NULL; - } - - /* handle list head remove */ - if (strcmp(p->data.interface, iface)==0) { - dataptr = p->next; - if (debug) { - printf("cache: h %s removed\n", iface); - } - free(p); - return dataptr; - } - - o = p; - p = p->next; - - /* handle other locations */ - while (p != NULL) { - - if (strcmp(p->data.interface, iface)==0) { - o->next = p->next; - if (debug) { - printf("cache: %s removed\n", iface); - } - free(p); - return o->next; - } - - o = p; - p = p->next; - } - - return NULL; -} - -int cacheupdate(void) -{ - datanode *p, *n; - - p = dataptr; - - /* update if already in list */ - while (p != NULL) { - if (strcmp(p->data.interface, data.interface)==0) { - if (memcpy(&p->data, &data, sizeof(p->data))!=NULL) { - p->filled = 1; - } else { - p->filled = 0; - } - if (debug) { - printf("cache: %s updated (%d)\n", p->data.interface, p->filled); - } - return p->filled; - } - p = p->next; - } - - /* add new node if not in list */ - n = malloc(sizeof(datanode)); - - if (n == NULL) { - return 0; - } - - n->next = dataptr; - dataptr = n; - if (memcpy(&n->data, &data, sizeof(n->data))!=NULL) { - n->filled = 1; - } else { - n->filled = 0; - } - - if (debug) { - printf("cache: %s added and updated (%d)\n", n->data.interface, n->filled); - } - - return n->filled; -} - -void cacheshow(void) -{ - int i = 1; - datanode *p = dataptr; - - if (p == NULL) { - printf("cache: empty.\n"); - return; - } - - printf("cache:"); - while (p != NULL) { - printf(" %d. \"%s\" ", i, p->data.interface); - p = p->next; - i++; - } - printf("\n"); -} - -void cachestatus(void) -{ - char buffer[512], bwtemp[16]; - int b = 13, count = 0, bwlimit = 0; - datanode *p = dataptr; - - snprintf(buffer, b, "Monitoring: "); - - while (p != NULL) { - if ((b+strlen(p->data.interface)+16) < 508) { - bwlimit = ibwget(p->data.interface); - if (bwlimit < 0) { - snprintf(bwtemp, 16, " (no limit) "); - } else { - snprintf(bwtemp, 16, " (%d Mbit) ", bwlimit); - } - strncat(buffer, p->data.interface, strlen(p->data.interface)); - strncat(buffer, bwtemp, strlen(bwtemp)); - b += strlen(p->data.interface) + strlen(bwtemp); - } else { - strcat(buffer, "..."); - break; - } - count++; - p = p->next; - } - - if (count) { - strncpy_nt(errorstring, buffer, 512); - errorstring[511] = '\0'; - } else { - snprintf(errorstring, 512, "Nothing to monitor"); - } - printe(PT_Info); -} - -int cacheget(datanode *dn) -{ - if (dn == NULL) - return 0; - - if (dn->filled) { - memcpy(&data, &dn->data, sizeof(data)); - - /* do simple data validation */ - if (data.version != DBVERSION || - data.created == 0 || - data.lastupdated == 0 || - data.interface[0] == '\0' || - data.active > 1 || - data.active < 0) { - - if (debug) - printf("cache get: validation failed (%d/%u/%u/%d/%d)\n", data.version, (unsigned int)data.created, (unsigned int)data.lastupdated, data.interface[0], data.active); - - /* force reading of database file */ - dn->filled = 0; - } - } - - if (debug) { - printf("cache get: %s (%d/%d)\n", dn->data.interface, dn->filled, dn->data.active); - } - - return dn->filled; -} - -/* flush cached data to disk and free all memory allocted for it */ -void cacheflush(const char *dirname) -{ - datanode *f, *p = dataptr; - - while (p != NULL) { - f = p; - p = p->next; - - /* write data to file if needed */ - if (f->filled && dirname!=NULL) { - memcpy(&data, &f->data, sizeof(data)); - writedb(f->data.interface, dirname, 0); - } - - free(f); - } - - dataptr = NULL; -} - -int cachecount(void) -{ - datanode *p = dataptr; - int c = 0; - - while (p != NULL) { - c++; - p = p->next; - } - - return c; -} - -int cacheactivecount(void) -{ - datanode *p = dataptr; - int c = 0; - - while (p != NULL) { - if (p->data.active) { - c++; - } - p = p->next; - } - - return c; -} diff --git a/src/dbcache.h b/src/dbcache.h deleted file mode 100644 index 4fc6866..0000000 --- a/src/dbcache.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef DBCACHE_H -#define DBCACHE_H - -typedef struct datanode { - DATA data; - short filled; - short sync; - struct datanode *next; -} datanode; - -int cacheadd(const char *iface, int sync); -datanode *cacheremove(const char *iface); -int cacheupdate(void); -void cacheshow(void); -void cachestatus(void); -int cacheget(datanode *dn); -void cacheflush(const char *dirname); -int cachecount(void); -int cacheactivecount(void); - -/* global variables */ -datanode *dataptr; - -#endif -- 2.40.0