diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-12-05 19:02:14 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-12-05 19:18:23 +0100 |
commit | f9568765d4d3d57de1ec01d85f0a0682920f4d10 (patch) | |
tree | e90215c3ef1a7a4bf8ce6372aecb66b0e35e4017 /src/creds | |
parent | NEWS: finalize for v255-rc4 (diff) | |
download | systemd-f9568765d4d3d57de1ec01d85f0a0682920f4d10.tar.xz systemd-f9568765d4d3d57de1ec01d85f0a0682920f4d10.zip |
variuos: fwrite() does not set errno
The man page doesn't even mention errno. It just says that ferror() should
be used to check for errors. Those writes are unlikely to fail, but if they
do, errno might even be 0. Also, we have fflush_and_check() which does
additional paranoia around errno, because we apparently do not trust that
errno will always be set correctly.
Diffstat (limited to 'src/creds')
-rw-r--r-- | src/creds/creds.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/creds/creds.c b/src/creds/creds.c index 101e5abf9b..7a98a5dcd3 100644 --- a/src/creds/creds.c +++ b/src/creds/creds.c @@ -350,14 +350,15 @@ static int write_blob(FILE *f, const void *data, size_t size) { } if (fwrite(data, 1, size, f) != size) - return log_error_errno(errno, "Failed to write credential data: %m"); + return log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to write credential data: %m"); r = print_newline(f, data, size); if (r < 0) return r; - if (fflush(f) != 0) - return log_error_errno(errno, "Failed to flush output: %m"); + r = fflush_and_check(f); + if (r < 0) + return log_error_errno(r, "Failed to flush output: %m"); return 0; } |