Skip to content

Commit

Permalink
Merge pull request #1639 from aarontomlin/main
Browse files Browse the repository at this point in the history
cgroup: Show the absolute path to cgroup.controllers when a controller is not available
  • Loading branch information
rhatdan authored Jan 15, 2025
2 parents 283ffdf + a4dcb9c commit a646439
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/libcrun/cgroup-resources.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,18 @@ check_cgroup_v2_controller_available_wrapper (int ret, int cgroup_dirfd, const c
}
if (! found)
{
cleanup_free char *absolute_path = NULL;
libcrun_error_t tmp_err = NULL;

crun_error_release (err);
return crun_make_error (err, 0, "the requested cgroup controller `%s` is not available", key);
ret = get_realpath_to_file (cgroup_dirfd, "cgroup.controllers", &absolute_path, &tmp_err);
if (LIKELY (ret >= 0))
ret = crun_make_error (err, 0, "controller `%s` is not available under %s", key, absolute_path);
else
{
crun_error_release (&tmp_err);
ret = crun_make_error (err, 0, "the requested cgroup controller `%s` is not available", key);
}
}
}
return ret;
Expand Down
25 changes: 25 additions & 0 deletions src/libcrun/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,31 @@ read_all_file (const char *path, char **out, size_t *len, libcrun_error_t *err)
return read_all_file_at (AT_FDCWD, path, out, len, err);
}

int
get_realpath_to_file (int dirfd, const char *path_name, char **absolute_path, libcrun_error_t *err)
{
cleanup_close int targetfd = -1;

targetfd = TEMP_FAILURE_RETRY (openat (dirfd, path_name, O_RDONLY | O_CLOEXEC));
if (UNLIKELY (targetfd < 0))
return crun_make_error (err, errno, "error opening file `%s`", path_name);
else
{
ssize_t len;
proc_fd_path_t target_fd_path;

get_proc_self_fd_path (target_fd_path, targetfd);
len = safe_readlinkat (AT_FDCWD, target_fd_path, absolute_path, 0, err);
if (UNLIKELY (len < 0))
{
crun_error_release (err);
return crun_make_error (err, errno, "error unable to provide absolute path to file `%s`", path_name);
}
}

return 0;
}

int
open_unix_domain_client_socket (const char *path, int dgram, libcrun_error_t *err)
{
Expand Down
2 changes: 2 additions & 0 deletions src/libcrun/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ read_all_fd (int fd, const char *description, char **out, size_t *len, libcrun_e
return read_all_fd_with_size_hint (fd, description, out, len, 0, err);
}

int get_realpath_to_file (int dirfd, const char *path_name, char **absolute_path, libcrun_error_t *err);

int read_all_file (const char *path, char **out, size_t *len, libcrun_error_t *err);

int read_all_file_at (int dirfd, const char *path, char **out, size_t *len, libcrun_error_t *err);
Expand Down

0 comments on commit a646439

Please sign in to comment.