[PATCH 1/2] makedumpfile: Add ftruncate error handling
HAGIO KAZUHITO(萩尾 一仁)
k-hagio-ab at nec.com
Thu Aug 15 22:50:33 PDT 2024
On 2024/08/15 23:17, Stefan Wiehler wrote:
> 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);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hi Stefan, thanks for the patch.
I tried to reproduce those warnings, but could not get either one
with a plain make command and gcc 14.1 (or clang 18.1).
out of curiosity, what compiler version and build command do you use?
Thanks,
Kazu
>
> 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. */
More information about the kexec
mailing list