Skip to content

Commit

Permalink
fd-util: be more careful with fclose() errnos
Browse files Browse the repository at this point in the history
This might fix systemd#15859, a bug which I find very puzzling.

(cherry picked from commit 75f6d5d)
  • Loading branch information
poettering authored and keszybz committed Jul 27, 2020
1 parent af98104 commit 121a53a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/basic/fd-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 121a53a

Please sign in to comment.