]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxtables: Extend basic_exit_err()
authorPhil Sutter <phil@nwl.cc>
Fri, 26 Nov 2021 20:11:25 +0000 (21:11 +0100)
committerPhil Sutter <phil@nwl.cc>
Thu, 16 Dec 2021 13:30:29 +0000 (14:30 +0100)
Basically merge the function with xtables_exit_error,
printing a status-specific footer for parameter or version problems.

Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables/ip6tables.c
iptables/iptables.c
iptables/xtables-arp.c
iptables/xtables-eb.c
iptables/xtables.c
libxtables/xtables.c

index 44d2c08cddc422274bab526b2b8bcd3723c0b675..2f3ff034fbbb76fed2256f51326d81d74799b466 100644 (file)
@@ -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.
index 191877ec1bb064592c8a3a5d8d67b204d4b3ff89..ba04fbc6a806ed0ca3e59102e9fe272bc4645cae 100644 (file)
@@ -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.
index 8a226330a712487456404b84799bfb5628727c63..805fb19a5f93767f247379390b3976a50acf69a1 100644 (file)
@@ -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,
 };
index 604d4d39e90f7af2b1907f3c03642bec24eb7393..ed8f733246ca3f74575759361151d3cae12d9d32 100644 (file)
@@ -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,
 };
 
index a6b10cf846d58d0224ab6cd1b5a13d99673d139b..5255fa340d55d1e4bed2e61e5b86f87146b82731 100644 (file)
@@ -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.
index d670175db2236b561a9b0b5a0f7aea42244a0662..50fd6a44b01009d50e1857883bcd30bdbccf6fff 100644 (file)
@@ -90,6 +90,18 @@ void basic_exit_err(enum xtables_exittype status, const char *msg, ...)
        vfprintf(stderr, msg, args);
        va_end(args);
        fprintf(stderr, "\n");
+       if (status == PARAMETER_PROBLEM) {
+               if (line != -1)
+                       fprintf(stderr, "Error occurred at line: %d\n", line);
+               fprintf(stderr, "Try `%s -h' or '%s --help' for more information.\n",
+                               xt_params->program_name, xt_params->program_name);
+       } else if (status == VERSION_PROBLEM) {
+               fprintf(stderr,
+                       "Perhaps %s or your kernel needs to be upgraded.\n",
+                       xt_params->program_name);
+       }
+       /* On error paths, make sure that we don't leak memory */
+       xtables_free_opts(1);
        exit(status);
 }