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
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=46049
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
{
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,
_dbus_pipe_close (DBusPipe *pipe,
DBusError *error)
{
- if (!_dbus_close (pipe->fd_or_handle, error))
+ if (!_dbus_close (pipe->fd, error))
{
return -1;
}
#include "dbus-pipe.h"
#include <windows.h>
+#include <io.h>
/**
* write data to a 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;
}
/**
{
_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;
}
*/
void
_dbus_pipe_init (DBusPipe *pipe,
- intptr_t fd)
+ int fd)
{
- pipe->fd_or_handle = fd;
+ pipe->fd = fd;
}
/**
dbus_bool_t
_dbus_pipe_is_valid(DBusPipe *pipe)
{
- return pipe->fd_or_handle >= 0;
+ return pipe->fd >= 0;
}
/**
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;
}
/**
void
_dbus_pipe_invalidate (DBusPipe *pipe)
{
- pipe->fd_or_handle = -1;
+ pipe->fd = -1;
}
#include <dbus/dbus-sysdeps.h>
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,
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))
{
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))
{