build: allow creating empty package feeds
[openwrt.git] / package / network / utils / iptables / patches / 400-lenient-restore.patch
1 --- a/iptables/ip6tables-restore.c
2 +++ b/iptables/ip6tables-restore.c
3 @@ -14,6 +14,8 @@
4  #include <string.h>
5  #include <stdio.h>
6  #include <stdlib.h>
7 +#include <stdarg.h>
8 +#include <setjmp.h>
9  #include "ip6tables.h"
10  #include "xtables.h"
11  #include "libiptc/libip6tc.h"
12 @@ -25,6 +27,7 @@
13  #define DEBUGP(x, args...)
14  #endif
15  
16 +static jmp_buf jmp;
17  static int binary = 0, counters = 0, verbose = 0, noflush = 0;
18  
19  /* Keeping track of external matches and targets.  */
20 @@ -35,6 +38,7 @@ static const struct option options[] = {
21         {.name = "test",     .has_arg = false, .val = 't'},
22         {.name = "help",     .has_arg = false, .val = 'h'},
23         {.name = "noflush",  .has_arg = false, .val = 'n'},
24 +       {.name = "lenient",  .has_arg = false, .val = 'l'},
25         {.name = "modprobe", .has_arg = true,  .val = 'M'},
26         {.name = "table",    .has_arg = true,  .val = 'T'},
27         {NULL},
28 @@ -51,6 +55,7 @@ static void print_usage(const char *name
29                         "          [ --test ]\n"
30                         "          [ --help ]\n"
31                         "          [ --noflush ]\n"
32 +                       "          [ --lenient ]\n"
33                         "          [ --modprobe=<command>]\n", name);
34  
35         exit(1);
36 @@ -114,6 +119,17 @@ static void free_argv(void) {
37                 free(newargv[i]);
38  }
39  
40 +static void catch_exit_error(enum xtables_exittype status, const char *msg, ...)
41 +{
42 +       va_list args;
43 +       fprintf(stderr, "line %d: ", line);
44 +       va_start(args, msg);
45 +       vfprintf(stderr, msg, args);
46 +       va_end(args);
47 +       fprintf(stderr, "\n");
48 +       longjmp(jmp, status);
49 +}
50 +
51  static void add_param_to_argv(char *parsestart)
52  {
53         int quote_open = 0, escaped = 0, param_len = 0;
54 @@ -204,7 +220,7 @@ int ip6tables_restore_main(int argc, cha
55         init_extensions6();
56  #endif
57  
58 -       while ((c = getopt_long(argc, argv, "bcvthnM:T:", options, NULL)) != -1) {
59 +       while ((c = getopt_long(argc, argv, "bcvthnlM:T:", options, NULL)) != -1) {
60                 switch (c) {
61                         case 'b':
62                                 binary = 1;
63 @@ -225,6 +241,9 @@ int ip6tables_restore_main(int argc, cha
64                         case 'n':
65                                 noflush = 1;
66                                 break;
67 +                       case 'l':
68 +                               ip6tables_globals.exit_err = catch_exit_error;
69 +                               break;
70                         case 'M':
71                                 xtables_modprobe_program = optarg;
72                                 break;
73 @@ -437,8 +456,11 @@ int ip6tables_restore_main(int argc, cha
74                         for (a = 0; a < newargc; a++)
75                                 DEBUGP("argv[%u]: %s\n", a, newargv[a]);
76  
77 -                       ret = do_command6(newargc, newargv,
78 -                                        &newargv[2], &handle, true);
79 +                       if (!setjmp(jmp))
80 +                               ret = do_command6(newargc, newargv,
81 +                                                &newargv[2], &handle, true);
82 +                       else
83 +                               ret = 1;
84  
85                         free_argv();
86                         fflush(stdout);
87 --- a/iptables/iptables-restore.c
88 +++ b/iptables/iptables-restore.c
89 @@ -11,6 +11,8 @@
90  #include <string.h>
91  #include <stdio.h>
92  #include <stdlib.h>
93 +#include <stdarg.h>
94 +#include <setjmp.h>
95  #include "iptables.h"
96  #include "xtables.h"
97  #include "libiptc/libiptc.h"
98 @@ -22,6 +24,7 @@
99  #define DEBUGP(x, args...)
100  #endif
101  
102 +static jmp_buf jmp;
103  static int binary = 0, counters = 0, verbose = 0, noflush = 0;
104  
105  /* Keeping track of external matches and targets.  */
106 @@ -32,6 +35,7 @@ static const struct option options[] = {
107         {.name = "test",     .has_arg = false, .val = 't'},
108         {.name = "help",     .has_arg = false, .val = 'h'},
109         {.name = "noflush",  .has_arg = false, .val = 'n'},
110 +       {.name = "lenient",  .has_arg = false, .val = 'l'},
111         {.name = "modprobe", .has_arg = true,  .val = 'M'},
112         {.name = "table",    .has_arg = true,  .val = 'T'},
113         {NULL},
114 @@ -50,6 +54,7 @@ static void print_usage(const char *name
115                         "          [ --test ]\n"
116                         "          [ --help ]\n"
117                         "          [ --noflush ]\n"
118 +                       "          [ --lenient ]\n"
119                         "          [ --table=<TABLE> ]\n"
120                         "          [ --modprobe=<command>]\n", name);
121  
122 @@ -113,6 +118,17 @@ static void free_argv(void) {
123                 free(newargv[i]);
124  }
125  
126 +static void catch_exit_error(enum xtables_exittype status, const char *msg, ...)
127 +{
128 +       va_list args;
129 +       fprintf(stderr, "line %d: ", line);
130 +       va_start(args, msg);
131 +       vfprintf(stderr, msg, args);
132 +       va_end(args);
133 +       fprintf(stderr, "\n");
134 +       longjmp(jmp, status);
135 +}
136 +
137  static void add_param_to_argv(char *parsestart)
138  {
139         int quote_open = 0, escaped = 0, param_len = 0;
140 @@ -204,7 +220,7 @@ iptables_restore_main(int argc, char *ar
141         init_extensions4();
142  #endif
143  
144 -       while ((c = getopt_long(argc, argv, "bcvthnM:T:", options, NULL)) != -1) {
145 +       while ((c = getopt_long(argc, argv, "bcvthnlM:T:", options, NULL)) != -1) {
146                 switch (c) {
147                         case 'b':
148                                 binary = 1;
149 @@ -225,6 +241,9 @@ iptables_restore_main(int argc, char *ar
150                         case 'n':
151                                 noflush = 1;
152                                 break;
153 +                       case 'l':
154 +                               iptables_globals.exit_err = catch_exit_error;
155 +                               break;
156                         case 'M':
157                                 xtables_modprobe_program = optarg;
158                                 break;
159 @@ -437,8 +456,11 @@ iptables_restore_main(int argc, char *ar
160                         for (a = 0; a < newargc; a++)
161                                 DEBUGP("argv[%u]: %s\n", a, newargv[a]);
162  
163 -                       ret = do_command4(newargc, newargv,
164 -                                        &newargv[2], &handle, true);
165 +                       if (!setjmp(jmp))
166 +                               ret = do_command4(newargc, newargv,
167 +                                                &newargv[2], &handle, true);
168 +                       else
169 +                               ret = 1;
170  
171                         free_argv();
172                         fflush(stdout);