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

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