Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misspellings and compiler warnings #70

Merged
merged 4 commits into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FAQ
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions examples/systemd/vnstat.service
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
Alias=vnstatd.service
10 changes: 5 additions & 5 deletions man/vnstat.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions man/vnstat.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
10 changes: 5 additions & 5 deletions src/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/dbcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/dbjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions src/dbxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ void xmlhours(void)
void xmldate(time_t *date, int type)
{
struct tm *d;
char *type1 = "<date><year>%d</year><month>%02d</month><day>%02d</day></date>";
char *type2 = "<date><year>%d</year><month>%02d</month><day>%02d</day></date><time><hour>%02d</hour><minute>%02d</minute></time>";
char *type3 = "<date><year>%d</year><month>%02d</month></date>";
const char *type1 = "<date><year>%d</year><month>%02d</month><day>%02d</day></date>";
const char *type2 = "<date><year>%d</year><month>%02d</month><day>%02d</day></date><time><hour>%02d</hour><minute>%02d</minute></time>";
const char *type3 = "<date><year>%d</year><month>%02d</month></date>";

d = localtime(date);

Expand Down
4 changes: 2 additions & 2 deletions src/ibw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/ifinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
}
Expand All @@ -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__);
}
Expand All @@ -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__);
}
Expand All @@ -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__);
}
Expand All @@ -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__);
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions src/misc.c
Original file line number Diff line number Diff line change
@@ -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 <wchar.h>
Expand Down Expand Up @@ -304,9 +308,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) {
Expand All @@ -316,9 +320,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" };
Expand Down
4 changes: 2 additions & 2 deletions src/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/vnstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -612,7 +612,7 @@ void handlecountersync(PARAMS *p)

void handledelete(PARAMS *p)
{
if (!p->delete) {
if (!p->del) {
return;
}

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vnstat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/misc_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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++) {
Expand Down