The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/go-lxc/pull/139
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === which calls into LXC to allocate a new devpts fd for the containers devpts instance. Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
From 892c62586996d0bb9c12ba23ec876bcb3958db8a Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Wed, 5 Aug 2020 14:28:31 +0200 Subject: [PATCH] container: implement DevptsFd() which calls into LXC to allocate a new devpts fd for the containers devpts instance. Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- container.go | 13 +++++++++++++ lxc-binding.c | 8 ++++++++ lxc-binding.h | 1 + 3 files changed, 22 insertions(+) diff --git a/container.go b/container.go index 30c5ef6..ab57b80 100644 --- a/container.go +++ b/container.go @@ -312,6 +312,19 @@ func (c *Container) InitPidFd() (*os.File, error) { return os.NewFile(uintptr(pidfd), "[pidfd]"), nil } +// DevptsFd returns the pidfd of the container's init process. +func (c *Container) DevptsFd() (*os.File, error) { + c.mu.RLock() + defer c.mu.RUnlock() + + devptsFd := int(C.go_lxc_devpts_fd(c.container)) + if devptsFd < 0 { + return nil, unix.Errno(unix.EBADF) + } + + return os.NewFile(uintptr(devptsFd), "/dev/pts/ptmx"), nil +} + // SeccompNotifyFd returns the seccomp notify fd of the container. func (c *Container) SeccompNotifyFd() (*os.File, error) { c.mu.RLock() diff --git a/lxc-binding.c b/lxc-binding.c index 2c26162..6030f51 100644 --- a/lxc-binding.c +++ b/lxc-binding.c @@ -67,6 +67,14 @@ int go_lxc_seccomp_notify_fd(struct lxc_container *c) { #endif } +int go_lxc_devpts_fd(struct lxc_container *c) { +#if VERSION_AT_LEAST(4, 1, 0) + return c->devpts_fd(c); +#else + return ret_errno(ENOSYS); +#endif +} + bool go_lxc_want_daemonize(struct lxc_container *c, bool state) { return c->want_daemonize(c, state); } diff --git a/lxc-binding.h b/lxc-binding.h index b52e2cd..1264786 100644 --- a/lxc-binding.h +++ b/lxc-binding.h @@ -81,6 +81,7 @@ extern int go_lxc_snapshot_list(struct lxc_container *c, struct lxc_snapshot **r extern int go_lxc_snapshot(struct lxc_container *c); extern pid_t go_lxc_init_pid(struct lxc_container *c); extern int go_lxc_init_pidfd(struct lxc_container *c); +extern int go_lxc_devpts_fd(struct lxc_container *c); extern int go_lxc_seccomp_notify_fd(struct lxc_container *c); extern bool go_lxc_checkpoint(struct lxc_container *c, char *directory, bool stop, bool verbose); extern bool go_lxc_restore(struct lxc_container *c, char *directory, bool verbose);
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel