diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-02-26 10:25:24 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-02-26 18:38:22 +0100 |
commit | ee1aa61c4710ae567a2b844e0f0bb8cb0456ab8c (patch) | |
tree | 08c7524320649140c868f5aed1cd9c32af4490a4 /src/test/test-copy.c | |
parent | 97e535c7248cc0457395e2d62b6e7d6c342a0bd2 (diff) | |
download | systemd-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.c | 17 |
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; } |