From 316d8efbb7cd2d252c8627df77261a466493d09b Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Fri, 26 Nov 2021 21:11:25 +0100 Subject: libxtables: Extend basic_exit_err() Basically merge the function with xtables_exit_error, printing a status-specific footer for parameter or version problems. Signed-off-by: Phil Sutter --- iptables/ip6tables.c | 22 ---------------------- iptables/iptables.c | 23 ----------------------- iptables/xtables-arp.c | 2 -- iptables/xtables-eb.c | 2 -- iptables/xtables.c | 23 ----------------------- 5 files changed, 72 deletions(-) (limited to 'iptables') diff --git a/iptables/ip6tables.c b/iptables/ip6tables.c index 44d2c08c..2f3ff034 100644 --- a/iptables/ip6tables.c +++ b/iptables/ip6tables.c @@ -87,12 +87,10 @@ static struct option original_opts[] = { {NULL}, }; -void ip6tables_exit_error(enum xtables_exittype status, const char *msg, ...) __attribute__((noreturn, format(printf,2,3))); struct xtables_globals ip6tables_globals = { .option_offset = 0, .program_version = PACKAGE_VERSION " (legacy)", .orig_opts = original_opts, - .exit_err = ip6tables_exit_error, .compat_rev = xtables_compatible_revision, }; @@ -107,26 +105,6 @@ exit_printhelp(const struct xtables_rule_match *matches) exit(0); } -void -ip6tables_exit_error(enum xtables_exittype status, const char *msg, ...) -{ - va_list args; - - va_start(args, msg); - fprintf(stderr, "%s v%s: ", prog_name, prog_vers); - vfprintf(stderr, msg, args); - va_end(args); - fprintf(stderr, "\n"); - if (status == PARAMETER_PROBLEM) - exit_tryhelp(status, line); - if (status == VERSION_PROBLEM) - fprintf(stderr, - "Perhaps ip6tables or your kernel needs to be upgraded.\n"); - /* On error paths, make sure that we don't leak memory */ - xtables_free_opts(1); - exit(status); -} - /* * All functions starting with "parse" should succeed, otherwise * the program fails. diff --git a/iptables/iptables.c b/iptables/iptables.c index 191877ec..ba04fbc6 100644 --- a/iptables/iptables.c +++ b/iptables/iptables.c @@ -84,13 +84,10 @@ static struct option original_opts[] = { {NULL}, }; -void iptables_exit_error(enum xtables_exittype status, const char *msg, ...) __attribute__((noreturn, format(printf,2,3))); - struct xtables_globals iptables_globals = { .option_offset = 0, .program_version = PACKAGE_VERSION " (legacy)", .orig_opts = original_opts, - .exit_err = iptables_exit_error, .compat_rev = xtables_compatible_revision, }; @@ -105,26 +102,6 @@ exit_printhelp(const struct xtables_rule_match *matches) exit(0); } -void -iptables_exit_error(enum xtables_exittype status, const char *msg, ...) -{ - va_list args; - - va_start(args, msg); - fprintf(stderr, "%s v%s: ", prog_name, prog_vers); - vfprintf(stderr, msg, args); - va_end(args); - fprintf(stderr, "\n"); - if (status == PARAMETER_PROBLEM) - exit_tryhelp(status, line); - if (status == VERSION_PROBLEM) - fprintf(stderr, - "Perhaps iptables or your kernel needs to be upgraded.\n"); - /* On error paths, make sure that we don't leak memory */ - xtables_free_opts(1); - exit(status); -} - /* * All functions starting with "parse" should succeed, otherwise * the program fails. diff --git a/iptables/xtables-arp.c b/iptables/xtables-arp.c index 8a226330..805fb19a 100644 --- a/iptables/xtables-arp.c +++ b/iptables/xtables-arp.c @@ -84,14 +84,12 @@ static struct option original_opts[] = { #define opts xt_params->opts -extern void xtables_exit_error(enum xtables_exittype status, const char *msg, ...) __attribute__((noreturn, format(printf,2,3))); static void printhelp(const struct xtables_rule_match *m); struct xtables_globals arptables_globals = { .option_offset = 0, .program_version = PACKAGE_VERSION " (nf_tables)", .optstring = OPTSTRING_COMMON "C:R:S::" "h::l:nv" /* "m:" */, .orig_opts = original_opts, - .exit_err = xtables_exit_error, .compat_rev = nft_compatible_revision, .print_help = printhelp, }; diff --git a/iptables/xtables-eb.c b/iptables/xtables-eb.c index 604d4d39..ed8f7332 100644 --- a/iptables/xtables-eb.c +++ b/iptables/xtables-eb.c @@ -216,13 +216,11 @@ struct option ebt_original_options[] = { 0 } }; -extern void xtables_exit_error(enum xtables_exittype status, const char *msg, ...) __attribute__((noreturn, format(printf,2,3))); struct xtables_globals ebtables_globals = { .option_offset = 0, .program_version = PACKAGE_VERSION " (nf_tables)", .optstring = OPTSTRING_COMMON "h", .orig_opts = ebt_original_options, - .exit_err = xtables_exit_error, .compat_rev = nft_compatible_revision, }; diff --git a/iptables/xtables.c b/iptables/xtables.c index a6b10cf8..5255fa34 100644 --- a/iptables/xtables.c +++ b/iptables/xtables.c @@ -86,14 +86,11 @@ static struct option original_opts[] = { {NULL}, }; -void xtables_exit_error(enum xtables_exittype status, const char *msg, ...) __attribute__((noreturn, format(printf,2,3))); - struct xtables_globals xtables_globals = { .option_offset = 0, .program_version = PACKAGE_VERSION " (nf_tables)", .optstring = OPTSTRING_COMMON "R:S::W::" "46bfg:h::m:nvw::x", .orig_opts = original_opts, - .exit_err = xtables_exit_error, .compat_rev = nft_compatible_revision, .print_help = xtables_printhelp, }; @@ -102,26 +99,6 @@ struct xtables_globals xtables_globals = { #define prog_name xt_params->program_name #define prog_vers xt_params->program_version -void -xtables_exit_error(enum xtables_exittype status, const char *msg, ...) -{ - va_list args; - - va_start(args, msg); - fprintf(stderr, "%s v%s: ", prog_name, prog_vers); - vfprintf(stderr, msg, args); - va_end(args); - fprintf(stderr, "\n"); - if (status == PARAMETER_PROBLEM) - exit_tryhelp(status, line); - if (status == VERSION_PROBLEM) - fprintf(stderr, - "Perhaps iptables or your kernel needs to be upgraded.\n"); - /* On error paths, make sure that we don't leak memory */ - xtables_free_opts(1); - exit(status); -} - /* * All functions starting with "parse" should succeed, otherwise * the program fails. -- cgit v1.2.3