[libvirt] [PATCH] maint: use gnulib configmake rather than open-coding things
by Eric Blake
In some cases, we were just plain confusing (BINDIR expanded to
$(libexecdir), GETTEXT_PACKAGE redefined PACKAGE for no apparant
reason); in other cases, we might as well benefit from gnulib doing
the work for us (PKGDATADIR), sometimes with different spellings
(LOCAL_STATE_DIR vs. LOCALSTATEDIR).
* bootstrap.conf (gnulib_modules): Add configmake.
* daemon/Makefile.am (libvirtd_CFLAGS): Drop defines provided by
gnulib.
* src/Makefile.am (INCLUDES): Likewise.
* tests/Makefile.am (INCLUDES): Likewise.
* tools/Makefile.am (virsh_CFLAGS): Likewise.
* daemon/libvirtd.c (qemudInitPaths, usage, main): Update
clients.
* src/cpu/cpu_map.c (CPUMAPFILE): Likewise.
* src/driver.c (DEFAULT_DRIVER_DIR): Likewise.
* src/internal.h (_): Likewise.
* src/libvirt.c (virInitialize): Likewise.
* src/lxc/lxc_conf.h (LXC_CONFIG_DIR, LXC_STATE_DIR, LXC_LOG_DIR):
Likewise.
* src/lxc/lxc_conf.c (lxcCapsInit, lxcLoadDriverConfig):
Likewise.
* src/network/bridge_driver.c (NETWORK_PID_DIR)
(NETWORK_STATE_DIR, DNSMASQ_STATE_DIR, networkStartup): Likewise.
* src/nwfilter/nwfilter_driver.c (nwfilterDriverStartup):
Likewise.
* src/qemu/qemu_conf.c (qemudLoadDriverConfig): Likewise.
* src/qemu/qemu_driver.c (qemudStartup): Likewise.
* src/remote/remote_driver.h (LIBVIRTD_PRIV_UNIX_SOCKET)
(LIBVIRTD_PRIV_UNIX_SOCKET_RO, LIBVIRTD_CONFIGURATION_FILE)
(LIBVIRT_PKI_DIR): Likewise.
* src/secret/secret_driver.c (secretDriverStartup): Likewise.
* src/security/security_apparmor.c (VIRT_AA_HELPER): Likewise.
* src/security/virt-aa-helper.c (main): Likewise.
* src/storage/storage_backend_disk.c (PARTHELPER): Likewise.
* src/storage/storage_driver.c (storageDriverStartup): Likewise.
* src/uml/uml_driver.c (TEMPDIR, umlStartup): Likewise.
* src/util/hooks.c (LIBVIRT_HOOK_DIR): Likewise.
* tools/virsh.c (main): Likewise.
* docs/hooks.html.in: Likewise.
---
bootstrap.conf | 1 +
daemon/Makefile.am | 6 ++----
daemon/libvirtd.c | 14 ++++++++------
docs/hooks.html.in | 2 +-
src/Makefile.am | 8 --------
src/cpu/cpu_map.c | 4 ++--
src/driver.c | 3 ++-
src/internal.h | 2 +-
src/libvirt.c | 3 ++-
src/lxc/lxc_conf.c | 7 ++++---
src/lxc/lxc_conf.h | 7 ++++---
src/network/bridge_driver.c | 11 ++++++-----
src/nwfilter/nwfilter_driver.c | 6 +++---
src/qemu/qemu_conf.c | 6 ++++--
src/qemu/qemu_driver.c | 16 ++++++++--------
src/remote/remote_driver.h | 12 +++++++-----
src/secret/secret_driver.c | 3 ++-
src/security/security_apparmor.c | 5 +++--
src/security/virt-aa-helper.c | 7 ++++---
src/storage/storage_backend_disk.c | 3 ++-
src/storage/storage_driver.c | 5 +++--
src/uml/uml_driver.c | 9 +++++----
src/util/hooks.c | 3 ++-
tests/Makefile.am | 1 -
tools/Makefile.am | 2 --
tools/virsh.c | 5 +++--
26 files changed, 79 insertions(+), 72 deletions(-)
diff --git a/bootstrap.conf b/bootstrap.conf
index 12f64c8..2ad1957 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -25,6 +25,7 @@ c-ctype
canonicalize-lgpl
close
connect
+configmake
count-one-bits
crypto/md5
dirname-lgpl
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 8808226..72778e5 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -85,12 +85,10 @@ libvirtd_CFLAGS = \
-I$(top_srcdir)/src/remote \
$(LIBXML_CFLAGS) $(GNUTLS_CFLAGS) $(SASL_CFLAGS) \
$(POLKIT_CFLAGS) \
- $(WARN_CFLAGS) -DLOCAL_STATE_DIR="\"$(localstatedir)\"" \
+ $(WARN_CFLAGS) \
$(COVERAGE_CFLAGS) \
- -DSYSCONF_DIR="\"$(sysconfdir)\"" \
-DQEMUD_PID_FILE="\"$(QEMUD_PID_FILE)\"" \
- -DREMOTE_PID_FILE="\"$(REMOTE_PID_FILE)\"" \
- -DGETTEXT_PACKAGE=\"$(PACKAGE)\"
+ -DREMOTE_PID_FILE="\"$(REMOTE_PID_FILE)\""
libvirtd_LDFLAGS = \
$(WARN_CFLAGS) \
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 9446638..aab7667 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -137,6 +137,8 @@ static int unix_sock_ro_mask = 0777; /* Allow world */
#endif /* __sun */
+#include "configmake.h"
+
static int godaemon = 0; /* -d: Be a daemon */
static int verbose = 0; /* -v: Verbose mode */
static int timeout = -1; /* -t: Shutdown timeout */
@@ -745,7 +747,7 @@ static int qemudInitPaths(struct qemud_server *server,
/* The base_dir_prefix is the base under which all libvirtd
* files live */
if (server->privileged) {
- if (!(base_dir_prefix = strdup (LOCAL_STATE_DIR)))
+ if (!(base_dir_prefix = strdup (LOCALSTATEDIR)))
goto no_memory;
} else {
uid_t uid = geteuid();
@@ -3038,9 +3040,9 @@ libvirt management daemon:\n\
%s\n\
\n"),
argv0,
- SYSCONF_DIR,
- LOCAL_STATE_DIR,
- LOCAL_STATE_DIR,
+ SYSCONFDIR,
+ LOCALSTATEDIR,
+ LOCALSTATEDIR,
LIBVIRT_CACERT,
LIBVIRT_SERVERCERT,
LIBVIRT_SERVERKEY,
@@ -3137,7 +3139,7 @@ int main(int argc, char **argv) {
if (remote_config_file == NULL) {
static const char *default_config_file
- = SYSCONF_DIR "/libvirt/libvirtd.conf";
+ = SYSCONFDIR "/libvirt/libvirtd.conf";
remote_config_file =
(access(default_config_file, R_OK) == 0
? default_config_file
@@ -3169,7 +3171,7 @@ int main(int argc, char **argv) {
/* Ensure the rundir exists (on tmpfs on some systems) */
if (geteuid() == 0) {
- const char *rundir = LOCAL_STATE_DIR "/run/libvirt";
+ const char *rundir = LOCALSTATEDIR "/run/libvirt";
if (mkdir (rundir, 0755)) {
if (errno != EEXIST) {
diff --git a/docs/hooks.html.in b/docs/hooks.html.in
index 2ce785f..3503f8c 100644
--- a/docs/hooks.html.in
+++ b/docs/hooks.html.in
@@ -19,7 +19,7 @@
<h2><a name="location">Script location</a></h2>
<p>The libvirt hook scripts are located in the directory
- <code>$SYSCONF_DIR/libvirt/hooks/</code>.</p>
+ <code>$SYSCONFDIR/libvirt/hooks/</code>.</p>
<ul>
<li>In Linux distributions such as Fedora and RHEL, this is
<code>/etc/libvirt/hooks/</code>. Other Linux distributions may do
diff --git a/src/Makefile.am b/src/Makefile.am
index 20c0c9f..a9a1986 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,14 +11,6 @@ INCLUDES = \
-I@top_srcdir@/include \
$(DRIVER_MODULE_CFLAGS) \
$(LIBXML_CFLAGS) \
- -DLIBDIR=\""$(libdir)"\" \
- -DBINDIR=\""$(libexecdir)"\" \
- -DSBINDIR=\""$(sbindir)"\" \
- -DSYSCONF_DIR="\"$(sysconfdir)\"" \
- -DLOCALEBASEDIR=\""$(datadir)/locale"\" \
- -DPKGDATADIR=\""$(pkgdatadir)"\" \
- -DLOCAL_STATE_DIR=\""$(localstatedir)"\" \
- -DGETTEXT_PACKAGE=\"$(PACKAGE)\" \
$(WARN_CFLAGS) \
$(LOCK_CHECKING_CFLAGS) \
-DIN_LIBVIRT \
diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c
index 263bb9e..0c5ff8a 100644
--- a/src/cpu/cpu_map.c
+++ b/src/cpu/cpu_map.c
@@ -1,7 +1,7 @@
/*
* cpu_map.c: internal functions for handling CPU mapping configuration
*
- * Copyright (C) 2009 Red Hat, Inc.
+ * Copyright (C) 2009-2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -26,7 +26,7 @@
#include "memory.h"
#include "cpu.h"
#include "cpu_map.h"
-
+#include "configmake.h"
#define VIR_FROM_THIS VIR_FROM_CPU
diff --git a/src/driver.c b/src/driver.c
index a6f5558..d83b1fd 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -1,7 +1,7 @@
/*
* driver.c: Helpers for loading drivers
*
- * Copyright (C) 2006-2009 Red Hat, Inc.
+ * Copyright (C) 2006-2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -28,6 +28,7 @@
#include "memory.h"
#include "logging.h"
#include "util.h"
+#include "configmake.h"
#define DEFAULT_DRIVER_DIR LIBDIR "/libvirt/drivers"
diff --git a/src/internal.h b/src/internal.h
index fab3e11..a98daa3 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -52,7 +52,7 @@
# define INET_ADDRSTRLEN 16
# endif
-# define _(str) dgettext(GETTEXT_PACKAGE, (str))
+# define _(str) dgettext(PACKAGE, (str))
# define N_(str) str
/* String equality tests, suggested by Jim Meyering. */
diff --git a/src/libvirt.c b/src/libvirt.c
index 3c8bf30..eba0dee 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -39,6 +39,7 @@
#include "uuid.h"
#include "util.h"
#include "memory.h"
+#include "configmake.h"
#ifndef WITH_DRIVER_MODULES
# ifdef WITH_TEST
@@ -342,7 +343,7 @@ virInitialize(void)
if (winsock_init () == -1) return -1;
#endif
- if (!bindtextdomain(GETTEXT_PACKAGE, LOCALEBASEDIR))
+ if (!bindtextdomain(PACKAGE, LOCALEDIR))
return (-1);
/*
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index f4479e6..59d1161 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2010 Red Hat, Inc.
* Copyright IBM Corp. 2008
*
* lxc_conf.c: config functions for managing linux containers
@@ -34,7 +35,7 @@
#include "memory.h"
#include "logging.h"
#include "uuid.h"
-
+#include "configmake.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -73,7 +74,7 @@ virCapsPtr lxcCapsInit(void)
"exe",
utsname.machine,
sizeof(int) == 4 ? 32 : 8,
- BINDIR "/libvirt_lxc",
+ LIBEXECDIR "/libvirt_lxc",
NULL,
0,
NULL)) == NULL)
@@ -114,7 +115,7 @@ int lxcLoadDriverConfig(lxc_driver_t *driver)
goto no_memory;
- if ((filename = strdup(SYSCONF_DIR "/libvirt/lxc.conf")) == NULL)
+ if ((filename = strdup(SYSCONFDIR "/libvirt/lxc.conf")) == NULL)
goto no_memory;
/* Avoid error from non-existant or unreadable file. */
diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h
index e4c2c52..f820d6d 100644
--- a/src/lxc/lxc_conf.h
+++ b/src/lxc/lxc_conf.h
@@ -33,10 +33,11 @@
# include "capabilities.h"
# include "threads.h"
# include "cgroup.h"
+# include "configmake.h"
-# define LXC_CONFIG_DIR SYSCONF_DIR "/libvirt/lxc"
-# define LXC_STATE_DIR LOCAL_STATE_DIR "/run/libvirt/lxc"
-# define LXC_LOG_DIR LOCAL_STATE_DIR "/log/libvirt/lxc"
+# define LXC_CONFIG_DIR SYSCONFDIR "/libvirt/lxc"
+# define LXC_STATE_DIR LOCALSTATEDIR "/run/libvirt/lxc"
+# define LXC_LOG_DIR LOCALSTATEDIR "/log/libvirt/lxc"
# define LXC_AUTOSTART_DIR LXC_CONFIG_DIR "/autostart"
typedef struct __lxc_driver lxc_driver_t;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 631fbf1..54890f9 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -58,11 +58,12 @@
#include "logging.h"
#include "dnsmasq.h"
#include "util/network.h"
+#include "configmake.h"
-#define NETWORK_PID_DIR LOCAL_STATE_DIR "/run/libvirt/network"
-#define NETWORK_STATE_DIR LOCAL_STATE_DIR "/lib/libvirt/network"
+#define NETWORK_PID_DIR LOCALSTATEDIR "/run/libvirt/network"
+#define NETWORK_STATE_DIR LOCALSTATEDIR "/lib/libvirt/network"
-#define DNSMASQ_STATE_DIR LOCAL_STATE_DIR "/lib/libvirt/dnsmasq"
+#define DNSMASQ_STATE_DIR LOCALSTATEDIR "/lib/libvirt/dnsmasq"
#define VIR_FROM_THIS VIR_FROM_NETWORK
@@ -209,10 +210,10 @@ networkStartup(int privileged) {
if (privileged) {
if (virAsprintf(&driverState->logDir,
- "%s/log/libvirt/qemu", LOCAL_STATE_DIR) == -1)
+ "%s/log/libvirt/qemu", LOCALSTATEDIR) == -1)
goto out_of_memory;
- if ((base = strdup (SYSCONF_DIR "/libvirt")) == NULL)
+ if ((base = strdup (SYSCONFDIR "/libvirt")) == NULL)
goto out_of_memory;
} else {
char *userdir = virGetUserDirectory(uid);
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 4efeb3a..a305de6 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -2,7 +2,7 @@
* nwfilter_driver.c: core driver for network filter APIs
* (based on storage_driver.c)
*
- * Copyright (C) 2006-2009 Red Hat, Inc.
+ * Copyright (C) 2006-2010 Red Hat, Inc.
* Copyright (C) 2006-2008 Daniel P. Berrange
* Copyright (C) 2010 IBM Corporation
* Copyright (C) 2010 Stefan Berger
@@ -37,7 +37,7 @@
#include "nwfilter_conf.h"
#include "nwfilter_driver.h"
#include "nwfilter_gentech_driver.h"
-
+#include "configmake.h"
#include "nwfilter_learnipaddr.h"
@@ -83,7 +83,7 @@ nwfilterDriverStartup(int privileged) {
nwfilterDriverLock(driverState);
if (privileged) {
- if ((base = strdup (SYSCONF_DIR "/libvirt")) == NULL)
+ if ((base = strdup (SYSCONFDIR "/libvirt")) == NULL)
goto out_of_memory;
} else {
uid_t uid = geteuid();
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 83a117a..35caccc 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -56,6 +56,7 @@
#include "cpu/cpu.h"
#include "domain_nwfilter.h"
#include "files.h"
+#include "configmake.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -112,7 +113,7 @@ int qemudLoadDriverConfig(struct qemud_driver *driver,
virReportOOMError();
return -1;
}
- if (!(driver->vncTLSx509certdir = strdup(SYSCONF_DIR "/pki/libvirt-vnc"))) {
+ if (!(driver->vncTLSx509certdir = strdup(SYSCONFDIR "/pki/libvirt-vnc"))) {
virReportOOMError();
return -1;
}
@@ -121,7 +122,8 @@ int qemudLoadDriverConfig(struct qemud_driver *driver,
virReportOOMError();
return -1;
}
- if (!(driver->spiceTLSx509certdir = strdup(SYSCONF_DIR "/pki/libvirt-spice"))) {
+ if (!(driver->spiceTLSx509certdir
+ = strdup(SYSCONFDIR "/pki/libvirt-spice"))) {
virReportOOMError();
return -1;
}
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 772fd50..f3b158a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -84,7 +84,7 @@
#include "virtaudit.h"
#include "files.h"
#include "fdstream.h"
-
+#include "configmake.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -1762,28 +1762,28 @@ qemudStartup(int privileged) {
if (privileged) {
if (virAsprintf(&qemu_driver->logDir,
- "%s/log/libvirt/qemu", LOCAL_STATE_DIR) == -1)
+ "%s/log/libvirt/qemu", LOCALSTATEDIR) == -1)
goto out_of_memory;
- if ((base = strdup (SYSCONF_DIR "/libvirt")) == NULL)
+ if ((base = strdup (SYSCONFDIR "/libvirt")) == NULL)
goto out_of_memory;
if (virAsprintf(&qemu_driver->stateDir,
- "%s/run/libvirt/qemu", LOCAL_STATE_DIR) == -1)
+ "%s/run/libvirt/qemu", LOCALSTATEDIR) == -1)
goto out_of_memory;
if (virAsprintf(&qemu_driver->libDir,
- "%s/lib/libvirt/qemu", LOCAL_STATE_DIR) == -1)
+ "%s/lib/libvirt/qemu", LOCALSTATEDIR) == -1)
goto out_of_memory;
if (virAsprintf(&qemu_driver->cacheDir,
- "%s/cache/libvirt/qemu", LOCAL_STATE_DIR) == -1)
+ "%s/cache/libvirt/qemu", LOCALSTATEDIR) == -1)
goto out_of_memory;
if (virAsprintf(&qemu_driver->saveDir,
- "%s/lib/libvirt/qemu/save", LOCAL_STATE_DIR) == -1)
+ "%s/lib/libvirt/qemu/save", LOCALSTATEDIR) == -1)
goto out_of_memory;
if (virAsprintf(&qemu_driver->snapshotDir,
- "%s/lib/libvirt/qemu/snapshot", LOCAL_STATE_DIR) == -1)
+ "%s/lib/libvirt/qemu/snapshot", LOCALSTATEDIR) == -1)
goto out_of_memory;
} else {
uid_t uid = geteuid();
diff --git a/src/remote/remote_driver.h b/src/remote/remote_driver.h
index 49a63bd..1504eec 100644
--- a/src/remote/remote_driver.h
+++ b/src/remote/remote_driver.h
@@ -2,7 +2,7 @@
* remote_internal.h: driver to provide access to libvirtd running
* on a remote machine
*
- * Copyright (C) 2006-2007 Red Hat, Inc.
+ * Copyright (C) 2006-2007, 2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -26,6 +26,8 @@
# include "libvirt/virterror.h"
+# include "configmake.h"
+
int remoteRegister (void);
unsigned long remoteVersion(void);
@@ -33,13 +35,13 @@ unsigned long remoteVersion(void);
# define LIBVIRTD_LISTEN_ADDR NULL
# define LIBVIRTD_TLS_PORT "16514"
# define LIBVIRTD_TCP_PORT "16509"
-# define LIBVIRTD_PRIV_UNIX_SOCKET LOCAL_STATE_DIR "/run/libvirt/libvirt-sock"
-# define LIBVIRTD_PRIV_UNIX_SOCKET_RO LOCAL_STATE_DIR "/run/libvirt/libvirt-sock-ro"
+# define LIBVIRTD_PRIV_UNIX_SOCKET LOCALSTATEDIR "/run/libvirt/libvirt-sock"
+# define LIBVIRTD_PRIV_UNIX_SOCKET_RO LOCALSTATEDIR "/run/libvirt/libvirt-sock-ro"
# define LIBVIRTD_USER_UNIX_SOCKET "/.libvirt/libvirt-sock"
-# define LIBVIRTD_CONFIGURATION_FILE SYSCONF_DIR "/libvirtd.conf"
+# define LIBVIRTD_CONFIGURATION_FILE SYSCONFDIR "/libvirtd.conf"
/* Defaults for PKI directory. */
-# define LIBVIRT_PKI_DIR SYSCONF_DIR "/pki"
+# define LIBVIRT_PKI_DIR SYSCONFDIR "/pki"
# define LIBVIRT_CACERT LIBVIRT_PKI_DIR "/CA/cacert.pem"
# define LIBVIRT_CLIENTKEY LIBVIRT_PKI_DIR "/libvirt/private/clientkey.pem"
# define LIBVIRT_CLIENTCERT LIBVIRT_PKI_DIR "/libvirt/clientcert.pem"
diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c
index 2b5a7c6..c5a876b 100644
--- a/src/secret/secret_driver.c
+++ b/src/secret/secret_driver.c
@@ -42,6 +42,7 @@
#include "uuid.h"
#include "virterror_internal.h"
#include "files.h"
+#include "configmake.h"
#define VIR_FROM_THIS VIR_FROM_SECRET
@@ -994,7 +995,7 @@ secretDriverStartup(int privileged)
secretDriverLock(driverState);
if (privileged) {
- base = strdup(SYSCONF_DIR "/libvirt");
+ base = strdup(SYSCONFDIR "/libvirt");
if (base == NULL)
goto out_of_memory;
} else {
diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
index be39f75..b43c4ac 100644
--- a/src/security/security_apparmor.c
+++ b/src/security/security_apparmor.c
@@ -38,11 +38,12 @@
#include "pci.h"
#include "hostusb.h"
#include "files.h"
+#include "configmake.h"
#define VIR_FROM_THIS VIR_FROM_SECURITY
#define SECURITY_APPARMOR_VOID_DOI "0"
#define SECURITY_APPARMOR_NAME "apparmor"
-#define VIRT_AA_HELPER BINDIR "/virt-aa-helper"
+#define VIRT_AA_HELPER LIBEXECDIR "/virt-aa-helper"
/* Data structure to pass to *FileIterate so we have everything we need */
struct SDPDOP {
@@ -561,7 +562,7 @@ AppArmorRestoreSecurityAllLabel(virSecurityDriverPtr drv ATTRIBUTE_UNUSED,
}
/* Called via virExecWithHook. Output goes to
- * LOCAL_STATE_DIR/log/libvirt/qemu/<vm name>.log
+ * LOCALSTATEDIR/log/libvirt/qemu/<vm name>.log
*/
static int
AppArmorSetSecurityProcessLabel(virSecurityDriverPtr drv, virDomainObjPtr vm)
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index 5708cd8..0f94fe4 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -38,6 +38,7 @@
#include "hostusb.h"
#include "pci.h"
#include "files.h"
+#include "configmake.h"
static char *progname;
@@ -1179,11 +1180,11 @@ main(int argc, char **argv)
goto clean;
} else {
virBufferVSprintf(&buf, " \"%s/log/libvirt/**/%s.log\" w,\n",
- LOCAL_STATE_DIR, ctl->def->name);
+ LOCALSTATEDIR, ctl->def->name);
virBufferVSprintf(&buf, " \"%s/lib/libvirt/**/%s.monitor\" rw,\n",
- LOCAL_STATE_DIR, ctl->def->name);
+ LOCALSTATEDIR, ctl->def->name);
virBufferVSprintf(&buf, " \"%s/run/libvirt/**/%s.pid\" rwk,\n",
- LOCAL_STATE_DIR, ctl->def->name);
+ LOCALSTATEDIR, ctl->def->name);
if (ctl->files)
virBufferVSprintf(&buf, "%s", ctl->files);
}
diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index a8864dd..c7ade6b 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -31,10 +31,11 @@
#include "storage_backend_disk.h"
#include "util.h"
#include "memory.h"
+#include "configmake.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
-#define PARTHELPER BINDIR "/libvirt_parthelper"
+#define PARTHELPER LIBEXECDIR "/libvirt_parthelper"
#define SECTOR_SIZE 512
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index f6672d9..6df706b 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1,7 +1,7 @@
/*
* storage_driver.c: core driver for storage APIs
*
- * Copyright (C) 2006-2009 Red Hat, Inc.
+ * Copyright (C) 2006-2010 Red Hat, Inc.
* Copyright (C) 2006-2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@@ -46,6 +46,7 @@
#include "storage_backend.h"
#include "logging.h"
#include "files.h"
+#include "configmake.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -125,7 +126,7 @@ storageDriverStartup(int privileged) {
storageDriverLock(driverState);
if (privileged) {
- if ((base = strdup (SYSCONF_DIR "/libvirt")) == NULL)
+ if ((base = strdup (SYSCONFDIR "/libvirt")) == NULL)
goto out_of_memory;
} else {
uid_t uid = geteuid();
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 3588894..77610d4 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -61,11 +61,12 @@
#include "domain_nwfilter.h"
#include "files.h"
#include "fdstream.h"
+#include "configmake.h"
#define VIR_FROM_THIS VIR_FROM_UML
/* For storing short-lived temporary files. */
-#define TEMPDIR LOCAL_STATE_DIR "/cache/libvirt"
+#define TEMPDIR LOCALSTATEDIR "/cache/libvirt"
typedef struct _umlDomainObjPrivate umlDomainObjPrivate;
typedef umlDomainObjPrivate *umlDomainObjPrivatePtr;
@@ -371,14 +372,14 @@ umlStartup(int privileged) {
if (privileged) {
if (virAsprintf(¨_driver->logDir,
- "%s/log/libvirt/uml", LOCAL_STATE_DIR) == -1)
+ "%s/log/libvirt/uml", LOCALSTATEDIR) == -1)
goto out_of_memory;
- if ((base = strdup (SYSCONF_DIR "/libvirt")) == NULL)
+ if ((base = strdup (SYSCONFDIR "/libvirt")) == NULL)
goto out_of_memory;
if (virAsprintf(¨_driver->monitorDir,
- "%s/run/libvirt/uml-guest", LOCAL_STATE_DIR) == -1)
+ "%s/run/libvirt/uml-guest", LOCALSTATEDIR) == -1)
goto out_of_memory;
} else {
diff --git a/src/util/hooks.c b/src/util/hooks.c
index 6e4e2b9..8e24564 100644
--- a/src/util/hooks.c
+++ b/src/util/hooks.c
@@ -37,6 +37,7 @@
#include "logging.h"
#include "memory.h"
#include "files.h"
+#include "configmake.h"
#define VIR_FROM_THIS VIR_FROM_HOOK
@@ -44,7 +45,7 @@
virReportErrorHelper(NULL, VIR_FROM_HOOK, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__)
-#define LIBVIRT_HOOK_DIR SYSCONF_DIR "/libvirt/hooks"
+#define LIBVIRT_HOOK_DIR SYSCONFDIR "/libvirt/hooks"
VIR_ENUM_DECL(virHookDriver)
VIR_ENUM_DECL(virHookDaemonOp)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 20b6805..77b6fb9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -17,7 +17,6 @@ INCLUDES = \
$(SASL_CFLAGS) \
$(SELINUX_CFLAGS) \
$(APPARMOR_CFLAGS) \
- -DGETTEXT_PACKAGE=\"$(PACKAGE)\" \
$(COVERAGE_CFLAGS) \
$(WARN_CFLAGS)
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 921d621..376ffa8 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -55,8 +55,6 @@ virsh_CFLAGS = \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/util \
-I$(top_srcdir) \
- -DGETTEXT_PACKAGE=\"$(PACKAGE)\" \
- -DLOCALEBASEDIR=\""$(datadir)/locale"\" \
$(WARN_CFLAGS) \
$(COVERAGE_CFLAGS) \
$(LIBXML_CFLAGS) \
diff --git a/tools/virsh.c b/tools/virsh.c
index 3a74053..743d5a1 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -53,6 +53,7 @@
#include "libvirt/libvirt-qemu.h"
#include "files.h"
#include "../daemon/event.h"
+#include "configmake.h"
static char *progname;
@@ -11786,11 +11787,11 @@ main(int argc, char **argv)
perror("setlocale");
/* failure to setup locale is not fatal */
}
- if (!bindtextdomain(GETTEXT_PACKAGE, LOCALEBASEDIR)) {
+ if (!bindtextdomain(PACKAGE, LOCALEDIR)) {
perror("bindtextdomain");
return -1;
}
- if (!textdomain(GETTEXT_PACKAGE)) {
+ if (!textdomain(PACKAGE)) {
perror("textdomain");
return -1;
}
--
1.7.3.2
14 years, 4 months
[libvirt] [PATCH] doc: update virsh manual
by Osier Yang
* tools/virsh.pod (change things like "edit domain.xml" into
"vi domain.xml", so that it's more clear for user)
---
tools/virsh.pod | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 8032256..ca8ba74 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -306,7 +306,7 @@ L<http://libvirt.org/formatdomain.html#elementsCPU>
The following commands manipulate domains directly, as stated
previously most commands take domain-id as the first parameter. The
-I<domain-id> can be specified as an short integer, a name or a full UUID.
+I<domain-id> can be specified as a short integer, a name or a full UUID.
=over 4
@@ -334,7 +334,7 @@ If I<--console> is requested, attach to the console after creation.
B<Example>
virsh dumpxml <domain-id> > domain.xml
- edit domain.xml
+ vi domain.xml (or make changes with your other text editor)
virsh create < domain.xml
=item B<define> I<FILE>
@@ -431,7 +431,7 @@ Edit the XML configuration file for a domain.
This is equivalent to:
virsh dumpxml domain > domain.xml
- edit domain.xml
+ vi domain.xml (or make changes with your other text editor)
virsh define domain.xml
except that it does some error checking.
@@ -631,7 +631,7 @@ is not available the processes will provide an exit code of 1.
=head1 DEVICE COMMANDS
The following commands manipulate devices associated to domains.
-The domain-id can be specified as an short integer, a name or a full UUID.
+The domain-id can be specified as a short integer, a name or a full UUID.
To better understand the values allowed as options for the command
reading the documentation at L<http://libvirt.org/formatdomain.html> on the
format of the device sections to get the most accurate set of accepted values.
@@ -735,7 +735,7 @@ Edit the XML configuration file for a network.
This is equivalent to:
virsh net-dumpxml network > network.xml
- edit network.xml
+ vi network.xml (or make changes with your other text editor)
virsh net-define network.xml
except that it does some error checking.
@@ -851,7 +851,7 @@ Edit the XML configuration file for a storage pool.
This is equivalent to:
virsh pool-dumpxml pool > pool.xml
- edit pool.xml
+ vi pool.xml (or make changes with your other text editor)
virsh pool-define pool.xml
except that it does some error checking.
@@ -908,7 +908,7 @@ pre-existing volume.
B<Example>
virsh vol-dumpxml --pool storagepool1 appvolume1 > newvolume.xml
- edit newvolume.xml
+ vi newvolume.xml (or make changes with your other text editor)
virsh vol-create differentstoragepool newvolume.xml
=item B<vol-create-from> I<pool-or-uuid> I<FILE> [optional I<--inputpool>
@@ -1138,7 +1138,7 @@ Edit the XML of a network filter.
This is equivalent to:
virsh nwfilter-dumpxml myfilter > myfilter.xml
- edit myfilter.xml
+ vi myfilter.xml (or make changes with your other text editor)
virsh nwfilter-define myfilter.xml
except that it does some error checking.
--
1.7.3.2
14 years, 4 months
[libvirt] [PATCH 0/3] improve i18n
by Eric Blake
This patch series depends on these two previous patches (not reviewed
yet):
https://www.redhat.com/archives/libvir-list/2010-November/msg00733.html
https://www.redhat.com/archives/libvir-list/2010-November/msg00626.html
It also replaces my earlier patch here:
https://www.redhat.com/archives/libvir-list/2010-September/msg00583.html
It also makes it possible to boostrap on FreeBSD, as a side-effect of
updating bootstrap.
Eric Blake (3):
maint: improve i18n on non-Linux
maint: update to latest gnulib
virt-aa-helper: translate error messages
.gitignore | 65 +++++++------
.gnulib | 2 +-
.x-sc_bindtextdomain | 2 +
Makefile.am | 1 +
bootstrap | 44 ++++++---
build-aux/.gitignore | 16 ---
cfg.mk | 2 +
daemon/libvirtd.c | 10 ++-
m4/.gitignore | 37 -------
po/.gitignore | 17 ----
po/POTFILES.in | 1 +
src/internal.h | 11 ++-
src/lxc/lxc_controller.c | 9 ++
src/security/security_apparmor.c | 1 +
src/security/virt-aa-helper.c | 194 ++++++++++++++++++++------------------
src/storage/parthelper.c | 15 +++-
tools/virsh.c | 4 +-
17 files changed, 215 insertions(+), 216 deletions(-)
create mode 100644 .x-sc_bindtextdomain
delete mode 100644 build-aux/.gitignore
delete mode 100644 m4/.gitignore
delete mode 100644 po/.gitignore
--
1.7.3.2
14 years, 4 months
[libvirt] [PATCH] maint: avoid remaining sprintf uses
by Eric Blake
* cfg.mk (sc_prohibit_sprintf): New rule.
(sc_prohibit_asprintf): Avoid false positives.
* docs/hacking.html.in (Printf-style functions): Document the
policy.
* .x-sc_prohibit_sprintf: New exemptions.
* src/vbox/vbox_tmpl.c (vboxStartMachine, vboxAttachUSB): Use
virAsprintf instead.
* src/uml/uml_driver.c (umlOpenMonitor): Use snprintf instead.
* tools/virsh.c (cmdDetachInterface): Likewise.
* src/security/security_selinux.c (SELinuxGenSecurityLabel):
Likewise.
* src/openvz/openvz_driver.c (openvzDomainDefineCmd): Likewise,
and ensure large enough buffer.
---
.x-sc_prohibit_sprintf | 3 +++
cfg.mk | 13 ++++++++++---
docs/hacking.html.in | 9 +++++++++
src/openvz/openvz_driver.c | 5 +++--
src/security/security_selinux.c | 6 +++---
src/uml/uml_driver.c | 3 ++-
tools/virsh.c | 2 +-
7 files changed, 31 insertions(+), 10 deletions(-)
create mode 100644 .x-sc_prohibit_sprintf
diff --git a/.x-sc_prohibit_sprintf b/.x-sc_prohibit_sprintf
new file mode 100644
index 0000000..0a1f448
--- /dev/null
+++ b/.x-sc_prohibit_sprintf
@@ -0,0 +1,3 @@
+^docs/
+^po/
+ChangeLog
diff --git a/cfg.mk b/cfg.mk
index 16c2ae3..01cada8 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -238,10 +238,17 @@ sc_prohibit_strcmp_and_strncmp:
halt='use STREQ() in place of the above uses of str[n]cmp' \
$(_sc_search_regexp)
-# Use virAsprintf rather than a'sprintf since *strp is undefined on error.
+# Use virAsprintf rather than as'printf since *strp is undefined on error.
sc_prohibit_asprintf:
- @prohibit='\<[a]sprintf\>' \
- halt='use virAsprintf, not a'sprintf \
+ @prohibit='\<a[s]printf\>' \
+ halt='use virAsprintf, not as'printf \
+ $(_sc_search_regexp)
+
+# Use snprintf rather than s'printf, even if buffer is provably large enough,
+# since gnulib has more guarantees for snprintf portability
+sc_prohibit_sprintf:
+ @prohibit='\<[s]printf\>' \
+ halt='use snprintf, not s'printf \
$(_sc_search_regexp)
sc_prohibit_strncpy:
diff --git a/docs/hacking.html.in b/docs/hacking.html.in
index bd8b443..a79250e 100644
--- a/docs/hacking.html.in
+++ b/docs/hacking.html.in
@@ -602,6 +602,15 @@
of arguments.
</p>
+ <p>
+ When printing to a string, consider using virBuffer for
+ incremental allocations, virAsprintf for a one-shot allocation,
+ and snprintf for fixed-width buffers. Do not use sprintf, even
+ if you can prove the buffer won't overflow, since gnulib does
+ not provide the same portability guarantees for sprintf as it
+ does for snprintf.
+ </p>
+
<h2><a name="goto">Use of goto</a></h2>
<p>
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index 2893f69..f799691 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -58,6 +58,7 @@
#include "memory.h"
#include "bridge.h"
#include "files.h"
+#include "intprops.h"
#define VIR_FROM_THIS VIR_FROM_OPENVZ
@@ -104,7 +105,7 @@ openvzDomainDefineCmd(const char *args[],
int narg;
int veid;
int max_veid;
- char str_id[10];
+ char str_id[INT_BUFSIZE_BOUND(max_veid)];
FILE *fp;
for (narg = 0; narg < maxarg; narg++)
@@ -162,7 +163,7 @@ openvzDomainDefineCmd(const char *args[],
max_veid++;
}
- sprintf(str_id, "%d", max_veid);
+ snprintf(str_id, sizeof(str_id), "%d", max_veid);
ADD_ARG_LIT(str_id);
ADD_ARG_LIT("--name");
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 7dd9b14..5e0e7bb 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -182,12 +182,12 @@ SELinuxGenSecurityLabel(virSecurityDriverPtr drv ATTRIBUTE_UNUSED,
c2 = virRandom(1024);
if ( c1 == c2 ) {
- sprintf(mcs, "s0:c%d", c1);
+ snprintf(mcs, sizeof(mcs), "s0:c%d", c1);
} else {
if ( c1 < c2 )
- sprintf(mcs, "s0:c%d,c%d", c1, c2);
+ snprintf(mcs, sizeof(mcs), "s0:c%d,c%d", c1, c2);
else
- sprintf(mcs, "s0:c%d,c%d", c2, c1);
+ snprintf(mcs, sizeof(mcs), "s0:c%d,c%d", c2, c1);
}
} while(mcsAdd(mcs) == -1);
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 348f299..5b2a553 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -655,7 +655,8 @@ restat:
}
memset(addr.sun_path, 0, sizeof addr.sun_path);
- sprintf(addr.sun_path + 1, "libvirt-uml-%u", vm->pid);
+ snprintf(addr.sun_path + 1, sizeof(addr.sun_path) - 1,
+ "libvirt-uml-%u", vm->pid);
VIR_DEBUG("Reply address for monitor is '%s'", addr.sun_path+1);
if (bind(priv->monitor, (struct sockaddr *)&addr, sizeof addr) < 0) {
virReportSystemError(errno,
diff --git a/tools/virsh.c b/tools/virsh.c
index cd20d34..053aee7 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -8450,7 +8450,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
}
- sprintf(buf, "/domain/devices/interface[@type='%s']", type);
+ snprintf(buf, sizeof(buf), "/domain/devices/interface[@type='%s']", type);
obj = xmlXPathEval(BAD_CAST buf, ctxt);
if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
(obj->nodesetval == NULL) || (obj->nodesetval->nodeNr == 0)) {
--
1.7.3.2
14 years, 4 months
[libvirt] [PATCH v2] replace last instances of close()
by Stefan Berger
v2:
- added comments about the monitor lock being used to protect the
file descriptor 'fd'
- eofcb is not set anywhere, so also removing it; the if statement
checking on it seems dead code
I am replacing the last instances of close() I found with VIR_CLOSE() /
VIR_FORCE_CLOSE respectively.
The first part patches virsh, which I missed out on previously.
The 2nd patch I had left out intentionally to look at it more carefully:
The 'closed' variable could be easily removed since it wasn't used
anywhere else. The possible race condition that could result from the
filedescriptor being closed and not set to -1 (and possibly let us write
into 'something' totally different if the fd was allocated by another
thread) seems to be prevented by the qemuMonitorLock() already placed
around the code that reads from or writes to the fd. So the change of
this code as shown in the patch should not have any side-effects.
Signed-off-by: Stefan Berger<stefanb(a)us.ibm.com>
---
src/qemu/qemu_monitor.c | 32 +++++++++++---------------------
tools/virsh.c | 4 ++--
2 files changed, 13 insertions(+), 23 deletions(-)
Index: libvirt-acl/tools/virsh.c
===================================================================
--- libvirt-acl.orig/tools/virsh.c
+++ libvirt-acl/tools/virsh.c
@@ -8994,12 +8994,12 @@ editWriteToTempFile (vshControl *ctl, co
if (safewrite (fd, doc, strlen (doc)) == -1) {
vshError(ctl, _("write: %s: failed to write to temporary file: %s"),
ret, strerror(errno));
- close (fd);
+ VIR_FORCE_CLOSE(fd);
unlink (ret);
VIR_FREE(ret);
return NULL;
}
- if (close (fd) == -1) {
+ if (VIR_CLOSE(fd)< 0) {
vshError(ctl, _("close: %s: failed to write or close temporary file: %s"),
ret, strerror(errno));
unlink (ret);
Index: libvirt-acl/src/qemu/qemu_monitor.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_monitor.c
+++ libvirt-acl/src/qemu/qemu_monitor.c
@@ -44,7 +44,7 @@
#define DEBUG_RAW_IO 0
struct _qemuMonitor {
- virMutex lock;
+ virMutex lock; /* also used to protect fd */
virCond notify;
int refs;
@@ -71,11 +71,6 @@ struct _qemuMonitor {
* the next monitor msg */
int lastErrno;
- /* If the monitor EOF callback is currently active (stops more commands being run) */
- unsigned eofcb: 1;
- /* If the monitor is in process of shutting down */
- unsigned closed: 1;
-
unsigned json: 1;
};
@@ -356,6 +351,7 @@ qemuMonitorIOProcess(qemuMonitorPtr mon)
}
+/* Call this function while holding the monitor lock. */
static int
qemuMonitorIOWriteWithFD(qemuMonitorPtr mon,
const char *data,
@@ -400,7 +396,10 @@ qemuMonitorIOWriteWithFD(qemuMonitorPtr
return ret;
}
-/* Called when the monitor is able to write data */
+/*
+ * Called when the monitor is able to write data
+ * Call this function while holding the monitor lock.
+ */
static int
qemuMonitorIOWrite(qemuMonitorPtr mon)
{
@@ -433,6 +432,7 @@ qemuMonitorIOWrite(qemuMonitorPtr mon)
/*
* Called when the monitor has incoming data to read
+ * Call this function while holding the monitor lock.
*
* Returns -1 on error, or number of bytes read
*/
@@ -505,6 +505,7 @@ qemuMonitorIO(int watch, int fd, int eve
qemuMonitorPtr mon = opaque;
int quit = 0, failed = 0;
+ /* lock access to the monitor and protect fd */
qemuMonitorLock(mon);
qemuMonitorRef(mon);
#if DEBUG_IO
@@ -692,17 +693,11 @@ void qemuMonitorClose(qemuMonitorPtr mon
VIR_DEBUG("mon=%p", mon);
qemuMonitorLock(mon);
- if (!mon->closed) {
+
+ if (mon->fd>= 0) {
if (mon->watch)
virEventRemoveHandle(mon->watch);
- 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
- * we merely close them, but not clear their values and
- * use this explicit 'closed' flag to track this state */
- mon->closed = 1;
+ VIR_FORCE_CLOSE(mon->fd);
}
if (qemuMonitorUnref(mon)> 0)
@@ -715,11 +710,6 @@ int qemuMonitorSend(qemuMonitorPtr mon,
{
int ret = -1;
- if (mon->eofcb) {
- msg->lastErrno = EIO;
- return -1;
- }
-
mon->msg = msg;
qemuMonitorUpdateWatch(mon);
14 years, 4 months
[libvirt] [PATCH] [RESEND] To list basic information about the network.
by Osier Yang
* tools/virsh.c
---
tools/virsh.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 59 insertions(+), 0 deletions(-)
mode change 100644 => 100755 tools/virsh.c
diff --git a/tools/virsh.c b/tools/virsh.c
old mode 100644
new mode 100755
index d15a8df..3a74053
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -3678,6 +3678,64 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd)
return ret;
}
+/*
+ * "net-info" command
+ */
+static const vshCmdInfo info_network_info[] = {
+ {"help", N_("network information")},
+ {"desc", "Returns basic information about the network"},
+ {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_network_info[] = {
+ {"network", VSH_OT_DATA, VSH_OFLAG_REQ, N_("network name")},
+ {NULL, 0, 0, NULL}
+};
+
+static int
+cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd)
+{
+ virNetworkPtr network;
+ char uuid[VIR_UUID_STRING_BUFLEN];
+ int autostart;
+ int persistent = -1;
+ int active = -1;
+ char *bridge = NULL;
+
+ if (!vshConnectionUsability(ctl, ctl->conn))
+ return FALSE;
+
+ if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL,
+ VSH_BYNAME)))
+ return FALSE;
+
+ vshPrint(ctl, "%-15s %s\n", _("Name"), virNetworkGetName(network));
+
+ if (virNetworkGetUUIDString(network, uuid) == 0)
+ vshPrint(ctl, "%-15s %s\n", _("UUID"), uuid);
+
+ active = virNetworkIsActive(network);
+ if (active >= 0)
+ vshPrint(ctl, "%-15s %s\n", _("Active:"), active? _("yes") : _("no"));
+
+ persistent = virNetworkIsPersistent(network);
+ if (persistent < 0)
+ vshPrint(ctl, "%-15s %s\n", _("Persistent:"), _("unknown"));
+ else
+ vshPrint(ctl, "%-15s %s\n", _("Persistent:"), persistent ? _("yes") : _("no"));
+
+ if (virNetworkGetAutostart(network, &autostart) < 0)
+ vshPrint(ctl, "%-15s %s\n", _("Autostart:"), _("no autostart"));
+ else
+ vshPrint(ctl, "%-15s %s\n", _("Autostart:"), autostart ? _("yes") : _("no"));
+
+ bridge = virNetworkGetBridgeName(network);
+ if (bridge)
+ vshPrint(ctl, "%-15s %s\n", _("Bridge:"), bridge);
+
+ virNetworkFree(network);
+ return TRUE;
+}
/*
* "iface-edit" command
@@ -9879,6 +9937,7 @@ static const vshCmdDef commands[] = {
{"net-destroy", cmdNetworkDestroy, opts_network_destroy, info_network_destroy},
{"net-dumpxml", cmdNetworkDumpXML, opts_network_dumpxml, info_network_dumpxml},
{"net-edit", cmdNetworkEdit, opts_network_edit, info_network_edit},
+ {"net-info", cmdNetworkInfo, opts_network_info, info_network_info},
{"net-list", cmdNetworkList, opts_network_list, info_network_list},
{"net-name", cmdNetworkName, opts_network_name, info_network_name},
{"net-start", cmdNetworkStart, opts_network_start, info_network_start},
--
1.7.3.2
14 years, 4 months
[libvirt] [PATCH v3] deprecate fclose() and introduce VIR_{FORCE_}FCLOSE()
by Stefan Berger
V3:
- fixes from V2 review + one lost hunk
-> diff(tree+V2, tree+v3) at bottom of email
V2:
- following Eric's suggestion, deprecating fdclose(), introducing VIR_FDCLOSE()
- following some other nits that Eric pointed out
- replaced some more fclose () I previously had missed (last 2 files in patch)
Similarly to deprecating close(), I am now deprecating fclose() and
introduce VIR_FORCE_FCLOSE() and VIR_FCLOSE(). Also, fdopen() is replaced with
VIR_FDOPEN().
Most of the files are opened in read-only mode, so usage of
VIR_FORCE_CLOSE() seemed appropriate. Others that are opened in write
mode already had the fclose()< 0 check and I converted those to
VIR_FCLOSE()< 0.
I did not find occurrences of possible double-closed files on the way.
Signed-off-by: Stefan Berger<stefanb(a)us.ibm.com>
---
HACKING | 33 +++++++++++++++++++++++++++------
daemon/libvirtd.c | 6 +++---
docs/hacking.html.in | 36 ++++++++++++++++++++++++++++--------
src/libvirt_private.syms | 2 ++
src/nodeinfo.c | 8 ++++----
src/openvz/openvz_conf.c | 16 +++++++++-------
src/openvz/openvz_driver.c | 4 ++--
src/qemu/qemu_driver.c | 4 ++--
src/storage/storage_backend.c | 18 +++++++-----------
src/storage/storage_backend_fs.c | 4 ++--
src/storage/storage_backend_iscsi.c | 9 +++------
src/storage/storage_backend_scsi.c | 2 +-
src/uml/uml_driver.c | 8 ++++----
src/util/cgroup.c | 10 +++++-----
src/util/dnsmasq.c | 5 +++--
src/util/files.c | 34 ++++++++++++++++++++++++++++++++++
src/util/files.h | 10 +++++++++-
src/util/macvtap.c | 4 ++--
src/util/stats_linux.c | 5 +++--
src/util/util.c | 10 ++++------
src/xen/block_stats.c | 3 ++-
src/xen/xen_driver.c | 7 ++++---
src/xen/xen_hypervisor.c | 8 +++-----
tests/nodeinfotest.c | 5 +++--
tests/testutils.c | 8 ++++----
tests/xencapstest.c | 7 +++----
26 files changed, 173 insertions(+), 93 deletions(-)
Index: libvirt-acl/src/util/files.c
===================================================================
--- libvirt-acl.orig/src/util/files.c
+++ libvirt-acl/src/util/files.c
@@ -44,3 +44,37 @@ int virClose(int *fdptr, bool preserve_e
return rc;
}
+
+
+int virFclose(FILE **file, bool preserve_errno)
+{
+ int saved_errno;
+ int rc = 0;
+
+ if (*file) {
+ if (preserve_errno)
+ saved_errno = errno;
+ rc = fclose(*file);
+ *file = NULL;
+ if (preserve_errno)
+ errno = saved_errno;
+ }
+
+ return rc;
+}
+
+
+FILE *virFdopen(int *fdptr, const char *mode)
+{
+ FILE *file = NULL;
+
+ if (*fdptr>= 0) {
+ file = fdopen(*fdptr, mode);
+ if (file)
+ *fdptr = -1;
+ } else {
+ errno = EBADF;
+ }
+
+ return file;
+}
Index: libvirt-acl/src/util/files.h
===================================================================
--- libvirt-acl.orig/src/util/files.h
+++ libvirt-acl/src/util/files.h
@@ -27,20 +27,28 @@
# define __VIR_FILES_H_
# include<stdbool.h>
+# include<stdio.h>
# include "internal.h"
# include "ignore-value.h"
-/* Don't call this directly - use the macros below */
+/* Don't call these directly - use the macros below */
int virClose(int *fdptr, bool preserve_errno) ATTRIBUTE_RETURN_CHECK;
+int virFclose(FILE **file, bool preserve_errno) ATTRIBUTE_RETURN_CHECK;
+FILE *virFdopen(int *fdptr, const char *mode) ATTRIBUTE_RETURN_CHECK;
/* For use on normal paths; caller must check return value,
and failure sets errno per close(). */
# define VIR_CLOSE(FD) virClose(&(FD), false)
+# define VIR_FCLOSE(FILE) virFclose(&(FILE), false)
+
+/* Wrapper around fdopen that consumes fd on success. */
+# define VIR_FDOPEN(FD, MODE) virFdopen(&(FD), MODE)
/* For use on cleanup paths; errno is unaffected by close,
and no return value to worry about. */
# define VIR_FORCE_CLOSE(FD) ignore_value(virClose(&(FD), true))
+# define VIR_FORCE_FCLOSE(FILE) ignore_value(virFclose(&(FILE), true))
#endif /* __VIR_FILES_H */
Index: libvirt-acl/src/libvirt_private.syms
===================================================================
--- libvirt-acl.orig/src/libvirt_private.syms
+++ libvirt-acl/src/libvirt_private.syms
@@ -344,6 +344,8 @@ virFDStreamCreateFile;
# files.h
virClose;
+virFclose;
+virFdopen;
# hash.h
Index: libvirt-acl/daemon/libvirtd.c
===================================================================
--- libvirt-acl.orig/daemon/libvirtd.c
+++ libvirt-acl/daemon/libvirtd.c
@@ -512,7 +512,7 @@ static int qemudWritePidFile(const char
return -1;
}
- if (!(fh = fdopen(fd, "w"))) {
+ if (!(fh = VIR_FDOPEN(fd, "w"))) {
VIR_ERROR(_("Failed to fdopen pid file '%s' : %s"),
pidFile, virStrerror(errno, ebuf, sizeof ebuf));
VIR_FORCE_CLOSE(fd);
@@ -522,11 +522,11 @@ static int qemudWritePidFile(const char
if (fprintf(fh, "%lu\n", (unsigned long)getpid())< 0) {
VIR_ERROR(_("%s: Failed to write to pid file '%s' : %s"),
argv0, pidFile, virStrerror(errno, ebuf, sizeof ebuf));
- fclose(fh);
+ VIR_FORCE_FCLOSE(fh);
return -1;
}
- if (fclose(fh) == EOF) {
+ if (VIR_FCLOSE(fh) == EOF) {
VIR_ERROR(_("%s: Failed to close pid file '%s' : %s"),
argv0, pidFile, virStrerror(errno, ebuf, sizeof ebuf));
return -1;
Index: libvirt-acl/src/nodeinfo.c
===================================================================
--- libvirt-acl.orig/src/nodeinfo.c
+++ libvirt-acl/src/nodeinfo.c
@@ -46,6 +46,7 @@
#include "virterror_internal.h"
#include "count-one-bits.h"
#include "intprops.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_NONE
@@ -102,8 +103,7 @@ get_cpu_value(unsigned int cpu, const ch
}
cleanup:
- if (pathfp)
- fclose(pathfp);
+ VIR_FORCE_FCLOSE(pathfp);
VIR_FREE(path);
return value;
@@ -155,7 +155,7 @@ static unsigned long count_thread_siblin
}
cleanup:
- fclose(pathfp);
+ VIR_FORCE_FCLOSE(pathfp);
VIR_FREE(path);
return ret;
@@ -329,7 +329,7 @@ int nodeGetInfo(virConnectPtr conn ATTRI
return -1;
}
ret = linuxNodeInfoCPUPopulate(cpuinfo, nodeinfo);
- fclose(cpuinfo);
+ VIR_FORCE_FCLOSE(cpuinfo);
if (ret< 0)
return -1;
Index: libvirt-acl/src/openvz/openvz_conf.c
===================================================================
--- libvirt-acl.orig/src/openvz/openvz_conf.c
+++ libvirt-acl/src/openvz/openvz_conf.c
@@ -528,7 +528,7 @@ int openvzLoadDomains(struct openvz_driv
dom = NULL;
}
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return 0;
@@ -536,7 +536,7 @@ int openvzLoadDomains(struct openvz_driv
virReportOOMError();
cleanup:
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
if (dom)
virDomainObjUnref(dom);
return -1;
@@ -888,6 +888,7 @@ openvzSetDefinedUUID(int vpsid, unsigned
{
char *conf_file;
char uuidstr[VIR_UUID_STRING_BUFLEN];
+ FILE *fp = NULL;
int ret = -1;
if (uuid == NULL)
@@ -900,21 +901,22 @@ openvzSetDefinedUUID(int vpsid, unsigned
goto cleanup;
if (uuidstr[0] == 0) {
- FILE *fp = fopen(conf_file, "a"); /* append */
+ fp = fopen(conf_file, "a"); /* append */
if (fp == NULL)
goto cleanup;
virUUIDFormat(uuid, uuidstr);
- /* Record failure if fprintf or fclose fails,
+ /* Record failure if fprintf or VIR_FCLOSE fails,
and be careful always to close the stream. */
- if ((fprintf(fp, "\n#UUID: %s\n", uuidstr)< 0)
- + (fclose(fp) == EOF))
+ if ((fprintf(fp, "\n#UUID: %s\n", uuidstr)< 0) ||
+ (VIR_FCLOSE(fp) == EOF))
goto cleanup;
}
ret = 0;
cleanup:
+ VIR_FORCE_FCLOSE(fp);
VIR_FREE(conf_file);
return ret;
}
@@ -996,7 +998,7 @@ int openvzGetVEID(const char *name) {
}
ok = fscanf(fp, "%d\n",&veid ) == 1;
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
if (ok&& veid>= 0)
return veid;
Index: libvirt-acl/src/openvz/openvz_driver.c
===================================================================
--- libvirt-acl.orig/src/openvz/openvz_driver.c
+++ libvirt-acl/src/openvz/openvz_driver.c
@@ -154,7 +154,7 @@ openvzDomainDefineCmd(const char *args[]
max_veid = veid;
}
}
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
if (max_veid == 0) {
max_veid = 100;
@@ -189,7 +189,7 @@ no_memory:
return -1;
cleanup:
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return -1;
#undef ADD_ARG
Index: libvirt-acl/src/qemu/qemu_driver.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_driver.c
+++ libvirt-acl/src/qemu/qemu_driver.c
@@ -4588,7 +4588,7 @@ static int qemudGetProcessInfo(unsigned
/* startstack -> processor */
"%*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*d %d",
&usertime,&systime,&cpu) != 3) {
- fclose(pidinfo);
+ VIR_FORCE_FCLOSE(pidinfo);
VIR_WARN0("cannot parse process status data");
errno = -EINVAL;
return -1;
@@ -4608,7 +4608,7 @@ static int qemudGetProcessInfo(unsigned
VIR_DEBUG("Got status for %d/%d user=%llu sys=%llu cpu=%d",
pid, tid, usertime, systime, cpu);
- fclose(pidinfo);
+ VIR_FORCE_FCLOSE(pidinfo);
return 0;
}
Index: libvirt-acl/src/storage/storage_backend.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend.c
+++ libvirt-acl/src/storage/storage_backend.c
@@ -1398,7 +1398,7 @@ virStorageBackendRunProgRegex(virStorage
goto cleanup;
}
- if ((list = fdopen(fd, "r")) == NULL) {
+ if ((list = VIR_FDOPEN(fd, "r")) == NULL) {
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot read fd"));
goto cleanup;
@@ -1458,10 +1458,8 @@ virStorageBackendRunProgRegex(virStorage
VIR_FREE(reg);
- if (list)
- fclose(list);
- else
- VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_FCLOSE(list);
+ VIR_FORCE_CLOSE(fd);
while ((err = waitpid(child,&exitstatus, 0) == -1)&& errno == EINTR);
@@ -1531,9 +1529,9 @@ virStorageBackendRunProgNul(virStoragePo
goto cleanup;
}
- if ((fp = fdopen(fd, "r")) == NULL) {
+ if ((fp = VIR_FDOPEN(fd, "r")) == NULL) {
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("cannot read fd"));
+ "%s", _("cannot open file using fd"));
goto cleanup;
}
@@ -1573,10 +1571,8 @@ virStorageBackendRunProgNul(virStoragePo
VIR_FREE(v[i]);
VIR_FREE(v);
- if (fp)
- fclose (fp);
- else
- VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_FCLOSE(fp);
+ 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
@@ -284,12 +284,12 @@ virStorageBackendFileSystemIsMounted(vir
while ((getmntent_r(mtab,&ent, buf, sizeof(buf))) != NULL) {
if (STREQ(ent.mnt_dir, pool->def->target.path)) {
- fclose(mtab);
+ VIR_FORCE_FCLOSE(mtab);
return 1;
}
}
- fclose(mtab);
+ VIR_FORCE_FCLOSE(mtab);
return 0;
}
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
@@ -188,7 +188,7 @@ virStorageBackendIQNFound(virStoragePool
goto out;
}
- if ((fp = fdopen(fd, "r")) == NULL) {
+ if ((fp = VIR_FDOPEN(fd, "r")) == NULL) {
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to open stream for file descriptor "
"when reading output from '%s': '%s'"),
@@ -235,11 +235,8 @@ out:
}
VIR_FREE(line);
- if (fp != NULL) {
- fclose(fp);
- } else {
- VIR_FORCE_CLOSE(fd);
- }
+ VIR_FORCE_FCLOSE(fp);
+ 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
@@ -70,7 +70,7 @@ getDeviceType(uint32_t host,
}
gottype = fgets(typestr, 3, typefile);
- fclose(typefile);
+ VIR_FORCE_FCLOSE(typefile);
if (gottype == NULL) {
virReportSystemError(errno,
Index: libvirt-acl/src/uml/uml_driver.c
===================================================================
--- libvirt-acl.orig/src/uml/uml_driver.c
+++ libvirt-acl/src/uml/uml_driver.c
@@ -587,11 +587,11 @@ reopen:
if (fscanf(file, "%d",&vm->pid) != 1) {
errno = EINVAL;
- fclose(file);
+ VIR_FORCE_FCLOSE(file);
goto cleanup;
}
- if (fclose(file)< 0)
+ if (VIR_FCLOSE(file)< 0)
goto cleanup;
rc = 0;
@@ -1096,7 +1096,7 @@ static int umlGetProcessInfo(unsigned lo
if (fscanf(pidinfo, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %llu %llu",&usertime,&systime) != 2) {
umlDebug("not enough arg");
- fclose(pidinfo);
+ VIR_FORCE_FCLOSE(pidinfo);
return -1;
}
@@ -1109,7 +1109,7 @@ static int umlGetProcessInfo(unsigned lo
umlDebug("Got %llu %llu %llu", usertime, systime, *cpuTime);
- fclose(pidinfo);
+ VIR_FORCE_FCLOSE(pidinfo);
return 0;
}
Index: libvirt-acl/src/util/cgroup.c
===================================================================
--- libvirt-acl.orig/src/util/cgroup.c
+++ libvirt-acl/src/util/cgroup.c
@@ -31,6 +31,7 @@
#include "memory.h"
#include "cgroup.h"
#include "logging.h"
+#include "files.h"
#define CGROUP_MAX_VAL 512
@@ -127,13 +128,12 @@ static int virCgroupDetectMounts(virCgro
}
}
- fclose(mounts);
+ VIR_FORCE_FCLOSE(mounts);
return 0;
no_memory:
- if (mounts)
- fclose(mounts);
+ VIR_FORCE_FCLOSE(mounts);
return -ENOMEM;
}
@@ -192,12 +192,12 @@ static int virCgroupDetectPlacement(virC
}
}
- fclose(mapping);
+ VIR_FORCE_FCLOSE(mapping);
return 0;
no_memory:
- fclose(mapping);
+ VIR_FORCE_FCLOSE(mapping);
return -ENOMEM;
}
Index: libvirt-acl/src/util/dnsmasq.c
===================================================================
--- libvirt-acl.orig/src/util/dnsmasq.c
+++ libvirt-acl/src/util/dnsmasq.c
@@ -44,6 +44,7 @@
#include "memory.h"
#include "virterror_internal.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_NETWORK
#define DNSMASQ_HOSTSFILE_SUFFIX "hostsfile"
@@ -171,7 +172,7 @@ hostsfileWrite(const char *path,
for (i = 0; i< nhosts; i++) {
if (fputs(hosts[i].host, f) == EOF || fputc('\n', f) == EOF) {
rc = errno;
- fclose(f);
+ VIR_FORCE_FCLOSE(f);
if (istmp)
unlink(tmp);
@@ -180,7 +181,7 @@ hostsfileWrite(const char *path,
}
}
- if (fclose(f) == EOF) {
+ if (VIR_FCLOSE(f) == EOF) {
rc = errno;
goto cleanup;
}
Index: libvirt-acl/src/util/macvtap.c
===================================================================
--- libvirt-acl.orig/src/util/macvtap.c
+++ libvirt-acl/src/util/macvtap.c
@@ -414,11 +414,11 @@ int openTap(const char *ifname,
virReportSystemError(errno,
"%s",_("cannot determine macvtap's tap device "
"interface index"));
- fclose(file);
+ VIR_FORCE_FCLOSE(file);
return -1;
}
- fclose(file);
+ VIR_FORCE_FCLOSE(file);
if (snprintf(tapname, sizeof(tapname),
"/dev/tap%d", ifindex)>= sizeof(tapname)) {
Index: libvirt-acl/src/util/util.c
===================================================================
--- libvirt-acl.orig/src/util/util.c
+++ libvirt-acl/src/util/util.c
@@ -1816,7 +1816,7 @@ int virFileWritePidPath(const char *pidf
goto cleanup;
}
- if (!(file = fdopen(fd, "w"))) {
+ if (!(file = VIR_FDOPEN(fd, "w"))) {
rc = errno;
VIR_FORCE_CLOSE(fd);
goto cleanup;
@@ -1830,10 +1830,8 @@ int virFileWritePidPath(const char *pidf
rc = 0;
cleanup:
- if (file&&
- fclose(file)< 0) {
+ if (VIR_FCLOSE(file)< 0)
rc = errno;
- }
return rc;
}
@@ -1864,11 +1862,11 @@ int virFileReadPid(const char *dir,
if (fscanf(file, "%d", pid) != 1) {
rc = EINVAL;
- fclose(file);
+ VIR_FORCE_FCLOSE(file);
goto cleanup;
}
- if (fclose(file)< 0) {
+ if (VIR_FCLOSE(file)< 0) {
rc = errno;
goto cleanup;
}
Index: libvirt-acl/src/xen/xen_driver.c
===================================================================
--- libvirt-acl.orig/src/xen/xen_driver.c
+++ libvirt-acl/src/xen/xen_driver.c
@@ -47,6 +47,7 @@
#include "pci.h"
#include "uuid.h"
#include "fdstream.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_XEN
@@ -216,10 +217,10 @@ xenUnifiedProbe (void)
return 1;
#endif
#ifdef __sun
- FILE *fh;
+ int fd;
- if (fh = fopen("/dev/xen/domcaps", "r")) {
- fclose(fh);
+ if ((fd = open("/dev/xen/domcaps", O_RDONLY))>= 0) {
+ VIR_FORCE_CLOSE(fd);
return 1;
}
#endif
Index: libvirt-acl/src/xen/xen_hypervisor.c
===================================================================
--- libvirt-acl.orig/src/xen/xen_hypervisor.c
+++ libvirt-acl/src/xen/xen_hypervisor.c
@@ -2641,7 +2641,7 @@ xenHypervisorMakeCapabilities(virConnect
capabilities = fopen ("/sys/hypervisor/properties/capabilities", "r");
if (capabilities == NULL) {
if (errno != ENOENT) {
- fclose(cpuinfo);
+ VIR_FORCE_FCLOSE(cpuinfo);
virReportSystemError(errno,
_("cannot read file %s"),
"/sys/hypervisor/properties/capabilities");
@@ -2654,10 +2654,8 @@ xenHypervisorMakeCapabilities(virConnect
cpuinfo,
capabilities);
- if (cpuinfo)
- fclose(cpuinfo);
- if (capabilities)
- fclose(capabilities);
+ VIR_FORCE_FCLOSE(cpuinfo);
+ VIR_FORCE_FCLOSE(capabilities);
return caps;
#endif /* __sun */
Index: libvirt-acl/tests/nodeinfotest.c
===================================================================
--- libvirt-acl.orig/tests/nodeinfotest.c
+++ libvirt-acl/tests/nodeinfotest.c
@@ -9,6 +9,7 @@
#include "internal.h"
#include "nodeinfo.h"
#include "util.h"
+#include "files.h"
#ifndef __linux__
@@ -49,10 +50,10 @@ static int linuxTestCompareFiles(const c
fprintf(stderr, "\n%s\n", error->message);
virFreeError(error);
}
- fclose(cpuinfo);
+ VIR_FORCE_FCLOSE(cpuinfo);
return -1;
}
- fclose(cpuinfo);
+ VIR_FORCE_FCLOSE(cpuinfo);
/* 'nodes' is filled using libnuma.so from current machine
* topology, which makes it unsuitable for the test suite
Index: libvirt-acl/tests/testutils.c
===================================================================
--- libvirt-acl.orig/tests/testutils.c
+++ libvirt-acl/tests/testutils.c
@@ -180,26 +180,26 @@ int virtTestLoadFile(const char *file,
if (fstat(fileno(fp),&st)< 0) {
fprintf (stderr, "%s: failed to fstat: %s\n", file, strerror(errno));
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return -1;
}
if (st.st_size> (buflen-1)) {
fprintf (stderr, "%s: larger than buffer (> %d)\n", file, buflen-1);
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return -1;
}
if (st.st_size) {
if (fread(*buf, st.st_size, 1, fp) != 1) {
fprintf (stderr, "%s: read failed: %s\n", file, strerror(errno));
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return -1;
}
}
(*buf)[st.st_size] = '\0';
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return st.st_size;
}
Index: libvirt-acl/tests/xencapstest.c
===================================================================
--- libvirt-acl.orig/tests/xencapstest.c
+++ libvirt-acl/tests/xencapstest.c
@@ -9,6 +9,7 @@
#include "xml.h"
#include "testutils.h"
#include "xen/xen_hypervisor.h"
+#include "files.h"
static char *progname;
static char *abs_srcdir;
@@ -63,10 +64,8 @@ static int testCompareFiles(const char *
fail:
free(actualxml);
- if (fp1)
- fclose(fp1);
- if (fp2)
- fclose(fp2);
+ VIR_FORCE_FCLOSE(fp1);
+ VIR_FORCE_FCLOSE(fp2);
virCapabilitiesFree(caps);
return ret;
Index: libvirt-acl/docs/hacking.html.in
===================================================================
--- libvirt-acl.orig/docs/hacking.html.in
+++ libvirt-acl/docs/hacking.html.in
@@ -414,25 +414,45 @@
<h2><a name="file_handling">File handling</a></h2>
<p>
- Use of the close() API is deprecated in libvirt code base to help
- avoiding double-closing of a file descriptor. Instead of this API,
- use the macro from files.h
+ Usage of the<code>fdopen()</code>,<code>close()</code>,<code>fclose()</code>
+ APIs is deprecated in libvirt code base to help avoiding double-closing of files
+ or file descriptors, which is particulary dangerous in a multi-threaded
+ applications. Instead of these APIs, use the macros from files.h
</p>
-<ul>
+<ul>
+<li><p>eg opening a file from a file descriptor</p>
+
+<pre>
+ if ((file = VIR_FDOPEN(fd, "r")) == NULL) {
+ virReportSystemError(errno, "%s",
+ _("failed to open file from file descriptor"));
+ return -1;
+ }
+ /* fd is now invalid; only access the file using file variable */
+</pre></li>
+
<li><p>e.g. close a file descriptor</p>
<pre>
if (VIR_CLOSE(fd)< 0) {
- virReportSystemError(errno, _("failed to close file"));
+ virReportSystemError(errno, "%s", _("failed to close file"));
}
-</pre>
-</li>
+</pre></li>
+
+<li><p>eg close a file</p>
+
+<pre>
+ if (VIR_FCLOSE(file)< 0) {
+ virReportSystemError(errno, "%s", _("failed to close file"));
+ }
+</pre></li>
-<li><p>eg close a file descriptor in an error path, without losing
+<li><p>eg close a file or file descriptor in an error path, without losing
the previous<code>errno</code> value</p>
<pre>
VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_FCLOSE(file);
</pre>
</li>
</ul>
Index: libvirt-acl/HACKING
===================================================================
--- libvirt-acl.orig/HACKING
+++ libvirt-acl/HACKING
@@ -339,22 +339,43 @@ routines, use the macros from memory.h
File handling
=============
-Use of the close() API is deprecated in libvirt code base to help avoiding
-double-closing of a file descriptor. Instead of this API, use the macro from
-files.h
+Usage of the "fdopen()", "close()", "fclose()" APIs is deprecated in libvirt
+code base to help avoiding double-closing of files or file descriptors, which
+is particulary dangerous in a multi-threaded applications. Instead of these
+APIs, use the macros from files.h
+
+- eg opening a file from a file descriptor
+
+ if ((file = VIR_FDOPEN(fd, "r")) == NULL) {
+ virReportSystemError(errno, "%s",
+ _("failed to open file from file descriptor"));
+ return -1;
+ }
+ /* fd is now invalid; only access the file using file variable */
+
+
- e.g. close a file descriptor
if (VIR_CLOSE(fd)< 0) {
- virReportSystemError(errno, _("failed to close file"));
+ virReportSystemError(errno, "%s", _("failed to close file"));
+ }
+
+
+
+- eg close a file
+
+ if (VIR_FCLOSE(file)< 0) {
+ virReportSystemError(errno, "%s", _("failed to close file"));
}
-- eg close a file descriptor in an error path, without losing the previous
-"errno" value
+- eg close a file or file descriptor in an error path, without losing the
+previous "errno" value
VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_FCLOSE(file);
Index: libvirt-acl/src/util/stats_linux.c
===================================================================
--- libvirt-acl.orig/src/util/stats_linux.c
+++ libvirt-acl/src/util/stats_linux.c
@@ -25,6 +25,7 @@
# include "util.h"
# include "stats_linux.h"
# include "memory.h"
+# include "files.h"
# define VIR_FROM_THIS VIR_FROM_STATS_LINUX
@@ -98,12 +99,12 @@ linuxDomainInterfaceStats(const char *pa
stats->tx_packets = tx_packets;
stats->tx_errs = tx_errs;
stats->tx_drop = tx_drop;
- fclose (fp);
+ VIR_FORCE_FCLOSE (fp);
return 0;
}
}
- fclose (fp);
+ VIR_FORCE_FCLOSE(fp);
virStatsError(VIR_ERR_INTERNAL_ERROR,
"/proc/net/dev: Interface not found");
Index: libvirt-acl/src/xen/block_stats.c
===================================================================
--- libvirt-acl.orig/src/xen/block_stats.c
+++ libvirt-acl/src/xen/block_stats.c
@@ -27,6 +27,7 @@
# include "util.h"
# include "block_stats.h"
# include "memory.h"
+# include "files.h"
# define VIR_FROM_THIS VIR_FROM_STATS_LINUX
@@ -100,7 +101,7 @@ read_stat (const char *path)
/* read, but don't bail out before closing */
i = fread (str, 1, sizeof str - 1, fp);
- if (fclose (fp) != 0 /* disk error */
+ if (VIR_FCLOSE(fp) != 0 /* disk error */
|| i< 1) /* ensure we read at least one byte */
return -1;
-------------------------------------------------------------
--- /root/tmp/bak/libvirt-acl/src/openvz/openvz_conf.c 2010-11-15 17:03:15.962422965 -0500
+++ src/openvz/openvz_conf.c 2010-11-16 06:31:49.716482090 -0500
@@ -887,8 +887,9 @@
openvzSetDefinedUUID(int vpsid, unsigned char *uuid)
{
char *conf_file;
char uuidstr[VIR_UUID_STRING_BUFLEN];
+ FILE *fp = NULL;
int ret = -1;
if (uuid == NULL)
return -1;
@@ -899,9 +900,9 @@
if (openvzGetVPSUUID(vpsid, uuidstr, sizeof(uuidstr)))
goto cleanup;
if (uuidstr[0] == 0) {
- FILE *fp = fopen(conf_file, "a"); /* append */
+ fp = fopen(conf_file, "a"); /* append */
if (fp == NULL)
goto cleanup;
virUUIDFormat(uuid, uuidstr);
@@ -914,8 +915,9 @@
}
ret = 0;
cleanup:
+ VIR_FORCE_FCLOSE(fp);
VIR_FREE(conf_file);
return ret;
}
--- /root/tmp/bak/libvirt-acl/src/util/files.c 2010-11-15 17:03:15.949423495 -0500
+++ src/util/files.c 2010-11-16 06:31:49.714482170 -0500
@@ -71,8 +71,10 @@
if (*fdptr>= 0) {
file = fdopen(*fdptr, mode);
if (file)
*fdptr = -1;
+ } else {
+ errno = EBADF;
}
return file;
}
--- /root/tmp/bak/libvirt-acl/src/util/files.h 2010-11-15 17:03:15.956423210 -0500
+++ src/util/files.h 2010-11-16 06:31:49.714482170 -0500
@@ -32,17 +32,19 @@
# include "internal.h"
# include "ignore-value.h"
-/* Don't call this directly - use the macros below */
+/* Don't call these directly - use the macros below */
int virClose(int *fdptr, bool preserve_errno) ATTRIBUTE_RETURN_CHECK;
int virFclose(FILE **file, bool preserve_errno) ATTRIBUTE_RETURN_CHECK;
-FILE *virFdopen(int *fdptr, const char *mode);
+FILE *virFdopen(int *fdptr, const char *mode) ATTRIBUTE_RETURN_CHECK;
/* For use on normal paths; caller must check return value,
and failure sets errno per close(). */
# define VIR_CLOSE(FD) virClose(&(FD), false)
# define VIR_FCLOSE(FILE) virFclose(&(FILE), false)
+
+/* Wrapper around fdopen that consumes fd on success. */
# define VIR_FDOPEN(FD, MODE) virFdopen(&(FD), MODE)
/* For use on cleanup paths; errno is unaffected by close,
and no return value to worry about. */
--- /root/tmp/bak/libvirt-acl/src/util/stats_linux.c 2010-11-15 17:03:15.994421659 -0500
+++ src/util/stats_linux.c 2010-11-16 06:31:49.724481766 -0500
@@ -98,9 +98,9 @@
stats->tx_bytes = tx_bytes;
stats->tx_packets = tx_packets;
stats->tx_errs = tx_errs;
stats->tx_drop = tx_drop;
- fclose (fp);
+ VIR_FORCE_FCLOSE (fp);
return 0;
}
}
--- /root/tmp/bak/libvirt-acl/src/xen/xen_driver.c 2010-11-15 17:03:15.972422557 -0500
+++ src/xen/xen_driver.c 2010-11-16 06:31:49.722481846 -0500
@@ -218,9 +218,9 @@
#endif
#ifdef __sun
int fd;
- if (fd = open("/dev/xen/domcaps", O_RDONLY)) {
+ if ((fd = open("/dev/xen/domcaps", O_RDONLY))>= 0) {
VIR_FORCE_CLOSE(fd);
return 1;
}
#endif
14 years, 4 months
[libvirt] [PATCH] nwfilter: also purge ip(6)tables rules before detecting IP address
by Stefan Berger
Rather than only cleaning any remaining ebtables rules, also clean those
applied to iptables and ip6tables when detecting the IP address of an
interface. Previous applied iptables rules may hinder DHCP packets.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
src/nwfilter/nwfilter_ebiptables_driver.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
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
@@ -117,6 +117,7 @@ static int ebtablesRemoveBasicRules(cons
static int ebiptablesDriverInit(void);
static void ebiptablesDriverShutdown(void);
static int ebtablesCleanAll(const char *ifname);
+static int ebiptablesAllTeardown(const char *ifname);
static virMutex execCLIMutex;
@@ -2942,7 +2943,7 @@ ebtablesApplyBasicRules(const char *ifna
virFormatMacAddr(macaddr, macaddr_str);
- ebtablesCleanAll(ifname);
+ ebiptablesAllTeardown(ifname);
ebtablesCreateTmpRootChain(&buf, 1, ifname, 1);
@@ -3041,7 +3042,7 @@ ebtablesApplyDHCPOnlyRules(const char *i
virFormatMacAddr(macaddr, macaddr_str);
- ebtablesCleanAll(ifname);
+ ebiptablesAllTeardown(ifname);
ebtablesCreateTmpRootChain(&buf, 1, ifname, 1);
ebtablesCreateTmpRootChain(&buf, 0, ifname, 1);
@@ -3143,7 +3144,7 @@ ebtablesApplyDropAllRules(const char *if
return 1;
}
- ebtablesCleanAll(ifname);
+ ebiptablesAllTeardown(ifname);
ebtablesCreateTmpRootChain(&buf, 1, ifname, 1);
ebtablesCreateTmpRootChain(&buf, 0, ifname, 1);
14 years, 4 months
[libvirt] Experimental 32-bit windows libvirt installer
by Justin Clift
Hi all,
If people have time to try out a tentative first "Libvirt Windows Installer", it's
online here:
http://libvirt.org/sources/win32_experimental/Libvirt-0.8.5-0.exe
At the moment it includes the libvirt development headers and libraries
for compiling against, plus the virsh shell with it's needed dependencies,
and that's about it.
It's been compiled on Windows 7 x86_64, but (in theory) might also work
on earlier windows versions like Vista and XP. (not yet tested)
A couple of notes:
+ This installer is _not_ production ready. More like early, early stage
alpha. ;)
+ This installer just repackages the files compiled using Matthias
Bolte's msys_setup scripting:
https://github.com/photron/msys_setup
+ This is a .exe installer, created using NSIS. Mathias Bolte mentioned,
it might be a better idea to use something that creates .msi files, which
I kind of agree with. So, next versions will probably not be NSIS based,
but no idea what they will be based upon yet.
+ The only connection type I've tried, and that's known to work for sure,
is qemu+tcp://. qemu+ssh:// doesn't work on windows (at this stage),
and qemu+tls:// (on windows) doesn't work due to a problem with
GnuTLS.
If anyone has time to look into the GnuTLS problem, that would be really
helpful. :)
+ This version includes Python bindings, but I haven't tried/tested them. :)
+ Suggestions for what else to include are welcome. ie. other bindings (C#,
what else?), and so on
+ The NSIS installer scripting is on github if anyone's interested:
https://github.com/justinclift/nsis_libvirt_installer
Regards and best wishes,
Justin Clift
14 years, 4 months