MCPcopy
hub / github.com/opencontainers/runc / reOpenDevNull

Function reOpenDevNull

libcontainer/rootfs_linux.go:932–954  ·  view source on GitHub ↗

If stdin, stdout, and/or stderr are pointing to `/dev/null` in the parent's rootfs this method will make them point to `/dev/null` in this container's rootfs. This needs to be called after we chroot/pivot into the container's rootfs so that any symlinks are resolved locally.

()

Source from the content-addressed store, hash-verified

930// needs to be called after we chroot/pivot into the container's rootfs so that any
931// symlinks are resolved locally.
932func reOpenDevNull() error {
933 file, err := os.OpenFile("/dev/null", os.O_RDWR, 0)
934 if err != nil {
935 return err
936 }
937 defer file.Close()
938 if err := verifyDevNull(file); err != nil {
939 return fmt.Errorf("can't reopen /dev/null: %w", err)
940 }
941 for fd := range 3 {
942 var stat unix.Stat_t
943 if err := unix.Fstat(fd, &stat); err != nil {
944 return &os.PathError{Op: "fstat", Path: "fd " + strconv.Itoa(fd), Err: err}
945 }
946 if isDevNull(&stat) {
947 // Close and re-open the fd.
948 if err := linux.Dup3(int(file.Fd()), fd, 0); err != nil {
949 return err
950 }
951 }
952 }
953 return nil
954}
955
956// Create the device nodes in the container.
957func createDevices(rootFd *os.File, config *configs.Config) error {

Callers 1

prepareRootfsFunction · 0.85

Calls 4

Dup3Function · 0.92
verifyDevNullFunction · 0.85
isDevNullFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…