mirror of
https://github.com/opencontainers/runc.git
synced 2026-04-22 23:17:17 +08:00
fix path error in systemd when stopped
When we use cgroup with systemd driver, the cgroup path will be auto removed by systemd when all processes exited. So we should check cgroup path exists when we access the cgroup path, for example in `kill/ps`, or else we will got an error. Signed-off-by: lifubang <lifubang@acmcoder.com>
This commit is contained in:
@@ -50,6 +50,15 @@ func (m *mockCgroupManager) Destroy() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockCgroupManager) Exists() bool {
|
||||
paths := m.GetPaths()
|
||||
if paths != nil {
|
||||
_, err := os.Lstat(paths["devices"])
|
||||
return err == nil
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *mockCgroupManager) GetPaths() map[string]string {
|
||||
return m.paths
|
||||
}
|
||||
@@ -134,11 +143,27 @@ func (m *mockProcess) forwardChildLogs() {
|
||||
}
|
||||
|
||||
func TestGetContainerPids(t *testing.T) {
|
||||
container := &linuxContainer{
|
||||
id: "myid",
|
||||
config: &configs.Config{},
|
||||
cgroupManager: &mockCgroupManager{allPids: []int{1, 2, 3}},
|
||||
pid := 1
|
||||
stat, err := system.Stat(pid)
|
||||
if err != nil {
|
||||
t.Fatalf("can't stat pid %d, got %v", pid, err)
|
||||
}
|
||||
container := &linuxContainer{
|
||||
id: "myid",
|
||||
config: &configs.Config{},
|
||||
cgroupManager: &mockCgroupManager{
|
||||
allPids: []int{1, 2, 3},
|
||||
paths: map[string]string{
|
||||
"device": "/proc/self/cgroups",
|
||||
},
|
||||
},
|
||||
initProcess: &mockProcess{
|
||||
_pid: 1,
|
||||
started: 10,
|
||||
},
|
||||
initProcessStartTime: stat.StartTime,
|
||||
}
|
||||
container.state = &runningState{c: container}
|
||||
pids, err := container.Processes()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user