dbus/dbus dbus-sysdeps-unix.c, 1.23, 1.24 dbus-sysdeps-win.c, 1.7, 1.8 dbus-sysdeps.c, 1.120, 1.121

Ralf Habacker rhabacker at kemper.freedesktop.org
Tue Mar 13 10:14:37 PDT 2007


Update of /cvs/dbus/dbus/dbus
In directory kemper:/tmp/cvs-serv5963/dbus

Modified Files:
	dbus-sysdeps-unix.c dbus-sysdeps-win.c dbus-sysdeps.c 
Log Message:
* dbus/dbus-sysdeps-win.c: fixed broken DBusPipe on win32. 
* dbus/dbus-sysdeps-win.c, dbus/dbus-sysdeps-unix.c: moved platform independent DBusPipe function to dbus-sysdeps.c.

Index: dbus-sysdeps-unix.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps-unix.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- dbus-sysdeps-unix.c	12 Mar 2007 22:52:40 -0000	1.23
+++ dbus-sysdeps-unix.c	13 Mar 2007 17:14:35 -0000	1.24
@@ -170,30 +170,6 @@
 }
 
 /**
- * init a pipe instance.
- *
- * @param pipe the pipe
- * @param fd the file descriptor to init from 
- */
-void
-_dbus_pipe_init (DBusPipe *pipe,
-                 int       fd)
-{
-  pipe->fd_or_handle = fd;
-}
-
-/**
- * init a pipe with stdout
- *
- * @param pipe the pipe
- */
-void
-_dbus_pipe_init_stdout (DBusPipe *pipe)
-{
-  _dbus_pipe_init (pipe, 1);
-}
-
-/**
  * write data to a pipe.
  *
  * @param pipe the pipe instance
@@ -245,41 +221,6 @@
 }
 
 /**
- * check if a pipe is valid; pipes can be set invalid, similar to
- * a -1 file descriptor.
- *
- * @param pipe the pipe instance
- * @returns #FALSE if pipe is not valid
- */
-dbus_bool_t
-_dbus_pipe_is_valid(DBusPipe *pipe)
-{
-  return pipe->fd_or_handle >= 0;
-}
-
-/**
- * Check if a pipe is stdout or stderr.
- *
- * @param pipe the pipe instance
- * @returns #TRUE if pipe is one of the standard out/err channels
- */
-dbus_bool_t
-_dbus_pipe_is_stdout_or_stderr (DBusPipe *pipe)
-{
-  return pipe->fd_or_handle == 1 || pipe->fd_or_handle == 2;
-}
-
-/**
- * Initializes a pipe to an invalid value.
- * @param pipe the pipe
- */
-void
-_dbus_pipe_invalidate (DBusPipe *pipe)
-{
-  pipe->fd_or_handle = -1;
-}
-
-/**
  * Like _dbus_write_two() but only works on sockets and is thus
  * available on Windows.
  * 

Index: dbus-sysdeps-win.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps-win.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- dbus-sysdeps-win.c	13 Mar 2007 16:56:32 -0000	1.7
+++ dbus-sysdeps-win.c	13 Mar 2007 17:14:35 -0000	1.8
@@ -267,54 +267,33 @@
 }
 
 /**
- * init a pipe instance.
- *
- * @param fd the file descriptor to init from 
- * @returns a DBusPipe instance
- */
-DBusPipe _dbus_pipe_init(int         fd)
-{
-	DBusPipe pipe;
-	pipe.fd = fd;
-	return pipe;
-}
-
-/**
  * write data to a pipe.
  *
  * @param pipe the pipe instance
  * @param buffer the buffer to write data from
  * @param start the first byte in the buffer to write
  * @param len the number of bytes to try to write
+ * @param error error return
  * @returns the number of bytes written or -1 on error
  */
 int
-_dbus_pipe_write (DBusPipe          pipe,
+_dbus_pipe_write (DBusPipe         *pipe,
                   const DBusString *buffer,
                   int               start,
-                  int               len)
-{
-	DBusFile file;
-	file.FDATA = pipe.fd;
-	return _dbus_file_write(&file, buffer, start, len);
-}
-
-/**
- * read data from a pipe.
- *
- * @param pipe the pipe instance
- * @param buffer the buffer to read data in
- * @param count the number of bytes to try to read
- * @returns the number of bytes read or -1 on error
- */
-int
-_dbus_pipe_read(DBusPipe    pipe,
-                DBusString *buffer,
-                int         count)
+                  int               len,
+                  DBusError        *error)
 {
-	DBusFile file;
-	file.FDATA = pipe.fd;
-	return _dbus_file_read(&file, buffer, count);
+  int written;
+  DBusFile file;
+  file.FDATA = pipe->fd_or_handle;
+  written = _dbus_file_write (&file, buffer, start, len);
+  if (written < 0)
+    {
+      dbus_set_error (error, DBUS_ERROR_FAILED,
+                      "Writing to pipe: %s\n",
+                      _dbus_strerror (errno));
+    }
+  return written;
 }
 
 /**
@@ -324,37 +303,21 @@
  * @param error return location for an error
  * @returns #FALSE if error is set
  */
