diff options
author | Thomas Haller <thaller@redhat.com> | 2017-11-14 14:42:38 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-11-14 15:09:26 +0100 |
commit | f4780f85ae02fa32141cd56aa759d041ed4b27cf (patch) | |
tree | fb7f051d87f0b5434f112dd69a7c6047d13dfb85 /shared | |
parent | b31118cfd2ce863d4c4808a9d410f03be6d9170e (diff) | |
download | NetworkManager-f4780f85ae02fa32141cd56aa759d041ed4b27cf.tar.gz |
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.
Diffstat (limited to 'shared')
-rw-r--r-- | shared/nm-utils/nm-macros-internal.h | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 2d62ba7d97..f4dca4b37a 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -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__ */ |