@@ -6,13 +6,12 @@ import (
6
6
"errors"
7
7
"fmt"
8
8
"os"
9
- "path/filepath "
9
+ "strconv "
10
10
"time"
11
11
12
12
"github.com/hashicorp/go-hclog"
13
13
"github.com/opencontainers/runc/libcontainer/cgroups"
14
14
"github.com/opencontainers/runc/libcontainer/cgroups/fs"
15
- "github.com/opencontainers/runc/libcontainer/cgroups/fs2"
16
15
"github.com/opencontainers/runc/libcontainer/configs"
17
16
)
18
17
@@ -96,56 +95,24 @@ func (d *killer) v1(cgroup *configs.Cgroup) error {
96
95
}
97
96
98
97
func (d * killer ) v2 (cgroup * configs.Cgroup ) error {
99
- if cgroup == nil {
98
+ if cgroup == nil || cgroup . Path == "" {
100
99
return errors .New ("missing cgroup" )
101
100
}
102
101
103
- path := filepath .Join (CgroupRoot , cgroup .Path )
104
-
105
- existingPIDs , err := cgroups .GetPids (path )
106
- if err != nil {
107
- return fmt .Errorf ("failed to determine pids in cgroup: %w" , err )
108
- }
109
-
110
- d .logger .Trace ("killing processes" , "cgroup_path" , path , "cgroup_version" , "v2" , "executor_pid" , d .pid , "existing_pids" , existingPIDs )
111
-
112
- mgr , err := fs2 .NewManager (cgroup , "" , rootless )
113
- if err != nil {
114
- return fmt .Errorf ("failed to create v2 cgroup manager: %w" , err )
115
- }
116
-
117
- // move executor PID into the root init.scope so we can kill the task pids
118
- // without killing the executor (which is the process running this code, doing
119
- // the killing)
120
- init , err := fs2 .NewManager (nil , filepath .Join (CgroupRoot , "init.scope" ), rootless )
121
- if err != nil {
122
- return fmt .Errorf ("failed to create v2 init cgroup manager: %w" , err )
123
- }
124
- if err = init .Apply (d .pid ); err != nil {
125
- return fmt .Errorf ("failed to move executor pid into init.scope cgroup: %w" , err )
126
- }
127
-
128
- d .logger .Trace ("move of executor pid into init.scope complete" , "pid" , d .pid )
129
-
130
- // ability to freeze the cgroup
131
- freeze := func () {
132
- _ = mgr .Freeze (configs .Frozen )
133
- }
134
-
135
- // ability to thaw the cgroup
136
- thaw := func () {
137
- _ = mgr .Freeze (configs .Thawed )
102
+ // move executor (d.PID) into init.scope
103
+ editSelf := & editor {"init.scope" }
104
+ if err := editSelf .write ("cgroup.procs" , strconv .Itoa (d .pid )); err != nil {
105
+ return err
138
106
}
139
107
140
- // do the common kill logic
141
-
142
- if err = d . kill ( path , freeze , thaw ); err != nil {
108
+ // write "1" to cgroup. kill
109
+ editTask := & editor { cgroup . Path }
110
+ if err := editTask . write ( "cgroup.kill" , "1" ); err != nil {
143
111
return err
144
112
}
145
113
146
- // note: do NOT remove the cgroup from disk; leave that to the alloc-level
147
- // cpuset mananager.
148
-
114
+ // note: do NOT remove the cgroup from disk; leave that to the Client, at
115
+ // least until #14375 is implemented.
149
116
return nil
150
117
}
151
118
0 commit comments