@@ -167,6 +167,9 @@ cleanup_private_data (void *private_data)
167
167
if (p -> dev_fds )
168
168
cleanup_close_mapp (& (p -> dev_fds ));
169
169
170
+ if (p -> rootfsfd >= 0 )
171
+ close (p -> rootfsfd );
172
+
170
173
free (p -> unified_cgroup_path );
171
174
free (p -> host_notify_socket_path );
172
175
free (p -> container_notify_socket_path );
@@ -2045,13 +2048,14 @@ get_force_cgroup_v1_annotation (libcrun_container_t *container)
2045
2048
}
2046
2049
2047
2050
static int
2048
- do_mounts (libcrun_container_t * container , int rootfsfd , const char * rootfs , libcrun_error_t * err )
2051
+ do_mounts (libcrun_container_t * container , const char * rootfs , libcrun_error_t * err )
2049
2052
{
2050
2053
size_t i ;
2051
2054
int ret ;
2052
2055
runtime_spec_schema_config_schema * def = container -> container_def ;
2053
2056
const char * systemd_cgroup_v1 = get_force_cgroup_v1_annotation (container );
2054
2057
cleanup_close_map struct libcrun_fd_map * mount_fds = NULL ;
2058
+ int rootfsfd = get_private_data (container )-> rootfsfd ;
2055
2059
2056
2060
mount_fds = get_private_data (container )-> mount_fds ;
2057
2061
get_private_data (container )-> mount_fds = NULL ;
@@ -2576,9 +2580,7 @@ int
2576
2580
libcrun_set_mounts (struct container_entrypoint_s * entrypoint_args , libcrun_container_t * container , const char * rootfs , set_mounts_cb_t cb , void * cb_data , libcrun_error_t * err )
2577
2581
{
2578
2582
runtime_spec_schema_config_schema * def = container -> container_def ;
2579
- cleanup_close int rootfsfd_cleanup = -1 ;
2580
2583
unsigned long rootfs_propagation = 0 ;
2581
- int rootfsfd = -1 ;
2582
2584
int cgroup_mode ;
2583
2585
int is_user_ns = 0 ;
2584
2586
int ret = 0 ;
@@ -2609,12 +2611,12 @@ libcrun_set_mounts (struct container_entrypoint_s *entrypoint_args, libcrun_cont
2609
2611
return ret ;
2610
2612
}
2611
2613
2612
- rootfsfd = rootfsfd_cleanup = open (rootfs , O_PATH | O_CLOEXEC );
2613
- if (UNLIKELY (rootfsfd < 0 ))
2614
+ ret = open (rootfs , O_PATH | O_CLOEXEC );
2615
+ if (UNLIKELY (ret < 0 ))
2614
2616
return crun_make_error (err , errno , "open `%s`" , rootfs );
2615
2617
2618
+ get_private_data (container )-> rootfsfd = ret ;
2616
2619
get_private_data (container )-> rootfs = rootfs ;
2617
- get_private_data (container )-> rootfsfd = rootfsfd ;
2618
2620
2619
2621
// configure handler mounts
2620
2622
ret = libcrun_container_notify_handler (entrypoint_args , HANDLER_CONFIGURE_MOUNTS , container , rootfs , err );
@@ -2627,7 +2629,7 @@ libcrun_set_mounts (struct container_entrypoint_s *entrypoint_args, libcrun_cont
2627
2629
unsigned long remount_flags = MS_REMOUNT | MS_BIND | MS_RDONLY ;
2628
2630
int fd ;
2629
2631
2630
- fd = dup (rootfsfd );
2632
+ fd = dup (get_private_data ( container ) -> rootfsfd );
2631
2633
if (UNLIKELY (fd < 0 ))
2632
2634
return crun_make_error (err , errno , "dup fd for `%s`" , rootfs );
2633
2635
@@ -2655,7 +2657,7 @@ libcrun_set_mounts (struct container_entrypoint_s *entrypoint_args, libcrun_cont
2655
2657
if (UNLIKELY (ret < 0 ))
2656
2658
return ret ;
2657
2659
2658
- ret = do_mounts (container , rootfsfd , rootfs , err );
2660
+ ret = do_mounts (container , rootfs , err );
2659
2661
if (UNLIKELY (ret < 0 ))
2660
2662
return ret ;
2661
2663
@@ -2691,7 +2693,7 @@ libcrun_set_mounts (struct container_entrypoint_s *entrypoint_args, libcrun_cont
2691
2693
libcrun_error_t tmp_err = NULL ;
2692
2694
const char * rel_cwd = consume_slashes (def -> process -> cwd );
2693
2695
/* Ignore errors here and let it fail later. */
2694
- (void ) crun_safe_ensure_directory_at (rootfsfd , rootfs , rel_cwd , 0755 , & tmp_err );
2696
+ (void ) crun_safe_ensure_directory_at (get_private_data ( container ) -> rootfsfd , rootfs , rel_cwd , 0755 , & tmp_err );
2695
2697
crun_error_release (& tmp_err );
2696
2698
}
2697
2699
@@ -2708,7 +2710,7 @@ libcrun_set_mounts (struct container_entrypoint_s *entrypoint_args, libcrun_cont
2708
2710
if (UNLIKELY (ret < 0 ))
2709
2711
return crun_make_error (err , errno , "failed configuring mounts for handler at phase: HANDLER_CONFIGURE_AFTER_MOUNTS" );
2710
2712
2711
- get_private_data (container )-> rootfsfd = -1 ;
2713
+ close_and_reset ( & ( get_private_data (container )-> rootfsfd )) ;
2712
2714
2713
2715
return 0 ;
2714
2716
}
0 commit comments