MCPcopy Create free account
hub / github.com/containerd/nerdctl / writePidFile

Function writePidFile

pkg/ocihook/ocihook.go:772–792  ·  view source on GitHub ↗

writePidFile writes the pid atomically to a file. From https://github.com/containerd/containerd/blob/v1.7.0-rc.2/cmd/ctr/commands/commands.go#L265-L282

(path string, pid int)

Source from the content-addressed store, hash-verified

770// writePidFile writes the pid atomically to a file.
771// From https://github.com/containerd/containerd/blob/v1.7.0-rc.2/cmd/ctr/commands/commands.go#L265-L282
772func writePidFile(path string, pid int) error {
773 path, err := filepath.Abs(path)
774 if err != nil {
775 return err
776 }
777 dir := filepath.Dir(path)
778 if err := os.MkdirAll(dir, 0755); err != nil {
779 return err
780 }
781 tempPath := filepath.Join(dir, fmt.Sprintf(".%s", filepath.Base(path)))
782 f, err := os.OpenFile(tempPath, os.O_RDWR|os.O_CREATE|os.O_EXCL|os.O_SYNC, 0666)
783 if err != nil {
784 return err
785 }
786 _, err = fmt.Fprint(f, pid)
787 f.Close()
788 if err != nil {
789 return err
790 }
791 return os.Rename(tempPath, path)
792}
793
794func killProcessByPidFile(pidFile string) error {
795 pidData, err := os.ReadFile(pidFile)

Callers 2

newHandlerOptsFunction · 0.85
applyNetworkSettingsFunction · 0.85

Calls 3

DirMethod · 0.65
RenameMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…