-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix ZFS command output uses wrong comma separator #17075
base: master
Are you sure you want to change the base?
Conversation
ZFS incorrectly uses a full stop (.) as the decimal separator in human-readable output, even in locales that require a comma (,). This inconsistency causes issues with tools like `sort -h`, making sorting unreliable. This fix ensures that ZFS respects the system locale when formatting numerical output by setting `LC_NUMERIC` via `setlocale()`. Signed-off-by: Egor Kovalcuk <egor.kovalchuk@ossrevival.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not really fresh on locales, but setting it per value printed does not sound right.
Could you explain a bit more about what you mean and how I could do it better? Like, should I set the locale once somewhere else? |
Yea, I'd expect it to be set somewhere at the program start. |
Line 9171 in ecc44c4
Changing this line should fix issue too, but I don't know if it's good idea, maybe it's there for a reason. Could you tell me if it's okay? |
Could someone review it? |
The location seems better, but having there "C" locale previously makes me think it was intentional. Have you looked into the history why it is there? I suppose somebody wanted predictable numbers in output, possibly for some scripting. |
I imagine it's there to explicitly not change the output based on the local language, as ZFS is not translated in general. Like, even on a German system, I wouldn't expect OpenZFS to suddenly use the (German) comma separator, as all other output is still in English. It makes no sense to only "translate" the numeric representation then. That's more confusing than just expecting the English output with a dot as the separator, as is the case with all other untranslated programs. In your script, you could just use |
Clearly, the zfs output is meant to be human readable, I would think of it as containing an implicit |
Motivation and Context
Currently, OpenZFS incorrectly uses a full stop (.) as the decimal separator in its human-readable output, even in locales that require a comma (,). This issue not only affects aesthetics but also breaks tools like sort -h, which rely on correct numerical formatting.
For example, running:
produces incorrect sorting when using a locale that expects a comma separator.
This issue does not exist in illumos' ZFS, where numeric formatting respects the system locale.
This PR ensures that OpenZFS respects the system’s locale when formatting numerical output.
Description
This change ensures that OpenZFS uses the correct decimal separator based on the system locale.
The fix involves adding:
to lib/libzutil/zutil_nicenum.c, ensuring that numeric output is formatted according to the user's locale settings.
How Has This Been Tested?
The changes were tested on a system with different locales, including en_US.UTF-8 and de_DE.UTF-8, to verify that the decimal separator correctly follows the system locale. The output of zfs list -o used | sort -h was checked before and after applying the fix, ensuring that numeric sorting behaves as expected. Additional testing confirmed that the change does not affect systems where the default decimal separator is a period (.).
Types of changes
Checklist:
Signed-off-by
.