]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coredump: use fstatvfs to check the available space
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 17 Jan 2023 08:00:00 +0000 (08:00 +0000)
committerLennart Poettering <lennart@poettering.net>
Tue, 17 Jan 2023 21:22:12 +0000 (22:22 +0100)
Given that we already have the file descriptor opened for writing, it
would make sense to call fstatvfs with that file descriptor rather than
statvfs with the directory path that was used to open that descriptor.

src/coredump/coredump.c

index 192dc4c654b044dbcba6cc2740c1a5e952b5629c..013ebb4c2871d4c50ace650a7f29ba4de35aabcc 100644 (file)
@@ -597,7 +597,7 @@ static int save_external_coredump(
                 /* tmpfs might get full quickly, so check the available space too.
                  * But don't worry about errors here, failing to access the storage
                  * location will be better logged when writing to it. */
-                if (statvfs("/var/lib/systemd/coredump/", &sv) >= 0)
+                if (fstatvfs(fd, &sv) >= 0)
                         max_size = MIN((uint64_t)sv.f_frsize * (uint64_t)sv.f_bfree, max_size);
 
                 log_debug("Limiting core file size to %" PRIu64 " bytes due to cgroup memory limits.", max_size);