s.updateinterval = cfg.updateinterval;
s.saveinterval = cfg.saveinterval * 60;
- /* parse parameters, maybe not the best way but... */
- for (currentarg = 1; currentarg < argc; currentarg++) {
- if (debug)
- printf("arg %d: \"%s\"\n", currentarg, argv[currentarg]);
- if ((strcmp(argv[currentarg], "-?") == 0) || (strcmp(argv[currentarg], "--help") == 0)) {
- break;
- } else if (strcmp(argv[currentarg], "--config") == 0) {
- /* config has already been parsed earlier so nothing to do here */
- currentarg++;
- continue;
- } else if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) {
- debug = 1;
- } else if ((strcmp(argv[currentarg], "-d") == 0) || (strcmp(argv[currentarg], "--daemon") == 0)) {
- s.rundaemon = 1;
- s.showhelp = 0;
- } else if ((strcmp(argv[currentarg], "-n") == 0) || (strcmp(argv[currentarg], "--nodaemon") == 0)) {
- s.showhelp = 0;
- } else if ((strcmp(argv[currentarg], "-s") == 0) || (strcmp(argv[currentarg], "--sync") == 0)) {
- s.sync = 1;
- } else if ((strcmp(argv[currentarg], "-u") == 0) || (strcmp(argv[currentarg], "--user") == 0)) {
- if (currentarg + 1 < argc) {
- strncpy_nt(s.user, argv[currentarg + 1], 33);
- if (debug)
- printf("Requested user: \"%s\"\n", s.user);
- currentarg++;
- continue;
- } else {
- printf("Error: User for --user missing.\n");
- return 1;
- }
- } else if ((strcmp(argv[currentarg], "-g") == 0) || (strcmp(argv[currentarg], "--group") == 0)) {
- if (currentarg + 1 < argc) {
- strncpy_nt(s.group, argv[currentarg + 1], 33);
- if (debug)
- printf("Requested group: \"%s\"\n", s.group);
- currentarg++;
- continue;
- } else {
- printf("Error: Group for --group missing.\n");
- return 1;
- }
- } else if (strcmp(argv[currentarg], "--noadd") == 0) {
- s.noadd = 1;
- } else if (strcmp(argv[currentarg], "--alwaysadd") == 0) {
- s.alwaysadd = 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", getversion());
- return 0;
- } else if ((strcmp(argv[currentarg], "-p") == 0) || (strcmp(argv[currentarg], "--pidfile") == 0)) {
- if (currentarg + 1 < argc) {
- strncpy_nt(cfg.pidfile, argv[currentarg + 1], 512);
- cfg.pidfile[511] = '\0';
- if (debug)
- printf("Used pid file: %s\n", cfg.pidfile);
- currentarg++;
- continue;
- } else {
- printf("Error: File for --pidfile missing.\n");
- return 1;
- }
- } else {
- printf("Unknown arg \"%s\". Use --help for help.\n", argv[currentarg]);
- return 1;
- }
- }
-
- if (s.noadd && s.alwaysadd) {
- printf("Error: --noadd and --alwaysadd can't both be used at the same time.\n");
- return 1;
- }
-
- if (s.rundaemon && debug) {
- printf("Error: --daemon and --debug can't both be used at the same time.\n");
- return 1;
- }
-
- /* show help if nothing else was asked to be done */
- if (s.showhelp) {
- showhelp();
- return 0;
- }
+ parseargs(&s, argc, argv);
preparedirs(&s);
printf("See also \"man vnstatd\".\n");
}
+
+void parseargs(DSTATE *s, int argc, char **argv)
+{
+ int currentarg;
+
+ /* parse parameters, maybe not the best way but... */
+ for (currentarg = 1; currentarg < argc; currentarg++) {
+ if (debug)
+ printf("arg %d: \"%s\"\n", currentarg, argv[currentarg]);
+ if ((strcmp(argv[currentarg], "-?") == 0) || (strcmp(argv[currentarg], "--help") == 0)) {
+ break;
+ } else if (strcmp(argv[currentarg], "--config") == 0) {
+ /* config has already been parsed earlier so nothing to do here */
+ currentarg++;
+ continue;
+ } else if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) {
+ debug = 1;
+ } else if ((strcmp(argv[currentarg], "-d") == 0) || (strcmp(argv[currentarg], "--daemon") == 0)) {
+ s->rundaemon = 1;
+ s->showhelp = 0;
+ } else if ((strcmp(argv[currentarg], "-n") == 0) || (strcmp(argv[currentarg], "--nodaemon") == 0)) {
+ s->showhelp = 0;
+ } else if ((strcmp(argv[currentarg], "-s") == 0) || (strcmp(argv[currentarg], "--sync") == 0)) {
+ s->sync = 1;
+ } else if ((strcmp(argv[currentarg], "-u") == 0) || (strcmp(argv[currentarg], "--user") == 0)) {
+ if (currentarg + 1 < argc) {
+ strncpy_nt(s->user, argv[currentarg + 1], 33);
+ if (debug)
+ printf("Requested user: \"%s\"\n", s->user);
+ currentarg++;
+ continue;
+ } else {
+ printf("Error: User for --user missing.\n");
+ exit(EXIT_FAILURE);
+ }
+ } else if ((strcmp(argv[currentarg], "-g") == 0) || (strcmp(argv[currentarg], "--group") == 0)) {
+ if (currentarg + 1 < argc) {
+ strncpy_nt(s->group, argv[currentarg + 1], 33);
+ if (debug)
+ printf("Requested group: \"%s\"\n", s->group);
+ currentarg++;
+ continue;
+ } else {
+ printf("Error: Group for --group missing.\n");
+ exit(EXIT_FAILURE);
+ }
+ } else if (strcmp(argv[currentarg], "--noadd") == 0) {
+ s->noadd = 1;
+ } else if (strcmp(argv[currentarg], "--alwaysadd") == 0) {
+ s->alwaysadd = 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", getversion());
+ exit(EXIT_SUCCESS);
+ } else if ((strcmp(argv[currentarg], "-p") == 0) || (strcmp(argv[currentarg], "--pidfile") == 0)) {
+ if (currentarg + 1 < argc) {
+ strncpy_nt(cfg.pidfile, argv[currentarg + 1], 512);
+ cfg.pidfile[511] = '\0';
+ if (debug)
+ printf("Used pid file: %s\n", cfg.pidfile);
+ currentarg++;
+ continue;
+ } else {
+ printf("Error: File for --pidfile missing.\n");
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ printf("Unknown arg \"%s\". Use --help for help.\n", argv[currentarg]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (s->noadd && s->alwaysadd) {
+ printf("Error: --noadd and --alwaysadd can't both be used at the same time.\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (s->rundaemon && debug) {
+ printf("Error: --daemon and --debug can't both be used at the same time.\n");
+ exit(EXIT_FAILURE);
+ }
+
+ /* show help if nothing else was asked to be done */
+ if (s->showhelp) {
+ showhelp();
+ exit(EXIT_SUCCESS);
+ }
+}