From 53a9f7d88eaea5d252c2db479a33662a112dd8c7 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Thu, 5 Mar 2015 19:50:12 +0100 Subject: [PATCH] Use typedef DBusSocket for sockets fd's to avoid conversion warnings. --- dbus/dbus-nonce.c | 8 ++++---- dbus/dbus-nonce.h | 5 +++-- dbus/dbus-server-debug-pipe.c | 2 +- dbus/dbus-server-socket.c | 12 ++++++------ dbus/dbus-server-socket.h | 2 +- dbus/dbus-server-unix.c | 2 +- dbus/dbus-spawn-win.c | 12 ++++++------ dbus/dbus-sysdeps-unix.c | 12 ++++++------ dbus/dbus-sysdeps-win.c | 40 ++++++++++++++++++++-------------------- dbus/dbus-sysdeps.h | 36 +++++++++++++++++++++--------------- dbus/dbus-transport-socket.c | 5 +++-- 11 files changed, 72 insertions(+), 64 deletions(-) diff --git a/dbus/dbus-nonce.c b/dbus/dbus-nonce.c index 44c46b2..280abb2 100644 --- a/dbus/dbus-nonce.c +++ b/dbus/dbus-nonce.c @@ -142,10 +142,10 @@ _dbus_read_nonce (const DBusString *fname, DBusString *nonce, DBusError* error) return TRUE; } -int -_dbus_accept_with_noncefile (int listen_fd, const DBusNonceFile *noncefile) +DBusSocket +_dbus_accept_with_noncefile (DBusSocket listen_fd, const DBusNonceFile *noncefile) { - int fd; + DBusSocket fd; DBusString nonce; _dbus_assert (noncefile != NULL); @@ -431,7 +431,7 @@ _dbus_noncefile_get_path (const DBusNonceFile *noncefile) * and matches the nonce from the given nonce file */ dbus_bool_t -_dbus_noncefile_check_nonce (int fd, +_dbus_noncefile_check_nonce (DBusSocket fd, const DBusNonceFile *noncefile, DBusError* error) { diff --git a/dbus/dbus-nonce.h b/dbus/dbus-nonce.h index 474ea72..26308fd 100644 --- a/dbus/dbus-nonce.h +++ b/dbus/dbus-nonce.h @@ -27,6 +27,7 @@ #include #include #include +#include DBUS_BEGIN_DECLS @@ -46,13 +47,13 @@ dbus_bool_t _dbus_noncefile_create (DBusNonceFile *noncefile, dbus_bool_t _dbus_noncefile_delete (DBusNonceFile *noncefile, DBusError *error); -dbus_bool_t _dbus_noncefile_check_nonce (int fd, +dbus_bool_t _dbus_noncefile_check_nonce (DBusSocket fd, const DBusNonceFile *noncefile, DBusError *error); const DBusString* _dbus_noncefile_get_path (const DBusNonceFile *noncefile); -int _dbus_accept_with_noncefile (int listen_fd, +DBusSocket _dbus_accept_with_noncefile(DBusSocket listen_fd, const DBusNonceFile *noncefile); // shared diff --git a/dbus/dbus-server-debug-pipe.c b/dbus/dbus-server-debug-pipe.c index 8f5ff5f..a81b3e2 100644 --- a/dbus/dbus-server-debug-pipe.c +++ b/dbus/dbus-server-debug-pipe.c @@ -211,7 +211,7 @@ _dbus_transport_debug_pipe_new (const char *server_name, DBusTransport *client_transport; DBusTransport *server_transport; DBusConnection *connection; - int client_fd, server_fd; + DBusSocket client_fd, server_fd; DBusServer *server; DBusString address; diff --git a/dbus/dbus-server-socket.c b/dbus/dbus-server-socket.c index 70367c7..aa2ce85 100644 --- a/dbus/dbus-server-socket.c +++ b/dbus/dbus-server-socket.c @@ -51,7 +51,7 @@ struct DBusServerSocket { DBusServer base; /**< Parent class members. */ int n_fds; /**< Number of active file handles */ - int *fds; /**< File descriptor or -1 if disconnected. */ + DBusSocket *fds; /**< File descriptor or -1 if disconnected. */ DBusWatch **watch; /**< File descriptor watch. */ char *socket_name; /**< Name of domain socket, to unlink if appropriate */ DBusNonceFile *noncefile; /**< Nonce file used to authenticate clients */ @@ -182,8 +182,8 @@ socket_handle_watch (DBusWatch *watch, if (flags & DBUS_WATCH_READABLE) { - int client_fd; - int listen_fd; + DBusSocket client_fd; + DBusSocket listen_fd; int saved_errno; listen_fd = dbus_watch_get_socket (watch); @@ -280,7 +280,7 @@ static const DBusServerVTable socket_vtable = { * */ DBusServer* -_dbus_server_new_for_socket (int *fds, +_dbus_server_new_for_socket (DBusSocket *fds, int n_fds, const DBusString *address, DBusNonceFile *noncefile) @@ -295,7 +295,7 @@ _dbus_server_new_for_socket (int *fds, socket_server->noncefile = noncefile; - socket_server->fds = dbus_new (int, n_fds); + socket_server->fds = (DBusSocket *)dbus_new (int, n_fds); if (!socket_server->fds) goto failed_0; @@ -396,7 +396,7 @@ _dbus_server_new_for_tcp_socket (const char *host, dbus_bool_t use_nonce) { DBusServer *server; - int *listen_fds = NULL; + DBusSocket *listen_fds = NULL; int nlisten_fds = 0, i; DBusString address; DBusString host_str; diff --git a/dbus/dbus-server-socket.h b/dbus/dbus-server-socket.h index 44e11e8..cdb6284 100644 --- a/dbus/dbus-server-socket.h +++ b/dbus/dbus-server-socket.h @@ -29,7 +29,7 @@ DBUS_BEGIN_DECLS -DBusServer* _dbus_server_new_for_socket (int *fds, +DBusServer* _dbus_server_new_for_socket (DBusSocket *fds, int n_fds, const DBusString *address, DBusNonceFile *noncefile); diff --git a/dbus/dbus-server-unix.c b/dbus/dbus-server-unix.c index fcfe27f..e94bc2e 100644 --- a/dbus/dbus-server-unix.c +++ b/dbus/dbus-server-unix.c @@ -289,7 +289,7 @@ _dbus_server_new_for_domain_socket (const char *path, DBusError *error) { DBusServer *server; - int listen_fd; + DBusSocket listen_fd; DBusString address; char *path_copy; DBusString path_str; diff --git a/dbus/dbus-spawn-win.c b/dbus/dbus-spawn-win.c index 7da7a43..8b08c2c 100644 --- a/dbus/dbus-spawn-win.c +++ b/dbus/dbus-spawn-win.c @@ -77,8 +77,8 @@ struct DBusBabysitter char **envp; HANDLE child_handle; - int socket_to_babysitter; /* Connection to the babysitter thread */ - int socket_to_main; + DBusSocket socket_to_babysitter; /* Connection to the babysitter thread */ + DBusSocket socket_to_main; DBusWatchList *watches; DBusWatch *sitter_watch; @@ -171,10 +171,10 @@ close_socket_to_babysitter (DBusBabysitter *sitter) sitter->sitter_watch = NULL; } - if (sitter->socket_to_babysitter != -1) + if (sitter->socket_to_babysitter != INVALID_SOCKET) { _dbus_close_socket (sitter->socket_to_babysitter, NULL); - sitter->socket_to_babysitter = -1; + sitter->socket_to_babysitter = INVALID_SOCKET; } } @@ -198,10 +198,10 @@ _dbus_babysitter_unref (DBusBabysitter *sitter) { close_socket_to_babysitter (sitter); - if (sitter->socket_to_main != -1) + if (sitter->socket_to_main != INVALID_SOCKET) { _dbus_close_socket (sitter->socket_to_main, NULL); - sitter->socket_to_main = -1; + sitter->socket_to_main = INVALID_SOCKET; } PING(); diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 3f60671..dae3b25 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -274,10 +274,10 @@ _dbus_write_socket (int fd, * @returns number of bytes appended to string */ int -_dbus_read_socket_with_unix_fds (int fd, +_dbus_read_socket_with_unix_fds (DBusSocket fd, DBusString *buffer, int count, - int *fds, + DBusSocket *fds, int *n_fds) { #ifndef HAVE_UNIX_FD_PASSING int r; @@ -1807,7 +1807,7 @@ out: * @returns #TRUE on success */ dbus_bool_t -_dbus_read_credentials_socket (int client_fd, +_dbus_read_credentials_socket (DBusSocket client_fd, DBusCredentials *credentials, DBusError *error) { @@ -3287,13 +3287,13 @@ _dbus_print_backtrace (void) * @returns #FALSE on failure (if error is set) */ dbus_bool_t -_dbus_full_duplex_pipe (int *fd1, - int *fd2, +_dbus_full_duplex_pipe (DBusSocket *fd1, + DBusSocket *fd2, dbus_bool_t blocking, DBusError *error) { #ifdef HAVE_SOCKETPAIR - int fds[2]; + DBusSocket fds[2]; int retval; #ifdef SOCK_CLOEXEC diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 5025815..f0270f3 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -52,7 +52,6 @@ #include "dbus-credentials.h" #include -#include #include #include @@ -376,7 +375,7 @@ _dbus_win_free_error_string (char *string) */ int -_dbus_read_socket (int fd, +_dbus_read_socket (DBusSocket fd, DBusString *buffer, int count) { @@ -446,7 +445,7 @@ _dbus_read_socket (int fd, * @returns the number of bytes written or -1 on error */ int -_dbus_write_socket (int fd, +_dbus_write_socket (DBusSocket fd, const DBusString *buffer, int start, int len) @@ -490,7 +489,7 @@ _dbus_write_socket (int fd, * @returns #FALSE if error set */ dbus_bool_t -_dbus_close_socket (int fd, +_dbus_close_socket (DBusSocket fd, DBusError *error) { _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -580,7 +579,7 @@ _dbus_set_fd_nonblocking (int handle, * @returns total bytes written from both buffers, or -1 on error */ int -_dbus_write_socket_two (int fd, +_dbus_write_socket_two (DBusSocket fd, const DBusString *buffer1, int start1, int len1, @@ -646,7 +645,7 @@ _dbus_write_socket_two (int fd, dbus_bool_t _dbus_socket_is_invalid (int fd) { - return fd == INVALID_SOCKET ? TRUE : FALSE; + return fd == (int)INVALID_SOCKET ? TRUE : FALSE; } #if 0 @@ -1055,8 +1054,8 @@ failed: * @returns #FALSE on failure (if error is set) */ dbus_bool_t -_dbus_full_duplex_pipe (int *fd1, - int *fd2, +_dbus_full_duplex_pipe (DBusSocket *fd1, + DBusSocket *fd2, dbus_bool_t blocking, DBusError *error) { @@ -1507,7 +1506,7 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, const char *noncefile, DBusError *error) { - int fd = -1, res; + SOCKET fd = INVALID_SOCKET, res; struct addrinfo hints; struct addrinfo *ai, *tmp; @@ -1579,7 +1578,7 @@ _dbus_connect_tcp_socket_with_nonce (const char *host, } freeaddrinfo(ai); - if (fd == -1) + if (fd == INVALID_SOCKET) { dbus_set_error (error, _dbus_error_from_errno (errno), @@ -1643,10 +1642,11 @@ _dbus_listen_tcp_socket (const char *host, const char *port, const char *family, DBusString *retport, - int **fds_p, + DBusSocket **fds_p, DBusError *error) { - int nlisten_fd = 0, *listen_fd = NULL, res, i, port_num = -1; + DBusSocket *listen_fd = NULL; + int nlisten_fd = 0, res, i, port_num = -1; struct addrinfo hints; struct addrinfo *ai, *tmp; @@ -1706,8 +1706,8 @@ _dbus_listen_tcp_socket (const char *host, tmp = ai; while (tmp) { - int fd = -1, *newlisten_fd; - if ((fd = socket (tmp->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET) + DBusSocket fd = INVALID_SOCKET, *newlisten_fd; + if ((fd = (DBusSocket)socket (tmp->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET) { DBUS_SOCKET_SET_ERRNO (); dbus_set_error (error, @@ -1849,10 +1849,10 @@ _dbus_listen_tcp_socket (const char *host, * @param listen_fd the listen file descriptor * @returns the connection fd of the client, or -1 on error */ -int -_dbus_accept (int listen_fd) +DBusSocket +_dbus_accept (DBusSocket listen_fd) { - int client_fd; + DBusSocket client_fd; retry: client_fd = accept (listen_fd, NULL, NULL); @@ -1873,8 +1873,8 @@ _dbus_accept (int listen_fd) dbus_bool_t -_dbus_send_credentials_socket (int handle, - DBusError *error) +_dbus_send_credentials_socket (DBusSocket handle, + DBusError *error) { /* FIXME: for the session bus credentials shouldn't matter (?), but * for the system bus they are presumably essential. A rough outline @@ -1950,7 +1950,7 @@ again: * @returns #TRUE on success */ dbus_bool_t -_dbus_read_credentials_socket (int handle, +_dbus_read_credentials_socket (DBusSocket handle, DBusCredentials *credentials, DBusError *error) { diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index 2dbc420..25b633a 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -128,20 +128,26 @@ typedef unsigned long dbus_gid_t; * will be checked by the compiler. * */ +#ifndef DBUS_WIN +typedef int DBusSocket; +#else +#include +typedef SOCKET DBusSocket; +#endif DBUS_PRIVATE_EXPORT -dbus_bool_t _dbus_close_socket (int fd, +dbus_bool_t _dbus_close_socket (DBusSocket fd, DBusError *error); DBUS_PRIVATE_EXPORT -int _dbus_read_socket (int fd, +int _dbus_read_socket (DBusSocket fd, DBusString *buffer, int count); DBUS_PRIVATE_EXPORT -int _dbus_write_socket (int fd, +int _dbus_write_socket (DBusSocket fd, const DBusString *buffer, int start, int len); -int _dbus_write_socket_two (int fd, +int _dbus_write_socket_two (DBusSocket fd, const DBusString *buffer1, int start1, int len1, @@ -149,19 +155,19 @@ int _dbus_write_socket_two (int fd, int start2, int len2); -int _dbus_read_socket_with_unix_fds (int fd, +int _dbus_read_socket_with_unix_fds (DBusSocket fd, DBusString *buffer, int count, - int *fds, + DBusSocket *fds, int *n_fds); DBUS_PRIVATE_EXPORT -int _dbus_write_socket_with_unix_fds (int fd, +int _dbus_write_socket_with_unix_fds (DBusSocket fd, const DBusString *buffer, int start, int len, const int *fds, int n_fds); -int _dbus_write_socket_with_unix_fds_two (int fd, +int _dbus_write_socket_with_unix_fds_two (DBusSocket fd, const DBusString *buffer1, int start1, int len1, @@ -186,15 +192,15 @@ int _dbus_listen_tcp_socket (const char *host, const char *port, const char *family, DBusString *retport, - int **fds_p, + DBusSocket **fds_p, DBusError *error); -int _dbus_accept (int listen_fd); +DBusSocket _dbus_accept (DBusSocket listen_fd); -dbus_bool_t _dbus_read_credentials_socket (int client_fd, +dbus_bool_t _dbus_read_credentials_socket (DBusSocket client_fd, DBusCredentials *credentials, DBusError *error); -dbus_bool_t _dbus_send_credentials_socket (int server_fd, +dbus_bool_t _dbus_send_credentials_socket (DBusSocket server_fd, DBusError *error); dbus_bool_t _dbus_credentials_add_from_user (DBusCredentials *credentials, @@ -224,7 +230,7 @@ dbus_bool_t _dbus_daemon_publish_session_bus_address (const char* address, const void _dbus_daemon_unpublish_session_bus_address (void); -dbus_bool_t _dbus_socket_can_pass_unix_fd(int fd); +dbus_bool_t _dbus_socket_can_pass_unix_fd(DBusSocket fd); /** Opaque type representing an atomically-modifiable integer * that can be used from multiple threads. @@ -438,8 +444,8 @@ dbus_bool_t _dbus_stat (const DBusString *filename, DBusStat *statbuf, DBusError *error); DBUS_PRIVATE_EXPORT -dbus_bool_t _dbus_full_duplex_pipe (int *fd1, - int *fd2, +dbus_bool_t _dbus_full_duplex_pipe (DBusSocket *fd1, + DBusSocket *fd2, dbus_bool_t blocking, DBusError *error); diff --git a/dbus/dbus-transport-socket.c b/dbus/dbus-transport-socket.c index c1e4701..518395a 100644 --- a/dbus/dbus-transport-socket.c +++ b/dbus/dbus-transport-socket.c @@ -604,7 +604,7 @@ do_writing (DBusTransport *transport) if (socket_transport->message_bytes_written <= 0 && DBUS_TRANSPORT_CAN_SEND_UNIX_FD(transport)) { /* Send the fds along with the first byte of the message */ - const int *unix_fds; + const DBusSocket *unix_fds; unsigned n; _dbus_message_get_unix_fds(message, &unix_fds, &n); @@ -821,7 +821,8 @@ do_reading (DBusTransport *transport) #ifdef HAVE_UNIX_FD_PASSING if (DBUS_TRANSPORT_CAN_SEND_UNIX_FD(transport)) { - int *fds, n_fds; + DBusSocket *fds; + int n_fds; if (!_dbus_message_loader_get_unix_fds(transport->loader, &fds, &n_fds)) { -- 1.8.4.5