summaryrefslogtreecommitdiffstats
path: root/iptables/xtables.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2021-11-27 00:18:28 +0100
committerPhil Sutter <phil@nwl.cc>2021-12-16 14:30:29 +0100
commit51e5d29357644965bc6a8a4d1f3b2878936147f7 (patch)
treee2ce6355b527d1de1629dbacd83d4923e1c03c48 /iptables/xtables.c
parent56ac0452a4968f1af8d3ad1717c8646593177155 (diff)
xshared: Share exit_tryhelp()
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>
Diffstat (limited to 'iptables/xtables.c')
-rw-r--r--iptables/xtables.c21
1 files changed, 5 insertions, 16 deletions
diff --git a/iptables/xtables.c b/iptables/xtables.c
index 36324a5d..d53fd758 100644
--- a/iptables/xtables.c
+++ b/iptables/xtables.c
@@ -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;