kill: a better option parser

The previous commit would not work in newlib. Further investigation
found a better way of parsing this extra option using optind

References:
 commit 536cea324b
This commit is contained in:
Craig Small 2017-02-07 22:37:36 +11:00
parent 536cea324b
commit 9ca2f35f04

View File

@ -422,7 +422,6 @@ static void __attribute__ ((__noreturn__))
int loop = 1; int loop = 1;
long pid; long pid;
int exitvalue = EXIT_SUCCESS; int exitvalue = EXIT_SUCCESS;
int optindex;
char *sig_option; char *sig_option;
static const struct option longopts[] = { static const struct option longopts[] = {
@ -447,14 +446,14 @@ static void __attribute__ ((__noreturn__))
signo = SIGTERM; signo = SIGTERM;
opterr=0; /* suppress errors on -123 */ opterr=0; /* suppress errors on -123 */
while (loop == 1 && (i = getopt_long(argc, argv, "l::Ls:hV", longopts, &optindex)) != -1) while (loop == 1 && (i = getopt_long(argc, argv, "l::Ls:hV", longopts, NULL)) != -1)
switch (i) { switch (i) {
case 'l': case 'l':
sig_option = NULL; sig_option = NULL;
if (optarg) { if (optarg) {
sig_option = optarg; sig_option = optarg;
} else if (argv[optindex+1] != NULL && argv[optindex+1][0] != '-') { } else if (argv[optind] != NULL && argv[optind][0] != '-') {
sig_option = argv[optindex+1]; sig_option = argv[optind];
} }
if (sig_option) { if (sig_option) {
char *s; char *s;