Skip to content

Commit

Permalink
pillar: containerd: Create a pipe for container's stdin
Browse files Browse the repository at this point in the history
Currently the device /dev/null is used as the standard input for a
container task. However, any process reading from /dev/null will always get
0 bytes as the result, which makes interactive containers, e.g., those that
runs a shell as the entrypoint (and expects data on the standard input), to
exit right after starting. In order to keep the container task blocked (in
these situations), a valid standard input device must be provided.  This
commit creates a fake stdin that reads from an unpopulated pipe so it
blocks the reader process.

Signed-off-by: Renê de Souza Pinto <rene@renesp.com.br>
  • Loading branch information
rene authored and OhmSpectator committed Sep 11, 2024
1 parent 39739ff commit 9a29580
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions pkg/pillar/containerd/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,19 +481,23 @@ func (client *Client) CtrContainerInfo(ctx context.Context, name string) (int, i
func (client *Client) CtrLogIOCreator(domainName string) cio.Creator {
logger := GetLog()

io := func(id string) (cio.IO, error) {
stdoutFile := logger.Path("guest_vm-" + domainName)
stderrFile := logger.Path("guest_vm_err-" + domainName)
return &logio{
cio.Config{
Stdin: "/dev/null",
Stdout: stdoutFile,
Stderr: stderrFile,
Terminal: false,
},
}, nil
// Create the named pipes for stdout and stderr
stdoutFile := logger.Path("guest_vm-" + domainName)
stderrFile := logger.Path("guest_vm_err-" + domainName)
pipeStdout, err := os.OpenFile(stdoutFile, os.O_WRONLY, 0)
if err != nil {
logrus.Errorf("CtrLogIOCreator: Error opening file %s with: %s", stdoutFile, err)
}
pipeStderr, err := os.OpenFile(stderrFile, os.O_WRONLY, 0)
if err != nil {
logrus.Errorf("CtrLogIOCreator: Error opening file %s with: %s", stderrFile, err)
}

// Create a fake stdin, so we won't break any interactive application
fakeStdin, _ := io.Pipe()

io := cio.NewCreator(cio.WithStreams(fakeStdin, pipeStdout, pipeStderr))

return io
}

Expand Down

0 comments on commit 9a29580

Please sign in to comment.