runc/libcontainer/nsenter
Natanael Copa ac6bd95319 nsexec: fix build against musl libc
Remove a wrongly added include which was added in commit 3c2e77ee (Add a
compatibility header for CentOS/RHEL 6, 2016-01-29) apparently to
fix this compile error on centos 6:

> In file included from
> Godeps/_workspace/src/github.com/opencontainers/runc/libcontainer/nsenter/nsexec.c:20:
> /usr/include/linux/netlink.h:35: error: expected specifier-qualifier-list before 'sa_family_t'

The glibc bits/sockaddr.h says that this header should never be included
directly[1]. Instead, sys/socket.h should be used.

The problem was correctly fixed later, in commit 394fb55 (Fix build
error on centos6, 2016-03-02) so the incorrect bits/sockaddr.h can
safely be removed.

This is needed to build musl libc.

Fixes #761

[1]: 20003c4988/bits/sockaddr.h (L20)

Signed-off-by: Natanael Copa <natanael.copa@docker.com>
2016-04-19 10:58:17 +02:00
..
README.md Move libcontainer into subdirectory 2015-06-21 19:29:15 -07:00
nsenter.go Move libcontainer into subdirectory 2015-06-21 19:29:15 -07:00
nsenter_gccgo.go Move libcontainer into subdirectory 2015-06-21 19:29:15 -07:00
nsenter_test.go Fix hanging tests when run without root 2016-03-27 01:53:01 -03:00
nsenter_unsupported.go Move libcontainer into subdirectory 2015-06-21 19:29:15 -07:00
nsexec.c nsexec: fix build against musl libc 2016-04-19 10:58:17 +02: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.