summaryrefslogtreecommitdiffstats
path: root/iptables/iptables-save.c
diff options
context:
space:
mode:
authorThomas Habets <thomas@habets.se>2017-01-18 08:58:13 -0500
committerFlorian Westphal <fw@strlen.de>2017-01-18 15:03:22 +0100
commit96472f872800db05bb7d66db827dbd9c76e28ea6 (patch)
tree12b3c1ec74441ce13c9b980893336d7001a2643c /iptables/iptables-save.c
parent1123e6a069123756c6c73d5557d06bc5fc31497e (diff)
iptables-save: exit with error if unable to open proc file
Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'iptables/iptables-save.c')
-rw-r--r--iptables/iptables-save.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/iptables/iptables-save.c b/iptables/iptables-save.c
index 238f368e..e8ae9c6c 100644
--- a/iptables/iptables-save.c
+++ b/iptables/iptables-save.c
@@ -33,10 +33,16 @@ static int for_each_table(int (*func)(const char *tablename))
int ret = 1;
FILE *procfile = NULL;
char tablename[XT_TABLE_MAXNAMELEN+1];
-
- procfile = fopen("/proc/net/ip_tables_names", "re");
- if (!procfile)
- return ret;
+ static const char filename[] = "/proc/net/ip_tables_names";
+
+ procfile = fopen(filename, "re");
+ if (!procfile) {
+ if (errno == ENOENT)
+ return ret;
+ fprintf(stderr, "Failed to list table names in %s: %s\n",
+ filename, strerror(errno));
+ exit(1);
+ }
while (fgets(tablename, sizeof(tablename), procfile)) {
if (tablename[strlen(tablename) - 1] != '\n')