mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-03-13 12:58:20 +03:00
xattr-util: check if fd has O_PATH and do not try setxattr() twice
Follow-up for a4d2461c46f40c9ae5002a2aea35b35ccb60ef9c.
This commit is contained in:
parent
ea61e2e9bd
commit
5f904eb751
@ -330,8 +330,14 @@ int xsetxattr(int fd,
|
||||
|
||||
if (fd == AT_FDCWD) /* Both unspecified? Then operate on current working directory */
|
||||
path = ".";
|
||||
else
|
||||
else {
|
||||
r = fd_is_opath(fd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
by_procfs = r;
|
||||
path = NULL;
|
||||
}
|
||||
|
||||
} else if (fd != AT_FDCWD) {
|
||||
|
||||
@ -345,25 +351,14 @@ int xsetxattr(int fd,
|
||||
by_procfs = true; /* fsetxattr() is not going to work, go via /proc/ link right-away */
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (path)
|
||||
r = FLAGS_SET(flags, AT_SYMLINK_FOLLOW) ? setxattr(path, name, value, size, 0)
|
||||
: lsetxattr(path, name, value, size, 0);
|
||||
else
|
||||
r = by_procfs ? setxattr(FORMAT_PROC_FD_PATH(fd), name, value, size, 0)
|
||||
: fsetxattr(fd, name, value, size, 0);
|
||||
if (r < 0) {
|
||||
if (errno == EBADF) {
|
||||
if (by_procfs || path)
|
||||
return -EBADF;
|
||||
if (path)
|
||||
r = FLAGS_SET(flags, AT_SYMLINK_FOLLOW) ? setxattr(path, name, value, size, 0)
|
||||
: lsetxattr(path, name, value, size, 0);
|
||||
else
|
||||
r = by_procfs ? setxattr(FORMAT_PROC_FD_PATH(fd), name, value, size, 0)
|
||||
: fsetxattr(fd, name, value, size, 0);
|
||||
if (r < 0)
|
||||
return -errno;
|
||||
|
||||
by_procfs = true; /* Might be an O_PATH fd, try again via /proc/ link */
|
||||
continue;
|
||||
}
|
||||
|
||||
return -errno;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user