commands: refactor applet_usage functions to take a status code (ref #16)
This commit is contained in:
parent
f96a74f232
commit
ebd04cafda
4 changed files with 15 additions and 15 deletions
|
@ -164,7 +164,7 @@ print_interface_property(struct lif_interface *iface, const char *property)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ifquery_usage(void)
|
ifquery_usage(int status)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: ifquery [options] <interfaces>\n");
|
fprintf(stderr, "usage: ifquery [options] <interfaces>\n");
|
||||||
fprintf(stderr, " ifquery [options] --list\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, " -D, --dot generate a dependency graph\n");
|
||||||
fprintf(stderr, " -p, --property PROPERTY print values of properties matching PROPERTY\n");
|
fprintf(stderr, " -p, --property PROPERTY print values of properties matching PROPERTY\n");
|
||||||
|
|
||||||
exit(1);
|
exit(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct match_options {
|
struct match_options {
|
||||||
|
@ -289,7 +289,7 @@ ifquery_main(int argc, char *argv[])
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'h':
|
case 'h':
|
||||||
ifquery_usage();
|
ifquery_usage(EXIT_SUCCESS);
|
||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
lif_common_version();
|
lif_common_version();
|
||||||
|
@ -344,7 +344,7 @@ ifquery_main(int argc, char *argv[])
|
||||||
|
|
||||||
/* --list --state is not allowed */
|
/* --list --state is not allowed */
|
||||||
if (listing && listing_stat)
|
if (listing && listing_stat)
|
||||||
ifquery_usage();
|
ifquery_usage(EXIT_FAILURE);
|
||||||
|
|
||||||
if (listing)
|
if (listing)
|
||||||
{
|
{
|
||||||
|
@ -358,7 +358,7 @@ ifquery_main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optind >= argc)
|
if (optind >= argc)
|
||||||
ifquery_usage();
|
ifquery_usage(EXIT_FAILURE);
|
||||||
|
|
||||||
int idx = optind;
|
int idx = optind;
|
||||||
for (; idx < argc; idx++)
|
for (; idx < argc; idx++)
|
||||||
|
|
|
@ -38,7 +38,7 @@ static struct lif_execute_opts exec_opts = {
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
ifupdown_usage(void)
|
ifupdown_usage(int status)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: %s [options] <interfaces>\n", argv0);
|
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, " -f, --force force (de)configuration\n");
|
||||||
fprintf(stderr, " -L, --no-lock do not use a lockfile to serialize state changes\n");
|
fprintf(stderr, " -L, --no-lock do not use a lockfile to serialize state changes\n");
|
||||||
|
|
||||||
exit(1);
|
exit(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -220,7 +220,7 @@ ifupdown_main(int argc, char *argv[])
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'h':
|
case 'h':
|
||||||
ifupdown_usage();
|
ifupdown_usage(EXIT_SUCCESS);
|
||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
lif_common_version();
|
lif_common_version();
|
||||||
|
@ -284,7 +284,7 @@ ifupdown_main(int argc, char *argv[])
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
else if (optind >= argc)
|
else if (optind >= argc)
|
||||||
ifupdown_usage();
|
ifupdown_usage(EXIT_FAILURE);
|
||||||
|
|
||||||
int idx = optind;
|
int idx = optind;
|
||||||
for (; idx < argc; idx++)
|
for (; idx < argc; idx++)
|
||||||
|
|
|
@ -44,7 +44,7 @@ applet_cmp(const void *a, const void *b)
|
||||||
return strcmp(key, applet->name);
|
return strcmp(key, applet->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void multicall_usage(void) __attribute__((noreturn));
|
void multicall_usage(int status) __attribute__((noreturn));
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
|
@ -59,7 +59,7 @@ main(int argc, char *argv[])
|
||||||
if (app == NULL)
|
if (app == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: applet not found\n", argv0);
|
fprintf(stderr, "%s: applet not found\n", argv0);
|
||||||
multicall_usage();
|
multicall_usage(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (*app)->main(argc, argv);
|
return (*app)->main(argc, argv);
|
||||||
|
@ -69,13 +69,13 @@ int
|
||||||
multicall_main(int argc, char *argv[])
|
multicall_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
multicall_usage();
|
multicall_usage(EXIT_FAILURE);
|
||||||
|
|
||||||
return main(argc - 1, argv + 1);
|
return main(argc - 1, argv + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
multicall_usage(void)
|
multicall_usage(int status)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: ifupdown <applet> [options]\n");
|
fprintf(stderr, "usage: ifupdown <applet> [options]\n");
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ multicall_usage(void)
|
||||||
|
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
exit(EXIT_FAILURE);
|
exit(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct if_applet ifupdown_applet = {
|
struct if_applet ifupdown_applet = {
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
struct if_applet {
|
struct if_applet {
|
||||||
const char *name;
|
const char *name;
|
||||||
int (*const main)(int argc, char *argv[]);
|
int (*const main)(int argc, char *argv[]);
|
||||||
void (*const usage)(void);
|
void (*const usage)(int status);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern char *argv0;
|
extern char *argv0;
|
||||||
|
|
Loading…
Reference in a new issue