On 11/12/26 06:10, Filip Hejsek wrote:
On Thu, 2026-11-12 at 05:07 +0300, Michael Tokarev wrote:

Hmm.  It looks like linux is the obscure system now, not the other way
around.  Before, POSIX.1-2008 stated that after EINTR, the state of the
FD is unspecified.  However, POSIX.1-2024 states that after EINTR, the
FD should remain open.  And linux isn't going to change the way close(2)
works there.

The system where close() may keep the fd open is HP-UX, which QEMU
doesn't support. On Linux, macOS, Windows, and FreeBSD/NetBSD/OpenBSD,
the fd is always closed. Of these, at least Linux can close the fd and
return EINTR when the syscall is interrupted, in violation of POSIX.1-
2024.

Yes, I understand. Yet, POSIX standartized the HP-UX behavior, so all other
systems has become "obscure" this way.


Why do we care about this close(2) return value here anyway?
Have you seen actual failure case?

This was spotted while reading the code, so no failures observed. But
the risk isn't an incorrect return value, it's about finalize()
calling close() a second time. That applies to the tools as well.

I mean, this weren't a problem until now, for all the decades qemu exists.
Not a problem in practice, that is.

I understand what the problem we have.  And yes it is better to keep such
an FD "dangling" in case of close() returned error and haven't actually
closed the FD, than to close an innocent/reused FD.

So what about changing the comment to this? I can send a v2 if we agree
on wording.

   Set fioc->fd to -1, to prevent qio_channel_file_finalize() from
   closing it again.

   POSIX.1-2024 specifies that the fd is closed even when close()
   returns an error, except when the error is EINTR. The systems that
   QEMU supports however violate the standard and always close the fd,
   even when returning EINTR. If the fd was actually closed, we must not
   try to close it a second time as we could accidentally close someone
   else's fd.

Yes, let's pick this commit instead.  No need to re-send.

Thanks,

/mjt

Reply via email to