Make dbus-daemon.exe --print-address work under Windows
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 13 Feb 2012 19:54:52 +0000 (19:54 +0000)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 28 Feb 2012 12:37:41 +0000 (12:37 +0000)
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>
dbus/dbus-pipe-unix.c
dbus/dbus-pipe-win.c
dbus/dbus-pipe.c
dbus/dbus-pipe.h
dbus/dbus-sysdeps-util-unix.c
dbus/dbus-sysdeps-util-win.c

index 1a2806e..cfc5704 100644 (file)
@@ -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;
     }
index f734518..9c7c257 100644 (file)
@@ -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;
     }
index 06560f1..7b5fe6d 100644 (file)
@@ -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;
 }
index f6eac5f..c2063b5 100644 (file)
 #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,
index a1915cb..ef86d73 100644 (file)
@@ -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))
         {
index f5646f3..111db9e 100644 (file)
@@ -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))
         {