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 <jhjeong.kr@gmail.com>

    patch for issue opencontainers#39:
        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
	Also, I refined indentation and added code for slice length check

Signed-off-by: Jin-Hwan Jeong <jhjeong.kr@gmail.com>
  • Loading branch information
jhjeong-kr committed Jul 16, 2015
1 parent 31f23e4 commit a4229ff
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion libcontainer/factory_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,30 @@ 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)
_, runcName := filepath.Split(os.Args[0])
pid, err := ioutil.ReadFile(filepath.Join(containerRoot, "task"))
if err != nil {
return nil, newGenericError(fmt.Errorf("delete the directory: %s", containerRoot), IdInUse)
}
procPath := fmt.Sprintf("/proc/%s/cmdline", pid)
cmdline, err := ioutil.ReadFile(procPath)
if err != nil {
return nil, newGenericError(fmt.Errorf("delete the directory: %s", containerRoot), IdInUse)
}
_, exeName := filepath.Split(string(cmdline))
if len(exeName) >= len(runcName) && exeName[0:len(runcName)] == runcName {
return nil, newGenericError(fmt.Errorf("Container with id exists: %v", id), IdInUse)
}
return nil, newGenericError(fmt.Errorf("Container with id by other cli exists: %v", id), 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 a4229ff

Please sign in to comment.