[libvirt] libvirt-guests output

Hi, Here is an example of libvirt-guest output: $Running guests on default URI: test-vm $Suspending guests on default URI... $Suspending test-vm: $done Why all the lines begin with "$" ? Thank you, -- Laurent Léonard

On 12/09/2010 11:21 AM, Laurent Léonard wrote:
Hi,
Here is an example of libvirt-guest output: $Running guests on default URI: test-vm $Suspending guests on default URI... $Suspending test-vm: $done
Why all the lines begin with "$" ?
Because you aren't using bash. Bash supports $"" as a way to provide gettext translation of strings into the user's preferred location. Init scripts written for Fedora-based systems assume that /bin/sh is bash, and therefore that $"" is usable. Dash does not understand $"" (POSIX says it has unspecified behavior), and treats it as a literal '$' followed by a normal (untranslated) "". It's probably a nice goal to port libvirt-guests to non-bash /bin/sh, but it may take a lot more work; in particular, there are TONS of existing init scripts on Fedora that assume bash extensions, which libvirt-guests used as its starting point. And I'm not quite sure what the POSIX-compliant replacement for $"" string translation would be. There are two problems to solve - how to get xgettext to recognize a string that needs translation, and how to use gettext(1) (rather than bash's magic $"" automatically calling gettext(3)) to do the translation at runtime. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

Le jeudi 09 décembre 2010 19:31:22, Eric Blake a écrit :
On 12/09/2010 11:21 AM, Laurent Léonard wrote:
Hi,
Here is an example of libvirt-guest output: $Running guests on default URI: test-vm $Suspending guests on default URI... $Suspending test-vm: $done
Why all the lines begin with "$" ?
Because you aren't using bash.
Bash supports $"" as a way to provide gettext translation of strings into the user's preferred location. Init scripts written for Fedora-based systems assume that /bin/sh is bash, and therefore that $"" is usable.
Dash does not understand $"" (POSIX says it has unspecified behavior), and treats it as a literal '$' followed by a normal (untranslated) "".
It's probably a nice goal to port libvirt-guests to non-bash /bin/sh, but it may take a lot more work; in particular, there are TONS of existing init scripts on Fedora that assume bash extensions, which libvirt-guests used as its starting point. And I'm not quite sure what the POSIX-compliant replacement for $"" string translation would be. There are two problems to solve - how to get xgettext to recognize a string that needs translation, and how to use gettext(1) (rather than bash's magic $"" automatically calling gettext(3)) to do the translation at runtime.
Guido Günter wrote :
Hi Laurent,
this looks great, one suggestion:
On Tue, Dec 14, 2010 at 10:49:01AM +0000, Laurent Léonard wrote:
The following commit has been merged in the experimental branch: commit 7d7aed44c56d113713547e5dd9bdbe4ab6684c00 Author: Laurent Léonard <laurent@open-minds.org> Date: Tue Dec 14 11:24:42 2010 +0100
New patch 0010-Debianize-libvirt-guests.patch
+ if ! $configured; then +- echo $"Ignoring guests on $uri URI" ++ echo "Ignoring guests on $uri URI"
It might make sense to introduce a function:
libvirt_echo() { echo $"$@" }
So that the lines above become:
if ! $configured; then libvirt_echo "Ignoring guests on $uri URI"
If we get this integrated upstream we'd only have to patch a single line which might future merging easier. We might even be able to either pick $" or just " by looking at the shell used.
What about that proposition ? -- Laurent Léonard

On 12/14/2010 10:58 AM, Laurent Léonard wrote:
New patch 0010-Debianize-libvirt-guests.patch
+ if ! $configured; then +- echo $"Ignoring guests on $uri URI" ++ echo "Ignoring guests on $uri URI"
It might make sense to introduce a function:
libvirt_echo() { echo $"$@" }
So that the lines above become:
if ! $configured; then libvirt_echo "Ignoring guests on $uri URI"
If we get this integrated upstream we'd only have to patch a single line which might future merging easier. We might even be able to either pick $" or just " by looking at the shell used.
What about that proposition ?
Certainly it is better to go through a wrapper function, to minimize the number of places where translation is attempted. And run-time detection of which method to use seems easy enough; something like this (minimally tested): if (LC_ALL=C; test $"x" = x); then libvirt_echo() { echo $"$1" } else libvirt_echo() { gettext "$1" } fi But there is still the issue of marking translated strings in such a way that xgettext can find them. How do other debian-ized init scripts handle this problem? Is there something in $sysconfdir/rc.d/init.d/functions that is already common between distros to aid in this effort? Oh, and this is interesting reading[1], since it claims the use of $"" in bash is a security hole. Instead, the current gettext recommendations for adding i18n to a shell script are to source the file gettext.sh, set TEXTDOMAIN and TEXTDOMAINDIR, and use gettext(1) and friends everywhere in the first place. But I didn't find out how xgettext works on shell scripts (if it even can); xgettext -L doesn't seem to support a shell-like language. I guess I'll ask for more advice on the gettext mailing list. [1] http://www.gnu.org/software/gettext/manual/gettext.html#bash But if we go with the gettext advice of avoiding $"" altogether, then there's no need to go through an intermediate function, and we should instead mark every translated string by using gettext instead of echo. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

Le mardi 14 décembre 2010 19:34:01, Eric Blake a écrit :
On 12/14/2010 10:58 AM, Laurent Léonard wrote:
New patch 0010-Debianize-libvirt-guests.patch
+ if ! $configured; then +- echo $"Ignoring guests on $uri URI" ++ echo "Ignoring guests on $uri URI"
It might make sense to introduce a function:
libvirt_echo() {
echo $"$@"
}
So that the lines above become: if ! $configured; then
libvirt_echo "Ignoring guests on $uri URI"
If we get this integrated upstream we'd only have to patch a single line which might future merging easier. We might even be able to either pick $" or just " by looking at the shell used.
What about that proposition ?
Certainly it is better to go through a wrapper function, to minimize the number of places where translation is attempted. And run-time detection of which method to use seems easy enough; something like this (minimally tested):
if (LC_ALL=C; test $"x" = x); then libvirt_echo() { echo $"$1" } else libvirt_echo() { gettext "$1" } fi
But there is still the issue of marking translated strings in such a way that xgettext can find them. How do other debian-ized init scripts handle this problem? Is there something in $sysconfdir/rc.d/init.d/functions that is already common between distros to aid in this effort?
Oh, and this is interesting reading[1], since it claims the use of $"" in bash is a security hole. Instead, the current gettext recommendations for adding i18n to a shell script are to source the file gettext.sh, set TEXTDOMAIN and TEXTDOMAINDIR, and use gettext(1) and friends everywhere in the first place. But I didn't find out how xgettext works on shell scripts (if it even can); xgettext -L doesn't seem to support a shell-like language. I guess I'll ask for more advice on the gettext mailing list.
[1] http://www.gnu.org/software/gettext/manual/gettext.html#bash
But if we go with the gettext advice of avoiding $"" altogether, then there's no need to go through an intermediate function, and we should instead mark every translated string by using gettext instead of echo.
"xgettext -L Shell" prints the following warning message when using with a script that use the $"..." syntax: the syntax $"..." is deprecated due to security reasons; use eval_gettext instead "eval_gettext" seems to work like $"..." with Bash, but doesn't work with Dash... Indeed if we find a solution that works with Bash and Dash there is no need to go through an intermediate function. -- Laurent Léonard

Le mardi 14 décembre 2010 21:03:26, Laurent Léonard a écrit :
Le mardi 14 décembre 2010 19:34:01, Eric Blake a écrit :
On 12/14/2010 10:58 AM, Laurent Léonard wrote:
New patch 0010-Debianize-libvirt-guests.patch
+ if ! $configured; then +- echo $"Ignoring guests on $uri URI" ++ echo "Ignoring guests on $uri URI"
It might make sense to introduce a function:
libvirt_echo() {
echo $"$@"
}
So that the lines above become: if ! $configured; then
libvirt_echo "Ignoring guests on $uri URI"
If we get this integrated upstream we'd only have to patch a single line which might future merging easier. We might even be able to either pick $" or just " by looking at the shell used.
What about that proposition ?
Certainly it is better to go through a wrapper function, to minimize the number of places where translation is attempted. And run-time detection of which method to use seems easy enough; something like this (minimally tested):
if (LC_ALL=C; test $"x" = x); then
libvirt_echo() {
echo $"$1"
}
else
libvirt_echo() {
gettext "$1"
}
fi
But there is still the issue of marking translated strings in such a way that xgettext can find them. How do other debian-ized init scripts handle this problem? Is there something in $sysconfdir/rc.d/init.d/functions that is already common between distros to aid in this effort?
Oh, and this is interesting reading[1], since it claims the use of $"" in bash is a security hole. Instead, the current gettext recommendations for adding i18n to a shell script are to source the file gettext.sh, set TEXTDOMAIN and TEXTDOMAINDIR, and use gettext(1) and friends everywhere in the first place. But I didn't find out how xgettext works on shell scripts (if it even can); xgettext -L doesn't seem to support a shell-like language. I guess I'll ask for more advice on the gettext mailing list.
[1] http://www.gnu.org/software/gettext/manual/gettext.html#bash
But if we go with the gettext advice of avoiding $"" altogether, then there's no need to go through an intermediate function, and we should instead mark every translated string by using gettext instead of echo.
"xgettext -L Shell" prints the following warning message when using with a script that use the $"..." syntax: the syntax $"..." is deprecated due to security reasons; use eval_gettext instead
"eval_gettext" seems to work like $"..." with Bash, but doesn't work with Dash...
Indeed if we find a solution that works with Bash and Dash there is no need to go through an intermediate function.
"eval_gettext" works with Bash and Dash if we add . /usr/bin/gettext.sh in the script. So "eval_gettext" seems to be the right way... -- Laurent Léonard
participants (2)
-
Eric Blake
-
Laurent Léonard