diff options
author | Masahiro Yamada <masahiroy@kernel.org> | 2022-03-06 16:25:35 +0900 |
---|---|---|
committer | Masahiro Yamada <masahiroy@kernel.org> | 2022-03-31 12:03:46 +0900 |
commit | 69304379ff036ce8ecf41efc2aeea4b29dd0c43f (patch) | |
tree | 4c92064e4eff53b54c9b4afbc5f9c2f20c05ad1f /scripts/mod/file2alias.c | |
parent | bbc90bc1bd4a63121bae9cbfafe1e1f0beaf24b1 (diff) | |
download | linux-69304379ff036ce8ecf41efc2aeea4b29dd0c43f.tar.bz2 |
fixdep: use fflush() and ferror() to ensure successful write to files
Currently, fixdep checks the return value from (v)printf(), but it does
not ensure the complete write to the .cmd file.
printf() just writes data to the internal buffer, which usually succeeds.
(Of course, it may fail for another reason, for example when the file
descriptor is closed, but that is another story.)
When the buffer (4k?) is full, an actual write occurs, and printf() may
really fail. One of typical cases is "No space left on device" when the
disk is full.
The data remaining in the buffer will be pushed out to the file when
the program exits, but we never know if it is successful.
One straight-forward fix would be to add the following code at the end
of the program.
ret = fflush(stdout);
if (ret < 0) {
/* error handling */
}
However, it is tedious to check the return code in all the call sites
of printf(), fflush(), fclose(), and whatever can cause actual writes
to the end device. Doing that lets the program bail out at the first
failure but is usually not worth the effort.
Instead, let's check the error status from ferror(). This is 'sticky',
so you need to check it just once. You still need to call fflush().
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: David Laight <david.laight@aculab.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Diffstat (limited to 'scripts/mod/file2alias.c')
0 files changed, 0 insertions, 0 deletions