From 94d74d356600a6bef76530bf9e5d9f89c4c132fd Mon Sep 17 00:00:00 2001 From: Jan Hoffmann Date: Thu, 1 Feb 2024 21:12:05 +0100 Subject: [PATCH] vnstat2: update to version 2.12 This version includes several new features that allow to simplify the package significantly: The noexit patch and hotplug script are no longer needed, and the init script doesn't have to check for legacy databases anymore. Signed-off-by: Jan Hoffmann --- net/vnstat2/Makefile | 6 +- net/vnstat2/files/vnstat.hotplug | 23 -------- net/vnstat2/files/vnstat.init | 31 ++-------- net/vnstat2/patches/100-noexit.patch | 84 ---------------------------- 4 files changed, 6 insertions(+), 138 deletions(-) delete mode 100644 net/vnstat2/files/vnstat.hotplug delete mode 100644 net/vnstat2/patches/100-noexit.patch diff --git a/net/vnstat2/Makefile b/net/vnstat2/Makefile index 3968a718bb..01e52df15d 100644 --- a/net/vnstat2/Makefile +++ b/net/vnstat2/Makefile @@ -6,12 +6,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=vnstat2 -PKG_VERSION:=2.11 +PKG_VERSION:=2.12 PKG_RELEASE:=1 PKG_SOURCE:=vnstat-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=https://humdi.net/vnstat -PKG_HASH:=babc3f1583cc40e4e8ffb2f53296d93d308cb5a5043e85054f6eaf7b4ae57856 +PKG_HASH:=b7386b12fc1fc6f47fab31f208b12eda61862e63e229e84e95a6fa80406d2852 PKG_LICENSE:=GPL-2.0-only PKG_LICENSE_FILES:=COPYING @@ -77,8 +77,6 @@ define Package/vnstat2/install $(INSTALL_CONF) ./files/vnstat.config $(1)/etc/config/vnstat $(INSTALL_DIR) $(1)/etc/init.d $(INSTALL_BIN) ./files/vnstat.init $(1)/etc/init.d/vnstat - $(INSTALL_DIR) $(1)/etc/hotplug.d/iface - $(INSTALL_DATA) ./files/vnstat.hotplug $(1)/etc/hotplug.d/iface/50-vnstat endef define Package/vnstati2/install diff --git a/net/vnstat2/files/vnstat.hotplug b/net/vnstat2/files/vnstat.hotplug deleted file mode 100644 index 339c0ac82d..0000000000 --- a/net/vnstat2/files/vnstat.hotplug +++ /dev/null @@ -1,23 +0,0 @@ -/etc/init.d/vnstat running || exit 0 -[ "$ACTION" = "ifup" ] || exit 0 - -. /lib/functions.sh - -check_iface() { - local iface="$1" - - [ "$iface" = "$DEVICE" ] || return - - /usr/bin/vnstat --add -i "$iface" >/dev/null - - exit 0 -} - -check_ifaces() { - local cfg="$1" - - config_list_foreach "$cfg" interface check_iface -} - -config_load vnstat -config_foreach check_ifaces vnstat diff --git a/net/vnstat2/files/vnstat.init b/net/vnstat2/files/vnstat.init index d69d7385f5..d2d8b2520a 100644 --- a/net/vnstat2/files/vnstat.init +++ b/net/vnstat2/files/vnstat.init @@ -5,26 +5,8 @@ STOP=50 USE_PROCD=1 -vnstat_option() { - sed -ne "s/^[[:space:]]*$1[[:space:]]*['\"]\([^'\"]*\)['\"].*/\1/p" \ - /etc/vnstat.conf -} - init_database() { - local lib database_count - - lib="$(vnstat_option DatabaseDir)" - [ -n "$lib" ] || lib="/var/lib/vnstat" - - database_count="$(ls "$lib" 2>/dev/null | wc -l)" - - # only init database when folder is empty, as it would prevent import of legacy databases - if [ "$database_count" -eq "0" ]; then - /usr/sbin/vnstatd --initdb >/dev/null - else - # if vnstat.db doesn't exist, there are legacy databases to import - [ ! -f "$lib/vnstat.db" ] && echo -n "1" - fi + /usr/sbin/vnstatd --initdb >/dev/null } init_ifaces() { @@ -33,19 +15,14 @@ init_ifaces() { init_iface() { local ifn="$1" - /usr/bin/vnstat --add -i "$ifn" >/dev/null + /usr/bin/vnstat --add --force -i "$ifn" >/dev/null } config_list_foreach "$cfg" interface init_iface } start_service() { - local options needs_import - - needs_import="$(init_database)" - - # --noadd would prevent import of legacy databases - [ -z "$needs_import" ] && options="--noadd --noexit" + init_database config_load vnstat config_foreach init_ifaces vnstat @@ -53,7 +30,7 @@ start_service() { procd_open_instance procd_set_param stdout 1 procd_set_param stderr 1 - procd_set_param command /usr/sbin/vnstatd --nodaemon $options + procd_set_param command /usr/sbin/vnstatd --nodaemon --noadd --startempty --noremove procd_set_param file /etc/vnstat.conf procd_set_param respawn procd_close_instance diff --git a/net/vnstat2/patches/100-noexit.patch b/net/vnstat2/patches/100-noexit.patch deleted file mode 100644 index 9940e814f4..0000000000 --- a/net/vnstat2/patches/100-noexit.patch +++ /dev/null @@ -1,84 +0,0 @@ ---- 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 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; - }