mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
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:
@@ -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;
|
||||
|
||||
@@ -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");
|
||||
if (virGettextInitialize() < 0)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (!textdomain(PACKAGE)) {
|
||||
perror("textdomain");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (isatty(STDIN_FILENO)) {
|
||||
ctl->istty = true;
|
||||
|
||||
@@ -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");
|
||||
if (virGettextInitialize() < 0)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (!textdomain(PACKAGE)) {
|
||||
perror("textdomain");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
while ((c = getopt_long(argc, argv, "hvq", argOptions, NULL)) != -1) {
|
||||
switch (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");
|
||||
if (virGettextInitialize() < 0)
|
||||
return ret;
|
||||
}
|
||||
if (!textdomain(PACKAGE)) {
|
||||
perror("textdomain");
|
||||
return ret;
|
||||
}
|
||||
|
||||
while ((arg = getopt_long(argc, argv, "hV", opt, &longindex)) != -1) {
|
||||
switch (arg) {
|
||||
|
||||
@@ -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>
|
||||
@@ -54,7 +53,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"
|
||||
|
||||
Reference in New Issue
Block a user