Language selection for newly created user confusing

Bug #740754 reported by Gunnar Hjalmarsson on 2011-03-23
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gdm (Ubuntu)
Undecided
Gunnar Hjalmarsson

Bug Description

Binary package hint: gdm

When a user is about to log in for the first time, and if only LANG is
set in /etc/default/locale, GDM's language picker suggests the language
corresponding to the LANG locale. The user may stick to that suggestion,
or pick some other language, and the user language will be set
accordingly.

If also LANGUAGE is set in /etc/default/locale, there are two problems:

1. The language suggested by the language picker is still grabbed from
   LANG.

2. Because of the "no surprise" code in Xsession, the user language
   will be set based on LANGUAGE whether the user picks some other
   language or not.

I would suggest two things to make GDM behave as expected. One of the
ideas is described in the failed-attempt.txt attachment. In addition to
that, Xsession should test whether it's a new user, and skip the "no
surprise" code if it is. Don't know how to test that, though.

Gunnar Hjalmarsson (gunnarhj) wrote :
Gunnar Hjalmarsson (gunnarhj) wrote :

As regards item 2, maybe [ -f "$HOME/.xsession-errors.old" ] ?

Gunnar Hjalmarsson (gunnarhj) wrote :

Tried the below code, but no success. Unlike the previous code, the screen didn't turn black. Progress?

static const char *
get_default_language_name (GdmSessionDirect *session)
{
    char *langlist;
    char language[50];

    if (session->priv->saved_language != NULL) {
                return session->priv->saved_language;
    }

    langlist = getenv("LANGUAGE");

    if (langlist != NULL && strlen(langlist) > 0) {
        strncpy( language, langlist, strcspn(langlist, ":") );
        return language;
    }

    return setlocale (LC_MESSAGES, NULL);
}

Changed in gdm (Ubuntu):
assignee: nobody → Gunnar Hjalmarsson (gunnarhj)
status: New → In Progress
Gunnar Hjalmarsson (gunnarhj) wrote :

The above code was originally tested in Maverick. I noticed that declaring the language array with 100 elements instead of 50 reduces the risk for a segmentation fault. (50 or 500 elements trigger typically errors, while 100 works more safely!?)

Anyway, when I changed from 50 to 100 in the above code, GDM in Maverick seemed to 'almost' make it. The suggested language for added users was taken from the system $LANGUAGE as expected. However, after having typed the password and clicked the button, GDM hanged, and I had to switch off the power to shut down.

As regards GDM in Natty, getenv() seemed to fail in grabbing $LANGUAGE, so the code within the if block was never run, and login worked as usual. Consequently, the suggested language for added users were taken from $LANG - just as before.

The reason why I began to dig into this is that I have started to write an i18n document for the system docs. When I was about to say that the system LANGUAGE (and LC_MESSAGES) variables serve as defaults for added users, it struck me that I ought to test it.

Unless any of you is able to solve the problem easily, I would say that it can wait til 11.10. After all, the most important issue that is mentioned in this bug may be fixed with the linked MP.

Martin Pitt (pitti) wrote :

Gunnar,

returning a pointer to a static array on the stack will cause the crash. Can you please try with

  char *langlist, *language;

  [...]

    if (langlist != NULL && strlen(langlist) > 0) {
        char *colon = index (langlist, ':');
        if (colon)
            language = g_strndup (langlist, colon - langlist);
        else
            language = g_strdup (langlist);

        return language;
    }

Martin Pitt (pitti) wrote :

Sorry, please use "strchr" instead of "index", the latter is deprecated.

Gunnar Hjalmarsson (gunnarhj) wrote :

Martin,

That code runs fine without crashing. Thanks! In Maverick it also suggests language out from LANGUAGE, as expected.

In Natty, though, it suggests language out from LANG even if LANGUAGE is set in /etc/default/locale. It seems like getenv("LANGUAGE") does not return anything in Natty, so the additional code does not make a difference.

Has GDM been changed in some respect that affects at which point LANGUAGE is populated?

/ Gunnar

Martin Pitt (pitti) wrote :

Hm, no, gdm is supposed to know both LANG and LANGUAGE, the upstart job explicitly sources /etc/default/locale before launching gdm-binary:

    if [ -r /etc/default/locale ]; then
        . /etc/default/locale
        export LANG LANGUAGE
    elif [ -r /etc/environment ]; then
        . /etc/environment
        export LANG LANGUAGE
    fi
    export XORGCONFIG

    exec gdm-binary $CONFIG_FILE

and this also seems to work here:

$ sudo cat /proc/`pidof gdm-binary`/environ | xargs -0n1 | grep ^LANG
LANGUAGE=de:en
LANG=de_DE.UTF-8

$ sudo cat /proc/`pidof gdm-session-worker`/environ | xargs -0n1 | grep ^LANG
LANG=de_DE.UTF-8
LANGUAGE=de:en

Gunnar Hjalmarsson (gunnarhj) wrote :

You are right, my mistake. Sorry. Should know better than taking shortcuts when it comes to packaging in Ubuntu. :(

I updated the MP, which now also includes the C code snippet.

Martin Pitt (pitti) wrote :

Thanks Gunnar! I merged your branch, but will postpone the uploading until after the beta-1 freeze.

Changed in gdm (Ubuntu):
status: In Progress → Fix Committed
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package gdm - 2.32.0-0ubuntu13

---------------
gdm (2.32.0-0ubuntu13) natty; urgency=low

  [ Gunnar Hjalmarsson ]
  * debian/patches/36_language_environment_settings.patch:
    - Make the first item in the system LANGUAGE list serve as default
      language for new users (LP: #740754).
    - Do not apply code for faking $GDM_LANG if it is the $USER's
      first login ever (LP: #740754).
    - Check $DESKTOP_SESSION instead of $GDMSESSION to determine if
      it is a guest session.

  [ Martin Pitt ]
  * Add 41_pt_time_format.patch: Fix time format for Portugal. Thanks
    jbatista! (LP: #696560)
 -- Martin Pitt <email address hidden> Thu, 31 Mar 2011 18:09:26 +0200

Changed in gdm (Ubuntu):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers