bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reloading domain


From: Elan Ruusamäe
Subject: Re: reloading domain
Date: Mon, 27 Jul 2009 00:29:02 +0300
User-agent: KMail/1.11.2 (Linux/2.6.27.15-1; KDE/4.2.3; x86_64; ; )

hi

On Sunday 26 July 2009 23:13, Bruno Haible wrote:
> Elan Ruusamäe wrote:
> > is it possible to reload/unload existing .mo in running process?
> > as it seems the .mo file is cached and kept open forever.
>
> Yes, the .mo file is loaded with mmap, cached and kept open as long as the
> process runs.
>
> However, you should be able to mark the cache as invalid by doing
>
>   bindtextdomain (DOMAIN, "/");
>   bindtextdomain (DOMAIN, LOCALEDIR);
>
> where LOCALEDIR is the base directory for the .mo files used by your
> package (usually $PREFIX/share/locale).

well. it doesn't work if the file is REPLACED, meaning the inode changes (which 
is quite usual in `make install' case)...

$ gcc po.c -Wall -o po
$ LC_ALL=et_EE.utf8 ./po
laadimise aeg
updating .mo
LAADIMISE AEG

$ gcc po.c -Wall -o po -DDELETE
$ LC_ALL=et_EE.utf8 ./po
laadimise aeg
updating .mo
laadimise aeg

$ cat po.c
#include <libintl.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>

#include "paths.h"
#define PACKAGE "roke"
#define _(String) gettext(String)

int main() {
#ifdef DELETE
        system("rm "LOCALEDIR"/et/LC_MESSAGES/roke.mo");
#endif
        system("cp 1.mo "LOCALEDIR"/et/LC_MESSAGES/roke.mo");

        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);

        setlocale(LC_ALL, "");

        // 1. print original
        printf("%s\n", _("Load time"));

        printf("updating .mo\n");
//      { char buf[20]; fgets(buf, sizeof(buf), stdin); }

#ifdef DELETE
        system("rm "LOCALEDIR"/et/LC_MESSAGES/roke.mo");
#endif
        system("cp 2.mo "LOCALEDIR"/et/LC_MESSAGES/roke.mo");

        bindtextdomain(PACKAGE, "/");
        bindtextdomain(PACKAGE, LOCALEDIR);
        printf("%s\n", _("Load time"));

        return(0);
}

any luck with that case?

...like hacking _nl_domain_bindings symbol (it's visible in my glibc)
$ objdump -T /lib64/libc.so.6 | grep _nl_domain_bindings
00000000003582a8 g    DO .bss   0000000000000008  GLIBC_2.2.5 
_nl_domain_bindings


> Bruno

-- 
glen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]