virsh: remove variable 'ret' and use early return if possible

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Kristina Hanicova 2021-09-24 01:49:08 +02:00 committed by Michal Privoznik
parent 978a124659
commit 28051aaa9b
5 changed files with 60 additions and 82 deletions

View File

@ -1242,7 +1242,6 @@ static bool
cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
{
const char *from = NULL;
bool ret = false;
g_autofree char *result = NULL;
g_auto(GStrv) list = NULL;
unsigned int flags = 0;
@ -1259,16 +1258,12 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
if (!(list = vshExtractCPUDefXMLs(ctl, from)))
return false;
result = virConnectBaselineCPU(priv->conn, (const char **)list,
g_strv_length(list),
flags);
if (!(result = virConnectBaselineCPU(priv->conn, (const char **)list,
g_strv_length(list), flags)))
return false;
if (result) {
vshPrint(ctl, "%s", result);
ret = true;
}
return ret;
vshPrint(ctl, "%s", result);
return true;
}
/*

View File

@ -535,7 +535,6 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd)
{
virInterfacePtr iface;
const char *from = NULL;
bool ret = true;
g_autofree char *buffer = NULL;
unsigned int flags = 0;
virshControl *priv = ctl->privData;
@ -549,17 +548,15 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd)
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
iface = virInterfaceDefineXML(priv->conn, buffer, flags);
if (iface != NULL) {
vshPrintExtra(ctl, _("Interface %s defined from %s\n"),
virInterfaceGetName(iface), from);
virInterfaceFree(iface);
} else {
if (!(iface = virInterfaceDefineXML(priv->conn, buffer, flags))) {
vshError(ctl, _("Failed to define interface from %s"), from);
ret = false;
return false;
}
return ret;
vshPrintExtra(ctl, _("Interface %s defined from %s\n"),
virInterfaceGetName(iface), from);
virInterfaceFree(iface);
return true;
}
/*
@ -584,21 +581,20 @@ static bool
cmdInterfaceUndefine(vshControl *ctl, const vshCmd *cmd)
{
virInterfacePtr iface;
bool ret = true;
const char *name;
if (!(iface = virshCommandOptInterface(ctl, cmd, &name)))
return false;
if (virInterfaceUndefine(iface) == 0) {
vshPrintExtra(ctl, _("Interface %s undefined\n"), name);
} else {
if (virInterfaceUndefine(iface) < 0) {
vshError(ctl, _("Failed to undefine interface %s"), name);
ret = false;
virInterfaceFree(iface);
return false;
}
vshPrintExtra(ctl, _("Interface %s undefined\n"), name);
virInterfaceFree(iface);
return ret;
return true;
}
/*
@ -623,21 +619,20 @@ static bool
cmdInterfaceStart(vshControl *ctl, const vshCmd *cmd)
{
virInterfacePtr iface;
bool ret = true;
const char *name;
if (!(iface = virshCommandOptInterface(ctl, cmd, &name)))
return false;
if (virInterfaceCreate(iface, 0) == 0) {
vshPrintExtra(ctl, _("Interface %s started\n"), name);
} else {
if (virInterfaceCreate(iface, 0) < 0) {
vshError(ctl, _("Failed to start interface %s"), name);
ret = false;
virInterfaceFree(iface);
return false;
}
vshPrintExtra(ctl, _("Interface %s started\n"), name);
virInterfaceFree(iface);
return ret;
return true;
}
/*
@ -662,21 +657,20 @@ static bool
cmdInterfaceDestroy(vshControl *ctl, const vshCmd *cmd)
{
virInterfacePtr iface;
bool ret = true;
const char *name;
if (!(iface = virshCommandOptInterface(ctl, cmd, &name)))
return false;
if (virInterfaceDestroy(iface, 0) == 0) {
vshPrintExtra(ctl, _("Interface %s destroyed\n"), name);
} else {
if (virInterfaceDestroy(iface, 0) < 0) {
vshError(ctl, _("Failed to destroy interface %s"), name);
ret = false;
virInterfaceFree(iface);
return false;
}
vshPrintExtra(ctl, _("Interface %s destroyed\n"), name);
virInterfaceFree(iface);
return ret;
return false;
}
/*

View File

@ -209,7 +209,6 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd)
{
virNetworkPtr network;
const char *from = NULL;
bool ret = true;
g_autofree char *buffer = NULL;
unsigned int flags = 0;
virshControl *priv = ctl->privData;
@ -228,15 +227,15 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd)
else
network = virNetworkCreateXML(priv->conn, buffer);
if (network != NULL) {
vshPrintExtra(ctl, _("Network %s created from %s\n"),
virNetworkGetName(network), from);
virNetworkFree(network);
} else {
if (!network) {
vshError(ctl, _("Failed to create network from %s"), from);
ret = false;
return false;
}
return ret;
vshPrintExtra(ctl, _("Network %s created from %s\n"),
virNetworkGetName(network), from);
virNetworkFree(network);
return true;
}
/*
@ -267,7 +266,6 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd)
{
virNetworkPtr network;
const char *from = NULL;
bool ret = true;
g_autofree char *buffer = NULL;
unsigned int flags = 0;
virshControl *priv = ctl->privData;
@ -286,15 +284,15 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd)
else
network = virNetworkDefineXML(priv->conn, buffer);
if (network != NULL) {
vshPrintExtra(ctl, _("Network %s defined from %s\n"),
virNetworkGetName(network), from);
virNetworkFree(network);
} else {
if (!network) {
vshError(ctl, _("Failed to define network from %s"), from);
ret = false;
return false;
}
return ret;
vshPrintExtra(ctl, _("Network %s defined from %s\n"),
virNetworkGetName(network), from);
virNetworkFree(network);
return true;
}
/*

View File

@ -57,7 +57,6 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
{
virNodeDevicePtr dev = NULL;
const char *from = NULL;
bool ret = true;
g_autofree char *buffer = NULL;
virshControl *priv = ctl->privData;
@ -67,18 +66,15 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
dev = virNodeDeviceCreateXML(priv->conn, buffer, 0);
if (dev != NULL) {
vshPrintExtra(ctl, _("Node device %s created from %s\n"),
virNodeDeviceGetName(dev), from);
virNodeDeviceFree(dev);
} else {
if (!(dev = virNodeDeviceCreateXML(priv->conn, buffer, 0))) {
vshError(ctl, _("Failed to create node device from %s"), from);
ret = false;
return false;
}
return ret;
vshPrintExtra(ctl, _("Node device %s created from %s\n"),
virNodeDeviceGetName(dev), from);
virNodeDeviceFree(dev);
return true;
}
@ -1077,7 +1073,6 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
{
virNodeDevice *dev = NULL;
const char *from = NULL;
bool ret = true;
g_autofree char *buffer = NULL;
virshControl *priv = ctl->privData;
@ -1087,18 +1082,15 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
dev = virNodeDeviceDefineXML(priv->conn, buffer, 0);
if (dev != NULL) {
vshPrintExtra(ctl, _("Node device '%s' defined from '%s'\n"),
virNodeDeviceGetName(dev), from);
virNodeDeviceFree(dev);
} else {
if (!(dev = virNodeDeviceDefineXML(priv->conn, buffer, 0))) {
vshError(ctl, _("Failed to define node device from '%s'"), from);
ret = false;
return false;
}
return ret;
vshPrintExtra(ctl, _("Node device '%s' defined from '%s'\n"),
virNodeDeviceGetName(dev), from);
virNodeDeviceFree(dev);
return true;
}

View File

@ -515,7 +515,6 @@ cmdNWFilterBindingCreate(vshControl *ctl, const vshCmd *cmd)
{
virNWFilterBindingPtr binding;
const char *from = NULL;
bool ret = true;
char *buffer;
unsigned int flags = 0;
virshControl *priv = ctl->privData;
@ -532,15 +531,15 @@ cmdNWFilterBindingCreate(vshControl *ctl, const vshCmd *cmd)
binding = virNWFilterBindingCreateXML(priv->conn, buffer, flags);
VIR_FREE(buffer);
if (binding != NULL) {
vshPrintExtra(ctl, _("Network filter binding on %s created from %s\n"),
virNWFilterBindingGetPortDev(binding), from);
virNWFilterBindingFree(binding);
} else {
if (!binding) {
vshError(ctl, _("Failed to create network filter from %s"), from);
ret = false;
return false;
}
return ret;
vshPrintExtra(ctl, _("Network filter binding on %s created from %s\n"),
virNWFilterBindingGetPortDev(binding), from);
virNWFilterBindingFree(binding);
return true;
}