lib/utils.c: lazy initialize user_hz and psched_hz
Rather than initializing user_hz and psched_hz when libnl is loaded, defer initialization of these variables to the first time they are used. This has several advantages: 1) Avoids an unnecessary permission denied error on /proc/net/psched, which can occur on systems where /proc/net isn't readable due to security policy. 2) Allows program code to initialize the environment variables PROC_NET_PSCHED and/or PROC_ROOT prior to the first libnl call, giving a program more flexibility about where libnl should look. 3) Trivially faster startup time (although unlikely to be significant). 4) Compiler may be able to prove that the get_psched_settings() function is unreachable and optimize appropriately, because the callers never (directly or indirectly) use this method. This could occur, for instance, in doing dead code elimination for programs which statically link libnl. Signed-off-by:Nick Kralevich <nnk@google.com> https://github.com/thom311/libnl/pull/123 (cherry picked from commit 8e0ead4b5bcf22dcc210442629ebb416116ea1f0) Test: Compiles and ueventd proc_net denial is gone. Bug: 35197529 Change-Id: Iad9ea207315c92489617334edeba73053d67cf6b
Loading
Please sign in to comment