[libvirt] [PATCH] Cleanup of the quick dirty fix from last week

I tried lots of different solutions and this seems like the most clean and readable one. --- src/lxc/lxc_container.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index e93fda5..c55f264 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -449,8 +449,6 @@ static int lxcContainerMountBasicFS(const char *srcprefix, bool pivotRoot) char *opts = NULL; #if HAVE_SELINUX security_context_t con; -#else - bool con = false; #endif VIR_DEBUG("Mounting basic filesystems %s pivotRoot=%d", NULLSTR(srcprefix), pivotRoot); @@ -511,10 +509,14 @@ static int lxcContainerMountBasicFS(const char *srcprefix, bool pivotRoot) * tmpfs is limited to 64kb, since we only have device nodes in there * and don't want to DOS the entire OS RAM usage */ +#if HAVE_SELINUX if (virAsprintf(&opts, "mode=755,size=65536%s%s%s", con ? ",context=\"" : "", con ? (const char *)con : "", con ? "\"" : "") < 0) { +#else + if (virAsprintf(&opts, "mode=755,size=65536") < 0) { +#endif virReportOOMError(); goto cleanup; } -- 1.7.3.4

On 02/09/2012 08:00 AM, Martin Kletzander wrote:
I tried lots of different solutions and this seems like the most clean and readable one. --- src/lxc/lxc_container.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
@@ -511,10 +509,14 @@ static int lxcContainerMountBasicFS(const char *srcprefix, bool pivotRoot) * tmpfs is limited to 64kb, since we only have device nodes in there * and don't want to DOS the entire OS RAM usage */ +#if HAVE_SELINUX if (virAsprintf(&opts, "mode=755,size=65536%s%s%s", con ? ",context=\"" : "", con ? (const char *)con : "", con ? "\"" : "") < 0) { +#else + if (virAsprintf(&opts, "mode=755,size=65536") < 0) { +#endif
I'm not a big fan of unbalanced '{' (two open and one close, because only the open was protected by ifdef), if only because editors that are aware of indentation but not of #ifdef will mis-indent code that follows. I'm thinking this might read better, and avoid the unbalanced {}: #if HAVE_SELINUX security_context_t con; #endif VIR_DEBUG("Mounting basic filesystems %s pivotRoot=%d", NULLSTR(srcprefix), pivotRoot); ... #if HAVE_SELINUX if (con) ignore_value(virAsprintf(&opts, "mode=755,size=65536,context=\"%s\"", (const char *)con)); else #endif opts = strdup("mode=755,size=65536); if (!opts) { virReportOOMError(); goto cleanup; } -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Thu, Feb 09, 2012 at 01:52:10PM -0700, Eric Blake wrote:
On 02/09/2012 08:00 AM, Martin Kletzander wrote:
I tried lots of different solutions and this seems like the most clean and readable one. --- src/lxc/lxc_container.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
@@ -511,10 +509,14 @@ static int lxcContainerMountBasicFS(const char *srcprefix, bool pivotRoot) * tmpfs is limited to 64kb, since we only have device nodes in there * and don't want to DOS the entire OS RAM usage */ +#if HAVE_SELINUX if (virAsprintf(&opts, "mode=755,size=65536%s%s%s", con ? ",context=\"" : "", con ? (const char *)con : "", con ? "\"" : "") < 0) { +#else + if (virAsprintf(&opts, "mode=755,size=65536") < 0) { +#endif
I'm not a big fan of unbalanced '{' (two open and one close, because only the open was protected by ifdef), if only because editors that are aware of indentation but not of #ifdef will mis-indent code that follows. I'm thinking this might read better, and avoid the unbalanced {}:
#if HAVE_SELINUX security_context_t con; #endif
VIR_DEBUG("Mounting basic filesystems %s pivotRoot=%d", NULLSTR(srcprefix), pivotRoot); ...
#if HAVE_SELINUX if (con) ignore_value(virAsprintf(&opts, "mode=755,size=65536,context=\"%s\"", (const char *)con)); else #endif opts = strdup("mode=755,size=65536);
^^^ " ^^^
if (!opts) { virReportOOMError(); goto cleanup; }
ACK to this variant, with the missing quote fixed Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (3)
-
Daniel P. Berrange
-
Eric Blake
-
Martin Kletzander