runc/nsenter
Dmitri Shuralyov 22eb88ec49 Fix nsenter package on unsupported platforms.
Commit 4d1d6185ab added this nsenter_unsupported.go file in order for nsenter to be a valid (but empty, non-functional) Go package on unsupported platforms. However, on such platforms, Go still complains because there exists a .c file in this folder, but the package doesn't use cgo.
Fix that by importing "C" pseudo-package.

Signed-off-by: Dmitri Shuralyov <shurcooL@gmail.com>
2015-05-15 17:32:44 -07:00
..
README.md Add more explanation for nsenter 2015-04-15 17:27:00 +08:00
nsenter.go nsenter: fix the -Wunused-variable warning 2015-03-10 14:43:09 -04:00
nsenter_gccgo.go nsenter: fix the -Wunused-variable warning 2015-03-10 14:43:09 -04:00
nsenter_test.go Read _LIBCONTAINER_INITPID in nsexec.c 2015-04-10 11:23:09 -07:00
nsenter_unsupported.go Fix nsenter package on unsupported platforms. 2015-05-15 17:32:44 -07:00
nsexec.c add comments for nsexec.c 2015-04-14 13:55:04 +08:00

README.md

nsenter

The nsenter package registers a special init constructor that is called before the Go runtime has a chance to boot. This provides us the ability to setns on existing namespaces and avoid the issues that the Go runtime has with multiple threads. This constructor will be called if this package is registered, imported, in your go application.

The nsenter package will import "C" and it uses cgo package. In cgo, if the import of "C" is immediately preceded by a comment, that comment, called the preamble, is used as a header when compiling the C parts of the package. So every time we import package nsenter, the C code function nsexec() would be called. And package nsenter is now only imported in Docker execdriver, so every time before we call execdriver.Exec(), that C code would run.

nsexec() will first check the environment variable _LIBCONTAINER_INITPID which will give the process of the container that should be joined. Namespaces fd will be found from /proc/[pid]/ns and set by setns syscall.

And then get the pipe number from _LIBCONTAINER_INITPIPE, error message could be transfered through it. If tty is added, _LIBCONTAINER_CONSOLE_PATH will have value and start a console for output.

Finally, nsexec() will clone a child process , exit the parent process and let the Go runtime take over.