- int
-_dbus_pipe_close(DBusPipe    pipe,
-                 DBusError    *error)
-{
-	DBusFile file;
-	file.FDATA = pipe.fd;
-	return _dbus_file_close(&file, error);
-}
-
-/**
- * check if a pipe is valid, which means is constructed
- * by a valid file descriptor
- *
- * @param pipe the pipe instance
- * @returns #FALSE if pipe is not valid
- */
-dbus_bool_t _dbus_pipe_is_valid(DBusPipe pipe)
-{
-	return pipe.fd >= 0;
-}
-
-/**
- * check if a pipe is a special pipe, which means using 
- * a non default file descriptor (>2)
- *
- * @param pipe the pipe instance
- * @returns #FALSE if pipe is not a special pipe
- */
-dbus_bool_t _dbus_pipe_is_special(DBusPipe pipe)
+int
+_dbus_pipe_close  (DBusPipe         *pipe,
+                   DBusError        *error)
 {
-	return pipe.fd > 2;
+  DBusFile file;
+  file.FDATA = pipe->fd_or_handle;
+  if (_dbus_file_close (&file, error) < 0)
+    {
+      return -1;
+    }
+  else
+    {
+      _dbus_pipe_invalidate (pipe);
+      return 0;
+    }
 }
 
 #undef FDATA
@@ -3660,28 +3623,28 @@
 write_credentials_byte (int            handle,
                         DBusError      *error)
 {
-/* FIXME: for the session bus credentials shouldn't matter (?), but
- * for the system bus they are presumably essential. A rough outline
- * of a way to implement the credential transfer would be this:
- *
- * client waits to *read* a byte.
- *
- * server creates a named pipe with a random name, sends a byte
- * contining its length, and its name.
- *
- * client reads the name, connects to it (using Win32 API).
- *
- * server waits for connection to the named pipe, then calls
- * ImpersonateNamedPipeClient(), notes its now-current credentials,
- * calls RevertToSelf(), closes its handles to the named pipe, and
- * is done. (Maybe there is some other way to get the SID of a named
- * pipe client without having to use impersonation?)
- *
- * client closes its handles and is done.
- * 
- * Ralf: Why not sending credentials over the given this connection ?
- * Using named pipes makes it impossible to be connected from a unix client.  
- *
+/* FIXME: for the session bus credentials shouldn't matter (?), but
+ * for the system bus they are presumably essential. A rough outline
+ * of a way to implement the credential transfer would be this:
+ *
+ * client waits to *read* a byte.
+ *
+ * server creates a named pipe with a random name, sends a byte
+ * contining its length, and its name.
+ *
+ * client reads the name, connects to it (using Win32 API).
+ *
+ * server waits for connection to the named pipe, then calls
+ * ImpersonateNamedPipeClient(), notes its now-current credentials,
+ * calls RevertToSelf(), closes its handles to the named pipe, and
+ * is done. (Maybe there is some other way to get the SID of a named
+ * pipe client without having to use impersonation?)
+ *
+ * client closes its handles and is done.
+ * 
+ * Ralf: Why not sending credentials over the given this connection ?
+ * Using named pipes makes it impossible to be connected from a unix client.  
+ *
  */
   int bytes_written;
   DBusString buf; 

Index: dbus-sysdeps.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps.c,v
retrieving revision 1.120
retrieving revision 1.121
diff -u -d -r1.120 -r1.121
--- dbus-sysdeps.c	1 Jan 2007 21:29:59 -0000	1.120
+++ dbus-sysdeps.c	13 Mar 2007 17:14:35 -0000	1.121
@@ -172,6 +172,65 @@
   return getenv (varname);
 }
 
+/*
+ * init a pipe instance.
+ *
+ * @param pipe the pipe
+ * @param fd the file descriptor to init from 
+ */
+void
+_dbus_pipe_init (DBusPipe *pipe,
+                 int       fd)
+{
+  pipe->fd_or_handle = fd;
+}
+
+/**
+ * init a pipe with stdout
+ *
+ * @param pipe the pipe
+ */
+void
+_dbus_pipe_init_stdout (DBusPipe *pipe)
+{
+  _dbus_pipe_init (pipe, 1);
+}
+
+/**
+ * check if a pipe is valid; pipes can be set invalid, similar to
+ * a -1 file descriptor.
+ *
+ * @param pipe the pipe instance
+ * @returns #FALSE if pipe is not valid
+ */
+dbus_bool_t
+_dbus_pipe_is_valid(DBusPipe *pipe)
+{
+  return pipe->fd_or_handle >= 0;
+}
+
+/**
+ * Check if a pipe is stdout or stderr.
+ *
+ * @param pipe the pipe instance
+ * @returns #TRUE if pipe is one of the standard out/err channels
+ */
+dbus_bool_t
+_dbus_pipe_is_stdout_or_stderr (DBusPipe *pipe)
+{
+  return pipe->fd_or_handle == 1 || pipe->fd_or_handle == 2;
+}
+
+/**
+ * Initializes a pipe to an invalid value.
+ * @param pipe the pipe
+ */
+void
+_dbus_pipe_invalidate (DBusPipe *pipe)
+{
+  pipe->fd_or_handle = -1;
+}
+
 /** @} */
 
 /**



More information about the dbus-commit mailing list