Skip to content

Commit 174c490

Browse files
committed
Fix shim's file IO logging
Signed-off-by: Maksym Pavlenko <[email protected]>
1 parent b88362f commit 174c490

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

  • runtime/v1/linux/proc

runtime/v1/linux/proc/io.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,18 @@ func createIO(ctx context.Context, id string, ioUID, ioGID int, stdio proc.Stdio
103103
case "binary":
104104
pio.io, err = NewBinaryIO(ctx, id, u)
105105
case "file":
106-
if err := os.MkdirAll(filepath.Dir(u.Path), 0755); err != nil {
106+
filePath := u.Path
107+
if err := os.MkdirAll(filepath.Dir(filePath), 0755); err != nil {
107108
return nil, err
108109
}
109110
var f *os.File
110-
f, err = os.OpenFile(u.Path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
111+
f, err = os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
111112
if err != nil {
112113
return nil, err
113114
}
114115
f.Close()
116+
pio.stdio.Stdout = filePath
117+
pio.stdio.Stderr = filePath
115118
pio.copy = true
116119
pio.io, err = runc.NewPipeIO(ioUID, ioGID, withConditionalIO(stdio))
117120
default:
@@ -179,10 +182,10 @@ func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, w
179182
)
180183
if ok {
181184
if fw, err = fifo.OpenFifo(ctx, i.name, syscall.O_WRONLY, 0); err != nil {
182-
return fmt.Errorf("containerd-shim: opening %s failed: %s", i.name, err)
185+
return errors.Wrapf(err, "containerd-shim: opening w/o fifo %q failed", i.name)
183186
}
184187
if fr, err = fifo.OpenFifo(ctx, i.name, syscall.O_RDONLY, 0); err != nil {
185-
return fmt.Errorf("containerd-shim: opening %s failed: %s", i.name, err)
188+
return errors.Wrapf(err, "containerd-shim: opening r/o fifo %q failed", i.name)
186189
}
187190
} else {
188191
if sameFile != nil {
@@ -191,7 +194,7 @@ func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, w
191194
continue
192195
}
193196
if fw, err = os.OpenFile(i.name, syscall.O_WRONLY|syscall.O_APPEND, 0); err != nil {
194-
return fmt.Errorf("containerd-shim: opening %s failed: %s", i.name, err)
197+
return errors.Wrapf(err, "containerd-shim: opening file %q failed", i.name)
195198
}
196199
if stdout == stderr {
197200
sameFile = &countingWriteCloser{

0 commit comments

Comments
 (0)