Blame SOURCES/0007-coredump-fix-unexpected-truncation-of-generated-core.patch

0ba2b3
From dbb542e10bfe1b2e21c7927bda9be1d301cfef65 Mon Sep 17 00:00:00 2001
0ba2b3
From: HATAYAMA Daisuke <d.hatayama@fujitsu.com>
0ba2b3
Date: Fri, 17 Jun 2022 20:38:19 +0900
0ba2b3
Subject: [PATCH 7/8] coredump: fix unexpected truncation of generated core
0ba2b3
 files
0ba2b3
0ba2b3
Core files generated by crash gcore command are sometimes unexpectedly
0ba2b3
truncated. Then, we can get aware of this from the following warning
0ba2b3
message output by gdb:
0ba2b3
0ba2b3
    BFD: warning: /root/./core.1.systemd is truncated: expected core file size >= 43606016, found: 43597824
0ba2b3
0ba2b3
From the investigation, it turned out that this truncation is
0ba2b3
occurring when there is no write() operation after the area skipped by
0ba2b3
lseek(). Holes are generated only when there is write() operation.
0ba2b3
0ba2b3
To fix this issue, use ftruncate() to allocate holes explicitly.
0ba2b3
0ba2b3
Signed-off-by: HATAYAMA Daisuke <d.hatayama@fujitsu.com>
0ba2b3
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
0ba2b3
---
0ba2b3
 src/libgcore/gcore_coredump.c | 15 +++++++++++++++
0ba2b3
 1 file changed, 15 insertions(+)
0ba2b3
0ba2b3
diff --git a/src/libgcore/gcore_coredump.c b/src/libgcore/gcore_coredump.c
0ba2b3
index 424b0a40a42b..27086d91468b 100644
0ba2b3
--- a/src/libgcore/gcore_coredump.c
0ba2b3
+++ b/src/libgcore/gcore_coredump.c
0ba2b3
@@ -331,6 +331,21 @@ void gcore_coredump(void)
0ba2b3
 	}
0ba2b3
 	progressf("done.\n");
0ba2b3
 
0ba2b3
+	/*
0ba2b3
+	 * Use ftruncate() to generate holes explicitly, or core file
0ba2b3
+	 * gets truncated if there is no write() operation after the
0ba2b3
+	 * area skipped by lseek().
0ba2b3
+	 */
0ba2b3
+	if (fflush(gcore->fp))
0ba2b3
+		error(FATAL, "%s: fflush: %s\n",
0ba2b3
+		      gcore->corename,
0ba2b3
+		      strerror(errno));
0ba2b3
+
0ba2b3
+	if (ftruncate(fileno(gcore->fp), ftell(gcore->fp)) < 0)
0ba2b3
+		error(FATAL, "%s: ftruncate: %s\n",
0ba2b3
+		      gcore->corename,
0ba2b3
+		      strerror(errno));
0ba2b3
+
0ba2b3
 	gcore->flags |= GCF_SUCCESS;
0ba2b3
 
0ba2b3
 }
0ba2b3
-- 
0ba2b3
2.37.1
0ba2b3