|
7 | 7 | "path/filepath"
|
8 | 8 |
|
9 | 9 | "github.com/opencontainers/runc/libcontainer"
|
| 10 | + "github.com/opencontainers/runc/libcontainer/configs" |
10 | 11 | "github.com/urfave/cli"
|
11 | 12 | )
|
12 | 13 |
|
@@ -58,24 +59,28 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
|
58 | 59 | }
|
59 | 60 | return err
|
60 | 61 | }
|
61 |
| - // When --force is given, we kill all container processes and |
62 |
| - // then destroy the container. This is done even for a stopped |
63 |
| - // container, because (in case it does not have its own PID |
64 |
| - // namespace) there may be some leftover processes in the |
65 |
| - // container's cgroup. |
66 |
| - if force { |
67 |
| - return killContainer(container) |
68 |
| - } |
| 62 | + |
69 | 63 | s, err := container.Status()
|
70 | 64 | if err != nil {
|
71 | 65 | return err
|
72 | 66 | }
|
73 | 67 | switch s {
|
74 | 68 | case libcontainer.Stopped:
|
| 69 | + // For a stopped container, because (in case it does not have |
| 70 | + // its own PID namespace) there may be some leftover processes |
| 71 | + // in the container's cgroup. |
| 72 | + if !container.Config().Namespaces.IsPrivate(configs.NEWPID) { |
| 73 | + return killContainer(container) |
| 74 | + } |
75 | 75 | return container.Destroy()
|
76 | 76 | case libcontainer.Created:
|
77 | 77 | return killContainer(container)
|
78 | 78 | default:
|
| 79 | + // When --force is given, we kill all container processes and |
| 80 | + // then destroy the container. |
| 81 | + if force { |
| 82 | + return killContainer(container) |
| 83 | + } |
79 | 84 | return fmt.Errorf("cannot delete container %s that is not stopped: %s", id, s)
|
80 | 85 | }
|
81 | 86 | },
|
|
0 commit comments