[lxc-devel] [lxd/master] exec: fix OpenPtyInDevpts()
brauner on Github
lxc-bot at linuxcontainers.org
Thu Aug 6 10:34:18 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200806/84c56695/attachment.bin>
-------------- next part --------------
From a32272e33376a801165b7bacd56beac40156fc9d Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 6 Aug 2020 11:29:01 +0200
Subject: [PATCH] exec: fix OpenPtyInDevpts()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/instance_exec.go | 5 ++++-
shared/util_linux.go | 6 +++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/lxd/instance_exec.go b/lxd/instance_exec.go
index 5ca8006228..da59162df3 100644
--- a/lxd/instance_exec.go
+++ b/lxd/instance_exec.go
@@ -132,10 +132,13 @@ func (s *execWs) Do(op *operations.Operation) error {
if s.req.Interactive {
ttys = make([]*os.File, 1)
ptys = make([]*os.File, 1)
- ptys[0], ttys[0], err = shared.OpenPtyInDevpts(int(s.devptsFd.Fd()), s.rootUid, s.rootGid)
+
if s.devptsFd != nil {
+ ptys[0], ttys[0], err = shared.OpenPtyInDevpts(int(s.devptsFd.Fd()), s.rootUid, s.rootGid)
s.devptsFd.Close()
s.devptsFd = nil
+ } else {
+ ptys[0], ttys[0], err = shared.OpenPty(s.rootUid, s.rootGid)
}
if err != nil {
return err
diff --git a/shared/util_linux.go b/shared/util_linux.go
index eaba564795..ee689dd8aa 100644
--- a/shared/util_linux.go
+++ b/shared/util_linux.go
@@ -439,7 +439,11 @@ func OpenPtyInDevpts(devpts_fd int, uid, gid int64) (*os.File, *os.File, error)
}
pty = os.NewFile(ptyFd, fmt.Sprintf("/dev/pts/%d", id))
- } else if devpts_fd < 0 {
+ } else {
+ if devpts_fd >= 0 {
+ return nil, nil, fmt.Errorf("TIOCGPTPEER required but not available")
+ }
+
// Get the pty side.
id := 0
_, _, errno = unix.Syscall(unix.SYS_IOCTL, uintptr(ptx.Fd()), unix.TIOCGPTN, uintptr(unsafe.Pointer(&id)))
More information about the lxc-devel
mailing list