@@ -1030,7 +1030,6 @@ do_masked_or_readonly_path (libcrun_container_t *container, const char *rel_path
1030
1030
{
1031
1031
unsigned long mount_flags = 0 ;
1032
1032
const char * rootfs = get_private_data (container )-> rootfs ;
1033
- int rootfsfd = get_private_data (container )-> rootfsfd ;
1034
1033
cleanup_close int pathfd = -1 ;
1035
1034
struct statfs sfs ;
1036
1035
int ret ;
@@ -1039,7 +1038,7 @@ do_masked_or_readonly_path (libcrun_container_t *container, const char *rel_path
1039
1038
if (rel_path [0 ] == '/' )
1040
1039
rel_path ++ ;
1041
1040
1042
- pathfd = safe_openat (rootfsfd , rootfs , rel_path , O_PATH | O_CLOEXEC , 0 , err );
1041
+ pathfd = safe_openat (get_private_data ( container ) -> rootfsfd , rootfs , rel_path , O_PATH | O_CLOEXEC , 0 , err );
1043
1042
if (UNLIKELY (pathfd < 0 ))
1044
1043
{
1045
1044
if (errno != ENOENT && errno != EACCES )
@@ -1588,7 +1587,6 @@ libcrun_create_dev (libcrun_container_t *container, int devfd, int srcfd,
1588
1587
mode_t type = (device -> type [0 ] == 'b' ) ? S_IFBLK : ((device -> type [0 ] == 'p' ) ? S_IFIFO : S_IFCHR );
1589
1588
const char * fullname = device -> path ;
1590
1589
cleanup_close int fd = -1 ;
1591
- int rootfsfd = get_private_data (container )-> rootfsfd ;
1592
1590
const char * rootfs = get_private_data (container )-> rootfs ;
1593
1591
if (is_empty_string (fullname ))
1594
1592
return crun_make_error (err , EINVAL , "device path is empty" );
@@ -1619,7 +1617,7 @@ libcrun_create_dev (libcrun_container_t *container, int devfd, int srcfd,
1619
1617
{
1620
1618
const char * rel_path = consume_slashes (normalized_path );
1621
1619
1622
- fd = crun_safe_create_and_open_ref_at (false, rootfsfd , rootfs , rel_path , 0755 , err );
1620
+ fd = crun_safe_create_and_open_ref_at (false, get_private_data ( container ) -> rootfsfd , rootfs , rel_path , 0755 , err );
1623
1621
if (UNLIKELY (fd < 0 ))
1624
1622
return fd ;
1625
1623
}
@@ -1684,18 +1682,18 @@ libcrun_create_dev (libcrun_container_t *container, int devfd, int srcfd,
1684
1682
1685
1683
if (dirname [0 ] == '\0' )
1686
1684
{
1687
- dirfd = dup (rootfsfd );
1685
+ dirfd = dup (get_private_data ( container ) -> rootfsfd );
1688
1686
if (UNLIKELY (dirfd < 0 ))
1689
1687
return crun_make_error (err , errno , "dup fd for `%s`" , rootfs );
1690
1688
}
1691
1689
else
1692
1690
{
1693
- dirfd = safe_openat (rootfsfd , rootfs , dirname , O_DIRECTORY | O_PATH | O_CLOEXEC , 0 , err );
1691
+ dirfd = safe_openat (get_private_data ( container ) -> rootfsfd , rootfs , dirname , O_DIRECTORY | O_PATH | O_CLOEXEC , 0 , err );
1694
1692
if (dirfd < 0 && ensure_parent_dir )
1695
1693
{
1696
1694
crun_error_release (err );
1697
1695
1698
- dirfd = crun_safe_create_and_open_ref_at (true, rootfsfd , rootfs , dirname , 0755 , err );
1696
+ dirfd = crun_safe_create_and_open_ref_at (true, get_private_data ( container ) -> rootfsfd , rootfs , dirname , 0755 , err );
1699
1697
}
1700
1698
if (UNLIKELY (dirfd < 0 ))
1701
1699
return dirfd ;
@@ -1751,13 +1749,12 @@ create_missing_devs (libcrun_container_t *container, bool binds, libcrun_error_t
1751
1749
cleanup_close int devfd = -1 ;
1752
1750
runtime_spec_schema_config_schema * def = container -> container_def ;
1753
1751
const char * rootfs = get_private_data (container )-> rootfs ;
1754
- int rootfsfd = get_private_data (container )-> rootfsfd ;
1755
1752
cleanup_close_map struct libcrun_fd_map * dev_fds = NULL ;
1756
1753
1757
1754
dev_fds = get_private_data (container )-> dev_fds ;
1758
1755
get_private_data (container )-> dev_fds = NULL ;
1759
1756
1760
- devfd = openat (rootfsfd , "dev" , O_CLOEXEC | O_PATH | O_DIRECTORY );
1757
+ devfd = openat (get_private_data ( container ) -> rootfsfd , "dev" , O_CLOEXEC | O_PATH | O_DIRECTORY );
1761
1758
if (UNLIKELY (devfd < 0 ))
1762
1759
return crun_make_error (err , errno , "open `/dev` directory in `%s`" , rootfs );
1763
1760
@@ -1912,7 +1909,6 @@ static int
1912
1909
append_tmpfs_mode_if_missing (libcrun_container_t * container , runtime_spec_schema_defs_mount * mount , char * * data , libcrun_error_t * err )
1913
1910
{
1914
1911
const char * rootfs = get_private_data (container )-> rootfs ;
1915
- int rootfsfd = get_private_data (container )-> rootfsfd ;
1916
1912
bool empty_data = is_empty_string (* data );
1917
1913
cleanup_close int fd = -1 ;
1918
1914
struct stat st ;
@@ -1921,7 +1917,7 @@ append_tmpfs_mode_if_missing (libcrun_container_t *container, runtime_spec_schem
1921
1917
if (* data != NULL && strstr (* data , "mode=" ))
1922
1918
return 0 ;
1923
1919
1924
- fd = safe_openat (rootfsfd , rootfs , mount -> destination , O_CLOEXEC | O_RDONLY , 0 , err );
1920
+ fd = safe_openat (get_private_data ( container ) -> rootfsfd , rootfs , mount -> destination , O_CLOEXEC | O_RDONLY , 0 , err );
1925
1921
if (fd < 0 )
1926
1922
{
1927
1923
if (crun_error_get_errno (err ) != ENOENT )
@@ -2050,12 +2046,11 @@ get_force_cgroup_v1_annotation (libcrun_container_t *container)
2050
2046
static int
2051
2047
do_mounts (libcrun_container_t * container , const char * rootfs , libcrun_error_t * err )
2052
2048
{
2053
- size_t i ;
2054
- int ret ;
2055
2049
runtime_spec_schema_config_schema * def = container -> container_def ;
2056
2050
const char * systemd_cgroup_v1 = get_force_cgroup_v1_annotation (container );
2057
2051
cleanup_close_map struct libcrun_fd_map * mount_fds = NULL ;
2058
- int rootfsfd = get_private_data (container )-> rootfsfd ;
2052
+ size_t i ;
2053
+ int ret ;
2059
2054
2060
2055
mount_fds = get_private_data (container )-> mount_fds ;
2061
2056
get_private_data (container )-> mount_fds = NULL ;
@@ -2137,7 +2132,7 @@ do_mounts (libcrun_container_t *container, const char *rootfs, libcrun_error_t *
2137
2132
if (UNLIKELY (len < 0 ))
2138
2133
return len ;
2139
2134
2140
- ret = safe_create_symlink (rootfsfd , rootfs , target , def -> mounts [i ]-> destination , err );
2135
+ ret = safe_create_symlink (get_private_data ( container ) -> rootfsfd , rootfs , target , def -> mounts [i ]-> destination , err );
2141
2136
if (UNLIKELY (ret < 0 ))
2142
2137
return ret ;
2143
2138
@@ -2146,20 +2141,20 @@ do_mounts (libcrun_container_t *container, const char *rootfs, libcrun_error_t *
2146
2141
else if (is_sysfs_or_proc )
2147
2142
{
2148
2143
/* Enforce sysfs and proc to be mounted on a regular directory. */
2149
- ret = openat (rootfsfd , target , O_CLOEXEC | O_NOFOLLOW | O_DIRECTORY );
2144
+ ret = openat (get_private_data ( container ) -> rootfsfd , target , O_CLOEXEC | O_NOFOLLOW | O_DIRECTORY );
2150
2145
if (UNLIKELY (ret < 0 ))
2151
2146
{
2152
2147
if (errno == ENOENT )
2153
2148
{
2154
2149
if (strchr (target , '/' ))
2155
2150
return crun_make_error (err , 0 , "invalid target `%s`: it must be mounted at the root" , target );
2156
2151
2157
- ret = mkdirat (rootfsfd , target , 0755 );
2152
+ ret = mkdirat (get_private_data ( container ) -> rootfsfd , target , 0755 );
2158
2153
if (UNLIKELY (ret < 0 ))
2159
2154
return crun_make_error (err , errno , "mkdirat `%s`" , target );
2160
2155
2161
2156
/* Try opening it again. */
2162
- ret = openat (rootfsfd , target , O_CLOEXEC | O_NOFOLLOW | O_DIRECTORY );
2157
+ ret = openat (get_private_data ( container ) -> rootfsfd , target , O_CLOEXEC | O_NOFOLLOW | O_DIRECTORY );
2163
2158
}
2164
2159
else if (errno == ENOTDIR )
2165
2160
return crun_make_error (err , errno , "the target `/%s` is invalid" , target );
@@ -2175,7 +2170,7 @@ do_mounts (libcrun_container_t *container, const char *rootfs, libcrun_error_t *
2175
2170
bool is_dir = S_ISDIR (src_mode );
2176
2171
2177
2172
/* Make sure any other directory/file is created and take a O_PATH reference to it. */
2178
- ret = crun_safe_create_and_open_ref_at (is_dir , rootfsfd , rootfs , target , is_dir ? 01755 : 0755 , err );
2173
+ ret = crun_safe_create_and_open_ref_at (is_dir , get_private_data ( container ) -> rootfsfd , rootfs , target , is_dir ? 01755 : 0755 , err );
2179
2174
if (UNLIKELY (ret < 0 ))
2180
2175
return ret ;
2181
2176
@@ -2248,7 +2243,7 @@ do_mounts (libcrun_container_t *container, const char *rootfs, libcrun_error_t *
2248
2243
{
2249
2244
int destfd , tmpfd ;
2250
2245
2251
- destfd = safe_openat (rootfsfd , rootfs , target , O_CLOEXEC | O_DIRECTORY , 0 , err );
2246
+ destfd = safe_openat (get_private_data ( container ) -> rootfsfd , rootfs , target , O_CLOEXEC | O_DIRECTORY , 0 , err );
2252
2247
if (UNLIKELY (destfd < 0 ))
2253
2248
return crun_error_wrap (err , "open `%s` to write for tmpcopyup" , target );
2254
2249
@@ -2265,7 +2260,7 @@ do_mounts (libcrun_container_t *container, const char *rootfs, libcrun_error_t *
2265
2260
const bool is_dir = S_ISDIR (src_mode );
2266
2261
cleanup_close int dfd = -1 ;
2267
2262
2268
- dfd = safe_openat (rootfsfd , rootfs , target , O_RDONLY | O_PATH | O_CLOEXEC | (is_dir ? O_DIRECTORY : 0 ), 0 , err );
2263
+ dfd = safe_openat (get_private_data ( container ) -> rootfsfd , rootfs , target , O_RDONLY | O_PATH | O_CLOEXEC | (is_dir ? O_DIRECTORY : 0 ), 0 , err );
2269
2264
if (UNLIKELY (dfd < 0 ))
2270
2265
return crun_make_error (err , errno , "open mount target `/%s`" , target );
2271
2266
@@ -2286,7 +2281,6 @@ do_mounts (libcrun_container_t *container, const char *rootfs, libcrun_error_t *
2286
2281
int
2287
2282
libcrun_container_do_bind_mount (libcrun_container_t * container , char * mount_source , char * mount_destination , char * * mount_options , size_t mount_options_len , libcrun_error_t * err )
2288
2283
{
2289
- int ret , rootfsfd ;
2290
2284
const char * target = consume_slashes (mount_destination );
2291
2285
cleanup_free char * data = NULL ;
2292
2286
unsigned long flags = 0 ;
@@ -2296,9 +2290,9 @@ libcrun_container_do_bind_mount (libcrun_container_t *container, char *mount_sou
2296
2290
uint64_t rec_clear = 0 ;
2297
2291
uint64_t rec_set = 0 ;
2298
2292
const char * rootfs = get_private_data (container )-> rootfs ;
2299
- rootfsfd = get_private_data ( container ) -> rootfsfd ;
2293
+ int ret ;
2300
2294
2301
- if ((rootfsfd < 0 ) || (rootfs == NULL ))
2295
+ if ((get_private_data ( container ) -> rootfsfd < 0 ) || (rootfs == NULL ))
2302
2296
return crun_make_error (err , 0 , "invalid rootfs state while performing bind mount from external plugin or handler" );
2303
2297
2304
2298
if (mount_options == NULL )
@@ -2324,7 +2318,7 @@ libcrun_container_do_bind_mount (libcrun_container_t *container, char *mount_sou
2324
2318
}
2325
2319
2326
2320
/* Make sure any other directory/file is created and take a O_PATH reference to it. */
2327
- ret = crun_safe_create_and_open_ref_at (is_dir , rootfsfd , rootfs , target , is_dir ? 01755 : 0755 , err );
2321
+ ret = crun_safe_create_and_open_ref_at (is_dir , get_private_data ( container ) -> rootfsfd , rootfs , target , is_dir ? 01755 : 0755 , err );
2328
2322
if (UNLIKELY (ret < 0 ))
2329
2323
return ret ;
2330
2324
0 commit comments