With --track-fds=yes warn when file descriptor is closed a second time
We moved the record_fd_close call from POST to PRE sys_close handler,
because the POST handler is only called on success. Even if the close
syscall fails the file descriptor is still really closed/invalid.
In the PRE handler the file descriptor is about to be closed, but hasn't
been yet so we can capture also the description.
This patch add new field fd_closed to OpenFd structure to record if
the file descriptor was already closed.
We now capture a backtrace when closing file descriptors to be able to
print it in a case of a double close. Always add '<' brackets '>' around
"unbound" in the description for consistency.
getsockdetails now takes and returns a buffer describing the socket
because we want to record it, not just print it.
Note that close_range is handled similar to closing each descriptor
individually. But the case when the close_range is called with an
infinite end (~0U) is treated special. Add a new record_fd_close_range
function which handles close_range with an infinite end so double
close by close_range isn't an error because we don't want to loop
over such a wide range.
Add a new test cases:
- none/tests/socket_close.vgtest
- tests double closing a socket
- none/tests/double_close_range.vgtest
- uses close_range to double close the file descriptors
- none/tests/file_dclose.vgtest
- double closing regular file with regular close syscall
https://bugs.kde.org/show_bug.cgi?id=471222
Co-Authored-By: Mark Wielaard <mark@klomp.org>
30 files changed: