Merge pull request #31731 from poettering/stat-is-set

stat-util: add explicit helpers for checking if stat/statx is initialized
This commit is contained in:
Lennart Poettering
2024-03-13 10:37:15 +01:00
committed by GitHub
4 changed files with 38 additions and 5 deletions
+16
View File
@@ -3,6 +3,7 @@
#include <fcntl.h>
#include <linux/magic.h>
#include <sched.h>
#include <sys/eventfd.h>
#include <unistd.h>
#include "alloc-util.h"
@@ -195,6 +196,21 @@ TEST(inode_type_from_string) {
assert_se(inode_type_from_string(inode_type_to_string(*m)) == *m);
}
TEST(anonymous_inode) {
_cleanup_close_ int fd = -EBADF;
fd = eventfd(0, EFD_CLOEXEC);
assert_se(fd >= 0);
/* Verify that we handle anonymous inodes correctly, i.e. those which have no file type */
struct stat st;
assert_se(fstat(fd, &st) >= 0);
assert_se((st.st_mode & S_IFMT) == 0);
assert_se(!inode_type_to_string(st.st_mode));
}
TEST(fd_verify_linked) {
_cleanup_(rm_rf_physical_and_freep) char *t = NULL;
_cleanup_close_ int tfd = -EBADF, fd = -EBADF;