From: Corey Bryant <coreyb@linux.vnet.ibm.com>
To: Doug Goldstein <cardoe@cardoe.com>
Cc: Richa Marwaha <rmarwah@linux.vnet.ibm.com>,
Anthony Liguori <aliguori@us.ibm.com>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCHv2 2/2] bridge helper: support conf dirs
Date: Mon, 04 Mar 2013 11:40:57 -0500 [thread overview]
Message-ID: <5134CE99.9000607@linux.vnet.ibm.com> (raw)
In-Reply-To: <1362207528-27804-3-git-send-email-cardoe@cardoe.com>
On 03/02/2013 01:58 AM, Doug Goldstein wrote:
> 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 <cardoe@cardoe.com>
> CC: Anthony Liguori <aliguori@us.ibm.com>
> CC: Richa Marwaha <rmarwah@linux.vnet.ibm.com>
> CC: Corey Bryant <coreyb@linux.vnet.ibm.com>
> TO: qemu-devel@nongnu.org
> ---
> qemu-bridge-helper.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 55 insertions(+)
>
> diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c
> index ee67740..39d343c 100644
> --- a/qemu-bridge-helper.c
> +++ b/qemu-bridge-helper.c
> @@ -16,6 +16,7 @@
> #include "config-host.h"
>
> #include <stdio.h>
> +#include <dirent.h>
> #include <errno.h>
> #include <fcntl.h>
> #include <unistd.h>
> @@ -70,12 +71,27 @@ 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;
QEMU prefers braces on single statement blocks. Check out the
CODING_STYLE file. Also you'll want to run scripts/checkpatch.pl
against your patches and make sure it's not flagging any issues. It'll
catch things like this.
> +
> + 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 +153,37 @@ 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++) {
> + if (asprintf(&conf_file, "%s/%s", arg,
> + include_list[i]->d_name) < 0) {
> + fprintf(stderr, "Failed to allocate memory for "
> + "file path: %s/%s\n",
> + arg, include_list[i]->d_name);
> + ret = -ENOMEM;
> + goto failure;
> + }
> +
> + /* ignore errors like 'include' cmd */
> + parse_acl_file(conf_file, acl_list);
> +
> + 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 +199,14 @@ static int parse_acl_file(const char *filename, ACLList *acl_list)
> failure:
> fclose(f);
>
> + if (include_list) {
> + for (i = 0; i < include_count; i++) {
> + if (include_list[i])
> + free(include_list[i]);
Same comment here.
> + }
> + free(include_list);
> + }
> +
> return ret;
> }
>
--
Regards,
Corey Bryant
next prev parent reply other threads:[~2013-03-04 16:42 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1361757620-23318-1-git-send-email-cardoe@cardoe.com>
2013-03-02 6:58 ` [Qemu-devel] [PATCHv2 0/2] bridge helper: includedir conf arg Doug Goldstein
2013-03-02 6:58 ` [Qemu-devel] [PATCHv2 1/2] bridge helper: unified error cleanup for parse_acl_file Doug Goldstein
2013-03-04 16:27 ` Corey Bryant
2013-03-04 18:53 ` Doug Goldstein
2013-03-04 19:04 ` Corey Bryant
2013-03-02 6:58 ` [Qemu-devel] [PATCHv2 2/2] bridge helper: support conf dirs Doug Goldstein
2013-03-04 16:40 ` Corey Bryant [this message]
2013-03-05 9:19 ` Stefan Hajnoczi
2013-03-07 6:32 ` [Qemu-devel] [PATCHv3 0/2] bridge helper: includedir conf arg Doug Goldstein
2013-03-07 6:32 ` [Qemu-devel] [PATCHv3 1/2] bridge helper: unified error cleanup for parse_acl_file Doug Goldstein
2013-03-07 6:32 ` [Qemu-devel] [PATCHv3 2/2] bridge helper: support conf dirs Doug Goldstein
2013-03-09 9:50 ` Blue Swirl
2013-03-07 9:10 ` [Qemu-devel] [PATCHv3 0/2] bridge helper: includedir conf arg Stefan Hajnoczi
2013-03-07 15:11 ` Corey Bryant
2013-03-18 4:17 ` [Qemu-devel] [PATCH v3 " Doug Goldstein
2013-03-18 4:17 ` [Qemu-devel] [PATCH v3 1/2] bridge helper: unified error cleanup for parse_acl_file Doug Goldstein
2013-03-18 4:17 ` [Qemu-devel] [PATCH v3 2/2] bridge helper: support conf dirs Doug Goldstein
2013-03-18 10:01 ` [Qemu-devel] [PATCH v3 0/2] bridge helper: includedir conf arg Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5134CE99.9000607@linux.vnet.ibm.com \
--to=coreyb@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=cardoe@cardoe.com \
--cc=qemu-devel@nongnu.org \
--cc=rmarwah@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).