]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xshared: Share exit_tryhelp()
authorPhil Sutter <phil@nwl.cc>
Fri, 26 Nov 2021 23:18:28 +0000 (00:18 +0100)
committerPhil Sutter <phil@nwl.cc>
Thu, 16 Dec 2021 13:30:29 +0000 (14:30 +0100)
The function existed three times in identical form. Avoid having to
declare extern int line in xshared.c by making it a parameter.

Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables/ip6tables.c
iptables/iptables.c
iptables/xshared.c
iptables/xshared.h
iptables/xtables.c

index 46f7785b8a9c56c5523bcbf239d1c27683342db4..788966d6b68af2be021a424aa0056db1b2c8ed20 100644 (file)
@@ -100,17 +100,6 @@ struct xtables_globals ip6tables_globals = {
 #define prog_name ip6tables_globals.program_name
 #define prog_vers ip6tables_globals.program_version
 
-static void __attribute__((noreturn))
-exit_tryhelp(int status)
-{
-       if (line != -1)
-               fprintf(stderr, "Error occurred at line: %d\n", line);
-       fprintf(stderr, "Try `%s -h' or '%s --help' for more information.\n",
-                       prog_name, prog_name);
-       xtables_free_opts(1);
-       exit(status);
-}
-
 static void
 exit_printhelp(const struct xtables_rule_match *matches)
 {
@@ -129,7 +118,7 @@ ip6tables_exit_error(enum xtables_exittype status, const char *msg, ...)
        va_end(args);
        fprintf(stderr, "\n");
        if (status == PARAMETER_PROBLEM)
-               exit_tryhelp(status);
+               exit_tryhelp(status, line);
        if (status == VERSION_PROBLEM)
                fprintf(stderr,
                        "Perhaps ip6tables or your kernel needs to be upgraded.\n");
@@ -1106,7 +1095,7 @@ int do_command6(int argc, char *argv[], char **table,
                        if (line != -1)
                                return 1; /* success: line ignored */
                        fprintf(stderr, "This is the IPv6 version of ip6tables.\n");
-                       exit_tryhelp(2);
+                       exit_tryhelp(2, line);
 
                case '6':
                        /* This is indeed the IPv6 ip6tables */
@@ -1123,7 +1112,7 @@ int do_command6(int argc, char *argv[], char **table,
                                continue;
                        }
                        fprintf(stderr, "Bad argument `%s'\n", optarg);
-                       exit_tryhelp(2);
+                       exit_tryhelp(2, line);
 
                default:
                        if (command_default(&cs, &ip6tables_globals, invert))
@@ -1372,7 +1361,7 @@ int do_command6(int argc, char *argv[], char **table,
                break;
        default:
                /* We should never reach this... */
-               exit_tryhelp(2);
+               exit_tryhelp(2, line);
        }
 
        if (verbose > 1)
index 7b4503498865d1889a6e62ee1d97d313a55060a7..78fff9ef77b81fe3bf13eb49a9463d2fc3dbccae 100644 (file)
@@ -98,17 +98,6 @@ struct xtables_globals iptables_globals = {
 #define prog_name iptables_globals.program_name
 #define prog_vers iptables_globals.program_version
 
-static void __attribute__((noreturn))
-exit_tryhelp(int status)
-{
-       if (line != -1)
-               fprintf(stderr, "Error occurred at line: %d\n", line);
-       fprintf(stderr, "Try `%s -h' or '%s --help' for more information.\n",
-                       prog_name, prog_name);
-       xtables_free_opts(1);
-       exit(status);
-}
-
 static void
 exit_printhelp(const struct xtables_rule_match *matches)
 {
@@ -127,7 +116,7 @@ iptables_exit_error(enum xtables_exittype status, const char *msg, ...)
        va_end(args);
        fprintf(stderr, "\n");
        if (status == PARAMETER_PROBLEM)
-               exit_tryhelp(status);
+               exit_tryhelp(status, line);
        if (status == VERSION_PROBLEM)
                fprintf(stderr,
                        "Perhaps iptables or your kernel needs to be upgraded.\n");
@@ -1093,7 +1082,7 @@ int do_command4(int argc, char *argv[], char **table,
                        if (line != -1)
                                return 1; /* success: line ignored */
                        fprintf(stderr, "This is the IPv4 version of iptables.\n");
-                       exit_tryhelp(2);
+                       exit_tryhelp(2, line);
 
                case 1: /* non option */
                        if (optarg[0] == '!' && optarg[1] == '\0') {
@@ -1106,7 +1095,7 @@ int do_command4(int argc, char *argv[], char **table,
                                continue;
                        }
                        fprintf(stderr, "Bad argument `%s'\n", optarg);
-                       exit_tryhelp(2);
+                       exit_tryhelp(2, line);
 
                default:
                        if (command_default(&cs, &iptables_globals, invert))
@@ -1353,7 +1342,7 @@ int do_command4(int argc, char *argv[], char **table,
                break;
        default:
                /* We should never reach this... */
-               exit_tryhelp(2);
+               exit_tryhelp(2, line);
        }
 
        if (verbose > 1)
index 9b32610772ba5fbd8b6e15f5ce06f50038c8d215..efee7a30b39fdf439cb68bcce475bfcf2bc8ec75 100644 (file)
@@ -1252,3 +1252,13 @@ xtables_printhelp(const struct xtables_rule_match *matches)
 
        print_extension_helps(xtables_targets, matches);
 }
+
+void exit_tryhelp(int status, int line)
+{
+       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);
+       xtables_free_opts(1);
+       exit(status);
+}
index 3310954c1f441d371c9113f19c819574393c0e04..2c05b0d7c4acef2f626f1c8d32bf0f8f922f30fb 100644 (file)
@@ -260,5 +260,6 @@ void save_rule_details(const char *iniface, unsigned const char *iniface_mask,
 int print_match_save(const struct xt_entry_match *e, const void *ip);
 
 void xtables_printhelp(const struct xtables_rule_match *matches);
+void exit_tryhelp(int status, int line) __attribute__((noreturn));
 
 #endif /* IPTABLES_XSHARED_H */
index 36324a5de22a8503dd2b7093227680928a99d35a..d53fd758ac72df4400fd58d235fc8b31a9c3350a 100644 (file)
@@ -102,17 +102,6 @@ struct xtables_globals xtables_globals = {
 #define prog_name xt_params->program_name
 #define prog_vers xt_params->program_version
 
-static void __attribute__((noreturn))
-exit_tryhelp(int status)
-{
-       if (line != -1)
-               fprintf(stderr, "Error occurred at line: %d\n", line);
-       fprintf(stderr, "Try `%s -h' or '%s --help' for more information.\n",
-                       prog_name, prog_name);
-       xtables_free_opts(1);
-       exit(status);
-}
-
 void
 xtables_exit_error(enum xtables_exittype status, const char *msg, ...)
 {
@@ -124,7 +113,7 @@ xtables_exit_error(enum xtables_exittype status, const char *msg, ...)
        va_end(args);
        fprintf(stderr, "\n");
        if (status == PARAMETER_PROBLEM)
-               exit_tryhelp(status);
+               exit_tryhelp(status, line);
        if (status == VERSION_PROBLEM)
                fprintf(stderr,
                        "Perhaps iptables or your kernel needs to be upgraded.\n");
@@ -631,7 +620,7 @@ void do_parse(struct nft_handle *h, int argc, char *argv[],
                        if (p->restore && args->family == AF_INET6)
                                return;
 
-                       exit_tryhelp(2);
+                       exit_tryhelp(2, line);
 
                case '6':
                        if (args->family == AF_INET6)
@@ -640,7 +629,7 @@ void do_parse(struct nft_handle *h, int argc, char *argv[],
                        if (p->restore && args->family == AF_INET)
                                return;
 
-                       exit_tryhelp(2);
+                       exit_tryhelp(2, line);
 
                case 1: /* non option */
                        if (optarg[0] == '!' && optarg[1] == '\0') {
@@ -653,7 +642,7 @@ void do_parse(struct nft_handle *h, int argc, char *argv[],
                                continue;
                        }
                        fprintf(stderr, "Bad argument `%s'\n", optarg);
-                       exit_tryhelp(2);
+                       exit_tryhelp(2, line);
 
                default:
                        if (command_default(cs, xt_params, invert))
@@ -849,7 +838,7 @@ int do_commandx(struct nft_handle *h, int argc, char *argv[], char **table,
                break;
        default:
                /* We should never reach this... */
-               exit_tryhelp(2);
+               exit_tryhelp(2, line);
        }
 
        *table = p.table;