@@ -135,6 +135,7 @@ func getThisCgroup(cgroupType string) (string, error) {
135
135
// borrowed from docker/utils/utils.go
136
136
// modified to only return the first pid
137
137
// modified to glob with id
138
+ // modified to search for newer docker containers
138
139
func getPidForContainer (id string ) (int , error ) {
139
140
pid := 0
140
141
@@ -153,26 +154,29 @@ func getPidForContainer(id string) (int, error) {
153
154
154
155
id += "*"
155
156
156
- filename := filepath .Join (cgroupRoot , cgroupThis , id , "tasks" )
157
- filenames , _ := filepath .Glob (filename )
158
- if len (filenames ) > 1 {
159
- return pid , fmt .Errorf ("Ambiguous id supplied: %v" , filenames )
160
- } else if len (filenames ) == 1 {
161
- filename = filenames [0 ]
162
- }
163
- if _ , err := os .Stat (filename ); os .IsNotExist (err ) {
157
+ attempts := []string {
158
+ filepath .Join (cgroupRoot , cgroupThis , id , "tasks" ),
164
159
// With more recent lxc versions use, cgroup will be in lxc/
165
- filename = filepath .Join (cgroupRoot , cgroupThis , "lxc" , id , "tasks" )
166
- filenames , _ = filepath .Glob (filename )
160
+ filepath .Join (cgroupRoot , cgroupThis , "lxc" , id , "tasks" ),
161
+ // With more recent dockee, cgroup will be in docker/
162
+ filepath .Join (cgroupRoot , cgroupThis , "docker" , id , "tasks" ),
163
+ }
164
+
165
+ var filename string
166
+ for _ , attempt := range attempts {
167
+ filenames , _ := filepath .Glob (attempt )
167
168
if len (filenames ) > 1 {
168
169
return pid , fmt .Errorf ("Ambiguous id supplied: %v" , filenames )
169
170
} else if len (filenames ) == 1 {
170
171
filename = filenames [0 ]
171
- } else {
172
- return pid , fmt .Errorf ("Unable to find container: %v" , id [:len (id )- 1 ])
172
+ break ;
173
173
}
174
174
}
175
175
176
+ if filename == "" {
177
+ return pid , fmt .Errorf ("Unable to find container: %v" , id [:len (id )- 1 ])
178
+ }
179
+
176
180
output , err := ioutil .ReadFile (filename )
177
181
if err != nil {
178
182
return pid , err
0 commit comments