File tree Expand file tree Collapse file tree 1 file changed +7
-15
lines changed
crates/libcontainer/src/process Expand file tree Collapse file tree 1 file changed +7
-15
lines changed Original file line number Diff line number Diff line change @@ -250,26 +250,18 @@ fn move_network_devices_to_container(
250
250
) -> Result < ( ) > {
251
251
if let Some ( namespaces) = linux. namespaces ( ) {
252
252
// network devices are not moved for containers running in the host network.
253
- if ! namespaces
253
+ let net_ns = match namespaces
254
254
. iter ( )
255
- . any ( |ns| ns. typ ( ) == LinuxNamespaceType :: Network )
255
+ . find ( |ns| ns. typ ( ) == LinuxNamespaceType :: Network )
256
256
{
257
- return Ok ( ( ) ) ;
258
- }
257
+ Some ( ns) => ns,
258
+ None => return Ok ( ( ) ) ,
259
+ } ;
259
260
260
261
// the container init process has already joined the provided net namespace,
261
262
// so we can use the process's net ns path directly.
262
263
let default_ns_path = PathBuf :: from ( format ! ( "/proc/{}/ns/net" , init_pid. as_raw( ) ) ) ;
263
- let ns_path = namespaces
264
- . iter ( )
265
- . find_map ( |ns| {
266
- if ns. typ ( ) == LinuxNamespaceType :: Network {
267
- ns. path ( ) . as_deref ( )
268
- } else {
269
- None
270
- }
271
- } )
272
- . unwrap_or_else ( || & default_ns_path) ;
264
+ let ns_path = net_ns. path ( ) . as_deref ( ) . unwrap_or ( & default_ns_path) ;
273
265
274
266
// If moving any of the network devices fails, we return an error immediately.
275
267
// The runtime spec requires that the kernel handles moving back any devices
@@ -281,7 +273,7 @@ fn move_network_devices_to_container(
281
273
. iter ( )
282
274
. map ( |( name, net_dev) | {
283
275
let addrs =
284
- dev_change_net_namespace ( name, & ns_path, net_dev) . map_err ( |err| {
276
+ dev_change_net_namespace ( name, ns_path, net_dev) . map_err ( |err| {
285
277
tracing:: error!( "failed to dev_change_net_namespace: {}" , err) ;
286
278
err
287
279
} ) ?;
You can’t perform that action at this time.
0 commit comments