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
Use /dev/urandom and sysctl(RANDOM_UUID) on Linux. #743
Conversation
Add fallback paths for when the getrandom(2) system call is not available. Try /dev/urandom first and sysctl(RANDOM_UUID) second. The sysctl issues a warning in the system logs with some kernels but that seems like an acceptable tradeoff for the fallback of a fallback.
Looks good to me. Did you just push an update to fix the tests? |
Yep, ~30 minutes ago. I was going to wait until appveyor was done before posting a "fixed!" comment. |
Thanks! |
I noticed some stuff like I read up on the docs for sysctl, and found this:
I think let's try getting away with not supporting this, unless you have an actual use case in mind? Further, since we don't actually store method yet, let's just handle ENOSYS since the logic is way simpler. And let's use the posix abstraction functions already available (see the Darwin getRandomBytes implementation). Good point about read only supporting 0x7ffff000 bytes at max. That should go into the I already pushed all the above stuff into master. I hope you don't mind, it restructured a lot of what you did. |
Good idea!
Yes, kernels < 3.17 and no /dev mounted. One somewhat common use case is people running applications in containers.
Apologies, I should have written a better comment. Linux returns EINVAL when you pass in a value > INT_MAX, at least some of the time. We have hit this bug in libuv. |
I'm willing to support this use case, but isn't there kinda no excuse for using an old kernel in a container?
Ok, good to know. I'll push a fix to |
There's no excuse for lots of things but people still do them. If - I mean: when! - zig is going to get popular, you're going to get bug reports about it sooner or later.
Yes. Now that I think about it, it's predominantly an issue with 32 bits kernels although you can probably still trigger it on 64 bits kernels if you try to read or write 2**63 bytes or more. |
I agree with this, and I don't want to be stubborn here, but, would it be reasonable to tell people, "your use case is invalid and is therefore not supported"?
Makes sense. I'll push another fix. |
Hey, it's your project; that's your call to make. |
Add fallback paths for when the getrandom(2) system call is not
available. Try /dev/urandom first and sysctl(RANDOM_UUID) second.
The sysctl issues a warning in the system logs with some kernels but
that seems like an acceptable tradeoff for the fallback of a fallback.