Commit 1e35c693 authored by Simon McVittie's avatar Simon McVittie

Make dbus-daemon.exe --print-address work under Windows

The DBusPipe code was broken by commit 6e214b5b, 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=46049Signed-off-by: default avatarSimon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Ralf Habacker's avatarRalf Habacker <ralf.habacker@freenet.de>
parent 5ed44952
......@@ -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;
}
......
......@@ -29,6 +29,7 @@
#include "dbus-pipe.h"
#include <windows.h>
#include <io.h>
/**
* 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;
}
......
......@@ -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;
}
......@@ -39,11 +39,11 @@
#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,
......
......@@ -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))
{
......
......@@ -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))
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment