From fe33b38ac13f89e24651002e0ad471678fdf5ff3 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 13 Feb 2012 19:54:52 +0000 Subject: [PATCH] Make dbus-daemon.exe --print-address work under Windows The DBusPipe code was broken by commit 6e214b5b3c2837, which switched from C runtime API to Win32 API for WinCE's benefit. In a DBusPipe, fd_or_handle is in fact always a C runtime file descriptor, which can't be used with the Win32 API (which expects a HANDLE). This commit goes back to the C runtime API. It might cause WinCE support to regress, but at least dbus-daemon.exe --print-address works again. This is enough to make a few tests work under Wine when cross-compiling from Linux to mingw-w64: in particular, this now works: DBUS_TEST_DAEMON=bus/dbus-daemon.exe DBUS_TEST_DATA=test/data \ wine test/test-dbus-daemon.exe -p /echo/session Signed-off-by: Simon McVittie --- dbus/dbus-pipe-unix.c | 4 ++-- dbus/dbus-pipe-win.c | 26 +++++++++++++------------- dbus/dbus-pipe.c | 10 +++++----- dbus/dbus-pipe.h | 4 ++-- dbus/dbus-sysdeps-util-unix.c | 4 ++-- dbus/dbus-sysdeps-util-win.c | 2 +- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/dbus/dbus-pipe-unix.c b/dbus/dbus-pipe-unix.c index 1a2806e..cfc5704 100644 --- a/dbus/dbus-pipe-unix.c +++ b/dbus/dbus-pipe-unix.c @@ -50,7 +50,7 @@ _dbus_pipe_write (DBusPipe *pipe, { int written; - written = _dbus_write (pipe->fd_or_handle, buffer, start, len); + written = _dbus_write (pipe->fd, buffer, start, len); if (written < 0) { dbus_set_error (error, DBUS_ERROR_FAILED, @@ -71,7 +71,7 @@ int _dbus_pipe_close (DBusPipe *pipe, DBusError *error) { - if (!_dbus_close (pipe->fd_or_handle, error)) + if (!_dbus_close (pipe->fd, error)) { return -1; } diff --git a/dbus/dbus-pipe-win.c b/dbus/dbus-pipe-win.c index f734518..9c7c257 100644 --- a/dbus/dbus-pipe-win.c +++ b/dbus/dbus-pipe-win.c @@ -29,6 +29,7 @@ #include "dbus-pipe.h" #include +#include /** * write data to a pipe. @@ -47,19 +48,18 @@ _dbus_pipe_write (DBusPipe *pipe, int len, DBusError *error) { - DWORD written; - BOOL res; - const char *buffer_c = _dbus_string_get_const_data (buffer); + int written; - res = WriteFile ((HANDLE) pipe->fd_or_handle, buffer_c + start, len, &written, NULL); - if (res == 0 || written < 0) - { - dbus_set_error (error, DBUS_ERROR_FAILED, - "Writing to pipe: %s\n", - _dbus_strerror_from_errno ()); - } - return written; + written = _write (pipe->fd, buffer_c + start, len); + + if (written >= 0) + return written; + + dbus_set_error (error, _dbus_error_from_system_errno (), + "Writing to pipe: %s", + _dbus_strerror_from_errno ()); + return -1; } /** @@ -75,10 +75,10 @@ _dbus_pipe_close (DBusPipe *pipe, { _DBUS_ASSERT_ERROR_IS_CLEAR (error); - if (CloseHandle ((HANDLE) pipe->fd_or_handle) == 0) + if (_close (pipe->fd) != 0) { dbus_set_error (error, _dbus_error_from_system_errno (), - "Could not close pipe %d: %s", pipe->fd_or_handle, + "Could not close pipe fd %d: %s", pipe->fd, _dbus_strerror_from_errno ()); return -1; } diff --git a/dbus/dbus-pipe.c b/dbus/dbus-pipe.c index 06560f1..7b5fe6d 100644 --- a/dbus/dbus-pipe.c +++ b/dbus/dbus-pipe.c @@ -33,9 +33,9 @@ */ void _dbus_pipe_init (DBusPipe *pipe, - intptr_t fd) + int fd) { - pipe->fd_or_handle = fd; + pipe->fd = fd; } /** @@ -59,7 +59,7 @@ _dbus_pipe_init_stdout (DBusPipe *pipe) dbus_bool_t _dbus_pipe_is_valid(DBusPipe *pipe) { - return pipe->fd_or_handle >= 0; + return pipe->fd >= 0; } /** @@ -71,7 +71,7 @@ _dbus_pipe_is_valid(DBusPipe *pipe) dbus_bool_t _dbus_pipe_is_stdout_or_stderr (DBusPipe *pipe) { - return pipe->fd_or_handle == 1 || pipe->fd_or_handle == 2; + return pipe->fd == 1 || pipe->fd == 2; } /** @@ -81,5 +81,5 @@ _dbus_pipe_is_stdout_or_stderr (DBusPipe *pipe) void _dbus_pipe_invalidate (DBusPipe *pipe) { - pipe->fd_or_handle = -1; + pipe->fd = -1; } diff --git a/dbus/dbus-pipe.h b/dbus/dbus-pipe.h index f6eac5f..c2063b5 100644 --- a/dbus/dbus-pipe.h +++ b/dbus/dbus-pipe.h @@ -39,11 +39,11 @@ #include struct DBusPipe { - intptr_t fd_or_handle; + int fd; }; void _dbus_pipe_init (DBusPipe *pipe, - intptr_t fd); + int fd); void _dbus_pipe_init_stdout (DBusPipe *pipe); int _dbus_pipe_write (DBusPipe *pipe, const DBusString *buffer, diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c index a1915cb..ef86d73 100644 --- a/dbus/dbus-sysdeps-util-unix.c +++ b/dbus/dbus-sysdeps-util-unix.c @@ -254,8 +254,8 @@ _dbus_write_pid_to_file_and_pipe (const DBusString *pidfile, DBusString pid; int bytes; - _dbus_verbose ("writing our pid to pipe %"PRIuPTR"\n", - print_pid_pipe->fd_or_handle); + _dbus_verbose ("writing our pid to pipe %d\n", + print_pid_pipe->fd); if (!_dbus_string_init (&pid)) { diff --git a/dbus/dbus-sysdeps-util-win.c b/dbus/dbus-sysdeps-util-win.c index f5646f3..111db9e 100644 --- a/dbus/dbus-sysdeps-util-win.c +++ b/dbus/dbus-sysdeps-util-win.c @@ -191,7 +191,7 @@ _dbus_write_pid_to_file_and_pipe (const DBusString *pidfile, DBusString pid; int bytes; - _dbus_verbose ("writing our pid to pipe %d\n", print_pid_pipe->fd_or_handle); + _dbus_verbose ("writing our pid to pipe %d\n", print_pid_pipe->fd); if (!_dbus_string_init (&pid)) { -- 1.7.9