"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/vnstatd.c" between
vnstat-2.7.tar.gz and vnstat-2.8.tar.gz

About: vnStat is a console-based network traffic monitor (using the /proc filesystem).

vnstatd.c  (vnstat-2.7):vnstatd.c  (vnstat-2.8)
skipping to change at line 24 skipping to change at line 24
with this program; if not, write to the Free Software Foundation, Inc., with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "common.h" #include "common.h"
#include "datacache.h" #include "datacache.h"
#include "dbsql.h" #include "dbsql.h"
#include "cfg.h" #include "cfg.h"
#include "ibw.h" #include "ibw.h"
#include "id.h" #include "id.h"
#include "misc.h"
#include "daemon.h" #include "daemon.h"
#include "vnstatd.h" #include "vnstatd.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int currentarg; int currentarg;
uint32_t previflisthash; uint32_t previflisthash;
uint64_t temp; uint64_t temp;
DSTATE s; DSTATE s;
skipping to change at line 59 skipping to change at line 60
printf("Error: File for --config missing. \n"); printf("Error: File for --config missing. \n");
return 1; return 1;
} }
} }
} }
} }
timeused_debug("daemon_startup", 1); timeused_debug("daemon_startup", 1);
/* load config if available */ /* load config if available */
if (!loadcfg(s.cfgfile)) { if (!loadcfg(s.cfgfile, CT_Daemon)) {
return 1; return 1;
} }
if (!ibwloadcfg(s.cfgfile)) { if (!ibwloadcfg(s.cfgfile)) {
return 1; return 1;
} }
/* init config settings */ /* init config settings */
strncpy_nt(s.user, cfg.daemonuser, 33); strncpy_nt(s.user, cfg.daemonuser, 33);
strncpy_nt(s.group, cfg.daemongroup, 33); strncpy_nt(s.group, cfg.daemongroup, 33);
s.updateinterval = cfg.updateinterval; s.updateinterval = cfg.updateinterval;
skipping to change at line 124 skipping to change at line 125
if (!db_open_rw(0)) { if (!db_open_rw(0)) {
snprintf(errorstring, 1024, "Failed to reopen database \" %s/%s\": %s", cfg.dbdir, DATABASEFILE, strerror(errno)); snprintf(errorstring, 1024, "Failed to reopen database \" %s/%s\": %s", cfg.dbdir, DATABASEFILE, strerror(errno));
printe(PT_Error); printe(PT_Error);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
timeused_debug("daemon_startup", 0); timeused_debug("daemon_startup", 0);
s.running = 1; s.running = 1;
#if defined(__linux__) #if defined(__linux__) && HAVE_LINUX_RTNETLINK_H
#if HAVE_DECL_IFLA_STATS64 #if HAVE_DECL_IFLA_STATS64
snprintf(errorstring, 1024, "vnStat daemon %s started. (pid:%d uid:%d gid :%d 64-bit)", getversion(), (int)getpid(), (int)getuid(), (int)getgid()); snprintf(errorstring, 1024, "vnStat daemon %s started. (pid:%d uid:%d gid :%d 64-bit)", getversion(), (int)getpid(), (int)getuid(), (int)getgid());
#else #else
snprintf(errorstring, 1024, "vnStat daemon %s started. (pid:%d uid:%d gid :%d 32-bit)", getversion(), (int)getpid(), (int)getuid(), (int)getgid()); snprintf(errorstring, 1024, "vnStat daemon %s started. (pid:%d uid:%d gid :%d 32-bit)", getversion(), (int)getpid(), (int)getuid(), (int)getgid());
#endif #endif
#else #else
snprintf(errorstring, 1024, "vnStat daemon %s started. (pid:%d uid:%d gid :%d)", getversion(), (int)getpid(), (int)getuid(), (int)getgid()); snprintf(errorstring, 1024, "vnStat daemon %s started. (pid:%d uid:%d gid :%d)", getversion(), (int)getpid(), (int)getuid(), (int)getgid());
#endif #endif
printe(PT_Info); printe(PT_Info);
skipping to change at line 164 skipping to change at line 165
/* main loop */ /* main loop */
while (s.running) { while (s.running) {
s.current = time(NULL); s.current = time(NULL);
/* track interface status only if at least one database exists */ /* track interface status only if at least one database exists */
if (s.dbifcount != 0) { if (s.dbifcount != 0) {
previflisthash = s.iflisthash; previflisthash = s.iflisthash;
interfacechangecheck(&s); interfacechangecheck(&s);
if (s.alwaysadd && s.iflisthash != previflisthash && prev iflisthash != 0) { if (cfg.alwaysadd && s.iflisthash != previflisthash && pr eviflisthash != 0) {
temp = s.dbifcount; temp = s.dbifcount;
s.dbifcount += addinterfaces(&s); s.dbifcount += addinterfaces(&s);
if (temp != s.dbifcount) { if (temp != s.dbifcount) {
datacache_status(&s.dcache); datacache_status(&s.dcache);
} }
} }
} }
/* do update only if enough time has passed since the previous up date */ /* do update only if enough time has passed since the previous up date */
if ((s.current - s.prevdbupdate) >= s.updateinterval) { if ((s.current - s.prevdbupdate) >= s.updateinterval) {
skipping to change at line 249 skipping to change at line 250
printf(" -s, --sync sync interface counters on first u pdate\n"); printf(" -s, --sync sync interface counters on first u pdate\n");
printf(" -D, --debug show additional debug and disable daemon\n"); printf(" -D, --debug show additional debug and disable daemon\n");
printf(" -?, --help show this help\n"); printf(" -?, --help show this help\n");
printf(" -v, --version show version\n"); printf(" -v, --version show version\n");
printf(" -p, --pidfile <file> select used pid file\n"); printf(" -p, --pidfile <file> select used pid file\n");
printf(" -u, --user <user> set daemon process user\n"); printf(" -u, --user <user> set daemon process user\n");
printf(" -g, --group <group> set daemon process group\n"); printf(" -g, --group <group> set daemon process group\n");
printf(" --config <config file> select used config file\n"); printf(" --config <config file> select used config file\n");
printf(" --noadd prevent startup if database has no interfaces\n"); printf(" --noadd prevent startup if database has no interfaces\n");
printf(" --alwaysadd automatically start monitoring all new interfaces\n"); printf(" --alwaysadd [mode] automatically start monitoring all new interfaces\n");
printf(" --initdb create empty database and exit\n\n "); printf(" --initdb create empty database and exit\n\n ");
printf("See also \"man vnstatd\".\n"); printf("See also \"man vnstatd\".\n");
} }
void parseargs(DSTATE *s, int argc, char **argv) void parseargs(DSTATE *s, int argc, char **argv)
{ {
int currentarg, pidfiledefined = 0; int currentarg, pidfiledefined = 0;
/* parse parameters, maybe not the best way but... */ /* parse parameters, maybe not the best way but... */
skipping to change at line 300 skipping to change at line 301
if (debug) if (debug)
printf("Requested group: \"%s\"\n", s->gr oup); printf("Requested group: \"%s\"\n", s->gr oup);
currentarg++; currentarg++;
} else { } else {
printf("Error: Group for --group missing.\n"); printf("Error: Group for --group missing.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else if (strcmp(argv[currentarg], "--noadd") == 0) { } else if (strcmp(argv[currentarg], "--noadd") == 0) {
s->noadd = 1; s->noadd = 1;
} else if (strcmp(argv[currentarg], "--alwaysadd") == 0) { } else if (strcmp(argv[currentarg], "--alwaysadd") == 0) {
s->alwaysadd = 1; if (currentarg + 1 < argc && (strlen(argv[currentarg + 1]
) == 1 || ishelprequest(argv[currentarg + 1]))) {
if (!isdigit(argv[currentarg + 1][0]) || atoi(arg
v[currentarg + 1]) > 1 || atoi(argv[currentarg + 1]) < 0) {
if (!ishelprequest(argv[currentarg + 1]))
printf("Error: Invalid mode param
eter \"%s\".\n", argv[currentarg + 1]);
printf(" Valid parameters for %s:\n", arg
v[currentarg]);
printf(" 0 - disabled");
if (!cfg.alwaysadd) {
printf(" (default)");
}
printf("\n 1 - enabled");
if (cfg.alwaysadd) {
printf(" (default)");
}
printf("\n No mode parameter results in f
eature being enabled.\n");
exit(EXIT_FAILURE);
}
cfg.alwaysadd = atoi(argv[currentarg + 1]);
currentarg++;
} else {
cfg.alwaysadd = 1;
}
} else if (strcmp(argv[currentarg], "--initdb") == 0) { } else if (strcmp(argv[currentarg], "--initdb") == 0) {
s->initdb = 1; s->initdb = 1;
s->showhelp = 0; s->showhelp = 0;
} else if ((strcmp(argv[currentarg], "-v") == 0) || (strcmp(argv[ currentarg], "--version") == 0)) { } 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", getversion()); printf("vnStat daemon %s by Teemu Toivola <tst at iki dot fi>\n", getversion());
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} else if ((strcmp(argv[currentarg], "-p") == 0) || (strcmp(argv[ currentarg], "--pidfile") == 0)) { } else if ((strcmp(argv[currentarg], "-p") == 0) || (strcmp(argv[ currentarg], "--pidfile") == 0)) {
if (currentarg + 1 < argc) { if (currentarg + 1 < argc) {
strncpy_nt(cfg.pidfile, argv[currentarg + 1], 512 ); strncpy_nt(cfg.pidfile, argv[currentarg + 1], 512 );
cfg.pidfile[511] = '\0'; cfg.pidfile[511] = '\0';
skipping to change at line 325 skipping to change at line 346
} else { } else {
printf("Error: File for --pidfile missing.\n"); printf("Error: File for --pidfile missing.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else { } else {
printf("Unknown arg \"%s\". Use --help for help.\n", argv [currentarg]); printf("Unknown arg \"%s\". Use --help for help.\n", argv [currentarg]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
if (s->noadd && s->alwaysadd) { if (s->noadd && cfg.alwaysadd) {
printf("Error: --noadd and --alwaysadd can't both be used at the printf("Warning: --noadd and --alwaysadd can't both be enabled at
same time.\n"); the same time. --alwaysadd has been disabled.\n");
exit(EXIT_FAILURE); cfg.alwaysadd = 0;
} }
if (s->rundaemon && debug) { if (s->rundaemon && debug) {
printf("Error: --daemon and --debug can't both be used at the sam e time.\n"); printf("Error: --daemon and --debug can't both be used at the sam e time.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (s->rundaemon && s->initdb) { if (s->rundaemon && s->initdb) {
printf("Error: --daemon and --initdb can't both be used at the sa me time.\n"); printf("Error: --daemon and --initdb can't both be used at the sa me time.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
 End of changes. 7 change blocks. 
9 lines changed or deleted 35 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)