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.
()
| 930 | // needs to be called after we chroot/pivot into the container's rootfs so that any |
| 931 | // symlinks are resolved locally. |
| 932 | func 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. |
| 957 | func createDevices(rootFd *os.File, config *configs.Config) error { |
no test coverage detected
searching dependent graphs…