From: Lennart Poettering Date: Tue, 2 Jun 2020 08:39:25 +0000 (+0200) Subject: fd-util: be more careful with fclose() errnos X-Git-Tag: v245.7~101 X-Git-Url: http://git-history.diyao.me/?a=commitdiff_plain;h=121a53aec2251429132a6d4b41afa6575d1d7c8f;p=systemd%2F.git fd-util: be more careful with fclose() errnos This might fix #15859, a bug which I find very puzzling. (cherry picked from commit 75f6d5d87e950f62baced48fe9b58828969e3811) --- diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index 4be876e24c..de3f238d33 100644 --- a/src/basic/fd-util.c +++ b/src/basic/fd-util.c @@ -102,13 +102,16 @@ int fclose_nointr(FILE *f) { /* 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) return 0; if (errno == EINTR) return 0; - return -errno; + return errno_or_else(EIO); } FILE* safe_fclose(FILE *f) {