pgrep: Fixing regression in exitcodes
The pgrep usage() rework commit from 26-Sep-2011 introduced a regression in exitcodes and the pgrep tool now returns EXIT_FAILURE (1) or even EXIT_SUCCESS (0) instead of the documented EXIT_USAGE (2). This commit fixes the usage() so that the exitcodes match the manual.
This commit is contained in:
parent
411d218793
commit
4ba9ff5c0d
36
pgrep.c
36
pgrep.c
@ -137,7 +137,7 @@ static int __attribute__ ((__noreturn__)) usage(int opt)
|
|||||||
fputs(USAGE_VERSION, fp);
|
fputs(USAGE_VERSION, fp);
|
||||||
fprintf(fp, USAGE_MAN_TAIL("pgrep(1)"));
|
fprintf(fp, USAGE_MAN_TAIL("pgrep(1)"));
|
||||||
|
|
||||||
exit(fp == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
|
exit(fp == stderr ? EXIT_USAGE : EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct el *split_list (const char *restrict str, int (*convert)(const char *, struct el *))
|
static struct el *split_list (const char *restrict str, int (*convert)(const char *, struct el *))
|
||||||
@ -747,7 +747,7 @@ static void parse_opts (int argc, char **argv)
|
|||||||
case 'G': /* Solaris: match rgid/rgroup */
|
case 'G': /* Solaris: match rgid/rgroup */
|
||||||
opt_rgid = split_list (optarg, conv_gid);
|
opt_rgid = split_list (optarg, conv_gid);
|
||||||
if (opt_rgid == NULL)
|
if (opt_rgid == NULL)
|
||||||
usage (opt);
|
usage ('?');
|
||||||
++criteria_count;
|
++criteria_count;
|
||||||
break;
|
break;
|
||||||
/* case 'I': / * FreeBSD: require confirmation before killing * /
|
/* case 'I': / * FreeBSD: require confirmation before killing * /
|
||||||
@ -764,7 +764,7 @@ static void parse_opts (int argc, char **argv)
|
|||||||
case 'P': /* Solaris: match by PPID */
|
case 'P': /* Solaris: match by PPID */
|
||||||
opt_ppid = split_list (optarg, conv_num);
|
opt_ppid = split_list (optarg, conv_num);
|
||||||
if (opt_ppid == NULL)
|
if (opt_ppid == NULL)
|
||||||
usage (opt);
|
usage ('?');
|
||||||
++criteria_count;
|
++criteria_count;
|
||||||
break;
|
break;
|
||||||
/* case 'S': / * FreeBSD: don't ignore the built-in kernel tasks * /
|
/* case 'S': / * FreeBSD: don't ignore the built-in kernel tasks * /
|
||||||
@ -774,7 +774,7 @@ static void parse_opts (int argc, char **argv)
|
|||||||
case 'U': /* Solaris: match by ruid/rgroup */
|
case 'U': /* Solaris: match by ruid/rgroup */
|
||||||
opt_ruid = split_list (optarg, conv_uid);
|
opt_ruid = split_list (optarg, conv_uid);
|
||||||
if (opt_ruid == NULL)
|
if (opt_ruid == NULL)
|
||||||
usage (opt);
|
usage ('?');
|
||||||
++criteria_count;
|
++criteria_count;
|
||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
@ -794,7 +794,7 @@ static void parse_opts (int argc, char **argv)
|
|||||||
case 'g': /* Solaris: match pgrp */
|
case 'g': /* Solaris: match pgrp */
|
||||||
opt_pgrp = split_list (optarg, conv_pgrp);
|
opt_pgrp = split_list (optarg, conv_pgrp);
|
||||||
if (opt_pgrp == NULL)
|
if (opt_pgrp == NULL)
|
||||||
usage (opt);
|
usage ('?');
|
||||||
++criteria_count;
|
++criteria_count;
|
||||||
break;
|
break;
|
||||||
/* case 'i': / * FreeBSD: ignore case. OpenBSD: withdrawn. See -I. This sucks. * /
|
/* case 'i': / * FreeBSD: ignore case. OpenBSD: withdrawn. See -I. This sucks. * /
|
||||||
@ -812,37 +812,37 @@ static void parse_opts (int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
case 'n': /* Solaris: match only the newest */
|
case 'n': /* Solaris: match only the newest */
|
||||||
if (opt_oldest|opt_negate|opt_newest)
|
if (opt_oldest|opt_negate|opt_newest)
|
||||||
usage (opt);
|
usage ('?');
|
||||||
opt_newest = 1;
|
opt_newest = 1;
|
||||||
++criteria_count;
|
++criteria_count;
|
||||||
break;
|
break;
|
||||||
case 'o': /* Solaris: match only the oldest */
|
case 'o': /* Solaris: match only the oldest */
|
||||||
if (opt_oldest|opt_negate|opt_newest)
|
if (opt_oldest|opt_negate|opt_newest)
|
||||||
usage (opt);
|
usage ('?');
|
||||||
opt_oldest = 1;
|
opt_oldest = 1;
|
||||||
++criteria_count;
|
++criteria_count;
|
||||||
break;
|
break;
|
||||||
case 's': /* Solaris: match by session ID -- zero means self */
|
case 's': /* Solaris: match by session ID -- zero means self */
|
||||||
opt_sid = split_list (optarg, conv_sid);
|
opt_sid = split_list (optarg, conv_sid);
|
||||||
if (opt_sid == NULL)
|
if (opt_sid == NULL)
|
||||||
usage (opt);
|
usage ('?');
|
||||||
++criteria_count;
|
++criteria_count;
|
||||||
break;
|
break;
|
||||||
case 't': /* Solaris: match by tty */
|
case 't': /* Solaris: match by tty */
|
||||||
opt_term = split_list (optarg, conv_str);
|
opt_term = split_list (optarg, conv_str);
|
||||||
if (opt_term == NULL)
|
if (opt_term == NULL)
|
||||||
usage (opt);
|
usage ('?');
|
||||||
++criteria_count;
|
++criteria_count;
|
||||||
break;
|
break;
|
||||||
case 'u': /* Solaris: match by euid/egroup */
|
case 'u': /* Solaris: match by euid/egroup */
|
||||||
opt_euid = split_list (optarg, conv_uid);
|
opt_euid = split_list (optarg, conv_uid);
|
||||||
if (opt_euid == NULL)
|
if (opt_euid == NULL)
|
||||||
usage (opt);
|
usage ('?');
|
||||||
++criteria_count;
|
++criteria_count;
|
||||||
break;
|
break;
|
||||||
case 'v': /* Solaris: as in grep, invert the matching (uh... applied after selection I think) */
|
case 'v': /* Solaris: as in grep, invert the matching (uh... applied after selection I think) */
|
||||||
if (opt_oldest|opt_negate|opt_newest)
|
if (opt_oldest|opt_negate|opt_newest)
|
||||||
usage (opt);
|
usage ('?');
|
||||||
opt_negate = 1;
|
opt_negate = 1;
|
||||||
break;
|
break;
|
||||||
case 'w': // Linux: show threads (lightweight process) too
|
case 'w': // Linux: show threads (lightweight process) too
|
||||||
@ -857,25 +857,23 @@ static void parse_opts (int argc, char **argv)
|
|||||||
case NS_OPTION:
|
case NS_OPTION:
|
||||||
opt_ns_pid = atoi(optarg);
|
opt_ns_pid = atoi(optarg);
|
||||||
if (opt_ns_pid == 0)
|
if (opt_ns_pid == 0)
|
||||||
usage (opt);
|
usage ('?');
|
||||||
++criteria_count;
|
++criteria_count;
|
||||||
break;
|
break;
|
||||||
case NSLIST_OPTION:
|
case NSLIST_OPTION:
|
||||||
opt_nslist = split_list (optarg, conv_ns);
|
opt_nslist = split_list (optarg, conv_ns);
|
||||||
if (opt_nslist == NULL)
|
if (opt_nslist == NULL)
|
||||||
usage (opt);
|
usage ('?');
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
usage (opt);
|
|
||||||
break;
|
|
||||||
case '?':
|
case '?':
|
||||||
usage (optopt ? optopt : opt);
|
usage (opt);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(opt_lock && !opt_pidfile)
|
if(opt_lock && !opt_pidfile)
|
||||||
xerrx(EXIT_FAILURE, _("-L without -F makes no sense\n"
|
xerrx(EXIT_USAGE, _("-L without -F makes no sense\n"
|
||||||
"Try `%s --help' for more information."),
|
"Try `%s --help' for more information."),
|
||||||
program_invocation_short_name);
|
program_invocation_short_name);
|
||||||
|
|
||||||
@ -890,11 +888,11 @@ static void parse_opts (int argc, char **argv)
|
|||||||
if (argc - optind == 1)
|
if (argc - optind == 1)
|
||||||
opt_pattern = argv[optind];
|
opt_pattern = argv[optind];
|
||||||
else if (argc - optind > 1)
|
else if (argc - optind > 1)
|
||||||
xerrx(EXIT_FAILURE, _("only one pattern can be provided\n"
|
xerrx(EXIT_USAGE, _("only one pattern can be provided\n"
|
||||||
"Try `%s --help' for more information."),
|
"Try `%s --help' for more information."),
|
||||||
program_invocation_short_name);
|
program_invocation_short_name);
|
||||||
else if (criteria_count == 0)
|
else if (criteria_count == 0)
|
||||||
xerrx(EXIT_FAILURE, _("no matching criteria specified\n"
|
xerrx(EXIT_USAGE, _("no matching criteria specified\n"
|
||||||
"Try `%s --help' for more information."),
|
"Try `%s --help' for more information."),
|
||||||
program_invocation_short_name);
|
program_invocation_short_name);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user