From 6a1a0170525c472bfcf7b3b7c1e128c064f0f1dd Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 11 Sep 2014 12:04:04 +0100 Subject: [PATCH] Split _dbus_fd_set_close_on_exec into Unix and Windows versions On Unix, the thing that can be made close-on-exec is a file descriptor, which is an int. On Windows, the thing that can be made close-on-exec is a HANDLE, which is pointer-sized (but not necessarily a pointer!). In practice, on Windows we only called _dbus_fd_set_close_on_exec() on socket pseudo-file-descriptors (SOCKET, which is an unsigned int); every SOCKET can validly be cast to HANDLE, but not every HANDLE is a SOCKET. Before this commit we used an intptr_t as a sort of fake union { int; HANDLE; }, which just obscures what's going on. In practice, everything that called _dbus_fd_set_close_on_exec() is really platform-specific anyway, so let's just have two separate functions and call this solved. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39610 --- dbus/dbus-server-launchd.c | 1 + dbus/dbus-sysdeps-unix.c | 2 +- dbus/dbus-sysdeps-unix.h | 2 ++ dbus/dbus-sysdeps-win.c | 11 ++++++----- dbus/dbus-sysdeps.h | 2 -- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/dbus/dbus-server-launchd.c b/dbus/dbus-server-launchd.c index 9832875..d9d5908 100644 --- a/dbus/dbus-server-launchd.c +++ b/dbus/dbus-server-launchd.c @@ -42,6 +42,7 @@ #include "dbus-misc.h" #include "dbus-server-socket.h" +#include "dbus-sysdeps-unix.h" /* put other private launchd functions here */ diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 170d865..106c689 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -2919,7 +2919,7 @@ _dbus_disable_sigpipe (void) * @param fd the file descriptor */ void -_dbus_fd_set_close_on_exec (intptr_t fd) +_dbus_fd_set_close_on_exec (int fd) { int val; diff --git a/dbus/dbus-sysdeps-unix.h b/dbus/dbus-sysdeps-unix.h index a265b33..df9902d 100644 --- a/dbus/dbus-sysdeps-unix.h +++ b/dbus/dbus-sysdeps-unix.h @@ -142,6 +142,8 @@ dbus_bool_t _dbus_append_address_from_socket (int fd, DBusString *address, DBusError *error); +void _dbus_fd_set_close_on_exec (int fd); + /** @} */ DBUS_END_DECLS diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 1167e96..341db8a 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -518,10 +518,10 @@ _dbus_close_socket (int fd, * on exec. Should be called for all file * descriptors in D-Bus code. * - * @param handle the Windows HANDLE + * @param handle the Windows HANDLE (a SOCKET is also OK) */ -void -_dbus_fd_set_close_on_exec (intptr_t handle) +static void +_dbus_win_handle_set_close_on_exec (HANDLE handle) { if ( !SetHandleInformation( (HANDLE) handle, HANDLE_FLAG_INHERIT | HANDLE_FLAG_PROTECT_FROM_CLOSE, @@ -1605,7 +1605,8 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, } } - _dbus_fd_set_close_on_exec (fd); + /* Every SOCKET is also a HANDLE. */ + _dbus_win_handle_set_close_on_exec ((HANDLE) fd); if (!_dbus_set_fd_nonblocking (fd, error)) { @@ -1803,7 +1804,7 @@ _dbus_listen_tcp_socket (const char *host, for (i = 0 ; i < nlisten_fd ; i++) { - _dbus_fd_set_close_on_exec (listen_fd[i]); + _dbus_win_handle_set_close_on_exec ((HANDLE) listen_fd[i]); if (!_dbus_set_fd_nonblocking (listen_fd[i], error)) { goto failed; diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index 21033eb..7d44f93 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -359,8 +359,6 @@ void _dbus_directory_close (DBusDirIter *iter); dbus_bool_t _dbus_check_dir_is_private_to_user (DBusString *dir, DBusError *error); -void _dbus_fd_set_close_on_exec (intptr_t fd); - const char* _dbus_get_tmpdir (void); /** -- 2.1.0