MCPcopy
hub / github.com/containerd/containerd / runInternal

Function runInternal

core/runtime/v2/logging/logging_windows.go:41–109  ·  view source on GitHub ↗
(fn LoggerFunc)

Source from the content-addressed store, hash-verified

39}
40
41func runInternal(fn LoggerFunc) error {
42 ctx, cancel := context.WithCancel(context.Background())
43 defer cancel()
44
45 var (
46 soutPipe, serrPipe, waitPipe string
47 sout, serr, wait net.Conn
48 ok bool
49 err error
50 )
51
52 if soutPipe, ok = os.LookupEnv("CONTAINER_STDOUT"); !ok {
53 return errors.New("'CONTAINER_STDOUT' environment variable missing")
54 }
55 if sout, err = winio.DialPipeContext(ctx, soutPipe); err != nil {
56 return fmt.Errorf("unable to dial stdout pipe: %w", err)
57 }
58
59 if serrPipe, ok = os.LookupEnv("CONTAINER_STDERR"); !ok {
60 return errors.New("'CONTAINER_STDERR' environment variable missing")
61 }
62 if serr, err = winio.DialPipeContext(ctx, serrPipe); err != nil {
63 return fmt.Errorf("unable to dial stderr pipe: %w", err)
64 }
65
66 waitPipe = os.Getenv("CONTAINER_WAIT")
67 if wait, err = winio.DialPipeContext(ctx, waitPipe); err != nil {
68 return fmt.Errorf("unable to dial wait pipe: %w", err)
69 }
70
71 config := &Config{
72 ID: os.Getenv("CONTAINER_ID"),
73 Namespace: os.Getenv("CONTAINER_NAMESPACE"),
74 Stdout: sout,
75 Stderr: serr,
76 }
77
78 var (
79 sigCh = make(chan os.Signal, 2)
80 errCh = make(chan error, 1)
81 )
82
83 signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
84
85 // ready signals the shim that the logging binary is ready for the container to start.
86 // It writes a byte to the wait pipe before closing it - the shim verifies this byte
87 // was received to distinguish between "ready() called" vs "logger crashed".
88 ready := func() error {
89 _, err := wait.Write([]byte{0})
90 if err != nil {
91 wait.Close()
92 return err
93 }
94 return wait.Close()
95 }
96
97 go func() {
98 errCh <- fn(ctx, config, ready)

Callers 1

RunFunction · 0.85

Calls 2

WriteMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…