summaryrefslogtreecommitdiff
path: root/src/test/test-copy.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-02-26 10:25:24 +0100
committerLennart Poettering <lennart@poettering.net>2021-02-26 18:38:22 +0100
commitee1aa61c4710ae567a2b844e0f0bb8cb0456ab8c (patch)
tree08c7524320649140c868f5aed1cd9c32af4490a4 /src/test/test-copy.c
parent97e535c7248cc0457395e2d62b6e7d6c342a0bd2 (diff)
downloadsystemd-ee1aa61c4710ae567a2b844e0f0bb8cb0456ab8c.tar.gz
copy: handle copy_file_range() weirdness on procfs/sysfs
This addresses the issue described in https://lwn.net/Articles/846403/ and makes sure we will be able to stream bytes from procfs/sysfs via copy_bytes() if people ask us to.
Diffstat (limited to 'src/test/test-copy.c')
-rw-r--r--src/test/test-copy.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/test/test-copy.c b/src/test/test-copy.c
index ffa9297889..211b4a4925 100644
--- a/src/test/test-copy.c
+++ b/src/test/test-copy.c
@@ -304,6 +304,22 @@ static void test_copy_atomic(void) {
assert_se(copy_file_atomic("/etc/fstab", q, 0644, 0, 0, COPY_REPLACE) >= 0);
}
+static void test_copy_proc(void) {
+ _cleanup_(rm_rf_physical_and_freep) char *p = NULL;
+ _cleanup_free_ char *f = NULL, *a = NULL, *b = NULL;
+
+ /* Check if copying data from /proc/ works correctly, i.e. let's see if https://lwn.net/Articles/846403/ is a problem for us */
+
+ assert_se(mkdtemp_malloc(NULL, &p) >= 0);
+ assert_se(f = path_join(p, "version"));
+ assert_se(copy_file("/proc/version", f, 0, (mode_t) -1, 0, 0, 0) >= 0);
+
+ assert_se(read_one_line_file("/proc/version", &a) >= 0);
+ assert_se(read_one_line_file(f, &b) >= 0);
+ assert_se(streq(a, b));
+ assert_se(strlen(a) > 0);
+}
+
int main(int argc, char *argv[]) {
test_setup_logging(LOG_DEBUG);
@@ -318,6 +334,7 @@ int main(int argc, char *argv[]) {
test_copy_bytes_regular_file(argv[0], false, 32000); /* larger than copy buffer size */
test_copy_bytes_regular_file(argv[0], true, 32000);
test_copy_atomic();
+ test_copy_proc();
return 0;
}