mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-26 07:40:08 +01:00
shared: always call close() from nm_close() wrapper
The nm_close() wrapper should behave exactly the same as calling close() directly. This is well known, documented behavior. The only addition on top of that, should be the nm_assert() to catch double-closing. Prevously, when passing a negative file descriptor, we wouldn't properly set errno. Also, the call would not show up in strace, which it should (at least, if libc's close actually makes the syscall). I would argue, that passing a negative file descriptor is a bug already and we should never do that. Maybe we should even assert non-negative fds. I don't do that now, because I am not sufficiently confident. Anyway, the change should have not practical effect, because we shouldn't actually pass negative fds already.
This commit is contained in:
parent
b31118cfd2
commit
f4780f85ae
1 changed files with 5 additions and 6 deletions
|
|
@ -1246,12 +1246,11 @@ nm_steal_fd (int *p_fd)
|
|||
static inline int
|
||||
nm_close (int fd)
|
||||
{
|
||||
if (fd >= 0) {
|
||||
if (close (fd) == 0)
|
||||
return 0;
|
||||
nm_assert (errno != EBADF);
|
||||
}
|
||||
return -1;
|
||||
int r;
|
||||
|
||||
r = close (fd);
|
||||
nm_assert (r != -1 || fd < 0 || errno != EBADF);
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* __NM_MACROS_INTERNAL_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue