RE: [PATCH] fixdep: use fflush() and ferror() to ensure successful write to files

From: David Laight
Date: Tue Feb 22 2022 - 04:09:48 EST


From: Masahiro Yamada <masahiroy@xxxxxxxxxx>
> Sent: 22 February 2022 03:44
>
> On Tue, Feb 22, 2022 at 7:33 AM David Laight <David.Laight@xxxxxxxxxx> wrote:
> >
> > From: Masahiro Yamada
> > > Sent: 21 February 2022 16:43
> > > To: linux-kbuild@xxxxxxxxxxxxxxx
> > >
> > > Checking the return value of (v)printf does not ensure the successful
> > > write to the .cmd file.
> > >
> > > Call fflush() and ferror() to make sure that everything has been
> > > written to the file.
> > >
> > > Signed-off-by: Masahiro Yamada <masahiroy@xxxxxxxxxx>
> >
> > Reviewed-by: David Laight <dvid.laight@xxxxxxxxxx>
> >
> > I'll note that you've lost the perror("fixdep").
> > But I suspect that isn't very meaningful.
> > If the disk is full it'd probably get lost anyway.
>
>
> perror() will go to stderr, i.e. tty here.
> So, that is not the issue.
>
> ferror() itself does not set errno here; "man ferror" says,
> "These functions should not fail and do not set the external
> variable errno"
>
> So, I dropped perror() because I am not sure if any related error
> message is printed here.
>
> Perhaps, errno was set by some of preceding printf() calls,
> but I am not quite sure if it is carried all the way to the end
> of this program.

I was thinking or a slightly more descriptive error message :-)

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)