foundObjects / zram-swap

A simple zram swap service for modern systemd Linux
MIT License
309 stars 44 forks source link

Fixed sleep crashing the script when running it in some locales. #4

Closed klement01 closed 3 years ago

klement01 commented 3 years ago

awk, and by extension the calc function, both return a number with a decimal separator defined by LC_NUMERIC. In locales such as France and Germany, this meant calc would return a comma separated decimal. This caused the script to fail when reaching the sleep command, because it can only parse dot separated decimals. To fix this, awk in the calc function is forced to use LC_NUMERIC=C (portable locale), which does use dot separated decimals.

foundObjects commented 3 years ago

Thanks! I've pulled the commit into my local repo and I'll push it with the rest of my work soon.

Off hand, can you think of a downside to just setting LC_ALL=C for the whole script? That would avoid any parsing issues in the future and solve this one. Admittedly that's a hack solution to localization issues but for a non-interactive worker script like this I don't imagine it would cause problems.

klement01 commented 3 years ago

Hey, I'm glad my fix could make it!

I can't think of any downsides to setting LC_ALL=C, although admittedly I don't know much about locales in scripts. If it does cause any issues in the future, I imagine troubleshooting one locale is much easier than troubleshooting all possible locales.