Skip to content

Draft: nsenter Avoid unnecessary looping by keeping reference to each namespace #2387

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

igo95862
Copy link
Contributor

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.

…pace

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.
@karelzak
Copy link
Collaborator

It would be enough (and maybe more elegant) to define indexes for the namespaces array:

enum {
   FILE_NS_MNT,
   FILE_NS_PID,
   ...
};
...
open_namespace_fd(&namespace_files[FILE_NS_MNT], optarg);

Maybe we can also rename namespace_files[] to something shorter, for example, nsfiles[], so the result will be for example: nsfiles[FILE_NS_MNT] and without additional global variables.

@igo95862
Copy link
Contributor Author

Interesting. I will try using enum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants