[libvirt] [PATCH] Avoid pthread_sigmask on Win32 platforms
by Daniel P. Berrange
Win32 doesn't have a concept of signal masks so disable that
code. It is unclear how SIGINT is delivered (if at all) on
Win32, so this might further work to provide an alternative
to pthread_sigmask
* tools/virsh.c: Avoid pthread_sigmask on Win32
---
tools/virsh.c | 20 +++++++++++++++-----
1 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index be2cd67..6d9861f 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -3489,15 +3489,17 @@ doMigrate (void *opaque)
const char *migrateuri;
const char *dname;
int flags = 0, found;
- sigset_t sigmask, oldsigmask;
vshCtrlData *data = opaque;
vshControl *ctl = data->ctl;
const vshCmd *cmd = data->cmd;
+#if HAVE_PTHREAD_SIGMASK
+ sigset_t sigmask, oldsigmask;
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGINT);
if (pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask) < 0)
goto out_sig;
+#endif
if (!vshConnectionUsability (ctl, ctl->conn))
goto out;
@@ -3563,8 +3565,10 @@ doMigrate (void *opaque)
}
out:
+#if HAVE_PTHREAD_SIGMASK
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
out_sig:
+#endif
if (dom) virDomainFree (dom);
ignore_value(safewrite(data->writefd, &ret, sizeof(ret)));
}
@@ -3607,12 +3611,16 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
struct sigaction old_sig_action;
virDomainJobInfo jobinfo;
bool verbose = false;
- sigset_t sigmask, oldsigmask;
int timeout;
struct timeval start, curr;
bool live_flag = false;
-
vshCtrlData data;
+#if HAVE_PTHREAD_SIGMASK
+ sigset_t sigmask, oldsigmask;
+
+ sigemptyset(&sigmask);
+ sigaddset(&sigmask, SIGINT);
+#endif
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
@@ -3665,8 +3673,6 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
pollfd.fd = p[0];
pollfd.events = POLLIN;
pollfd.revents = 0;
- sigemptyset(&sigmask);
- sigaddset(&sigmask, SIGINT);
GETTIMEOFDAY(&start);
while (1) {
@@ -3709,9 +3715,13 @@ repoll:
}
if (verbose) {
+#if HAVE_PTHREAD_SIGMASK
pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask);
+#endif
ret = virDomainGetJobInfo(dom, &jobinfo);
+#if HAVE_PTHREAD_SIGMASK
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
+#endif
if (ret == 0)
print_job_progress(jobinfo.dataRemaining, jobinfo.dataTotal);
}
--
1.7.4
13 years, 8 months
[libvirt] [PATCH] build: avoid problems with autogen.sh runs from tarball
by Eric Blake
Introduced by commit fac97c65c distributing cfg.mk, which
previously could blindly assume it was in a git checkout.
* cfg.mk (_update_required): Also check for .git.
* autogen.sh: Don't run bootstrap from a tarball.
Reported by Daniel Veillard.
---
This should fix the issues of mistakenly running git on a tarball,
as reported here:
https://www.redhat.com/archives/libvir-list/2011-February/msg00371.html
autogen.sh | 27 +++++++++++++++------------
cfg.mk | 1 +
2 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/autogen.sh b/autogen.sh
index ff13fd1..b64521e 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -8,8 +8,8 @@ THEDIR=`pwd`
cd "$srcdir"
test -f src/libvirt.c || {
- echo "You must run this script in the top-level libvirt directory"
- exit 1
+ echo "You must run this script in the top-level libvirt directory"
+ exit 1
}
@@ -52,16 +52,19 @@ bootstrap_hash()
# Also, running 'make rpm' tends to litter the po/ directory, and some people
# like to run 'git clean -x -f po' to fix it; but only ./bootstrap regenerates
# the required file po/Makevars.
-curr_status=.git-module-status
-t=$(bootstrap_hash; git diff .gnulib)
-if test "$t" = "$(cat $curr_status 2>/dev/null)" \
- && test -f "po/Makevars"; then
- # good, it's up to date, all we need is autoreconf
- autoreconf -if
-else
- echo running bootstrap$no_git...
- ./bootstrap$no_git --bootstrap-sync && bootstrap_hash > $curr_status \
- || { echo "Failed to bootstrap, please investigate."; exit 1; }
+# Only run bootstrap from a git checkout, never from a tarball.
+if test -d .git; then
+ curr_status=.git-module-status
+ t=$(bootstrap_hash; git diff .gnulib)
+ if test "$t" = "$(cat $curr_status 2>/dev/null)" \
+ && test -f "po/Makevars"; then
+ # good, it's up to date, all we need is autoreconf
+ autoreconf -if
+ else
+ echo running bootstrap$no_git...
+ ./bootstrap$no_git --bootstrap-sync && bootstrap_hash > $curr_status \
+ || { echo "Failed to bootstrap, please investigate."; exit 1; }
+ fi
fi
cd "$THEDIR"
diff --git a/cfg.mk b/cfg.mk
index 120f452..4bbeb96 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -507,6 +507,7 @@ ifeq (0,$(MAKELEVEL))
_submodule_hash = sed 's/^[ +-]//;s/ .*//'
_update_required := $(shell \
cd '$(srcdir)'; \
+ test -d .git || { echo 0; exit; }; \
test -f po/Makevars || { echo 1; exit; }; \
actual=$$(git submodule status | $(_submodule_hash); \
git hash-object bootstrap.conf; \
--
1.7.4
13 years, 8 months
[libvirt] Unix socket credentials on OSX?
by Justin Clift
Hi all,
Interestingly, MacOS X has a working PolicyKit port, providing version 0.96.
Attempting to build libvirt 0.8.7 against it gives this error though:
libvirtd.c:1298:4: error: #error "UNIX socket credentials not supported/implemented on this platform yet..."
Does anyone have an idea of whether implementing Unix socket credentials for OSX would be a big task, or a small one, or ?
I'm thinking this could be what's needed to let qemu+ssh:// connections from OSX to RHEL/Fedora servers work.
Not critical at all, but would be nice, etc. :)
Regards and best wishes,
Justin Clift
13 years, 8 months
[libvirt] [PATCH v2] xen: Prevent updating device when attaching a device
by Osier Yang
When attaching a device that already exists, xend driver updates
the device with "device_configure", it causes problems (e.g. for
disk device, 'device_configure' only can be used to update device
like CDROM), on the other hand, we provide additional API
(virDomainUpdateDevice) to update device, this fix is to raise up
errors instead of updating the existed device which is not CDROM
device.
Changes from v1 to v2:
- allow update CDROM
* src/xen/xend_internal.c
---
src/xen/xend_internal.c | 42 +++++++++++++++++++++++++++++++++++++-----
1 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index cd30336..bc23595 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -3965,6 +3965,7 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, const char *xml,
virDomainDefPtr def = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
char class[8], ref[80];
+ char *target = NULL;
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__);
@@ -4029,6 +4030,13 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, const char *xml,
STREQ(def->os.type, "hvm") ? 1 : 0,
priv->xendConfigVersion, 1) < 0)
goto cleanup;
+
+ if (dev->data.disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
+ if (!(target = strdup(dev->data.disk->dst))) {
+ virReportOOMError();
+ goto cleanup;
+ }
+ }
break;
case VIR_DOMAIN_DEVICE_NET:
@@ -4038,6 +4046,14 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, const char *xml,
STREQ(def->os.type, "hvm") ? 1 : 0,
priv->xendConfigVersion, 1) < 0)
goto cleanup;
+
+ char macStr[VIR_MAC_STRING_BUFLEN];
+ virFormatMacAddr(dev->data.net->mac, macStr);
+
+ if (!(target = strdup(macStr))) {
+ virReportOOMError();
+ goto cleanup;
+ }
break;
case VIR_DOMAIN_DEVICE_HOSTDEV:
@@ -4046,6 +4062,17 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, const char *xml,
if (xenDaemonFormatSxprOnePCI(dev->data.hostdev,
&buf, 0) < 0)
goto cleanup;
+
+ virDomainDevicePCIAddress PCIAddr;
+
+ PCIAddr = dev->data.hostdev->source.subsys.u.pci;
+ virAsprintf(&target, "PCI device: %.4x:%.2x:%.2x", PCIAddr.domain,
+ PCIAddr.bus, PCIAddr.slot);
+
+ if (target == NULL) {
+ virReportOOMError();
+ goto cleanup;
+ }
} else {
virXendError(VIR_ERR_NO_SUPPORT, "%s",
_("unsupported device type"));
@@ -4065,17 +4092,22 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, const char *xml,
/* device doesn't exist, define it */
ret = xend_op(domain->conn, domain->name, "op", "device_create",
"config", sexpr, NULL);
- }
- else {
- /* device exists, attempt to modify it */
- ret = xend_op(domain->conn, domain->name, "op", "device_configure",
- "config", sexpr, "dev", ref, NULL);
+ } else {
+ if (dev->data.disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
+ virXendError(VIR_ERR_OPERATION_INVALID,
+ _("target '%s' already exists"), target);
+ } else {
+ /* device exists, attempt to modify it */
+ ret = xend_op(domain->conn, domain->name, "op", "device_configure",
+ "config", sexpr, "dev", ref, NULL);
+ }
}
cleanup:
VIR_FREE(sexpr);
virDomainDefFree(def);
virDomainDeviceDefFree(dev);
+ VIR_FREE(target);
return ret;
}
--
1.7.3.2
13 years, 8 months
[libvirt] [PATCH] build: fix cygwin strerror_r failure
by Eric Blake
Building the 0.8.8 release candidate on cygwin produced this compiler
warning, which is indicative of catastrophic failure on any attempt to
print an error message with errno turned to a string:
CC strerror_r.lo
strerror_r.c: In function 'rpl_strerror_r':
strerror_r.c:67: warning: assignment makes integer from pointer without a cast
This has been fixed in gnulib.
* .gnulib: Update to latest, for strerror_r fix.
* src/util/memory.c (includes): Satisfy 'make syntax-check'.
---
Pushing this under the build-breaker rule, even if cygwin is the
only platform where the build was broken.
* .gnulib 2f41af6...4cce65c (113):
> doc: update users.txt
> doc: update users.txt
> doc: update users.txt
> gnulib-tool: Make copyright notice adjustment more robust.
> New module 'towctrans'.
> New module 'wctrans'.
> New module 'iswctype'.
> New module 'wctype'.
> wctype-h: Ensure wctype_t and wctrans_t are defined.
> flock: fix license typo
> Split large sed scripts, for HP-UX sed.
> stdlib: improve random_r modularization
> stdlib: don't depend on stdint
> getloadavg: don't depend on c-strtod, cloexec, fcntl-safer
> di-set.h, ino-map.h: add multiple-inclusion guard
> iswblank: Ensure declaration on glibc systems.
> New module 'iswblank'.
> di-set tests: Refactor.
> ino-map tests: Refactor.
> di-set: add "const" to a cast
> ChangeLog: fix my old entry to give credit to Bastien
> update from texinfo
> Rename module 'wctype' to 'wctype-h'.
> New module 'wcswidth'.
> New module 'wcstok'.
> New module 'wcsstr'.
> New module 'wcspbrk'.
> New module 'wcsspn'.
> New module 'wcscspn'.
> New module 'wcsrchr'.
> New module 'wcschr'.
> New module 'wcsdup'.
> New module 'wcsxfrm'.
> New module 'wcscoll'.
> New module 'wcsncasecmp'.
> New module 'wcscasecmp'.
> New module 'wcsncmp'.
> New module 'wcscmp'.
> New module 'wcsncat'.
> New module 'wcscat'.
> New module 'wcpncpy'.
> New module 'wcsncpy'.
> New module 'wcpcpy'.
> New module 'wcscpy'.
> New module 'wcsnlen'.
> New module 'wcslen'.
> New module 'wmemset'.
> New module 'wmemmove'.
> New module 'wmemcpy'.
> New module 'wmemcmp'.
> di-set, ino-map: new modules, from coreutils
> getloadavg: merge minor changes from Emacs
> Allow multiple gnulib generated replacements to coexist.
> libposix: Revert the unreviewed part of yesterday's big merge.
> unsetenv: work around Haiku issues
> libposix: Add _HEADERS primaries to posix modules. Modify gnulib-tool to strip them from generated Makefile.am-s where they are not needed. Also, replace M4 macro prefixes when requested. Finally, omit calls to error() for libposix.
> strerror_r-posix: port to cygwin
> New module 'wmemchr', part 3.
> New module 'wmemchr', part 2.
> New module 'wmemchr'.
> fdopendir: detect FreeBSD bug
> stdbool: do not define HAVE_STDBOOL_H
> wcsnrtombs: Prepare for new module wwcsnrtombs.
> wcsrtombs: Prepare for new module wwcsrtombs.
> mbsnrtowcs: Prepare for new module mbsnrtowwcs.
> mbsrtowcs: Prepare for new module mbsrtowwcs.
> vasnprintf: Reduce use of malloc for small format strings.
> autoudpate
> update from texinfo
> dup2: work around Haiku bug
> doc: off_t is not available in eglibc 2.11.2 stdio.h.
> ignore-value: add missing test dependency
> mktime: clarify long_int width checking
> ignore-value: Fix self-test.
> TYPE_MAXIMUM: avoid theoretically undefined behavior
> mktime: #undef mktime before #defining it
> mktime: systematically normalize tm_isdst comparisons
> mktime: fix some integer overflow issues and sidestep the rest
> mktime: avoid infinite loop
> rename, unlink, same-inode: Relicense.
> mktime: avoid problems on NetBSD 5 / i386
> autoupdate
> mktime: fix misspelling in comment
> move-if-change: cope with concurrent mv of identical file.
> users.txt: Mention sharutils.
> doc: Update users.txt
> Prepare for supporting FreeBSD 10.
> Prepare for supporting FreeBSD 10.
> vma-iter, get-rusage-as: Add OpenBSD support.
> more make vars for makeinfo
> regen
> fcntl: work around Haiku F_DUPFD bugs
> autoupdate
> Enable memory leak tests on AIX.
> Tests for module 'get-rusage-data'.
> New module 'get-rusage-data'.
> get-rusage-as: Allow for easier testing.
> vma-iter: Treat Haiku like BeOS.
> c-stack: fix regression on cygwin when libsigsegv is present
> autoupdate
> vma-iter: Avoid empty intervals.
> u64: remove unnecessary #include
> Allow the user to avoid the GNULIB_TEST_* macros.
> New module 'vma-iter'.
> uninorm: Tweak includes.
> get-rusage-as: Improve on NetBSD.
> xreadlink.h: remove unnecessary #include
> maint.mk: add syntax-check rule: detect unnecessary #include <stddef.h>
> get-rusage-as: Fix bug.
> wctype: Ensure valid C syntax.
> wctype: Ensure valid C syntax.
> getopt: omit HAVE_OPTRESET, HAVE_GETOPT_CLIP from config.h
> gl_CHECK_NEXT_HEADERS implies AC_CHECK_HEADERS_ONCE
.gnulib | 2 +-
src/util/memory.c | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/.gnulib b/.gnulib
index 2f41af6..4cce65c 160000
--- a/.gnulib
+++ b/.gnulib
@@ -1 +1 @@
-Subproject commit 2f41af65087fb2460779bc4e7fb62453f79ebae3
+Subproject commit 4cce65cb2f10936f13760625f39d532564984fde
diff --git a/src/util/memory.c b/src/util/memory.c
index 03e2e80..bfa32a8 100644
--- a/src/util/memory.c
+++ b/src/util/memory.c
@@ -1,7 +1,7 @@
/*
* memory.c: safer memory allocation
*
- * Copyright (C) 2010 Red Hat, Inc.
+ * Copyright (C) 2010-2011 Red Hat, Inc.
* Copyright (C) 2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@@ -22,7 +22,6 @@
#include <config.h>
#include <stdlib.h>
-#include <stddef.h>
#include "memory.h"
#include "ignore-value.h"
--
1.7.4
13 years, 8 months
[libvirt] [PATCH] qemu: Fix escape_monitor(escape_shell(command))
by Philipp Hahn
Suspending a VM which contains shell meta characters doesn't work with
libvirt-0.8.7:
/var/log/libvirt/qemu/andreas_231-ne\ doch\ nicht.log:
sh: -c: line 0: syntax error near unexpected token `doch'
sh: -c: line 0: `cat | { dd bs=4096 seek=1 if=/dev/null && dd bs=1048576; }
Although target="andreas_231-ne doch nicht" contains shell meta
characters (here: blanks), they are not properly escaped by
src/qemu/qemu_monitor_{json,text}.c#qemuMonitor{JSON,Text}MigrateToFile()
First, the filename needs to be properly escaped for the shell, than
this command line has to be properly escaped for qemu again.
For this to work, remove the old qemuMonitorEscapeArg() wrapper, rename
qemuMonitorEscape() to it removing the handling for shell=TRUE, and
implement a new qemuMonitorEscapeShell() returning strings using single
quotes.
Using double quotes or escaping special shell characters with backslashes
would also be possible, but the set of special characters heavily
depends on the concrete shell (dsh, bash, zsh) and its setting (history
expansion, interactive use, ...)
Signed-off-by: Philipp Hahn <hahn(a)univention.de>
---
src/qemu/qemu_monitor.c | 65 +++++++++++++++++++++++++++-------------------
1 files changed, 38 insertions(+), 27 deletions(-)
13 years, 8 months
[libvirt] [RFC PATCH 0/6] Switch over qemu command line capabilities to virBitmap
by Jiri Denemark
There are two main reasons behind this patchset:
- we are getting very close to 64 flags which is the maximum we can use with
unsigned long long
- by using LL constants in enum we already violates C99 constraint that enum
values have to fit into int
This is a very conflict-prone patchset so I'd like to get some feedback on the
ideas and naming used so that this could possible be among the first patches
pushed after 0.8.8 release.
Patches 2/6 and 4/6 are fully and 3/6 mostly mechanical. 5/6 and 6/6 need to be
squashed into a single patch but are provided separately for easier review.
Jiri Denemark (6):
util: Add API for converting virBitmap into printable string
qemu: Rename QEMUD_CMD_FLAG_* to QEMU_CAPS_*
qemu: Use helper functions for handling cmd line capabilities
qemu: Rename qemud\?CmdFlags to qemuCaps
qemu: Switch over command line capabilities to virBitmap
tests: Use virBitmap for qemu command line caps
src/libvirt_private.syms | 1 +
src/qemu/qemu_capabilities.c | 238 +++++++++-----
src/qemu/qemu_capabilities.h | 150 +++++----
src/qemu/qemu_command.c | 384 +++++++++++-----------
src/qemu/qemu_command.h | 30 +-
src/qemu/qemu_driver.c | 106 ++++---
src/qemu/qemu_hotplug.c | 162 +++++-----
src/qemu/qemu_hotplug.h | 32 +-
src/util/bitmap.c | 32 ++-
src/util/bitmap.h | 3 +
tests/qemuargv2xmltest.c | 2 +-
tests/qemuhelptest.c | 745 +++++++++++++++++++++---------------------
tests/qemuxml2argvtest.c | 470 +++++++++++++-------------
13 files changed, 1249 insertions(+), 1106 deletions(-)
--
1.7.4
13 years, 8 months
[libvirt] [PATCH] Imprint all logs with version + package build information
by Daniel P. Berrange
The logging functions are enhanced so that immediately prior to
the first log message being printed to any output channel, the
libvirt package version will be printed.
eg
$ LIBVIRT_DEBUG=1 virsh
18:13:28.013: 17536: info : libvirt version: 0.8.7
18:13:28.013: 17536: debug : virInitialize:361 : register drivers
...
The 'configure' script gains two new arguments which can be
used as
--with-packager="Fedora Project, x86-01.phx2.fedoraproject.org, 01-27-2011-18:00:10"
--with-packager-version="1.fc14"
to allow distros to append a custom string with package specific
data.
The RPM specfile is modified so that it appends the RPM version,
the build host, the build date and the packager name.
eg
$ LIBVIRT_DEBUG=1 virsh
18:14:52.086: 17551: info : libvirt version: 0.8.7, package: 1.fc13 (Fedora Project, x86-01.phx2.fedoraproject.org, 01-27-2011-18:00:10)
18:14:52.086: 17551: debug : virInitialize:361 : register drivers
Thus when distro packagers receive bug reports they can clearly
see what version was in use, even if the bug reporter mistakenly
or intentionally lies about version/builds
* src/util/logging.c: Output version data prior to first log message
* libvirt.spec.in: Include RPM release, date, hostname & packager
* configure.ac: Add --with-packager & --with-packager-version args
---
configure.ac | 19 +++++++++++
libvirt.spec.in | 9 +++++
src/util/logging.c | 91 +++++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 104 insertions(+), 15 deletions(-)
diff --git a/configure.ac b/configure.ac
index 8a4083f..3cd824a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,6 +29,25 @@ AC_SUBST([LIBVIRT_VERSION])
AC_SUBST([LIBVIRT_VERSION_INFO])
AC_SUBST([LIBVIRT_VERSION_NUMBER])
+AC_ARG_WITH([packager],
+ [AS_HELP_STRING([--with-packager],
+ [Extra packager name])],
+ [],[])
+AC_ARG_WITH([packager-version],
+ [AS_HELP_STRING([--with-packager-version],
+ [Extra packager version])],
+ [],[])
+if test "x$with_packager" != "xno"
+then
+ AC_DEFINE_UNQUOTED([PACKAGER], ["$with_packager"],
+ [Extra package name])
+fi
+if test "x$with_packager_version" != "xno"
+then
+ AC_DEFINE_UNQUOTED([PACKAGER_VERSION], ["$with_packager_version"],
+ [Extra package version])
+fi
+
dnl Required minimum versions of all libs we depend on
LIBXML_REQUIRED="2.6.0"
GNUTLS_REQUIRED="1.0.25"
diff --git a/libvirt.spec.in b/libvirt.spec.in
index 0a2d10e..da1fe4a 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -592,6 +592,13 @@ of recent versions of Linux (and other OSes).
%define _without_dtrace --without-dtrace
%endif
+%define when %(date +"%%m-%%d-%%Y-%%H:%%M:%%S")
+%define where %(hostname)
+%define who %{?packager}%{!?packager:Unknown}
+%define with_packager --with-packager="%{who}, %{when}, %{where}"
+%define with_packager_version --with-packager-version="%{release}"
+
+
%configure %{?_without_xen} \
%{?_without_qemu} \
%{?_without_openvz} \
@@ -626,6 +633,8 @@ of recent versions of Linux (and other OSes).
%{?_without_macvtap} \
%{?_without_audit} \
%{?_without_dtrace} \
+ %{with_packager} \
+ %{with_packager_version} \
--with-qemu-user=%{qemu_user} \
--with-qemu-group=%{qemu_group} \
--with-init-script=redhat \
diff --git a/src/util/logging.c b/src/util/logging.c
index a80c3e3..85406bf 100644
--- a/src/util/logging.c
+++ b/src/util/logging.c
@@ -108,6 +108,7 @@ static int virLogNbFilters = 0;
* after filtering, multiple output can be used simultaneously
*/
struct _virLogOutput {
+ bool logVersion;
void *data;
virLogOutputFunc f;
virLogCloseFunc c;
@@ -490,6 +491,7 @@ int virLogDefineOutput(virLogOutputFunc f, virLogCloseFunc c, void *data,
goto cleanup;
}
ret = virLogNbOutputs++;
+ virLogOutputs[ret].logVersion = true;
virLogOutputs[ret].f = f;
virLogOutputs[ret].c = c;
virLogOutputs[ret].data = data;
@@ -501,6 +503,55 @@ cleanup:
return ret;
}
+static int
+virLogFormatString(char **msg,
+ const char *funcname,
+ long long linenr,
+ struct tm *time_info,
+ struct timeval *cur_time,
+ int priority,
+ const char *str)
+{
+ int ret;
+ if ((funcname != NULL)) {
+ ret = virAsprintf(msg, "%02d:%02d:%02d.%03d: %d: %s : %s:%lld : %s\n",
+ time_info->tm_hour, time_info->tm_min,
+ time_info->tm_sec, (int) cur_time->tv_usec / 1000,
+ virThreadSelfID(),
+ virLogPriorityString(priority), funcname, linenr, str);
+ } else {
+ ret = virAsprintf(msg, "%02d:%02d:%02d.%03d: %d: %s : %s\n",
+ time_info->tm_hour, time_info->tm_min,
+ time_info->tm_sec, (int) cur_time->tv_usec / 1000,
+ virThreadSelfID(),
+ virLogPriorityString(priority), str);
+ }
+ return ret;
+}
+
+static int
+virLogVersionString(char **msg,
+ struct tm *time_info,
+ struct timeval *cur_time)
+{
+#ifdef PACKAGER_VERSION
+# ifdef PACKAGER
+# define LOG_VERSION_STRING \
+ "libvirt version: " VERSION ", package: " PACKAGER_VERSION " (" PACKAGER ")"
+# else
+# define LOG_VERSION_STRING \
+ "libvirt version: " VERSION ", package: " PACKAGER_VERSION
+# endif
+#else
+# define LOG_VERSION_STRING \
+ "libvirt version: " VERSION
+#endif
+
+ return virLogFormatString(msg, NULL, 0,
+ time_info, cur_time,
+ VIR_LOG_INFO, LOG_VERSION_STRING);
+}
+
/**
* virLogMessage:
* @category: where is that message coming from
@@ -516,6 +567,7 @@ cleanup:
*/
void virLogMessage(const char *category, int priority, const char *funcname,
long long linenr, int flags, const char *fmt, ...) {
+ static bool logVersionStderr = true;
char *str = NULL;
char *msg;
struct timeval cur_time;
@@ -547,19 +599,9 @@ void virLogMessage(const char *category, int priority, const char *funcname,
gettimeofday(&cur_time, NULL);
localtime_r(&cur_time.tv_sec, &time_info);
- if ((funcname != NULL)) {
- ret = virAsprintf(&msg, "%02d:%02d:%02d.%03d: %d: %s : %s:%lld : %s\n",
- time_info.tm_hour, time_info.tm_min,
- time_info.tm_sec, (int) cur_time.tv_usec / 1000,
- virThreadSelfID(),
- virLogPriorityString(priority), funcname, linenr, str);
- } else {
- ret = virAsprintf(&msg, "%02d:%02d:%02d.%03d: %d: %s : %s\n",
- time_info.tm_hour, time_info.tm_min,
- time_info.tm_sec, (int) cur_time.tv_usec / 1000,
- virThreadSelfID(),
- virLogPriorityString(priority), str);
- }
+ ret = virLogFormatString(&msg, funcname, linenr,
+ &time_info, &cur_time,
+ priority, str);
VIR_FREE(str);
if (ret < 0) {
/* apparently we're running out of memory */
@@ -578,12 +620,31 @@ void virLogMessage(const char *category, int priority, const char *funcname,
virLogStr(msg, len);
virLogLock();
for (i = 0; i < virLogNbOutputs;i++) {
- if (priority >= virLogOutputs[i].priority)
+ if (priority >= virLogOutputs[i].priority) {
+ if (virLogOutputs[i].logVersion) {
+ char *ver = NULL;
+ if (virLogVersionString(&ver, &time_info, &cur_time) >= 0)
+ virLogOutputs[i].f(category, priority, __func__, __LINE__,
+ ver, strlen(ver),
+ virLogOutputs[i].data);
+ VIR_FREE(ver);
+ virLogOutputs[i].logVersion = false;
+ }
virLogOutputs[i].f(category, priority, funcname, linenr,
msg, len, virLogOutputs[i].data);
+ }
}
- if ((virLogNbOutputs == 0) && (flags != 1))
+ if ((virLogNbOutputs == 0) && (flags != 1)) {
+ if (logVersionStderr) {
+ char *ver = NULL;
+ if (virLogVersionString(&ver, &time_info, &cur_time) >= 0)
+ ignore_value (safewrite(STDERR_FILENO,
+ ver, strlen(ver)));
+ VIR_FREE(ver);
+ logVersionStderr = false;
+ }
ignore_value (safewrite(STDERR_FILENO, msg, len));
+ }
virLogUnlock();
VIR_FREE(msg);
--
1.7.3.5
13 years, 8 months