1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-04 21:47:31 +03:00

fd-util: be more careful with fclose() errnos

This might fix #15859, a bug which I find very puzzling.
This commit is contained in:
Lennart Poettering 2020-06-02 10:39:25 +02:00
parent 112bed84bf
commit 75f6d5d87e

View File

@ -103,13 +103,16 @@ int fclose_nointr(FILE *f) {
/* Same as close_nointr(), but for fclose() */ /* Same as close_nointr(), but for fclose() */
errno = 0; /* Extra safety: if the FILE* object is not encapsulating an fd, it might not set errno
* correctly. Let's hence initialize it to zero first, so that we aren't confused by any
* prior errno here */
if (fclose(f) == 0) if (fclose(f) == 0)
return 0; return 0;
if (errno == EINTR) if (errno == EINTR)
return 0; return 0;
return -errno; return errno_or_else(EIO);
} }
FILE* safe_fclose(FILE *f) { FILE* safe_fclose(FILE *f) {