[libvirt] [PATCH] tests: Fix VIR_TEST_REGENERATE_OUTPUT
by Cole Robinson
commit 950a90d489 mocked some virCommand handling for the qemu tests,
but we were using that in the test suite to call test-wrap-argv.pl for
regenerating test output.
Switch the generator code to just use system() instead
---
tests/testutils.c | 19 +++++--------------
1 file changed, 5 insertions(+), 14 deletions(-)
diff --git a/tests/testutils.c b/tests/testutils.c
index a0ce4b6..4f3e67b 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -434,24 +434,15 @@ virTestRewrapFile(const char *filename)
{
int ret = -1;
char *outbuf = NULL;
- char *script = NULL;
- virCommandPtr cmd = NULL;
+ char *cmd = NULL;
- if (virAsprintf(&script, "%s/test-wrap-argv.pl", abs_srcdir) < 0)
+ if (virAsprintf(&cmd, "echo \"$(%s/test-wrap-argv.pl %s)\" > %s",
+ abs_srcdir, filename, filename) < 0)
goto cleanup;
- cmd = virCommandNewArgList(script, filename, NULL);
- virCommandSetOutputBuffer(cmd, &outbuf);
- if (virCommandRun(cmd, NULL) < 0)
- goto cleanup;
-
- if (virFileWriteStr(filename, outbuf, 0666) < 0)
- goto cleanup;
-
- ret = 0;
+ ret = system(cmd);
cleanup:
- VIR_FREE(script);
- virCommandFree(cmd);
+ VIR_FREE(cmd);
VIR_FREE(outbuf);
return ret;
}
--
2.7.3
8 years, 8 months
[libvirt] [PATCH 0/7] Add notification for memory hot-unplug failure
by Peter Krempa
Add a new libvirt event VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED that will
handle failure to unplug a device if we are certain that it will not be unplugged
and wire up the ACPI_DEVICE_OST qemu event that is emitted on memory hotunplug
failure so that the event is propagated and the API fails in such case.
Along with that a few refactors were necessary.
Peter Krempa (7):
qemu: hotplug: Properly handle errors in
qemuDomainWaitForDeviceRemoval
qemu: hotplug: Refactor semantics of qemuDomainWaitForDeviceRemoval
qemu: Use domain condition for device removal singalling
qemu: hotplug: Add support for signalling device unplug failure
Add VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED event
qemu: monitor: Add support for ACPI_DEVICE_OST event handling
qemu: process: Wire up ACPI OST events to notify users of failed
memory unplug
daemon/remote.c | 36 +++++++++++++
include/libvirt/libvirt-domain.h | 21 ++++++++
src/conf/domain_event.c | 84 ++++++++++++++++++++++++++++++
src/conf/domain_event.h | 7 +++
src/libvirt_private.syms | 2 +
src/qemu/qemu_domain.c | 4 --
src/qemu/qemu_domain.h | 18 ++++++-
src/qemu/qemu_hotplug.c | 110 +++++++++++++++++----------------------
src/qemu/qemu_hotplug.h | 3 +-
src/qemu/qemu_monitor.c | 19 +++++++
src/qemu/qemu_monitor.h | 18 +++++++
src/qemu/qemu_monitor_json.c | 39 ++++++++++++++
src/qemu/qemu_process.c | 71 ++++++++++++++++++++++++-
src/remote/remote_driver.c | 30 +++++++++++
src/remote/remote_protocol.x | 14 ++++-
src/remote_protocol-structs | 6 +++
tools/virsh-domain.c | 18 +++++++
17 files changed, 428 insertions(+), 72 deletions(-)
--
2.8.0
8 years, 8 months
[libvirt] [PATCH 0/4] Test cleanups
by Ján Tomko
Noticed these while I was trying to look for an easy solution
to the VIR_TEST_REGENERATE_OUTPUT problem.
Ján Tomko (4):
drop qemuBuildCommandLineCallbacks
tests: clean up includes
qemuxml2argvtest: drop FLAG_EXPECT_ERROR
qemu: assign addresses before aliases
src/qemu/qemu_command.c | 35 +++++++++++------------------------
src/qemu/qemu_command.h | 18 ++----------------
src/qemu/qemu_hotplug.c | 3 +--
src/qemu/qemu_process.c | 29 ++++++++++++++---------------
tests/qemuxml2argvtest.c | 35 ++++++++++-------------------------
tests/qemuxml2xmltest.c | 2 +-
tests/testutilsqemu.c | 19 -------------------
tests/testutilsqemu.h | 3 +--
8 files changed, 40 insertions(+), 104 deletions(-)
--
2.7.3
8 years, 8 months
[libvirt] backport politics to redhat/centos
by Vasiliy Tolstov
Hi! I'm need to use CentOS for some project and i want to not modify
all my stuff (i'm use plain ethernet devices with bird routing
daemon).
CentOS have libvirt 1.2.17, does redhat in near feature want to
backport my ethernet changes to main branches or not?
Sorry for my questions.
--
Vasiliy Tolstov,
e-mail: v.tolstov(a)selfip.ru
8 years, 8 months
[libvirt] [PATCH 00/18] cleanup of graphics code
by Pavel Hrdina
Pavel Hrdina (18):
tests: remove unwanted VIR_FREE of spice and vnc default listen
docs: rewrite graphics XML documentation
domain_conf: introduce virDomainGraphicsListensParseXML
domain_conf: cleanup virDomainGraphicsListensParseXML
domain_conf: split graphics xml parser into multiple functions
domain_conf: cleanup error paths for graphics parser
domain_conf: introduce virDomainGraphicsListenAddAddress
domain_conf: introduce virDomainGraphicsListenAddNetwork
domain_conf: remove unused virDomainGraphicsListenSetType
domain_conf: cleanup virDomainGraphicsGetListen
use virDomainGraphicsGetListen instead of the other getters
domain_conf: cleanup virDomainGraphicsListenDefParseXML
domain_conf: remove unused virDomainGraphicsListenGet*
domain_conf: call ...ListensParseXML only for appropriate graphics
qemu_process: generate vnc unix socket in qemuProcessPrepareDomain
qemu_process: move listen code out of qemuProcessSetupGraphics
domain_conf: introduce virDomainGraphicsListenClear
qemu_domain: remove all listens if vncAutoUnixSocket is enabled
docs/formatdomain.html.in | 351 +++---
src/conf/domain_conf.c | 1163 ++++++++++----------
src/conf/domain_conf.h | 24 +-
src/libvirt_private.syms | 10 +-
src/libxl/libxl_conf.c | 15 +-
src/qemu/qemu_command.c | 120 +-
src/qemu/qemu_command.h | 3 +-
src/qemu/qemu_domain.c | 10 +
src/qemu/qemu_migration.c | 9 +-
src/qemu/qemu_parse_command.c | 4 +-
src/qemu/qemu_process.c | 69 +-
src/vbox/vbox_common.c | 14 +-
src/vmx/vmx.c | 9 +-
src/vz/vz_sdk.c | 11 +-
src/xenconfig/xen_common.c | 28 +-
src/xenconfig/xen_sxpr.c | 20 +-
src/xenconfig/xen_xl.c | 12 +-
.../qemuxml2argv-graphics-spice-timeout.args | 2 +-
...-graphics-vnc-auto-unix-socket-with-listen.args | 22 +
...v-graphics-vnc-auto-unix-socket-with-listen.xml | 36 +
...qemuxml2argv-graphics-vnc-auto-unix-socket.args | 22 +
.../qemuxml2argv-graphics-vnc-auto-unix-socket.xml | 34 +
tests/qemuxml2argvtest.c | 8 +-
23 files changed, 1051 insertions(+), 945 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket-with-listen.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket-with-listen.xml
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-auto-unix-socket.xml
--
2.7.4
8 years, 8 months
[libvirt] [PATCH 0/2] host-validate: Don't build on Windows
by Andrea Bolognani
The recent fixes to virt-host-validate have caused the mingw
build to fail[1].
Instead of working around Windows' quirks in the tool, just
stop building it altogether - it's not like it made any
sense to have it available on that OS anyway.
Cheers.
[1] https://ci.centos.org/view/libvirt-project/job/libvirt-mingw/1496/
Andrea Bolognani (2):
tools: Reorganize conditional bits
configure: Make virt-host-validate optional
configure.ac | 29 ++++++++++++++++++-----------
m4/virt-host-validate.m4 | 40 ++++++++++++++++++++++++++++++++++++++++
tools/Makefile.am | 35 ++++++++++++++++++-----------------
3 files changed, 76 insertions(+), 28 deletions(-)
create mode 100644 m4/virt-host-validate.m4
--
2.5.5
8 years, 8 months
[libvirt] [PATCH 00/10] conf: disk xml parser refactors
by Peter Krempa
I unfortunately looked at this function. I did not like what I've seen.
Let's start making it a bit more bearable.
This series starts splitting and cleaning up virDomainDiskDefParseXML which is
an unmaintainable spaghettti-code mess currently.
Peter Krempa (10):
util: Rename and move virStrIsPrint to virStringIsPrintable
conf: disk: Don't initialize fields allocated by calloc
conf: disk: Remove one unnecessary level of indentation
conf: disk: Extract iotune parsing into a separate func
conf: disk: Remove error label from virDomainDiskDefIotuneParse
conf: virDomainDiskDefIotuneParse: simplfiy parsing
conf: virDomainDiskDefIotuneParse: Report malformed number errors
conf: disk: Split out parsing of disk mirror data
conf: Refactor virDomainDiskDefMirrorParse
conf: extract disk geometry parsing code
src/conf/domain_conf.c | 777 ++++++++++++++++++++++-------------------------
src/libvirt_private.syms | 2 +-
src/util/virstring.c | 18 ++
src/util/virstring.h | 2 +
src/util/virutil.c | 12 -
src/util/virutil.h | 2 -
6 files changed, 377 insertions(+), 436 deletions(-)
--
2.8.0
8 years, 8 months
[libvirt] [libxl] shutdown a domain before it finishes starting
by Zhangbo (Oscar)
Hi all:
Suppose we have a guest domain which is pvops, for example, rhel6.4.
Steps to produce the problem:
1 start the guest by virDomainCreate()
2 the API returns before the guest domain fully available, which means, the disks, network interfaces and some import services are not available inside the guest.
3 we call virDomainShutdown() to shutdown the guest.
Expected result:
The guest got shutdown.
The result in fact:
Because the guest is not available when we call virDomainShutdown(), it couldn't respond to our 'shutdown' xenstore request, the guest turns on later, rather than shutting down.
So , the question is:
In libxl_driver( xen-hypervisor environment), how can we tell that the guest is available or not, and is it suitable to shutdown the guest at that moment?
Thanks in advance.
Oscar.
8 years, 8 months
[libvirt] How to get GCOV result of make check?
by Zhangbo (Oscar)
Hi all:
I want to get the coverage result of 'make check', here is my way:
1. ./configure *****
2. make clean -j
*3*. find ./ -name Makefile |xargs sed -i "s/\= gcc/= gcc -fprofile-arcs -ftest-coverage/g" # add gcov-related cflags
4. make check -j
5. lcov -d . -c -o libvirt.info
6. genhtml libvirt.info -o libvirtresult
My key work Is step 3, however, I don't think it's a graceful way to get gcov result.
How do you usually get the gcov results, thanks!
Oscar.
8 years, 8 months
[libvirt] [PATCH v3] util: Add virGettextInitialize, convert the code
by Cole Robinson
Take setlocale/gettext error handling pattern from tools/virsh-*
and use it for all standalone binaries via a new shared
virGettextInitialize routine. The virsh* pattern differed slightly
from other callers. All users now consistently:
* Ignore setlocale errors. virsh has done this forever, presumably for
good reason. This has been partially responsible for some bug reports:
https://bugzilla.redhat.com/show_bug.cgi?id=1312688
https://bugzilla.redhat.com/show_bug.cgi?id=1026514
https://bugzilla.redhat.com/show_bug.cgi?id=1016158
* Report the failed function name
* Report strerror
---
v3:
Fix make syntax-check; add a rule similar to the bindtextdomain
check that checks for the new virGettextInitialize
cfg.mk | 11 +++++++++
daemon/libvirtd.c | 6 ++---
src/Makefile.am | 2 ++
src/libvirt_private.syms | 4 ++++
src/locking/lock_daemon.c | 6 ++---
src/locking/sanlock_helper.c | 9 ++-----
src/logging/log_daemon.c | 6 ++---
src/lxc/lxc_controller.c | 6 ++---
src/network/leaseshelper.c | 12 +++-------
src/security/virt-aa-helper.c | 12 +++-------
src/storage/parthelper.c | 9 ++-----
src/util/iohelper.c | 13 +++-------
src/util/virgettext.c | 56 +++++++++++++++++++++++++++++++++++++++++++
src/util/virgettext.h | 25 +++++++++++++++++++
tools/virsh.c | 15 ++----------
tools/virt-admin.c | 15 ++----------
tools/virt-host-validate.c | 15 ++----------
tools/virt-login-shell.c | 14 ++---------
tools/vsh.c | 2 --
19 files changed, 127 insertions(+), 111 deletions(-)
create mode 100644 src/util/virgettext.c
create mode 100644 src/util/virgettext.h
diff --git a/cfg.mk b/cfg.mk
index 5372584..90bb709 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -1037,6 +1037,15 @@ sc_prohibit_verbose_strcat:
halt='Use strcat(a, b) instead of strncat(a, b, strlen(b))' \
$(_sc_search_regexp)
+# Ensure that each .c file containing a "main" function also
+# calls virGettextInitialize
+sc_gettext_init:
+ @require='virGettextInitialize *\(' \
+ in_vc_files='\.c$$' \
+ containing='\<main *(' \
+ halt='the above files do not call virGettextInitialize' \
+ $(_sc_search_regexp)
+
# We don't use this feature of maint.mk.
prev_version_file = /dev/null
@@ -1133,6 +1142,8 @@ _test1=shunloadtest|virnettlscontexttest|virnettlssessiontest|vircgroupmock
exclude_file_name_regexp--sc_avoid_write = \
^(src/($(_src1))|daemon/libvirtd|tools/virsh-console|tests/($(_test1)))\.c$$
+exclude_file_name_regexp--sc_bindtextdomain = .*
+
exclude_file_name_regexp--sc_gettext_init = ^(tests|examples)/
exclude_file_name_regexp--sc_copyright_usage = \
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 3d38a46..5f66e8b 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -30,7 +30,6 @@
#include <getopt.h>
#include <stdlib.h>
#include <grp.h>
-#include <locale.h>
#include "libvirt_internal.h"
#include "virerror.h"
@@ -58,6 +57,7 @@
#include "locking/lock_manager.h"
#include "viraccessmanager.h"
#include "virutil.h"
+#include "virgettext.h"
#ifdef WITH_DRIVER_MODULES
# include "driver.h"
@@ -1172,9 +1172,7 @@ int main(int argc, char **argv) {
{0, 0, 0, 0}
};
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL ||
+ if (virGettextInitialize() < 0 ||
virInitialize() < 0) {
fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
exit(EXIT_FAILURE);
diff --git a/src/Makefile.am b/src/Makefile.am
index eda0365..38b9560 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -114,6 +114,7 @@ UTIL_SOURCES = \
util/virfile.c util/virfile.h \
util/virfirewall.c util/virfirewall.h \
util/virfirewallpriv.h \
+ util/virgettext.c util/virgettext.h \
util/virgic.c util/virgic.h \
util/virhash.c util/virhash.h \
util/virhashcode.c util/virhashcode.h \
@@ -2321,6 +2322,7 @@ libvirt_setuid_rpc_client_la_SOURCES = \
util/virevent.c \
util/vireventpoll.c \
util/virfile.c \
+ util/virgettext.c \
util/virhash.c \
util/virhashcode.c \
util/virjson.c \
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 068bc00..af7de8a 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1517,6 +1517,10 @@ virFirewallStartRollback;
virFirewallStartTransaction;
+# util/virgettext.h
+virGettextInitialize;
+
+
# util/virgic.h
virGICVersionTypeFromString;
virGICVersionTypeToString;
diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index 973e691..bfdcfc6 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -28,7 +28,6 @@
#include <sys/stat.h>
#include <getopt.h>
#include <stdlib.h>
-#include <locale.h>
#include "lock_daemon.h"
@@ -47,6 +46,7 @@
#include "virhash.h"
#include "viruuid.h"
#include "virstring.h"
+#include "virgettext.h"
#include "locking/lock_daemon_dispatch.h"
#include "locking/lock_protocol.h"
@@ -1179,9 +1179,7 @@ int main(int argc, char **argv) {
privileged = geteuid() == 0;
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL ||
+ if (virGettextInitialize() < 0 ||
virThreadInitialize() < 0 ||
virErrorInitialize() < 0) {
fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
diff --git a/src/locking/sanlock_helper.c b/src/locking/sanlock_helper.c
index d8d294f..57e1cfb 100644
--- a/src/locking/sanlock_helper.c
+++ b/src/locking/sanlock_helper.c
@@ -1,13 +1,12 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
-#include <locale.h>
-#include "configmake.h"
#include "internal.h"
#include "virconf.h"
#include "viralloc.h"
#include "domain_conf.h"
+#include "virgettext.h"
static int
@@ -70,12 +69,8 @@ main(int argc, char **argv)
.cb = authCallback,
};
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL) {
- fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
+ if (virGettextInitialize() < 0)
exit(EXIT_FAILURE);
- }
if (getArgs(argc, argv, &uri, &uuid, &action) < 0)
goto cleanup;
diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c
index f674cbd..70339af 100644
--- a/src/logging/log_daemon.c
+++ b/src/logging/log_daemon.c
@@ -28,7 +28,6 @@
#include <sys/stat.h>
#include <getopt.h>
#include <stdlib.h>
-#include <locale.h>
#include "log_daemon.h"
@@ -46,6 +45,7 @@
#include "virhash.h"
#include "viruuid.h"
#include "virstring.h"
+#include "virgettext.h"
#include "log_daemon_dispatch.h"
#include "log_protocol.h"
@@ -936,9 +936,7 @@ int main(int argc, char **argv) {
privileged = geteuid() == 0;
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL ||
+ if (virGettextInitialize() < 0 ||
virThreadInitialize() < 0 ||
virErrorInitialize() < 0) {
fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 8b5ec4c..73e57e3 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -36,7 +36,6 @@
#include <signal.h>
#include <getopt.h>
#include <sys/mount.h>
-#include <locale.h>
#include <grp.h>
#include <sys/stat.h>
#include <time.h>
@@ -66,6 +65,7 @@
#include "virdbus.h"
#include "rpc/virnetdaemon.h"
#include "virstring.h"
+#include "virgettext.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -2505,9 +2505,7 @@ int main(int argc, char *argv[])
for (i = 0; i < VIR_LXC_DOMAIN_NAMESPACE_LAST; i++)
ns_fd[i] = -1;
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL ||
+ if (virGettextInitialize() < 0 ||
virThreadInitialize() < 0 ||
virErrorInitialize() < 0) {
fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c
index 097cd11..16f6eb8 100644
--- a/src/network/leaseshelper.c
+++ b/src/network/leaseshelper.c
@@ -25,7 +25,6 @@
#include <config.h>
-#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
@@ -38,6 +37,7 @@
#include "virjson.h"
#include "virlease.h"
#include "configmake.h"
+#include "virgettext.h"
#define VIR_FROM_THIS VIR_FROM_NETWORK
@@ -115,14 +115,8 @@ main(int argc, char **argv)
program_name = argv[0];
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL) {
- fprintf(stderr, _("%s: initialization failed\n"), program_name);
- exit(EXIT_FAILURE);
- }
-
- if (virThreadInitialize() < 0 ||
+ if (virGettextInitialize() < 0 ||
+ virThreadInitialize() < 0 ||
virErrorInitialize() < 0) {
fprintf(stderr, _("%s: initialization failed\n"), program_name);
exit(EXIT_FAILURE);
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index 50d2a08..5db9c02 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -35,7 +35,6 @@
#include <fcntl.h>
#include <getopt.h>
#include <sys/utsname.h>
-#include <locale.h>
#include "internal.h"
#include "virbuffer.h"
@@ -54,6 +53,7 @@
#include "configmake.h"
#include "virrandom.h"
#include "virstring.h"
+#include "virgettext.h"
#include "storage/storage_driver.h"
@@ -1298,14 +1298,8 @@ main(int argc, char **argv)
char *profile = NULL;
char *include_file = NULL;
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL) {
- fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
- exit(EXIT_FAILURE);
- }
-
- if (virThreadInitialize() < 0 ||
+ if (virGettextInitialize() < 0 ||
+ virThreadInitialize() < 0 ||
virErrorInitialize() < 0) {
fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
exit(EXIT_FAILURE);
diff --git a/src/storage/parthelper.c b/src/storage/parthelper.c
index d1df068..6695f23 100644
--- a/src/storage/parthelper.c
+++ b/src/storage/parthelper.c
@@ -39,13 +39,12 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
-#include <locale.h>
#include "virutil.h"
#include "virfile.h"
#include "c-ctype.h"
-#include "configmake.h"
#include "virstring.h"
+#include "virgettext.h"
/* we don't need to include the full internal.h just for this */
#define STREQ(a, b) (strcmp(a, b) == 0)
@@ -72,12 +71,8 @@ int main(int argc, char **argv)
const char *partsep;
bool devmap_nopartsep = false;
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL) {
- fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
+ if (virGettextInitialize() < 0)
exit(EXIT_FAILURE);
- }
if (argc == 3 && STREQ(argv[2], "-g")) {
cmd = DISK_GEOMETRY;
diff --git a/src/util/iohelper.c b/src/util/iohelper.c
index 8a3c377..275f993 100644
--- a/src/util/iohelper.c
+++ b/src/util/iohelper.c
@@ -27,7 +27,6 @@
#include <config.h>
-#include <locale.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
@@ -38,9 +37,9 @@
#include "virfile.h"
#include "viralloc.h"
#include "virerror.h"
-#include "configmake.h"
#include "virrandom.h"
#include "virstring.h"
+#include "virgettext.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -230,14 +229,8 @@ main(int argc, char **argv)
program_name = argv[0];
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL) {
- fprintf(stderr, _("%s: initialization failed\n"), program_name);
- exit(EXIT_FAILURE);
- }
-
- if (virThreadInitialize() < 0 ||
+ if (virGettextInitialize() < 0 ||
+ virThreadInitialize() < 0 ||
virErrorInitialize() < 0) {
fprintf(stderr, _("%s: initialization failed\n"), program_name);
exit(EXIT_FAILURE);
diff --git a/src/util/virgettext.c b/src/util/virgettext.c
new file mode 100644
index 0000000..7e32043
--- /dev/null
+++ b/src/util/virgettext.c
@@ -0,0 +1,56 @@
+/*
+ * virgettext.c: gettext helper routines
+ *
+ * Copyright (C) 2016 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include <locale.h>
+#include <stdio.h>
+
+#include "configmake.h"
+#include "internal.h"
+#include "virgettext.h"
+
+
+/**
+ * virGettextInit:
+ *
+ * Initialize standard gettext setup
+ * Returns -1 on fatal error
+ */
+int
+virGettextInitialize(void)
+{
+ if (!setlocale(LC_ALL, "")) {
+ perror("setlocale");
+ /* failure to setup locale is not fatal */
+ }
+
+ if (!bindtextdomain(PACKAGE, LOCALEDIR)) {
+ perror("bindtextdomain");
+ return -1;
+ }
+
+ if (!textdomain(PACKAGE)) {
+ perror("textdomain");
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/src/util/virgettext.h b/src/util/virgettext.h
new file mode 100644
index 0000000..4584d83
--- /dev/null
+++ b/src/util/virgettext.h
@@ -0,0 +1,25 @@
+/*
+ * virgettext.h: gettext helper routines
+ *
+ * Copyright (C) 2016 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+#ifndef __VIR_GETTEXT_H__
+# define __VIR_GETTEXT_H__
+
+int virGettextInitialize(void);
+
+#endif /* __VIR_GETTEXT_H__ */
diff --git a/tools/virsh.c b/tools/virsh.c
index fe33839..f632405 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -34,7 +34,6 @@
#include <getopt.h>
#include <sys/time.h>
#include <fcntl.h>
-#include <locale.h>
#include <time.h>
#include <limits.h>
#include <sys/stat.h>
@@ -53,12 +52,12 @@
#include <libvirt/libvirt-qemu.h>
#include <libvirt/libvirt-lxc.h>
#include "virfile.h"
-#include "configmake.h"
#include "virthread.h"
#include "vircommand.h"
#include "conf/domain_conf.h"
#include "virtypedparam.h"
#include "virstring.h"
+#include "virgettext.h"
#include "virsh-console.h"
#include "virsh-domain.h"
@@ -933,18 +932,8 @@ main(int argc, char **argv)
progname++;
ctl->progname = progname;
- if (!setlocale(LC_ALL, "")) {
- perror("setlocale");
- /* failure to setup locale is not fatal */
- }
- if (!bindtextdomain(PACKAGE, LOCALEDIR)) {
- perror("bindtextdomain");
- return EXIT_FAILURE;
- }
- if (!textdomain(PACKAGE)) {
- perror("textdomain");
+ if (virGettextInitialize() < 0)
return EXIT_FAILURE;
- }
if (isatty(STDIN_FILENO)) {
ctl->istty = true;
diff --git a/tools/virt-admin.c b/tools/virt-admin.c
index f0a49a3..195088b 100644
--- a/tools/virt-admin.c
+++ b/tools/virt-admin.c
@@ -25,20 +25,19 @@
#include <errno.h>
#include <getopt.h>
-#include <locale.h>
#if WITH_READLINE
# include <readline/readline.h>
# include <readline/history.h>
#endif
-#include "configmake.h"
#include "internal.h"
#include "viralloc.h"
#include "virerror.h"
#include "virfile.h"
#include "virstring.h"
#include "virthread.h"
+#include "virgettext.h"
/* Gnulib doesn't guarantee SA_SIGINFO support. */
#ifndef SA_SIGINFO
@@ -689,18 +688,8 @@ main(int argc, char **argv)
progname++;
ctl->progname = progname;
- if (!setlocale(LC_ALL, "")) {
- perror("setlocale");
- /* failure to setup locale is not fatal */
- }
- if (!bindtextdomain(PACKAGE, LOCALEDIR)) {
- perror("bindtextdomain");
- return EXIT_FAILURE;
- }
- if (!textdomain(PACKAGE)) {
- perror("textdomain");
+ if (virGettextInitialize() < 0)
return EXIT_FAILURE;
- }
if (isatty(STDIN_FILENO)) {
ctl->istty = true;
diff --git a/tools/virt-host-validate.c b/tools/virt-host-validate.c
index a8c2075..5b7fe9b 100644
--- a/tools/virt-host-validate.c
+++ b/tools/virt-host-validate.c
@@ -25,10 +25,9 @@
#include <stdlib.h>
#include <gettext.h>
#include <getopt.h>
-#include <locale.h>
#include "internal.h"
-#include "configmake.h"
+#include "virgettext.h"
#include "virt-host-validate-common.h"
#if WITH_QEMU
@@ -80,18 +79,8 @@ main(int argc, char **argv)
bool quiet = false;
bool usedHvname = false;
- if (!setlocale(LC_ALL, "")) {
- perror("setlocale");
- /* failure to setup locale is not fatal */
- }
- if (!bindtextdomain(PACKAGE, LOCALEDIR)) {
- perror("bindtextdomain");
- return EXIT_FAILURE;
- }
- if (!textdomain(PACKAGE)) {
- perror("textdomain");
+ if (virGettextInitialize() < 0)
return EXIT_FAILURE;
- }
while ((c = getopt_long(argc, argv, "hvq", argOptions, NULL)) != -1) {
switch (c) {
diff --git a/tools/virt-login-shell.c b/tools/virt-login-shell.c
index ec759dc..8f87227 100644
--- a/tools/virt-login-shell.c
+++ b/tools/virt-login-shell.c
@@ -24,7 +24,6 @@
#include <errno.h>
#include <fnmatch.h>
#include <getopt.h>
-#include <locale.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
@@ -41,6 +40,7 @@
#include "virstring.h"
#include "viralloc.h"
#include "vircommand.h"
+#include "virgettext.h"
#define VIR_FROM_THIS VIR_FROM_NONE
static const char *conf_file = SYSCONFDIR "/libvirt/virt-login-shell.conf";
@@ -207,18 +207,8 @@ main(int argc, char **argv)
virSetErrorLogPriorityFunc(NULL);
progname = argv[0];
- if (!setlocale(LC_ALL, "")) {
- perror("setlocale");
- /* failure to setup locale is not fatal */
- }
- if (!bindtextdomain(PACKAGE, LOCALEDIR)) {
- perror("bindtextdomain");
- return ret;
- }
- if (!textdomain(PACKAGE)) {
- perror("textdomain");
+ if (virGettextInitialize() < 0)
return ret;
- }
while ((arg = getopt_long(argc, argv, "hV", opt, &longindex)) != -1) {
switch (arg) {
diff --git a/tools/vsh.c b/tools/vsh.c
index 6bdc082..f033c05 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -35,7 +35,6 @@
#include <sys/time.h>
#include "c-ctype.h"
#include <fcntl.h>
-#include <locale.h>
#include <time.h>
#include <limits.h>
#include <sys/stat.h>
@@ -55,7 +54,6 @@
#include <libvirt/libvirt-qemu.h>
#include <libvirt/libvirt-lxc.h>
#include "virfile.h"
-#include "configmake.h"
#include "virthread.h"
#include "vircommand.h"
#include "conf/domain_conf.h"
--
2.7.3
8 years, 8 months