[libvirt] [PATCH V6 04/11] Use scripting for cleaning and renaming of chains

Eric Blake eblake at redhat.com
Fri Nov 18 16:01:51 UTC 2011


On 11/18/2011 06:32 AM, Stefan Berger wrote:
> Use scripts for the renaming and cleaning up of chains. This allows us to get
> rid of some of the code that is only capable of renaming and removing chains
> whose names are hardcoded.
> 
> +static const char ebtables_script_func_collect_chains[] =
> +    "collect_chains()\n"
> +    "{\n"
> +    "  for tmp2 in $*; do\n"
> +    "    for tmp in $(%s -t %s -L $tmp2 | \\\n"
> +    "      sed -n \"/Bridge chain/,\\$ s/.*-j \\\\([%s]-.*\\\\)/\\\\1/p\");\n"

No need to change this unless you want, but this could be written in
fewer bytes as:

"    sed -n '/Bridge chain/,$ s/.*-j \\([%s]-.*\\)/\\1/p')\n"

> +    virBufferAsprintf(buf, NWFILTER_FUNC_SET_IFS);
> +    virBufferAddLit(buf, "a=\"$(collect_chains ");
> +    for (i = 0; chains[i] != 0; i++) {
> +        PRINT_ROOT_CHAIN(rootchain, chains[i], ifname);
> +        virBufferAsprintf(buf, "%s ", rootchain);
> +    }
> +    virBufferAddLit(buf, ")\"\n");

As written, you generate:
  a="$(collect_chains a b )"
with an odd space before ).  I also think the name $a is rather terse;
it might be better to use something a bit less cryptic.  What you have
works, but you could also make this tweak if you'd like:

virBufferAddLit(buf, "chains=\"$(collect_chains");
for ...
  virBufferAsprintf(buf, " %s", rootchain);
virBufferAddLit(buf, ")\"\n");
...
virBufferAddLit(buf, "rm_chains $chains\n");

-- 
Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20111118/c699be74/attachment-0001.sig>


More information about the libvir-list mailing list