sdlog2: getopt invalid usage fixed

This commit is contained in:
Anton Babushkin
2014-02-28 00:49:12 +04:00
parent 680f2dd417
commit 8783bed114
+13 -2
View File
@@ -652,6 +652,10 @@ int sdlog2_thread_main(int argc, char *argv[])
argv += 2; argv += 2;
int ch; int ch;
/* don't exit from getopt loop to leave getopt global variables in consistent state,
* set error flag instead */
bool err_flag = false;
while ((ch = getopt(argc, argv, "r:b:eat")) != EOF) { while ((ch = getopt(argc, argv, "r:b:eat")) != EOF) {
switch (ch) { switch (ch) {
case 'r': { case 'r': {
@@ -699,13 +703,20 @@ int sdlog2_thread_main(int argc, char *argv[])
} else { } else {
warnx("unknown option character `\\x%x'", optopt); warnx("unknown option character `\\x%x'", optopt);
} }
err_flag = true;
break;
default: default:
sdlog2_usage("unrecognized flag"); warnx("unrecognized flag");
errx(1, "exiting"); err_flag = true;
break;
} }
} }
if (err_flag) {
sdlog2_usage(NULL);
}
gps_time = 0; gps_time = 0;
/* create log root dir */ /* create log root dir */