[libvirt] [PATCH 2/2] virsh: update attach-interface docs
by Osier Yang
* tools/virsh.pod (attach-interface): add docs for new option
'model' and missed option 'persistent'.
---
tools/virsh.pod | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 61875af..d904800 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -647,7 +647,7 @@ although this use only replaces the media within the existing virtual cdrom or
floppy device; consider using B<update-device> for this usage instead.
I<mode> can specify the two specific mode I<readonly> or I<shareable>.
-=item B<attach-interface> I<domain-id> I<type> I<source> optional I<--target target> I<--mac mac> I<--script script>
+=item B<attach-interface> I<domain-id> I<type> I<source> optional I<--target target> I<--mac mac> I<--script script> I<--model model> I<--persistent>
Attach a new network interface to the domain.
I<type> can be either I<network> to indicate a physical network device or I<bridge> to indicate a bridge to a device.
@@ -656,6 +656,8 @@ I<target> allows to indicate the target device in the guest.
I<mac> allows to specify the MAC address of the network interface.
I<script> allows to specify a path to a script handling a bridge instead of
the default one.
+I<model> allows to specify the model type.
+I<persistent> indicates the changes will affect the next boot of the domain.
=item B<detach-device> I<domain-id> I<FILE>
--
1.7.1
14 years, 1 month
[libvirt] [PATCH] Fix formatting of network address in iptables helpers
by Daniel P. Berrange
The network address was being set to 192.168.122.0 instead
of 192.168.122.0/24. Fix this by removing the unneccessary
'network' field from virNetworkDef and just pass the
network address and netmask into the iptables APIs directly.
* src/conf/network_conf.h, src/conf/network_conf.c: Remove
the 'network' field from virNEtworkDef.
* src/network/bridge_driver.c: Update for iptables API changes
* src/util/iptables.c, src/util/iptables.h: Require the
network address + netmask pair to be passed in
---
src/conf/network_conf.c | 4 -
src/conf/network_conf.h | 1 -
src/network/bridge_driver.c | 62 ++++++++++++------
src/util/iptables.c | 149 +++++++++++++++++++++++++------------------
src/util/iptables.h | 24 +++++--
5 files changed, 142 insertions(+), 98 deletions(-)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 0bc5a54..3f2bf1f 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -438,10 +438,6 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
goto error;
}
- def->network = def->ipAddress;
- def->network.data.inet4.sin_addr.s_addr &=
- def->netmask.data.inet4.sin_addr.s_addr;
-
if ((ip = virXPathNode("./ip[1]", ctxt)) &&
virNetworkIPParseXML(def, ip) < 0)
goto error;
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 5a01bbf..7d31693 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -72,7 +72,6 @@ struct _virNetworkDef {
virSocketAddr ipAddress; /* Bridge IP address */
virSocketAddr netmask;
- virSocketAddr network;
unsigned int nranges; /* Zero or more dhcp ranges */
virNetworkDHCPRangeDefPtr ranges;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 5ee47eb..8721747 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -671,7 +671,8 @@ networkAddMasqueradingIptablesRules(struct network_driver *driver,
int err;
/* allow forwarding packets from the bridge interface */
if ((err = iptablesAddForwardAllowOut(driver->iptables,
- &network->def->network,
+ &network->def->ipAddress,
+ &network->def->netmask,
network->def->bridge,
network->def->forwardDev))) {
virReportSystemError(err,
@@ -682,9 +683,10 @@ networkAddMasqueradingIptablesRules(struct network_driver *driver,
/* allow forwarding packets to the bridge interface if they are part of an existing connection */
if ((err = iptablesAddForwardAllowRelatedIn(driver->iptables,
- &network->def->network,
- network->def->bridge,
- network->def->forwardDev))) {
+ &network->def->ipAddress,
+ &network->def->netmask,
+ network->def->bridge,
+ network->def->forwardDev))) {
virReportSystemError(err,
_("failed to add iptables rule to allow forwarding to '%s'"),
network->def->bridge);
@@ -716,7 +718,8 @@ networkAddMasqueradingIptablesRules(struct network_driver *driver,
/* First the generic masquerade rule for other protocols */
if ((err = iptablesAddForwardMasquerade(driver->iptables,
- &network->def->network,
+ &network->def->ipAddress,
+ &network->def->netmask,
network->def->forwardDev,
NULL))) {
virReportSystemError(err,
@@ -727,7 +730,8 @@ networkAddMasqueradingIptablesRules(struct network_driver *driver,
/* UDP with a source port restriction */
if ((err = iptablesAddForwardMasquerade(driver->iptables,
- &network->def->network,
+ &network->def->ipAddress,
+ &network->def->netmask,
network->def->forwardDev,
"udp"))) {
virReportSystemError(err,
@@ -738,7 +742,8 @@ networkAddMasqueradingIptablesRules(struct network_driver *driver,
/* TCP with a source port restriction */
if ((err = iptablesAddForwardMasquerade(driver->iptables,
- &network->def->network,
+ &network->def->ipAddress,
+ &network->def->netmask,
network->def->forwardDev,
"tcp"))) {
virReportSystemError(err,
@@ -751,22 +756,26 @@ networkAddMasqueradingIptablesRules(struct network_driver *driver,
masqerr5:
iptablesRemoveForwardMasquerade(driver->iptables,
- &network->def->network,
+ &network->def->ipAddress,
+ &network->def->netmask,
network->def->forwardDev,
"udp");
masqerr4:
iptablesRemoveForwardMasquerade(driver->iptables,
- &network->def->network,
+ &network->def->ipAddress,
+ &network->def->netmask,
network->def->forwardDev,
NULL);
masqerr3:
iptablesRemoveForwardAllowRelatedIn(driver->iptables,
- &network->def->network,
- network->def->bridge,
- network->def->forwardDev);
+ &network->def->ipAddress,
+ &network->def->netmask,
+ network->def->bridge,
+ network->def->forwardDev);
masqerr2:
iptablesRemoveForwardAllowOut(driver->iptables,
- &network->def->network,
+ &network->def->ipAddress,
+ &network->def->netmask,
network->def->bridge,
network->def->forwardDev);
masqerr1:
@@ -779,7 +788,8 @@ networkAddRoutingIptablesRules(struct network_driver *driver,
int err;
/* allow routing packets from the bridge interface */
if ((err = iptablesAddForwardAllowOut(driver->iptables,
- &network->def->network,
+ &network->def->ipAddress,
+ &network->def->netmask,
network->def->bridge,
network->def->forwardDev))) {
virReportSystemError(err,
@@ -790,7 +800,8 @@ networkAddRoutingIptablesRules(struct network_driver *driver,
/* allow routing packets to the bridge interface */
if ((err = iptablesAddForwardAllowIn(driver->iptables,
- &network->def->network,
+ &network->def->ipAddress,
+ &network->def->netmask,
network->def->bridge,
network->def->forwardDev))) {
virReportSystemError(err,
@@ -804,7 +815,8 @@ networkAddRoutingIptablesRules(struct network_driver *driver,
routeerr2:
iptablesRemoveForwardAllowOut(driver->iptables,
- &network->def->network,
+ &network->def->ipAddress,
+ &network->def->netmask,
network->def->bridge,
network->def->forwardDev);
routeerr1:
@@ -943,29 +955,35 @@ networkRemoveIptablesRules(struct network_driver *driver,
if (network->def->forwardType != VIR_NETWORK_FORWARD_NONE) {
if (network->def->forwardType == VIR_NETWORK_FORWARD_NAT) {
iptablesRemoveForwardMasquerade(driver->iptables,
- &network->def->network,
+ &network->def->ipAddress,
+ &network->def->netmask,
network->def->forwardDev,
"tcp");
iptablesRemoveForwardMasquerade(driver->iptables,
- &network->def->network,
+ &network->def->ipAddress,
+ &network->def->netmask,
network->def->forwardDev,
"udp");
iptablesRemoveForwardMasquerade(driver->iptables,
- &network->def->network,
+ &network->def->ipAddress,
+ &network->def->netmask,
network->def->forwardDev,
NULL);
iptablesRemoveForwardAllowRelatedIn(driver->iptables,
- &network->def->network,
+ &network->def->ipAddress,
+ &network->def->netmask,
network->def->bridge,
network->def->forwardDev);
} else if (network->def->forwardType == VIR_NETWORK_FORWARD_ROUTE)
iptablesRemoveForwardAllowIn(driver->iptables,
- &network->def->network,
+ &network->def->ipAddress,
+ &network->def->netmask,
network->def->bridge,
network->def->forwardDev);
iptablesRemoveForwardAllowOut(driver->iptables,
- &network->def->network,
+ &network->def->ipAddress,
+ &network->def->netmask,
network->def->bridge,
network->def->forwardDev);
}
diff --git a/src/util/iptables.c b/src/util/iptables.c
index 64efd45..fc656b9 100644
--- a/src/util/iptables.c
+++ b/src/util/iptables.c
@@ -44,8 +44,9 @@
#include "virterror_internal.h"
#include "logging.h"
+#define VIR_FROM_THIS VIR_FROM_NONE
#define iptablesError(code, ...) \
- virReportErrorHelper(NULL, VIR_FROM_NONE, code, __FILE__, \
+ virReportErrorHelper(NULL, VIR_FROM_THIS, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__)
enum {
@@ -323,26 +324,55 @@ iptablesRemoveUdpInput(iptablesContext *ctx,
}
+static char *iptablesFormatNetwork(virSocketAddr *netaddr,
+ virSocketAddr *netmask)
+{
+ virSocketAddr network;
+ int prefix;
+ char *netstr;
+ char *ret;
+
+ if (!VIR_SOCKET_IS_FAMILY(netaddr, AF_INET) ||
+ !VIR_SOCKET_IS_FAMILY(netmask, AF_INET)) {
+ iptablesError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Only IPv4 addresses can be used with iptables"));
+ return NULL;
+ }
+
+ network = *netaddr;
+ network.data.inet4.sin_addr.s_addr &=
+ netmask->data.inet4.sin_addr.s_addr;
+
+ prefix = virSocketGetNumNetmaskBits(netmask);
+
+ netstr = virSocketFormatAddr(&network);
+
+ if (!netstr)
+ return NULL;
+
+ if (virAsprintf(&ret, "%s/%d", netstr, prefix) < 0)
+ virReportOOMError();
+
+ VIR_FREE(netstr);
+ return ret;
+}
+
+
/* Allow all traffic coming from the bridge, with a valid network address
* to proceed to WAN
*/
static int
iptablesForwardAllowOut(iptablesContext *ctx,
- virSocketAddr *network,
- const char *iface,
- const char *physdev,
- int action)
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
+ const char *iface,
+ const char *physdev,
+ int action)
{
int ret;
char *networkstr;
- if (!VIR_SOCKET_IS_FAMILY(network, AF_INET)) {
- iptablesError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Only IPv4 addresses can be used with iptables"));
- return -1;
- }
-
- if (!(networkstr = virSocketFormatAddr(network)))
+ if (!(networkstr = iptablesFormatNetwork(netaddr, netmask)))
return -1;
if (physdev && physdev[0]) {
@@ -380,11 +410,12 @@ iptablesForwardAllowOut(iptablesContext *ctx,
*/
int
iptablesAddForwardAllowOut(iptablesContext *ctx,
- virSocketAddr *network,
- const char *iface,
- const char *physdev)
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
+ const char *iface,
+ const char *physdev)
{
- return iptablesForwardAllowOut(ctx, network, iface, physdev, ADD);
+ return iptablesForwardAllowOut(ctx, netaddr, netmask, iface, physdev, ADD);
}
/**
@@ -402,11 +433,12 @@ iptablesAddForwardAllowOut(iptablesContext *ctx,
*/
int
iptablesRemoveForwardAllowOut(iptablesContext *ctx,
- virSocketAddr *network,
- const char *iface,
- const char *physdev)
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
+ const char *iface,
+ const char *physdev)
{
- return iptablesForwardAllowOut(ctx, network, iface, physdev, REMOVE);
+ return iptablesForwardAllowOut(ctx, netaddr, netmask, iface, physdev, REMOVE);
}
@@ -415,21 +447,16 @@ iptablesRemoveForwardAllowOut(iptablesContext *ctx,
*/
static int
iptablesForwardAllowRelatedIn(iptablesContext *ctx,
- virSocketAddr *network,
- const char *iface,
- const char *physdev,
- int action)
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
+ const char *iface,
+ const char *physdev,
+ int action)
{
int ret;
char *networkstr;
- if (!VIR_SOCKET_IS_FAMILY(network, AF_INET)) {
- iptablesError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Only IPv4 addresses can be used with iptables"));
- return -1;
- }
-
- if (!(networkstr = virSocketFormatAddr(network)))
+ if (!(networkstr = iptablesFormatNetwork(netaddr, netmask)))
return -1;
if (physdev && physdev[0]) {
@@ -471,11 +498,12 @@ iptablesForwardAllowRelatedIn(iptablesContext *ctx,
*/
int
iptablesAddForwardAllowRelatedIn(iptablesContext *ctx,
- virSocketAddr *network,
- const char *iface,
- const char *physdev)
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
+ const char *iface,
+ const char *physdev)
{
- return iptablesForwardAllowRelatedIn(ctx, network, iface, physdev, ADD);
+ return iptablesForwardAllowRelatedIn(ctx, netaddr, netmask, iface, physdev, ADD);
}
/**
@@ -493,18 +521,20 @@ iptablesAddForwardAllowRelatedIn(iptablesContext *ctx,
*/
int
iptablesRemoveForwardAllowRelatedIn(iptablesContext *ctx,
- virSocketAddr *network,
- const char *iface,
- const char *physdev)
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
+ const char *iface,
+ const char *physdev)
{
- return iptablesForwardAllowRelatedIn(ctx, network, iface, physdev, REMOVE);
+ return iptablesForwardAllowRelatedIn(ctx, netaddr, netmask, iface, physdev, REMOVE);
}
/* Allow all traffic destined to the bridge, with a valid network address
*/
static int
iptablesForwardAllowIn(iptablesContext *ctx,
- virSocketAddr *network,
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
const char *iface,
const char *physdev,
int action)
@@ -512,13 +542,7 @@ iptablesForwardAllowIn(iptablesContext *ctx,
int ret;
char *networkstr;
- if (!VIR_SOCKET_IS_FAMILY(network, AF_INET)) {
- iptablesError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Only IPv4 addresses can be used with iptables"));
- return -1;
- }
-
- if (!(networkstr = virSocketFormatAddr(network)))
+ if (!(networkstr = iptablesFormatNetwork(netaddr, netmask)))
return -1;
if (physdev && physdev[0]) {
@@ -556,11 +580,12 @@ iptablesForwardAllowIn(iptablesContext *ctx,
*/
int
iptablesAddForwardAllowIn(iptablesContext *ctx,
- virSocketAddr *network,
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
const char *iface,
const char *physdev)
{
- return iptablesForwardAllowIn(ctx, network, iface, physdev, ADD);
+ return iptablesForwardAllowIn(ctx, netaddr, netmask, iface, physdev, ADD);
}
/**
@@ -578,11 +603,12 @@ iptablesAddForwardAllowIn(iptablesContext *ctx,
*/
int
iptablesRemoveForwardAllowIn(iptablesContext *ctx,
- virSocketAddr *network,
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
const char *iface,
const char *physdev)
{
- return iptablesForwardAllowIn(ctx, network, iface, physdev, REMOVE);
+ return iptablesForwardAllowIn(ctx, netaddr, netmask, iface, physdev, REMOVE);
}
@@ -744,7 +770,8 @@ iptablesRemoveForwardRejectIn(iptablesContext *ctx,
*/
static int
iptablesForwardMasquerade(iptablesContext *ctx,
- virSocketAddr *network,
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
const char *physdev,
const char *protocol,
int action)
@@ -752,13 +779,7 @@ iptablesForwardMasquerade(iptablesContext *ctx,
int ret;
char *networkstr;
- if (!VIR_SOCKET_IS_FAMILY(network, AF_INET)) {
- iptablesError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Only IPv4 addresses can be used with iptables"));
- return -1;
- }
-
- if (!(networkstr = virSocketFormatAddr(network)))
+ if (!(networkstr = iptablesFormatNetwork(netaddr, netmask)))
return -1;
if (protocol && protocol[0]) {
@@ -819,11 +840,12 @@ iptablesForwardMasquerade(iptablesContext *ctx,
*/
int
iptablesAddForwardMasquerade(iptablesContext *ctx,
- virSocketAddr *network,
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
const char *physdev,
const char *protocol)
{
- return iptablesForwardMasquerade(ctx, network, physdev, protocol, ADD);
+ return iptablesForwardMasquerade(ctx, netaddr, netmask, physdev, protocol, ADD);
}
/**
@@ -841,11 +863,12 @@ iptablesAddForwardMasquerade(iptablesContext *ctx,
*/
int
iptablesRemoveForwardMasquerade(iptablesContext *ctx,
- virSocketAddr *network,
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
const char *physdev,
const char *protocol)
{
- return iptablesForwardMasquerade(ctx, network, physdev, protocol, REMOVE);
+ return iptablesForwardMasquerade(ctx, netaddr, netmask, physdev, protocol, REMOVE);
}
diff --git a/src/util/iptables.h b/src/util/iptables.h
index fd49685..ed843ec 100644
--- a/src/util/iptables.h
+++ b/src/util/iptables.h
@@ -44,29 +44,35 @@ int iptablesRemoveUdpInput (iptablesContext *ctx,
int port);
int iptablesAddForwardAllowOut (iptablesContext *ctx,
- virSocketAddr *network,
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
const char *iface,
const char *physdev);
int iptablesRemoveForwardAllowOut (iptablesContext *ctx,
- virSocketAddr *network,
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
const char *iface,
const char *physdev);
int iptablesAddForwardAllowRelatedIn(iptablesContext *ctx,
- virSocketAddr *network,
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
const char *iface,
const char *physdev);
int iptablesRemoveForwardAllowRelatedIn(iptablesContext *ctx,
- virSocketAddr *network,
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
const char *iface,
const char *physdev);
int iptablesAddForwardAllowIn (iptablesContext *ctx,
- virSocketAddr *network,
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
const char *iface,
const char *physdev);
int iptablesRemoveForwardAllowIn (iptablesContext *ctx,
- virSocketAddr *network,
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
const char *iface,
const char *physdev);
@@ -86,11 +92,13 @@ int iptablesRemoveForwardRejectIn (iptablesContext *ctx,
const char *iface);
int iptablesAddForwardMasquerade (iptablesContext *ctx,
- virSocketAddr *network,
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
const char *physdev,
const char *protocol);
int iptablesRemoveForwardMasquerade (iptablesContext *ctx,
- virSocketAddr *network,
+ virSocketAddr *netaddr,
+ virSocketAddr *netmask,
const char *physdev,
const char *protocol);
int iptablesAddOutputFixUdpChecksum (iptablesContext *ctx,
--
1.7.2.3
14 years, 1 month
[libvirt] [PATCH v2] [TCK] network: create networks and check for expected results
by Stefan Berger
V2:
- test cases for ipconfig, brctl added
- fixed test data after after using iptables with -n
Derived from the nwfilter test program, this one works with libvirt's
networks. It creates networks from provided xml files and checks for
expected configuration in iptables, running processes and virsh output
using provided data files with commands to execute and the expected
results for after creating the network and after tearing it down
(*.post.dat). 3 tests are currently not passing due to a bug in
libvirt...
Signed-off-by: Stefan Berger<stefanb(a)us.ibm.com>
---
Build.PL | 2
scripts/networks/100-apply-verify-host.t | 10
scripts/networks/networkApplyTest.sh | 343 +++++++++++++
scripts/networks/networkxml2hostout/tck-testnet-1.dat | 17
scripts/networks/networkxml2hostout/tck-testnet-1.post.dat | 7
scripts/networks/networkxml2hostout/tck-testnet-2.dat | 14
scripts/networks/networkxml2hostout/tck-testnet-2.post.dat | 7
scripts/networks/networkxml2xmlin/tck-testnet-1.xml | 12
scripts/networks/networkxml2xmlin/tck-testnet-2.xml | 12
9 files changed, 423 insertions(+), 1 deletion(-)
Index: libvirt-tck/scripts/networks/networkApplyTest.sh
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/networks/networkApplyTest.sh
@@ -0,0 +1,343 @@
+#!/bin/bash
+
+VIRSH=virsh
+
+uri=
+if [ "x${LIBVIRT_TCK_CONFIG}x" != "xx" ]; then
+ uri_exp=`cat ${LIBVIRT_TCK_CONFIG} | grep "^uri\s*=" | sed -e 's/uri\s*=\s*//' | tail -n 1`
+ if [ "x${uri_exp}x" != "xx" ]; then
+ eval "uri=${uri_exp}"
+ fi
+ if [ "x${uri}x" == "xx" ]; then
+ uri="qemu:///system"
+ fi
+else
+ uri="qemu:///system"
+fi
+LIBVIRT_URI=${uri}
+
+
+FLAG_WAIT="$((1<<0))"
+FLAG_VERBOSE="$((1<<2))"
+FLAG_LIBVIRT_TEST="$((1<<3))"
+FLAG_TAP_TEST="$((1<<4))"
+FLAG_FORCE_CLEAN="$((1<<5))"
+
+failctr=0
+passctr=0
+attachfailctr=0
+attachctr=0
+
+TAP_FAIL_LIST=""
+TAP_FAIL_CTR=0
+TAP_TOT_CTR=0
+
+function usage() {
+ local cmd="$0"
+cat<<EOF
+Usage: ${cmd} [--help|-h|-?] [--noattach] [--wait] [--verbose]
+ [--libvirt-test] [--tap-test]
+
+Options:
+ --help,-h,-? : Display this help screen.
+ --wait : Wait for the user to press the enter key once an error
+ was detected
+ --verbose : Verbose output
+ --libvirt-test : Use the libvirt test output format
+ --tap-test : TAP format output
+ --force : Allow the automatic cleaning of VMs and networks
+ previously created by the TCK test suite
+
+This test creates libvirt 'networks' and checks for expected results
+(iptables, running processes (dnsmasq)) using provided xml and data
+file respectively.
+EOF
+}
+
+
+function tap_fail() {
+ echo "not ok $1 - ${2:0:66}"
+ TAP_FAIL_LIST+="$1 "
+ ((TAP_FAIL_CTR++))
+ ((TAP_TOT_CTR++))
+}
+
+function tap_pass() {
+ echo "ok $1 - ${2:0:70}"
+ ((TAP_TOT_CTR++))
+}
+
+function tap_final() {
+ local okay
+
+ [ -n "${TAP_FAIL_LIST}" ]&& echo "FAILED tests ${TAP_FAIL_LIST}"
+
+ okay=`echo "($TAP_TOT_CTR-$TAP_FAIL_CTR)*100/$TAP_TOT_CTR" | bc -l`
+ echo "Failed ${TAP_FAIL_CTR}/${TAP_TOT_CTR} tests, ${okay:0:5}% okay"
+}
+
+# A wrapper for mktemp in case it does not exist
+# Echos the name of a temporary file.
+function mktmpfile() {
+ local tmp
+ type -P mktemp> /dev/null
+ if [ $? -eq 0 ]; then
+ tmp=$(mktemp -t nwfvmtest.XXXXXX)
+ echo ${tmp}
+ else
+ while :; do
+ tmp="/tmp/nwfvmtest.${RANDOM}"
+ if [ ! -f ${tmp} ]; then
+ touch ${tmp}
+ chmod 666 ${tmp}
+ echo ${tmp}
+ break
+ fi
+ done
+ fi
+ return 0
+}
+
+
+function checkExpectedOutput() {
+ local xmlfile="$1"
+ local datafile="$2"
+ local flags="$3"
+ local skipregex="$4"
+ local cmd line tmpfile tmpfile2 skip
+
+ tmpfile=`mktmpfile`
+ tmpfile2=`mktmpfile`
+
+ exec 4<${datafile}
+
+ read<&4
+ line="${REPLY}"
+
+ while [ "x${line}x" != "xx" ]; do
+ cmd=`echo ${line##\#}`
+
+ skip=0
+ if [ "x${skipregex}x" != "xx" ]; then
+ skip=`echo ${cmd} | grep -c -E ${skipregex}`
+ fi
+
+ eval ${cmd} 2>&1 | tee ${tmpfile} 1>/dev/null
+
+ rm ${tmpfile2} 2>/dev/null
+ touch ${tmpfile2}
+
+ while [ 1 ]; do
+ read<&4
+ line="${REPLY}"
+
+ if [ "${line:0:1}" == "#" ] || [ "x${line}x" == "xx" ]; then
+
+ if [ ${skip} -ne 0 ]; then
+ break
+ fi
+
+ diff ${tmpfile} ${tmpfile2}>/dev/null
+
+ if [ $? -ne 0 ]; then
+ if [ $((flags& FLAG_VERBOSE)) -ne 0 ]; then
+ echo "FAIL ${xmlfile} : ${cmd}"
+ diff ${tmpfile} ${tmpfile2}
+ fi
+ ((failctr++))
+ if [ $((flags& FLAG_WAIT)) -ne 0 ]; then
+ echo "tmp files: $tmpfile, $tmpfile2"
+ echo "Press enter"
+ read
+ fi
+ [ $((flags& FLAG_LIBVIRT_TEST)) -ne 0 ]&& \
+ test_result $((passctr+failctr)) "" 1
+ [ $((flags& FLAG_TAP_TEST)) -ne 0 ]&& \
+ tap_fail $((passctr+failctr)) "${xmlfile} : ${cmd}"
+ else
+ ((passctr++))
+ [ $((flags& FLAG_VERBOSE)) -ne 0 ]&& \
+ echo "PASS ${xmlfile} : ${cmd}"
+ [ $((flags& FLAG_LIBVIRT_TEST)) -ne 0 ]&& \
+ test_result $((passctr+failctr)) "" 0
+ [ $((flags& FLAG_TAP_TEST)) -ne 0 ]&& \
+ tap_pass $((passctr+failctr)) "${xmlfile} : ${cmd}"
+ fi
+
+ break
+
+ fi
+ echo "${line}">> ${tmpfile2}
+ done
+ done
+
+ exec 4>&-
+
+ rm -rf "${tmpfile}" "${tmpfile2}" 2>/dev/null
+}
+
+
+function doTest() {
+ local xmlfile="$1"
+ local datafile="$2"
+ local postdatafile="$3"
+ local flags="$4"
+ local netname
+
+ if [ ! -r "${xmlfile}" ]; then
+ echo "FAIL : Cannot access filter XML file ${xmlfile}."
+ return 1
+ fi
+
+ netname=`cat "${xmlfile}" | sed -n 's/.*<name>\([[:print:]]*\)<.*/\1/p'`
+
+ ${VIRSH} net-create "${xmlfile}"> /dev/null
+
+ checkExpectedOutput "${xmlfile}" "${datafile}" "${flags}" ""
+
+ ${VIRSH} net-destroy "${netname}"> /dev/null
+
+ if [ -r ${postdatafile} ]; then
+ checkExpectedOutput "${xmlfile}" "${postdatafile}" "${flags}" ""
+ fi
+
+ return 0
+}
+
+
+function runTests() {
+ local xmldir="$1"
+ local hostoutdir="$2"
+ local flags="$3"
+ local datafiles f c
+ local tap_total=0 ctr=0
+
+ pushd ${PWD}> /dev/null
+ cd ${hostoutdir}
+ datafiles=`ls *.dat`
+ popd> /dev/null
+
+ if [ $((flags& FLAG_TAP_TEST)) -ne 0 ]; then
+ # Need to count the number of total tests
+ for fil in ${datafiles}; do
+ c=$(grep -c "^#" ${hostoutdir}/${fil})
+ ((tap_total+=c))
+ ((ctr++))
+ done
+ echo "1..${tap_total}"
+ fi
+
+ for fil in `echo "${datafiles}" | grep -v "\.post\.dat$"`; do
+ f=${fil%%.dat}
+ doTest "${xmldir}/${f}.xml" "${hostoutdir}/${fil}" \
+ "${hostoutdir}/${f}.post.dat" "${flags}"
+ done
+
+ if [ $((flags& FLAG_LIBVIRT_TEST)) -ne 0 ]; then
+ test_final $((passctr+failctr)) $failctr
+ elif [ $((flags& FLAG_TAP_TEST)) -ne 0 ]; then
+ tap_final
+ else
+ echo ""
+ echo "Summary: ${failctr} failures, ${passctr} passes,"
+ if [ ${attachctr} -ne 0 ]; then
+ echo " ${attachfailctr} interface attachment failures with ${attachctr} attempts"
+ fi
+ fi
+}
+
+
+function main() {
+ local prgname="$0"
+ local vm1 vm2
+ local xmldir="networkxml2xmlin"
+ local hostoutdir="networkxml2hostout"
+ local res rc
+ local flags
+
+ while [ $# -ne 0 ]; do
+ case "$1" in
+ --help|-h|-\?) usage ${prgname}; exit 0;;
+ --wait) ((flags |= FLAG_WAIT ));;
+ --verbose) ((flags |= FLAG_VERBOSE ));;
+ --libvirt-test) ((flags |= FLAG_LIBVIRT_TEST ));;
+ --tap-test) ((flags |= FLAG_TAP_TEST ));;
+ --force) ((flags |= FLAG_FORCE_CLEAN ));;
+ *) usage ${prgname}; exit 1;;
+ esac
+ shift 1
+ done
+
+ if [ `uname` != "Linux" ]; then
+ if [ $((flags& FLAG_TAP_TEST)) -ne 0 ]; then
+ echo "1..0 # Skipped: Only valid on Linux hosts"
+ else
+ echo "This script will only run on Linux."
+ fi
+ exit 1;
+ fi
+
+ if [ $((flags& FLAG_TAP_TEST)) -ne 0 ]; then
+ if [ "${LIBVIRT_URI}" != "qemu:///system" ]; then
+ echo "1..0 # Skipped: Only valid for Qemu system driver"
+ exit 0
+ fi
+
+ for name in `virsh list | awk '{print $2}'`
+ do
+ case ${name} in
+ tck*)
+ if [ "x${LIBVIRT_TCK_AUTOCLEAN}" == "x1" -o \
+ $((flags& FLAG_FORCE_CLEAN)) -ne 0 ]; then
+ res=$(virsh destroy ${name} 2>&1)
+ res=$(virsh undefine ${name} 2>&1)
+ if [ $? -ne 0 ]; then
+ echo "Bail out! Could not undefine VM ${name}: ${res}"
+ exit 0
+ fi
+ else
+ echo "Bail out! TCK VMs from previous tests still exist, use --force to clean"
+ exit 1
+ fi
+ esac
+ done
+
+ for name in `virsh net-list | sed -n '3,$p'`
+ do
+ case ${name} in
+ tck*)
+ if [ "x${LIBVIRT_TCK_AUTOCLEAN}" == "x1" -o \
+ $((flags& FLAG_FORCE_CLEAN)) -ne 0 ]; then
+ res=$(virsh net-destroy ${name} 2>&1)
+ rc=$?
+ res=$(virsh net-undefine ${name} 2>&1)
+ if [ $rc -ne 0 -a $? -ne 0 ]; then
+ echo "Bail out! Could not destroy/undefine network ${name}: ${res}"
+ exit 1
+ fi
+ else
+ echo "Bail out! Network ${name} already exists, use --force to clean"
+ exit 1
+ fi
+ esac
+ done
+ fi
+
+ if [ $((flags& FLAG_LIBVIRT_TEST)) -ne 0 ]; then
+ pushd ${PWD}> /dev/null
+ . test-lib.sh
+ if [ $? -ne 0 ]; then
+ exit 1
+ fi
+ test_intro $this_test
+ popd> /dev/null
+ fi
+
+ res=$(${VIRSH} capabilities 2>&1)
+
+ runTests "${xmldir}" "${hostoutdir}" "${flags}"
+
+ return 0
+}
+
+main "$@"
Index: libvirt-tck/scripts/networks/networkxml2hostout/tck-testnet-1.dat
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/networks/networkxml2hostout/tck-testnet-1.dat
@@ -0,0 +1,17 @@
+#iptables -t nat -L -n | grep 10.1.2
+MASQUERADE tcp -- 10.1.2.0/24 !10.1.2.0/24 masq ports: 1024-65535
+MASQUERADE udp -- 10.1.2.0/24 !10.1.2.0/24 masq ports: 1024-65535
+MASQUERADE all -- 10.1.2.0/24 !10.1.2.0/24
+#iptables -n -L FORWARD | grep 10.1.2
+ACCEPT all -- 0.0.0.0/0 10.1.2.0/24 state RELATED,ESTABLISHED
+ACCEPT all -- 10.1.2.0/24 0.0.0.0/0
+#ps aux | grep dnsmasq | grep 10.1.2 | sed -n 's/.*\\(dnsmasq[[:print:]*]\\)/\\1/p'
+dnsmasq --strict-order --bind-interfaces --pid-file=/var/run/libvirt/network/tck-testnet.pid --conf-file= --listen-address 10.1.2.1 --except-interface lo --dhcp-range 10.1.2.2,10.1.2.254 --dhcp-lease-max=253 --dhcp-no-override
+#route -n | grep 10.1.2
+10.1.2.0 0.0.0.0 255.255.255.0 U 0 0 0 tck-testbr
+#brctl show | grep tck-testbr
+tck-testbr 8000.000000000000 yes
+#ifconfig tck-testbr | grep 10.1.2
+ inet addr:10.1.2.1 Bcast:10.1.2.255 Mask:255.255.255.0
+#virsh net-list | grep tck-testnet
+tck-testnet active no
Index: libvirt-tck/scripts/networks/networkxml2xmlin/tck-testnet-1.xml
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/networks/networkxml2xmlin/tck-testnet-1.xml
@@ -0,0 +1,12 @@
+<network>
+<name>tck-testnet</name>
+<uuid>aadc8920-502a-4774-ac2b-cd382a204d06</uuid>
+<forward mode='nat'/>
+<bridge name='tck-testbr' stp='on' delay='0' />
+<ip address='10.1.2.1' netmask='255.255.255.0'>
+<dhcp>
+<range start='10.1.2.2' end='10.1.2.254' />
+</dhcp>
+</ip>
+</network>
+
Index: libvirt-tck/scripts/networks/networkxml2hostout/tck-testnet-2.dat
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/networks/networkxml2hostout/tck-testnet-2.dat
@@ -0,0 +1,14 @@
+#iptables -L FORWARD -n | grep 10.1.2
+ACCEPT all -- 0.0.0.0/0 10.1.2.0/24
+ACCEPT all -- 10.1.2.0/24 0.0.0.0/0
+#iptables -t nat -L -n | grep 10.1.2
+#ps aux | grep dnsmasq | grep 10.1.2 | sed -n 's/.*\\(dnsmasq[[:print:]*]\\)/\\1/p'
+dnsmasq --strict-order --bind-interfaces --pid-file=/var/run/libvirt/network/tck-testnet.pid --conf-file= --listen-address 10.1.2.1 --except-interface lo --dhcp-range 10.1.2.2,10.1.2.254 --dhcp-lease-max=253 --dhcp-no-override
+#route -n | grep 10.1.2
+10.1.2.0 0.0.0.0 255.255.255.0 U 0 0 0 tck-testbr
+#brctl show | grep tck-testbr
+tck-testbr 8000.000000000000 yes
+#ifconfig tck-testbr | grep 10.1.2
+ inet addr:10.1.2.1 Bcast:10.1.2.255 Mask:255.255.255.0
+#virsh net-list | grep tck-testnet
+tck-testnet active no
Index: libvirt-tck/scripts/networks/networkxml2xmlin/tck-testnet-2.xml
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/networks/networkxml2xmlin/tck-testnet-2.xml
@@ -0,0 +1,12 @@
+<network>
+<name>tck-testnet</name>
+<uuid>aadc8920-502a-4774-ac2b-cd382a204d06</uuid>
+<forward mode='route'/>
+<bridge name='tck-testbr' stp='on' delay='0' />
+<ip address='10.1.2.1' netmask='255.255.255.0'>
+<dhcp>
+<range start='10.1.2.2' end='10.1.2.254' />
+</dhcp>
+</ip>
+</network>
+
Index: libvirt-tck/scripts/networks/100-apply-verify-host.t
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/networks/100-apply-verify-host.t
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+pwd=$(dirname $0)
+
+pushd ${PWD}> /dev/null
+
+cd ${pwd}
+bash ./networkApplyTest.sh --tap-test
+
+popd> /dev/null
Index: libvirt-tck/scripts/networks/networkxml2hostout/tck-testnet-1.post.dat
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/networks/networkxml2hostout/tck-testnet-1.post.dat
@@ -0,0 +1,7 @@
+#iptables -t nat -L -n | grep 10.1.2
+#iptables -n -L FORWARD | grep 10.1.2
+#ps aux | grep dnsmasq | grep 10.1.2 | sed -n 's/.*\\(dnsmasq[[:print:]*]\\)/\\1/p'
+#route -n | grep 10.1.2
+#brctl show | grep tck-testbr
+#ifconfig tck-testbr 2>/dev/null| grep 10.1.2
+#virsh net-list | grep tck-testnet
Index: libvirt-tck/scripts/networks/networkxml2hostout/tck-testnet-2.post.dat
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/networks/networkxml2hostout/tck-testnet-2.post.dat
@@ -0,0 +1,7 @@
+#iptables -t nat -L -n | grep 10.1.2
+#iptables -n -L FORWARD | grep 10.1.2
+#ps aux | grep dnsmasq | grep 10.1.2 | sed -n 's/.*\\(dnsmasq[[:print:]*]\\)/\\1/p'
+#route -n | grep 10.1.2
+#brctl show | grep tck-testbr
+#ifconfig tck-testbr 2>/dev/null | grep 10.1.2
+#virsh net-list | grep tck-testnet
Index: libvirt-tck/Build.PL
===================================================================
--- libvirt-tck.orig/Build.PL
+++ libvirt-tck/Build.PL
@@ -29,7 +29,7 @@ sub process_pkgdata_files {
my $name = $File::Find::name;
if (-d) {
$tck_dirs{$name} = [];
- } elsif (-f&& (/\.t$/ || /\.sh$/ || /\.fwall$/ || /\.xml$/)) {
+ } elsif (-f&& /\.(t|sh|fwall|xml|dat)$/) {
push @{$tck_dirs{$dir}}, $name;
}
};
14 years, 1 month
[libvirt] [PATCH v2] bye to close(), welcome to VIR_(FORCE_)CLOSE()
by Stefan Berger
V2:
- forgot to convert close ( occurrences (with whitespace)
- following Eric's and Laine's comments
Diff between (tree+V1, tree+v2) is at the end of the email.
Using automated replacement with sed and editing I have now replaced all
occurrences of close() with VIR_(FORCE_)CLOSE() except for one, of
course. Some replacements were straight forward, others I needed to pay
attention. I hope I payed attention in all the right places... Please
have a look. This should have at least solved one more double-close
error.
---
daemon/libvirtd.c | 48 ++++++---------
proxy/libvirt_proxy.c | 16 ++---
src/libvirt.c | 10 +--
src/lxc/lxc_container.c | 13 ++--
src/lxc/lxc_controller.c | 27 +++-----
src/lxc/lxc_driver.c | 25 +++----
src/node_device/node_device_linux_sysfs.c | 5 -
src/nwfilter/nwfilter_ebiptables_driver.c | 8 +-
src/openvz/openvz_conf.c | 35 ++++-------
src/openvz/openvz_driver.c | 3
src/phyp/phyp_driver.c | 19 ++++--
src/qemu/qemu_conf.c | 30 ++++-----
src/qemu/qemu_driver.c | 94 ++++++++++++------------------
src/qemu/qemu_monitor.c | 3
src/remote/remote_driver.c | 34 ++++------
src/secret/secret_driver.c | 12 +--
src/security/security_apparmor.c | 9 +-
src/security/security_selinux.c | 9 +-
src/security/virt-aa-helper.c | 9 +-
src/storage/storage_backend.c | 27 +++-----
src/storage/storage_backend_fs.c | 11 +--
src/storage/storage_backend_iscsi.c | 5 -
src/storage/storage_backend_logical.c | 10 +--
src/storage/storage_backend_mpath.c | 5 -
src/storage/storage_backend_scsi.c | 8 +-
src/storage/storage_driver.c | 5 -
src/test/test_driver.c | 20 ++----
src/uml/uml_conf.c | 3
src/uml/uml_driver.c | 24 +++----
src/util/bridge.c | 14 ++--
src/util/conf.c | 3
src/util/hooks.c | 21 ++----
src/util/interface.c | 12 +--
src/util/logging.c | 6 -
src/util/macvtap.c | 11 +--
src/util/pci.c | 6 -
src/util/storage_file.c | 5 -
src/util/util.c | 71 ++++++++++------------
src/util/uuid.c | 9 +-
src/util/virtaudit.c | 3
src/xen/proxy_internal.c | 14 ++--
src/xen/xen_hypervisor.c | 12 +--
src/xen/xen_inotify.c | 3
src/xen/xend_internal.c | 17 ++---
tests/testutils.c | 19 +++---
tools/console.c | 3
46 files changed, 354 insertions(+), 402 deletions(-)
Index: libvirt-acl/src/libvirt.c
===================================================================
--- libvirt-acl.orig/src/libvirt.c
+++ libvirt-acl/src/libvirt.c
@@ -10794,7 +10794,7 @@ virStreamRef(virStreamPtr stream)
* ... report an error ....
* done:
* virStreamFree(st);
- * close(fd);
+ * VIR_FORCE_CLOSE(fd);
*
* Returns the number of bytes written, which may be less
* than requested.
@@ -10884,8 +10884,8 @@ error:
* ... report an error ....
* done:
* virStreamFree(st);
- * close(fd);
- *
+ * if (VIR_CLOSE(fd) < 0)
+ * virReportSystemError(errno, _("failed to close file"));
*
* Returns the number of bytes read, which may be less
* than requested.
@@ -10964,7 +10964,7 @@ error:
* if (virStreamFinish(st) < 0)
* ...report an error...
* virStreamFree(st);
- * close(fd);
+ * VIR_FORCE_CLOSE(fd);
*
* Returns 0 if all the data was successfully sent. The caller
* should invoke virStreamFinish(st) to flush the stream upon
@@ -11061,7 +11061,7 @@ cleanup:
* if (virStreamFinish(st) < 0)
* ...report an error...
* virStreamFree(st);
- * close(fd);
+ * VIR_FORCE_CLOSE(fd);
*
* Returns 0 if all the data was successfully received. The caller
* should invoke virStreamFinish(st) to flush the stream upon
Index: libvirt-acl/src/lxc/lxc_container.c
===================================================================
--- libvirt-acl.orig/src/lxc/lxc_container.c
+++ libvirt-acl/src/lxc/lxc_container.c
@@ -52,6 +52,7 @@
#include "util.h"
#include "memory.h"
#include "veth.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -145,8 +146,10 @@ static int lxcContainerSetStdio(int cont
* close all FDs before executing the container */
open_max = sysconf (_SC_OPEN_MAX);
for (i = 0; i < open_max; i++)
- if (i != ttyfd && i != control)
- close(i);
+ if (i != ttyfd && i != control) {
+ int tmpfd = i;
+ VIR_FORCE_CLOSE(tmpfd);
+ }
if (dup2(ttyfd, 0) < 0) {
virReportSystemError(errno, "%s",
@@ -222,7 +225,7 @@ static int lxcContainerWaitForContinue(i
_("Failed to read the container continue message"));
return -1;
}
- close(control);
+ VIR_FORCE_CLOSE(control);
DEBUG0("Received container continue message");
@@ -776,10 +779,10 @@ static int lxcContainerChild( void *data
VIR_FREE(ttyPath);
if (lxcContainerSetStdio(argv->monitor, ttyfd) < 0) {
- close(ttyfd);
+ VIR_FORCE_CLOSE(ttyfd);
return -1;
}
- close(ttyfd);
+ VIR_FORCE_CLOSE(ttyfd);
if (lxcContainerSetupMounts(vmDef, root) < 0)
return -1;
Index: libvirt-acl/src/lxc/lxc_controller.c
===================================================================
--- libvirt-acl.orig/src/lxc/lxc_controller.c
+++ libvirt-acl/src/lxc/lxc_controller.c
@@ -48,6 +48,7 @@
#include "veth.h"
#include "memory.h"
#include "util.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -233,8 +234,7 @@ static int lxcMonitorServer(const char *
return fd;
error:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -409,7 +409,7 @@ static int lxcControllerMain(int monitor
goto cleanup;
}
if (client != -1) { /* Already connected, so kick new one out */
- close(fd);
+ VIR_FORCE_CLOSE(fd);
continue;
}
client = fd;
@@ -426,8 +426,7 @@ static int lxcControllerMain(int monitor
_("epoll_ctl(client) failed"));
goto cleanup;
}
- close(client);
- client = -1;
+ VIR_FORCE_CLOSE(client);
} else {
if (epollEvent.events & EPOLLIN) {
curFdOff = epollEvent.data.fd == appPty ? 0 : 1;
@@ -485,9 +484,9 @@ static int lxcControllerMain(int monitor
rc = 0;
cleanup:
- close(appPty);
- close(contPty);
- close(epollFd);
+ VIR_FORCE_CLOSE(appPty);
+ VIR_FORCE_CLOSE(contPty);
+ VIR_FORCE_CLOSE(epollFd);
return rc;
}
@@ -660,8 +659,7 @@ lxcControllerRun(virDomainDefPtr def,
control[1],
containerPtyPath)) < 0)
goto cleanup;
- close(control[1]);
- control[1] = -1;
+ VIR_FORCE_CLOSE(control[1]);
if (lxcControllerMoveInterfaces(nveths, veths, container) < 0)
goto cleanup;
@@ -679,13 +677,10 @@ lxcControllerRun(virDomainDefPtr def,
cleanup:
VIR_FREE(devptmx);
VIR_FREE(devpts);
- if (control[0] != -1)
- close(control[0]);
- if (control[1] != -1)
- close(control[1]);
+ VIR_FORCE_CLOSE(control[0]);
+ VIR_FORCE_CLOSE(control[1]);
VIR_FREE(containerPtyPath);
- if (containerPty != -1)
- close(containerPty);
+ VIR_FORCE_CLOSE(containerPty);
if (container > 1) {
int status;
Index: libvirt-acl/src/lxc/lxc_driver.c
===================================================================
--- libvirt-acl.orig/src/lxc/lxc_driver.c
+++ libvirt-acl/src/lxc/lxc_driver.c
@@ -51,6 +51,7 @@
#include "uuid.h"
#include "stats_linux.h"
#include "hooks.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -974,7 +975,7 @@ static int lxcVmCleanup(lxc_driver_t *dr
}
virEventRemoveHandle(priv->monitorWatch);
- close(priv->monitor);
+ VIR_FORCE_CLOSE(priv->monitor);
virFileDeletePid(driver->stateDir, vm->def->name);
virDomainDeleteConfig(driver->stateDir, NULL, vm);
@@ -1156,8 +1157,7 @@ static int lxcMonitorClient(lxc_driver_t
error:
VIR_FREE(sockpath);
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -1544,14 +1544,11 @@ cleanup:
vethDelete(veths[i]);
VIR_FREE(veths[i]);
}
- if (rc != 0 && priv->monitor != -1) {
- close(priv->monitor);
- priv->monitor = -1;
- }
- if (parentTty != -1)
- close(parentTty);
- if (logfd != -1)
- close(logfd);
+ if (rc != 0)
+ VIR_FORCE_CLOSE(priv->monitor);
+ VIR_FORCE_CLOSE(parentTty);
+ if (VIR_CLOSE(logfd) < 0)
+ virReportSystemError(errno, "%s", _("could not close logfile"));
VIR_FREE(logfile);
return rc;
}
@@ -2011,8 +2008,7 @@ lxcReconnectVM(void *payload, const char
/* Read pid from controller */
if ((virFileReadPid(lxc_driver->stateDir, vm->def->name, &vm->pid)) != 0) {
- close(priv->monitor);
- priv->monitor = -1;
+ VIR_FORCE_CLOSE(priv->monitor);
goto cleanup;
}
@@ -2042,8 +2038,7 @@ lxcReconnectVM(void *payload, const char
}
} else {
vm->def->id = -1;
- close(priv->monitor);
- priv->monitor = -1;
+ VIR_FORCE_CLOSE(priv->monitor);
}
cleanup:
Index: libvirt-acl/src/node_device/node_device_linux_sysfs.c
===================================================================
--- libvirt-acl.orig/src/node_device/node_device_linux_sysfs.c
+++ libvirt-acl/src/node_device/node_device_linux_sysfs.c
@@ -31,6 +31,7 @@
#include "virterror_internal.h"
#include "memory.h"
#include "logging.h"
+#include "files.h"
#include <dirent.h>
#define VIR_FROM_THIS VIR_FROM_NODEDEV
@@ -104,9 +105,7 @@ int read_wwn_linux(int host, const char
}
out:
- if (fd != -1) {
- close(fd);
- }
+ VIR_FORCE_CLOSE(fd);
return retval;
}
Index: libvirt-acl/src/nwfilter/nwfilter_ebiptables_driver.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_ebiptables_driver.c
+++ libvirt-acl/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -37,6 +37,7 @@
#include "nwfilter_conf.h"
#include "nwfilter_gentech_driver.h"
#include "nwfilter_ebiptables_driver.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_NWFILTER
@@ -2493,13 +2494,12 @@ ebiptablesWriteToTempFile(const char *st
}
VIR_FREE(header);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return filnam;
err_exit:
VIR_FREE(header);
- if (fd >= 0)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
unlink(filename);
return NULL;
}
@@ -3259,7 +3259,7 @@ iptablesCheckBridgeNFCallEnabled(bool is
lastReport = now;
}
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
}
}
}
Index: libvirt-acl/src/openvz/openvz_conf.c
===================================================================
--- libvirt-acl.orig/src/openvz/openvz_conf.c
+++ libvirt-acl/src/openvz/openvz_conf.c
@@ -50,6 +50,7 @@
#include "memory.h"
#include "util.h"
#include "nodeinfo.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_OPENVZ
@@ -109,7 +110,7 @@ openvzExtractVersionInfo(const char *cmd
cleanup2:
VIR_FREE(help);
- if (close(newstdout) < 0)
+ if (VIR_CLOSE(newstdout) < 0)
ret = -1;
rewait:
@@ -569,7 +570,7 @@ openvzWriteConfigParam(const char * conf
goto error;
temp_fd = open(temp_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (temp_fd == -1) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
goto error;
}
@@ -590,12 +591,10 @@ openvzWriteConfigParam(const char * conf
safewrite(temp_fd, "\"\n", 2) < 0)
goto error;
- if (close(fd) < 0)
+ if (VIR_CLOSE(fd) < 0)
goto error;
- fd = -1;
- if (close(temp_fd) < 0)
+ if (VIR_CLOSE(temp_fd) < 0)
goto error;
- temp_fd = -1;
if (rename(temp_file, conf_file) < 0)
goto error;
@@ -603,10 +602,8 @@ openvzWriteConfigParam(const char * conf
return 0;
error:
- if (fd != -1)
- close(fd);
- if (temp_fd != -1)
- close(temp_fd);
+ VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_CLOSE(temp_fd);
if (temp_file)
unlink(temp_file);
VIR_FREE(temp_file);
@@ -662,7 +659,7 @@ openvzReadConfigParam(const char * conf_
}
}
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (ret == 0 && found)
ret = 1;
@@ -703,7 +700,7 @@ openvz_copyfile(char* from_path, char* t
return -1;
copy_fd = open(to_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (copy_fd == -1) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -716,19 +713,16 @@ openvz_copyfile(char* from_path, char* t
goto error;
}
- if (close(fd) < 0)
+ if (VIR_CLOSE(fd) < 0)
goto error;
- fd = -1;
- if (close(copy_fd) < 0)
+ if (VIR_CLOSE(copy_fd) < 0)
goto error;
return 0;
error:
- if (fd != -1)
- close(fd);
- if (copy_fd != -1)
- close(copy_fd);
+ VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_CLOSE(copy_fd);
return -1;
}
@@ -880,8 +874,7 @@ openvzGetVPSUUID(int vpsid, char *uuidst
}
retval = 0;
cleanup:
- if (fd >= 0)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
VIR_FREE(conf_file);
return retval;
Index: libvirt-acl/src/openvz/openvz_driver.c
===================================================================
--- libvirt-acl.orig/src/openvz/openvz_driver.c
+++ libvirt-acl/src/openvz/openvz_driver.c
@@ -57,6 +57,7 @@
#include "nodeinfo.h"
#include "memory.h"
#include "bridge.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_OPENVZ
@@ -1540,7 +1541,7 @@ Version: 2.2
}
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (ret < 0)
return -1;
Index: libvirt-acl/src/phyp/phyp_driver.c
===================================================================
--- libvirt-acl.orig/src/phyp/phyp_driver.c
+++ libvirt-acl/src/phyp/phyp_driver.c
@@ -58,6 +58,7 @@
#include "domain_conf.h"
#include "storage_conf.h"
#include "nodeinfo.h"
+#include "files.h"
#include "phyp_driver.h"
@@ -457,11 +458,15 @@ phypUUIDTable_WriteFile(virConnectPtr co
}
}
- close(fd);
+ if (VIR_CLOSE(fd) < 0)
+ virReportSystemError(errno, _("Could not close %s\n"),
+ local_file);
return 0;
err:
- close(fd);
+ if (VIR_CLOSE(fd) < 0)
+ virReportSystemError(errno, _("Could not close %s\n"),
+ local_file);
return -1;
}
@@ -672,11 +677,11 @@ phypUUIDTable_ReadFile(virConnectPtr con
} else
virReportOOMError();
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return 0;
err:
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -764,7 +769,9 @@ phypUUIDTable_Pull(virConnectPtr conn)
}
break;
}
- close(fd);
+ if (VIR_CLOSE(fd) < 0)
+ virReportSystemError(errno, _("Could not close %s\n"),
+ local_file);
goto exit;
exit:
@@ -1001,7 +1008,7 @@ openSSHSession(virConnectPtr conn, virCo
if (connect(sock, cur->ai_addr, cur->ai_addrlen) == 0) {
goto connected;
}
- close(sock);
+ VIR_FORCE_CLOSE(sock);
}
cur = cur->ai_next;
}
Index: libvirt-acl/src/qemu/qemu_conf.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_conf.c
+++ libvirt-acl/src/qemu/qemu_conf.c
@@ -55,6 +55,7 @@
#include "macvtap.h"
#include "cpu/cpu.h"
#include "domain_nwfilter.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -530,7 +531,7 @@ qemudProbeMachineTypes(const char *binar
cleanup2:
VIR_FREE(output);
cleanup:
- if (close(newstdout) < 0)
+ if (VIR_CLOSE(newstdout) < 0)
ret = -1;
rewait:
@@ -780,7 +781,7 @@ qemudProbeCPUModels(const char *qemu,
cleanup:
VIR_FREE(output);
- if (close(newstdout) < 0)
+ if (VIR_CLOSE(newstdout) < 0)
ret = -1;
rewait:
@@ -1421,7 +1422,7 @@ static void qemudParsePCIDeviceStrs(cons
cleanup:
VIR_FREE(pciassign);
- close(newstderr);
+ VIR_FORCE_CLOSE(newstderr);
rewait:
if (waitpid(child, &status, 0) != child) {
if (errno == EINTR)
@@ -1481,7 +1482,7 @@ int qemudExtractVersionInfo(const char *
cleanup2:
VIR_FREE(help);
- if (close(newstdout) < 0)
+ if (VIR_CLOSE(newstdout) < 0)
ret = -1;
rewait:
@@ -1596,8 +1597,7 @@ qemudPhysIfaceConnect(virConnectPtr conn
if ((net->filter) && (net->ifname)) {
err = virDomainConfNWFilterInstantiate(conn, net);
if (err) {
- close(rc);
- rc = -1;
+ VIR_FORCE_CLOSE(rc);
delMacvtap(net->ifname, net->mac, net->data.direct.linkdev,
&net->data.direct.virtPortProfile);
VIR_FREE(net->ifname);
@@ -1742,10 +1742,8 @@ qemudNetworkIfaceConnect(virConnectPtr c
if (tapfd >= 0) {
if ((net->filter) && (net->ifname)) {
err = virDomainConfNWFilterInstantiate(conn, net);
- if (err) {
- close(tapfd);
- tapfd = -1;
- }
+ if (err)
+ VIR_FORCE_CLOSE(tapfd);
}
}
@@ -4557,7 +4555,7 @@ int qemudBuildCommandLine(virConnectPtr
if (VIR_REALLOC_N(*vmfds, (*nvmfds)+1) < 0) {
virDomainConfNWFilterTeardown(net);
- close(tapfd);
+ VIR_FORCE_CLOSE(tapfd);
goto no_memory;
}
@@ -4576,7 +4574,7 @@ int qemudBuildCommandLine(virConnectPtr
if (VIR_REALLOC_N(*vmfds, (*nvmfds)+1) < 0) {
virDomainConfNWFilterTeardown(net);
- close(tapfd);
+ VIR_FORCE_CLOSE(tapfd);
goto no_memory;
}
@@ -4596,7 +4594,7 @@ int qemudBuildCommandLine(virConnectPtr
int vhostfd = qemudOpenVhostNet(net, qemuCmdFlags);
if (vhostfd >= 0) {
if (VIR_REALLOC_N(*vmfds, (*nvmfds)+1) < 0) {
- close(vhostfd);
+ VIR_FORCE_CLOSE(vhostfd);
goto no_memory;
}
@@ -5096,14 +5094,14 @@ int qemudBuildCommandLine(virConnectPtr
if (configfd >= 0) {
if (virAsprintf(&configfd_name, "%d", configfd) < 0) {
- close(configfd);
+ VIR_FORCE_CLOSE(configfd);
virReportOOMError();
goto no_memory;
}
if (VIR_REALLOC_N(*vmfds, (*nvmfds)+1) < 0) {
VIR_FREE(configfd_name);
- close(configfd);
+ VIR_FORCE_CLOSE(configfd);
goto no_memory;
}
@@ -5196,7 +5194,7 @@ int qemudBuildCommandLine(virConnectPtr
if (vmfds &&
*vmfds) {
for (i = 0; i < *nvmfds; i++)
- close((*vmfds)[i]);
+ VIR_FORCE_CLOSE((*vmfds)[i]);
VIR_FREE(*vmfds);
*nvmfds = 0;
}
Index: libvirt-acl/src/qemu/qemu_driver.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_driver.c
+++ libvirt-acl/src/qemu/qemu_driver.c
@@ -81,6 +81,7 @@
#include "hooks.h"
#include "storage_file.h"
#include "virtaudit.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -761,7 +762,7 @@ qemudLogFD(struct qemud_driver *driver,
if (virSetCloseExec(fd) < 0) {
virReportSystemError(errno, "%s",
_("Unable to set VM logfile close-on-exec flag"));
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
return fd;
@@ -793,14 +794,14 @@ qemudLogReadFD(const char* logDir, const
if (virSetCloseExec(fd) < 0) {
virReportSystemError(errno, "%s",
_("Unable to set VM logfile close-on-exec flag"));
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
if (pos < 0 || lseek(fd, pos, SEEK_SET) < 0) {
- virReportSystemError(pos < 0 ? 0 : errno,
+ virReportSystemError(pos < 0 ? 0 : errno,
_("Unable to seek to %lld in %s"),
(long long) pos, logfile);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
}
return fd;
}
@@ -2392,7 +2393,7 @@ cleanup:
}
closelog:
- if (close(logfd) < 0) {
+ if (VIR_CLOSE(logfd) < 0) {
char ebuf[4096];
VIR_WARN("Unable to close logfile: %s",
virStrerror(errno, ebuf, sizeof ebuf));
@@ -2971,13 +2972,13 @@ static int qemudNextFreeVNCPort(struct q
return -1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void*)&reuse, sizeof(reuse)) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
break;
}
if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == 0) {
/* Not in use, lets grab it */
- close(fd);
+ VIR_FORCE_CLOSE(fd);
/* Add port to bitmap of reserved ports */
if (virBitmapSetBit(driver->reservedVNCPorts,
i - QEMU_VNC_PORT_MIN) < 0) {
@@ -2986,7 +2987,7 @@ static int qemudNextFreeVNCPort(struct q
}
return i;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (errno == EADDRINUSE) {
/* In use, try next */
@@ -3238,7 +3239,7 @@ qemuPrepareChardevDevice(virDomainDefPtr
return -1;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return 0;
}
@@ -3955,7 +3956,7 @@ static int qemudStartVMDaemon(virConnect
if (vmfds) {
for (i = 0 ; i < nvmfds ; i++) {
- close(vmfds[i]);
+ VIR_FORCE_CLOSE(vmfds[i]);
}
VIR_FREE(vmfds);
}
@@ -4008,8 +4009,7 @@ static int qemudStartVMDaemon(virConnect
if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0)
goto cleanup;
- if (logfile != -1)
- close(logfile);
+ VIR_FORCE_CLOSE(logfile);
return 0;
@@ -4019,8 +4019,7 @@ cleanup:
* pretend we never started it */
qemudShutdownVMDaemon(driver, vm, 0);
- if (logfile != -1)
- close(logfile);
+ VIR_FORCE_CLOSE(logfile);
return -1;
}
@@ -4295,7 +4294,7 @@ static int kvmGetMaxVCPUs(void) {
if (r > 0)
maxvcpus = r;
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return maxvcpus;
}
@@ -5397,10 +5396,10 @@ static int qemudDomainSaveFlag(struct qe
goto endjob;
}
if (qemudDomainSaveFileOpHook(fd, &hdata) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
goto endjob;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno, _("unable to close %s"), path);
goto endjob;
}
@@ -5796,7 +5795,7 @@ static int qemudDomainCoreDump(virDomain
goto endjob;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("unable to save file %s"),
path);
@@ -6424,8 +6423,7 @@ static int qemudOpenAsUID(const char *pa
/* parent */
/* parent doesn't need the write side of the pipe */
- close(pipefd[1]);
- pipefd[1] = -1;
+ VIR_FORCE_CLOSE(pipefd[1]);
if (forkRet < 0) {
virReportSystemError(errno,
@@ -6437,10 +6435,8 @@ static int qemudOpenAsUID(const char *pa
fd = pipefd[0];
pipefd[0] = -1;
parent_cleanup:
- if (pipefd[0] != -1)
- close(pipefd[0]);
- if (pipefd[1] != -1)
- close(pipefd[1]);
+ VIR_FORCE_CLOSE(pipefd[0]);
+ VIR_FORCE_CLOSE(pipefd[1]);
if ((fd < 0) && (*child_pid > 0)) {
/* a child process was started and subsequently an error
occurred in the parent, so we need to wait for it to
@@ -6466,7 +6462,7 @@ parent_cleanup:
struct passwd pwd, *pwd_result;
/* child doesn't need the read side of the pipe */
- close(pipefd[0]);
+ VIR_FORCE_CLOSE(pipefd[0]);
if (forkRet < 0) {
exit_code = errno;
@@ -6531,10 +6527,8 @@ parent_cleanup:
child_cleanup:
VIR_FREE(buf);
- if (fd != -1)
- close(fd);
- if (pipefd[1] != -1)
- close(pipefd[1]);
+ VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_CLOSE(pipefd[1]);
_exit(exit_code);
}
@@ -6542,8 +6536,10 @@ static int qemudDomainSaveImageClose(int
{
int ret = 0;
- if (fd != -1)
- close(fd);
+ if (VIR_CLOSE(fd) < 0) {
+ virReportSystemError(errno, "%s",
+ _("cannot close file"));
+ }
if (read_pid != -1) {
/* reap the process that read the file */
@@ -6699,8 +6695,7 @@ qemudDomainSaveImageStartVM(virConnectPt
/* empty */
}
}
- if (intermediatefd != -1)
- close(intermediatefd);
+ VIR_FORCE_CLOSE(intermediatefd);
wait_ret = qemudDomainSaveImageClose(fd, read_pid, &status);
fd = -1;
@@ -8065,9 +8060,7 @@ static int qemudDomainAttachNetDevice(vi
}
qemuDomainObjExitMonitorWithDriver(driver, vm);
- if (tapfd != -1)
- close(tapfd);
- tapfd = -1;
+ VIR_FORCE_CLOSE(tapfd);
if (!virDomainObjIsActive(vm)) {
qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -8117,8 +8110,7 @@ cleanup:
VIR_FREE(nicstr);
VIR_FREE(netstr);
VIR_FREE(tapfd_name);
- if (tapfd != -1)
- close(tapfd);
+ VIR_FORCE_CLOSE(tapfd);
return ret;
@@ -8247,8 +8239,7 @@ static int qemudDomainAttachHostPciDevic
VIR_FREE(devstr);
VIR_FREE(configfd_name);
- if (configfd >= 0)
- close(configfd);
+ VIR_FORCE_CLOSE(configfd);
return 0;
@@ -8262,8 +8253,7 @@ error:
VIR_FREE(devstr);
VIR_FREE(configfd_name);
- if (configfd >= 0)
- close(configfd);
+ VIR_FORCE_CLOSE(configfd);
return -1;
}
@@ -10115,8 +10105,7 @@ qemudDomainBlockPeek (virDomainPtr dom,
}
cleanup:
- if (fd >= 0)
- close (fd);
+ VIR_FORCE_CLOSE(fd);
if (vm)
virDomainObjUnlock(vm);
return ret;
@@ -10203,7 +10192,7 @@ endjob:
cleanup:
VIR_FREE(tmp);
- if (fd >= 0) close (fd);
+ VIR_FORCE_CLOSE(fd);
unlink (tmp);
if (vm)
virDomainObjUnlock(vm);
@@ -10357,8 +10346,7 @@ static int qemuDomainGetBlockInfo(virDom
}
cleanup:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (vm)
virDomainObjUnlock(vm);
return ret;
@@ -10673,8 +10661,7 @@ cleanup:
static void qemuStreamMigFree(struct qemuStreamMigFile *qemust)
{
- if (qemust->fd != -1)
- close(qemust->fd);
+ VIR_FORCE_CLOSE(qemust->fd);
VIR_FREE(qemust);
}
@@ -11510,10 +11497,8 @@ finish:
qemuDomainObjExitRemoteWithDriver(driver, vm);
cleanup:
- if (client_sock != -1)
- close(client_sock);
- if (qemu_sock != -1)
- close(qemu_sock);
+ VIR_FORCE_CLOSE(client_sock);
+ VIR_FORCE_CLOSE(qemu_sock);
if (ddomain)
virUnrefDomain(ddomain);
@@ -12292,8 +12277,7 @@ cleanup:
VIR_FREE(snapFile);
VIR_FREE(snapDir);
VIR_FREE(newxml);
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
Index: libvirt-acl/src/qemu/qemu_monitor.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_monitor.c
+++ libvirt-acl/src/qemu/qemu_monitor.c
@@ -36,6 +36,7 @@
#include "virterror_internal.h"
#include "memory.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -283,7 +284,7 @@ qemuMonitorOpenUnix(const char *monitor)
return monfd;
error:
- close(monfd);
+ VIR_FORCE_CLOSE(monfd);
return -1;
}
Index: libvirt-acl/src/remote/remote_driver.c
===================================================================
--- libvirt-acl.orig/src/remote/remote_driver.c
+++ libvirt-acl/src/remote/remote_driver.c
@@ -82,6 +82,7 @@
#include "util.h"
#include "event.h"
#include "ignore-value.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_REMOTE
@@ -621,7 +622,7 @@ doRemoteOpen (virConnectPtr conn,
if (connect (priv->sock, r->ai_addr, r->ai_addrlen) == -1) {
saved_errno = errno;
- close (priv->sock);
+ VIR_FORCE_CLOSE(priv->sock);
continue;
}
@@ -630,8 +631,7 @@ doRemoteOpen (virConnectPtr conn,
negotiate_gnutls_on_connection
(conn, priv, no_verify);
if (!priv->session) {
- close (priv->sock);
- priv->sock = -1;
+ VIR_FORCE_CLOSE(priv->sock);
goto failed;
}
}
@@ -711,8 +711,7 @@ doRemoteOpen (virConnectPtr conn,
if (errno == ECONNREFUSED &&
flags & VIR_DRV_OPEN_REMOTE_AUTOSTART &&
trials < 20) {
- close(priv->sock);
- priv->sock = -1;
+ VIR_FORCE_CLOSE(priv->sock);
if (trials > 0 ||
remoteForkDaemon() == 0) {
trials++;
@@ -806,8 +805,8 @@ doRemoteOpen (virConnectPtr conn,
goto failed;
/* Parent continues here. */
- close (sv[1]);
- close (errfd[1]);
+ VIR_FORCE_CLOSE(sv[1]);
+ VIR_FORCE_CLOSE(errfd[1]);
priv->sock = sv[0];
priv->errfd = errfd[0];
priv->pid = pid;
@@ -955,15 +954,14 @@ doRemoteOpen (virConnectPtr conn,
failed:
/* Close the socket if we failed. */
- if (priv->errfd >= 0)
- close(priv->errfd);
+ VIR_FORCE_CLOSE(priv->errfd);
if (priv->sock >= 0) {
if (priv->uses_tls && priv->session) {
gnutls_bye (priv->session, GNUTLS_SHUT_RDWR);
gnutls_deinit (priv->session);
}
- close (priv->sock);
+ VIR_FORCE_CLOSE(priv->sock);
#ifndef WIN32
if (priv->pid > 0) {
pid_t reap;
@@ -977,10 +975,8 @@ retry:
#endif
}
- if (wakeupFD[0] >= 0) {
- close(wakeupFD[0]);
- close(wakeupFD[1]);
- }
+ VIR_FORCE_CLOSE(wakeupFD[0]);
+ VIR_FORCE_CLOSE(wakeupFD[1]);
VIR_FREE(priv->hostname);
goto cleanup;
@@ -1442,8 +1438,8 @@ doRemoteClose (virConnectPtr conn, struc
if (priv->saslconn)
sasl_dispose (&priv->saslconn);
#endif
- close (priv->sock);
- close (priv->errfd);
+ VIR_FORCE_CLOSE(priv->sock);
+ VIR_FORCE_CLOSE(priv->errfd);
#ifndef WIN32
if (priv->pid > 0) {
@@ -1456,10 +1452,8 @@ retry:
} while (reap != -1 && reap != priv->pid);
}
#endif
- if (priv->wakeupReadFD >= 0) {
- close(priv->wakeupReadFD);
- close(priv->wakeupSendFD);
- }
+ VIR_FORCE_CLOSE(priv->wakeupReadFD);
+ VIR_FORCE_CLOSE(priv->wakeupSendFD);
/* Free hostname copy */
Index: libvirt-acl/src/secret/secret_driver.c
===================================================================
--- libvirt-acl.orig/src/secret/secret_driver.c
+++ libvirt-acl/src/secret/secret_driver.c
@@ -41,6 +41,7 @@
#include "util.h"
#include "uuid.h"
#include "virterror_internal.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_SECRET
@@ -181,7 +182,7 @@ replaceFile(const char *filename, void *
tmp_path);
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno, _("error closing '%s'"), tmp_path);
goto cleanup;
}
@@ -196,8 +197,7 @@ replaceFile(const char *filename, void *
ret = 0;
cleanup:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (tmp_path != NULL) {
unlink(tmp_path);
VIR_FREE(tmp_path);
@@ -394,8 +394,7 @@ secretLoadValue(virSecretDriverStatePtr
virReportSystemError(errno, _("cannot read '%s'"), filename);
goto cleanup;
}
- close(fd);
- fd = -1;
+ VIR_FORCE_CLOSE(fd);
if (!base64_decode_alloc(contents, st.st_size, &value, &value_size)) {
virSecretReportError(VIR_ERR_INTERNAL_ERROR,
@@ -422,8 +421,7 @@ cleanup:
memset(contents, 0, st.st_size);
VIR_FREE(contents);
}
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
VIR_FREE(filename);
return ret;
}
Index: libvirt-acl/src/security/security_apparmor.c
===================================================================
--- libvirt-acl.orig/src/security/security_apparmor.c
+++ libvirt-acl/src/security/security_apparmor.c
@@ -37,6 +37,7 @@
#include "uuid.h"
#include "pci.h"
#include "hostusb.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_SECURITY
#define SECURITY_APPARMOR_VOID_DOI "0"
@@ -215,7 +216,7 @@ load_profile(virSecurityDriverPtr drv,
virReportSystemError(errno, "%s", _("unable to write to pipe"));
goto clean;
}
- close(pipefd[1]);
+ VIR_FORCE_CLOSE(pipefd[1]);
rc = 0;
rewait:
@@ -233,10 +234,8 @@ load_profile(virSecurityDriverPtr drv,
clean:
VIR_FREE(xml);
- if (pipefd[0] > 0)
- close(pipefd[0]);
- if (pipefd[1] > 0)
- close(pipefd[1]);
+ VIR_FORCE_CLOSE(pipefd[0]);
+ VIR_FORCE_CLOSE(pipefd[1]);
return rc;
}
Index: libvirt-acl/src/security/security_selinux.c
===================================================================
--- libvirt-acl.orig/src/security/security_selinux.c
+++ libvirt-acl/src/security/security_selinux.c
@@ -30,6 +30,7 @@
#include "storage_file.h"
#include "uuid.h"
#include "virtaudit.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_SECURITY
@@ -122,10 +123,10 @@ SELinuxInitialize(void)
virReportSystemError(errno,
_("cannot read SELinux virtual domain context file %s"),
selinux_virtual_domain_context_path());
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
ptr = strchrnul(default_domain_context, '\n');
*ptr = '\0';
@@ -141,10 +142,10 @@ SELinuxInitialize(void)
virReportSystemError(errno,
_("cannot read SELinux virtual image context file %s"),
selinux_virtual_image_context_path());
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
ptr = strchrnul(default_image_context, '\n');
if (*ptr == '\n') {
Index: libvirt-acl/src/security/virt-aa-helper.c
===================================================================
--- libvirt-acl.orig/src/security/virt-aa-helper.c
+++ libvirt-acl/src/security/virt-aa-helper.c
@@ -37,6 +37,7 @@
#include "uuid.h"
#include "hostusb.h"
#include "pci.h"
+#include "files.h"
static char *progname;
@@ -278,12 +279,12 @@ update_include_file(const char *include_
}
if (safewrite(fd, pcontent, plen) < 0) { /* don't write the '\0' */
- close(fd);
+ VIR_FORCE_CLOSE(fd);
vah_error(NULL, 0, "failed to write to profile");
goto clean;
}
- if (close(fd) != 0) {
+ if (VIR_CLOSE(fd) != 0) {
vah_error(NULL, 0, "failed to close or write to profile");
goto clean;
}
@@ -385,12 +386,12 @@ create_profile(const char *profile, cons
}
if (safewrite(fd, pcontent, plen - 1) < 0) { /* don't write the '\0' */
- close(fd);
+ VIR_FORCE_CLOSE(fd);
vah_error(NULL, 0, "failed to write to profile");
goto clean_all;
}
- if (close(fd) != 0) {
+ if (VIR_CLOSE(fd) != 0) {
vah_error(NULL, 0, "failed to close or write to profile");
goto clean_all;
}
Index: libvirt-acl/src/storage/storage_backend.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend.c
+++ libvirt-acl/src/storage/storage_backend.c
@@ -51,6 +51,7 @@
#include "storage_file.h"
#include "storage_backend.h"
#include "logging.h"
+#include "files.h"
#if WITH_STORAGE_LVM
# include "storage_backend_logical.h"
@@ -181,7 +182,7 @@ virStorageBackendCopyToFD(virStorageVolD
} while ((amtleft -= 512) > 0);
}
- if (inputfd != -1 && close(inputfd) < 0) {
+ if (VIR_CLOSE(inputfd) < 0) {
ret = -errno;
virReportSystemError(errno,
_("cannot close file '%s'"),
@@ -193,8 +194,7 @@ virStorageBackendCopyToFD(virStorageVolD
*total -= remain;
cleanup:
- if (inputfd != -1)
- close(inputfd);
+ VIR_FORCE_CLOSE(inputfd);
VIR_FREE(buf);
@@ -251,7 +251,7 @@ virStorageBackendCreateBlockFrom(virConn
vol->target.path, vol->target.perms.mode);
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("cannot close file '%s'"),
vol->target.path);
@@ -261,8 +261,7 @@ virStorageBackendCreateBlockFrom(virConn
ret = 0;
cleanup:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
@@ -608,7 +607,7 @@ static int virStorageBackendQEMUImgBacki
cleanup:
VIR_FREE(help);
- close(newstdout);
+ VIR_FORCE_CLOSE(newstdout);
rewait:
if (child) {
if (waitpid(child, &status, 0) != child) {
@@ -997,7 +996,7 @@ virStorageBackendVolOpenCheckMode(const
virReportSystemError(errno,
_("cannot stat file '%s'"),
path);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -1009,7 +1008,7 @@ virStorageBackendVolOpenCheckMode(const
mode = VIR_STORAGE_VOL_OPEN_BLOCK;
if (!(mode & flags)) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (mode & VIR_STORAGE_VOL_OPEN_ERROR) {
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
@@ -1045,7 +1044,7 @@ virStorageBackendUpdateVolTargetInfo(vir
allocation,
capacity);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
@@ -1461,10 +1460,8 @@ virStorageBackendRunProgRegex(virStorage
if (list)
fclose(list);
- else {
- if (fd >= 0)
- close(fd);
- }
+ else
+ VIR_FORCE_CLOSE(fd);
while ((err = waitpid(child, &exitstatus, 0) == -1) && errno == EINTR);
@@ -1579,7 +1576,7 @@ virStorageBackendRunProgNul(virStoragePo
if (fp)
fclose (fp);
else
- close (fd);
+ VIR_FORCE_CLOSE(fd);
while ((w_err = waitpid (child, &exitstatus, 0) == -1) && errno == EINTR)
/* empty */ ;
Index: libvirt-acl/src/storage/storage_backend_fs.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_fs.c
+++ libvirt-acl/src/storage/storage_backend_fs.c
@@ -45,6 +45,7 @@
#include "util.h"
#include "memory.h"
#include "xml.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -72,25 +73,25 @@ virStorageBackendProbeTarget(virStorageV
if ((ret = virStorageBackendUpdateVolTargetInfoFD(target, fd,
allocation,
capacity)) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
memset(&meta, 0, sizeof(meta));
if ((target->format = virStorageFileProbeFormatFromFD(target->path, fd)) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
if (virStorageFileGetMetadataFromFD(target->path, fd,
target->format,
&meta) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (meta.backingStore) {
*backingStore = meta.backingStore;
@@ -98,7 +99,7 @@ virStorageBackendProbeTarget(virStorageV
if (meta.backingStoreFormat == VIR_STORAGE_FILE_AUTO) {
if ((*backingStoreFormat
= virStorageFileProbeFormat(*backingStore)) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
goto cleanup;
}
} else {
Index: libvirt-acl/src/storage/storage_backend_iscsi.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_iscsi.c
+++ libvirt-acl/src/storage/storage_backend_iscsi.c
@@ -41,6 +41,7 @@
#include "util.h"
#include "memory.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -237,9 +238,7 @@ out:
if (fp != NULL) {
fclose(fp);
} else {
- if (fd != -1) {
- close(fd);
- }
+ VIR_FORCE_CLOSE(fd);
}
return ret;
Index: libvirt-acl/src/storage/storage_backend_logical.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_logical.c
+++ libvirt-acl/src/storage/storage_backend_logical.c
@@ -37,6 +37,7 @@
#include "util.h"
#include "memory.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -408,10 +409,10 @@ virStorageBackendLogicalBuildPool(virCon
virReportSystemError(errno,
_("cannot clear device header of '%s'"),
pool->def->source.devices[i].path);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("cannot close device '%s'"),
pool->def->source.devices[i].path);
@@ -622,7 +623,7 @@ virStorageBackendLogicalCreateVol(virCon
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("cannot close file '%s'"),
vol->target.path);
@@ -641,8 +642,7 @@ virStorageBackendLogicalCreateVol(virCon
return 0;
cleanup:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
virStorageBackendLogicalDeleteVol(conn, pool, vol, 0);
return -1;
}
Index: libvirt-acl/src/storage/storage_backend_mpath.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_mpath.c
+++ libvirt-acl/src/storage/storage_backend_mpath.c
@@ -35,6 +35,7 @@
#include "storage_backend.h"
#include "memory.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -61,9 +62,7 @@ virStorageBackendMpathUpdateVolTargetInf
ret = 0;
out:
- if (fd != -1) {
- close(fd);
- }
+ VIR_FORCE_CLOSE(fd);
return ret;
}
Index: libvirt-acl/src/storage/storage_backend_scsi.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_scsi.c
+++ libvirt-acl/src/storage/storage_backend_scsi.c
@@ -32,6 +32,7 @@
#include "storage_backend_scsi.h"
#include "memory.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -154,8 +155,7 @@ virStorageBackendSCSIUpdateVolTargetInfo
ret = 0;
cleanup:
- if (fd >= 0)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
@@ -572,14 +572,14 @@ virStorageBackendSCSITriggerRescan(uint3
if (safewrite(fd,
LINUX_SYSFS_SCSI_HOST_SCAN_STRING,
sizeof(LINUX_SYSFS_SCSI_HOST_SCAN_STRING)) < 0) {
-
+ VIR_FORCE_CLOSE(fd);
virReportSystemError(errno,
_("Write to '%s' to trigger host scan failed"),
path);
retval = -1;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
free_path:
VIR_FREE(path);
out:
Index: libvirt-acl/src/storage/storage_driver.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_driver.c
+++ libvirt-acl/src/storage/storage_driver.c
@@ -45,6 +45,7 @@
#include "memory.h"
#include "storage_backend.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -1664,9 +1665,7 @@ storageVolumeWipeInternal(virStorageVolD
out:
VIR_FREE(writebuf);
- if (fd != -1) {
- close(fd);
- }
+ VIR_FORCE_CLOSE(fd);
return ret;
}
Index: libvirt-acl/src/test/test_driver.c
===================================================================
--- libvirt-acl.orig/src/test/test_driver.c
+++ libvirt-acl/src/test/test_driver.c
@@ -50,6 +50,7 @@
#include "xml.h"
#include "threads.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_TEST
@@ -788,8 +789,7 @@ static int testOpenFromFile(virConnectPt
_("Invalid XML in file '%s'"), file);
goto error;
}
- close(fd);
- fd = -1;
+ VIR_FORCE_CLOSE(fd);
root = xmlDocGetRootElement(xml);
if ((root == NULL) || (!xmlStrEqual(root->name, BAD_CAST "node"))) {
@@ -1101,8 +1101,7 @@ static int testOpenFromFile(virConnectPt
VIR_FREE(networks);
VIR_FREE(ifaces);
VIR_FREE(pools);
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
virDomainObjListDeinit(&privconn->domains);
virNetworkObjListFree(&privconn->networks);
virInterfaceObjListFree(&privconn->ifaces);
@@ -1752,7 +1751,7 @@ static int testDomainSave(virDomainPtr d
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("saving domain '%s' to '%s': write failed"),
domain->name, path);
@@ -1779,8 +1778,7 @@ cleanup:
* in either case we're already in a failure scenario
* and have reported a earlier error */
if (ret != 0) {
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
unlink(path);
}
if (privdom)
@@ -1870,8 +1868,7 @@ static int testDomainRestore(virConnectP
cleanup:
virDomainDefFree(def);
VIR_FREE(xml);
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (dom)
virDomainObjUnlock(dom);
if (event)
@@ -1911,7 +1908,7 @@ static int testDomainCoreDump(virDomainP
domain->name, to);
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("domain '%s' coredump: write failed: %s"),
domain->name, to);
@@ -1932,8 +1929,7 @@ static int testDomainCoreDump(virDomainP
ret = 0;
cleanup:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (privdom)
virDomainObjUnlock(privdom);
if (event)
Index: libvirt-acl/src/uml/uml_conf.c
===================================================================
--- libvirt-acl.orig/src/uml/uml_conf.c
+++ libvirt-acl/src/uml/uml_conf.c
@@ -47,6 +47,7 @@
#include "bridge.h"
#include "logging.h"
#include "domain_nwfilter.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_UML
@@ -367,7 +368,7 @@ umlBuildCommandLineChr(virDomainChrDefPt
}
if (virAsprintf(&ret, "%s%d=null,fd:%d", dev, def->target.port, fd_out) < 0) {
virReportOOMError();
- close(fd_out);
+ VIR_FORCE_CLOSE(fd_out);
return NULL;
}
FD_SET(fd_out, keepfd);
Index: libvirt-acl/src/uml/uml_driver.c
===================================================================
--- libvirt-acl.orig/src/uml/uml_driver.c
+++ libvirt-acl/src/uml/uml_driver.c
@@ -59,6 +59,7 @@
#include "datatypes.h"
#include "logging.h"
#include "domain_nwfilter.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_UML
@@ -533,7 +534,7 @@ umlShutdown(void) {
umlDriverLock(uml_driver);
if (uml_driver->inotifyWatch != -1)
virEventRemoveHandle(uml_driver->inotifyWatch);
- close(uml_driver->inotifyFD);
+ VIR_FORCE_CLOSE(uml_driver->inotifyFD);
virCapabilitiesFree(uml_driver->caps);
/* shutdown active VMs
@@ -659,8 +660,7 @@ restat:
if (bind(priv->monitor, (struct sockaddr *)&addr, sizeof addr) < 0) {
virReportSystemError(errno,
"%s", _("cannot bind socket"));
- close(priv->monitor);
- priv->monitor = -1;
+ VIR_FORCE_CLOSE(priv->monitor);
return -1;
}
@@ -870,13 +870,13 @@ static int umlStartVMDaemon(virConnectPt
if (umlSetCloseExec(logfd) < 0) {
virReportSystemError(errno,
"%s", _("Unable to set VM logfile close-on-exec flag"));
- close(logfd);
+ VIR_FORCE_CLOSE(logfd);
return -1;
}
if (umlBuildCommandLine(conn, driver, vm, &keepfd,
&argv, &progenv) < 0) {
- close(logfd);
+ VIR_FORCE_CLOSE(logfd);
virDomainConfVMNWFilterTeardown(vm);
umlCleanupTapDevices(conn, vm);
return -1;
@@ -912,15 +912,17 @@ static int umlStartVMDaemon(virConnectPt
-1, &logfd, &logfd,
VIR_EXEC_CLEAR_CAPS,
NULL, NULL, NULL);
- close(logfd);
+ VIR_FORCE_CLOSE(logfd);
/*
* At the moment, the only thing that populates keepfd is
* umlBuildCommandLineChr. We want to close every fd it opens.
*/
for (i = 0; i < FD_SETSIZE; i++)
- if (FD_ISSET(i, &keepfd))
- close(i);
+ if (FD_ISSET(i, &keepfd)) {
+ int tmpfd = i;
+ VIR_FORCE_CLOSE(tmpfd);
+ }
for (i = 0 ; argv[i] ; i++)
VIR_FREE(argv[i]);
@@ -957,9 +959,7 @@ static void umlShutdownVMDaemon(virConne
virKillProcess(vm->pid, SIGTERM);
- if (priv->monitor != -1)
- close(priv->monitor);
- priv->monitor = -1;
+ VIR_FORCE_CLOSE(priv->monitor);
if ((ret = waitpid(vm->pid, NULL, 0)) != vm->pid) {
VIR_WARN("Got unexpected pid %d != %d",
@@ -2088,7 +2088,7 @@ umlDomainBlockPeek (virDomainPtr dom,
}
cleanup:
- if (fd >= 0) close (fd);
+ VIR_FORCE_CLOSE(fd);
if (vm)
virDomainObjUnlock(vm);
return ret;
Index: libvirt-acl/src/util/bridge.c
===================================================================
--- libvirt-acl.orig/src/util/bridge.c
+++ libvirt-acl/src/util/bridge.c
@@ -24,6 +24,7 @@
#if defined(WITH_BRIDGE)
# include "bridge.h"
+# include "files.h"
# include <stdlib.h>
# include <stdio.h>
@@ -82,12 +83,12 @@ brInit(brControl **ctlp)
if ((flags = fcntl(fd, F_GETFD)) < 0 ||
fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
int err = errno;
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return err;
}
if (VIR_ALLOC(*ctlp) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ENOMEM;
}
@@ -108,8 +109,7 @@ brShutdown(brControl *ctl)
if (!ctl)
return;
- close(ctl->fd);
- ctl->fd = 0;
+ VIR_FORCE_CLOSE(ctl->fd);
VIR_FREE(ctl);
}
@@ -540,11 +540,11 @@ brAddTap(brControl *ctl,
if (tapfd)
*tapfd = fd;
else
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return 0;
error:
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return errno;
}
@@ -575,7 +575,7 @@ int brDeleteTap(brControl *ctl,
}
error:
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return errno;
}
Index: libvirt-acl/src/util/conf.c
===================================================================
--- libvirt-acl.orig/src/util/conf.c
+++ libvirt-acl/src/util/conf.c
@@ -24,6 +24,7 @@
#include "util.h"
#include "c-ctype.h"
#include "memory.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_CONF
@@ -954,7 +955,7 @@ virConfWriteFile(const char *filename, v
content = virBufferContentAndReset(&buf);
ret = safewrite(fd, content, use);
VIR_FREE(content);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (ret != (int)use) {
virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to save content"));
return -1;
Index: libvirt-acl/src/util/interface.c
===================================================================
--- libvirt-acl.orig/src/util/interface.c
+++ libvirt-acl/src/util/interface.c
@@ -39,6 +39,7 @@
#include "util.h"
#include "interface.h"
#include "virterror_internal.h"
+#include "files.h"
#define ifaceError(code, ...) \
virReportErrorHelper(NULL, VIR_FROM_NET, code, __FILE__, \
@@ -82,7 +83,7 @@ ifaceGetFlags(const char *ifname, short
*flags = ifr.ifr_flags;
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return rc;
}
@@ -161,7 +162,7 @@ static int chgIfaceFlags(const char *ifn
}
err_exit:
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return rc;
}
@@ -259,8 +260,7 @@ ifaceCheck(bool reportError, const char
}
err_exit:
- if (fd >= 0)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return rc;
}
@@ -326,7 +326,7 @@ ifaceGetIndex(bool reportError, const ch
}
err_exit:
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return rc;
}
@@ -373,7 +373,7 @@ ifaceGetVlanID(const char *vlanifname, i
*vlanid = vlanargs.u.VID;
err_exit:
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return rc;
}
Index: libvirt-acl/src/util/logging.c
===================================================================
--- libvirt-acl.orig/src/util/logging.c
+++ libvirt-acl/src/util/logging.c
@@ -40,6 +40,7 @@
#include "util.h"
#include "buf.h"
#include "threads.h"
+#include "files.h"
/*
* Macro used to format the message as a string in virLogMessage
@@ -603,8 +604,7 @@ static int virLogOutputToFd(const char *
static void virLogCloseFd(void *data) {
int fd = (long) data;
- if (fd >= 0)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
}
static int virLogAddOutputToStderr(int priority) {
@@ -622,7 +622,7 @@ static int virLogAddOutputToFile(int pri
return(-1);
if (virLogDefineOutput(virLogOutputToFd, virLogCloseFd, (void *)(long)fd,
priority, VIR_LOG_TO_FILE, file, 0) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return(-1);
}
return(0);
Index: libvirt-acl/src/util/macvtap.c
===================================================================
--- libvirt-acl.orig/src/util/macvtap.c
+++ libvirt-acl/src/util/macvtap.c
@@ -52,6 +52,7 @@
# include "conf/domain_conf.h"
# include "virterror_internal.h"
# include "uuid.h"
+# include "files.h"
# define VIR_FROM_THIS VIR_FROM_NET
@@ -94,7 +95,9 @@ static int nlOpen(void)
static void nlClose(int fd)
{
- close(fd);
+ if (VIR_CLOSE(fd) < 0)
+ virReportSystemError(errno,
+ "%s",_("cannot close netlink socket"));
}
@@ -689,8 +692,7 @@ create_name:
if (rc >= 0) {
if (configMacvtapTap(rc, vnet_hdr) < 0) {
- close(rc);
- rc = -1;
+ VIR_FORCE_CLOSE(rc); /* sets rc to -1 */
goto disassociate_exit;
}
*res_ifname = strdup(cr_ifname);
@@ -778,8 +780,7 @@ getLldpadPid(void) {
_("Error opening file %s"), LLDPAD_PID_FILE);
}
- if (fd >= 0)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return pid;
}
Index: libvirt-acl/src/util/pci.c
===================================================================
--- libvirt-acl.orig/src/util/pci.c
+++ libvirt-acl/src/util/pci.c
@@ -37,6 +37,7 @@
#include "memory.h"
#include "util.h"
#include "virterror_internal.h"
+#include "files.h"
/* avoid compilation breakage on some systems */
#ifndef MODPROBE
@@ -188,10 +189,7 @@ pciCloseConfig(pciDevice *dev)
if (!dev)
return;
- if (dev->fd >= 0) {
- close(dev->fd);
- dev->fd = -1;
- }
+ VIR_FORCE_CLOSE(dev->fd);
}
static int
Index: libvirt-acl/src/util/storage_file.c
===================================================================
--- libvirt-acl.orig/src/util/storage_file.c
+++ libvirt-acl/src/util/storage_file.c
@@ -36,6 +36,7 @@
#include "memory.h"
#include "virterror_internal.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -688,7 +689,7 @@ virStorageFileProbeFormat(const char *pa
ret = virStorageFileProbeFormatFromFD(path, fd);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
@@ -782,7 +783,7 @@ virStorageFileGetMetadata(const char *pa
ret = virStorageFileGetMetadataFromFD(path, fd, format, meta);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
Index: libvirt-acl/src/util/util.c
===================================================================
--- libvirt-acl.orig/src/util/util.c
+++ libvirt-acl/src/util/util.c
@@ -71,6 +71,7 @@
#include "memory.h"
#include "threads.h"
#include "verify.h"
+#include "files.h"
#ifndef NSIG
# define NSIG 32
@@ -461,6 +462,7 @@ __virExec(const char *const*argv,
int pipeerr[2] = {-1,-1};
int childout = -1;
int childerr = -1;
+ int tmpfd;
if ((null = open("/dev/null", O_RDONLY)) < 0) {
virReportSystemError(errno,
@@ -534,13 +536,13 @@ __virExec(const char *const*argv,
}
if (pid) { /* parent */
- close(null);
+ VIR_FORCE_CLOSE(null);
if (outfd && *outfd == -1) {
- close(pipeout[1]);
+ VIR_FORCE_CLOSE(pipeout[1]);
*outfd = pipeout[0];
}
if (errfd && *errfd == -1) {
- close(pipeerr[1]);
+ VIR_FORCE_CLOSE(pipeerr[1]);
*errfd = pipeerr[0];
}
@@ -568,8 +570,10 @@ __virExec(const char *const*argv,
i != childout &&
i != childerr &&
(!keepfd ||
- !FD_ISSET(i, keepfd)))
- close(i);
+ !FD_ISSET(i, keepfd))) {
+ tmpfd = i;
+ VIR_FORCE_CLOSE(tmpfd);
+ }
if (dup2(infd >= 0 ? infd : null, STDIN_FILENO) < 0) {
virReportSystemError(errno,
@@ -589,14 +593,15 @@ __virExec(const char *const*argv,
goto fork_error;
}
- if (infd > 0)
- close(infd);
- close(null);
- if (childout > 0)
- close(childout);
+ VIR_FORCE_CLOSE(infd);
+ VIR_FORCE_CLOSE(null);
+ tmpfd = childout; /* preserve childout value */
+ VIR_FORCE_CLOSE(tmpfd);
if (childerr > 0 &&
- childerr != childout)
- close(childerr);
+ childerr != childout) {
+ VIR_FORCE_CLOSE(childerr);
+ childout = -1;
+ }
/* Daemonize as late as possible, so the parent process can detect
* the above errors with wait* */
@@ -666,16 +671,11 @@ __virExec(const char *const*argv,
/* NB we don't virUtilError() on any failures here
because the code which jumped hre already raised
an error condition which we must not overwrite */
- if (pipeerr[0] > 0)
- close(pipeerr[0]);
- if (pipeerr[1] > 0)
- close(pipeerr[1]);
- if (pipeout[0] > 0)
- close(pipeout[0]);
- if (pipeout[1] > 0)
- close(pipeout[1]);
- if (null > 0)
- close(null);
+ VIR_FORCE_CLOSE(pipeerr[0]);
+ VIR_FORCE_CLOSE(pipeerr[1]);
+ VIR_FORCE_CLOSE(pipeout[0]);
+ VIR_FORCE_CLOSE(pipeout[1]);
+ VIR_FORCE_CLOSE(null);
return -1;
}
@@ -865,10 +865,8 @@ virRunWithHook(const char *const*argv,
VIR_FREE(outbuf);
VIR_FREE(errbuf);
VIR_FREE(argv_str);
- if (outfd != -1)
- close(outfd);
- if (errfd != -1)
- close(errfd);
+ VIR_FORCE_CLOSE(outfd);
+ VIR_FORCE_CLOSE(errfd);
return ret;
}
@@ -1099,7 +1097,7 @@ int virFileReadAll(const char *path, int
}
int len = virFileReadLimFD(fd, maxlen, buf);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (len < 0) {
virReportSystemError(errno, _("Failed to read file '%s'"), path);
return -1;
@@ -1120,13 +1118,13 @@ int virFileWriteStr(const char *path, co
if (safewrite(fd, str, strlen(str)) < 0) {
int saved_errno = errno;
- close (fd);
+ VIR_FORCE_CLOSE(fd);
errno = saved_errno;
return -1;
}
/* Use errno from failed close only if there was no write error. */
- if (close (fd) != 0)
+ if (VIR_CLOSE(fd) != 0)
return -1;
return 0;
@@ -1305,7 +1303,7 @@ static int virFileOperationNoFork(const
if ((hook) && ((ret = hook(fd, hookdata)) != 0)) {
goto error;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
ret = -errno;
virReportSystemError(errno, _("failed to close new file '%s'"),
path);
@@ -1314,8 +1312,7 @@ static int virFileOperationNoFork(const
}
fd = -1;
error:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
@@ -1466,7 +1463,7 @@ parenterror:
if ((hook) && ((ret = hook(fd, hookdata)) != 0)) {
goto childerror;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
ret = -errno;
virReportSystemError(errno, _("child failed to close new file '%s'"),
path);
@@ -1743,10 +1740,8 @@ int virFileOpenTtyAt(const char *ptmx,
rc = 0;
cleanup:
- if (rc != 0 &&
- *ttymaster != -1) {
- close(*ttymaster);
- }
+ if (rc != 0)
+ VIR_FORCE_CLOSE(*ttymaster);
return rc;
@@ -1812,7 +1807,7 @@ int virFileWritePidPath(const char *pidf
if (!(file = fdopen(fd, "w"))) {
rc = errno;
- close(fd);
+ VIR_FORCE_CLOSE(fd);
goto cleanup;
}
Index: libvirt-acl/src/util/uuid.c
===================================================================
--- libvirt-acl.orig/src/util/uuid.c
+++ libvirt-acl/src/util/uuid.c
@@ -39,6 +39,7 @@
#include "virterror_internal.h"
#include "logging.h"
#include "memory.h"
+#include "files.h"
#ifndef ENODATA
# define ENODATA EIO
@@ -61,7 +62,7 @@ virUUIDGenerateRandomBytes(unsigned char
if ((n = read(fd, buf, buflen)) <= 0) {
if (errno == EINTR)
continue;
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return n < 0 ? errno : ENODATA;
}
@@ -69,7 +70,7 @@ virUUIDGenerateRandomBytes(unsigned char
buflen -= n;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return 0;
}
@@ -240,10 +241,10 @@ getDMISystemUUID(char *uuid, int len)
int fd = open(paths[i], O_RDONLY);
if (fd > 0) {
if (saferead(fd, uuid, len) == len) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return 0;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
}
i++;
}
Index: libvirt-acl/src/util/virtaudit.c
===================================================================
--- libvirt-acl.orig/src/util/virtaudit.c
+++ libvirt-acl/src/util/virtaudit.c
@@ -30,6 +30,7 @@
#include "virterror_internal.h"
#include "logging.h"
#include "virtaudit.h"
+#include "files.h"
/* Provide the macros in case the header file is old.
FIXME: should be removed. */
@@ -133,6 +134,6 @@ void virAuditSend(const char *file ATTRI
void virAuditClose(void)
{
#if HAVE_AUDIT
- close(auditfd);
+ VIR_FORCE_CLOSE(auditfd);
#endif
}
Index: libvirt-acl/src/xen/proxy_internal.c
===================================================================
--- libvirt-acl.orig/src/xen/proxy_internal.c
+++ libvirt-acl/src/xen/proxy_internal.c
@@ -30,6 +30,7 @@
#include "util.h"
#include "xen_driver.h"
#include "memory.h"
+#include "files.h"
#define STANDALONE
@@ -196,7 +197,7 @@ retry:
addr.sun_family = AF_UNIX;
addr.sun_path[0] = '\0';
if (virStrcpy(&addr.sun_path[1], path, sizeof(addr.sun_path) - 1) == NULL) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -204,7 +205,7 @@ retry:
* now bind the socket to that address and listen on it
*/
if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (trials < 3) {
if (virProxyForkServer() < 0)
return(-1);
@@ -232,16 +233,17 @@ retry:
static int
virProxyCloseSocket(xenUnifiedPrivatePtr priv) {
int ret;
+ int tmpfd;
if (priv->proxy < 0)
return(-1);
- ret = close(priv->proxy);
+ tmpfd = priv->proxy;
+ ret = VIR_CLOSE(priv->proxy);
if (ret != 0)
- VIR_WARN("Failed to close socket %d", priv->proxy);
+ VIR_WARN("Failed to close socket %d", tmpfd);
else
- VIR_DEBUG("Closed socket %d", priv->proxy);
- priv->proxy = -1;
+ VIR_DEBUG("Closed socket %d", tmpfd);
return(ret);
}
Index: libvirt-acl/src/xen/xen_hypervisor.c
===================================================================
--- libvirt-acl.orig/src/xen/xen_hypervisor.c
+++ libvirt-acl/src/xen/xen_hypervisor.c
@@ -65,6 +65,7 @@
#include "buf.h"
#include "capabilities.h"
#include "memory.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_XEN
@@ -2036,7 +2037,7 @@ xenHypervisorInit(void)
hypervisor_version = -1;
virXenError(VIR_ERR_XEN_CALL, " ioctl %lu",
(unsigned long) IOCTL_PRIVCMD_HYPERCALL);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
in_init = 0;
return(-1);
@@ -2122,13 +2123,13 @@ xenHypervisorInit(void)
hypervisor_version = -1;
virXenError(VIR_ERR_XEN_CALL, " ioctl %lu",
(unsigned long)IOCTL_PRIVCMD_HYPERCALL);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
in_init = 0;
VIR_FREE(ipt);
return(-1);
done:
- close(fd);
+ VIR_FORCE_CLOSE(fd);
in_init = 0;
VIR_FREE(ipt);
return(0);
@@ -2191,7 +2192,7 @@ xenHypervisorClose(virConnectPtr conn)
if (priv->handle < 0)
return -1;
- ret = close(priv->handle);
+ ret = VIR_CLOSE(priv->handle);
if (ret < 0)
return (-1);
@@ -2396,8 +2397,7 @@ get_cpu_flags(virConnectPtr conn, const
ret = 1;
out:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
Index: libvirt-acl/src/xen/xen_inotify.c
===================================================================
--- libvirt-acl.orig/src/xen/xen_inotify.c
+++ libvirt-acl/src/xen/xen_inotify.c
@@ -39,6 +39,7 @@
#include "xend_internal.h"
#include "logging.h"
#include "uuid.h"
+#include "files.h"
#include "xm_internal.h" /* for xenXMDomainConfigParse */
@@ -483,7 +484,7 @@ xenInotifyClose(virConnectPtr conn)
if (priv->inotifyWatch != -1)
virEventRemoveHandle(priv->inotifyWatch);
- close(priv->inotifyFD);
+ VIR_FORCE_CLOSE(priv->inotifyFD);
return 0;
}
Index: libvirt-acl/src/xen/xend_internal.c
===================================================================
--- libvirt-acl.orig/src/xen/xend_internal.c
+++ libvirt-acl/src/xen/xend_internal.c
@@ -45,6 +45,7 @@
#include "xs_internal.h" /* To extract VNC port & Serial console TTY */
#include "memory.h"
#include "count-one-bits.h"
+#include "files.h"
/* required for cpumap_t */
#include <xen/dom0_ops.h>
@@ -118,7 +119,6 @@ static int
do_connect(virConnectPtr xend)
{
int s;
- int serrno;
int no_slow_start = 1;
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) xend->privateData;
@@ -137,10 +137,7 @@ do_connect(virConnectPtr xend)
if (connect(s, (struct sockaddr *)&priv->addr, priv->addrlen) == -1) {
- serrno = errno;
- close(s);
- errno = serrno;
- s = -1;
+ VIR_FORCE_CLOSE(s); /* preserves errno */
/*
* Connecting to XenD when privileged is mandatory, so log this
@@ -387,7 +384,7 @@ xend_get(virConnectPtr xend, const char
"Content-Type: application/x-www-form-urlencoded\r\n" "\r\n");
ret = xend_req(s, content);
- close(s);
+ VIR_FORCE_CLOSE(s);
if (((ret < 0) || (ret >= 300)) &&
((ret != 404) || (!STRPREFIX(path, "/xend/domain/")))) {
@@ -437,7 +434,7 @@ xend_post(virConnectPtr xend, const char
swrites(s, ops);
ret = xend_req(s, &err_buf);
- close(s);
+ VIR_FORCE_CLOSE(s);
if ((ret < 0) || (ret >= 300)) {
virXendError(VIR_ERR_POST_FAILED,
@@ -833,7 +830,7 @@ xenDaemonOpen_tcp(virConnectPtr conn, co
if (connect (sock, r->ai_addr, r->ai_addrlen) == -1) {
saved_errno = errno;
- close (sock);
+ VIR_FORCE_CLOSE(sock);
continue;
}
@@ -843,7 +840,7 @@ xenDaemonOpen_tcp(virConnectPtr conn, co
memcpy(&priv->addr,
r->ai_addr,
r->ai_addrlen);
- close(sock);
+ VIR_FORCE_CLOSE(sock);
break;
}
@@ -5153,7 +5150,7 @@ xenDaemonDomainBlockPeek (virDomainPtr d
ret = 0;
cleanup:
- if (fd >= 0) close (fd);
+ VIR_FORCE_CLOSE(fd);
sexpr_free(root);
virDomainDefFree(def);
return ret;
Index: libvirt-acl/daemon/libvirtd.c
===================================================================
--- libvirt-acl.orig/daemon/libvirtd.c
+++ libvirt-acl/daemon/libvirtd.c
@@ -50,6 +50,7 @@
#include "libvirt_internal.h"
#include "virterror_internal.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -425,7 +426,7 @@ static int daemonForkIntoBackground(void
int stdoutfd = -1;
int nextpid;
- close(statuspipe[0]);
+ VIR_FORCE_CLOSE(statuspipe[0]);
if ((stdinfd = open("/dev/null", O_RDONLY)) < 0)
goto cleanup;
@@ -437,12 +438,10 @@ static int daemonForkIntoBackground(void
goto cleanup;
if (dup2(stdoutfd, STDERR_FILENO) != STDERR_FILENO)
goto cleanup;
- if (close(stdinfd) < 0)
+ if (VIR_CLOSE(stdinfd) < 0)
goto cleanup;
- stdinfd = -1;
- if (close(stdoutfd) < 0)
+ if (VIR_CLOSE(stdoutfd) < 0)
goto cleanup;
- stdoutfd = -1;
if (setsid() < 0)
goto cleanup;
@@ -458,10 +457,8 @@ static int daemonForkIntoBackground(void
}
cleanup:
- if (stdoutfd != -1)
- close(stdoutfd);
- if (stdinfd != -1)
- close(stdinfd);
+ VIR_FORCE_CLOSE(stdoutfd);
+ VIR_FORCE_CLOSE(stdinfd);
return -1;
}
@@ -475,7 +472,7 @@ static int daemonForkIntoBackground(void
int ret;
char status;
- close(statuspipe[1]);
+ VIR_FORCE_CLOSE(statuspipe[1]);
/* We wait to make sure the first child forked successfully */
if ((got = waitpid(pid, &exitstatus, 0)) < 0 ||
@@ -518,7 +515,7 @@ static int qemudWritePidFile(const char
if (!(fh = fdopen(fd, "w"))) {
VIR_ERROR(_("Failed to fdopen pid file '%s' : %s"),
pidFile, virStrerror(errno, ebuf, sizeof ebuf));
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -610,8 +607,7 @@ static int qemudListenUnix(struct qemud_
return 0;
cleanup:
- if (sock->fd >= 0)
- close(sock->fd);
+ VIR_FORCE_CLOSE(sock->fd);
VIR_FREE(sock);
return -1;
}
@@ -665,7 +661,7 @@ remoteMakeSockets (int *fds, int max_fds
VIR_ERROR(_("bind: %s"), virStrerror (errno, ebuf, sizeof ebuf));
return -1;
}
- close (fds[*nfds_r]);
+ VIR_FORCE_CLOSE(fds[*nfds_r]);
} else {
++*nfds_r;
}
@@ -734,7 +730,7 @@ remoteListenTCP (struct qemud_server *se
cleanup:
for (i = 0; i < nfds; ++i)
- close(fds[i]);
+ VIR_FORCE_CLOSE(fds[i]);
return -1;
}
@@ -1483,7 +1479,7 @@ error:
VIR_FREE(client);
}
VIR_FREE(addrstr);
- close (fd);
+ VIR_FORCE_CLOSE(fd);
PROBE(CLIENT_DISCONNECT, "fd=%d", fd);
return -1;
}
@@ -1529,8 +1525,7 @@ void qemudDispatchClientFailure(struct q
}
if (client->fd != -1) {
PROBE(CLIENT_DISCONNECT, "fd=%d", client->fd);
- close(client->fd);
- client->fd = -1;
+ VIR_FORCE_CLOSE(client->fd);
}
VIR_FREE(client->addrstr);
}
@@ -2433,17 +2428,15 @@ static int qemudStartEventLoop(struct qe
static void qemudCleanup(struct qemud_server *server) {
struct qemud_socket *sock;
- if (server->sigread != -1)
- close(server->sigread);
- if (server->sigwrite != -1)
- close(server->sigwrite);
+ VIR_FORCE_CLOSE(server->sigread);
+ VIR_FORCE_CLOSE(server->sigwrite);
sock = server->sockets;
while (sock) {
struct qemud_socket *next = sock->next;
if (sock->watch)
virEventRemoveHandleImpl(sock->watch);
- close(sock->fd);
+ VIR_FORCE_CLOSE(sock->fd);
/* Unlink unix domain sockets which are not in
* the abstract namespace */
@@ -2999,8 +2992,8 @@ daemonSetupSignals(struct qemud_server *
return 0;
error:
- close(sigpipe[0]);
- close(sigpipe[1]);
+ VIR_FORCE_CLOSE(sigpipe[0]);
+ VIR_FORCE_CLOSE(sigpipe[1]);
return -1;
}
@@ -3257,8 +3250,7 @@ int main(int argc, char **argv) {
while (write(statuswrite, &status, 1) == -1 &&
errno == EINTR)
;
- close(statuswrite);
- statuswrite = -1;
+ VIR_FORCE_CLOSE(statuswrite);
}
/* Start the event loop in a background thread, since
@@ -3315,7 +3307,7 @@ error:
errno == EINTR)
;
}
- close(statuswrite);
+ VIR_FORCE_CLOSE(statuswrite);
}
if (server)
qemudCleanup(server);
Index: libvirt-acl/src/util/hooks.c
===================================================================
--- libvirt-acl.orig/src/util/hooks.c
+++ libvirt-acl/src/util/hooks.c
@@ -36,6 +36,7 @@
#include "conf/domain_conf.h"
#include "logging.h"
#include "memory.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_HOOK
@@ -368,7 +369,7 @@ virHookCall(int driver, const char *id,
}
ret = virExec(argv, env, NULL, &pid, pipefd[0], &outfd, &errfd,
VIR_EXEC_NONE | VIR_EXEC_NONBLOCK);
- if (close(pipefd[1]) < 0) {
+ if (VIR_CLOSE(pipefd[1]) < 0) {
virReportSystemError(errno, "%s",
_("unable to close pipe for hook input"));
}
@@ -418,17 +419,13 @@ virHookCall(int driver, const char *id,
}
cleanup:
- if (pipefd[0] >= 0) {
- if (close(pipefd[0]) < 0) {
- virReportSystemError(errno, "%s",
- _("unable to close pipe for hook input"));
- }
- }
- if (pipefd[1] >= 0) {
- if (close(pipefd[1]) < 0) {
- virReportSystemError(errno, "%s",
- _("unable to close pipe for hook input"));
- }
+ if (VIR_CLOSE(pipefd[0]) < 0) {
+ virReportSystemError(errno, "%s",
+ _("unable to close pipe for hook input"));
+ }
+ if (VIR_CLOSE(pipefd[1]) < 0) {
+ virReportSystemError(errno, "%s",
+ _("unable to close pipe for hook input"));
}
if (argv) {
for (i = 0 ; i < argc ; i++)
Index: libvirt-acl/tests/testutils.c
===================================================================
--- libvirt-acl.orig/tests/testutils.c
+++ libvirt-acl/tests/testutils.c
@@ -47,6 +47,8 @@
((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
+#include "files.h"
+
static unsigned int testDebug = -1;
static unsigned int testVerbose = -1;
@@ -222,8 +224,10 @@ void virtTestCaptureProgramExecChild(con
open_max = sysconf (_SC_OPEN_MAX);
for (i = 0; i < open_max; i++) {
if (i != stdinfd &&
- i != pipefd)
- close(i);
+ i != pipefd) {
+ int tmpfd = i;
+ VIR_FORCE_CLOSE(tmpfd);
+ }
}
if (dup2(stdinfd, STDIN_FILENO) != STDIN_FILENO)
@@ -237,8 +241,7 @@ void virtTestCaptureProgramExecChild(con
execve(argv[0], (char *const*)argv, (char *const*)env);
cleanup:
- if (stdinfd != -1)
- close(stdinfd);
+ VIR_FORCE_CLOSE(stdinfd);
}
int virtTestCaptureProgramOutput(const char *const argv[],
@@ -252,10 +255,10 @@ int virtTestCaptureProgramOutput(const c
int pid = fork();
switch (pid) {
case 0:
- close(pipefd[0]);
+ VIR_FORCE_CLOSE(pipefd[0]);
virtTestCaptureProgramExecChild(argv, pipefd[1]);
- close(pipefd[1]);
+ VIR_FORCE_CLOSE(pipefd[1]);
_exit(1);
case -1:
@@ -267,7 +270,7 @@ int virtTestCaptureProgramOutput(const c
int ret = -1;
int want = buflen-1;
- close(pipefd[1]);
+ VIR_FORCE_CLOSE(pipefd[1]);
while (want) {
if ((ret = read(pipefd[0], (*buf)+got, want)) <= 0)
@@ -275,7 +278,7 @@ int virtTestCaptureProgramOutput(const c
got += ret;
want -= ret;
}
- close(pipefd[0]);
+ VIR_FORCE_CLOSE(pipefd[0]);
if (!ret)
(*buf)[got] = '\0';
Index: libvirt-acl/proxy/libvirt_proxy.c
===================================================================
--- libvirt-acl.orig/proxy/libvirt_proxy.c
+++ libvirt-acl/proxy/libvirt_proxy.c
@@ -31,6 +31,7 @@
# include "xend_internal.h"
# include "xs_internal.h"
# include "xen_driver.h"
+# include "files.h"
static int fdServer = -1;
static int debug = 0;
@@ -133,10 +134,9 @@ proxyCloseUnixSocket(void) {
if (fdServer < 0)
return(0);
- ret = close(fdServer);
if (debug > 0)
fprintf(stderr, "closing unix socket %d: %d\n", fdServer, ret);
- fdServer = -1;
+ ret = VIR_CLOSE(fdServer);
pollInfos[0].fd = -1;
return(ret);
}
@@ -172,7 +172,7 @@ proxyListenUnixSocket(const char *path)
addr.sun_path[0] = '\0';
if (virStrcpy(&addr.sun_path[1], path, sizeof(addr.sun_path) - 1) == NULL) {
fprintf(stderr, "Path %s too long to fit into destination\n", path);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -181,12 +181,12 @@ proxyListenUnixSocket(const char *path)
*/
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
fprintf(stderr, "Failed to bind to socket %s\n", path);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return (-1);
}
if (listen(fd, 30 /* backlog */ ) < 0) {
fprintf(stderr, "Failed to listen to socket %s\n", path);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return (-1);
}
@@ -230,7 +230,7 @@ retry:
if (nbClients >= MAX_CLIENT) {
fprintf(stderr, "Too many client registered\n");
- close(client);
+ VIR_FORCE_CLOSE(client);
return(-1);
}
nbClients++;
@@ -260,7 +260,7 @@ static int
proxyCloseClientSocket(int nr) {
int ret;
- ret = close(pollInfos[nr].fd);
+ ret = VIR_CLOSE(pollInfos[nr].fd);
if (ret != 0)
fprintf(stderr, "Failed to close socket %d from client %d\n",
pollInfos[nr].fd, nr);
@@ -285,7 +285,7 @@ proxyCloseClientSockets(void) {
int i, ret;
for (i = 1;i <= nbClients;i++) {
- ret = close(pollInfos[i].fd);
+ ret = VIR_CLOSE(pollInfos[i].fd);
if (ret != 0)
fprintf(stderr, "Failed to close socket %d from client %d\n",
pollInfos[i].fd, i);
Index: libvirt-acl/tools/console.c
===================================================================
--- libvirt-acl.orig/tools/console.c
+++ libvirt-acl/tools/console.c
@@ -39,6 +39,7 @@
# include "internal.h"
# include "logging.h"
# include "util.h"
+# include "files.h"
/* ie Ctrl-] as per telnet */
# define CTRL_CLOSE_BRACKET '\35'
@@ -192,7 +193,7 @@ int vshRunConsole(const char *tty) {
tcsetattr(STDIN_FILENO, TCSAFLUSH, &ttyattr);
closetty:
- close(ttyfd);
+ VIR_FORCE_CLOSE(ttyfd);
return ret;
}
This is the diff between the V1 patch rebased to more recent tree and V2 patch applied to the same tree.
--- ../bak/libvirt-acl/daemon/libvirtd.c 2010-10-25 08:05:34.073376459 -0400
+++ daemon/libvirtd.c 2010-10-25 07:58:41.219366410 -0400
@@ -661,7 +661,7 @@
VIR_ERROR(_("bind: %s"), virStrerror (errno, ebuf, sizeof ebuf));
return -1;
}
- close (fds[*nfds_r]);
+ VIR_FORCE_CLOSE(fds[*nfds_r]);
} else {
++*nfds_r;
}
@@ -1479,7 +1479,7 @@
VIR_FREE(client);
}
VIR_FREE(addrstr);
- close (fd);
+ VIR_FORCE_CLOSE(fd);
PROBE(CLIENT_DISCONNECT, "fd=%d", fd);
return -1;
}
--- ../bak/libvirt-acl/src/libvirt.c 2010-10-25 08:05:11.956617043 -0400
+++ src/libvirt.c 2010-10-25 08:00:26.470626887 -0400
@@ -10884,8 +10884,8 @@
* ... report an error ....
* done:
* virStreamFree(st);
- * VIR_FORCE_CLOSE(fd);
- *
+ * if (VIR_CLOSE(fd) < 0)
+ * virReportSystemError(errno, "%s", _("failed to close file"));
*
* Returns the number of bytes read, which may be less
* than requested.
--- ../bak/libvirt-acl/src/lxc/lxc_container.c 2010-10-25 08:05:11.957617025 -0400
+++ src/lxc/lxc_container.c 2010-10-25 07:58:41.200616329 -0400
@@ -128,7 +128,7 @@
static int lxcContainerSetStdio(int control, int ttyfd)
{
int rc = -1;
- int open_max, i, tpmfd;
+ int open_max, i;
if (setsid() < 0) {
virReportSystemError(errno, "%s",
@@ -147,8 +147,8 @@
open_max = sysconf (_SC_OPEN_MAX);
for (i = 0; i < open_max; i++)
if (i != ttyfd && i != control) {
- tpmfd = i;
- VIR_FORCE_CLOSE(tpmfd);
+ int tmpfd = i;
+ VIR_FORCE_CLOSE(tmpfd);
}
if (dup2(ttyfd, 0) < 0) {
--- ../bak/libvirt-acl/src/lxc/lxc_driver.c 2010-10-25 08:05:11.958616635 -0400
+++ src/lxc/lxc_driver.c 2010-10-25 07:58:41.201616790 -0400
@@ -1547,7 +1547,8 @@
if (rc != 0)
VIR_FORCE_CLOSE(priv->monitor);
VIR_FORCE_CLOSE(parentTty);
- VIR_FORCE_CLOSE(logfd);
+ if (VIR_CLOSE(logfd) < 0)
+ virReportSystemError(errno, "%s", _("could not close logfile"));
VIR_FREE(logfile);
return rc;
}
--- ../bak/libvirt-acl/src/phyp/phyp_driver.c 2010-10-25 08:05:11.960366499 -0400
+++ src/phyp/phyp_driver.c 2010-10-25 07:58:41.203616607 -0400
@@ -458,11 +458,15 @@
}
}
- VIR_FORCE_CLOSE(fd);
+ if (VIR_CLOSE(fd) < 0)
+ virReportSystemError(errno, _("Could not close %s\n"),
+ local_file);
return 0;
err:
- VIR_FORCE_CLOSE(fd);
+ if (VIR_CLOSE(fd) < 0)
+ virReportSystemError(errno, _("Could not close %s\n"),
+ local_file);
return -1;
}
@@ -765,7 +769,9 @@
}
break;
}
- VIR_FORCE_CLOSE(fd);
+ if (VIR_CLOSE(fd) < 0)
+ virReportSystemError(errno, _("Could not close %s\n"),
+ local_file);
goto exit;
exit:
--- ../bak/libvirt-acl/src/qemu/qemu_driver.c 2010-10-25 08:05:11.964366399 -0400
+++ src/qemu/qemu_driver.c 2010-10-25 07:58:41.206616997 -0400
@@ -10105,8 +10105,7 @@
}
cleanup:
- if (fd >= 0)
- close (fd);
+ VIR_FORCE_CLOSE(fd);
if (vm)
virDomainObjUnlock(vm);
return ret;
@@ -10193,7 +10192,7 @@
cleanup:
VIR_FREE(tmp);
- if (fd >= 0) close (fd);
+ VIR_FORCE_CLOSE(fd);
unlink (tmp);
if (vm)
virDomainObjUnlock(vm);
--- ../bak/libvirt-acl/src/qemu/qemu_monitor.c 2010-10-25 08:05:11.964366399 -0400
+++ src/qemu/qemu_monitor.c 2010-10-25 07:58:41.207616319 -0400
@@ -695,7 +695,8 @@
if (!mon->closed) {
if (mon->watch)
virEventRemoveHandle(mon->watch);
- VIR_FORCE_CLOSE(mon->fd);
+ if (mon->fd != -1)
+ close(mon->fd);
/* NB: ordinarily one might immediately set mon->watch to -1
* and mon->fd to -1, but there may be a callback active
* that is still relying on these fields being valid. So
--- ../bak/libvirt-acl/src/remote/remote_driver.c 2010-10-25 08:05:11.966366690 -0400
+++ src/remote/remote_driver.c 2010-10-25 07:58:41.209367026 -0400
@@ -622,7 +622,7 @@
if (connect (priv->sock, r->ai_addr, r->ai_addrlen) == -1) {
saved_errno = errno;
- close (priv->sock);
+ VIR_FORCE_CLOSE(priv->sock);
continue;
}
@@ -631,8 +631,7 @@
negotiate_gnutls_on_connection
(conn, priv, no_verify);
if (!priv->session) {
- close (priv->sock);
- priv->sock = -1;
+ VIR_FORCE_CLOSE(priv->sock);
goto failed;
}
}
@@ -713,7 +712,6 @@
flags & VIR_DRV_OPEN_REMOTE_AUTOSTART &&
trials < 20) {
VIR_FORCE_CLOSE(priv->sock);
- priv->sock = -1;
if (trials > 0 ||
remoteForkDaemon() == 0) {
trials++;
@@ -807,8 +805,8 @@
goto failed;
/* Parent continues here. */
- close (sv[1]);
- close (errfd[1]);
+ VIR_FORCE_CLOSE(sv[1]);
+ VIR_FORCE_CLOSE(errfd[1]);
priv->sock = sv[0];
priv->errfd = errfd[0];
priv->pid = pid;
@@ -963,7 +961,7 @@
gnutls_bye (priv->session, GNUTLS_SHUT_RDWR);
gnutls_deinit (priv->session);
}
- close (priv->sock);
+ VIR_FORCE_CLOSE(priv->sock);
#ifndef WIN32
if (priv->pid > 0) {
pid_t reap;
@@ -1440,8 +1438,8 @@
if (priv->saslconn)
sasl_dispose (&priv->saslconn);
#endif
- close (priv->sock);
- close (priv->errfd);
+ VIR_FORCE_CLOSE(priv->sock);
+ VIR_FORCE_CLOSE(priv->errfd);
#ifndef WIN32
if (priv->pid > 0) {
--- ../bak/libvirt-acl/src/storage/storage_backend.c 2010-10-25 08:05:11.968366374 -0400
+++ src/storage/storage_backend.c 2010-10-25 07:58:41.210366504 -0400
@@ -1576,7 +1576,7 @@
if (fp)
fclose (fp);
else
- close (fd);
+ VIR_FORCE_CLOSE(fd);
while ((w_err = waitpid (child, &exitstatus, 0) == -1) && errno == EINTR)
/* empty */ ;
--- ../bak/libvirt-acl/src/uml/uml_driver.c 2010-10-25 08:05:11.971366403 -0400
+++ src/uml/uml_driver.c 2010-10-25 07:58:41.214366625 -0400
@@ -811,7 +811,7 @@
virDomainObjPtr vm) {
const char **argv = NULL, **tmp;
const char **progenv = NULL;
- int i, ret, tmpfd;
+ int i, ret;
pid_t pid;
char *logfile;
int logfd = -1;
@@ -920,7 +920,7 @@
*/
for (i = 0; i < FD_SETSIZE; i++)
if (FD_ISSET(i, &keepfd)) {
- tmpfd = i;
+ int tmpfd = i;
VIR_FORCE_CLOSE(tmpfd);
}
@@ -2088,7 +2088,7 @@
}
cleanup:
- if (fd >= 0) close (fd);
+ VIR_FORCE_CLOSE(fd);
if (vm)
virDomainObjUnlock(vm);
return ret;
--- ../bak/libvirt-acl/src/util/bridge.c 2010-10-25 08:05:11.971366403 -0400
+++ src/util/bridge.c 2010-10-25 07:58:41.214366625 -0400
@@ -110,7 +110,6 @@
return;
VIR_FORCE_CLOSE(ctl->fd);
- ctl->fd = 0;
VIR_FREE(ctl);
}
--- ../bak/libvirt-acl/src/util/macvtap.c 2010-10-25 08:05:11.972366517 -0400
+++ src/util/macvtap.c 2010-10-25 07:58:41.215366412 -0400
@@ -95,7 +95,9 @@
static void nlClose(int fd)
{
- VIR_FORCE_CLOSE(fd);
+ if (VIR_CLOSE(fd) < 0)
+ virReportSystemError(errno,
+ "%s",_("cannot close netlink socket"));
}
@@ -690,8 +692,7 @@
if (rc >= 0) {
if (configMacvtapTap(rc, vnet_hdr) < 0) {
- VIR_FORCE_CLOSE(rc);
- rc = -1;
+ VIR_FORCE_CLOSE(rc); /* sets rc to -1 */
goto disassociate_exit;
}
*res_ifname = strdup(cr_ifname);
--- ../bak/libvirt-acl/src/util/util.c 2010-10-25 08:05:11.973366471 -0400
+++ src/util/util.c 2010-10-25 07:58:41.216366619 -0400
@@ -1118,13 +1118,13 @@
if (safewrite(fd, str, strlen(str)) < 0) {
int saved_errno = errno;
- close (fd);
+ VIR_FORCE_CLOSE(fd);
errno = saved_errno;
return -1;
}
/* Use errno from failed close only if there was no write error. */
- if (close (fd) != 0)
+ if (VIR_CLOSE(fd) != 0)
return -1;
return 0;
--- ../bak/libvirt-acl/src/util/virtaudit.c 2010-10-25 08:05:11.974366438 -0400
+++ src/util/virtaudit.c 2010-10-25 07:58:41.216366619 -0400
@@ -134,6 +134,6 @@
void virAuditClose(void)
{
#if HAVE_AUDIT
- VIR_CLOSE(auditfd);
+ VIR_FORCE_CLOSE(auditfd);
#endif
}
--- ../bak/libvirt-acl/src/xen/proxy_internal.c 2010-10-25 08:05:11.974366438 -0400
+++ src/xen/proxy_internal.c 2010-10-25 07:58:41.216366619 -0400
@@ -233,15 +233,17 @@
static int
virProxyCloseSocket(xenUnifiedPrivatePtr priv) {
int ret;
+ int tmpfd;
if (priv->proxy < 0)
return(-1);
+ tmpfd = priv->proxy;
ret = VIR_CLOSE(priv->proxy);
if (ret != 0)
- VIR_WARN("Failed to close socket %d", priv->proxy);
+ VIR_WARN("Failed to close socket %d", tmpfd);
else
- VIR_DEBUG("Closed socket %d", priv->proxy);
+ VIR_DEBUG("Closed socket %d", tmpfd);
return(ret);
}
--- ../bak/libvirt-acl/src/xen/xend_internal.c 2010-10-25 08:05:11.976366405 -0400
+++ src/xen/xend_internal.c 2010-10-25 07:58:41.218366941 -0400
@@ -137,8 +137,7 @@
if (connect(s, (struct sockaddr *)&priv->addr, priv->addrlen) == -1) {
- VIR_FORCE_CLOSE(s);
- s = -1;
+ VIR_FORCE_CLOSE(s); /* preserves errno */
/*
* Connecting to XenD when privileged is mandatory, so log this
@@ -831,7 +830,7 @@
if (connect (sock, r->ai_addr, r->ai_addrlen) == -1) {
saved_errno = errno;
- close (sock);
+ VIR_FORCE_CLOSE(sock);
continue;
}
@@ -5151,7 +5150,7 @@
ret = 0;
cleanup:
- if (fd >= 0) close (fd);
+ VIR_FORCE_CLOSE(fd);
sexpr_free(root);
virDomainDefFree(def);
return ret;
--- ../bak/libvirt-acl/tests/testutils.c 2010-10-25 08:05:11.977367703 -0400
+++ tests/testutils.c 2010-10-25 07:58:41.219366410 -0400
@@ -207,7 +207,7 @@
static
void virtTestCaptureProgramExecChild(const char *const argv[],
int pipefd) {
- int i, tmpfd;
+ int i;
int open_max;
int stdinfd = -1;
const char *const env[] = {
@@ -225,7 +225,7 @@
for (i = 0; i < open_max; i++) {
if (i != stdinfd &&
i != pipefd) {
- tmpfd = i;
+ int tmpfd = i;
VIR_FORCE_CLOSE(tmpfd);
}
}
14 years, 1 month
[libvirt] [libvirt-tck 1/3] Correct typos in documents
by Osier Yang
* docs/intro.pod
* docs/writing-tests.pod
---
docs/intro.pod | 10 +++++-----
docs/writing-tests.pod | 8 ++++----
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/docs/intro.pod b/docs/intro.pod
index 5943f3b..3684d51 100644
--- a/docs/intro.pod
+++ b/docs/intro.pod
@@ -16,7 +16,7 @@
=head1 libvirt TCK: Technology Compatability Kit
The libvirt TCK provides a framework for performing testing
-of the integration bqetween libvirt drivers, the underlying virt
+of the integration between libvirt drivers, the underlying virt
hypervisor technology, related operating system services and system
configuration. The idea (and name) is motivated by the Java TCK
@@ -51,7 +51,7 @@ to determine the level of compatability of their platform, and
evaluate whether it will meet their needs, and get awareness of any
regressions that may have occurred since a previous test run
-In relation to other libvirt testing, the split of responsibiity
+In relation to other libvirt testing, the split of responsibility
will be
=over 4
@@ -131,7 +131,7 @@ These are all currently available within Fedora 11, and later
These modules are all well tested, actively maintained parts of
Perl / CPAN, so easily available for every other operating system
-in existance.
+in existence.
=head2 Overview of framework structure
@@ -238,7 +238,7 @@ update the 'ID' field in the virDomainPtr
=item *
-After destroying a active domain, the remote driver did not
+After destroying an active domain, the remote driver did not
update the 'ID' field in the virDomainPtr
=item *
@@ -340,7 +340,7 @@ vs a virtual root filesystem for containers
=item More helper XML helper modules
-Add helpers for building network, storage and inteface XML
+Add helpers for building network, storage and interface XML
configs
=item Broader host configuration
diff --git a/docs/writing-tests.pod b/docs/writing-tests.pod
index 5380f5d..3bc70b0 100644
--- a/docs/writing-tests.pod
+++ b/docs/writing-tests.pod
@@ -38,7 +38,7 @@ of checks that will be run in the test case. This enables the
test harness to determine if a test case crashed / exited earlier
than expected without running all checks. Each line starts with
a word 'ok' or 'not ok' to indicate state of the check, followed
-by the check number (assigned incremnetally), and a description
+by the check number (assigned incrementally), and a description
of the check performed. Diagnostic comments can be output using
a leading '#' to assist in debugging / interpreting the results.
@@ -148,7 +148,7 @@ Going line by line, this first imports the 'Sys::Virt::TCK' package
and its functions. Then it creates an instance of the 'Sys::Virt::TCK'
object. Then it runs the 'setup' method to obtain a libvirt
connection, catching any error that may be thrown. The fourth line
-willl abort the entire test if an error occurred during setup. The
+will abort the entire test if an error occurred during setup. The
final line registers a 'END' block which will perform cleanup when
Perl exits.
@@ -190,7 +190,7 @@ domain.
"created a running domain", "test");
This creates a new running guest from '$xml', and checks that it
-succeeeded and returns a domain object with an expected name of
+succeeded and returns a domain object with an expected name of
'test'. If an exception was thrown during guest creation this
will be reported as an error. If the guest has the incorrect name,
that will also be reported as an error.
@@ -428,6 +428,6 @@ If something went wrong, it might look like
# Looks like you failed 1 test of 2 run.
# Looks like your test died just after 2.
-Notice that since the tst script declared upfront that it intended
+Notice that since the test script declared upfront that it intended
to run 5 checks, Perl was able to detect that it aborted earlier
than expected.
--
1.7.1
14 years, 1 month
[libvirt] [TCK] Add test case for domain hook testing.
by Osier Yang
The test case will be valid only when the Sys::Virt::TCK connection
object is "qemu:///system" or "lxc:///", because currently libvirt
only support hooks for QEMU and LXC domain.
Also update scripts/hooks/051-daemon-hook.t, replace "$hook->foo"
with "$hook->foo()".
---
lib/Sys/Virt/TCK/Hooks.pm | 8 +-
scripts/hooks/051-daemon-hook.t | 36 ++++----
scripts/hooks/052-domain-hook.t | 183 +++++++++++++++++++++++++++++++++++++++
3 files changed, 205 insertions(+), 22 deletions(-)
create mode 100644 scripts/hooks/052-domain-hook.t
diff --git a/lib/Sys/Virt/TCK/Hooks.pm b/lib/Sys/Virt/TCK/Hooks.pm
index 7d20fa4..eb5e8f9 100644
--- a/lib/Sys/Virt/TCK/Hooks.pm
+++ b/lib/Sys/Virt/TCK/Hooks.pm
@@ -35,7 +35,7 @@ sub new {
conf_dir => $params{conf_dir} ? $params{conf_dir} : $HOOKS_CONF_DIR,
name => $params{conf_dir}.'/'.$params{type},
expect_result => $params{expect_result} ? $params{expect_result} : 0,
- log_name => $params{log_name} ? $params{log_name} : "/tmp/$self->{type}.log",
+ log_name => $params{log_name} ? $params{log_name} : "/tmp/$params{type}.log",
libvirtd_status => undef,
domain_name => undef,
domain_state => undef,
@@ -144,13 +144,13 @@ sub expect_log {
}
}
} elsif ($self->{type} eq 'qemu' or $self->{type} eq 'lxc') {
- if ($domain_state eq 'running') {
- if ($action eq 'stop') {
+ if ($domain_state eq &Sys::Virt::Domain::STATE_RUNNING) {
+ if ($action eq 'destroy') {
$expect_log = "$hook $domain_name stopped end -";
} else {
die "hooks testing doesn't support $action running domain";
}
- } elsif ($domain_state eq 'shut off') {
+ } elsif ($domain_state eq &Sys::Virt::Domain::STATE_SHUTOFF) {
if ($action eq 'start') {
$expect_log = "$hook $domain_name start begin -";
} else {
diff --git a/scripts/hooks/051-daemon-hook.t b/scripts/hooks/051-daemon-hook.t
index c378bd0..5218d24 100644
--- a/scripts/hooks/051-daemon-hook.t
+++ b/scripts/hooks/051-daemon-hook.t
@@ -50,24 +50,24 @@ SKIP: {
conf_dir => '/etc/libvirt/hooks',
log_name => '/tmp/daemon.log');
- $hook->libvirtd_status;
+ $hook->libvirtd_status();
BAIL_OUT "libvirtd is not running, Exit..."
if ($hook->{libvirtd_status} eq 'stopped');
- eval { $hook->prepare; };
+ eval { $hook->prepare(); };
BAIL_OUT "failed to setup hooks testing ENV: $@" if $@;
- diag "restart libvirtd for hooks scripts taking effect";
- $hook->action('restart');
- $hook->service_libvirtd;
+ diag "reload libvirtd for hooks scripts taking effect";
+ $hook->action('reload');
+ $hook->service_libvirtd();
unlink $hook->{log_name} unless -f $hook->{log_name};
# stop libvirtd
$hook->action('stop');
- $hook->expect_log;
+ $hook->expect_log();
diag "$hook->{action} libvirtd";
- $hook->service_libvirtd;
+ $hook->service_libvirtd();
my $hook_data = slurp($hook->{name});
diag "hook script: $hook->{name} '$hook_data'";
@@ -82,17 +82,17 @@ SKIP: {
diag "expected log:\n$hook->{expect_log}";
diag "check if the actual log is same with expected log";
- ok($hook->compare_log, "$hook->{name} is invoked correctly while $hook->{action} libvirtd");
+ ok($hook->compare_log(), "$hook->{name} is invoked correctly while $hook->{action} libvirtd");
diag "check if libvirtd is stopped";
ok(`service libvirtd status` =~ /stopped/, "libvirtd is stopped");
# start libvirtd
$hook->action('start');
- $hook->expect_log;
+ $hook->expect_log();
diag "$hook->{action} libvirtd";
- $hook->service_libvirtd;
+ $hook->service_libvirtd();
$hook_data = slurp($hook->{name});
diag "hook script: $hook->{name} '$hook_data'";
@@ -107,17 +107,17 @@ SKIP: {
diag "expected log: \n$hook->{expect_log}";
diag "check if the actual log is same with expected log";
- ok($hook->compare_log, "$hook->{name} is invoked correctly while $hook->{action} libvirtd");
+ ok($hook->compare_log(), "$hook->{name} is invoked correctly while $hook->{action} libvirtd");
diag "check if libvirtd is still running";
ok(`service libvirtd status` =~ /running/, "libvirtd is running");
# restart libvirtd
$hook->action('restart');
- $hook->expect_log;
+ $hook->expect_log();
diag "$hook->{action} libvirtd";
- $hook->service_libvirtd;
+ $hook->service_libvirtd();
$hook_data = slurp($hook->{name});
diag "hook script: $hook->{name} '$hook_data'";
@@ -132,17 +132,17 @@ SKIP: {
diag "expected log: \n$hook->{expect_log}";
diag "check if the actual log is same with expected log";
- ok($hook->compare_log, "$hook->{name} is invoked correctly while $hook->{action} libvirtd");
+ ok($hook->compare_log(), "$hook->{name} is invoked correctly while $hook->{action} libvirtd");
diag "check if libvirtd is still running";
ok(`service libvirtd status` =~ /running/, "libvirtd is running");
# reload libvirtd
$hook->action('reload');
- $hook->expect_log;
+ $hook->expect_log();
diag "$hook->{action} libvirtd";
- $hook->service_libvirtd;
+ $hook->service_libvirtd();
$hook_data = slurp($hook->{name});
diag "hook script: $hook->{name} '$hook_data'";
@@ -157,11 +157,11 @@ SKIP: {
diag "expected log: \n$hook->{expect_log}";
diag "check if the actual log is same with expected log";
- ok($hook->compare_log, "$hook->{name} is invoked correctly while $hook->{action} libvirtd");
+ ok($hook->compare_log(), "$hook->{name} is invoked correctly while $hook->{action} libvirtd");
diag "check if libvirtd is still running";
ok(`service libvirtd status` =~ /running/, "libvirtd is running");
- $hook->cleanup;
+ $hook->cleanup();
};
diff --git a/scripts/hooks/052-domain-hook.t b/scripts/hooks/052-domain-hook.t
new file mode 100644
index 0000000..e82aeb9
--- /dev/null
+++ b/scripts/hooks/052-domain-hook.t
@@ -0,0 +1,183 @@
+# -*- perl -*-
+#
+# Copyright (C) 2010 Red Hat, Inc.
+# Copyright (C) 2010 Osier Yang
+#
+# This program is free software; You can redistribute it and/or modify
+# it under the GNU General Public License as published by the Free
+# Software Foundation; either version 2, or (at your option) any
+# later version
+#
+# The file "LICENSE" distributed along with this file provides full
+# details of the terms and conditions
+#
+
+=pod
+
+=head1 NAME
+
+domain/052-domain-hook.t - domain hook testing
+
+=head1 DESCRIPTION
+
+This test case validates that the hook for QEMU or LXC domain is
+invoked correctly while start/stop domain, and if the exit status
+of testing hook script is 0, it expects domain could be started and
+stopped successfully. Otherwise, it expects domain 'start' will be
+failed, 'stop' is fine.
+
+=cut
+
+use strict;
+use warnings;
+
+use Slurp;
+
+use Test::More tests => 12;
+
+use Sys::Virt::TCK;
+use Sys::Virt::TCK::Hooks;
+
+my $tck = Sys::Virt::TCK->new();
+my $conn = eval { $tck->setup(); };
+BAIL_OUT "failed to setup test harness: $@" if $@;
+END { $tck->cleanup if $tck; }
+
+SKIP: {
+ my $uri = $conn->get_uri();
+
+ skip 12, "Not using QEMU/LXC driver" unless
+ $uri eq "qemu:///system" or $uri eq "lxc:///";
+
+ my $xml = $tck->generic_domain("tck")->as_xml;
+
+ diag "Creating a new persistent domain";
+ my $dom;
+ ok_domain(sub { $dom = $conn->define_domain($xml) }, "created persistent domain object");
+
+ my $hook_type = $uri eq "qemu:///system" ? 'qemu' : 'lxc';
+
+ my $hook = Sys::Virt::TCK::Hooks->new(type => $hook_type,
+ conf_dir => '/etc/libvirt/hooks',
+ expect_result => 0);
+ eval { $hook->prepare(); };
+ BAIL_OUT "failed to setup hooks testing ENV: $@" if $@;
+
+ diag "reload libvirtd for hooks scripts taking effect";
+ $hook->action('reload');
+ $hook->service_libvirtd();
+
+ # start domain
+ my $domain_state = $dom->get_info()->{state};
+ my $domain_name = $dom->get_name();
+
+ $hook->domain_name($domain_name);
+ $hook->domain_state($domain_state);
+ $hook->action('start');
+ $hook->expect_log();
+
+ diag "start $domain_name";
+ $dom->create();
+
+ diag "check if the domain is running";
+ $domain_state = $dom->get_info()->{state};
+ ok($domain_state eq &Sys::Virt::Domain::STATE_RUNNING, "domain is running");
+
+ my $hook_data = slurp($hook->{name});
+ diag "hook script: $hook->{name} '$hook_data'";
+
+ diag "check if $hook->{name} is invoked";
+ ok(-f "$hook->{name}", "$hook->{name} is invoked");
+
+ my $actual_log_data = slurp($hook->{log_name});
+ diag "acutal log: $hook->{log_name} '$actual_log_data'";
+
+ diag "expect log:\n $hook->{expect_log}";
+
+ diag "check if the actual log is same with expected log";
+ ok($hook->compare_log, "$hook->{name} is invoked correctly while start $domain_name");
+
+ diag "truncate $hook->{log_name}";
+ truncate $hook->{log_name}, 0 if -f $hook->{log_name};
+
+ # stop domain
+ $domain_state = $dom->get_info()->{state};
+
+ $hook->domain_state($domain_state);
+ $hook->action('destroy');
+ $hook->expect_log();
+
+ diag "destroy $domain_name";
+ $dom->destroy();
+
+ diag "check if the domain is shut off";
+ $domain_state = $dom->get_info()->{state};
+ ok($domain_state eq &Sys::Virt::Domain::STATE_SHUTOFF, "domain is shut off");
+
+ $hook_data = slurp($hook->{name});
+ diag "hook script: $hook->{name} '$hook_data'";
+
+ diag "check if $hook->{name} is invoked";
+ ok(-f "$hook->{name}", "$hook->{name} is invoked");
+
+ $actual_log_data = slurp($hook->{log_name});
+ diag "acutal log: $hook->{log_name} '$actual_log_data'";
+
+ diag "expect log:\n $hook->{expect_log}";
+
+ diag "check if the actual log is same with expected log";
+ ok($hook->compare_log(), "$hook->{name} is invoked correctly while start $domain_name");
+
+ $hook->cleanup();
+
+ # Create a new testing hook script with exit status is 1.
+ $hook = Sys::Virt::TCK::Hooks->new(type => $hook_type,
+ conf_dir => '/etc/libvirt/hooks',
+ expect_result => 1);
+ eval { $hook->prepare(); };
+ BAIL_OUT "failed to setup hooks testing ENV: $@" if $@;
+
+ diag "reload libvirtd for hooks scripts taking effect";
+ $hook->action('reload');
+ $hook->service_libvirtd();
+
+ # start domain once more after the testing hook script is changed.
+ $domain_state = $dom->get_info()->{state};
+ $domain_name = $dom->get_name();
+
+ $hook->domain_name($domain_name);
+ $hook->domain_state($domain_state);
+ $hook->action('start');
+ $hook->expect_log();
+
+ diag "start $domain_name";
+ eval { $dom->create(); };
+ ok($@, $@);
+
+ diag "check if the domain is running";
+ $domain_state = $dom->get_info()->{state};
+ ok($domain_state eq &Sys::Virt::Domain::STATE_SHUTOFF, "domain is not started ");
+
+ $hook_data = slurp($hook->{name});
+ diag "hook script: $hook->{name} '$hook_data'";
+
+ diag "check if $hook->{name} is invoked";
+ ok(-f "$hook->{name}", "$hook->{name} is invoked");
+
+ $actual_log_data = slurp($hook->{log_name});
+ diag "acutal log: $hook->{log_name} '$actual_log_data'";
+
+ diag "expect log:\n $hook->{expect_log}";
+
+ diag "check if the actual log is same with expected log";
+ ok($hook->compare_log, "$hook->{name} is invoked correctly while start $domain_name");
+
+ # undefine domain
+ diag "undefine $domain_name";
+ $dom->undefine();
+
+ ok_error(sub { $conn->get_domain_by_name("tck") }, "NO_DOMAIN error raised from missing domain",
+ Sys::Virt::Error::ERR_NO_DOMAIN);
+
+ $hook->cleanup();
+};
--
1.7.1
14 years, 1 month
[libvirt] [PATCH] configure: adds an option for not using the readline library
by Justin Clift
So we can use "--with-readline=no" for situations where that
helpful. ie. MacOS X 10.5.
By default, we use "--with-readline=check".
---
configure.ac | 47 ++++++++++++++++++++++++++++-------------------
1 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/configure.ac b/configure.ac
index e41f2b5..2831db0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -240,6 +240,10 @@ AC_ARG_WITH([remote],
AC_ARG_WITH([libvirtd],
AC_HELP_STRING([--with-libvirtd], [add libvirtd support @<:@default=yes@:>@]),[],[with_libvirtd=yes])
+dnl Add a --help string for the readline usage option
+AC_ARG_WITH([readline],
+ AC_HELP_STRING([--with-readline], [add readline support @<:@default=check@:>@]),[],[with_readline=check])
+
dnl
dnl in case someone want to build static binaries
dnl STATIC_BINARIES="-static"
@@ -1338,26 +1342,29 @@ AM_CONDITIONAL([HAVE_CAPNG], [test "$with_capng" != "no"])
AC_SUBST([CAPNG_CFLAGS])
AC_SUBST([CAPNG_LIBS])
+dnl If we've been instructed to not use readline, then don't even check for it
+if test "$with_readline" = "no"; then
+ lv_use_readline="no"
+fi
+if test "$with_readline" != "no"; then
+ dnl virsh libraries
+ AC_CHECK_HEADERS([readline/readline.h])
-
-dnl virsh libraries
-AC_CHECK_HEADERS([readline/readline.h])
-
-# Check for readline.
-AC_CHECK_LIB([readline], [readline],
+ # Check for readline.
+ AC_CHECK_LIB([readline], [readline],
[lv_use_readline=yes; VIRSH_LIBS="$VIRSH_LIBS -lreadline"],
[lv_use_readline=no])
-# If the above test failed, it may simply be that -lreadline requires
-# some termcap-related code, e.g., from one of the following libraries.
-# See if adding one of them to LIBS helps.
-if test $lv_use_readline = no; then
- lv_saved_libs=$LIBS
- LIBS=
- AC_SEARCH_LIBS([tgetent], [ncurses curses termcap termlib])
- case $LIBS in
- no*) ;; # handle "no" and "none required"
- *) # anything else is a -lLIBRARY
+ # If the above test failed, it may simply be that -lreadline requires
+ # some termcap-related code, e.g., from one of the following libraries.
+ # See if adding one of them to LIBS helps.
+ if test $lv_use_readline = no; then
+ lv_saved_libs=$LIBS
+ LIBS=
+ AC_SEARCH_LIBS([tgetent], [ncurses curses termcap termlib])
+ case $LIBS in
+ no*) ;; # handle "no" and "none required"
+ *) # anything else is a -lLIBRARY
# Now, check for -lreadline again, also using $LIBS.
# Note: this time we use a different function, so that
# we don't get a cached "no" result.
@@ -1366,12 +1373,14 @@ if test $lv_use_readline = no; then
VIRSH_LIBS="$VIRSH_LIBS -lreadline $LIBS"],,
[$LIBS])
;;
- esac
- test $lv_use_readline = no &&
+ esac
+ test $lv_use_readline = no &&
AC_MSG_WARN([readline library not found])
- LIBS=$lv_saved_libs
+ LIBS=$lv_saved_libs
+ fi
fi
+dnl We now adjust things to suit the result of our checks for readline
if test $lv_use_readline = yes; then
AC_DEFINE_UNQUOTED([USE_READLINE], 1,
[whether virsh can use readline])
--
1.7.2.3
14 years, 1 month
[libvirt] [PATCH] bye to close(), welcome to VIR_(FORCE_)CLOSE()
by Stefan Berger
Using automated replacement with sed and editing I have now replaced all
occurrences of close() with VIR_(FORCE_)CLOSE() except for one, of
course. Some replacements were straight forward, others I needed to pay
attention. I hope I payed attention in all the right places... Please
have a look. This should have at least solved one more double-close
error.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
daemon/libvirtd.c | 46 ++++++---------
proxy/libvirt_proxy.c | 16 ++---
src/libvirt.c | 8 +-
src/lxc/lxc_container.c | 15 +++--
src/lxc/lxc_controller.c | 27 +++------
src/lxc/lxc_driver.c | 24 +++-----
src/node_device/node_device_linux_sysfs.c | 5 -
src/nwfilter/nwfilter_ebiptables_driver.c | 8 +-
src/openvz/openvz_conf.c | 35 ++++-------
src/openvz/openvz_driver.c | 3 -
src/phyp/phyp_driver.c | 13 ++--
src/qemu/qemu_conf.c | 30 ++++------
src/qemu/qemu_driver.c | 89 ++++++++++++------------------
src/qemu/qemu_monitor.c | 6 +-
src/remote/remote_driver.c | 18 ++----
src/secret/secret_driver.c | 12 +---
src/security/security_apparmor.c | 9 +--
src/security/security_selinux.c | 9 +--
src/security/virt-aa-helper.c | 9 +--
src/storage/storage_backend.c | 25 +++-----
src/storage/storage_backend_fs.c | 11 ++-
src/storage/storage_backend_iscsi.c | 5 -
src/storage/storage_backend_logical.c | 10 +--
src/storage/storage_backend_mpath.c | 5 -
src/storage/storage_backend_scsi.c | 8 +-
src/storage/storage_driver.c | 5 -
src/test/test_driver.c | 20 ++----
src/uml/uml_conf.c | 3 -
src/uml/uml_driver.c | 24 ++++----
src/util/bridge.c | 13 ++--
src/util/conf.c | 3 -
src/util/hooks.c | 21 +++----
src/util/interface.c | 12 ++--
src/util/logging.c | 6 +-
src/util/macvtap.c | 8 +-
src/util/pci.c | 6 --
src/util/storage_file.c | 5 +
src/util/util.c | 67 ++++++++++------------
src/util/uuid.c | 9 +--
src/util/virtaudit.c | 3 -
src/xen/proxy_internal.c | 8 +-
src/xen/xen_hypervisor.c | 12 ++--
src/xen/xen_inotify.c | 3 -
src/xen/xend_internal.c | 12 +---
tests/testutils.c | 21 ++++---
tools/console.c | 3 -
46 files changed, 327 insertions(+), 383 deletions(-)
Index: libvirt-acl/src/libvirt.c
===================================================================
--- libvirt-acl.orig/src/libvirt.c
+++ libvirt-acl/src/libvirt.c
@@ -10794,7 +10794,7 @@ virStreamRef(virStreamPtr stream)
* ... report an error ....
* done:
* virStreamFree(st);
- * close(fd);
+ * VIR_FORCE_CLOSE(fd);
*
* Returns the number of bytes written, which may be less
* than requested.
@@ -10884,7 +10884,7 @@ error:
* ... report an error ....
* done:
* virStreamFree(st);
- * close(fd);
+ * VIR_FORCE_CLOSE(fd);
*
*
* Returns the number of bytes read, which may be less
@@ -10964,7 +10964,7 @@ error:
* if (virStreamFinish(st) < 0)
* ...report an error...
* virStreamFree(st);
- * close(fd);
+ * VIR_FORCE_CLOSE(fd);
*
* Returns 0 if all the data was successfully sent. The caller
* should invoke virStreamFinish(st) to flush the stream upon
@@ -11061,7 +11061,7 @@ cleanup:
* if (virStreamFinish(st) < 0)
* ...report an error...
* virStreamFree(st);
- * close(fd);
+ * VIR_FORCE_CLOSE(fd);
*
* Returns 0 if all the data was successfully received. The caller
* should invoke virStreamFinish(st) to flush the stream upon
Index: libvirt-acl/src/lxc/lxc_container.c
===================================================================
--- libvirt-acl.orig/src/lxc/lxc_container.c
+++ libvirt-acl/src/lxc/lxc_container.c
@@ -52,6 +52,7 @@
#include "util.h"
#include "memory.h"
#include "veth.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -127,7 +128,7 @@ static int lxcContainerExecInit(virDomai
static int lxcContainerSetStdio(int control, int ttyfd)
{
int rc = -1;
- int open_max, i;
+ int open_max, i, tpmfd;
if (setsid() < 0) {
virReportSystemError(errno, "%s",
@@ -145,8 +146,10 @@ static int lxcContainerSetStdio(int cont
* close all FDs before executing the container */
open_max = sysconf (_SC_OPEN_MAX);
for (i = 0; i < open_max; i++)
- if (i != ttyfd && i != control)
- close(i);
+ if (i != ttyfd && i != control) {
+ tpmfd = i;
+ VIR_FORCE_CLOSE(tpmfd);
+ }
if (dup2(ttyfd, 0) < 0) {
virReportSystemError(errno, "%s",
@@ -222,7 +225,7 @@ static int lxcContainerWaitForContinue(i
_("Failed to read the container continue message"));
return -1;
}
- close(control);
+ VIR_FORCE_CLOSE(control);
DEBUG0("Received container continue message");
@@ -776,10 +779,10 @@ static int lxcContainerChild( void *data
VIR_FREE(ttyPath);
if (lxcContainerSetStdio(argv->monitor, ttyfd) < 0) {
- close(ttyfd);
+ VIR_FORCE_CLOSE(ttyfd);
return -1;
}
- close(ttyfd);
+ VIR_FORCE_CLOSE(ttyfd);
if (lxcContainerSetupMounts(vmDef, root) < 0)
return -1;
Index: libvirt-acl/src/lxc/lxc_controller.c
===================================================================
--- libvirt-acl.orig/src/lxc/lxc_controller.c
+++ libvirt-acl/src/lxc/lxc_controller.c
@@ -48,6 +48,7 @@
#include "veth.h"
#include "memory.h"
#include "util.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -233,8 +234,7 @@ static int lxcMonitorServer(const char *
return fd;
error:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -409,7 +409,7 @@ static int lxcControllerMain(int monitor
goto cleanup;
}
if (client != -1) { /* Already connected, so kick new one out */
- close(fd);
+ VIR_FORCE_CLOSE(fd);
continue;
}
client = fd;
@@ -426,8 +426,7 @@ static int lxcControllerMain(int monitor
_("epoll_ctl(client) failed"));
goto cleanup;
}
- close(client);
- client = -1;
+ VIR_FORCE_CLOSE(client);
} else {
if (epollEvent.events & EPOLLIN) {
curFdOff = epollEvent.data.fd == appPty ? 0 : 1;
@@ -485,9 +484,9 @@ static int lxcControllerMain(int monitor
rc = 0;
cleanup:
- close(appPty);
- close(contPty);
- close(epollFd);
+ VIR_FORCE_CLOSE(appPty);
+ VIR_FORCE_CLOSE(contPty);
+ VIR_FORCE_CLOSE(epollFd);
return rc;
}
@@ -660,8 +659,7 @@ lxcControllerRun(virDomainDefPtr def,
control[1],
containerPtyPath)) < 0)
goto cleanup;
- close(control[1]);
- control[1] = -1;
+ VIR_FORCE_CLOSE(control[1]);
if (lxcControllerMoveInterfaces(nveths, veths, container) < 0)
goto cleanup;
@@ -679,13 +677,10 @@ lxcControllerRun(virDomainDefPtr def,
cleanup:
VIR_FREE(devptmx);
VIR_FREE(devpts);
- if (control[0] != -1)
- close(control[0]);
- if (control[1] != -1)
- close(control[1]);
+ VIR_FORCE_CLOSE(control[0]);
+ VIR_FORCE_CLOSE(control[1]);
VIR_FREE(containerPtyPath);
- if (containerPty != -1)
- close(containerPty);
+ VIR_FORCE_CLOSE(containerPty);
if (container > 1) {
int status;
Index: libvirt-acl/src/lxc/lxc_driver.c
===================================================================
--- libvirt-acl.orig/src/lxc/lxc_driver.c
+++ libvirt-acl/src/lxc/lxc_driver.c
@@ -51,6 +51,7 @@
#include "uuid.h"
#include "stats_linux.h"
#include "hooks.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -974,7 +975,7 @@ static int lxcVmCleanup(lxc_driver_t *dr
}
virEventRemoveHandle(priv->monitorWatch);
- close(priv->monitor);
+ VIR_FORCE_CLOSE(priv->monitor);
virFileDeletePid(driver->stateDir, vm->def->name);
virDomainDeleteConfig(driver->stateDir, NULL, vm);
@@ -1156,8 +1157,7 @@ static int lxcMonitorClient(lxc_driver_t
error:
VIR_FREE(sockpath);
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -1544,14 +1544,10 @@ cleanup:
vethDelete(veths[i]);
VIR_FREE(veths[i]);
}
- if (rc != 0 && priv->monitor != -1) {
- close(priv->monitor);
- priv->monitor = -1;
- }
- if (parentTty != -1)
- close(parentTty);
- if (logfd != -1)
- close(logfd);
+ if (rc != 0)
+ VIR_FORCE_CLOSE(priv->monitor);
+ VIR_FORCE_CLOSE(parentTty);
+ VIR_FORCE_CLOSE(logfd);
VIR_FREE(logfile);
return rc;
}
@@ -2011,8 +2007,7 @@ lxcReconnectVM(void *payload, const char
/* Read pid from controller */
if ((virFileReadPid(lxc_driver->stateDir, vm->def->name, &vm->pid)) != 0) {
- close(priv->monitor);
- priv->monitor = -1;
+ VIR_FORCE_CLOSE(priv->monitor);
goto cleanup;
}
@@ -2042,8 +2037,7 @@ lxcReconnectVM(void *payload, const char
}
} else {
vm->def->id = -1;
- close(priv->monitor);
- priv->monitor = -1;
+ VIR_FORCE_CLOSE(priv->monitor);
}
cleanup:
Index: libvirt-acl/src/node_device/node_device_linux_sysfs.c
===================================================================
--- libvirt-acl.orig/src/node_device/node_device_linux_sysfs.c
+++ libvirt-acl/src/node_device/node_device_linux_sysfs.c
@@ -31,6 +31,7 @@
#include "virterror_internal.h"
#include "memory.h"
#include "logging.h"
+#include "files.h"
#include <dirent.h>
#define VIR_FROM_THIS VIR_FROM_NODEDEV
@@ -104,9 +105,7 @@ int read_wwn_linux(int host, const char
}
out:
- if (fd != -1) {
- close(fd);
- }
+ VIR_FORCE_CLOSE(fd);
return retval;
}
Index: libvirt-acl/src/nwfilter/nwfilter_ebiptables_driver.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_ebiptables_driver.c
+++ libvirt-acl/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -37,6 +37,7 @@
#include "nwfilter_conf.h"
#include "nwfilter_gentech_driver.h"
#include "nwfilter_ebiptables_driver.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_NWFILTER
@@ -2501,13 +2502,12 @@ ebiptablesWriteToTempFile(const char *st
}
VIR_FREE(header);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return filnam;
err_exit:
VIR_FREE(header);
- if (fd >= 0)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
unlink(filename);
return NULL;
}
@@ -3267,7 +3267,7 @@ iptablesCheckBridgeNFCallEnabled(bool is
lastReport = now;
}
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
}
}
}
Index: libvirt-acl/src/openvz/openvz_conf.c
===================================================================
--- libvirt-acl.orig/src/openvz/openvz_conf.c
+++ libvirt-acl/src/openvz/openvz_conf.c
@@ -50,6 +50,7 @@
#include "memory.h"
#include "util.h"
#include "nodeinfo.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_OPENVZ
@@ -109,7 +110,7 @@ openvzExtractVersionInfo(const char *cmd
cleanup2:
VIR_FREE(help);
- if (close(newstdout) < 0)
+ if (VIR_CLOSE(newstdout) < 0)
ret = -1;
rewait:
@@ -569,7 +570,7 @@ openvzWriteConfigParam(const char * conf
goto error;
temp_fd = open(temp_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (temp_fd == -1) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
goto error;
}
@@ -590,12 +591,10 @@ openvzWriteConfigParam(const char * conf
safewrite(temp_fd, "\"\n", 2) < 0)
goto error;
- if (close(fd) < 0)
+ if (VIR_CLOSE(fd) < 0)
goto error;
- fd = -1;
- if (close(temp_fd) < 0)
+ if (VIR_CLOSE(temp_fd) < 0)
goto error;
- temp_fd = -1;
if (rename(temp_file, conf_file) < 0)
goto error;
@@ -603,10 +602,8 @@ openvzWriteConfigParam(const char * conf
return 0;
error:
- if (fd != -1)
- close(fd);
- if (temp_fd != -1)
- close(temp_fd);
+ VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_CLOSE(temp_fd);
if (temp_file)
unlink(temp_file);
VIR_FREE(temp_file);
@@ -662,7 +659,7 @@ openvzReadConfigParam(const char * conf_
}
}
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (ret == 0 && found)
ret = 1;
@@ -703,7 +700,7 @@ openvz_copyfile(char* from_path, char* t
return -1;
copy_fd = open(to_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (copy_fd == -1) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -716,19 +713,16 @@ openvz_copyfile(char* from_path, char* t
goto error;
}
- if (close(fd) < 0)
+ if (VIR_CLOSE(fd) < 0)
goto error;
- fd = -1;
- if (close(copy_fd) < 0)
+ if (VIR_CLOSE(copy_fd) < 0)
goto error;
return 0;
error:
- if (fd != -1)
- close(fd);
- if (copy_fd != -1)
- close(copy_fd);
+ VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_CLOSE(copy_fd);
return -1;
}
@@ -880,8 +874,7 @@ openvzGetVPSUUID(int vpsid, char *uuidst
}
retval = 0;
cleanup:
- if (fd >= 0)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
VIR_FREE(conf_file);
return retval;
Index: libvirt-acl/src/openvz/openvz_driver.c
===================================================================
--- libvirt-acl.orig/src/openvz/openvz_driver.c
+++ libvirt-acl/src/openvz/openvz_driver.c
@@ -57,6 +57,7 @@
#include "nodeinfo.h"
#include "memory.h"
#include "bridge.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_OPENVZ
@@ -1540,7 +1541,7 @@ Version: 2.2
}
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (ret < 0)
return -1;
Index: libvirt-acl/src/phyp/phyp_driver.c
===================================================================
--- libvirt-acl.orig/src/phyp/phyp_driver.c
+++ libvirt-acl/src/phyp/phyp_driver.c
@@ -58,6 +58,7 @@
#include "domain_conf.h"
#include "storage_conf.h"
#include "nodeinfo.h"
+#include "files.h"
#include "phyp_driver.h"
@@ -457,11 +458,11 @@ phypUUIDTable_WriteFile(virConnectPtr co
}
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return 0;
err:
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -672,11 +673,11 @@ phypUUIDTable_ReadFile(virConnectPtr con
} else
virReportOOMError();
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return 0;
err:
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -764,7 +765,7 @@ phypUUIDTable_Pull(virConnectPtr conn)
}
break;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
goto exit;
exit:
@@ -1001,7 +1002,7 @@ openSSHSession(virConnectPtr conn, virCo
if (connect(sock, cur->ai_addr, cur->ai_addrlen) == 0) {
goto connected;
}
- close(sock);
+ VIR_FORCE_CLOSE(sock);
}
cur = cur->ai_next;
}
Index: libvirt-acl/src/qemu/qemu_conf.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_conf.c
+++ libvirt-acl/src/qemu/qemu_conf.c
@@ -55,6 +55,7 @@
#include "macvtap.h"
#include "cpu/cpu.h"
#include "domain_nwfilter.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -530,7 +531,7 @@ qemudProbeMachineTypes(const char *binar
cleanup2:
VIR_FREE(output);
cleanup:
- if (close(newstdout) < 0)
+ if (VIR_CLOSE(newstdout) < 0)
ret = -1;
rewait:
@@ -780,7 +781,7 @@ qemudProbeCPUModels(const char *qemu,
cleanup:
VIR_FREE(output);
- if (close(newstdout) < 0)
+ if (VIR_CLOSE(newstdout) < 0)
ret = -1;
rewait:
@@ -1421,7 +1422,7 @@ static void qemudParsePCIDeviceStrs(cons
cleanup:
VIR_FREE(pciassign);
- close(newstderr);
+ VIR_FORCE_CLOSE(newstderr);
rewait:
if (waitpid(child, &status, 0) != child) {
if (errno == EINTR)
@@ -1481,7 +1482,7 @@ int qemudExtractVersionInfo(const char *
cleanup2:
VIR_FREE(help);
- if (close(newstdout) < 0)
+ if (VIR_CLOSE(newstdout) < 0)
ret = -1;
rewait:
@@ -1596,8 +1597,7 @@ qemudPhysIfaceConnect(virConnectPtr conn
if ((net->filter) && (net->ifname)) {
err = virDomainConfNWFilterInstantiate(conn, net);
if (err) {
- close(rc);
- rc = -1;
+ VIR_FORCE_CLOSE(rc);
delMacvtap(net->ifname, net->mac, net->data.direct.linkdev,
&net->data.direct.virtPortProfile);
VIR_FREE(net->ifname);
@@ -1742,10 +1742,8 @@ qemudNetworkIfaceConnect(virConnectPtr c
if (tapfd >= 0) {
if ((net->filter) && (net->ifname)) {
err = virDomainConfNWFilterInstantiate(conn, net);
- if (err) {
- close(tapfd);
- tapfd = -1;
- }
+ if (err)
+ VIR_FORCE_CLOSE(tapfd);
}
}
@@ -4557,7 +4555,7 @@ int qemudBuildCommandLine(virConnectPtr
if (VIR_REALLOC_N(*vmfds, (*nvmfds)+1) < 0) {
virDomainConfNWFilterTeardown(net);
- close(tapfd);
+ VIR_FORCE_CLOSE(tapfd);
goto no_memory;
}
@@ -4576,7 +4574,7 @@ int qemudBuildCommandLine(virConnectPtr
if (VIR_REALLOC_N(*vmfds, (*nvmfds)+1) < 0) {
virDomainConfNWFilterTeardown(net);
- close(tapfd);
+ VIR_FORCE_CLOSE(tapfd);
goto no_memory;
}
@@ -4596,7 +4594,7 @@ int qemudBuildCommandLine(virConnectPtr
int vhostfd = qemudOpenVhostNet(net, qemuCmdFlags);
if (vhostfd >= 0) {
if (VIR_REALLOC_N(*vmfds, (*nvmfds)+1) < 0) {
- close(vhostfd);
+ VIR_FORCE_CLOSE(vhostfd);
goto no_memory;
}
@@ -5094,14 +5092,14 @@ int qemudBuildCommandLine(virConnectPtr
if (configfd >= 0) {
if (virAsprintf(&configfd_name, "%d", configfd) < 0) {
- close(configfd);
+ VIR_FORCE_CLOSE(configfd);
virReportOOMError();
goto no_memory;
}
if (VIR_REALLOC_N(*vmfds, (*nvmfds)+1) < 0) {
VIR_FREE(configfd_name);
- close(configfd);
+ VIR_FORCE_CLOSE(configfd);
goto no_memory;
}
@@ -5194,7 +5192,7 @@ int qemudBuildCommandLine(virConnectPtr
if (vmfds &&
*vmfds) {
for (i = 0; i < *nvmfds; i++)
- close((*vmfds)[i]);
+ VIR_FORCE_CLOSE((*vmfds)[i]);
VIR_FREE(*vmfds);
*nvmfds = 0;
}
Index: libvirt-acl/src/qemu/qemu_driver.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_driver.c
+++ libvirt-acl/src/qemu/qemu_driver.c
@@ -81,6 +81,7 @@
#include "hooks.h"
#include "storage_file.h"
#include "virtaudit.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -761,7 +762,7 @@ qemudLogFD(struct qemud_driver *driver,
if (virSetCloseExec(fd) < 0) {
virReportSystemError(errno, "%s",
_("Unable to set VM logfile close-on-exec flag"));
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
return fd;
@@ -793,14 +794,14 @@ qemudLogReadFD(const char* logDir, const
if (virSetCloseExec(fd) < 0) {
virReportSystemError(errno, "%s",
_("Unable to set VM logfile close-on-exec flag"));
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
if (pos < 0 || lseek(fd, pos, SEEK_SET) < 0) {
- virReportSystemError(pos < 0 ? 0 : errno,
+ virReportSystemError(pos < 0 ? 0 : errno,
_("Unable to seek to %lld in %s"),
(long long) pos, logfile);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
}
return fd;
}
@@ -2392,7 +2393,7 @@ cleanup:
}
closelog:
- if (close(logfd) < 0) {
+ if (VIR_CLOSE(logfd) < 0) {
char ebuf[4096];
VIR_WARN("Unable to close logfile: %s",
virStrerror(errno, ebuf, sizeof ebuf));
@@ -2971,13 +2972,13 @@ static int qemudNextFreeVNCPort(struct q
return -1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void*)&reuse, sizeof(reuse)) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
break;
}
if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == 0) {
/* Not in use, lets grab it */
- close(fd);
+ VIR_FORCE_CLOSE(fd);
/* Add port to bitmap of reserved ports */
if (virBitmapSetBit(driver->reservedVNCPorts,
i - QEMU_VNC_PORT_MIN) < 0) {
@@ -2986,7 +2987,7 @@ static int qemudNextFreeVNCPort(struct q
}
return i;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (errno == EADDRINUSE) {
/* In use, try next */
@@ -3238,7 +3239,7 @@ qemuPrepareChardevDevice(virDomainDefPtr
return -1;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return 0;
}
@@ -3955,7 +3956,7 @@ static int qemudStartVMDaemon(virConnect
if (vmfds) {
for (i = 0 ; i < nvmfds ; i++) {
- close(vmfds[i]);
+ VIR_FORCE_CLOSE(vmfds[i]);
}
VIR_FREE(vmfds);
}
@@ -4008,8 +4009,7 @@ static int qemudStartVMDaemon(virConnect
if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0)
goto cleanup;
- if (logfile != -1)
- close(logfile);
+ VIR_FORCE_CLOSE(logfile);
return 0;
@@ -4019,8 +4019,7 @@ cleanup:
* pretend we never started it */
qemudShutdownVMDaemon(driver, vm, 0);
- if (logfile != -1)
- close(logfile);
+ VIR_FORCE_CLOSE(logfile);
return -1;
}
@@ -4295,7 +4294,7 @@ static int kvmGetMaxVCPUs(void) {
if (r > 0)
maxvcpus = r;
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return maxvcpus;
}
@@ -5397,10 +5396,10 @@ static int qemudDomainSaveFlag(struct qe
goto endjob;
}
if (qemudDomainSaveFileOpHook(fd, &hdata) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
goto endjob;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno, _("unable to close %s"), path);
goto endjob;
}
@@ -5796,7 +5795,7 @@ static int qemudDomainCoreDump(virDomain
goto endjob;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("unable to save file %s"),
path);
@@ -6424,8 +6423,7 @@ static int qemudOpenAsUID(const char *pa
/* parent */
/* parent doesn't need the write side of the pipe */
- close(pipefd[1]);
- pipefd[1] = -1;
+ VIR_FORCE_CLOSE(pipefd[1]);
if (forkRet < 0) {
virReportSystemError(errno,
@@ -6437,10 +6435,8 @@ static int qemudOpenAsUID(const char *pa
fd = pipefd[0];
pipefd[0] = -1;
parent_cleanup:
- if (pipefd[0] != -1)
- close(pipefd[0]);
- if (pipefd[1] != -1)
- close(pipefd[1]);
+ VIR_FORCE_CLOSE(pipefd[0]);
+ VIR_FORCE_CLOSE(pipefd[1]);
if ((fd < 0) && (*child_pid > 0)) {
/* a child process was started and subsequently an error
occurred in the parent, so we need to wait for it to
@@ -6466,7 +6462,7 @@ parent_cleanup:
struct passwd pwd, *pwd_result;
/* child doesn't need the read side of the pipe */
- close(pipefd[0]);
+ VIR_FORCE_CLOSE(pipefd[0]);
if (forkRet < 0) {
exit_code = errno;
@@ -6531,10 +6527,8 @@ parent_cleanup:
child_cleanup:
VIR_FREE(buf);
- if (fd != -1)
- close(fd);
- if (pipefd[1] != -1)
- close(pipefd[1]);
+ VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_CLOSE(pipefd[1]);
_exit(exit_code);
}
@@ -6542,8 +6536,10 @@ static int qemudDomainSaveImageClose(int
{
int ret = 0;
- if (fd != -1)
- close(fd);
+ if (VIR_CLOSE(fd) < 0) {
+ virReportSystemError(errno, "%s",
+ _("cannot close file"));
+ }
if (read_pid != -1) {
/* reap the process that read the file */
@@ -6699,8 +6695,7 @@ qemudDomainSaveImageStartVM(virConnectPt
/* empty */
}
}
- if (intermediatefd != -1)
- close(intermediatefd);
+ VIR_FORCE_CLOSE(intermediatefd);
wait_ret = qemudDomainSaveImageClose(fd, read_pid, &status);
fd = -1;
@@ -8065,9 +8060,7 @@ static int qemudDomainAttachNetDevice(vi
}
qemuDomainObjExitMonitorWithDriver(driver, vm);
- if (tapfd != -1)
- close(tapfd);
- tapfd = -1;
+ VIR_FORCE_CLOSE(tapfd);
if (!virDomainObjIsActive(vm)) {
qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -8117,8 +8110,7 @@ cleanup:
VIR_FREE(nicstr);
VIR_FREE(netstr);
VIR_FREE(tapfd_name);
- if (tapfd != -1)
- close(tapfd);
+ VIR_FORCE_CLOSE(tapfd);
return ret;
@@ -8247,8 +8239,7 @@ static int qemudDomainAttachHostPciDevic
VIR_FREE(devstr);
VIR_FREE(configfd_name);
- if (configfd >= 0)
- close(configfd);
+ VIR_FORCE_CLOSE(configfd);
return 0;
@@ -8262,8 +8253,7 @@ error:
VIR_FREE(devstr);
VIR_FREE(configfd_name);
- if (configfd >= 0)
- close(configfd);
+ VIR_FORCE_CLOSE(configfd);
return -1;
}
@@ -10357,8 +10347,7 @@ static int qemuDomainGetBlockInfo(virDom
}
cleanup:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (vm)
virDomainObjUnlock(vm);
return ret;
@@ -10673,8 +10662,7 @@ cleanup:
static void qemuStreamMigFree(struct qemuStreamMigFile *qemust)
{
- if (qemust->fd != -1)
- close(qemust->fd);
+ VIR_FORCE_CLOSE(qemust->fd);
VIR_FREE(qemust);
}
@@ -11510,10 +11498,8 @@ finish:
qemuDomainObjExitRemoteWithDriver(driver, vm);
cleanup:
- if (client_sock != -1)
- close(client_sock);
- if (qemu_sock != -1)
- close(qemu_sock);
+ VIR_FORCE_CLOSE(client_sock);
+ VIR_FORCE_CLOSE(qemu_sock);
if (ddomain)
virUnrefDomain(ddomain);
@@ -12292,8 +12278,7 @@ cleanup:
VIR_FREE(snapFile);
VIR_FREE(snapDir);
VIR_FREE(newxml);
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
Index: libvirt-acl/src/qemu/qemu_monitor.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_monitor.c
+++ libvirt-acl/src/qemu/qemu_monitor.c
@@ -36,6 +36,7 @@
#include "virterror_internal.h"
#include "memory.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -283,7 +284,7 @@ qemuMonitorOpenUnix(const char *monitor)
return monfd;
error:
- close(monfd);
+ VIR_FORCE_CLOSE(monfd);
return -1;
}
@@ -694,8 +695,7 @@ void qemuMonitorClose(qemuMonitorPtr mon
if (!mon->closed) {
if (mon->watch)
virEventRemoveHandle(mon->watch);
- if (mon->fd != -1)
- close(mon->fd);
+ VIR_FORCE_CLOSE(mon->fd);
/* NB: ordinarily one might immediately set mon->watch to -1
* and mon->fd to -1, but there may be a callback active
* that is still relying on these fields being valid. So
Index: libvirt-acl/src/remote/remote_driver.c
===================================================================
--- libvirt-acl.orig/src/remote/remote_driver.c
+++ libvirt-acl/src/remote/remote_driver.c
@@ -82,6 +82,7 @@
#include "util.h"
#include "event.h"
#include "ignore-value.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_REMOTE
@@ -711,7 +712,7 @@ doRemoteOpen (virConnectPtr conn,
if (errno == ECONNREFUSED &&
flags & VIR_DRV_OPEN_REMOTE_AUTOSTART &&
trials < 20) {
- close(priv->sock);
+ VIR_FORCE_CLOSE(priv->sock);
priv->sock = -1;
if (trials > 0 ||
remoteForkDaemon() == 0) {
@@ -955,8 +956,7 @@ doRemoteOpen (virConnectPtr conn,
failed:
/* Close the socket if we failed. */
- if (priv->errfd >= 0)
- close(priv->errfd);
+ VIR_FORCE_CLOSE(priv->errfd);
if (priv->sock >= 0) {
if (priv->uses_tls && priv->session) {
@@ -977,10 +977,8 @@ retry:
#endif
}
- if (wakeupFD[0] >= 0) {
- close(wakeupFD[0]);
- close(wakeupFD[1]);
- }
+ VIR_FORCE_CLOSE(wakeupFD[0]);
+ VIR_FORCE_CLOSE(wakeupFD[1]);
VIR_FREE(priv->hostname);
goto cleanup;
@@ -1456,10 +1454,8 @@ retry:
} while (reap != -1 && reap != priv->pid);
}
#endif
- if (priv->wakeupReadFD >= 0) {
- close(priv->wakeupReadFD);
- close(priv->wakeupSendFD);
- }
+ VIR_FORCE_CLOSE(priv->wakeupReadFD);
+ VIR_FORCE_CLOSE(priv->wakeupSendFD);
/* Free hostname copy */
Index: libvirt-acl/src/secret/secret_driver.c
===================================================================
--- libvirt-acl.orig/src/secret/secret_driver.c
+++ libvirt-acl/src/secret/secret_driver.c
@@ -41,6 +41,7 @@
#include "util.h"
#include "uuid.h"
#include "virterror_internal.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_SECRET
@@ -181,7 +182,7 @@ replaceFile(const char *filename, void *
tmp_path);
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno, _("error closing '%s'"), tmp_path);
goto cleanup;
}
@@ -196,8 +197,7 @@ replaceFile(const char *filename, void *
ret = 0;
cleanup:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (tmp_path != NULL) {
unlink(tmp_path);
VIR_FREE(tmp_path);
@@ -394,8 +394,7 @@ secretLoadValue(virSecretDriverStatePtr
virReportSystemError(errno, _("cannot read '%s'"), filename);
goto cleanup;
}
- close(fd);
- fd = -1;
+ VIR_FORCE_CLOSE(fd);
if (!base64_decode_alloc(contents, st.st_size, &value, &value_size)) {
virSecretReportError(VIR_ERR_INTERNAL_ERROR,
@@ -422,8 +421,7 @@ cleanup:
memset(contents, 0, st.st_size);
VIR_FREE(contents);
}
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
VIR_FREE(filename);
return ret;
}
Index: libvirt-acl/src/security/security_apparmor.c
===================================================================
--- libvirt-acl.orig/src/security/security_apparmor.c
+++ libvirt-acl/src/security/security_apparmor.c
@@ -37,6 +37,7 @@
#include "uuid.h"
#include "pci.h"
#include "hostusb.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_SECURITY
#define SECURITY_APPARMOR_VOID_DOI "0"
@@ -215,7 +216,7 @@ load_profile(virSecurityDriverPtr drv,
virReportSystemError(errno, "%s", _("unable to write to pipe"));
goto clean;
}
- close(pipefd[1]);
+ VIR_FORCE_CLOSE(pipefd[1]);
rc = 0;
rewait:
@@ -233,10 +234,8 @@ load_profile(virSecurityDriverPtr drv,
clean:
VIR_FREE(xml);
- if (pipefd[0] > 0)
- close(pipefd[0]);
- if (pipefd[1] > 0)
- close(pipefd[1]);
+ VIR_FORCE_CLOSE(pipefd[0]);
+ VIR_FORCE_CLOSE(pipefd[1]);
return rc;
}
Index: libvirt-acl/src/security/security_selinux.c
===================================================================
--- libvirt-acl.orig/src/security/security_selinux.c
+++ libvirt-acl/src/security/security_selinux.c
@@ -30,6 +30,7 @@
#include "storage_file.h"
#include "uuid.h"
#include "virtaudit.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_SECURITY
@@ -122,10 +123,10 @@ SELinuxInitialize(void)
virReportSystemError(errno,
_("cannot read SELinux virtual domain context file %s"),
selinux_virtual_domain_context_path());
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
ptr = strchrnul(default_domain_context, '\n');
*ptr = '\0';
@@ -141,10 +142,10 @@ SELinuxInitialize(void)
virReportSystemError(errno,
_("cannot read SELinux virtual image context file %s"),
selinux_virtual_image_context_path());
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
ptr = strchrnul(default_image_context, '\n');
if (*ptr == '\n') {
Index: libvirt-acl/src/security/virt-aa-helper.c
===================================================================
--- libvirt-acl.orig/src/security/virt-aa-helper.c
+++ libvirt-acl/src/security/virt-aa-helper.c
@@ -37,6 +37,7 @@
#include "uuid.h"
#include "hostusb.h"
#include "pci.h"
+#include "files.h"
static char *progname;
@@ -278,12 +279,12 @@ update_include_file(const char *include_
}
if (safewrite(fd, pcontent, plen) < 0) { /* don't write the '\0' */
- close(fd);
+ VIR_FORCE_CLOSE(fd);
vah_error(NULL, 0, "failed to write to profile");
goto clean;
}
- if (close(fd) != 0) {
+ if (VIR_CLOSE(fd) != 0) {
vah_error(NULL, 0, "failed to close or write to profile");
goto clean;
}
@@ -385,12 +386,12 @@ create_profile(const char *profile, cons
}
if (safewrite(fd, pcontent, plen - 1) < 0) { /* don't write the '\0' */
- close(fd);
+ VIR_FORCE_CLOSE(fd);
vah_error(NULL, 0, "failed to write to profile");
goto clean_all;
}
- if (close(fd) != 0) {
+ if (VIR_CLOSE(fd) != 0) {
vah_error(NULL, 0, "failed to close or write to profile");
goto clean_all;
}
Index: libvirt-acl/src/storage/storage_backend.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend.c
+++ libvirt-acl/src/storage/storage_backend.c
@@ -51,6 +51,7 @@
#include "storage_file.h"
#include "storage_backend.h"
#include "logging.h"
+#include "files.h"
#if WITH_STORAGE_LVM
# include "storage_backend_logical.h"
@@ -181,7 +182,7 @@ virStorageBackendCopyToFD(virStorageVolD
} while ((amtleft -= 512) > 0);
}
- if (inputfd != -1 && close(inputfd) < 0) {
+ if (VIR_CLOSE(inputfd) < 0) {
ret = -errno;
virReportSystemError(errno,
_("cannot close file '%s'"),
@@ -193,8 +194,7 @@ virStorageBackendCopyToFD(virStorageVolD
*total -= remain;
cleanup:
- if (inputfd != -1)
- close(inputfd);
+ VIR_FORCE_CLOSE(inputfd);
VIR_FREE(buf);
@@ -251,7 +251,7 @@ virStorageBackendCreateBlockFrom(virConn
vol->target.path, vol->target.perms.mode);
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("cannot close file '%s'"),
vol->target.path);
@@ -261,8 +261,7 @@ virStorageBackendCreateBlockFrom(virConn
ret = 0;
cleanup:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
@@ -608,7 +607,7 @@ static int virStorageBackendQEMUImgBacki
cleanup:
VIR_FREE(help);
- close(newstdout);
+ VIR_FORCE_CLOSE(newstdout);
rewait:
if (child) {
if (waitpid(child, &status, 0) != child) {
@@ -997,7 +996,7 @@ virStorageBackendVolOpenCheckMode(const
virReportSystemError(errno,
_("cannot stat file '%s'"),
path);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -1009,7 +1008,7 @@ virStorageBackendVolOpenCheckMode(const
mode = VIR_STORAGE_VOL_OPEN_BLOCK;
if (!(mode & flags)) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (mode & VIR_STORAGE_VOL_OPEN_ERROR) {
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
@@ -1045,7 +1044,7 @@ virStorageBackendUpdateVolTargetInfo(vir
allocation,
capacity);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
@@ -1461,10 +1460,8 @@ virStorageBackendRunProgRegex(virStorage
if (list)
fclose(list);
- else {
- if (fd >= 0)
- close(fd);
- }
+ else
+ VIR_FORCE_CLOSE(fd);
while ((err = waitpid(child, &exitstatus, 0) == -1) && errno == EINTR);
Index: libvirt-acl/src/storage/storage_backend_fs.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_fs.c
+++ libvirt-acl/src/storage/storage_backend_fs.c
@@ -45,6 +45,7 @@
#include "util.h"
#include "memory.h"
#include "xml.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -72,25 +73,25 @@ virStorageBackendProbeTarget(virStorageV
if ((ret = virStorageBackendUpdateVolTargetInfoFD(target, fd,
allocation,
capacity)) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
memset(&meta, 0, sizeof(meta));
if ((target->format = virStorageFileProbeFormatFromFD(target->path, fd)) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
if (virStorageFileGetMetadataFromFD(target->path, fd,
target->format,
&meta) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (meta.backingStore) {
*backingStore = meta.backingStore;
@@ -98,7 +99,7 @@ virStorageBackendProbeTarget(virStorageV
if (meta.backingStoreFormat == VIR_STORAGE_FILE_AUTO) {
if ((*backingStoreFormat
= virStorageFileProbeFormat(*backingStore)) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
goto cleanup;
}
} else {
Index: libvirt-acl/src/storage/storage_backend_iscsi.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_iscsi.c
+++ libvirt-acl/src/storage/storage_backend_iscsi.c
@@ -41,6 +41,7 @@
#include "util.h"
#include "memory.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -237,9 +238,7 @@ out:
if (fp != NULL) {
fclose(fp);
} else {
- if (fd != -1) {
- close(fd);
- }
+ VIR_FORCE_CLOSE(fd);
}
return ret;
Index: libvirt-acl/src/storage/storage_backend_logical.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_logical.c
+++ libvirt-acl/src/storage/storage_backend_logical.c
@@ -37,6 +37,7 @@
#include "util.h"
#include "memory.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -408,10 +409,10 @@ virStorageBackendLogicalBuildPool(virCon
virReportSystemError(errno,
_("cannot clear device header of '%s'"),
pool->def->source.devices[i].path);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("cannot close device '%s'"),
pool->def->source.devices[i].path);
@@ -622,7 +623,7 @@ virStorageBackendLogicalCreateVol(virCon
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("cannot close file '%s'"),
vol->target.path);
@@ -641,8 +642,7 @@ virStorageBackendLogicalCreateVol(virCon
return 0;
cleanup:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
virStorageBackendLogicalDeleteVol(conn, pool, vol, 0);
return -1;
}
Index: libvirt-acl/src/storage/storage_backend_mpath.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_mpath.c
+++ libvirt-acl/src/storage/storage_backend_mpath.c
@@ -35,6 +35,7 @@
#include "storage_backend.h"
#include "memory.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -61,9 +62,7 @@ virStorageBackendMpathUpdateVolTargetInf
ret = 0;
out:
- if (fd != -1) {
- close(fd);
- }
+ VIR_FORCE_CLOSE(fd);
return ret;
}
Index: libvirt-acl/src/storage/storage_backend_scsi.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_scsi.c
+++ libvirt-acl/src/storage/storage_backend_scsi.c
@@ -32,6 +32,7 @@
#include "storage_backend_scsi.h"
#include "memory.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -154,8 +155,7 @@ virStorageBackendSCSIUpdateVolTargetInfo
ret = 0;
cleanup:
- if (fd >= 0)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
@@ -572,14 +572,14 @@ virStorageBackendSCSITriggerRescan(uint3
if (safewrite(fd,
LINUX_SYSFS_SCSI_HOST_SCAN_STRING,
sizeof(LINUX_SYSFS_SCSI_HOST_SCAN_STRING)) < 0) {
-
+ VIR_FORCE_CLOSE(fd);
virReportSystemError(errno,
_("Write to '%s' to trigger host scan failed"),
path);
retval = -1;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
free_path:
VIR_FREE(path);
out:
Index: libvirt-acl/src/storage/storage_driver.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_driver.c
+++ libvirt-acl/src/storage/storage_driver.c
@@ -45,6 +45,7 @@
#include "memory.h"
#include "storage_backend.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -1664,9 +1665,7 @@ storageVolumeWipeInternal(virStorageVolD
out:
VIR_FREE(writebuf);
- if (fd != -1) {
- close(fd);
- }
+ VIR_FORCE_CLOSE(fd);
return ret;
}
Index: libvirt-acl/src/test/test_driver.c
===================================================================
--- libvirt-acl.orig/src/test/test_driver.c
+++ libvirt-acl/src/test/test_driver.c
@@ -50,6 +50,7 @@
#include "xml.h"
#include "threads.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_TEST
@@ -788,8 +789,7 @@ static int testOpenFromFile(virConnectPt
_("Invalid XML in file '%s'"), file);
goto error;
}
- close(fd);
- fd = -1;
+ VIR_FORCE_CLOSE(fd);
root = xmlDocGetRootElement(xml);
if ((root == NULL) || (!xmlStrEqual(root->name, BAD_CAST "node"))) {
@@ -1101,8 +1101,7 @@ static int testOpenFromFile(virConnectPt
VIR_FREE(networks);
VIR_FREE(ifaces);
VIR_FREE(pools);
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
virDomainObjListDeinit(&privconn->domains);
virNetworkObjListFree(&privconn->networks);
virInterfaceObjListFree(&privconn->ifaces);
@@ -1752,7 +1751,7 @@ static int testDomainSave(virDomainPtr d
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("saving domain '%s' to '%s': write failed"),
domain->name, path);
@@ -1779,8 +1778,7 @@ cleanup:
* in either case we're already in a failure scenario
* and have reported a earlier error */
if (ret != 0) {
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
unlink(path);
}
if (privdom)
@@ -1870,8 +1868,7 @@ static int testDomainRestore(virConnectP
cleanup:
virDomainDefFree(def);
VIR_FREE(xml);
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (dom)
virDomainObjUnlock(dom);
if (event)
@@ -1911,7 +1908,7 @@ static int testDomainCoreDump(virDomainP
domain->name, to);
goto cleanup;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("domain '%s' coredump: write failed: %s"),
domain->name, to);
@@ -1932,8 +1929,7 @@ static int testDomainCoreDump(virDomainP
ret = 0;
cleanup:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (privdom)
virDomainObjUnlock(privdom);
if (event)
Index: libvirt-acl/src/uml/uml_conf.c
===================================================================
--- libvirt-acl.orig/src/uml/uml_conf.c
+++ libvirt-acl/src/uml/uml_conf.c
@@ -47,6 +47,7 @@
#include "bridge.h"
#include "logging.h"
#include "domain_nwfilter.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_UML
@@ -367,7 +368,7 @@ umlBuildCommandLineChr(virDomainChrDefPt
}
if (virAsprintf(&ret, "%s%d=null,fd:%d", dev, def->target.port, fd_out) < 0) {
virReportOOMError();
- close(fd_out);
+ VIR_FORCE_CLOSE(fd_out);
return NULL;
}
FD_SET(fd_out, keepfd);
Index: libvirt-acl/src/uml/uml_driver.c
===================================================================
--- libvirt-acl.orig/src/uml/uml_driver.c
+++ libvirt-acl/src/uml/uml_driver.c
@@ -59,6 +59,7 @@
#include "datatypes.h"
#include "logging.h"
#include "domain_nwfilter.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_UML
@@ -533,7 +534,7 @@ umlShutdown(void) {
umlDriverLock(uml_driver);
if (uml_driver->inotifyWatch != -1)
virEventRemoveHandle(uml_driver->inotifyWatch);
- close(uml_driver->inotifyFD);
+ VIR_FORCE_CLOSE(uml_driver->inotifyFD);
virCapabilitiesFree(uml_driver->caps);
/* shutdown active VMs
@@ -659,8 +660,7 @@ restat:
if (bind(priv->monitor, (struct sockaddr *)&addr, sizeof addr) < 0) {
virReportSystemError(errno,
"%s", _("cannot bind socket"));
- close(priv->monitor);
- priv->monitor = -1;
+ VIR_FORCE_CLOSE(priv->monitor);
return -1;
}
@@ -811,7 +811,7 @@ static int umlStartVMDaemon(virConnectPt
virDomainObjPtr vm) {
const char **argv = NULL, **tmp;
const char **progenv = NULL;
- int i, ret;
+ int i, ret, tmpfd;
pid_t pid;
char *logfile;
int logfd = -1;
@@ -870,13 +870,13 @@ static int umlStartVMDaemon(virConnectPt
if (umlSetCloseExec(logfd) < 0) {
virReportSystemError(errno,
"%s", _("Unable to set VM logfile close-on-exec flag"));
- close(logfd);
+ VIR_FORCE_CLOSE(logfd);
return -1;
}
if (umlBuildCommandLine(conn, driver, vm, &keepfd,
&argv, &progenv) < 0) {
- close(logfd);
+ VIR_FORCE_CLOSE(logfd);
virDomainConfVMNWFilterTeardown(vm);
umlCleanupTapDevices(conn, vm);
return -1;
@@ -912,15 +912,17 @@ static int umlStartVMDaemon(virConnectPt
-1, &logfd, &logfd,
VIR_EXEC_CLEAR_CAPS,
NULL, NULL, NULL);
- close(logfd);
+ VIR_FORCE_CLOSE(logfd);
/*
* At the moment, the only thing that populates keepfd is
* umlBuildCommandLineChr. We want to close every fd it opens.
*/
for (i = 0; i < FD_SETSIZE; i++)
- if (FD_ISSET(i, &keepfd))
- close(i);
+ if (FD_ISSET(i, &keepfd)) {
+ tmpfd = i;
+ VIR_FORCE_CLOSE(tmpfd);
+ }
for (i = 0 ; argv[i] ; i++)
VIR_FREE(argv[i]);
@@ -957,9 +959,7 @@ static void umlShutdownVMDaemon(virConne
virKillProcess(vm->pid, SIGTERM);
- if (priv->monitor != -1)
- close(priv->monitor);
- priv->monitor = -1;
+ VIR_FORCE_CLOSE(priv->monitor);
if ((ret = waitpid(vm->pid, NULL, 0)) != vm->pid) {
VIR_WARN("Got unexpected pid %d != %d",
Index: libvirt-acl/src/util/bridge.c
===================================================================
--- libvirt-acl.orig/src/util/bridge.c
+++ libvirt-acl/src/util/bridge.c
@@ -24,6 +24,7 @@
#if defined(WITH_BRIDGE)
# include "bridge.h"
+# include "files.h"
# include <stdlib.h>
# include <stdio.h>
@@ -81,12 +82,12 @@ brInit(brControl **ctlp)
if ((flags = fcntl(fd, F_GETFD)) < 0 ||
fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
int err = errno;
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return err;
}
if (VIR_ALLOC(*ctlp) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ENOMEM;
}
@@ -107,7 +108,7 @@ brShutdown(brControl *ctl)
if (!ctl)
return;
- close(ctl->fd);
+ VIR_FORCE_CLOSE(ctl->fd);
ctl->fd = 0;
VIR_FREE(ctl);
@@ -539,11 +540,11 @@ brAddTap(brControl *ctl,
if (tapfd)
*tapfd = fd;
else
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return 0;
error:
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return errno;
}
@@ -574,7 +575,7 @@ int brDeleteTap(brControl *ctl,
}
error:
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return errno;
}
Index: libvirt-acl/src/util/conf.c
===================================================================
--- libvirt-acl.orig/src/util/conf.c
+++ libvirt-acl/src/util/conf.c
@@ -24,6 +24,7 @@
#include "util.h"
#include "c-ctype.h"
#include "memory.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_CONF
@@ -954,7 +955,7 @@ virConfWriteFile(const char *filename, v
content = virBufferContentAndReset(&buf);
ret = safewrite(fd, content, use);
VIR_FREE(content);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (ret != (int)use) {
virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to save content"));
return -1;
Index: libvirt-acl/src/util/interface.c
===================================================================
--- libvirt-acl.orig/src/util/interface.c
+++ libvirt-acl/src/util/interface.c
@@ -39,6 +39,7 @@
#include "util.h"
#include "interface.h"
#include "virterror_internal.h"
+#include "files.h"
#define ifaceError(code, ...) \
virReportErrorHelper(NULL, VIR_FROM_NET, code, __FILE__, \
@@ -82,7 +83,7 @@ ifaceGetFlags(const char *ifname, short
*flags = ifr.ifr_flags;
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return rc;
}
@@ -161,7 +162,7 @@ static int chgIfaceFlags(const char *ifn
}
err_exit:
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return rc;
}
@@ -259,8 +260,7 @@ ifaceCheck(bool reportError, const char
}
err_exit:
- if (fd >= 0)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return rc;
}
@@ -326,7 +326,7 @@ ifaceGetIndex(bool reportError, const ch
}
err_exit:
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return rc;
}
@@ -373,7 +373,7 @@ ifaceGetVlanID(const char *vlanifname, i
*vlanid = vlanargs.u.VID;
err_exit:
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return rc;
}
Index: libvirt-acl/src/util/logging.c
===================================================================
--- libvirt-acl.orig/src/util/logging.c
+++ libvirt-acl/src/util/logging.c
@@ -40,6 +40,7 @@
#include "util.h"
#include "buf.h"
#include "threads.h"
+#include "files.h"
/*
* Macro used to format the message as a string in virLogMessage
@@ -603,8 +604,7 @@ static int virLogOutputToFd(const char *
static void virLogCloseFd(void *data) {
int fd = (long) data;
- if (fd >= 0)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
}
static int virLogAddOutputToStderr(int priority) {
@@ -622,7 +622,7 @@ static int virLogAddOutputToFile(int pri
return(-1);
if (virLogDefineOutput(virLogOutputToFd, virLogCloseFd, (void *)(long)fd,
priority, VIR_LOG_TO_FILE, file, 0) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return(-1);
}
return(0);
Index: libvirt-acl/src/util/macvtap.c
===================================================================
--- libvirt-acl.orig/src/util/macvtap.c
+++ libvirt-acl/src/util/macvtap.c
@@ -52,6 +52,7 @@
# include "conf/domain_conf.h"
# include "virterror_internal.h"
# include "uuid.h"
+# include "files.h"
# define VIR_FROM_THIS VIR_FROM_NET
@@ -94,7 +95,7 @@ static int nlOpen(void)
static void nlClose(int fd)
{
- close(fd);
+ VIR_FORCE_CLOSE(fd);
}
@@ -689,7 +690,7 @@ create_name:
if (rc >= 0) {
if (configMacvtapTap(rc, vnet_hdr) < 0) {
- close(rc);
+ VIR_FORCE_CLOSE(rc);
rc = -1;
goto disassociate_exit;
}
@@ -778,8 +779,7 @@ getLldpadPid(void) {
_("Error opening file %s"), LLDPAD_PID_FILE);
}
- if (fd >= 0)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return pid;
}
Index: libvirt-acl/src/util/pci.c
===================================================================
--- libvirt-acl.orig/src/util/pci.c
+++ libvirt-acl/src/util/pci.c
@@ -37,6 +37,7 @@
#include "memory.h"
#include "util.h"
#include "virterror_internal.h"
+#include "files.h"
/* avoid compilation breakage on some systems */
#ifndef MODPROBE
@@ -188,10 +189,7 @@ pciCloseConfig(pciDevice *dev)
if (!dev)
return;
- if (dev->fd >= 0) {
- close(dev->fd);
- dev->fd = -1;
- }
+ VIR_FORCE_CLOSE(dev->fd);
}
static int
Index: libvirt-acl/src/util/storage_file.c
===================================================================
--- libvirt-acl.orig/src/util/storage_file.c
+++ libvirt-acl/src/util/storage_file.c
@@ -36,6 +36,7 @@
#include "memory.h"
#include "virterror_internal.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -688,7 +689,7 @@ virStorageFileProbeFormat(const char *pa
ret = virStorageFileProbeFormatFromFD(path, fd);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
@@ -782,7 +783,7 @@ virStorageFileGetMetadata(const char *pa
ret = virStorageFileGetMetadataFromFD(path, fd, format, meta);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
Index: libvirt-acl/src/util/util.c
===================================================================
--- libvirt-acl.orig/src/util/util.c
+++ libvirt-acl/src/util/util.c
@@ -71,6 +71,7 @@
#include "memory.h"
#include "threads.h"
#include "verify.h"
+#include "files.h"
#ifndef NSIG
# define NSIG 32
@@ -461,6 +462,7 @@ __virExec(const char *const*argv,
int pipeerr[2] = {-1,-1};
int childout = -1;
int childerr = -1;
+ int tmpfd;
if ((null = open("/dev/null", O_RDONLY)) < 0) {
virReportSystemError(errno,
@@ -534,13 +536,13 @@ __virExec(const char *const*argv,
}
if (pid) { /* parent */
- close(null);
+ VIR_FORCE_CLOSE(null);
if (outfd && *outfd == -1) {
- close(pipeout[1]);
+ VIR_FORCE_CLOSE(pipeout[1]);
*outfd = pipeout[0];
}
if (errfd && *errfd == -1) {
- close(pipeerr[1]);
+ VIR_FORCE_CLOSE(pipeerr[1]);
*errfd = pipeerr[0];
}
@@ -568,8 +570,10 @@ __virExec(const char *const*argv,
i != childout &&
i != childerr &&
(!keepfd ||
- !FD_ISSET(i, keepfd)))
- close(i);
+ !FD_ISSET(i, keepfd))) {
+ tmpfd = i;
+ VIR_FORCE_CLOSE(tmpfd);
+ }
if (dup2(infd >= 0 ? infd : null, STDIN_FILENO) < 0) {
virReportSystemError(errno,
@@ -589,14 +593,15 @@ __virExec(const char *const*argv,
goto fork_error;
}
- if (infd > 0)
- close(infd);
- close(null);
- if (childout > 0)
- close(childout);
+ VIR_FORCE_CLOSE(infd);
+ VIR_FORCE_CLOSE(null);
+ tmpfd = childout; /* preserve childout value */
+ VIR_FORCE_CLOSE(tmpfd);
if (childerr > 0 &&
- childerr != childout)
- close(childerr);
+ childerr != childout) {
+ VIR_FORCE_CLOSE(childerr);
+ childout = -1;
+ }
/* Daemonize as late as possible, so the parent process can detect
* the above errors with wait* */
@@ -666,16 +671,11 @@ __virExec(const char *const*argv,
/* NB we don't virUtilError() on any failures here
because the code which jumped hre already raised
an error condition which we must not overwrite */
- if (pipeerr[0] > 0)
- close(pipeerr[0]);
- if (pipeerr[1] > 0)
- close(pipeerr[1]);
- if (pipeout[0] > 0)
- close(pipeout[0]);
- if (pipeout[1] > 0)
- close(pipeout[1]);
- if (null > 0)
- close(null);
+ VIR_FORCE_CLOSE(pipeerr[0]);
+ VIR_FORCE_CLOSE(pipeerr[1]);
+ VIR_FORCE_CLOSE(pipeout[0]);
+ VIR_FORCE_CLOSE(pipeout[1]);
+ VIR_FORCE_CLOSE(null);
return -1;
}
@@ -865,10 +865,8 @@ virRunWithHook(const char *const*argv,
VIR_FREE(outbuf);
VIR_FREE(errbuf);
VIR_FREE(argv_str);
- if (outfd != -1)
- close(outfd);
- if (errfd != -1)
- close(errfd);
+ VIR_FORCE_CLOSE(outfd);
+ VIR_FORCE_CLOSE(errfd);
return ret;
}
@@ -1099,7 +1097,7 @@ int virFileReadAll(const char *path, int
}
int len = virFileReadLimFD(fd, maxlen, buf);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (len < 0) {
virReportSystemError(errno, _("Failed to read file '%s'"), path);
return -1;
@@ -1305,7 +1303,7 @@ static int virFileOperationNoFork(const
if ((hook) && ((ret = hook(fd, hookdata)) != 0)) {
goto error;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
ret = -errno;
virReportSystemError(errno, _("failed to close new file '%s'"),
path);
@@ -1314,8 +1312,7 @@ static int virFileOperationNoFork(const
}
fd = -1;
error:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
@@ -1466,7 +1463,7 @@ parenterror:
if ((hook) && ((ret = hook(fd, hookdata)) != 0)) {
goto childerror;
}
- if (close(fd) < 0) {
+ if (VIR_CLOSE(fd) < 0) {
ret = -errno;
virReportSystemError(errno, _("child failed to close new file '%s'"),
path);
@@ -1743,10 +1740,8 @@ int virFileOpenTtyAt(const char *ptmx,
rc = 0;
cleanup:
- if (rc != 0 &&
- *ttymaster != -1) {
- close(*ttymaster);
- }
+ if (rc != 0)
+ VIR_FORCE_CLOSE(*ttymaster);
return rc;
@@ -1812,7 +1807,7 @@ int virFileWritePidPath(const char *pidf
if (!(file = fdopen(fd, "w"))) {
rc = errno;
- close(fd);
+ VIR_FORCE_CLOSE(fd);
goto cleanup;
}
Index: libvirt-acl/src/util/uuid.c
===================================================================
--- libvirt-acl.orig/src/util/uuid.c
+++ libvirt-acl/src/util/uuid.c
@@ -39,6 +39,7 @@
#include "virterror_internal.h"
#include "logging.h"
#include "memory.h"
+#include "files.h"
#ifndef ENODATA
# define ENODATA EIO
@@ -61,7 +62,7 @@ virUUIDGenerateRandomBytes(unsigned char
if ((n = read(fd, buf, buflen)) <= 0) {
if (errno == EINTR)
continue;
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return n < 0 ? errno : ENODATA;
}
@@ -69,7 +70,7 @@ virUUIDGenerateRandomBytes(unsigned char
buflen -= n;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return 0;
}
@@ -240,10 +241,10 @@ getDMISystemUUID(char *uuid, int len)
int fd = open(paths[i], O_RDONLY);
if (fd > 0) {
if (saferead(fd, uuid, len) == len) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return 0;
}
- close(fd);
+ VIR_FORCE_CLOSE(fd);
}
i++;
}
Index: libvirt-acl/src/util/virtaudit.c
===================================================================
--- libvirt-acl.orig/src/util/virtaudit.c
+++ libvirt-acl/src/util/virtaudit.c
@@ -30,6 +30,7 @@
#include "virterror_internal.h"
#include "logging.h"
#include "virtaudit.h"
+#include "files.h"
/* Provide the macros in case the header file is old.
FIXME: should be removed. */
@@ -133,6 +134,6 @@ void virAuditSend(const char *file ATTRI
void virAuditClose(void)
{
#if HAVE_AUDIT
- close(auditfd);
+ VIR_CLOSE(auditfd);
#endif
}
Index: libvirt-acl/src/xen/proxy_internal.c
===================================================================
--- libvirt-acl.orig/src/xen/proxy_internal.c
+++ libvirt-acl/src/xen/proxy_internal.c
@@ -30,6 +30,7 @@
#include "util.h"
#include "xen_driver.h"
#include "memory.h"
+#include "files.h"
#define STANDALONE
@@ -196,7 +197,7 @@ retry:
addr.sun_family = AF_UNIX;
addr.sun_path[0] = '\0';
if (virStrcpy(&addr.sun_path[1], path, sizeof(addr.sun_path) - 1) == NULL) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -204,7 +205,7 @@ retry:
* now bind the socket to that address and listen on it
*/
if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- close(fd);
+ VIR_FORCE_CLOSE(fd);
if (trials < 3) {
if (virProxyForkServer() < 0)
return(-1);
@@ -236,12 +237,11 @@ virProxyCloseSocket(xenUnifiedPrivatePtr
if (priv->proxy < 0)
return(-1);
- ret = close(priv->proxy);
+ ret = VIR_CLOSE(priv->proxy);
if (ret != 0)
VIR_WARN("Failed to close socket %d", priv->proxy);
else
VIR_DEBUG("Closed socket %d", priv->proxy);
- priv->proxy = -1;
return(ret);
}
Index: libvirt-acl/src/xen/xen_hypervisor.c
===================================================================
--- libvirt-acl.orig/src/xen/xen_hypervisor.c
+++ libvirt-acl/src/xen/xen_hypervisor.c
@@ -65,6 +65,7 @@
#include "buf.h"
#include "capabilities.h"
#include "memory.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_XEN
@@ -2036,7 +2037,7 @@ xenHypervisorInit(void)
hypervisor_version = -1;
virXenError(VIR_ERR_XEN_CALL, " ioctl %lu",
(unsigned long) IOCTL_PRIVCMD_HYPERCALL);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
in_init = 0;
return(-1);
@@ -2122,13 +2123,13 @@ xenHypervisorInit(void)
hypervisor_version = -1;
virXenError(VIR_ERR_XEN_CALL, " ioctl %lu",
(unsigned long)IOCTL_PRIVCMD_HYPERCALL);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
in_init = 0;
VIR_FREE(ipt);
return(-1);
done:
- close(fd);
+ VIR_FORCE_CLOSE(fd);
in_init = 0;
VIR_FREE(ipt);
return(0);
@@ -2191,7 +2192,7 @@ xenHypervisorClose(virConnectPtr conn)
if (priv->handle < 0)
return -1;
- ret = close(priv->handle);
+ ret = VIR_CLOSE(priv->handle);
if (ret < 0)
return (-1);
@@ -2396,8 +2397,7 @@ get_cpu_flags(virConnectPtr conn, const
ret = 1;
out:
- if (fd != -1)
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
Index: libvirt-acl/src/xen/xen_inotify.c
===================================================================
--- libvirt-acl.orig/src/xen/xen_inotify.c
+++ libvirt-acl/src/xen/xen_inotify.c
@@ -39,6 +39,7 @@
#include "xend_internal.h"
#include "logging.h"
#include "uuid.h"
+#include "files.h"
#include "xm_internal.h" /* for xenXMDomainConfigParse */
@@ -483,7 +484,7 @@ xenInotifyClose(virConnectPtr conn)
if (priv->inotifyWatch != -1)
virEventRemoveHandle(priv->inotifyWatch);
- close(priv->inotifyFD);
+ VIR_FORCE_CLOSE(priv->inotifyFD);
return 0;
}
Index: libvirt-acl/src/xen/xend_internal.c
===================================================================
--- libvirt-acl.orig/src/xen/xend_internal.c
+++ libvirt-acl/src/xen/xend_internal.c
@@ -45,6 +45,7 @@
#include "xs_internal.h" /* To extract VNC port & Serial console TTY */
#include "memory.h"
#include "count-one-bits.h"
+#include "files.h"
/* required for cpumap_t */
#include <xen/dom0_ops.h>
@@ -118,7 +119,6 @@ static int
do_connect(virConnectPtr xend)
{
int s;
- int serrno;
int no_slow_start = 1;
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) xend->privateData;
@@ -137,9 +137,7 @@ do_connect(virConnectPtr xend)
if (connect(s, (struct sockaddr *)&priv->addr, priv->addrlen) == -1) {
- serrno = errno;
- close(s);
- errno = serrno;
+ VIR_FORCE_CLOSE(s);
s = -1;
/*
@@ -387,7 +385,7 @@ xend_get(virConnectPtr xend, const char
"Content-Type: application/x-www-form-urlencoded\r\n" "\r\n");
ret = xend_req(s, content);
- close(s);
+ VIR_FORCE_CLOSE(s);
if (((ret < 0) || (ret >= 300)) &&
((ret != 404) || (!STRPREFIX(path, "/xend/domain/")))) {
@@ -437,7 +435,7 @@ xend_post(virConnectPtr xend, const char
swrites(s, ops);
ret = xend_req(s, &err_buf);
- close(s);
+ VIR_FORCE_CLOSE(s);
if ((ret < 0) || (ret >= 300)) {
virXendError(VIR_ERR_POST_FAILED,
@@ -843,7 +841,7 @@ xenDaemonOpen_tcp(virConnectPtr conn, co
memcpy(&priv->addr,
r->ai_addr,
r->ai_addrlen);
- close(sock);
+ VIR_FORCE_CLOSE(sock);
break;
}
Index: libvirt-acl/daemon/libvirtd.c
===================================================================
--- libvirt-acl.orig/daemon/libvirtd.c
+++ libvirt-acl/daemon/libvirtd.c
@@ -50,6 +50,7 @@
#include "libvirt_internal.h"
#include "virterror_internal.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -425,7 +426,7 @@ static int daemonForkIntoBackground(void
int stdoutfd = -1;
int nextpid;
- close(statuspipe[0]);
+ VIR_FORCE_CLOSE(statuspipe[0]);
if ((stdinfd = open("/dev/null", O_RDONLY)) < 0)
goto cleanup;
@@ -437,12 +438,10 @@ static int daemonForkIntoBackground(void
goto cleanup;
if (dup2(stdoutfd, STDERR_FILENO) != STDERR_FILENO)
goto cleanup;
- if (close(stdinfd) < 0)
+ if (VIR_CLOSE(stdinfd) < 0)
goto cleanup;
- stdinfd = -1;
- if (close(stdoutfd) < 0)
+ if (VIR_CLOSE(stdoutfd) < 0)
goto cleanup;
- stdoutfd = -1;
if (setsid() < 0)
goto cleanup;
@@ -458,10 +457,8 @@ static int daemonForkIntoBackground(void
}
cleanup:
- if (stdoutfd != -1)
- close(stdoutfd);
- if (stdinfd != -1)
- close(stdinfd);
+ VIR_FORCE_CLOSE(stdoutfd);
+ VIR_FORCE_CLOSE(stdinfd);
return -1;
}
@@ -475,7 +472,7 @@ static int daemonForkIntoBackground(void
int ret;
char status;
- close(statuspipe[1]);
+ VIR_FORCE_CLOSE(statuspipe[1]);
/* We wait to make sure the first child forked successfully */
if ((got = waitpid(pid, &exitstatus, 0)) < 0 ||
@@ -518,7 +515,7 @@ static int qemudWritePidFile(const char
if (!(fh = fdopen(fd, "w"))) {
VIR_ERROR(_("Failed to fdopen pid file '%s' : %s"),
pidFile, virStrerror(errno, ebuf, sizeof ebuf));
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -607,8 +604,7 @@ static int qemudListenUnix(struct qemud_
return 0;
cleanup:
- if (sock->fd >= 0)
- close(sock->fd);
+ VIR_FORCE_CLOSE(sock->fd);
VIR_FREE(sock);
return -1;
}
@@ -745,7 +741,7 @@ remoteListenTCP (struct qemud_server *se
cleanup:
for (i = 0; i < nfds; ++i)
- close(fds[i]);
+ VIR_FORCE_CLOSE(fds[i]);
return -1;
}
@@ -1518,10 +1514,7 @@ void qemudDispatchClientFailure(struct q
gnutls_deinit (client->tlssession);
client->tlssession = NULL;
}
- if (client->fd != -1) {
- close(client->fd);
- client->fd = -1;
- }
+ VIR_FORCE_CLOSE(client->fd);
}
@@ -2421,17 +2414,15 @@ static int qemudStartEventLoop(struct qe
static void qemudCleanup(struct qemud_server *server) {
struct qemud_socket *sock;
- if (server->sigread != -1)
- close(server->sigread);
- if (server->sigwrite != -1)
- close(server->sigwrite);
+ VIR_FORCE_CLOSE(server->sigread);
+ VIR_FORCE_CLOSE(server->sigwrite);
sock = server->sockets;
while (sock) {
struct qemud_socket *next = sock->next;
if (sock->watch)
virEventRemoveHandleImpl(sock->watch);
- close(sock->fd);
+ VIR_FORCE_CLOSE(sock->fd);
/* Unlink unix domain sockets which are not in
* the abstract namespace */
@@ -2986,8 +2977,8 @@ daemonSetupSignals(struct qemud_server *
return 0;
error:
- close(sigpipe[0]);
- close(sigpipe[1]);
+ VIR_FORCE_CLOSE(sigpipe[0]);
+ VIR_FORCE_CLOSE(sigpipe[1]);
return -1;
}
@@ -3244,8 +3235,7 @@ int main(int argc, char **argv) {
while (write(statuswrite, &status, 1) == -1 &&
errno == EINTR)
;
- close(statuswrite);
- statuswrite = -1;
+ VIR_FORCE_CLOSE(statuswrite);
}
/* Start the event loop in a background thread, since
@@ -3302,7 +3292,7 @@ error:
errno == EINTR)
;
}
- close(statuswrite);
+ VIR_FORCE_CLOSE(statuswrite);
}
if (server)
qemudCleanup(server);
Index: libvirt-acl/src/util/hooks.c
===================================================================
--- libvirt-acl.orig/src/util/hooks.c
+++ libvirt-acl/src/util/hooks.c
@@ -36,6 +36,7 @@
#include "conf/domain_conf.h"
#include "logging.h"
#include "memory.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_HOOK
@@ -368,7 +369,7 @@ virHookCall(int driver, const char *id,
}
ret = virExec(argv, env, NULL, &pid, pipefd[0], &outfd, &errfd,
VIR_EXEC_NONE | VIR_EXEC_NONBLOCK);
- if (close(pipefd[1]) < 0) {
+ if (VIR_CLOSE(pipefd[1]) < 0) {
virReportSystemError(errno, "%s",
_("unable to close pipe for hook input"));
}
@@ -418,17 +419,13 @@ virHookCall(int driver, const char *id,
}
cleanup:
- if (pipefd[0] >= 0) {
- if (close(pipefd[0]) < 0) {
- virReportSystemError(errno, "%s",
- _("unable to close pipe for hook input"));
- }
- }
- if (pipefd[1] >= 0) {
- if (close(pipefd[1]) < 0) {
- virReportSystemError(errno, "%s",
- _("unable to close pipe for hook input"));
- }
+ if (VIR_CLOSE(pipefd[0]) < 0) {
+ virReportSystemError(errno, "%s",
+ _("unable to close pipe for hook input"));
+ }
+ if (VIR_CLOSE(pipefd[1]) < 0) {
+ virReportSystemError(errno, "%s",
+ _("unable to close pipe for hook input"));
}
if (argv) {
for (i = 0 ; i < argc ; i++)
Index: libvirt-acl/tests/testutils.c
===================================================================
--- libvirt-acl.orig/tests/testutils.c
+++ libvirt-acl/tests/testutils.c
@@ -47,6 +47,8 @@
((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
+#include "files.h"
+
static unsigned int testDebug = -1;
static unsigned int testVerbose = -1;
@@ -205,7 +207,7 @@ int virtTestLoadFile(const char *file,
static
void virtTestCaptureProgramExecChild(const char *const argv[],
int pipefd) {
- int i;
+ int i, tmpfd;
int open_max;
int stdinfd = -1;
const char *const env[] = {
@@ -222,8 +224,10 @@ void virtTestCaptureProgramExecChild(con
open_max = sysconf (_SC_OPEN_MAX);
for (i = 0; i < open_max; i++) {
if (i != stdinfd &&
- i != pipefd)
- close(i);
+ i != pipefd) {
+ tmpfd = i;
+ VIR_FORCE_CLOSE(tmpfd);
+ }
}
if (dup2(stdinfd, STDIN_FILENO) != STDIN_FILENO)
@@ -237,8 +241,7 @@ void virtTestCaptureProgramExecChild(con
execve(argv[0], (char *const*)argv, (char *const*)env);
cleanup:
- if (stdinfd != -1)
- close(stdinfd);
+ VIR_FORCE_CLOSE(stdinfd);
}
int virtTestCaptureProgramOutput(const char *const argv[],
@@ -252,10 +255,10 @@ int virtTestCaptureProgramOutput(const c
int pid = fork();
switch (pid) {
case 0:
- close(pipefd[0]);
+ VIR_FORCE_CLOSE(pipefd[0]);
virtTestCaptureProgramExecChild(argv, pipefd[1]);
- close(pipefd[1]);
+ VIR_FORCE_CLOSE(pipefd[1]);
_exit(1);
case -1:
@@ -267,7 +270,7 @@ int virtTestCaptureProgramOutput(const c
int ret = -1;
int want = buflen-1;
- close(pipefd[1]);
+ VIR_FORCE_CLOSE(pipefd[1]);
while (want) {
if ((ret = read(pipefd[0], (*buf)+got, want)) <= 0)
@@ -275,7 +278,7 @@ int virtTestCaptureProgramOutput(const c
got += ret;
want -= ret;
}
- close(pipefd[0]);
+ VIR_FORCE_CLOSE(pipefd[0]);
if (!ret)
(*buf)[got] = '\0';
Index: libvirt-acl/proxy/libvirt_proxy.c
===================================================================
--- libvirt-acl.orig/proxy/libvirt_proxy.c
+++ libvirt-acl/proxy/libvirt_proxy.c
@@ -31,6 +31,7 @@
# include "xend_internal.h"
# include "xs_internal.h"
# include "xen_driver.h"
+# include "files.h"
static int fdServer = -1;
static int debug = 0;
@@ -133,10 +134,9 @@ proxyCloseUnixSocket(void) {
if (fdServer < 0)
return(0);
- ret = close(fdServer);
if (debug > 0)
fprintf(stderr, "closing unix socket %d: %d\n", fdServer, ret);
- fdServer = -1;
+ ret = VIR_CLOSE(fdServer);
pollInfos[0].fd = -1;
return(ret);
}
@@ -172,7 +172,7 @@ proxyListenUnixSocket(const char *path)
addr.sun_path[0] = '\0';
if (virStrcpy(&addr.sun_path[1], path, sizeof(addr.sun_path) - 1) == NULL) {
fprintf(stderr, "Path %s too long to fit into destination\n", path);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -181,12 +181,12 @@ proxyListenUnixSocket(const char *path)
*/
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
fprintf(stderr, "Failed to bind to socket %s\n", path);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return (-1);
}
if (listen(fd, 30 /* backlog */ ) < 0) {
fprintf(stderr, "Failed to listen to socket %s\n", path);
- close(fd);
+ VIR_FORCE_CLOSE(fd);
return (-1);
}
@@ -230,7 +230,7 @@ retry:
if (nbClients >= MAX_CLIENT) {
fprintf(stderr, "Too many client registered\n");
- close(client);
+ VIR_FORCE_CLOSE(client);
return(-1);
}
nbClients++;
@@ -260,7 +260,7 @@ static int
proxyCloseClientSocket(int nr) {
int ret;
- ret = close(pollInfos[nr].fd);
+ ret = VIR_CLOSE(pollInfos[nr].fd);
if (ret != 0)
fprintf(stderr, "Failed to close socket %d from client %d\n",
pollInfos[nr].fd, nr);
@@ -285,7 +285,7 @@ proxyCloseClientSockets(void) {
int i, ret;
for (i = 1;i <= nbClients;i++) {
- ret = close(pollInfos[i].fd);
+ ret = VIR_CLOSE(pollInfos[i].fd);
if (ret != 0)
fprintf(stderr, "Failed to close socket %d from client %d\n",
pollInfos[i].fd, i);
Index: libvirt-acl/tools/console.c
===================================================================
--- libvirt-acl.orig/tools/console.c
+++ libvirt-acl/tools/console.c
@@ -39,6 +39,7 @@
# include "internal.h"
# include "logging.h"
# include "util.h"
+# include "files.h"
/* ie Ctrl-] as per telnet */
# define CTRL_CLOSE_BRACKET '\35'
@@ -192,7 +193,7 @@ int vshRunConsole(const char *tty) {
tcsetattr(STDIN_FILENO, TCSAFLUSH, &ttyattr);
closetty:
- close(ttyfd);
+ VIR_FORCE_CLOSE(ttyfd);
return ret;
}
14 years, 1 month