From bc88e3fcd2bef9f5b7fec62e0ed0afe1ba2f53a0 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Fri, 24 Jul 2020 03:23:41 -0600 Subject: [PATCH] multicall: add stub applet like busybox has --- cmd/multicall.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/cmd/multicall.c b/cmd/multicall.c index 94102e0..927f8ad 100644 --- a/cmd/multicall.c +++ b/cmd/multicall.c @@ -22,11 +22,13 @@ extern struct if_applet ifquery_applet; extern struct if_applet ifup_applet; extern struct if_applet ifdown_applet; +struct if_applet ifupdown_applet; struct if_applet *applet_table[] = { &ifdown_applet, &ifquery_applet, &ifup_applet, + &ifupdown_applet, }; #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x)) @@ -40,6 +42,8 @@ applet_cmp(const void *a, const void *b) return strcmp(key, applet->name); } +void multicall_usage(void); + int main(int argc, char *argv[]) { @@ -53,8 +57,42 @@ main(int argc, char *argv[]) if (app == NULL) { fprintf(stderr, "%s: applet not found\n", argv0); - return EXIT_FAILURE; + multicall_usage(); } return (*app)->main(argc, argv); } + +int +multicall_main(int argc, char *argv[]) +{ + if (argc < 2) + multicall_usage(); + + return main(argc - 1, argv + 1); +} + +void +multicall_usage(void) +{ + fprintf(stderr, "usage: ifupdown [options]\n"); + + fprintf(stderr, "\nBuilt-in applets:\n\t"); + for (size_t i = 0; i < ARRAY_SIZE(applet_table); i++) + { + if (i != 0) + fprintf(stderr, ", "); + + fprintf(stderr, "%s", applet_table[i]->name); + } + + fprintf(stderr, "\n"); + + exit(EXIT_FAILURE); +} + +struct if_applet ifupdown_applet = { + .name = "ifupdown", + .main = multicall_main, + .usage = multicall_usage, +};