1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-06-23 06:25:24 +00:00

Cleanup: Got argv[] parser into better shape

This commit is contained in:
Philipp Schafft 2022-02-25 23:05:41 +00:00
parent 00368b68e8
commit 66375b57e4

View File

@ -212,7 +212,7 @@ void main_config_reload(ice_config_t *config)
static bool _parse_config_opts(int argc, char **argv, char *filename, size_t size) static bool _parse_config_opts(int argc, char **argv, char *filename, size_t size)
{ {
int i = 1; int i;
bool config_ok = false; bool config_ok = false;
background = false; background = false;
@ -226,8 +226,10 @@ static bool _parse_config_opts(int argc, char **argv, char *filename, size_t siz
} }
} }
while (i < argc) { for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-b") == 0) { const char *opt = argv[i];
if (strcmp(opt, "-b") == 0) {
#ifndef WIN32 #ifndef WIN32
pid_t pid; pid_t pid;
fprintf(stdout, "Starting icecast2\nDetaching from the console\n"); fprintf(stdout, "Starting icecast2\nDetaching from the console\n");
@ -237,29 +239,27 @@ static bool _parse_config_opts(int argc, char **argv, char *filename, size_t siz
if (pid > 0) { if (pid > 0) {
/* exit the parent */ /* exit the parent */
exit(0); exit(0);
} } else if (pid < 0) {
else if(pid < 0) { fprintf(stderr, "FATAL: Unable to fork child!\n");
fprintf(stderr, "FATAL: Unable to fork child!");
exit(1); exit(1);
} }
background = true; background = true;
#endif #endif
} } else if (strcmp(opt, "-v") == 0 || strcmp(opt, "--version") == 0) {
if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
fprintf(stdout, "%s\n", ICECAST_VERSION_STRING); fprintf(stdout, "%s\n", ICECAST_VERSION_STRING);
exit(0); exit(0);
} } else if (strcmp(opt, "-c") == 0) {
if ((i + 1) < argc) {
if (strcmp(argv[i], "-c") == 0) { strncpy(filename, argv[++i], size-1);
if (i + 1 < argc) {
strncpy(filename, argv[i + 1], size-1);
filename[size-1] = 0; filename[size-1] = 0;
config_ok = true; config_ok = true;
} else { } else {
return false; return false;
} }
} else {
fprintf(stderr, "FATAL: Invalid option: %s\n", opt);
return false;
} }
i++;
} }
return config_ok; return config_ok;