The cidfile should be created when the container is created

Currently if you run an interactive session of podman run and
specifiy the --cidfile option, the cidfile will not get created
until the container finishes running.  If you run a detached
container, it will get created right away.  This Patch creates
the cidfile as soon as the container is created.  This could allow
other tools to use the cidefile on all running containers.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2020-10-23 06:58:41 -04:00
parent 8f498b52de
commit 32af1be01a
6 changed files with 33 additions and 43 deletions

View File

@ -638,3 +638,18 @@ func ValidateSysctls(strSlice []string) (map[string]string, error) {
func DefaultContainerConfig() *config.Config {
return containerConfig
}
func CreateCidFile(cidfile string, id string) error {
cidFile, err := OpenExclusiveFile(cidfile)
if err != nil {
if os.IsExist(err) {
return errors.Errorf("container id file exists. Ensure another container is not using it or delete %s", cidfile)
}
return errors.Errorf("error opening cidfile %s", cidfile)
}
if _, err = cidFile.WriteString(id); err != nil {
logrus.Error(err)
}
cidFile.Close()
return nil
}