convert to multicall binary
This commit is contained in:
parent
b9f1ae8254
commit
1a9fd7a0cc
5 changed files with 139 additions and 27 deletions
|
|
@ -19,6 +19,7 @@
|
|||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include "libifupdown/libifupdown.h"
|
||||
#include "cmd/multicall.h"
|
||||
|
||||
void
|
||||
print_interface(struct lif_interface *iface)
|
||||
|
|
@ -61,7 +62,7 @@ print_interface(struct lif_interface *iface)
|
|||
}
|
||||
|
||||
void
|
||||
usage()
|
||||
ifquery_usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: ifquery [options] <interfaces>\n");
|
||||
fprintf(stderr, " ifquery [options] --list\n");
|
||||
|
|
@ -138,7 +139,7 @@ list_state(struct lif_dict *state, struct match_options *opts)
|
|||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
ifquery_main(int argc, char *argv[])
|
||||
{
|
||||
struct lif_dict state = {};
|
||||
struct lif_dict collection = {};
|
||||
|
|
@ -168,7 +169,7 @@ main(int argc, char *argv[])
|
|||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
usage();
|
||||
ifquery_usage();
|
||||
break;
|
||||
case 'V':
|
||||
lif_common_version();
|
||||
|
|
@ -214,7 +215,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* --list --state is not allowed */
|
||||
if (listing && listing_stat)
|
||||
usage();
|
||||
ifquery_usage();
|
||||
|
||||
if (listing)
|
||||
{
|
||||
|
|
@ -228,7 +229,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
if (optind >= argc)
|
||||
usage();
|
||||
ifquery_usage();
|
||||
|
||||
int idx = optind;
|
||||
for (; idx < argc; idx++)
|
||||
|
|
@ -254,3 +255,9 @@ main(int argc, char *argv[])
|
|||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
struct if_applet ifquery_applet = {
|
||||
.name = "ifquery",
|
||||
.main = ifquery_main,
|
||||
.usage = ifquery_usage
|
||||
};
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include "libifupdown/libifupdown.h"
|
||||
#include "cmd/multicall.h"
|
||||
|
||||
struct match_options {
|
||||
bool is_auto;
|
||||
|
|
@ -31,7 +32,7 @@ static bool up;
|
|||
static struct lif_execute_opts exec_opts = {};
|
||||
|
||||
void
|
||||
usage()
|
||||
ifupdown_usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: %s [options] <interfaces>\n", argv0);
|
||||
|
||||
|
|
@ -106,7 +107,7 @@ change_auto_interfaces(struct lif_dict *collection, struct lif_dict *state, stru
|
|||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
ifupdown_main(int argc, char *argv[])
|
||||
{
|
||||
argv0 = basename(argv[0]);
|
||||
up = !is_ifdown();
|
||||
|
|
@ -137,7 +138,7 @@ main(int argc, char *argv[])
|
|||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
usage();
|
||||
ifupdown_usage();
|
||||
break;
|
||||
case 'V':
|
||||
lif_common_version();
|
||||
|
|
@ -187,7 +188,7 @@ main(int argc, char *argv[])
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
else if (optind >= argc)
|
||||
usage();
|
||||
ifupdown_usage();
|
||||
|
||||
int idx = optind;
|
||||
for (; idx < argc; idx++)
|
||||
|
|
@ -231,3 +232,15 @@ main(int argc, char *argv[])
|
|||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
struct if_applet ifup_applet = {
|
||||
.name = "ifup",
|
||||
.main = ifupdown_main,
|
||||
.usage = ifupdown_usage
|
||||
};
|
||||
|
||||
struct if_applet ifdown_applet = {
|
||||
.name = "ifdown",
|
||||
.main = ifupdown_main,
|
||||
.usage = ifupdown_usage
|
||||
};
|
||||
|
|
|
|||
60
cmd/multicall.c
Normal file
60
cmd/multicall.c
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* cmd/multicall.c
|
||||
* Purpose: multi-call binary frontend
|
||||
*
|
||||
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* This software is provided 'as is' and without any warranty, express or
|
||||
* implied. In no event shall the authors be liable for any damages arising
|
||||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "cmd/multicall.h"
|
||||
|
||||
extern struct if_applet ifquery_applet;
|
||||
extern struct if_applet ifup_applet;
|
||||
extern struct if_applet ifdown_applet;
|
||||
|
||||
struct if_applet *applet_table[] = {
|
||||
&ifdown_applet,
|
||||
&ifquery_applet,
|
||||
&ifup_applet,
|
||||
};
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
|
||||
|
||||
int
|
||||
applet_cmp(const void *a, const void *b)
|
||||
{
|
||||
const char *key = a;
|
||||
const struct if_applet *applet = *(void **)b;
|
||||
|
||||
return strcmp(key, applet->name);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char *argv0 = basename(argv[0]);
|
||||
struct if_applet **app;
|
||||
|
||||
app = bsearch(argv0, applet_table,
|
||||
ARRAY_SIZE(applet_table), sizeof(*applet_table),
|
||||
applet_cmp);
|
||||
|
||||
if (app == NULL)
|
||||
{
|
||||
fprintf(stderr, "%s: applet not found\n", argv0);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return (*app)->main(argc, argv);
|
||||
}
|
||||
27
cmd/multicall.h
Normal file
27
cmd/multicall.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* cmd/multicall.h
|
||||
* Purpose: structures for multicall frontend
|
||||
*
|
||||
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* This software is provided 'as is' and without any warranty, express or
|
||||
* implied. In no event shall the authors be liable for any damages arising
|
||||
* from the use of this software.
|
||||
*/
|
||||
|
||||
#ifndef IFUPDOWN_CMD_MULTICALL_H__GUARD
|
||||
#define IFUPDOWN_CMD_MULTICALL_H__GUARD
|
||||
|
||||
#include "libifupdown/libifupdown.h"
|
||||
|
||||
struct if_applet {
|
||||
const char *name;
|
||||
int (*const main)(int argc, char *argv[]);
|
||||
void (*const usage)(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue