main() now exits with return in all cases, except when the daemon runs; #2752
Costa Tsaousis (ktsaou) committed
Sep 17, 2017 at 23:42 UTC
c54af7e0d2cd80fa3e10378313c55b9854f54354
1 file changed
+19
-18
src/main.c
+19
-18
@@ -239,7 +239,7 @@ struct option_def options[] = {
239
{ 'W', "See Advanced options below.", "options", NULL},
240
};
241
242
-void help(int exitcode) {
242
+int help(int exitcode) {
243
FILE *stream;
244
if(exitcode == 0)
245
stream = stdout;
@@ -318,7 +318,7 @@ void help(int exitcode) {
318
);
319
320
fflush(stream);
321
- exit(exitcode);
321
+ return exitcode;
322
}
323
324
// TODO: Remove this function with the nix major release.
@@ -595,7 +595,7 @@ int main(int argc, char **argv) {
595
case 'c':
596
if(config_load(optarg, 1) != 1) {
597
error("Cannot load configuration file %s.", optarg);
598
- exit(1);
598
+ return 1;
599
}
600
else {
601
debug(D_OPTIONS, "Configuration loaded from %s.", optarg);
@@ -606,7 +606,7 @@ int main(int argc, char **argv) {
606
dont_fork = 1;
607
break;
608
case 'h':
609
- help(0);
609
+ return help(0);
610
break;
611
case 'i':
612
config_set(CONFIG_SECTION_WEB, "bind to", optarg);
@@ -637,8 +637,8 @@ int main(int argc, char **argv) {
637
char* debug_flags_string = "debug_flags=";
638
639
if(strcmp(optarg, "unittest") == 0) {
640
- if(unit_test_buffer()) exit(1);
641
- if(unit_test_str2ld()) exit(1);
640
+ if(unit_test_buffer()) return 1;
641
+ if(unit_test_str2ld()) return 1;
642
//default_rrd_update_every = 1;
643
//default_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
644
//if(!config_loaded) config_load(NULL, 0);
@@ -648,10 +648,10 @@ int main(int argc, char **argv) {
648
default_health_enabled = 0;
649
rrd_init("unittest");
650
default_rrdpush_enabled = 0;
651
- if(run_all_mockup_tests()) exit(1);
652
- if(unit_test_storage()) exit(1);
651
+ if(run_all_mockup_tests()) return 1;
652
+ if(unit_test_storage()) return 1;
653
fprintf(stderr, "\n\nALL TESTS PASSED\n\n");
654
- exit(0);
654
+ return 0;
655
}
656
else if(strcmp(optarg, "simple-pattern") == 0) {
657
if(optind + 2 > argc) {
@@ -675,7 +675,7 @@ int main(int argc, char **argv) {
675
" -W simple-pattern '!/path/*/*.ext /path/*.ext' '/path/test.ext'\n"
676
"\n"
677
);
678
- exit(1);
678
+ return 1;
679
}
680
681
const char *heystack = argv[optind];
@@ -688,11 +688,11 @@ int main(int argc, char **argv) {
688
689
if(ret) {
690
fprintf(stdout, "RESULT: MATCHED - pattern '%s' matches '%s'\n", heystack, needle);
691
- exit(0);
691
+ return 0;
692
}
693
else {
694
fprintf(stdout, "RESULT: NOT MATCHED - pattern '%s' does not match '%s'\n", heystack, needle);
695
- exit(1);
695
+ return 1;
696
}
697
}
698
else if(strncmp(optarg, stacksize_string, strlen(stacksize_string)) == 0) {
@@ -718,7 +718,7 @@ int main(int argc, char **argv) {
718
" parameters."
719
"\n"
720
);
721
- exit(1);
721
+ return 1;
722
}
723
const char *section = argv[optind];
724
const char *key = argv[optind + 1];
@@ -743,7 +743,7 @@ int main(int argc, char **argv) {
743
" -c netdata.conf has to be given before -W get.\n"
744
"\n"
745
);
746
- exit(1);
746
+ return 1;
747
}
748
749
if(!config_loaded) {
@@ -759,18 +759,18 @@ int main(int argc, char **argv) {
759
const char *def = argv[optind + 2];
760
const char *value = config_get(section, key, def);
761
printf("%s\n", value);
762
- exit(0);
762
+ return 0;
763
}
764
else {
765
fprintf(stderr, "Unknown -W parameter '%s'\n", optarg);
766
- help(1);
766
+ return help(1);
767
}
768
}
769
break;
770
+
771
default: /* ? */
772
fprintf(stderr, "Unknown parameter '%c'\n", opt);
772
- help(1);
773
- break;
773
+ return help(1);
774
}
775
}
776
}
@@ -1001,5 +1001,6 @@ int main(int argc, char **argv) {
1001
signals_handle();
1002
1003
// should never reach this point
1004
+ // but we need it for rpmlint #2752
1005
return 1;
1006
}