From df15bd49b7c870a13f48f78ae7958380ad01f565 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 26 Mar 2018 13:25:51 +0200 Subject: 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.. --- src/test/test-fs-util.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/test') diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c index ba01eea4e..35bb699c3 100644 --- a/src/test/test-fs-util.c +++ b/src/test/test-fs-util.c @@ -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); -- cgit v1.2.3