Skip to content

Commit 8daa5c9

Browse files
committed
Add WritePid utility function
Signed-off-by: German Maglione <[email protected]>
1 parent 103abed commit 8daa5c9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/utils/file.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ func ReadPidFile(pidFile string) (int, error) {
2626
return int(pid), nil
2727
}
2828

29+
func WritePidFile(pidFile string, pid int) error {
30+
if pid < 1 {
31+
// We might be running as PID 1 when running docker-in-docker,
32+
// but 0 or negative PIDs are not acceptable.
33+
return fmt.Errorf("invalid negative PID %d", pid)
34+
}
35+
return os.WriteFile(pidFile, []byte(strconv.Itoa(pid)), 0o644)
36+
}
37+
2938
func FileExists(path string) (bool, error) {
3039
_, err := os.Stat(path)
3140
exists := false

0 commit comments

Comments
 (0)