Skip to content

Commit

Permalink
patch for issue opencontainers#39:
Browse files Browse the repository at this point in the history
	runc always shows "container in use" if /var/run/ocf/container exists
	However, there are two cases
		1) case 1: "container in use"
		2) case 2: /var/run/ocf/container still exists after runc was terminated by SIGKILL or abnormal crash
	For case 2, runc should yield "delete the lock dir" instead of "container in use"
	This patch is for this issue using "pid" file in /var/run/ocf/container/task

Signed-off-by: Jin-Hwan Jeong <[email protected]>
  • Loading branch information
jhjeong-kr authored and jhjeong committed Jul 14, 2015
1 parent 31f23e4 commit fe69168
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion libcontainer/factory_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,27 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err
}
containerRoot := filepath.Join(l.Root, id)
if _, err := os.Stat(containerRoot); err == nil {
return nil, newGenericError(fmt.Errorf("Container with id exists: %v", id), IdInUse)
pid, err := ioutil.ReadFile(filepath.Join(containerRoot, "task"))
if err == nil {
procPath := fmt.Sprintf("/proc/%s/cmdline", pid)
if cmdline, err := ioutil.ReadFile(procPath); err == nil {
_, exeName := filepath.Split(string(cmdline))
exeName = exeName[0:4]
if exeName[0:4] == "runc" {
return nil, newGenericError(fmt.Errorf("Container with id exists: %v", id), IdInUse)
}
}
}
return nil, newGenericError(fmt.Errorf("delete the directory: %s", containerRoot), IdInUse)
} else if !os.IsNotExist(err) {
return nil, newGenericError(err, SystemError)
}
if err := os.MkdirAll(containerRoot, 0700); err != nil {
return nil, newGenericError(err, SystemError)
}
if err := ioutil.WriteFile(filepath.Join(containerRoot, "task"), []byte(fmt.Sprintf("%d", os.Getpid())), 0700); err != nil {
return nil, newGenericError(err, SystemError)
}
return &linuxContainer{
id: id,
root: containerRoot,
Expand Down

0 comments on commit fe69168

Please sign in to comment.