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]>
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(3p) says:
       The exit() function shall then flush all open streams with
       unwritten buffered data, close all open  streams,  and remove all
       files created by tmpfile().

It was added here:

2004-03-13  Paolo Bonzini  <[email protected]>

        Exit as soon as possible on an I/O error, and with
        a better error message.
    ...
        (panic): Unlink temporary files before exiting.


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().)

fclose(3p) says:
DESCRIPTION
       The  fclose() function shall cause the stream pointed to by
       stream to be flushed and the associated file to be closed. Any
       unwritten buffered data for the stream shall be written to the
       file; any unread buffered data shall be discarded.

It was added here:

2002-06-08  Paolo Bonzini  <[email protected]>
       * lib/utils.c (ck_fclose): Work on stdout as well if stream == NULL
        and flush before closing to check for errors


Well, and the check for EBADF in ck_fflush() looks like a hack that
could hide a problem elsewhere.

It was added here:

2002-10-28  Paolo Bonzini  <[email protected]>
        
        * lib/utils.c: Don't fail for EBADF in fflush

-- 
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.