mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
never send procError after the socket closed
Signed-off-by: lifubang <lifubang@acmcoder.com>
This commit is contained in:
@@ -107,7 +107,11 @@ func startInitialization() (retErr error) {
|
||||
|
||||
defer func() {
|
||||
// If this defer is ever called, this means initialization has failed.
|
||||
// Send the error back to the parent process in the form of an initError.
|
||||
// Send the error back to the parent process in the form of an initError
|
||||
// if the sync socket has not been closed.
|
||||
if syncPipe.isClosed() {
|
||||
return
|
||||
}
|
||||
ierr := initError{Message: retErr.Error()}
|
||||
if err := writeSyncArg(syncPipe, procError, ierr); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"sync/atomic"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
@@ -14,7 +15,8 @@ import (
|
||||
// which ends up making things like json.Decoder hang forever if the packet is
|
||||
// bigger than the internal read buffer.
|
||||
type syncSocket struct {
|
||||
f *os.File
|
||||
f *os.File
|
||||
closed atomic.Bool
|
||||
}
|
||||
|
||||
func newSyncSocket(f *os.File) *syncSocket {
|
||||
@@ -26,9 +28,15 @@ func (s *syncSocket) File() *os.File {
|
||||
}
|
||||
|
||||
func (s *syncSocket) Close() error {
|
||||
// Even with errors from Close(), we have to assume the pipe was closed.
|
||||
s.closed.Store(true)
|
||||
return s.f.Close()
|
||||
}
|
||||
|
||||
func (s *syncSocket) isClosed() bool {
|
||||
return s.closed.Load()
|
||||
}
|
||||
|
||||
func (s *syncSocket) WritePacket(b []byte) (int, error) {
|
||||
return s.f.Write(b)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user