summaryrefslogtreecommitdiffstats
path: root/iptables/iptables.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/iptables.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/iptables.c')
-rw-r--r--iptables/iptables.c19
1 files changed, 4 insertions, 15 deletions
diff --git a/iptables/iptables.c b/iptables/iptables.c
index 7b450349..78fff9ef 100644
--- a/iptables/iptables.c
+++ b/iptables/iptables.c
@@ -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)