Received: from eggs.gnu.org ([208.118.235.92]:56839) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHRW0-00089u-IR for qemu-devel@nongnu.org; Mon, 18 Mar 2013 00:17:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UHRVx-0006Ph-El for qemu-devel@nongnu.org; Mon, 18 Mar 2013 00:17:40 -0400 Received: from mail-qc0-x22e.google.com ([2607:f8b0:400d:c01::22e]:44540) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHRVx-0006Pb-6L for qemu-devel@nongnu.org; Mon, 18 Mar 2013 00:17:37 -0400 Received: by mail-qc0-f174.google.com with SMTP id z24so2588906qcq.33 for ; Sun, 17 Mar 2013 21:17:36 -0700 (PDT) From: Doug Goldstein Date: Sun, 17 Mar 2013 23:17:21 -0500 Message-Id: <1363580241-31141-3-git-send-email-cardoe@cardoe.com> In-Reply-To: <1363580241-31141-1-git-send-email-cardoe@cardoe.com> References: <1363580241-31141-1-git-send-email-cardoe@cardoe.com> Subject: [Qemu-devel] [PATCH v3 2/2] bridge helper: support conf dirs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , Corey Bryant , Doug Goldstein , Richa Marwaha Allow the bridge helper to take a config directory rather than having to specify every file in the directory manually via an include statement. Signed-off-by: Doug Goldstein Reviewed-by: Stefan Hajnoczi Reviewed-by: Corey Bryant CC: Anthony Liguori CC: Richa Marwaha CC: Corey Bryant TO: qemu-devel@nongnu.org --- qemu-bridge-helper.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c index 95486e7..b647848 100644 --- a/qemu-bridge-helper.c +++ b/qemu-bridge-helper.c @@ -16,6 +16,7 @@ #include "config-host.h" #include +#include #include #include #include @@ -70,12 +71,28 @@ static void usage(void) "Usage: qemu-bridge-helper [--use-vnet] --br=bridge --fd=unixfd\n"); } +static int filter_bridge_conf_dir(const struct dirent *entry) +{ + ssize_t len = strlen(entry->d_name); + + /* We only want files ending in .conf */ + if (len > 5 && + strcmp(".conf", &entry->d_name[len-5]) == 0) { + return 1; + } + + return 0; +} + static int parse_acl_file(const char *filename, ACLList *acl_list) { FILE *f; char line[4096]; int ret = -EINVAL; ACLRule *acl_rule; + struct dirent **include_list = NULL; + int i, include_count = 0; + char *conf_file; f = fopen(filename, "r"); if (f == NULL) { @@ -137,6 +154,31 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) snprintf(acl_rule->iface, IFNAMSIZ, "%s", arg); } QSIMPLEQ_INSERT_TAIL(acl_list, acl_rule, entry); + } else if (strcmp(cmd, "includedir") == 0) { + include_count = scandir(arg, &include_list, + filter_bridge_conf_dir, alphasort); + if (include_count < 0) { + ret = -errno; + fprintf(stderr, "Unable to retrieve conf files from '%s': %s\n", + arg, strerror(errno)); + goto failure; + } + + for (i = 0; i < include_count; i++) { + conf_file = g_strdup_printf("%s/%s", arg, + include_list[i]->d_name); + + /* ignore errors like 'include' cmd */ + parse_acl_file(conf_file, acl_list); + + g_free(conf_file); + free(include_list[i]); + include_list[i] = NULL; + } + free(include_list); + include_list = NULL; + include_count = 0; + } else if (strcmp(cmd, "include") == 0) { /* ignore errors */ parse_acl_file(arg, acl_list); @@ -152,6 +194,11 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) failure: fclose(f); + for (i = 0; i < include_count; i++) { + free(include_list[i]); + } + free(include_list); + return ret; } -- 1.8.1.5