Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions libcontainer/factory_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,35 @@ func (l *LinuxFactory) StartInitialization() (err error) {
if err != nil {
return err
}
flushReadPipe(pipefd)
return i.Init()
}

func fd_set(p *syscall.FdSet, i int) {
p.Bits[i/64] |= 1 << uint(i) % 64
}

func fd_isset(p *syscall.FdSet, i int) bool {
return (p.Bits[i/64] & (1 << uint(i) % 64)) != 0
}

// flushReadPipe ensures that all data has been read from the pipe to ensure the
// parent does not get an ECONNRESET after the pipe is closed.
func flushReadPipe(pipefd int) {
rfds := &syscall.FdSet{}
timeout := &syscall.Timeval{}

fd_set(rfds, pipefd)
_, err := syscall.Select(pipefd+1, rfds, nil, nil, timeout)
if err != nil {
return
}

if fd_isset(rfds, pipefd) {
syscall.Read(pipefd, make([]byte, 256))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really, this should probably just read 1 byte, since we're only potentially expecting to see 1 additional byte (the newline) in the pipe.

}
}

func (l *LinuxFactory) loadState(root string) (*State, error) {
f, err := os.Open(filepath.Join(root, stateFilename))
if err != nil {
Expand Down