createPidFile creates a file containing the PID, doing so atomically (via create and rename).
(path string, process *libcontainer.Process)
| 160 | // createPidFile creates a file containing the PID, |
| 161 | // doing so atomically (via create and rename). |
| 162 | func 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 | |
| 183 | func createContainer(context *cli.Context, id string, spec *specs.Spec) (*libcontainer.Container, error) { |
| 184 | rootlessCg, err := shouldUseRootlessCgroupManager(context) |