From 4a11d4fdd8fddca706f2ae9f4c64a52a38feb3b5 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Thu, 20 Aug 2020 03:46:31 -0600 Subject: [PATCH] interface-file: break out source keyword handling --- libifupdown/interface-file.c | 38 ++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/libifupdown/interface-file.c b/libifupdown/interface-file.c index 8a1f002..f1f18ce 100644 --- a/libifupdown/interface-file.c +++ b/libifupdown/interface-file.c @@ -95,6 +95,28 @@ handle_auto(struct lif_dict *collection, const char *filename, size_t lineno, ch return true; } +static bool +handle_source(struct lif_dict *collection, const char *filename, size_t lineno, char *token, char *bufp) +{ + (void) token; + + char *source_filename = lif_next_token(&bufp); + if (!*source_filename) + { + report_error(filename, lineno, "missing filename to source"); + return false; + } + + if (!strcmp(filename, source_filename)) + { + report_error(filename, lineno, "attempt to source %s would create infinite loop", + source_filename); + return false; + } + + return lif_interface_file_parse(collection, source_filename); +} + /* map keywords to parser functions */ struct parser_keyword { const char *token; @@ -103,6 +125,7 @@ struct parser_keyword { static const struct parser_keyword keywords[] = { {"auto", handle_auto}, + {"source", handle_source}, }; static int @@ -141,21 +164,6 @@ lif_interface_file_parse(struct lif_dict *collection, const char *filename) if (!parserkw->handle(collection, filename, lineno, token, bufp)) goto parse_error; } - else if (!strcmp(token, "source")) - { - char *source_filename = lif_next_token(&bufp); - if (!*source_filename) - goto parse_error; - - if (!strcmp(filename, source_filename)) - { - report_error(filename, lineno, "attempt to source %s would create infinite loop", - source_filename); - goto parse_error; - } - - lif_interface_file_parse(collection, source_filename); - } else if (!strcmp(token, "iface")) { char *ifname = lif_next_token(&bufp);