[lxc-devel] [lxd/master] util_linux: update terminology

brauner on Github lxc-bot at linuxcontainers.org
Fri Jun 19 22:16:23 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/20200619/136bd2da/attachment.bin>
-------------- next part --------------
From cebef33c2f8d1d4ed59aacdd044f56b5925a6631 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 20 Jun 2020 00:06:36 +0200
Subject: [PATCH] util_linux: update terminology

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxd/instance/drivers/driver_lxc.go | 14 ++++++------
 shared/util_linux.go               | 36 +++++++++++++++---------------
 2 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index fa943932c4..03e7490295 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -5556,7 +5556,7 @@ func (c *lxc) Console() (*os.File, chan error, error) {
 		rootUID, rootGID = idmapset.ShiftIntoNs(0, 0)
 	}
 
-	master, slave, err := shared.OpenPty(rootUID, rootGID)
+	ptmx, pts, err := shared.OpenPty(rootUID, rootGID)
 	if err != nil {
 		return nil, nil, err
 	}
@@ -5564,9 +5564,9 @@ func (c *lxc) Console() (*os.File, chan error, error) {
 	cmd := exec.Cmd{}
 	cmd.Path = c.state.OS.ExecPath
 	cmd.Args = args
-	cmd.Stdin = slave
-	cmd.Stdout = slave
-	cmd.Stderr = slave
+	cmd.Stdin = pts
+	cmd.Stdout = pts
+	cmd.Stderr = pts
 
 	err = cmd.Start()
 	if err != nil {
@@ -5575,8 +5575,8 @@ func (c *lxc) Console() (*os.File, chan error, error) {
 
 	go func() {
 		err = cmd.Wait()
-		master.Close()
-		slave.Close()
+		ptmx.Close()
+		pts.Close()
 	}()
 
 	go func() {
@@ -5584,7 +5584,7 @@ func (c *lxc) Console() (*os.File, chan error, error) {
 		cmd.Process.Kill()
 	}()
 
-	return master, chDisconnect, nil
+	return ptmx, chDisconnect, nil
 }
 
 // ConsoleLog returns console log.
diff --git a/shared/util_linux.go b/shared/util_linux.go
index 83f69d8f46..ad391f3ed1 100644
--- a/shared/util_linux.go
+++ b/shared/util_linux.go
@@ -401,56 +401,56 @@ func OpenPty(uid, gid int64) (*os.File, *os.File, error) {
 	revert := true
 
 	// Create a PTS pair.
-	master, err := os.OpenFile("/dev/ptmx", os.O_RDWR|unix.O_CLOEXEC, 0)
+	ptmx, err := os.OpenFile("/dev/ptmx", os.O_RDWR|unix.O_CLOEXEC, 0)
 	if err != nil {
 		return nil, nil, err
 	}
 	defer func() {
 		if revert {
-			master.Close()
+			ptmx.Close()
 		}
 	}()
 
-	// Unlock the master and slave.
+	// Unlock the ptmx and pts.
 	val := 0
-	_, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(master.Fd()), unix.TIOCSPTLCK, uintptr(unsafe.Pointer(&val)))
+	_, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(ptmx.Fd()), unix.TIOCSPTLCK, uintptr(unsafe.Pointer(&val)))
 	if errno != 0 {
 		return nil, nil, unix.Errno(errno)
 	}
 
-	var slave *os.File
-	slaveFd, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(master.Fd()), unix.TIOCGPTPEER, uintptr(unix.O_NOCTTY|unix.O_CLOEXEC|os.O_RDWR))
+	var pts *os.File
+	ptsFd, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(ptmx.Fd()), unix.TIOCGPTPEER, uintptr(unix.O_NOCTTY|unix.O_CLOEXEC|os.O_RDWR))
 	if errno == 0 {
-		// Get the slave side.
+		// Get the pts side.
 		id := 0
-		_, _, errno = unix.Syscall(unix.SYS_IOCTL, uintptr(master.Fd()), unix.TIOCGPTN, uintptr(unsafe.Pointer(&id)))
+		_, _, errno = unix.Syscall(unix.SYS_IOCTL, uintptr(ptmx.Fd()), unix.TIOCGPTN, uintptr(unsafe.Pointer(&id)))
 		if errno != 0 {
 			return nil, nil, unix.Errno(errno)
 		}
 
-		slave = os.NewFile(slaveFd, fmt.Sprintf("/dev/pts/%d", id))
+		pts = os.NewFile(ptsFd, fmt.Sprintf("/dev/pts/%d", id))
 	} else {
-		// Get the slave side.
+		// Get the pts side.
 		id := 0
-		_, _, errno = unix.Syscall(unix.SYS_IOCTL, uintptr(master.Fd()), unix.TIOCGPTN, uintptr(unsafe.Pointer(&id)))
+		_, _, errno = unix.Syscall(unix.SYS_IOCTL, uintptr(ptmx.Fd()), unix.TIOCGPTN, uintptr(unsafe.Pointer(&id)))
 		if errno != 0 {
 			return nil, nil, unix.Errno(errno)
 		}
 
-		// Open the slave.
-		slave, err = os.OpenFile(fmt.Sprintf("/dev/pts/%d", id), os.O_RDWR|unix.O_NOCTTY, 0)
+		// Open the pts.
+		pts, err = os.OpenFile(fmt.Sprintf("/dev/pts/%d", id), os.O_RDWR|unix.O_NOCTTY, 0)
 		if err != nil {
 			return nil, nil, err
 		}
 	}
 	defer func() {
 		if revert {
-			slave.Close()
+			pts.Close()
 		}
 	}()
 
 	// Configure both sides
-	for _, entry := range []*os.File{master, slave} {
+	for _, entry := range []*os.File{ptmx, pts} {
 		// Get termios.
 		t, err := unix.IoctlGetTermios(int(entry.Fd()), unix.TCGETS)
 		if err != nil {
@@ -488,14 +488,14 @@ func OpenPty(uid, gid int64) (*os.File, *os.File, error) {
 		}
 	}
 
-	// Fix the ownership of the slave side.
-	err = unix.Fchown(int(slave.Fd()), int(uid), int(gid))
+	// Fix the ownership of the pts side.
+	err = unix.Fchown(int(pts.Fd()), int(uid), int(gid))
 	if err != nil {
 		return nil, nil, err
 	}
 
 	revert = false
-	return master, slave, nil
+	return ptmx, pts, nil
 }
 
 // Extensively commented directly in the code. Please leave the comments!


More information about the lxc-devel mailing list