Skip to content

Commit 8d13093

Browse files
committed
fix: use exit instead of return for argument parsing errors
Update error handling in main.c to call exit(EXIT_FAILURE) directly instead of returning from parse_arg_list when encountering invalid arguments (such as cache size thresholds or config file errors). This ensures consistent exit behavior.
1 parent 47d79de commit 8d13093

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/main.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,16 @@ int main(int argc, char **argv)
101101
add_arg(&all_argv, &all_argc, argv[i]);
102102
if (!strncmp(argv[i], "--config=", 9)) {
103103
if (argv[i][9] == '\0') {
104-
lprintf(fatal, "--config requires a path\n");
104+
lprintf(error, "--config requires a path\n");
105+
exit(EXIT_FAILURE);
105106
}
106107
FREE(config_path);
107108
config_path = STRDUP(argv[i] + 9);
108109
} else if (!strcmp(argv[i], "--config")) {
109110
if (i + 1 >= argc || argv[i + 1][0] == '\0'
110111
|| argv[i + 1][0] == '-') {
111-
lprintf(fatal, "--config requires a path\n");
112+
lprintf(error, "--config requires a path\n");
113+
exit(EXIT_FAILURE);
112114
}
113115
FREE(config_path);
114116
config_path = STRDUP(argv[i + 1]);
@@ -486,7 +488,7 @@ static int parse_arg_list(int argc, char **argv, char ***fuse_argv,
486488
fprintf(stderr,
487489
"Error: --cache-min-size requires a "
488490
"non-negative integer within off_t range\n");
489-
return 1;
491+
exit(EXIT_FAILURE);
490492
}
491493
CONFIG.cache_min_size = (off_t)val;
492494
} break;
@@ -499,25 +501,25 @@ static int parse_arg_list(int argc, char **argv, char ***fuse_argv,
499501
fprintf(stderr,
500502
"Error: --cache-max-size requires a "
501503
"non-negative integer within off_t range\n");
502-
return 1;
504+
exit(EXIT_FAILURE);
503505
}
504506
CONFIG.cache_max_size = (off_t)val;
505507
} break;
506508
default:
507509
fprintf(stderr, "see httpdirfs -h for usage\n");
508-
return 1;
510+
exit(EXIT_FAILURE);
509511
}
510512
break;
511513
default:
512514
fprintf(stderr, "see httpdirfs -h for usage\n");
513-
return 1;
515+
exit(EXIT_FAILURE);
514516
}
515517
};
516518
if (CONFIG.cache_min_size >= 0 && CONFIG.cache_max_size >= 0
517519
&& CONFIG.cache_min_size > CONFIG.cache_max_size) {
518520
fprintf(stderr, "Error: --cache-min-size cannot be greater than "
519521
"--cache-max-size\n");
520-
return 1;
522+
exit(EXIT_FAILURE);
521523
}
522524
return 0;
523525
}

0 commit comments

Comments
 (0)