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
This commit is contained in:
Simon McVittie 2014-09-11 12:04:04 +01:00 committed by Ralf Habacker
parent 31b3809018
commit 3765075c5f
5 changed files with 10 additions and 8 deletions

View file

@ -42,6 +42,7 @@
#include "dbus-misc.h"
#include "dbus-server-socket.h"
#include "dbus-sysdeps-unix.h"
/* put other private launchd functions here */

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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);
/**