Skip to content

Commit 335add4

Browse files
sidneychangurunc-bot[bot]
authored andcommitted
fix: write runtime PID file when provided
Ensure the PID is written to the runtime-provided --pid-file after container creation. This allows supervisors 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. PR: #439 Signed-off-by: sidneychang <2190206983@qq.com> Reviewed-by: Charalampos Mainas <cmainas@nubificus.co.uk> Approved-by: Charalampos Mainas <cmainas@nubificus.co.uk>
1 parent d5178ae commit 335add4

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎cmd/urunc/create.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,10 @@ func createUnikontainer(cmd *cli.Command, uruncCfg *unikontainers.UruncConfig) (
252252

253253
// Retrieve reexec cmd's pid and write to file and state
254254
containerPid := reexecPid
255+
pidFilePath := cmd.String("pid-file")
255256
metrics.Capture(m.TS06)
256257

257-
err = unikontainer.Create(containerPid)
258+
err = unikontainer.Create(containerPid, pidFilePath)
258259
if err != nil {
259260
return err
260261
}

‎pkg/unikontainers/unikontainers.go‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,14 @@ func (u *Unikontainer) InitialSetup() error {
147147
}
148148

149149
// Create sets the Unikernel status as created,
150-
// and saves the given PID in init.pid
151-
func (u *Unikontainer) Create(pid int) error {
152-
err := writePidFile(filepath.Join(u.State.Bundle, initPidFilename), pid)
150+
// and saves the given PID in the provided pid file path.
151+
// If pidFilePath is empty, it falls back to the default init.pid path.
152+
func (u *Unikontainer) Create(pid int, pidFilePath string) error {
153+
path := filepath.Join(u.State.Bundle, initPidFilename)
154+
if pidFilePath != "" {
155+
path = pidFilePath
156+
}
157+
err := writePidFile(path, pid)
153158
if err != nil {
154159
return err
155160
}

0 commit comments

Comments
 (0)