void *scanner;
struct scope *top_scope;
void *json_root;
- FILE *f[MAX_INCLUDE_DEPTH];
};
enum nftables_exit_codes {
* struct input_descriptor
*
* @location: location, used for include statements
+ * @f: file descriptor
* @type: input descriptor type
* @name: name describing the input
* @union: buffer or file descriptor, depending on type
*/
struct input_descriptor {
struct list_head list;
+ FILE *f;
struct location location;
enum input_descriptor_types type;
const char *name;
}
static void scanner_push_file(struct nft_ctx *nft, void *scanner,
- const char *filename, const struct location *loc)
+ FILE *f, const char *filename,
+ const struct location *loc)
{
struct parser_state *state = yyget_extra(scanner);
struct input_descriptor *indesc;
YY_BUFFER_STATE b;
- b = yy_create_buffer(nft->f[state->indesc_idx], YY_BUF_SIZE, scanner);
+ b = yy_create_buffer(f, YY_BUF_SIZE, scanner);
yypush_buffer_state(b, scanner);
indesc = xzalloc(sizeof(struct input_descriptor));
indesc->location = *loc;
indesc->type = INDESC_FILE;
indesc->name = xstrdup(filename);
+ indesc->f = f;
init_pos(indesc);
scanner_push_indesc(state, indesc);
filename, strerror(errno));
goto err;
}
- nft->f[state->indesc_idx] = f;
- scanner_push_file(nft, scanner, filename, loc);
+ scanner_push_file(nft, scanner, f, filename, loc);
return 0;
err:
erec_queue(erec, state->msgs);
struct input_descriptor *indesc, *next;
list_for_each_entry_safe(indesc, next, &state->indesc_list, list) {
+ if (indesc->f) {
+ fclose(indesc->f);
+ indesc->f = NULL;
+ }
list_del(&indesc->list);
input_descriptor_destroy(indesc);
}
do {
yypop_buffer_state(nft->scanner);
-
- if (nft->f[state->indesc_idx]) {
- fclose(nft->f[state->indesc_idx]);
- nft->f[state->indesc_idx] = NULL;
- }
} while (state->indesc_idx--);
input_descriptor_list_destroy(state);