-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
make ps command to print the pid in container, not the pid in host #1015
Conversation
return fmt.Errorf("open /proc/%d/ns/pid %v", pids[0], err) | ||
} | ||
defer syscall.Close(fd) | ||
err = system.Setns(uintptr(fd), 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, okay. This is how I would like this to be done, unfortunately there are several potential problems with trying to Setns
in Go:
- Since Go programs are multithreaded (with no way of disabling it), this syscall can fail arbitrarily (the interface says that you should only use
setns
for single-threaded programs). - In SELinux (and rootless container) contexts, you'll also need to join the user namespace as well.
I think this would work better if we made libcontainer.Container.Processes()
do all of this internally, where it goes through the full runc exec
process (but only joins the User and PID namespaces). Then we send the PIDs to the main runC process over an AF_UNIX socket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't think we need to show inner pids for runc ps
, the global pids would be more useful, and we can do runc exec <id> ps -ef
if we really need to know the inner pids. Plus, docker top
shows global pids all the time and it works well, no one complained about it, why we think runc users would like this?
Even if someone really like it, we should add option like runc ps --inner <id>
instead of replacing the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "send PIDs over an AF_UNIX socket" means you'll get PIDs in your current PID namespace (as close to "global" as you can get). This was one of the extensions to the current set up I was considering (it means you could use libcontainer.Container.Processes()
inside a rootless container -- since we don't have cgroups).
ff50722
to
b4b3dba
Compare
Signed-off-by: Shukui Yang <[email protected]>
@cyphar http://man7.org/linux/man-pages/man2/setns.2.html |
make ps command to print the pid in container, not the pid in host
this pr depends upon #1013
before this ptch:
after this patch:
Signed-off-by: Shukui Yang [email protected]