[PATCH 1/2] makedumpfile: Add ftruncate error handling

Stefan Wiehler stefan.wiehler at nokia.com
Thu Aug 15 07:17:33 PDT 2024


Found via -Werror:

  makedumpfile.c: In function ‘dump_dmesg’:
  makedumpfile.c:5884:33: error: ignoring return value of ‘ftruncate’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
   5884 |                                 ftruncate(info->fd_dumpfile, 0);
        |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Stefan Wiehler <stefan.wiehler at nokia.com>
---
 makedumpfile.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/makedumpfile.c b/makedumpfile.c
index ce0d40e..c6f70ff 100644
--- a/makedumpfile.c
+++ b/makedumpfile.c
@@ -5881,7 +5881,11 @@ dump_dmesg()
 				char *first;
 
 				/* Clear everything we have already written... */
-				ftruncate(info->fd_dumpfile, 0);
+				if (ftruncate(info->fd_dumpfile, 0) != 0) {
+					ERRMSG("Can't truncate file(%s). %s\n",
+					       info->name_dumpfile, strerror(errno));
+					goto out;
+				}
 				lseek(info->fd_dumpfile, 0, SEEK_SET);
 
 				/* ...and only write up to the corruption. */
-- 
2.42.0




More information about the kexec mailing list