main: fix -r and -t options

Add -t option to optstring.

Check for optarg when using -r. Fixes max_redirect initializing to
the same value of max_clients when using short option -r.
master
Jose M. Guisado 2022-02-16 20:58:45 +01:00
parent c80bd1c525
commit 93eb1de2a7
1 changed files with 8 additions and 6 deletions

View File

@ -54,7 +54,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
while (1) { while (1) {
val = getopt_long(argc, argv, "n:r::d", tip_repo_opts, NULL); val = getopt_long(argc, argv, "n:t:r::d", tip_repo_opts, NULL);
if (val < 0) if (val < 0)
break; break;
@ -67,16 +67,18 @@ int main(int argc, char *argv[])
} }
break; break;
case 'r': case 'r':
if (optind < argc && if (optarg) {
max_redirect = atoi(optarg);
} else if (optind < argc &&
argv[optind][0] != '-') { argv[optind][0] != '-') {
max_redirect = atoi(argv[optind++]); max_redirect = atoi(argv[optind++]);
} else {
max_redirect = max_clients;
}
if (max_redirect < 0) { if (max_redirect < 0) {
syslog(LOG_ERR, "Invalid number for redirections"); syslog(LOG_ERR, "Invalid number for redirections");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} else {
max_redirect = max_clients;
}
break; break;
case 't': case 't':
root = strdup(optarg); root = strdup(optarg);