]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-fileio: fix confusing log output
authorLennart Poettering <lennart@poettering.net>
Fri, 21 May 2021 15:35:12 +0000 (17:35 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 21 May 2021 19:54:43 +0000 (21:54 +0200)
Previously we'd pass all return values of read_virtual_file() to
log_info_errno() as error, but that makes no sense, given that we
sometimes return positive one with means "not truncated" but we'd show
as "Permission denied. Let's fix this, and log differently for sucess
and error.

src/test/test-fileio.c

index 51ae6652797eab99ecd82a76e301feb2fa54cfe0..9c5c7bf7379bf698a2fd8ce4d90c2581631f6129 100644 (file)
@@ -1034,8 +1034,11 @@ static void test_read_virtual_file(size_t max_size) {
                 size_t size = 0;
 
                 r = read_virtual_file(filename, max_size, &buf, &size);
-                log_info_errno(r, "read_virtual_file(\"%s\", %zu): %m (%zu bytes)", filename, max_size, size);
-                assert_se(r == 0 || ERRNO_IS_PRIVILEGE(r) || r == -ENOENT);
+                if (r < 0) {
+                        log_info_errno(r, "read_virtual_file(\"%s\", %zu): %m", filename, max_size);
+                        assert_se(ERRNO_IS_PRIVILEGE(r) || r == -ENOENT);
+                } else
+                        log_info("read_virtual_file(\"%s\", %zu): %s (%zu bytes)", filename, max_size, r ? "non-truncated" : "truncated", size);
         }
 }