mirror of
https://github.com/opencontainers/runc.git
synced 2025-10-05 15:37:02 +08:00

Umask is problematic for Go programs as it affects other goroutines (see [1] for more details). Instead of using it, let's just prop up with Chmod. Note this patch misses the MkdirAll call in createDeviceNode. Since the runtime spec does not say anything about creating intermediary directories for device nodes, let's assume that doing it via mkdir with the current umask set is sufficient (if not, we have to reimplement MkdirAll from scratch, with added call to os.Chmod). [1] https://github.com/opencontainers/runc/pull/3563#discussion_r990293788 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
44 lines
984 B
Go
44 lines
984 B
Go
package libcontainer
|
|
|
|
import (
|
|
"os"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// mount initializes the console inside the rootfs mounting with the specified mount label
|
|
// and applying the correct ownership of the console.
|
|
func mountConsole(slavePath string) error {
|
|
f, err := os.Create("/dev/console")
|
|
if err != nil && !os.IsExist(err) {
|
|
return err
|
|
}
|
|
if f != nil {
|
|
// Ensure permission bits (can be different because of umask).
|
|
if err := f.Chmod(0o666); err != nil {
|
|
return err
|
|
}
|
|
f.Close()
|
|
}
|
|
return mount(slavePath, "/dev/console", "bind", unix.MS_BIND, "")
|
|
}
|
|
|
|
// dupStdio opens the slavePath for the console and dups the fds to the current
|
|
// processes stdio, fd 0,1,2.
|
|
func dupStdio(slavePath string) error {
|
|
fd, err := unix.Open(slavePath, unix.O_RDWR, 0)
|
|
if err != nil {
|
|
return &os.PathError{
|
|
Op: "open",
|
|
Path: slavePath,
|
|
Err: err,
|
|
}
|
|
}
|
|
for _, i := range []int{0, 1, 2} {
|
|
if err := unix.Dup3(fd, i, 0); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|