From: Yu Watanabe Date: Wed, 18 Dec 2024 02:55:47 +0000 (+0900) Subject: data-fd-util: drop dead code X-Git-Tag: v258-rc1~1823 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=114453d79585bba6f33c6267f1359dec16949bd7;p=thirdparty%2Fsystemd.git data-fd-util: drop dead code Also drops unnecessary header inclusions. Follow-ups for a87a9625f8bde776ece11b8ddb77588cfff73038. Fixes CID#1568419. --- diff --git a/src/shared/data-fd-util.c b/src/shared/data-fd-util.c index 2a9549f0c2b..6f4825d8c13 100644 --- a/src/shared/data-fd-util.c +++ b/src/shared/data-fd-util.c @@ -1,22 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include -#include -#include -#if HAVE_LINUX_MEMFD_H -#include -#endif - -#include "alloc-util.h" #include "copy.h" #include "data-fd-util.h" #include "fd-util.h" #include "fs-util.h" -#include "io-util.h" #include "memfd-util.h" #include "missing_mman.h" -#include "missing_syscall.h" #include "tmpfile-util.h" /* When the data is smaller or equal to 64K, try to place the copy in a memfd */ @@ -27,8 +16,6 @@ int copy_data_fd(int fd) { _cleanup_close_ int copy_fd = -EBADF, tmp_fd = -EBADF; - _cleanup_free_ void *remains = NULL; - size_t remains_size = 0; const char *td; struct stat st; int r; @@ -82,8 +69,7 @@ int copy_data_fd(int fd) { } /* If we have reason to believe this will fit fine in /tmp, then use that as first fallback. */ - if ((!S_ISREG(st.st_mode) || (uint64_t) st.st_size < DATA_FD_TMP_LIMIT) && - (DATA_FD_MEMORY_LIMIT + remains_size) < DATA_FD_TMP_LIMIT) { + if ((!S_ISREG(st.st_mode) || (uint64_t) st.st_size < DATA_FD_TMP_LIMIT)) { tmp_fd = open_tmpfile_unlinkable(NULL /* NULL as directory means /tmp */, O_RDWR|O_CLOEXEC); if (tmp_fd < 0) return tmp_fd; @@ -99,16 +85,7 @@ int copy_data_fd(int fd) { assert(r == 0); } - if (remains_size > 0) { - /* If there were remaining bytes (i.e. read into memory, but not written out yet) from the - * failed copy operation, let's flush them out next. */ - - r = loop_write(tmp_fd, remains, remains_size); - if (r < 0) - return r; - } - - r = copy_bytes(fd, tmp_fd, DATA_FD_TMP_LIMIT - DATA_FD_MEMORY_LIMIT - remains_size, COPY_REFLINK); + r = copy_bytes(fd, tmp_fd, DATA_FD_TMP_LIMIT - DATA_FD_MEMORY_LIMIT, COPY_REFLINK); if (r < 0) return r; if (r == 0) @@ -122,9 +99,6 @@ int copy_data_fd(int fd) { return -EIO; close_and_replace(copy_fd, tmp_fd); - - remains = mfree(remains); - remains_size = 0; } /* As last fallback use /var/tmp/ */ @@ -146,13 +120,6 @@ int copy_data_fd(int fd) { assert(r == 0); } - if (remains_size > 0) { - /* Then, copy in any read but not yet written bytes. */ - r = loop_write(tmp_fd, remains, remains_size); - if (r < 0) - return r; - } - /* Copy in the rest */ r = copy_bytes(fd, tmp_fd, UINT64_MAX, COPY_REFLINK); if (r < 0)