Skip to content

Commit 32401ed

Browse files
committed
fix: write runtime PID file when provided
Ensure the PID is written to the runtime-provided --pid-file after container creation. This allows supervisors like conmon to track and reap the container process correctly, preventing early cleanup or EOF failures. This change also ensures that Podman can reliably start urunc containers. Signed-off-by: sidneychang <2190206983@qq.com>
1 parent e2000cf commit 32401ed

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

cmd/urunc/create.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ func createUnikontainer(cmd *cli.Command, uruncCfg *unikontainers.UruncConfig) (
258258
if err != nil {
259259
return err
260260
}
261+
// OCI runtimes are expected to write the PID to the provided pid-file.
262+
// Without it, the supervising runtime cannot track/reap the process and cleanup may fail.
263+
if pidFile := cmd.String("pid-file"); pidFile != "" {
264+
if err := unikontainers.WritePidFile(pidFile, containerPid); err != nil {
265+
return err
266+
}
267+
}
261268

262269
// execute CreateRuntime hooks
263270
err = unikontainer.ExecuteHooks("CreateRuntime")

pkg/unikontainers/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ func loadSpec(bundleDir string) (*specs.Spec, error) {
131131
return &spec, nil
132132
}
133133

134+
// WritePidFile is a public wrapper used by cmd to satisfy OCI pid-file expectations.
135+
func WritePidFile(path string, pid int) error {
136+
return writePidFile(path, pid)
137+
}
138+
134139
// writePidFile writes the content of pid to the file defined by path
135140
func writePidFile(path string, pid int) error {
136141
var (

0 commit comments

Comments
 (0)