]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
data-fd-util: drop dead code
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 18 Dec 2024 02:55:47 +0000 (11:55 +0900)
committerLennart Poettering <lennart@poettering.net>
Wed, 18 Dec 2024 12:47:35 +0000 (13:47 +0100)
Also drops unnecessary header inclusions.

Follow-ups for a87a9625f8bde776ece11b8ddb77588cfff73038.
Fixes CID#1568419.

src/shared/data-fd-util.c

index 2a9549f0c2b98c3a64648135357cf8d6cbc27013..6f4825d8c132ba8560b0456a746463f6665005d6 100644 (file)
@@ -1,22 +1,11 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-#if HAVE_LINUX_MEMFD_H
-#include <linux/memfd.h>
-#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)