xattr-util: merge various getxattr()/listxattr() helpers into getxattr_at_malloc() + listxattr_at_malloc()

Unfortunately fgetxattr() and flistxattr() don't work via O_PATH fds.
Let's thus add fallbacks to go via /proc/self/fd/ in these cases.

Also, let's merge all the various flavours we have here into singular
implementations that can do everything we need:

1. malloc() loop handling
2. by fd, by path, or combination (i.e. a proper openat() like API)
3. work on O_PATH
This commit is contained in:
Lennart Poettering
2021-10-07 11:49:22 +02:00
parent c9d1c37c93
commit c53e07e249
11 changed files with 193 additions and 198 deletions
+8 -12
View File
@@ -53,11 +53,10 @@ static void patch_realtime(
const struct stat *st,
unsigned long long *realtime) {
usec_t x, crtime = 0;
usec_t x;
/* The timestamp was determined by the file name, but let's
* see if the file might actually be older than the file name
* suggested... */
/* The timestamp was determined by the file name, but let's see if the file might actually be older
* than the file name suggested... */
assert(fd >= 0);
assert(fn);
@@ -76,15 +75,12 @@ static void patch_realtime(
if (x > 0 && x != USEC_INFINITY && x < *realtime)
*realtime = x;
/* Let's read the original creation time, if possible. Ideally
* we'd just query the creation time the FS might provide, but
* unfortunately there's currently no sane API to query
* it. Hence let's implement this manually... */
/* Let's read the original creation time, if possible. Ideally we'd just query the creation time the
* FS might provide, but unfortunately there's currently no sane API to query it. Hence let's
* implement this manually... */
if (fd_getcrtime_at(fd, fn, &crtime, 0) >= 0) {
if (crtime < *realtime)
*realtime = crtime;
}
if (fd_getcrtime_at(fd, fn, AT_SYMLINK_FOLLOW, &x) >= 0 && x < *realtime)
*realtime = x;
}
static int journal_file_empty(int dir_fd, const char *name) {