Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgroup: Show the absolute path to cgroup.controllers when a controller is not available #1639

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/libcrun/cgroup-resources.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,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
Loading