Skip to content

Commit

Permalink
direct: use /proc/self/fd to read xattrs
Browse files Browse the repository at this point in the history
instead of using the lgetxattr and llistxattr system calls on the
entire file path, use the /proc/self/fd/$FD/$RELATIVE_PATH path
instead so that the lookup is relative to the lower dir file
descriptor that is already open.

Closes: #364

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Jul 29, 2022
1 parent e59b4f6 commit 257d904
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ static int
direct_listxattr (struct ovl_layer *l, const char *path, char *buf, size_t size)
{
char full_path[PATH_MAX];

strconcat3 (full_path, PATH_MAX, l->path, "/", path);
int ret;
ret = snprintf (full_path, sizeof (full_path), "/proc/self/fd/%d/%s", l->fd, path);
if (ret >= sizeof (full_path))
{
errno = ENAMETOOLONG;
return -1;
}

return llistxattr (full_path, buf, size);
}
Expand All @@ -54,9 +59,13 @@ static int
direct_getxattr (struct ovl_layer *l, const char *path, const char *name, char *buf, size_t size)
{
char full_path[PATH_MAX];

strconcat3 (full_path, PATH_MAX, l->path, "/", path);

int ret;
ret = snprintf (full_path, sizeof (full_path), "/proc/self/fd/%d/%s", l->fd, path);
if (ret >= sizeof (full_path))
{
errno = ENAMETOOLONG;
return -1;
}
return lgetxattr (full_path, name, buf, size);
}

Expand Down

0 comments on commit 257d904

Please sign in to comment.