-
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: make zfs_strerror really thread-safe and portable #16923
Conversation
Fixes openzfs#15793 Fixes openzfs#16640 Signed-off-by: Richard Kojedzinszky <[email protected]>
07ad792
to
cfb5106
Compare
May it happen that strerror_r() is available in most libc implementations, and the mutex could be dropped? |
I can't speak about other OS'es, but in FreeBSD I see it for 20+ years since FreeBSD 4.x. |
Did a quick check, found that uClibc and Musl do have strerror_r(). Glibc and FreeBSD have it too, so maybe, we could remove that piece of code? |
From FreeBSD's man page: "The strerror_r() function conforms to IEEE Std 1003.1-2001 (“POSIX.1”)". Sounds like quite a while ago. |
uClibc and Musl are known to be small libc implementations, perhaps with missing functions. Howewer, I found that both have strerror_r(), and it seems not to be configurable/optional. |
There appears to be two versions of From https://manpages.ubuntu.com/manpages/bionic/man3/strerror.3.html
It's also not clear to me from the documentation if |
Good catch, the GNU version may not write to the supplied buffer. Oh. |
Regarding locale, it should behave as strerror(). |
Unfortunately, openzfs has |
62ade6f
to
5d97eff
Compare
5d97eff
to
cbfe177
Compare
Signed-off-by: Richard Kojedzinszky <[email protected]>
cbfe177
to
af53b7d
Compare
openzfs#15793 wanted to make zfs_strerror threadsafe, unfortunately, it turned out that strerror_l() usage was wrong, and also, some libc implementations dont have strerror_l(). zfs_strerror() now simply calls original strerror() and copies the result to a thread-local buffer, then returns that. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Richard Kojedzinszky <[email protected]> Closes openzfs#15793 Closes openzfs#16640 Closes openzfs#16923
openzfs#15793 wanted to make zfs_strerror threadsafe, unfortunately, it turned out that strerror_l() usage was wrong, and also, some libc implementations dont have strerror_l(). zfs_strerror() now simply calls original strerror() and copies the result to a thread-local buffer, then returns that. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Richard Kojedzinszky <[email protected]> Closes openzfs#15793 Closes openzfs#16640 Closes openzfs#16923
turned out that strerror_l() usage was wrong, and also, some libc implementations dont have strerror_l(). zfs_strerror() now simply calls original strerror() and copies the result to a thread-local buffer, then returns that. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Richard Kojedzinszky <[email protected]> Closes openzfs#15793 Closes openzfs#16640 Closes openzfs#16923 Upstream commit dc0324b
Fixes #15793
Fixes #16640
Closes #16916
Motivation and Context
#15793 wanted to make zfs_strerror threadsafe, unfortunately, it turned out that strerror_l() usage was wrong, and also, some libc implementations dont have strerror_l().
Description
zfs_strerror() now simply calls original strerror() and copies the result to a thread-local buffer, then returns that.
How Has This Been Tested?
Code did compile.
Types of changes
Checklist:
Signed-off-by
.