container: make ENOENT error clearer#2126
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies resolve_rootfs_path in src/libcrun/container.c to immediately return an error if realpath fails with ENOENT. However, the reviewer points out that this change breaks the fallback mechanism designed for cases where the absolute path is not visible in the current mount namespace but is accessible relatively. The reviewer suggests fixing the fallback mechanism itself and only returning the ENOENT error after the fallback has been attempted and failed.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if (errno == ENOENT) | ||
| return crun_make_error (err, errno, "the rootfs path `%s` does not exist", def->root->path); |
There was a problem hiding this comment.
Issue
Immediately returning an error when errno == ENOENT completely bypasses and breaks the fallback mechanism designed for cases where the absolute path is not visible/accessible in the current mount namespace but is accessible relatively (e.g., when running in restricted namespaces or chroots).
Root Cause of the Weird Error
The reason the weird error message readlink : No such file or directory` happens is because the fallback mechanism itself has a bug:
- It opens
/proc/self/cwdwithO_RDONLY(which follows the symlink and opens the directory). - It then calls
safe_readlinkatwith""and flags0, which always fails withENOENTon directories (especially on kernels < 5.14 whereAT_EMPTY_PATHis not supported or when flags is0). - Because the fallback fails, it immediately returns the error from
safe_readlinkatinstead of falling back to the next option or returning the originalENOENTerror.
Recommended Solution
To fix both issues properly, we should:
- Fix the fallback to use
safe_readlinkat (AT_FDCWD, "/proc/self/cwd", ...)which is clean, standard, and works on all kernels. - Use a temporary error variable so we don't pollute
errif the fallback fails. - Only return the clear
ENOENTerror after the fallback has been attempted and failed to resolve the path.
Here is the fully refactored resolve_rootfs_path function:
static int
resolve_rootfs_path (libcrun_container_t *container, char **rootfs, libcrun_error_t *err)
{
runtime_spec_schema_config_schema *def = container->container_def;
if (def->root && def->root->path)
{
*rootfs = realpath (def->root->path, NULL);
if (UNLIKELY (*rootfs == NULL))
{
int saved_errno = errno;
/* If realpath failed for any reason, try the relative directory. */
if (def->root->path[0] == '/')
{
cleanup_free char *cwd = NULL;
ssize_t len;
libcrun_error_t tmp_err = NULL;
len = safe_readlinkat (AT_FDCWD, "/proc/self/cwd", &cwd, 0, &tmp_err);
if (len >= 0)
{
/* If the rootfs is under the current working directory, just use its relative path. */
if (has_prefix (def->root->path, cwd) && def->root->path[len] == '/')
{
const char *it = consume_slashes (def->root->path + len);
if (*it)
*rootfs = xstrdup (it);
}
}
else
{
crun_error_release (&tmp_err);
}
}
/* If nothing else worked, return a clear error if it was ENOENT. */
if (*rootfs == NULL)
{
if (saved_errno == ENOENT)
return crun_make_error (err, saved_errno, "the rootfs path `%s` does not exist", def->root->path);
*rootfs = xstrdup (def->root->path);
}
}
}
return 0;
}fea9fbb to
aefbd68
Compare
a not existing rootfs path was giving a weird error message: 2026-07-10T11:02:00.086289Z: readlink ``: No such file or directory Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
aefbd68 to
691ba78
Compare
a not existing rootfs path was giving a weird error message:
2026-07-10T11:02:00.086289Z: readlink ``: No such file or directory