[libvirt] [PATCH] Be more clever and verbose about localization-initialization.

Currently libvirt fails with an uninformative error message if no translations are found. Fixes: * If bindtextdomain fails due to missing language files, fall back to locale C. * If textdomain still fails, report the exact error without translation attempt. https://bugzilla.redhat.com/show_bug.cgi?id=1016158 Signed-off-by: Andreas Fuchs <andreas.fuchs@sit.fraunhofer.de> --- daemon/libvirtd.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 99c0342..490acbf 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -1132,9 +1132,17 @@ int main(int argc, char **argv) { }; if (setlocale(LC_ALL, "") == NULL || - bindtextdomain(PACKAGE, LOCALEDIR) == NULL || - textdomain(PACKAGE) == NULL || - virInitialize() < 0) { + bindtextdomain(PACKAGE, LOCALEDIR) == NULL || + textdomain(PACKAGE) == NULL) { + VIR_WARN("Cannot find localization information. Falling back to non-localized messages."); + if (setlocale(LC_ALL, "C") == NULL || + textdomain(PACKAGE) == NULL) { + fprintf(stderr, "%s: localization initialization failed\n", argv[0]); + exit(EXIT_FAILURE); + } + } + + if (virInitialize() < 0) { fprintf(stderr, _("%s: initialization failed\n"), argv[0]); exit(EXIT_FAILURE); } -- 1.7.10.4

On Mon, Oct 07, 2013 at 03:47:48PM +0000, Fuchs, Andreas wrote:
Currently libvirt fails with an uninformative error message if no translations are found.
I don't see any failure if I delete all the libvirt.mo files. What are you actually doing to trigger an error, and what is the exact error you get. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (2)
-
Daniel P. Berrange
-
Fuchs, Andreas