]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
iptables-save: exit with error if unable to open proc file
authorThomas Habets <thomas@habets.se>
Wed, 18 Jan 2017 13:58:13 +0000 (08:58 -0500)
committerFlorian Westphal <fw@strlen.de>
Wed, 18 Jan 2017 14:03:22 +0000 (15:03 +0100)
Signed-off-by: Florian Westphal <fw@strlen.de>
iptables/ip6tables-save.c
iptables/iptables-save.c

index f35e921ebcff99ef2285a7fa189f15e1738d1128..053413a9dfe2bd7b38d15e72346529207274a4c5 100644 (file)
@@ -35,10 +35,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/ip6_tables_names", "re");
-       if (!procfile)
-               return ret;
+       static const char filename[] = "/proc/net/ip6_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')
index 238f368ed29063c3804664839f3d0dff37bb1815..e8ae9c6c4cc93571f159b25c3d561d0a5775b204 100644 (file)
@@ -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')