util: Add virGettextInitialize, convert the code

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
This commit is contained in:
Cole Robinson
2016-04-12 18:29:52 -04:00
parent 0f8be2531c
commit e7db227810
19 changed files with 128 additions and 112 deletions

View File

@@ -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"
@@ -936,18 +935,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");
if (virGettextInitialize() < 0)
return EXIT_FAILURE;
}
if (!textdomain(PACKAGE)) {
perror("textdomain");
return EXIT_FAILURE;
}
if (isatty(STDIN_FILENO)) {
ctl->istty = true;