fd-util: introduce fd_reopen() helper for reopening an fd

We have the same code for this in place at various locations, let's
unify that. Also, let's repurpose test-fs-util.c as a test for this new
helper cal..
This commit is contained in:
Lennart Poettering
2018-03-29 15:33:12 +02:00
parent c75436067f
commit f2324783ce
4 changed files with 24 additions and 16 deletions
+1 -5
View File
@@ -270,17 +270,13 @@ static void test_chase_symlinks(void) {
pfd = chase_symlinks(p, NULL, CHASE_OPEN, NULL);
if (pfd != -ENOENT) {
char procfs[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(pfd) + 1];
_cleanup_close_ int fd = -1;
sd_id128_t a, b;
assert_se(pfd >= 0);
xsprintf(procfs, "/proc/self/fd/%i", pfd);
fd = open(procfs, O_RDONLY|O_CLOEXEC);
fd = fd_reopen(pfd, O_RDONLY|O_CLOEXEC);
assert_se(fd >= 0);
safe_close(pfd);
assert_se(id128_read_fd(fd, ID128_PLAIN, &a) >= 0);