-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 portable C++ Pseudorandom number generator #10541
Comments
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
I see that random() is called in two places: src/libstore/unix/gc.cc:44: Path tempLink = fmt("%1%.tmp-%2%-%3%", link, getpid(), random()); Should we create a PRNG before every call? |
@RCoeurjoly good question! When in doubt, it is better to avoid global state. I think for the Thanks for looking into this! |
I see another random() call in - src/libstore/unix/build/derivation-goal.cc:826 too |
That can also use a per-store PRNG |
The problem is that random() in gc.cc:44 is called by makeSymlink(const Path & link, const Path & target), a free function, so there is no way to access a per-store PRNG. I was thinking of the following: Initialize the PRNG in initNix, as it is done now with srandom(). Use this class wherever is needed. Thoughts? |
|
@RCoeurjoly After #10556 it will not be a free function @dottharun And the PRNG will be for one the |
#10556 is now merged, so this should be a bit easier. |
Avoid calls to
rand
/srand
/random
/srandom
and other things which are not portable to WindowsOriginally posted by @edolstra in #8901 (comment)
The text was updated successfully, but these errors were encountered: