s->alwaysadd = 0;
s->iflisthash = 0;
s->cfgfile[0] = '\0';
- s->dirname[0] = '\0';
s->user[0] = '\0';
s->group[0] = '\0';
s->prevdbupdate = 0;
exit(EXIT_FAILURE);
}
- if (!spacecheck(s->dirname)) {
+ if (!spacecheck(cfg.dbdir)) {
printf("Error: Not enough free diskspace available, exiting.\n");
exit(EXIT_FAILURE);
}
struct dirent *di;
unsigned int importcount = 0;
- if ((dir = opendir(s->dirname)) == NULL) {
- printf("Error: Unable to open database directory \"%s\": %s\n", s->dirname, strerror(errno));
+ if ((dir = opendir(cfg.dbdir)) == NULL) {
+ printf("Error: Unable to open database directory \"%s\": %s\n", cfg.dbdir, strerror(errno));
printf("Make sure it exists and is at least read enabled for current user.\n");
printf("Exiting...\n");
exit(EXIT_FAILURE);
if (db_getinterfacecountbyname(di->d_name)) {
continue;
}
- if (importlegacydb(di->d_name, s->dirname)) {
+ if (importlegacydb(di->d_name, cfg.dbdir)) {
importcount++;
}
}
s->dbifcount = 0;
ibwflush();
db_close();
- if (loadcfg(s->cfgfile)) {
- strncpy_nt(s->dirname, cfg.dbdir, 512);
- }
+ loadcfg(s->cfgfile);
ibwloadcfg(s->cfgfile);
if (!db_open_rw(1)) {
snprintf(errorstring, 1024, "Opening database after SIGHUP failed (%s), exiting.", strerror(errno));
void preparedirs(DSTATE *s)
{
/* database directory */
- if (mkpath(s->dirname, 0775)) {
- updatedirowner(s->dirname, s->user, s->group);
+ if (mkpath(cfg.dbdir, 0775)) {
+ updatedirowner(cfg.dbdir, s->user, s->group);
}
if (!cfg.createdirs || !s->rundaemon) {
short alwaysadd, bootdetected, cleanuphour, dbretrycount;
uint32_t iflisthash;
uint64_t dbifcount;
- char cfgfile[512], dirname[512];
+ char cfgfile[512];
char user[33], group[33];
time_t current, prevdbupdate, prevdbsave, prevwaldbcheckpoint;
datacache *dcache;
strncpy_nt(p.definterface, cfg.iface, 32);
strncpy_nt(p.alias, "none", 32);
- /* init dirname */
- strncpy_nt(p.dirname, cfg.dbdir, 512);
-
/* parse parameters, maybe not the best way but... */
for (currentarg = 1; currentarg < argc; currentarg++) {
if (debug)
}
} else if ((strcmp(argv[currentarg], "--dbdir")) == 0) {
if (currentarg + 1 < argc) {
- strncpy_nt(p.dirname, argv[currentarg + 1], 512);
+ strncpy_nt(cfg.dbdir, argv[currentarg + 1], 512);
if (debug)
- printf("DatabaseDir: \"%s\"\n", p.dirname);
+ printf("DatabaseDir: \"%s\"\n", cfg.dbdir);
currentarg++;
continue;
} else {
/* open database and see if it contains any interfaces */
if (!p.traffic && !p.livetraffic) {
- if ((dir = opendir(p.dirname)) != NULL) {
+ if ((dir = opendir(cfg.dbdir)) != NULL) {
if (debug)
printf("Dir OK\n");
closedir(dir);
- strncpy_nt(cfg.dbdir, p.dirname, 512);
if (!db_open_ro()) {
- printf("Error: Failed to open database \"%s/%s\" in read-only mode.\n", p.dirname, DATABASEFILE);
+ printf("Error: Failed to open database \"%s/%s\" in read-only mode.\n", cfg.dbdir, DATABASEFILE);
if (errno == ENOENT) {
printf("The vnStat daemon should have created the database when started.\n");
printf("Check that it is configured and running. See also \"man vnstatd\".\n");
strncpy_nt(p.definterface, cfg.iface, 32);
}
} else {
- printf("Error: Unable to open database directory \"%s\": %s\n", p.dirname, strerror(errno));
+ printf("Error: Unable to open database directory \"%s\": %s\n", cfg.dbdir, strerror(errno));
if (errno == ENOENT) {
printf("The vnStat daemon should have created this directory when started.\n");
printf("Check that it is configured and running. See also \"man vnstatd\".\n");
}
if (!db_close() || !db_open_rw(0)) {
- printf("Error: Handling database \"%s/%s\" failing: %s\n", p->dirname, DATABASEFILE, strerror(errno));
+ printf("Error: Handling database \"%s/%s\" failing: %s\n", cfg.dbdir, DATABASEFILE, strerror(errno));
exit(EXIT_FAILURE);
}
exit(EXIT_FAILURE);
}
- if (!p->force && !spacecheck(p->dirname)) {
+ if (!p->force && !spacecheck(cfg.dbdir)) {
printf("Error: Not enough free diskspace available.\n");
exit(EXIT_FAILURE);
}
if (!db_close() || !db_open_rw(0)) {
- printf("Error: Handling database \"%s/%s\" failing: %s\n", p->dirname, DATABASEFILE, strerror(errno));
+ printf("Error: Handling database \"%s/%s\" failing: %s\n", cfg.dbdir, DATABASEFILE, strerror(errno));
exit(EXIT_FAILURE);
}
}
if (!db_close() || !db_open_rw(0)) {
- printf("Error: Handling database \"%s/%s\" failing: %s\n", p->dirname, DATABASEFILE, strerror(errno));
+ printf("Error: Handling database \"%s/%s\" failing: %s\n", cfg.dbdir, DATABASEFILE, strerror(errno));
exit(EXIT_FAILURE);
}
int addiface, force, traffic;
int livetraffic, defaultiface, removeiface, livemode;
uint64_t dbifcount;
- char interface[32], dirname[512], alias[32], filename[512];
+ char interface[32], alias[32], filename[512];
char definterface[32], cfgfile[512], *ifacelist, jsonmode, xmlmode;
char databegin[18], dataend[18];
} PARAMS;
return 1;
}
- /* init dirname and other config settings */
- strncpy_nt(s.dirname, cfg.dbdir, 512);
+ /* init config settings */
strncpy_nt(s.user, cfg.daemonuser, 33);
strncpy_nt(s.group, cfg.daemongroup, 33);
s.updateinterval = cfg.updateinterval;
setuser(s.user);
if (!db_open_rw(1)) {
- printf("Error: Failed to open database \"%s/%s\" in read/write mode.\n", s.dirname, DATABASEFILE);
+ printf("Error: Failed to open database \"%s/%s\" in read/write mode.\n", cfg.dbdir, DATABASEFILE);
printf("Exiting...\n");
exit(EXIT_FAILURE);
}
preparedatabases(&s);
if (!db_removeoldentries()) {
- printf("Error: Database \"%s/%s\" cleanup failed: %s\n", s.dirname, DATABASEFILE, strerror(errno));
+ printf("Error: Database \"%s/%s\" cleanup failed: %s\n", cfg.dbdir, DATABASEFILE, strerror(errno));
printf("Exiting...\n");
exit(EXIT_FAILURE);
}
/* start as daemon if requested, debug can't be enabled at the same time */
if (s.rundaemon && !debug) {
if (!db_close()) {
- printf("Error: Failed to close database \"%s/%s\" before starting daemon: %s\n", s.dirname, DATABASEFILE, strerror(errno));
+ printf("Error: Failed to close database \"%s/%s\" before starting daemon: %s\n", cfg.dbdir, DATABASEFILE, strerror(errno));
printf("Exiting...\n");
exit(EXIT_FAILURE);
}
noexit++;
daemonize();
if (!db_open_rw(0)) {
- snprintf(errorstring, 1024, "Failed to reopen database \"%s/%s\": %s", s.dirname, DATABASEFILE, strerror(errno));
+ snprintf(errorstring, 1024, "Failed to reopen database \"%s/%s\": %s", cfg.dbdir, DATABASEFILE, strerror(errno));
printe(PT_Error);
exit(EXIT_FAILURE);
}
defaultcfg();
initdstate(&s);
suppress_output();
- strncpy_nt(s.dirname, TESTDBDIR, 512);
+ strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
ck_assert_int_eq(remove_directory(TESTDIR), 1);
ck_assert_int_eq(clean_testdbdir(), 1);
initdstate(&s);
s.noadd = 1;
suppress_output();
- strncpy_nt(s.dirname, TESTDBDIR, 512);
+ strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
ck_assert_int_eq(remove_directory(TESTDIR), 1);
ck_assert_int_eq(clean_testdbdir(), 1);
defaultcfg();
initdstate(&s);
suppress_output();
- strncpy_nt(s.dirname, TESTDBDIR, 512);
+ strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
ck_assert_int_eq(remove_directory(TESTDIR), 1);
ck_assert_int_eq(clean_testdbdir(), 1);
fake_proc_net_dev("w", "ethone", 1, 2, 3, 4);
defaultcfg();
initdstate(&s);
disable_logprints();
- strncpy_nt(s.dirname, TESTDBDIR, 512);
+ strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
ck_assert_int_eq(remove_directory(TESTDIR), 1);
filldatabaselist(&s);
initdstate(&s);
disable_logprints();
strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
- strncpy_nt(s.dirname, TESTDBDIR, 512);
+ strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
s.sync = 1;
ck_assert_int_eq(remove_directory(TESTDIR), 1);
ck_assert_int_eq(clean_testdbdir(), 1);
s.running = 1;
intsignal = SIGHUP;
- strncpy_nt(s.dirname, TESTDBDIR, 512);
+ strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
handleintsignals(&s);
ck_assert_int_eq(intsignal, 0);
ck_assert_int_eq(s.running, 1);
defaultcfg();
cfg.uselogging = 1;
s.rundaemon = 1;
- strncpy_nt(s.dirname, TESTDBDIR, 512);
+ strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
snprintf(logdir, 500, "%s/log/vnstat", TESTDIR);
snprintf(piddir, 500, "%s/pid/vnstat", TESTDIR);
snprintf(cfg.logfile, 512, "%s/vnstat.log", logdir);
defaultcfg();
cfg.uselogging = 1;
s.rundaemon = 1;
- strncpy_nt(s.dirname, TESTDBDIR, 512);
+ strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
snprintf(logdir, 500, "%s/log/vnstat", TESTDIR);
snprintf(piddir, 500, "%s/pid/vnstat", TESTDIR);
snprintf(cfg.logfile, 512, "%s/vnstat.log", logdir);