MCPcopy
hub / github.com/opencontainers/runc / createPidFile

Function createPidFile

utils_linux.go:162–181  ·  view source on GitHub ↗

createPidFile creates a file containing the PID, doing so atomically (via create and rename).

(path string, process *libcontainer.Process)

Source from the content-addressed store, hash-verified

160// createPidFile creates a file containing the PID,
161// doing so atomically (via create and rename).
162func createPidFile(path string, process *libcontainer.Process) error {
163 pid, err := process.Pid()
164 if err != nil {
165 return err
166 }
167 var (
168 tmpDir = filepath.Dir(path)
169 tmpName = filepath.Join(tmpDir, "."+filepath.Base(path))
170 )
171 f, err := os.OpenFile(tmpName, os.O_RDWR|os.O_CREATE|os.O_EXCL|os.O_SYNC, 0o666)
172 if err != nil {
173 return err
174 }
175 _, err = f.WriteString(strconv.Itoa(pid))
176 f.Close()
177 if err != nil {
178 return err
179 }
180 return os.Rename(tmpName, path)
181}
182
183func createContainer(context *cli.Context, id string, spec *specs.Spec) (*libcontainer.Container, error) {
184 rootlessCg, err := shouldUseRootlessCgroupManager(context)

Callers 1

runMethod · 0.85

Calls 2

PidMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…