[libvirt] [PATCH v4] util: Add virGettextInitialize, convert the code
John Ferlan
jferlan at redhat.com
Thu Apr 14 17:18:48 UTC 2016
On 04/13/2016 08:21 AM, Cole Robinson wrote:
> 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
> ---
> v4:
> sigh, forgot to squash in a cfg.mk change
>
> cfg.mk | 13 +++++++++-
> 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, 128 insertions(+), 112 deletions(-)
> create mode 100644 src/util/virgettext.c
> create mode 100644 src/util/virgettext.h
>
Minor nit in virgettext.c below
ACK -
John
[...]
> +++ 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:
^^ virGettextInitialize
> + *
> + * 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;
> +}
[...]
More information about the libvir-list
mailing list