From e09f9e4c32b2c083756e22606c924172c02840c6 Mon Sep 17 00:00:00 2001 From: Martin Kletzander Date: Fri, 14 Nov 2014 15:57:17 +0100 Subject: [PATCH] virsh: Convert EDIT_NOT_CHANGED macro to do-while block. This macro is being used as an inline body after an if and might get pretty confusing. Signed-off-by: Martin Kletzander --- tools/virsh-domain.c | 33 +++++++++++++++++++++------------ tools/virsh-interface.c | 13 ++++++++----- tools/virsh-network.c | 11 +++++++---- tools/virsh-nwfilter.c | 15 +++++++++------ tools/virsh-pool.c | 11 +++++++---- tools/virsh-snapshot.c | 22 ++++++++++++---------- 6 files changed, 64 insertions(+), 41 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 541363d844..76f8b23563 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -4376,10 +4376,13 @@ cmdSaveImageEdit(vshControl *ctl, const vshCmd *cmd) #define EDIT_GET_XML \ virDomainSaveImageGetXMLDesc(ctl->conn, file, getxml_flags) -#define EDIT_NOT_CHANGED \ - vshPrint(ctl, _("Saved image %s XML configuration " \ - "not changed.\n"), file); \ - ret = true; goto edit_cleanup; +#define EDIT_NOT_CHANGED \ + do { \ + vshPrint(ctl, _("Saved image %s XML configuration " \ + "not changed.\n"), file); \ + ret = true; \ + goto edit_cleanup; \ + } while (0) #define EDIT_DEFINE \ (virDomainSaveImageDefineXML(ctl->conn, file, doc_edited, define_flags) == 0) #include "virsh-edit.c" @@ -7560,10 +7563,13 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd) } else if (edit) { #define EDIT_GET_XML \ vshDomainGetEditMetadata(ctl, dom, uri, flags) -#define EDIT_NOT_CHANGED \ - vshPrint(ctl, "%s", _("Metadata not changed")); \ - ret = true; \ - goto edit_cleanup; +#define EDIT_NOT_CHANGED \ + do { \ + vshPrint(ctl, "%s", _("Metadata not changed")); \ + ret = true; \ + goto edit_cleanup; \ + } while (0) + #define EDIT_DEFINE \ (virDomainSetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT, doc_edited, \ key, uri, flags) == 0) @@ -11058,10 +11064,13 @@ cmdEdit(vshControl *ctl, const vshCmd *cmd) goto cleanup; #define EDIT_GET_XML virDomainGetXMLDesc(dom, flags) -#define EDIT_NOT_CHANGED \ - vshPrint(ctl, _("Domain %s XML configuration not changed.\n"), \ - virDomainGetName(dom)); \ - ret = true; goto edit_cleanup; +#define EDIT_NOT_CHANGED \ + do { \ + vshPrint(ctl, _("Domain %s XML configuration not changed.\n"), \ + virDomainGetName(dom)); \ + ret = true; \ + goto edit_cleanup; \ + } while (0) #define EDIT_DEFINE \ (dom_edited = virDomainDefineXML(ctl->conn, doc_edited)) #include "virsh-edit.c" diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 6cacaf1071..5f848b6140 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -1,7 +1,7 @@ /* * virsh-interface.c: Commands to manage host interface * - * Copyright (C) 2005, 2007-2013 Red Hat, Inc. + * Copyright (C) 2005, 2007-2014 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -122,10 +122,13 @@ cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd) goto cleanup; #define EDIT_GET_XML virInterfaceGetXMLDesc(iface, flags) -#define EDIT_NOT_CHANGED \ - vshPrint(ctl, _("Interface %s XML configuration not changed.\n"), \ - virInterfaceGetName(iface)); \ - ret = true; goto edit_cleanup; +#define EDIT_NOT_CHANGED \ + do { \ + vshPrint(ctl, _("Interface %s XML configuration not changed.\n"), \ + virInterfaceGetName(iface)); \ + ret = true; \ + goto edit_cleanup; \ + } while (0) #define EDIT_DEFINE \ (iface_edited = virInterfaceDefineXML(ctl->conn, doc_edited, 0)) #include "virsh-edit.c" diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 8f9fbd3ecb..9dc52e58ee 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -1105,10 +1105,13 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd) goto cleanup; #define EDIT_GET_XML vshNetworkGetXMLDesc(network) -#define EDIT_NOT_CHANGED \ - vshPrint(ctl, _("Network %s XML configuration not changed.\n"), \ - virNetworkGetName(network)); \ - ret = true; goto edit_cleanup; +#define EDIT_NOT_CHANGED \ + do { \ + vshPrint(ctl, _("Network %s XML configuration not changed.\n"), \ + virNetworkGetName(network)); \ + ret = true; \ + goto edit_cleanup; \ + } while (0) #define EDIT_DEFINE \ (network_edited = virNetworkDefineXML(ctl->conn, doc_edited)) #include "virsh-edit.c" diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index ca54c9db58..2a75175ce0 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -1,7 +1,7 @@ /* * virsh-nwfilter.c: Commands to manage network filters * - * Copyright (C) 2005, 2007-2013 Red Hat, Inc. + * Copyright (C) 2005, 2007-2014 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -421,11 +421,14 @@ cmdNWFilterEdit(vshControl *ctl, const vshCmd *cmd) goto cleanup; #define EDIT_GET_XML virNWFilterGetXMLDesc(nwfilter, 0) -#define EDIT_NOT_CHANGED \ - vshPrint(ctl, _("Network filter %s XML " \ - "configuration not changed.\n"), \ - virNWFilterGetName(nwfilter)); \ - ret = true; goto edit_cleanup; +#define EDIT_NOT_CHANGED \ + do { \ + vshPrint(ctl, _("Network filter %s XML " \ + "configuration not changed.\n"), \ + virNWFilterGetName(nwfilter)); \ + ret = true; \ + goto edit_cleanup; \ + } while (0) #define EDIT_DEFINE \ (nwfilter_edited = virNWFilterDefineXML(ctl->conn, doc_edited)) #include "virsh-edit.c" diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 31f7ec3c90..d671efcfed 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -1761,10 +1761,13 @@ cmdPoolEdit(vshControl *ctl, const vshCmd *cmd) } #define EDIT_GET_XML virStoragePoolGetXMLDesc(pool, flags) -#define EDIT_NOT_CHANGED \ - vshPrint(ctl, _("Pool %s XML configuration not changed.\n"), \ - virStoragePoolGetName(pool)); \ - ret = true; goto edit_cleanup; +#define EDIT_NOT_CHANGED \ + do { \ + vshPrint(ctl, _("Pool %s XML configuration not changed.\n"), \ + virStoragePoolGetName(pool)); \ + ret = true; \ + goto edit_cleanup; \ + } while (0) #define EDIT_DEFINE \ (pool_edited = virStoragePoolDefineXML(ctl->conn, doc_edited, 0)) #include "virsh-edit.c" diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 885ad22ec5..9fe7751bad 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -1,7 +1,7 @@ /* * virsh-snapshot.c: Commands to manage domain snapshot * - * Copyright (C) 2005, 2007-2013 Red Hat, Inc. + * Copyright (C) 2005, 2007-2014 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -576,15 +576,17 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd) #define EDIT_GET_XML \ virDomainSnapshotGetXMLDesc(snapshot, getxml_flags) -#define EDIT_NOT_CHANGED \ - /* Depending on flags, we re-edit even if XML is unchanged. */ \ - if (!(define_flags & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT)) { \ - vshPrint(ctl, \ - _("Snapshot %s XML configuration not changed.\n"), \ - name); \ - ret = true; \ - goto edit_cleanup; \ - } +#define EDIT_NOT_CHANGED \ + do { \ + /* Depending on flags, we re-edit even if XML is unchanged. */ \ + if (!(define_flags & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT)) { \ + vshPrint(ctl, \ + _("Snapshot %s XML configuration not changed.\n"), \ + name); \ + ret = true; \ + goto edit_cleanup; \ + } \ + } while (0) #define EDIT_DEFINE \ (strstr(doc, "disk-snapshot") ? \ define_flags |= VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY : 0), \