Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ndctl:ndctl / inject-smart.sh fails with LANG=cs_CZ.UTF-8 #254

Open
lenticularis39 opened this issue Sep 12, 2023 · 2 comments
Open

ndctl:ndctl / inject-smart.sh fails with LANG=cs_CZ.UTF-8 #254

lenticularis39 opened this issue Sep 12, 2023 · 2 comments

Comments

@lenticularis39
Copy link

With locale set to cs_CZ.UTF-8, inject-smart.sh test fails with the following error (full log of the test here):

++ printf '%0.0f\n' 23.0
/home/tglozar/dev/ndctl/test/inject-smart.sh: řádek 108: printf: 23.0: chybné číslo
+++ err 108
++++ basename /home/tglozar/dev/ndctl/test/inject-smart.sh
+++ echo test/inject-smart.sh: failed at line 108
+++ '[' -n '' ']'
+++ exit 1
+ old_val='23
test/inject-smart.sh: failed at line 108'
++ err 132
+++ basename /home/tglozar/d
ev/ndctl/test/inject-smart.sh
++ echo test/inject-smart.sh: failed at line 132
++ '[' -n '' ']'
++ exit 1

This is caused by the floating point separator being , in Czech locale rather than .:

$ printf '%f\n' 20.0; echo $?
bash: printf: 20.0: chybné číslo
20,000000
1
$ LC_ALL=C printf '%f\n' 20.0; echo $?
20.000000
0

Running the test with LC_ALL=C fixes the issue.

@stellarhopper
Copy link
Member

@lenticularis39 Does something like this fix it for you?

diff --git a/test/inject-smart.sh b/test/inject-smart.sh
index 046322b..4bca492 100755
--- a/test/inject-smart.sh
+++ b/test/inject-smart.sh
@@ -105,7 +105,14 @@ get_field()
        json="$($NDCTL list -b $bus -d $dimm -H)"
        val="$(jq -r ".[].dimms[].health.$smart_listing" <<< $json)"
        val="$(translate_val $val)"
-       printf "%0.0f\n" "$val"
+
+       # val can be e.g. "20.0". Printf complains on this for locales that
+       # use ',' as the decimal separator. For this %0.0f case, it doesn't
+       # matter what the decimal separator is, and bash helpfully does print
+       # "20" even if #$? indicates an error, and there is an error message
+       # on stderr. Ignore the error, and just pick the "20" to avoid such
+       # cases
+       printf "%0.0f\n" "$val" 2 >/dev/null || true
 }
 
 verify()

@lenticularis39
Copy link
Author

@stellarhopper Yes, that fixes the issue, if applied without typo 2 >/dev/null -> 2>/dev/null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants