commands: refactor applet_usage functions to take a status code (ref #16)

This commit is contained in:
Ariadne Conill 2020-08-11 20:44:04 -06:00
parent f96a74f232
commit ebd04cafda
4 changed files with 15 additions and 15 deletions

View file

@ -164,7 +164,7 @@ print_interface_property(struct lif_interface *iface, const char *property)
}
void
ifquery_usage(void)
ifquery_usage(int status)
{
fprintf(stderr, "usage: ifquery [options] <interfaces>\n");
fprintf(stderr, " ifquery [options] --list\n");
@ -183,7 +183,7 @@ ifquery_usage(void)
fprintf(stderr, " -D, --dot generate a dependency graph\n");
fprintf(stderr, " -p, --property PROPERTY print values of properties matching PROPERTY\n");
exit(1);
exit(status);
}
struct match_options {
@ -289,7 +289,7 @@ ifquery_main(int argc, char *argv[])
switch (c) {
case 'h':
ifquery_usage();
ifquery_usage(EXIT_SUCCESS);
break;
case 'V':
lif_common_version();
@ -344,7 +344,7 @@ ifquery_main(int argc, char *argv[])
/* --list --state is not allowed */
if (listing && listing_stat)
ifquery_usage();
ifquery_usage(EXIT_FAILURE);
if (listing)
{
@ -358,7 +358,7 @@ ifquery_main(int argc, char *argv[])
}
if (optind >= argc)
ifquery_usage();
ifquery_usage(EXIT_FAILURE);
int idx = optind;
for (; idx < argc; idx++)

View file

@ -38,7 +38,7 @@ static struct lif_execute_opts exec_opts = {
};
void
ifupdown_usage(void)
ifupdown_usage(int status)
{
fprintf(stderr, "usage: %s [options] <interfaces>\n", argv0);
@ -56,7 +56,7 @@ ifupdown_usage(void)
fprintf(stderr, " -f, --force force (de)configuration\n");
fprintf(stderr, " -L, --no-lock do not use a lockfile to serialize state changes\n");
exit(1);
exit(status);
}
bool
@ -220,7 +220,7 @@ ifupdown_main(int argc, char *argv[])
switch (c) {
case 'h':
ifupdown_usage();
ifupdown_usage(EXIT_SUCCESS);
break;
case 'V':
lif_common_version();
@ -284,7 +284,7 @@ ifupdown_main(int argc, char *argv[])
return EXIT_SUCCESS;
}
else if (optind >= argc)
ifupdown_usage();
ifupdown_usage(EXIT_FAILURE);
int idx = optind;
for (; idx < argc; idx++)

View file

@ -44,7 +44,7 @@ applet_cmp(const void *a, const void *b)
return strcmp(key, applet->name);
}
void multicall_usage(void) __attribute__((noreturn));
void multicall_usage(int status) __attribute__((noreturn));
int
main(int argc, char *argv[])
@ -59,7 +59,7 @@ main(int argc, char *argv[])
if (app == NULL)
{
fprintf(stderr, "%s: applet not found\n", argv0);
multicall_usage();
multicall_usage(EXIT_FAILURE);
}
return (*app)->main(argc, argv);
@ -69,13 +69,13 @@ int
multicall_main(int argc, char *argv[])
{
if (argc < 2)
multicall_usage();
multicall_usage(EXIT_FAILURE);
return main(argc - 1, argv + 1);
}
void
multicall_usage(void)
multicall_usage(int status)
{
fprintf(stderr, "usage: ifupdown <applet> [options]\n");
@ -90,7 +90,7 @@ multicall_usage(void)
fprintf(stderr, "\n");
exit(EXIT_FAILURE);
exit(status);
}
struct if_applet ifupdown_applet = {

View file

@ -21,7 +21,7 @@
struct if_applet {
const char *name;
int (*const main)(int argc, char *argv[]);
void (*const usage)(void);
void (*const usage)(int status);
};
extern char *argv0;