[lxc-devel] [go-lxc/v2] container: implement DevptsFd()
brauner on Github
lxc-bot at linuxcontainers.org
Wed Aug 5 12:43:36 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 455 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200805/f37c61cc/attachment.bin>
-------------- next part --------------
From 892c62586996d0bb9c12ba23ec876bcb3958db8a Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at 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.brauner at 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);
More information about the lxc-devel
mailing list