myclean: maintainer-clean
clean-local:
- -rm -fr coverage *.lcov *.gz test*.log test*.xml
+ -rm -fr coverage *.lcov *.gz test*.log test*.xml src/*.gc* tests/*.gc*
myclean: maintainer-clean
clean-local:
- -rm -fr coverage *.lcov *.gz test*.log test*.xml
+ -rm -fr coverage *.lcov *.gz test*.log test*.xml src/*.gc* tests/*.gc*
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
{
ibwnode *p = ifacebw;
- printf("# vnStat %s config file\n", VNSTATVERSION);
+ printf("# vnStat %s config file\n", getversion());
printf("##\n\n");
printf("# default interface\n");
printe(PT_Error);
exit(EXIT_FAILURE);
}
+
+char *getversion(void)
+{
+ int i;
+ static char versionbuffer[16];
+ strncpy_nt(versionbuffer, VERSION, 16);
+ for (i=0; i<strlen(versionbuffer); i++) {
+ if (versionbuffer[i] == '_') {
+ versionbuffer[i] = ' ';
+ }
+ }
+ return versionbuffer;
+}
/* 1 = 1.0, 2 = 1.1-1.2, 3 = 1.3- */
#define DBVERSION 3
-/* version string */
-#define VNSTATVERSION "1.15 beta"
-
/* xml format version */
/* 1 = 1.7- */
#define XMLVERSION 1
char *strncpy_nt(char *dest, const char *src, size_t n);
int isnumeric(const char *s);
void panicexit(const char *sourcefile, const int sourceline);
+char *getversion(void);
/* global variables */
DATA data;
setsid(); /* obtain a new process group */
if (cfg.uselogging) {
- snprintf(errorstring, 512, "vnStat daemon %s started. (uid:%d gid:%d)", VNSTATVERSION, (int)getuid(), (int)getgid());
+ snprintf(errorstring, 512, "vnStat daemon %s started. (uid:%d gid:%d)", VERSION, (int)getuid(), (int)getgid());
if (!printe(PT_Info)) {
printf("Error: Unable to use logfile. Exiting.\n");
exit(EXIT_FAILURE);
void jsonheader(void)
{
- printf("{\"vnstatversion\":\"%s\",\"jsonversion\":\"%d\",\"interfaces\":[", VNSTATVERSION, JSONVERSION);
+ printf("{\"vnstatversion\":\"%s\",\"jsonversion\":\"%d\",\"interfaces\":[", getversion(), JSONVERSION);
}
void jsonfooter(void)
void xmlheader(void)
{
- printf("<vnstat version=\"%s\" xmlversion=\"%d\">\n", VNSTATVERSION, XMLVERSION);
+ printf("<vnstat version=\"%s\" xmlversion=\"%d\">\n", getversion(), XMLVERSION);
}
void xmlfooter(void)
free(p.ifacelist);
return 0;
} else if ((strcmp(argv[currentarg],"-v")==0) || (strcmp(argv[currentarg],"--version")==0)) {
- printf("vnStat %s by Teemu Toivola <tst at iki dot fi>\n", VNSTATVERSION);
+ printf("vnStat %s by Teemu Toivola <tst at iki dot fi>\n", getversion());
return 0;
} else if ((strcmp(argv[currentarg],"-r")==0) || (strcmp(argv[currentarg],"--reset")==0)) {
p.reset=1;
void showhelp(PARAMS *p)
{
- printf(" vnStat %s by Teemu Toivola <tst at iki dot fi>\n\n", VNSTATVERSION);
+ printf(" vnStat %s by Teemu Toivola <tst at iki dot fi>\n\n", getversion());
printf(" -q, --query query database\n");
printf(" -h, --hours show hours\n");
void showlonghelp(PARAMS *p)
{
- printf(" vnStat %s by Teemu Toivola <tst at iki dot fi>\n\n", VNSTATVERSION);
+ printf(" vnStat %s by Teemu Toivola <tst at iki dot fi>\n\n", getversion());
printf(" Query:\n");
printf(" -q, --query query database\n");
} else if (strcmp(argv[currentarg],"--noadd")==0) {
s.noadd = 1;
} else if ((strcmp(argv[currentarg],"-v")==0) || (strcmp(argv[currentarg],"--version")==0)) {
- printf("vnStat daemon %s by Teemu Toivola <tst at iki dot fi>\n", VNSTATVERSION);
+ printf("vnStat daemon %s by Teemu Toivola <tst at iki dot fi>\n", getversion());
return 0;
} else if ((strcmp(argv[currentarg],"-p")==0) || (strcmp(argv[currentarg],"--pidfile")==0)) {
if (currentarg+1<argc) {
void showhelp(void)
{
- printf(" vnStat daemon %s by Teemu Toivola <tst at iki dot fi>\n\n", VNSTATVERSION);
+ printf(" vnStat daemon %s by Teemu Toivola <tst at iki dot fi>\n\n", getversion());
printf(" -d, --daemon fork process to background\n");
printf(" -n, --nodaemon stay in foreground attached to the terminal\n\n");
printf(" -s, --sync sync interface counters on first update\n");
printf("Rateunit changed: %d\n", cfg.rateunit);
}
} else if ((strcmp(argv[currentarg],"-v")==0) || (strcmp(argv[currentarg],"--version"))==0) {
- printf("vnStat image output %s by Teemu Toivola <tst at iki dot fi>\n", VNSTATVERSION);
+ printf("vnStat image output %s by Teemu Toivola <tst at iki dot fi>\n", getversion());
return 0;
} else {
printf("Unknown arg \"%s\". Use --help for help.\n",argv[currentarg]);
void showihelp(IPARAMS *p)
{
- printf(" vnStat image output %s by Teemu Toivola <tst at iki dot fi>\n\n", VNSTATVERSION);
+ printf(" vnStat image output %s by Teemu Toivola <tst at iki dot fi>\n\n", getversion());
printf(" -h, --hours output hours\n");
printf(" -d, --days output days\n");
printf(" -m, --months output months\n");
}
END_TEST
+START_TEST(getversion_returns_a_version)
+{
+ ck_assert_int_gt((int)strlen(getversion()), 1);
+ ck_assert(strchr(getversion(), '_') == NULL);
+ ck_assert(strchr(getversion(), '.') != NULL);
+}
+END_TEST
+
void add_common_tests(Suite *s)
{
TCase *tc_common = tcase_create("Common");
tcase_add_test(tc_common, isnumeric_empty);
tcase_add_test(tc_common, isnumeric_it_is);
tcase_add_test(tc_common, isnumeric_it_is_not);
+ tcase_add_test(tc_common, getversion_returns_a_version);
suite_add_tcase(s, tc_common);
}