]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
copy: add splice() based fallback
authorLennart Poettering <lennart@poettering.net>
Thu, 27 Aug 2015 22:10:35 +0000 (00:10 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 28 Aug 2015 00:05:42 +0000 (02:05 +0200)
Apparently, sendfile() does not work between fifos and ttys, but
splice() does, hence let's optionally fall back to that. This is useful
to implement the fallback pager this way.

src/basic/copy.c

index 33427c6a73fb1bfbbf67b0d8ce193880c1755e84..cc5faa80a17e24a8714e0c633958067a637a4a20 100644 (file)
@@ -30,7 +30,7 @@
 #define COPY_BUFFER_SIZE (16*1024)
 
 int copy_bytes(int fdf, int fdt, off_t max_bytes, bool try_reflink) {
-        bool try_sendfile = true;
+        bool try_sendfile = true, try_splice = true;
         int r;
 
         assert(fdf >= 0);
@@ -69,7 +69,23 @@ int copy_bytes(int fdf, int fdt, off_t max_bytes, bool try_reflink) {
                         } else if (n == 0) /* EOF */
                                 break;
                         else if (n > 0)
-                                /* Succcess! */
+                                /* Success! */
+                                goto next;
+                }
+
+                /* The try splice, unless we already tried */
+                if (try_splice) {
+                        n  = splice(fdf, NULL, fdt, NULL, m, 0);
+                        if (n < 0) {
+                                if (errno != EINVAL && errno != ENOSYS)
+                                        return -errno;
+
+                                try_splice = false;
+                                /* use fallback below */
+                        } else if (n == 0) /* EOF */
+                                break;
+                        else if (n > 0)
+                                /* Success! */
                                 goto next;
                 }