@@ -3,8 +3,9 @@ package libcontainer
3
3
import (
4
4
"fmt"
5
5
"os"
6
- "syscall"
7
6
"unsafe"
7
+
8
+ "golang.org/x/sys/unix"
8
9
)
9
10
10
11
func ConsoleFromFile (f * os.File ) Console {
@@ -16,7 +17,7 @@ func ConsoleFromFile(f *os.File) Console {
16
17
// newConsole returns an initialized console that can be used within a container by copying bytes
17
18
// from the master side to the slave that is attached as the tty for the container's init process.
18
19
func 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 )
20
21
if err != nil {
21
22
return nil , err
22
23
}
@@ -68,28 +69,28 @@ func (c *linuxConsole) Close() error {
68
69
// mount initializes the console inside the rootfs mounting with the specified mount label
69
70
// and applying the correct ownership of the console.
70
71
func (c * linuxConsole ) mount () error {
71
- oldMask := syscall .Umask (0000 )
72
- defer syscall .Umask (oldMask )
72
+ oldMask := unix .Umask (0000 )
73
+ defer unix .Umask (oldMask )
73
74
f , err := os .Create ("/dev/console" )
74
75
if err != nil && ! os .IsExist (err ) {
75
76
return err
76
77
}
77
78
if f != nil {
78
79
f .Close ()
79
80
}
80
- return syscall .Mount (c .slavePath , "/dev/console" , "bind" , syscall .MS_BIND , "" )
81
+ return unix .Mount (c .slavePath , "/dev/console" , "bind" , unix .MS_BIND , "" )
81
82
}
82
83
83
84
// dupStdio opens the slavePath for the console and dups the fds to the current
84
85
// processes stdio, fd 0,1,2.
85
86
func (c * linuxConsole ) dupStdio () error {
86
- slave , err := c .open (syscall .O_RDWR )
87
+ slave , err := c .open (unix .O_RDWR )
87
88
if err != nil {
88
89
return err
89
90
}
90
91
fd := int (slave .Fd ())
91
92
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 {
93
94
return err
94
95
}
95
96
}
@@ -98,7 +99,7 @@ func (c *linuxConsole) dupStdio() error {
98
99
99
100
// open is a clone of os.OpenFile without the O_CLOEXEC used to open the pty slave.
100
101
func (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 )
102
103
if e != nil {
103
104
return nil , & os.PathError {
104
105
Op : "open" ,
@@ -110,7 +111,7 @@ func (c *linuxConsole) open(flag int) (*os.File, error) {
110
111
}
111
112
112
113
func 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 {
114
115
return err
115
116
}
116
117
return nil
@@ -120,13 +121,13 @@ func ioctl(fd uintptr, flag, data uintptr) error {
120
121
// unlockpt should be called before opening the slave side of a pty.
121
122
func unlockpt (f * os.File ) error {
122
123
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 )))
124
125
}
125
126
126
127
// ptsname retrieves the name of the first available pts for the given master.
127
128
func ptsname (f * os.File ) (string , error ) {
128
129
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 {
130
131
return "" , err
131
132
}
132
133
return fmt .Sprintf ("/dev/pts/%d" , n ), nil
@@ -139,16 +140,16 @@ func ptsname(f *os.File) (string, error) {
139
140
// also relay that funky line discipline.
140
141
func saneTerminal (terminal * os.File ) error {
141
142
// Go doesn't have a wrapper for any of the termios ioctls.
142
- var termios syscall .Termios
143
+ var termios unix .Termios
143
144
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 {
145
146
return fmt .Errorf ("ioctl(tty, tcgets): %s" , err .Error ())
146
147
}
147
148
148
149
// Set -onlcr so we don't have to deal with \r.
149
- termios .Oflag &^= syscall .ONLCR
150
+ termios .Oflag &^= unix .ONLCR
150
151
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 {
152
153
return fmt .Errorf ("ioctl(tty, tcsets): %s" , err .Error ())
153
154
}
154
155
0 commit comments