@@ -3,8 +3,9 @@ package libcontainer
33import (
44 "fmt"
55 "os"
6- "syscall"
76 "unsafe"
7+
8+ "golang.org/x/sys/unix"
89)
910
1011func ConsoleFromFile (f * os.File ) Console {
@@ -16,7 +17,7 @@ func ConsoleFromFile(f *os.File) Console {
1617// newConsole returns an initialized console that can be used within a container by copying bytes
1718// from the master side to the slave that is attached as the tty for the container's init process.
1819func newConsole () (Console , error ) {
19- master , err := os .OpenFile ("/dev/ptmx" , syscall .O_RDWR | syscall .O_NOCTTY | syscall .O_CLOEXEC , 0 )
20+ master , err := os .OpenFile ("/dev/ptmx" , unix .O_RDWR | unix .O_NOCTTY | unix .O_CLOEXEC , 0 )
2021 if err != nil {
2122 return nil , err
2223 }
@@ -68,28 +69,28 @@ func (c *linuxConsole) Close() error {
6869// mount initializes the console inside the rootfs mounting with the specified mount label
6970// and applying the correct ownership of the console.
7071func (c * linuxConsole ) mount () error {
71- oldMask := syscall .Umask (0000 )
72- defer syscall .Umask (oldMask )
72+ oldMask := unix .Umask (0000 )
73+ defer unix .Umask (oldMask )
7374 f , err := os .Create ("/dev/console" )
7475 if err != nil && ! os .IsExist (err ) {
7576 return err
7677 }
7778 if f != nil {
7879 f .Close ()
7980 }
80- return syscall .Mount (c .slavePath , "/dev/console" , "bind" , syscall .MS_BIND , "" )
81+ return unix .Mount (c .slavePath , "/dev/console" , "bind" , unix .MS_BIND , "" )
8182}
8283
8384// dupStdio opens the slavePath for the console and dups the fds to the current
8485// processes stdio, fd 0,1,2.
8586func (c * linuxConsole ) dupStdio () error {
86- slave , err := c .open (syscall .O_RDWR )
87+ slave , err := c .open (unix .O_RDWR )
8788 if err != nil {
8889 return err
8990 }
9091 fd := int (slave .Fd ())
9192 for _ , i := range []int {0 , 1 , 2 } {
92- if err := syscall .Dup3 (fd , i , 0 ); err != nil {
93+ if err := unix .Dup3 (fd , i , 0 ); err != nil {
9394 return err
9495 }
9596 }
@@ -98,7 +99,7 @@ func (c *linuxConsole) dupStdio() error {
9899
99100// open is a clone of os.OpenFile without the O_CLOEXEC used to open the pty slave.
100101func (c * linuxConsole ) open (flag int ) (* os.File , error ) {
101- r , e := syscall .Open (c .slavePath , flag , 0 )
102+ r , e := unix .Open (c .slavePath , flag , 0 )
102103 if e != nil {
103104 return nil , & os.PathError {
104105 Op : "open" ,
@@ -110,7 +111,7 @@ func (c *linuxConsole) open(flag int) (*os.File, error) {
110111}
111112
112113func ioctl (fd uintptr , flag , data uintptr ) error {
113- if _ , _ , err := syscall .Syscall (syscall .SYS_IOCTL , fd , flag , data ); err != 0 {
114+ if _ , _ , err := unix .Syscall (unix .SYS_IOCTL , fd , flag , data ); err != 0 {
114115 return err
115116 }
116117 return nil
@@ -120,13 +121,13 @@ func ioctl(fd uintptr, flag, data uintptr) error {
120121// unlockpt should be called before opening the slave side of a pty.
121122func unlockpt (f * os.File ) error {
122123 var u int32
123- return ioctl (f .Fd (), syscall .TIOCSPTLCK , uintptr (unsafe .Pointer (& u )))
124+ return ioctl (f .Fd (), unix .TIOCSPTLCK , uintptr (unsafe .Pointer (& u )))
124125}
125126
126127// ptsname retrieves the name of the first available pts for the given master.
127128func ptsname (f * os.File ) (string , error ) {
128129 var n int32
129- if err := ioctl (f .Fd (), syscall .TIOCGPTN , uintptr (unsafe .Pointer (& n ))); err != nil {
130+ if err := ioctl (f .Fd (), unix .TIOCGPTN , uintptr (unsafe .Pointer (& n ))); err != nil {
130131 return "" , err
131132 }
132133 return fmt .Sprintf ("/dev/pts/%d" , n ), nil
@@ -139,16 +140,16 @@ func ptsname(f *os.File) (string, error) {
139140// also relay that funky line discipline.
140141func saneTerminal (terminal * os.File ) error {
141142 // Go doesn't have a wrapper for any of the termios ioctls.
142- var termios syscall .Termios
143+ var termios unix .Termios
143144
144- if err := ioctl (terminal .Fd (), syscall .TCGETS , uintptr (unsafe .Pointer (& termios ))); err != nil {
145+ if err := ioctl (terminal .Fd (), unix .TCGETS , uintptr (unsafe .Pointer (& termios ))); err != nil {
145146 return fmt .Errorf ("ioctl(tty, tcgets): %s" , err .Error ())
146147 }
147148
148149 // Set -onlcr so we don't have to deal with \r.
149- termios .Oflag &^= syscall .ONLCR
150+ termios .Oflag &^= unix .ONLCR
150151
151- if err := ioctl (terminal .Fd (), syscall .TCSETS , uintptr (unsafe .Pointer (& termios ))); err != nil {
152+ if err := ioctl (terminal .Fd (), unix .TCSETS , uintptr (unsafe .Pointer (& termios ))); err != nil {
152153 return fmt .Errorf ("ioctl(tty, tcsets): %s" , err .Error ())
153154 }
154155
0 commit comments