Draft: nsenter Avoid unnecessary looping by keeping reference to each namespace #2387
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Instead of having to go over the
namespace_files
array every time to access a certain namespace file just have a global variable to each one.This makes
open_namespace_fd
function much shorter as exact namespace can be passed exactly.Also
set_parent_user_ns_fd
no longer has to do a workaround the uninititialized read and can set the user namespace directly.The reason I looked in to reworking this is the commit 32c7870. The
set_parent_user_ns_fd
has a local variable that has to be set inside the for loop. Some code scanners mark it as a NULL de reference but that is impossible.Currently the variables are set from after the array initialization which makes it pretty brittle as if the
namespace_files
array ever changes it will break the references. (maybe add some asserts?)Another way is to create the
namespace_file
global variables first and then create an array of pointers to them. The downside of that method is it would require a more complicated loop code.