Skip to content

Commit

Permalink
cgroup: Show the absolute path to cgroup.controllers when a controlle…
Browse files Browse the repository at this point in the history
…r is not available

This patch will provide the absolute path to the cgroup.controllers file
in the error message if the specified controller is not available.
Hopefully this will help with troubleshooting efforts.

Signed-off-by: Aaron Tomlin <[email protected]>
  • Loading branch information
aarontomlin committed Jan 11, 2025
1 parent 0b63b44 commit 43c0506
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/libcrun/cgroup-resources.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,15 @@ 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 (UNLIKELY (ret < 0))
ret = crun_make_error (err, 0, "the requested cgroup controller `%s` is not available", key);
else
ret = crun_make_error (err, 0, "controller `%s` is not available under %s", key, absolute_path);
}
}
return ret;
Expand Down
21 changes: 21 additions & 0 deletions src/libcrun/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,27 @@ 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
{
proc_fd_path_t target_fd_path;

get_proc_self_fd_path (target_fd_path, targetfd);
*absolute_path = realpath(target_fd_path, NULL);
if (UNLIKELY (*absolute_path == NULL))
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 43c0506

Please sign in to comment.