From 4289678f7a226d3a501fa8c2a6617a1f3ae6ea24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 20 Aug 2017 13:49:19 +0200 Subject: [PATCH 1/4] Spelling fixes found by Debian's lintian --- FAQ | 2 +- man/vnstat.1 | 10 +++++----- man/vnstat.conf.5 | 4 ++-- src/daemon.c | 2 +- src/vnstat.c | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/FAQ b/FAQ index 2c83e6e1..03b24ea6 100644 --- a/FAQ +++ b/FAQ @@ -107,7 +107,7 @@ Why is there problems with most 2.4.18 kernels? Every current kernel has a btime (boot time) value in /proc/stat that indicates when the system was booted. vnStat uses this to know when the - interface counters in the database should be reseted. Unfortunately, some + interface counters in the database should be reset. Unfortunately, some kernels don't keep the btime value static even when the system isn't rebooted. diff --git a/man/vnstat.1 b/man/vnstat.1 index e2b7f274..129a8b0b 100644 --- a/man/vnstat.1 +++ b/man/vnstat.1 @@ -185,7 +185,7 @@ to the up script. These two options aren't needed when the daemon is used. .TP .B "--exportdb" Instead of showing the database with a formatted output, this output will -dump the whole database in a plain text based architeture independent format. +dump the whole database in a plain text based architecture independent format. The output can be imported back using the .B "--importdb" option and can be used for moving a database from one host to another. See the @@ -195,7 +195,7 @@ the outputs of .B "--xml" and .B "--json" -are likely to be more suitable. The dump uses ; as field delimeter. +are likely to be more suitable. The dump uses ; as field delimiter. .TS l l. active;1 activity status @@ -241,7 +241,7 @@ Import a database from which was previously exported using the .B "--exportdb" option. This can be used to transfer a database between different architectures and -hosts, as the database is architecture dependant and not compatible between +hosts, as the database is architecture dependent and not compatible between different architectures. First dump the database on one host, e.g. with .B "vnstat -i ppp0 --exportdb >ppp0db.txt" and then import the text file on a different host using @@ -308,7 +308,7 @@ the set operation. .TP .B "--oneline" Show traffic summary for selected interface using one line with a parseable -format. The output contains 15 fields with ; used as field delimeter. The 1st +format. The output contains 15 fields with ; used as field delimiter. The 1st field contains the version information of the output that will be changed in future versions of vnStat if the field structure changes. The following fields in order 2) interface name, 3) timestamp for today, 4) rx for today, @@ -372,7 +372,7 @@ mode. .B "--sync" Synchronize internal counters in the database with interface counters for the selected interface. Use this if the system is -rebooted but interface counters aren't reseted. Such can occur +rebooted but interface counters aren't reset. Such can occur when suspend to ram/disk is used. Not needed when the daemon is used. .TP diff --git a/man/vnstat.conf.5 b/man/vnstat.conf.5 index 02097d2d..c918275a 100644 --- a/man/vnstat.conf.5 +++ b/man/vnstat.conf.5 @@ -36,7 +36,7 @@ Try to automatically detect value for each monitored interface. Mostly only ethernet interfaces support this feature. .B MaxBandwidth -or interface specfic +or interface specific .B MaxBW will be used as fallback value if detection fails. 1 = enabled, 0 = disabled. (vnstat and vnstatd only) @@ -308,7 +308,7 @@ Formatting of date in header. Uses the same format as .TP .B HourlyRate -Show hours with rate instead of transfered amount. 1 = enabled, 0 = disabled. +Show hours with rate instead of transferred amount. 1 = enabled, 0 = disabled. .TP .B SummaryLayout diff --git a/src/daemon.c b/src/daemon.c index 7b9d52b5..9160cd05 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -562,7 +562,7 @@ void handleintsignals(DSTATE *s) break; default: - snprintf(errorstring, 512, "Unkown signal %d received, ignoring.", intsignal); + snprintf(errorstring, 512, "Unknown signal %d received, ignoring.", intsignal); printe(PT_Info); break; } diff --git a/src/vnstat.c b/src/vnstat.c index d9f5b084..43880ac5 100644 --- a/src/vnstat.c +++ b/src/vnstat.c @@ -554,7 +554,7 @@ void handlecounterreset(PARAMS *p) data.curtx=0; writedb(p->interface, p->dirname, 0); if (debug) - printf("Counters reseted for \"%s\"\n", data.interface); + printf("Counters reset for \"%s\"\n", data.interface); } void handleimport(PARAMS *p) @@ -672,7 +672,7 @@ void handlerebuildtotal(PARAMS *p) rebuilddbtotal(p->interface, p->dirname); p->query=0; } else { - printf("Warning:\nThe current option would rebuild total tranfers for \"%s\".\n", p->interface); + printf("Warning:\nThe current option would rebuild total transfers for \"%s\".\n", p->interface); printf("Use --force in order to really do that.\n"); exit(EXIT_FAILURE); } From c7ab9f1c380f96d082ecf02efc0afee291e5fe28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 20 Aug 2017 13:49:51 +0200 Subject: [PATCH 2/4] Fx misc compiler warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit src/vnstat.h:7:33: warning: identifier ‘delete’ conflicts with C++ keyword [-Wc++-compat] src/ifinfo.c:61:13: warning: request for implicit conversion from ‘void *’ to ‘char *’ not permitted in C++ [-Wc++-compat] src/dbxml.c:110:16: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] src/dbjson.c:134:16: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] src/common.c:270:6: warning: function might be candidate for attribute ‘noreturn’ [-Wsuggest-attribute=noreturn] src/misc.c:309:32: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] src/ibw.c:34:5: warning: request for implicit conversion from ‘void *’ to ‘ibwnode * {aka struct ibwnode *}’ not permitted in C++ [-Wc++-compat] src/image.c:68:17: warning: passing argument 1 of ‘colorinitcheck’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] src/dbcache.c:26:4: warning: request for implicit conversion from ‘void *’ to ‘datanode * {aka struct datanode *}’ not permitted in C++ [-Wc++-compat] src/ifinfo.c:358:4: warning: unsuffixed float constant [-Wunsuffixed-float-constants] src/common.c:173:14: warning: nested extern declaration of ‘timezone’ [-Wnested-externs] src/common.c:173:14: warning: redundant redeclaration of ‘timezone’ [-Wredundant-decls] --- src/common.c | 3 ++- src/common.h | 2 +- src/dbcache.c | 4 ++-- src/dbjson.c | 6 +++--- src/dbxml.c | 6 +++--- src/ibw.c | 4 ++-- src/ifinfo.c | 12 ++++++------ src/image.c | 2 +- src/image.h | 2 +- src/misc.c | 8 ++++---- src/misc.h | 4 ++-- src/vnstat.c | 6 +++--- src/vnstat.h | 2 +- 13 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/common.c b/src/common.c index 914a1dac..1a3cb94a 100644 --- a/src/common.c +++ b/src/common.c @@ -170,7 +170,7 @@ uint32_t mosecs(void) { struct tm d; #if defined(_SVID_SOURCE) || defined(_XOPEN_SOURCE) || defined(__linux__) - extern long timezone; + /* extern long timezone; */ #else int timezone = 0; #endif @@ -267,6 +267,7 @@ int isnumeric(const char *s) return 1; } +__attribute__((noreturn)) void panicexit(const char *sourcefile, const int sourceline) { snprintf(errorstring, 512, "Unexpected error (%s), exiting. (%s:%d)\n", strerror(errno), sourcefile, sourceline); diff --git a/src/common.h b/src/common.h index fbaf4ad2..70f9d947 100644 --- a/src/common.h +++ b/src/common.h @@ -307,7 +307,7 @@ void addtraffic(uint64_t *destmb, int *destkb, const uint64_t srcmb, const int s uint64_t mbkbtokb(uint64_t mb, uint64_t kb); char *strncpy_nt(char *dest, const char *src, size_t n); int isnumeric(const char *s); -void panicexit(const char *sourcefile, const int sourceline); +void panicexit(const char *sourcefile, const int sourceline) __attribute__((noreturn)); char *getversion(void); /* global variables */ diff --git a/src/dbcache.c b/src/dbcache.c index a4329d63..6b852596 100644 --- a/src/dbcache.c +++ b/src/dbcache.c @@ -23,7 +23,7 @@ int cacheadd(const char *iface, int sync) } /* add new node if not in list */ - n = malloc(sizeof(datanode)); + n = (datanode *) malloc(sizeof(datanode)); if (n == NULL) { return 0; @@ -109,7 +109,7 @@ int cacheupdate(void) } /* add new node if not in list */ - n = malloc(sizeof(datanode)); + n = (datanode *) malloc(sizeof(datanode)); if (n == NULL) { return 0; diff --git a/src/dbjson.c b/src/dbjson.c index 2d4a5c1a..c6eb9481 100644 --- a/src/dbjson.c +++ b/src/dbjson.c @@ -131,9 +131,9 @@ void jsonhours(void) void jsondate(time_t *date, int type) { struct tm *d; - char *type1 = "\"date\":{\"year\":%d,\"month\":%d,\"day\":%d}"; - char *type2 = "\"date\":{\"year\":%d,\"month\":%d,\"day\":%d},\"time\":{\"hour\":%d,\"minutes\":%d}"; - char *type3 = "\"date\":{\"year\":%d,\"month\":%d}"; + const char *type1 = "\"date\":{\"year\":%d,\"month\":%d,\"day\":%d}"; + const char *type2 = "\"date\":{\"year\":%d,\"month\":%d,\"day\":%d},\"time\":{\"hour\":%d,\"minutes\":%d}"; + const char *type3 = "\"date\":{\"year\":%d,\"month\":%d}"; d = localtime(date); diff --git a/src/dbxml.c b/src/dbxml.c index b3eddf7b..674080ab 100644 --- a/src/dbxml.c +++ b/src/dbxml.c @@ -107,9 +107,9 @@ void xmlhours(void) void xmldate(time_t *date, int type) { struct tm *d; - char *type1 = "%d%02d%02d"; - char *type2 = "%d%02d%02d"; - char *type3 = "%d%02d"; + const char *type1 = "%d%02d%02d"; + const char *type2 = "%d%02d%02d"; + const char *type3 = "%d%02d"; d = localtime(date); diff --git a/src/ibw.c b/src/ibw.c index 5510d305..4741b2bc 100644 --- a/src/ibw.c +++ b/src/ibw.c @@ -31,7 +31,7 @@ int ibwadd(const char *iface, const uint32_t limit) /* add new node if list is empty */ if (p == NULL) { - n = malloc(sizeof(ibwnode)); + n = (ibwnode *) malloc(sizeof(ibwnode)); if (n == NULL) { return 0; @@ -57,7 +57,7 @@ int ibwadd(const char *iface, const uint32_t limit) } /* add new node if not found */ - n = malloc(sizeof(ibwnode)); + n = (ibwnode *) malloc(sizeof(ibwnode)); if (n == NULL) { return 0; diff --git a/src/ifinfo.c b/src/ifinfo.c index 6a5d25de..0356308d 100644 --- a/src/ifinfo.c +++ b/src/ifinfo.c @@ -58,7 +58,7 @@ int getiflist(char **ifacelist, int showspeed) #endif /* initialize list */ - *ifacelist = malloc(sizeof(char)); + *ifacelist = (char *) malloc(sizeof(char)); if (*ifacelist == NULL) { panicexit(__FILE__, __LINE__); } @@ -72,7 +72,7 @@ int getiflist(char **ifacelist, int showspeed) sscanf(procline, "%63s", temp); if (strlen(temp)>0 && (isdigit(temp[(strlen(temp)-1)]) || temp[(strlen(temp)-1)]==':')) { sscanf(temp, "%31[^':']s", interface); - *ifacelist = realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(interface) + 2 ) * sizeof(char)) ); + *ifacelist = (char *) realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(interface) + 2 ) * sizeof(char)) ); if (*ifacelist == NULL) { panicexit(__FILE__, __LINE__); } @@ -84,7 +84,7 @@ int getiflist(char **ifacelist, int showspeed) speed = getifspeed(interface); if (speed > 0) { snprintf(temp, 64, "(%u Mbit) ", speed); - *ifacelist = realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(temp) + 1 ) * sizeof(char)) ); + *ifacelist = (char *) realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(temp) + 1 ) * sizeof(char)) ); if (*ifacelist == NULL) { panicexit(__FILE__, __LINE__); } @@ -105,7 +105,7 @@ int getiflist(char **ifacelist, int showspeed) if (di->d_name[0] == '.' || strlen(di->d_name) > 31) { continue; } - *ifacelist = realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(di->d_name) + 2 ) * sizeof(char)) ); + *ifacelist = (char *) realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(di->d_name) + 2 ) * sizeof(char)) ); if (*ifacelist == NULL) { panicexit(__FILE__, __LINE__); } @@ -117,7 +117,7 @@ int getiflist(char **ifacelist, int showspeed) speed = getifspeed(di->d_name); if (speed > 0) { snprintf(temp, 64, "(%u Mbit) ", speed); - *ifacelist = realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(temp) + 1 ) * sizeof(char)) ); + *ifacelist = (char *) realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(temp) + 1 ) * sizeof(char)) ); if (*ifacelist == NULL) { panicexit(__FILE__, __LINE__); } @@ -355,7 +355,7 @@ void parseifinfo(int newdb) /* calculate maximum possible transfer since last update based on set maximum rate */ /* and add 10% in order to be on the safe side */ - maxtransfer = ceil((maxbw/(float)8)*interval*(float)1.1); + maxtransfer = ceilf((maxbw/8.0f)*interval*1.1f); if (debug) printf("interval: %"PRIu64" maxbw: %"PRIu32" maxrate: %"PRIu64" rxc: %"PRIu64" txc: %"PRIu64"\n", (uint64_t)interval, maxbw, maxtransfer, rxchange, txchange); diff --git a/src/image.c b/src/image.c index 3cfddca0..6f9038d8 100644 --- a/src/image.c +++ b/src/image.c @@ -128,7 +128,7 @@ void colorinit(IMAGECONTENT *ic) colorinitcheck("ctxd", ic->ctxd, cfg.ctxd, rgb); } -void colorinitcheck(char *color, int value, char *cfgtext, int *rgb) +void colorinitcheck(const char *color, int value, const char *cfgtext, const int *rgb) { if (value==-1) { printf("Error: ImageColorAllocate failed.\n"); diff --git a/src/image.h b/src/image.h index e9188384..552808d7 100644 --- a/src/image.h +++ b/src/image.h @@ -27,7 +27,7 @@ typedef struct { void initimagecontent(IMAGECONTENT *ic); void drawimage(IMAGECONTENT *ic); void colorinit(IMAGECONTENT *ic); -void colorinitcheck(char *color, int value, char *cfgtext, int *rgb); +void colorinitcheck(const char *color, int value, const char *cfgtext, const int *rgb); void layoutinit(IMAGECONTENT *ic, char *title, int width, int height); void drawlegend(IMAGECONTENT *ic, int x, int y); void drawbar(IMAGECONTENT *ic, int x, int y, int len, uint64_t rx, int rxk, uint64_t tx, int txk, uint64_t max); diff --git a/src/misc.c b/src/misc.c index 9842448c..cfc7295b 100644 --- a/src/misc.c +++ b/src/misc.c @@ -304,9 +304,9 @@ uint64_t getscale(uint64_t kb) return result; } -char *getunitprefix(int index) +const char *getunitprefix(int index) { - static char *unitprefix[] = { "na", "KiB", "MiB", "GiB", "TiB", + static const char *unitprefix[] = { "na", "KiB", "MiB", "GiB", "TiB", "KB", "MB", "GB", "TB" }; if (index>UNITPREFIXCOUNT) { @@ -316,9 +316,9 @@ char *getunitprefix(int index) } } -char *getrateunitprefix(int unitmode, int index) +const char *getrateunitprefix(int unitmode, int index) { - static char *rateunitprefix[] = { "na", "KiB/s", "MiB/s", "GiB/s", "TiB/s", + static const char *rateunitprefix[] = { "na", "KiB/s", "MiB/s", "GiB/s", "TiB/s", "KB/s", "MB/s", "GB/s", "TB/s", "Kibit/s", "Mibit/s", "Gibit/s", "Tibit/s", "kbit/s", "Mbit/s", "Gbit/s", "Tbit/s" }; diff --git a/src/misc.h b/src/misc.h index 9910e116..75d29d61 100644 --- a/src/misc.h +++ b/src/misc.h @@ -11,8 +11,8 @@ char *getvalue(uint64_t mb, uint64_t kb, int len, int type); char *getrate(uint64_t mb, uint64_t kb, uint32_t interval, int len); char *gettrafficrate(uint64_t bytes, uint32_t interval, int len); uint64_t getscale(uint64_t kb); -char *getunitprefix(int index); -char *getrateunitprefix(int unitmode, int index); +const char *getunitprefix(int index); +const char *getrateunitprefix(int unitmode, int index); uint64_t getunitdivisor(int unitmode, int index); char *getratestring(uint64_t rate, int len, int declen, int unitmode); int getpadding(int len, char *str); diff --git a/src/vnstat.c b/src/vnstat.c index 43880ac5..3a2139ec 100644 --- a/src/vnstat.c +++ b/src/vnstat.c @@ -297,7 +297,7 @@ int main(int argc, char *argv[]) { printcfgfile(); return 0; } else if (strcmp(argv[currentarg],"--delete")==0) { - p.delete=1; + p.del=1; p.query=0; } else if (strcmp(argv[currentarg],"--iflist")==0) { getiflist(&p.ifacelist, 1); @@ -421,7 +421,7 @@ void initparams(PARAMS *p) p->traffic = 0; p->livetraffic = 0; p->defaultiface = 1; - p->delete=0; + p->del=0; p->livemode = 0; p->ifacelist = NULL; p->cfgfile[0] = '\0'; @@ -612,7 +612,7 @@ void handlecountersync(PARAMS *p) void handledelete(PARAMS *p) { - if (!p->delete) { + if (!p->del) { return; } diff --git a/src/vnstat.h b/src/vnstat.h index 181e03c6..7c8148d6 100644 --- a/src/vnstat.h +++ b/src/vnstat.h @@ -4,7 +4,7 @@ typedef struct { int update, query, newdb, reset, sync, merged, savemerged, import; int create, active, files, force, cleartop, rebuildtotal, traffic; - int livetraffic, defaultiface, delete, livemode; + int livetraffic, defaultiface, del, livemode; char interface[32], dirname[512], nick[32], filename[512]; char definterface[32], cfgfile[512], *ifacelist, jsonmode, xmlmode; } PARAMS; From 5b2c2509235e6c423e09291e534a3d6c70493c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 24 Aug 2017 19:44:18 +0200 Subject: [PATCH 3/4] fix additional compiler warnings Wformat-truncation Wimplicit-declaration of wcswidth() on kFreeBSD Wdiscard-qualifiers --- src/daemon.c | 8 ++++---- src/misc.c | 4 ++++ tests/misc_tests.c | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/daemon.c b/src/daemon.c index 9160cd05..8dc0a9bd 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -40,13 +40,13 @@ void daemonize(void) pidfile = open(cfg.pidfile, O_RDWR|O_CREAT, 0644); if (pidfile<0) { perror("Error: pidfile"); - snprintf(errorstring, 512, "opening pidfile \"%s\" failed (%s), exiting.", cfg.pidfile, strerror(errno)); + snprintf(errorstring, 512, "opening pidfile \"%.473s\" failed (%s), exiting.", cfg.pidfile, strerror(errno)); printe(PT_Error); exit(EXIT_FAILURE); /* can't open */ } if (lockf(pidfile,F_TLOCK,0)<0) { perror("Error: pidfile lock"); - snprintf(errorstring, 512, "pidfile \"%s\" lock failed (%s), exiting.", cfg.pidfile, strerror(errno)); + snprintf(errorstring, 512, "pidfile \"%.476s\" lock failed (%s), exiting.", cfg.pidfile, strerror(errno)); printe(PT_Error); exit(EXIT_FAILURE); /* can't lock */ } @@ -99,7 +99,7 @@ void daemonize(void) /* record pid to pidfile */ if (write(pidfile,str,strlen(str)) < 0) { perror("Error: write(pidfile)"); - snprintf(errorstring, 512, "writing to pidfile %s failed, exiting.", cfg.pidfile); + snprintf(errorstring, 512, "writing to pidfile %.475s failed, exiting.", cfg.pidfile); printe(PT_Error); exit(EXIT_FAILURE); } @@ -300,7 +300,7 @@ void filldatabaselist(DSTATE *s) struct dirent *di; if ((dir=opendir(s->dirname))==NULL) { - snprintf(errorstring, 512, "Unable to access database directory \"%s\" (%s), exiting.", s->dirname, strerror(errno)); + snprintf(errorstring, 512, "Unable to access database directory \"%.460s\" (%s), exiting.", s->dirname, strerror(errno)); printe(PT_Error); /* clean daemon stuff before exit */ diff --git a/src/misc.c b/src/misc.c index cfc7295b..84c22cea 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1,6 +1,10 @@ #if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__APPLE__) && !defined(__FreeBSD_kernel__) #define _XOPEN_SOURCE 600 #endif +/* enable wcswidth on kFreeBSD */ +#if defined(__FreeBSD_kernel__) && defined(__GLIBC__) +#define __USE_XOPEN +#endif #include "common.h" #include "misc.h" #include diff --git a/tests/misc_tests.c b/tests/misc_tests.c index 7815bdf1..3bad42a4 100644 --- a/tests/misc_tests.c +++ b/tests/misc_tests.c @@ -11,7 +11,7 @@ END_TEST START_TEST(getunitprefix_returns_something_with_all_cfg_combinations) { - char *string; + const char *string; int j; cfg.unitmode = _i; @@ -24,7 +24,7 @@ END_TEST START_TEST(getrateunitprefix_returns_something_with_all_cfg_combinations) { - char *string; + const char *string; int j; for (j=1; j<=(UNITPREFIXCOUNT+1); j++) { From 5817a62491d39077ec8149621bdc31152a8b258a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 6 Oct 2017 12:55:39 +0200 Subject: [PATCH 4/4] vnstat.service: add alias `vnstatd.service` --- examples/systemd/vnstat.service | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/systemd/vnstat.service b/examples/systemd/vnstat.service index 1d898f51..676255f0 100644 --- a/examples/systemd/vnstat.service +++ b/examples/systemd/vnstat.service @@ -9,3 +9,4 @@ ExecReload=/bin/kill -HUP $MAINPID [Install] WantedBy=multi-user.target +Alias=vnstatd.service