FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo Development

 
 
LinkBack Thread Tools
 
Old 02-14-2011, 08:10 AM
Martin Sivak
 
Default Generate locale files on request

---
loader/lang.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++-
scripts/upd-instroot | 16 +++++-------
2 files changed, 66 insertions(+), 10 deletions(-)

diff --git a/loader/lang.c b/loader/lang.c
index a84c2ec..ba1dae1 100644
--- a/loader/lang.c
+++ b/loader/lang.c
@@ -32,6 +32,8 @@
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include <unistd.h>
#include <wchar.h>

@@ -224,7 +226,13 @@ static void setLangEnv (int i) {
/* choice is the index of the chosen language in languages */
static int setupLanguage(int choice, int forced) {
char * buf;
+ char *locale_def = NULL;
+ char *locale_charset = NULL;
+ char *locale_mod = NULL;
+ char *locale_p = NULL;
+ char *locale_i = NULL;
int i;
+ pid_t localedef_pid;

logMessage(DEBUGLVL, "going to set language to %s", languages[choice].lc_all);
/* load the language only if it is displayable. if they're using
@@ -241,7 +249,57 @@ static int setupLanguage(int choice, int forced) {
setLangEnv(english);
return 0;
}
-
+
+ /* get locale parts out of locale name */
+ locale_p = locale_i = languages[choice].lc_all;
+ while (1) {
+ // we found separator
+ if (*locale_i == '.' || *locale_i == '@' || *locale_i == '') {
+ // last separator was annotating charset
+ if (*locale_p == '.') locale_charset = strndup(locale_p + 1, locale_i - locale_p - 1);
+ // last separator was annotating modifier
+ else if (*locale_p == '@') locale_mod = strndup(locale_p + 1, locale_i - locale_p - 1);
+ // there was no known separator last time
+ else locale_def = strndup(locale_p, locale_i - locale_p);
+
+ locale_p = locale_i;
+ if(*locale_i == '') break; // end of the string
+ }
+
+ locale_i++;
+ }
+ logMessage(DEBUGLVL, "locale %s: base: %s, mod: %s, charset: %s", languages[choice].lc_all, locale_def, locale_mod, locale_charset);
+
+ /* prepare locale name without charset */
+ i = strlen(locale_def);
+ if (locale_mod) i+= strlen(locale_mod) + 1; /* +1 for the @ char */
+ locale_p = (char*)calloc(i+1, sizeof(char));
+ locale_p = strcpy(locale_p, locale_def);
+ if (locale_mod){
+ locale_p[strlen(locale_p)] = '@';
+ locale_p = strcat(locale_p, locale_mod);
+ }
+
+ /* generate locale record */
+ logMessage(INFO, "going to prepare locales for %s (locale: %s, charset: %s)", languages[choice].lc_all, locale_p, locale_charset);
+ if ((localedef_pid = fork()) == 0) {
+ execl("/usr/bin/localedef", "localedef",
+ "-i", locale_p,
+ "-f", (locale_charset) ? locale_charset : "UTF-8",
+ languages[choice].lc_all, NULL);
+ }
+ if (localedef_pid < 0) logMessage(ERROR, "failed starting localedef for %s", languages[choice].lc_all);
+ else{
+ waitpid(localedef_pid, &i, 0);
+ if (WEXITSTATUS(i) != 0) logMessage(ERROR, "failed preparing locales %s [%d]", languages[choice].lc_all, WEXITSTATUS(i));
+ }
+
+ /* cleanup */
+ if (locale_charset) free(locale_charset);
+ if (locale_def) free(locale_def);
+ if (locale_mod) free(locale_mod);
+ if (locale_p) free(locale_p);
+
setLangEnv (choice);
isysLoadFont();

diff --git a/scripts/upd-instroot b/scripts/upd-instroot
index 5c8d5b5..2b2fc4a 100755
--- a/scripts/upd-instroot
+++ b/scripts/upd-instroot
@@ -634,6 +634,7 @@ usr/bin/hmount
usr/bin/humount
usr/bin/killall
usr/bin/logger
+usr/bin/localedef
usr/bin/lsattr*
usr/bin/maketilo
usr/bin/md5sum
@@ -754,6 +755,7 @@ usr/share/hwdata/pci.ids
usr/share/hwdata/usb.ids
usr/share/hwdata/videoaliases
usr/share/hwdata/videodrivers
+usr/share/i18n
usr/share/icons/hicolor/*/apps/nm-*
usr/share/icons/hicolor/index.theme
usr/share/locale/*/LC_MESSAGES/anaconda.mo
@@ -1113,10 +1115,13 @@ chmod 04755 $DEST/usr/libexec/polkit-1/polkit-agent-helper-1
chown root:dbus $DEST/$LIBDIR/dbus-1/dbus-daemon-launch-helper
chmod 04750 $DEST/$LIBDIR/dbus-1/dbus-daemon-launch-helper

-# Remove locales unused during the install
+# Generate default locale in case runtime doesn't work
+# /usr/share/i18n/ contains sources
install -m 644 $DEST/usr/share/anaconda/lang-table $DEST/etc/lang-table
+rm -f $DEST/usr/lib/locale/locale-archive
localedef -c -i en_US -f UTF-8 --prefix $DEST en_US

+# Remove unsupported translations
cat $DEST/usr/share/anaconda/lang-table* | awk '
{ gsub("-", "", $4);
print $4;
@@ -1135,14 +1140,7 @@ for p in lib share; do (
}
); done

-# Now shrink the locale-archive to contain just the minimum.
-localedef --prefix $DEST --list-archive > $DEST/locales.glibc
-LC_ALL=C unsupported="$(comm -13 $DEST/locales $DEST/locales.glibc)"
-localedef --prefix $DEST --delete-from-archive $unsupported
-mv $DEST/usr/lib/locale/locale-archive $DEST/usr/lib/locale/locale-archive.tmpl
-/usr/sbin/chroot $DEST /usr/sbin/build-locale-archive
-
-rm -f $DEST/locales $DEST/locales.list $DEST/locales.glibc
+rm -f $DEST/locales $DEST/locales.list

# fix up some links for man page related stuff
for file in nroff groff iconv geqn gtbl gpic grefer ; do
--
1.7.4

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 02-14-2011, 10:33 AM
Ales Kozumplik
 
Default Generate locale files on request

Hi,

some notes below.

On 02/14/2011 10:10 AM, Martin Sivak wrote:

+ /* get locale parts out of locale name */
+ locale_p = locale_i = languages[choice].lc_all;


Could you please add a sample locale string or two as a comment, it
makes the loop a lot easier to read and figure out what we really parse.



+ while (1) {
+ // we found separator
+ if (*locale_i == '.' || *locale_i == '@' || *locale_i == '') {
+ // last separator was annotating charset
+ if (*locale_p == '.') locale_charset = strndup(locale_p + 1, locale_i - locale_p - 1);
+ // last separator was annotating modifier
+ else if (*locale_p == '@') locale_mod = strndup(locale_p + 1, locale_i - locale_p - 1);
+ // there was no known separator last time
+ else locale_def = strndup(locale_p, locale_i - locale_p);


Doesn't this else imply locale_i == '' ?


+ /* generate locale record */
+ logMessage(INFO, "going to prepare locales for %s (locale: %s, charset: %s)", languages[choice].lc_all, locale_p, locale_charset);
+ if ((localedef_pid = fork()) == 0) {
+ execl("/usr/bin/localedef", "localedef",
+ "-i", locale_p,
+ "-f", (locale_charset) ? locale_charset : "UTF-8",
+ languages[choice].lc_all, NULL);
+ }
+ if (localedef_pid< 0) logMessage(ERROR, "failed starting localedef for %s", languages[choice].lc_all);


I think you want this log message say that a fork failed (unlikely,
maybe just abort). Also there should be an assert/abort/return after the
call to execl---that can fail but we don't want two instances of the
process to continue.




diff --git a/scripts/upd-instroot b/scripts/upd-instroot
index 5c8d5b5..2b2fc4a 100755
--- a/scripts/upd-instroot
+++ b/scripts/upd-instroot


There was a pjones's patch around that would remove all this stuff so
maybe this is not even necessary.


Other than that I applaud those image-shrinking efforts.

Al_

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 02-14-2011, 11:33 AM
Martin Gracik
 
Default Generate locale files on request

--

Martin Gracik

----- Original Message -----
> Hi,
>
> some notes below.
>
> On 02/14/2011 10:10 AM, Martin Sivak wrote:
> > + /* get locale parts out of locale name */
> > + locale_p = locale_i = languages[choice].lc_all;
>
> Could you please add a sample locale string or two as a comment, it
> makes the loop a lot easier to read and figure out what we really
> parse.
>
> > + while (1) {
> > + // we found separator
> > + if (*locale_i == '.' || *locale_i == '@' || *locale_i == '') {
> > + // last separator was annotating charset
> > + if (*locale_p == '.') locale_charset = strndup(locale_p + 1,
> > locale_i - locale_p - 1);
> > + // last separator was annotating modifier
> > + else if (*locale_p == '@') locale_mod = strndup(locale_p + 1,
> > locale_i - locale_p - 1);
> > + // there was no known separator last time
> > + else locale_def = strndup(locale_p, locale_i - locale_p);
>
> Doesn't this else imply locale_i == '' ?
>
> > + /* generate locale record */
> > + logMessage(INFO, "going to prepare locales for %s (locale: %s,
> > charset: %s)", languages[choice].lc_all, locale_p, locale_charset);
> > + if ((localedef_pid = fork()) == 0) {
> > + execl("/usr/bin/localedef", "localedef",
> > + "-i", locale_p,
> > + "-f", (locale_charset) ? locale_charset : "UTF-8",
> > + languages[choice].lc_all, NULL);
> > + }
> > + if (localedef_pid< 0) logMessage(ERROR, "failed starting localedef
> > for %s", languages[choice].lc_all);
>
> I think you want this log message say that a fork failed (unlikely,
> maybe just abort). Also there should be an assert/abort/return after
> the
> call to execl---that can fail but we don't want two instances of the
> process to continue.
>
>
> > diff --git a/scripts/upd-instroot b/scripts/upd-instroot
> > index 5c8d5b5..2b2fc4a 100755
> > --- a/scripts/upd-instroot
> > +++ b/scripts/upd-instroot
>
> There was a pjones's patch around that would remove all this stuff so
> maybe this is not even necessary.

The scripts/* cannot be removed yet, the secondary architectures still use buildinstall,
we talked about this in Tempe.

>
> Other than that I applaud those image-shrinking efforts.
>
> Al_
>
> _______________________________________________
> Anaconda-devel-list mailing list
> Anaconda-devel-list@redhat.com
> https://www.redhat.com/mailman/listinfo/anaconda-devel-list

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 02-14-2011, 01:40 PM
Martin Sivak
 
Default Generate locale files on request

> > + /* get locale parts out of locale name */
> > + locale_p = locale_i = languages[choice].lc_all;
>
> Could you please add a sample locale string or two as a comment, it
> makes the loop a lot easier to read and figure out what we really
> parse.

I can, but for the review the formats are as follows:

en
en_US
cs_CZ.UTF-8
cz_CZ.UTF-8@latin

> > + while (1) {
> > + // we found separator
> > + if (*locale_i == '.' || *locale_i == '@' || *locale_i == '') {
> > + // last separator was annotating charset
> > + if (*locale_p == '.') locale_charset = strndup(locale_p + 1,
> > locale_i - locale_p - 1);
> > + // last separator was annotating modifier
> > + else if (*locale_p == '@') locale_mod = strndup(locale_p + 1,
> > locale_i - locale_p - 1);
> > + // there was no known separator last time
> > + else locale_def = strndup(locale_p, locale_i - locale_p);
>

> Doesn't this else imply locale_i == '' ?

Nope, the first if tests current character, but following ifs test locale_p (the last separator), so the else is actually processed first, because locale_p points to first character of locale.


> > + /* generate locale record */
> > + logMessage(INFO, "going to prepare locales for %s (locale: %s,
> > charset: %s)", languages[choice].lc_all, locale_p, locale_charset);
> > + if ((localedef_pid = fork()) == 0) {
> > + execl("/usr/bin/localedef", "localedef",
> > + "-i", locale_p,
> > + "-f", (locale_charset) ? locale_charset : "UTF-8",
> > + languages[choice].lc_all, NULL);
> > + }
> > + if (localedef_pid< 0) logMessage(ERROR, "failed starting localedef
> > for %s", languages[choice].lc_all);
>
> I think you want this log message say that a fork failed (unlikely,
> maybe just abort). Also there should be an assert/abort/return after
> the
> call to execl---that can fail but we don't want two instances of the
> process to continue.
>


True, exit should be there. I will add one


--
Martin Sivák
msivak@redhat.com
Red Hat Czech
Anaconda team / Brno, CZ

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 02-14-2011, 01:51 PM
Martin Sivak
 
Default Generate locale files on request

---
loader/lang.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++-
scripts/upd-instroot | 16 +++++------
2 files changed, 80 insertions(+), 10 deletions(-)

diff --git a/loader/lang.c b/loader/lang.c
index a84c2ec..f3e00df 100644
--- a/loader/lang.c
+++ b/loader/lang.c
@@ -32,6 +32,8 @@
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include <unistd.h>
#include <wchar.h>

@@ -224,7 +226,13 @@ static void setLangEnv (int i) {
/* choice is the index of the chosen language in languages */
static int setupLanguage(int choice, int forced) {
char * buf;
+ char *locale_def = NULL; /* locale lang name */
+ char *locale_charset = NULL;/* locale charset */
+ char *locale_mod = NULL; /* locale variant */
+ char *locale_p = NULL; /* last known locale separator */
+ char *locale_i = NULL; /* string iterator */
int i;
+ pid_t localedef_pid;

logMessage(DEBUGLVL, "going to set language to %s", languages[choice].lc_all);
/* load the language only if it is displayable. if they're using
@@ -241,7 +249,71 @@ static int setupLanguage(int choice, int forced) {
setLangEnv(english);
return 0;
}
-
+
+ /* Parse locale parts out of locale name.
+
+ Locale examples:
+ en
+ en_US
+ cz_CS.UTF-8
+ cz_CS.UTF-8@latin
+ */
+
+ locale_p = locale_i = languages[choice].lc_all;
+ while (1) {
+ // we found new separator
+ if (*locale_i == '.' || *locale_i == '@' || *locale_i == '') {
+ // last separator was annotating charset
+ if (*locale_p == '.') locale_charset = strndup(locale_p + 1, locale_i - locale_p - 1);
+ // last separator was annotating modifier
+ else if (*locale_p == '@') locale_mod = strndup(locale_p + 1, locale_i - locale_p - 1);
+ // there was no known separator last time
+ else locale_def = strndup(locale_p, locale_i - locale_p);
+
+ // save last known separator
+ locale_p = locale_i;
+
+ if(*locale_i == '') break; // end of the string
+ }
+
+ // test next character
+ locale_i++;
+ }
+
+ logMessage(DEBUGLVL, "locale %s: base: %s, mod: %s, charset: %s", languages[choice].lc_all, locale_def, locale_mod, locale_charset);
+
+ /* prepare locale name without charset */
+ i = strlen(locale_def);
+ if (locale_mod) i+= strlen(locale_mod) + 1; /* +1 for the @ char */
+ locale_p = (char*)calloc(i+1, sizeof(char));
+ locale_p = strcpy(locale_p, locale_def);
+ if (locale_mod){
+ locale_p[strlen(locale_p)] = '@';
+ locale_p = strcat(locale_p, locale_mod);
+ }
+
+ /* generate locale record */
+ logMessage(INFO, "going to prepare locales for %s (locale: %s, charset: %s)", languages[choice].lc_all, locale_p, locale_charset);
+ if ((localedef_pid = fork()) == 0) {
+ execl("/usr/bin/localedef", "localedef",
+ "-i", locale_p,
+ "-f", (locale_charset) ? locale_charset : "UTF-8",
+ languages[choice].lc_all, NULL);
+ exit(254);
+ }
+
+ if (localedef_pid < 0) logMessage(ERROR, "failed forking localedef for %s", languages[choice].lc_all);
+ else{
+ waitpid(localedef_pid, &i, 0);
+ if (WEXITSTATUS(i) != 0) logMessage(ERROR, "failed preparing locales %s [%d]", languages[choice].lc_all, WEXITSTATUS(i));
+ }
+
+ /* cleanup */
+ if (locale_charset) free(locale_charset);
+ if (locale_def) free(locale_def);
+ if (locale_mod) free(locale_mod);
+ if (locale_p) free(locale_p);
+
setLangEnv (choice);
isysLoadFont();

diff --git a/scripts/upd-instroot b/scripts/upd-instroot
index 5c8d5b5..2b2fc4a 100755
--- a/scripts/upd-instroot
+++ b/scripts/upd-instroot
@@ -634,6 +634,7 @@ usr/bin/hmount
usr/bin/humount
usr/bin/killall
usr/bin/logger
+usr/bin/localedef
usr/bin/lsattr*
usr/bin/maketilo
usr/bin/md5sum
@@ -754,6 +755,7 @@ usr/share/hwdata/pci.ids
usr/share/hwdata/usb.ids
usr/share/hwdata/videoaliases
usr/share/hwdata/videodrivers
+usr/share/i18n
usr/share/icons/hicolor/*/apps/nm-*
usr/share/icons/hicolor/index.theme
usr/share/locale/*/LC_MESSAGES/anaconda.mo
@@ -1113,10 +1115,13 @@ chmod 04755 $DEST/usr/libexec/polkit-1/polkit-agent-helper-1
chown root:dbus $DEST/$LIBDIR/dbus-1/dbus-daemon-launch-helper
chmod 04750 $DEST/$LIBDIR/dbus-1/dbus-daemon-launch-helper

-# Remove locales unused during the install
+# Generate default locale in case runtime doesn't work
+# /usr/share/i18n/ contains sources
install -m 644 $DEST/usr/share/anaconda/lang-table $DEST/etc/lang-table
+rm -f $DEST/usr/lib/locale/locale-archive
localedef -c -i en_US -f UTF-8 --prefix $DEST en_US

+# Remove unsupported translations
cat $DEST/usr/share/anaconda/lang-table* | awk '
{ gsub("-", "", $4);
print $4;
@@ -1135,14 +1140,7 @@ for p in lib share; do (
}
); done

-# Now shrink the locale-archive to contain just the minimum.
-localedef --prefix $DEST --list-archive > $DEST/locales.glibc
-LC_ALL=C unsupported="$(comm -13 $DEST/locales $DEST/locales.glibc)"
-localedef --prefix $DEST --delete-from-archive $unsupported
-mv $DEST/usr/lib/locale/locale-archive $DEST/usr/lib/locale/locale-archive.tmpl
-/usr/sbin/chroot $DEST /usr/sbin/build-locale-archive
-
-rm -f $DEST/locales $DEST/locales.list $DEST/locales.glibc
+rm -f $DEST/locales $DEST/locales.list

# fix up some links for man page related stuff
for file in nroff groff iconv geqn gtbl gpic grefer ; do
--
1.7.4

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 02-14-2011, 02:26 PM
Ales Kozumplik
 
Default Generate locale files on request

Ack, thanks.

Al_

On 02/14/2011 03:40 PM, Martin Sivak wrote:

+ /* get locale parts out of locale name */
+ locale_p = locale_i = languages[choice].lc_all;


Could you please add a sample locale string or two as a comment, it
makes the loop a lot easier to read and figure out what we really
parse.


I can, but for the review the formats are as follows:

en
en_US
cs_CZ.UTF-8
cz_CZ.UTF-8@latin


+ while (1) {
+ // we found separator
+ if (*locale_i == '.' || *locale_i == '@' || *locale_i == '') {
+ // last separator was annotating charset
+ if (*locale_p == '.') locale_charset = strndup(locale_p + 1,
locale_i - locale_p - 1);
+ // last separator was annotating modifier
+ else if (*locale_p == '@') locale_mod = strndup(locale_p + 1,
locale_i - locale_p - 1);
+ // there was no known separator last time
+ else locale_def = strndup(locale_p, locale_i - locale_p);





Doesn't this else imply locale_i == '' ?


Nope, the first if tests current character, but following ifs test locale_p (the last separator), so the else is actually processed first, because locale_p points to first character of locale.



+ /* generate locale record */
+ logMessage(INFO, "going to prepare locales for %s (locale: %s,
charset: %s)", languages[choice].lc_all, locale_p, locale_charset);
+ if ((localedef_pid = fork()) == 0) {
+ execl("/usr/bin/localedef", "localedef",
+ "-i", locale_p,
+ "-f", (locale_charset) ? locale_charset : "UTF-8",
+ languages[choice].lc_all, NULL);
+ }
+ if (localedef_pid< 0) logMessage(ERROR, "failed starting localedef
for %s", languages[choice].lc_all);


I think you want this log message say that a fork failed (unlikely,
maybe just abort). Also there should be an assert/abort/return after
the
call to execl---that can fail but we don't want two instances of the
process to continue.




True, exit should be there. I will add one


--
Martin Sivák
msivak@redhat.com
Red Hat Czech
Anaconda team / Brno, CZ

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 

Thread Tools




All times are GMT. The time now is 08:58 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org