[SSSD] [PATCHES] util: Continue if setlocale fails

Lukas Slebodnik lslebodn at redhat.com
Mon Oct 19 14:21:48 UTC 2015


On (19/10/15 16:03), Michal Židek wrote:
>Hi,
>
>attached is patch to fix ticket:
>https://fedorahosted.org/sssd/ticket/2785
>
>And one additional patch to add DEBUG message.
>
>Michal

>From 3227027c3680b4503477135608969ca904e491c7 Mon Sep 17 00:00:00 2001
>From: =?UTF-8?q?Michal=20=C5=BDidek?= <mzidek at redhat.com>
>Date: Mon, 19 Oct 2015 15:38:08 +0200
>Subject: [PATCH 1/2] util: Continue if setlocale fails
>
>Fixes:
>https://fedorahosted.org/sssd/ticket/2785
>
>setlocale needs some environment variables
>to be set in order to work. These variables
>are not present in some special cases. We
>should not fail completely in these cases
>but continue with the compatible C locale.
>---
> src/sss_client/ssh/sss_ssh_client.c | 4 +++-
> src/tools/tools_util.c              | 4 +++-
> 2 files changed, 6 insertions(+), 2 deletions(-)
>
>diff --git a/src/sss_client/ssh/sss_ssh_client.c b/src/sss_client/ssh/sss_ssh_client.c
>index 0d206ef..ea7a1cc 100644
>--- a/src/sss_client/ssh/sss_ssh_client.c
>+++ b/src/sss_client/ssh/sss_ssh_client.c
>@@ -50,7 +50,9 @@ int set_locale(void)
> 
>     c = setlocale(LC_ALL, "");
>     if (c == NULL) {
>-        return EIO;
>+        /* If setlocale fails, continue with the compatible
>+         * C locale. */
I'm not sure wehter "compatible" is the best explanation.
I think that "continue with the default" would suit better.

BTW: man setlocale(3) says:
       On  startup of the main program, the portable "C" locale is selected as
       default.  A program may be made portable to all locales by calling:

           setlocale(LC_ALL, "");


Would you also mind to write integration test?
I can test on command line with:

[root at host ~]# LC_ALL="adasd" sss_cache -E
Error setting the locale
[root at host ~]# echo $?
5

LS


More information about the sssd-devel mailing list