Re: [PATCH sed] ck_fclose should unlink *before* calling do_ck_fclose.
Stanislav Brabec <[email protected]>
| Newsgroups | gmane.comp.gnu.utils.bugs |
|---|---|
| Organization | SUSE Linux s. r. o. |
| Message-ID | <[email protected]> |
Eric Blake wrote: > On 06/03/2014 02:55 PM, Stanislav Brabec wrote: > > NeilBrown wrote: > >> If do_ck_fclose gets an error from fclose() it will call > >> panic() which will try to close everything on the list. > > > > There is a question: Why this code is needed at all? Is there a > > platform, where exit(4) later in panic() keeps open file descriptors? > > exit() is guaranteed to close fds, but NOT guaranteed to affect return > status if there was an error detected during the close. Well, panic() always calls exit(4) at the end, so it always returns non-zero return code. And, by the way, panic() does not respond to failed fclose() inside itself. The patch proposed by NeilBrown will fix the crash when panic is trying to fclose() on a file where fclose() was already called and failed. But yes, as temporary files are not created by tmpfile(), we need to unlink them before exit, so we need the panic() or atexit(). And failed unlink() is reported. > We'd rather > close things manually, so that we can force a non-zero exit status via > _exit() if the close failed (which, for some filesystems such as NFS, is > all too real of a possibility). The panic() itself is a trap for failed fclose() in the whole rest of sed. > > And even: Why the fflush() is called before fclose()? fclose() should > > always flush. Isn't the error of fclose() sufficient? (Especially if > > both end in panic().) > > Again, fclose() is guaranteed to attempt a flush, but not guaranteed to > do sane reporting of errors in that process. Doing a manual fflush() > first gives us better error reporting. Is there any such platform? I would consider zero returned by fclose() after data loss while flushing as a serious bug in the underlying OS. (All errors mentioned in fflush(3p) are also mentioned by fclose(3p).) -- Best Regards / S pozdravem, Stanislav Brabec software developer --------------------------------------------------------------------- SUSE LINUX, s. r. o. e-mail: [email protected] Lihovarská 1060/12 tel: +49 911 7405384547 190 00 Praha 9 fax: +420 284 084 001 Czech Republic http://www.suse.cz/ PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76