multicall: expose argv0, use in applets

This commit is contained in:
Ariadne Conill 2020-07-24 04:52:15 -06:00
parent e0a7444640
commit 8714dab11d
4 changed files with 8 additions and 6 deletions

View file

@ -252,13 +252,13 @@ ifquery_main(int argc, char *argv[])
if (!lif_state_read_path(&state, state_file)) if (!lif_state_read_path(&state, state_file))
{ {
fprintf(stderr, "ifquery: could not parse %s\n", state_file); fprintf(stderr, "%s: could not parse %s\n", argv0, state_file);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (!lif_interface_file_parse(&collection, interfaces_file)) if (!lif_interface_file_parse(&collection, interfaces_file))
{ {
fprintf(stderr, "ifquery: could not parse %s\n", interfaces_file); fprintf(stderr, "%s: could not parse %s\n", argv0, interfaces_file);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -295,7 +295,7 @@ ifquery_main(int argc, char *argv[])
if (iface == NULL) if (iface == NULL)
{ {
fprintf(stderr, "ifquery: unknown interface %s\n", argv[idx]); fprintf(stderr, "%s: unknown interface %s\n", argv0, argv[idx]);
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View file

@ -27,7 +27,6 @@ struct match_options {
char *include_pattern; char *include_pattern;
}; };
static const char *argv0;
static bool up; static bool up;
static struct lif_execute_opts exec_opts = {}; static struct lif_execute_opts exec_opts = {};
@ -109,7 +108,6 @@ change_auto_interfaces(struct lif_dict *collection, struct lif_dict *state, stru
int int
ifupdown_main(int argc, char *argv[]) ifupdown_main(int argc, char *argv[])
{ {
argv0 = basename(argv[0]);
up = !is_ifdown(); up = !is_ifdown();
struct lif_dict state = {}; struct lif_dict state = {};

View file

@ -19,6 +19,8 @@
#include <string.h> #include <string.h>
#include "cmd/multicall.h" #include "cmd/multicall.h"
char *argv0;
extern struct if_applet ifquery_applet; extern struct if_applet ifquery_applet;
extern struct if_applet ifup_applet; extern struct if_applet ifup_applet;
extern struct if_applet ifdown_applet; extern struct if_applet ifdown_applet;
@ -47,7 +49,7 @@ void multicall_usage(void);
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
char *argv0 = basename(argv[0]); argv0 = basename(argv[0]);
struct if_applet **app; struct if_applet **app;
app = bsearch(argv0, applet_table, app = bsearch(argv0, applet_table,

View file

@ -24,4 +24,6 @@ struct if_applet {
void (*const usage)(void); void (*const usage)(void);
}; };
extern char *argv0;
#endif #endif