@@ -140,8 +140,6 @@ struct ProcessTracker {
140
140
rx : mpsc:: UnboundedReceiver < TrackerRequest > ,
141
141
/// current processes
142
142
processes : HashMap < Pid , ProcessData > ,
143
- /// current containers
144
- containers : HashMap < Namespaces , ContainerInfo > ,
145
143
/// scheduled removal of exited processes
146
144
next_cleanup : Timestamp ,
147
145
/// pending info requests arrived before the process was created
@@ -162,6 +160,7 @@ struct ProcessData {
162
160
> ,
163
161
argv : Vec < String > ,
164
162
namespaces : Namespaces ,
163
+ container : Option < ContainerInfo > ,
165
164
}
166
165
167
166
/// Cleanup timeout in nanoseconds. This is how long an exited process
@@ -186,12 +185,12 @@ impl ProcessTracker {
186
185
exec_changes : BTreeMap :: new ( ) ,
187
186
argv : Vec :: new ( ) ,
188
187
namespaces : Namespaces :: default ( ) ,
188
+ container : None ,
189
189
} ,
190
190
) ;
191
191
Self {
192
192
rx,
193
193
processes,
194
- containers : HashMap :: new ( ) ,
195
194
next_cleanup : Timestamp :: now ( ) + CLEANUP_TIMEOUT ,
196
195
pending_requests : Vec :: new ( ) ,
197
196
pending_updates : HashMap :: new ( ) ,
@@ -263,25 +262,24 @@ impl ProcessTracker {
263
262
}
264
263
}
265
264
266
- fn handle_container_info (
265
+ fn get_container_info (
267
266
& mut self ,
268
267
pid : Pid ,
269
- namespaces : Namespaces ,
270
268
is_new_container : bool ,
271
- ) -> Result < ( ) , ContainerError > {
269
+ ) -> Result < Option < ContainerInfo > , ContainerError > {
272
270
let container_id = procfs:: get_process_container_id ( pid) ?;
273
- if let Some ( id ) = container_id {
274
- let container_info = ContainerInfo :: from_container_id ( id. clone ( ) ) ? ;
275
- self . containers . entry ( namespaces ) . or_insert_with ( || {
271
+ match container_id {
272
+ Some ( id) => {
273
+ let container_info = ContainerInfo :: from_container_id ( id . clone ( ) ) ? ;
276
274
if is_new_container {
277
275
log:: debug!( "Detected a new container {id}" ) ;
278
276
} else {
279
277
log:: debug!( "Detected an already existing container {id}" ) ;
280
278
}
281
- container_info
282
- } ) ;
279
+ Ok ( Some ( container_info) )
280
+ }
281
+ None => Ok ( None ) ,
283
282
}
284
- Ok ( ( ) )
285
283
}
286
284
287
285
fn handle_update ( & mut self , mut update : TrackerUpdate ) {
@@ -293,8 +291,13 @@ impl ProcessTracker {
293
291
namespaces,
294
292
is_new_container,
295
293
} => {
296
- self . handle_container_info ( pid, namespaces, is_new_container)
297
- . unwrap_or_else ( |err| log:: error!( "{err}" ) ) ;
294
+ let container = match self . get_container_info ( pid, is_new_container) {
295
+ Ok ( container) => container,
296
+ Err ( err) => {
297
+ log:: error!( "{err}" ) ;
298
+ None
299
+ }
300
+ } ;
298
301
self . processes . insert (
299
302
pid,
300
303
ProcessData {
@@ -309,6 +312,7 @@ impl ProcessTracker {
309
312
. map ( |parent| parent. argv . clone ( ) )
310
313
. unwrap_or_default ( ) ,
311
314
namespaces,
315
+ container,
312
316
} ,
313
317
) ;
314
318
if let Some ( pending_updates) = self . pending_updates . remove ( & pid) {
@@ -325,11 +329,18 @@ impl ProcessTracker {
325
329
namespaces,
326
330
is_new_container,
327
331
} => {
328
- self . handle_container_info ( pid, namespaces, is_new_container)
329
- . unwrap_or_else ( |err| log:: error!( "{err}" ) ) ;
332
+ let container = match self . get_container_info ( pid, is_new_container) {
333
+ Ok ( container) => container,
334
+ Err ( err) => {
335
+ log:: error!( "{err}" ) ;
336
+ None
337
+ }
338
+ } ;
330
339
if let Some ( p) = self . processes . get_mut ( & pid) {
331
340
p. exec_changes . insert ( timestamp, std:: mem:: take ( image) ) ;
332
- p. argv = std:: mem:: take ( argv)
341
+ p. argv = std:: mem:: take ( argv) ;
342
+ p. namespaces = namespaces;
343
+ p. container = container;
333
344
} else {
334
345
// if exec arrived before the fork, we save the event as pending
335
346
log:: debug!( "(exec) Process {pid} not found in process tree, saving for later" ) ;
@@ -360,7 +371,6 @@ impl ProcessTracker {
360
371
. processes
361
372
. get ( & pid)
362
373
. ok_or ( TrackerError :: ProcessNotFound ) ?;
363
- let container: Option < ContainerInfo > = self . containers . get ( & process. namespaces ) . cloned ( ) ;
364
374
if ts < process. fork_time {
365
375
log:: warn!(
366
376
"{} not forked yet {} < {} ({}ms)" ,
@@ -383,7 +393,7 @@ impl ProcessTracker {
383
393
fork_time : process. fork_time ,
384
394
argv : process. argv . clone ( ) ,
385
395
namespaces : process. namespaces ,
386
- container,
396
+ container : process . container . clone ( ) ,
387
397
} )
388
398
}
389
399
0 commit comments