diff --git a/runtime/v1/linux/proc/io.go b/runtime/v1/linux/proc/io.go index e1bc64623..fde1872c8 100644 --- a/runtime/v1/linux/proc/io.go +++ b/runtime/v1/linux/proc/io.go @@ -103,15 +103,18 @@ func createIO(ctx context.Context, id string, ioUID, ioGID int, stdio proc.Stdio case "binary": pio.io, err = NewBinaryIO(ctx, id, u) case "file": - if err := os.MkdirAll(filepath.Dir(u.Path), 0755); err != nil { + filePath := u.Path + if err := os.MkdirAll(filepath.Dir(filePath), 0755); err != nil { return nil, err } var f *os.File - f, err = os.OpenFile(u.Path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + f, err = os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { return nil, err } f.Close() + pio.stdio.Stdout = filePath + pio.stdio.Stderr = filePath pio.copy = true pio.io, err = runc.NewPipeIO(ioUID, ioGID, withConditionalIO(stdio)) default: @@ -179,10 +182,10 @@ func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, w ) if ok { if fw, err = fifo.OpenFifo(ctx, i.name, syscall.O_WRONLY, 0); err != nil { - return fmt.Errorf("containerd-shim: opening %s failed: %s", i.name, err) + return errors.Wrapf(err, "containerd-shim: opening w/o fifo %q failed", i.name) } if fr, err = fifo.OpenFifo(ctx, i.name, syscall.O_RDONLY, 0); err != nil { - return fmt.Errorf("containerd-shim: opening %s failed: %s", i.name, err) + return errors.Wrapf(err, "containerd-shim: opening r/o fifo %q failed", i.name) } } else { if sameFile != nil { @@ -191,7 +194,7 @@ func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, w continue } if fw, err = os.OpenFile(i.name, syscall.O_WRONLY|syscall.O_APPEND, 0); err != nil { - return fmt.Errorf("containerd-shim: opening %s failed: %s", i.name, err) + return errors.Wrapf(err, "containerd-shim: opening file %q failed", i.name) } if stdout == stderr { sameFile = &countingWriteCloser{