[libvirt] [PATCH] util: Extract locale-related fixes into separate functions

Peter Krempa pkrempa at redhat.com
Thu Jun 22 13:49:03 UTC 2017


On Thu, Jun 22, 2017 at 14:36:53 +0200, Martin Kletzander wrote:
> Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
> ---
>  src/util/virstring.c | 96 ++++++++++++++++++++++++++++++++--------------------
>  1 file changed, 60 insertions(+), 36 deletions(-)
> 
> diff --git a/src/util/virstring.c b/src/util/virstring.c
> index feea5be05198..6125725364f3 100644
> --- a/src/util/virstring.c
> +++ b/src/util/virstring.c
> @@ -522,6 +522,7 @@ virStrToLong_ullp(char const *s, char **end_ptr, int base,
>  #if HAVE_NEWLOCALE
> 
>  static locale_t virLocale;
> +static locale_t virLocaleOld;

This is not a thread local variable ...

> 
>  static int
>  virLocaleOnceInit(void)
> @@ -533,7 +534,58 @@ virLocaleOnceInit(void)
>  }
> 
>  VIR_ONCE_GLOBAL_INIT(virLocale);
> -#endif
> +
> +static int
> +virLocaleSet(void)
> +{
> +    if (virLocaleInitialize() < 0)
> +        return -1;
> +    virLocaleOld = uselocale(virLocale);

... and this is called multiple times ...

> +    return 0;
> +}
> +
> +static void
> +virLocaleRevert(void)
> +{
> +    uselocale(virLocaleOld);

... so while this at this moment will behave correctly, since
virLocaleOld will only be ever set to the same old locale, the general
approach is not correct.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20170622/99bc2a61/attachment-0001.sig>


More information about the libvir-list mailing list