[systemd-devel] [PATCH 4/4] gdbus: Add basic kdbus tests

2013-11-21 Thread Karol Lewandowski
---
 configure.ac  |   1 +
 gio/tests/Makefile.am |  13 +++
 gio/tests/kdbus-test/README   | 108 
 gio/tests/kdbus-test/gdbus-example-kdbus-client.c |  51 ++
 gio/tests/kdbus-test/gdbus-example-kdbus-server.c | 117 ++
 5 files changed, 290 insertions(+)
 create mode 100644 gio/tests/kdbus-test/README
 create mode 100644 gio/tests/kdbus-test/gdbus-example-kdbus-client.c
 create mode 100644 gio/tests/kdbus-test/gdbus-example-kdbus-server.c

diff --git a/configure.ac b/configure.ac
index 413c9f2..c3349c4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -264,6 +264,7 @@ AS_IF([test x$enable_gc_friendly = xyes], [
 ], [ AC_MSG_RESULT([no]) ])
 
 AC_MSG_CHECKING([kdbus transport])
+AM_CONDITIONAL(KDBUS_TRANSPORT, [test x$enable_kdbus_transport = xyes])
 AS_IF([test x$enable_kdbus_transport = xyes], [
   AC_DEFINE(KDBUS_TRANSPORT, 1, [Define if kdbus transport is enabled])
   AC_MSG_RESULT([yes])
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index bec70d7..8d692bb 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -470,6 +470,19 @@ gdbus_serialization_SOURCES = \
gdbus-tests.c
 endif
 
+if KDBUS_TRANSPORT
+test_programs += gdbus-example-kdbus-server
+test_programs += gdbus-example-kdbus-client
+
+gdbus_example_kdbus_server_CFLAGS = $(AM_CFLAGS) $(DBUS1_CFLAGS)
+gdbus_example_kdbus_server_LDADD = $(LDADD) $(DBUS1_LIBS)
+gdbus_example_kdbus_server_SOURCES = kdbus-test/gdbus-example-kdbus-server.c
+
+gdbus_example_kdbus_client_CFLAGS = $(AM_CFLAGS) $(DBUS1_CFLAGS)
+gdbus_example_kdbus_client_LDADD = $(LDADD) $(DBUS1_LIBS)
+gdbus_example_kdbus_client_SOURCES = kdbus-test/gdbus-example-kdbus-client.c
+endif
+
 # -
 #  The resources test is a bit more complicated...
 
diff --git a/gio/tests/kdbus-test/README b/gio/tests/kdbus-test/README
new file mode 100644
index 000..6f44f0b
--- /dev/null
+++ b/gio/tests/kdbus-test/README
@@ -0,0 +1,108 @@
+Description
+===
+
+In order to perform tests of modified libgio library (with kdbus
+transport) we have created two programs: gdbus-example-kdbus-server
+and gdbus-example-kdbus-client.  The first of them acts as a server,
+registers itself on the bus under well-known name and waits for calls
+to its objects and methods. The second one (client) makes calls and
+records periods of time between moment of preparing of a call to the
+moment of receiving and parsing an answer. The measurement is made by
+performing one thousand of calls and computing a sum of duration of
+every call (for different sizes of message payload: 4B, 8B, 4kB, 8kB,
+16kB, 64kB and 512kB).  The client program returns total time of
+performed calls after successful execution.
+
+
+Requirements
+
+
+* kdbus kernel module,
+* modified version of glib (with kdbus transport),
+* modified version of dbus-daemon (with kdbus transport),
+
+
+KDBUS
+=
+
+Simple install procedure:
+
+  % git clone https://github.com/gregkh/kdbus.git# download kdbus source
+  % cd kdbus # change to kdbus 
directory
+  % make # build kdbus module
+  % insmod kdbus.ko  # load kdbus kernel module
+
+
+GLIB (modified version)
+===
+
+Simple install procedure:
+
+
+  % cd glib # change to glib directory
+  % ./configure --enable-kdbus-transport# run the `configure' 
script with kdbus support
+  % make# build GLIB
+
+
+DBUS-DAEMON (modified version)
+==
+
+Modified version of dbus-daemon (from tizen.org) is required to run
+kdbus transport in libgio.
+
+Solution, which we propose, includes modifications both in client
+libraries (libgio, libdbus) and dbus daemon. Daemon is registered on
+kdbus bus as a client under org.freedesktop.DBus name.  Only
+messages addressed to this interface are handled by daemon. Messages
+such as RequestName or AddMatch are translated by daemon to respective
+ioctl() calls, which send them through kdbus on behalf of original
+client process. The rest of messages would are going straight from
+origin to destination through kdbus.
+
+Simple install procedure:
+
+* download modified version of dbus from tizen.org repository
+  (kdbus-dev branch):
+
+  git clone git://review.tizen.org/platform/upstream/dbus.git -b kdbus-dev
+
+* change to dbus directory and build dbus-daemon with kdbus support:
+
+  ./configure --enable-kdbus-transport
+  make  make install
+
+* start of custom dbus-daemon supporting kdbus transport:
+
+  ./dbus-daemon --nofork --address=kdbus: 
--config-file=/etc/dbus-1/session.conf
+
+
+TESTS
+=
+
+* Build test binaries:
+
+  cd gio/tests
+  make
+
+* Set variable to use 

[systemd-devel] [PATCH 1/4] gdbus: Import kdbus interface header

2013-11-21 Thread Karol Lewandowski
kdbus.h taken from git://github.com/gregkh/kdbus, commit cc5b49c0d.
---
 gio/kdbus.h | 436 
 1 file changed, 436 insertions(+)
 create mode 100644 gio/kdbus.h

diff --git a/gio/kdbus.h b/gio/kdbus.h
new file mode 100644
index 000..06c2c24
--- /dev/null
+++ b/gio/kdbus.h
@@ -0,0 +1,436 @@
+/*
+ * Copyright (C) 2013 Kay Sievers
+ * Copyright (C) 2013 Greg Kroah-Hartman gre...@linuxfoundation.org
+ * Copyright (C) 2013 Linux Foundation
+ * Copyright (C) 2013 Lennart Poettering
+ * Copyright (C) 2013 Daniel Mack dan...@zonque.org
+ *
+ * kdbus is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ */
+
+#ifndef _KDBUS_H_
+#define _KDBUS_H_
+
+#ifndef __KERNEL__
+#include sys/ioctl.h
+#include sys/types.h
+#include linux/types.h
+#endif
+
+#define KDBUS_IOC_MAGIC0x95
+#define KDBUS_SRC_ID_KERNEL(0)
+#define KDBUS_DST_ID_WELL_KNOWN_NAME   (0)
+#define KDBUS_MATCH_SRC_ID_ANY (~0ULL)
+#define KDBUS_DST_ID_BROADCAST (~0ULL)
+
+/* Common first elements in a structure which are used to iterate over
+ * a list of elements. */
+#define KDBUS_PART_HEADER \
+   struct {\
+   __u64 size; \
+   __u64 type; \
+   }
+
+/* Message sent from kernel to userspace, when the owner or starter of
+ * a well-known name changes */
+struct kdbus_manager_msg_name_change {
+   __u64 old_id;
+   __u64 new_id;
+   __u64 flags;/* 0 or (possibly?) KDBUS_NAME_IN_QUEUE 
*/
+   char name[0];
+};
+
+struct kdbus_manager_msg_id_change {
+   __u64 id;
+   __u64 flags;/* The kernel flags field from 
KDBUS_HELLO */
+};
+
+struct kdbus_creds {
+   __u64 uid;
+   __u64 gid;
+   __u64 pid;
+   __u64 tid;
+
+   /* The starttime of the process PID. This is useful to detect
+   PID overruns from the client side. i.e. if you use the PID to
+   look something up in /proc/$PID/ you can afterwards check the
+   starttime field of it to ensure you didn't run into a PID
+   ovretun. */
+   __u64 starttime;
+};
+
+struct kdbus_audit {
+   __u64 sessionid;
+   __u64 loginuid;
+};
+
+struct kdbus_timestamp {
+   __u64 monotonic_ns;
+   __u64 realtime_ns;
+};
+
+struct kdbus_vec {
+   __u64 size;
+   union {
+   __u64 address;
+   __u64 offset;
+   };
+};
+
+struct kdbus_memfd {
+   __u64 size;
+   int fd;
+   __u32 __pad;
+};
+
+/* Message Item Types */
+enum {
+   _KDBUS_MSG_NULL,
+
+   /* Filled in by userspace */
+   KDBUS_MSG_PAYLOAD_VEC,  /* .data_vec, reference to memory area 
*/
+   KDBUS_MSG_PAYLOAD_OFF,  /* .data_vec, reference to memory area 
*/
+   KDBUS_MSG_PAYLOAD_MEMFD,/* file descriptor of a special data 
file */
+   KDBUS_MSG_FDS,  /* .data_fds of file descriptors */
+   KDBUS_MSG_BLOOM,/* for broadcasts, carries bloom filter 
blob in .data */
+   KDBUS_MSG_DST_NAME, /* destination's well-known name, in 
.str */
+   KDBUS_MSG_PRIORITY, /* queue priority for message */
+
+   /* Filled in by kernelspace */
+   KDBUS_MSG_SRC_NAMES = 0x400,/* NUL separated string list with 
well-known names of source */
+   KDBUS_MSG_TIMESTAMP,/* .timestamp */
+   KDBUS_MSG_SRC_CREDS,/* .creds */
+   KDBUS_MSG_SRC_PID_COMM, /* optional, in .str */
+   KDBUS_MSG_SRC_TID_COMM, /* optional, in .str */
+   KDBUS_MSG_SRC_EXE,  /* optional, in .str */
+   KDBUS_MSG_SRC_CMDLINE,  /* optional, in .str (a chain of NUL 
str) */
+   KDBUS_MSG_SRC_CGROUP,   /* optional, in .str */
+   KDBUS_MSG_SRC_CAPS, /* caps data blob, in .data */
+   KDBUS_MSG_SRC_SECLABEL, /* NUL terminated string, in .str */
+   KDBUS_MSG_SRC_AUDIT,/* .audit */
+
+   /* Special messages from kernel, consisting of one and only one of 
these data blocks */
+   KDBUS_MSG_NAME_ADD  = 0x800,/* .name_change */
+   KDBUS_MSG_NAME_REMOVE,  /* .name_change */
+   KDBUS_MSG_NAME_CHANGE,  /* .name_change */
+   KDBUS_MSG_ID_ADD,   /* .id_change */
+   KDBUS_MSG_ID_REMOVE,/* .id_change */
+   KDBUS_MSG_REPLY_TIMEOUT,/* empty, but .reply_cookie in 
.kdbus_msg is filled in */
+   KDBUS_MSG_REPLY_DEAD,   /* dito */
+};
+
+/**
+ * struct  kdbus_item - chain of data blocks
+ *
+ * size: overall data record size
+ * type: 

[systemd-devel] [PATCH 0/4] [RFC v1] gdbus: Preliminary kdbus-support patches

2013-11-21 Thread Karol Lewandowski
[ Cced systemd-devel@ and dev@tizen mailing lists in case someone
  there would be interested too. ]

Folks,

We have recently started experimenting with possibilities of
adding kdbus-support to glib's gio.  Following patchset is
result of our work.

Please note this is cleanup of modifications available from
Tizen repositories (please see notes for details), rebased on
top of glib's master branch - 6f7d8f6294 (gbacktrace: Print
out gdb exec errors correctly).


What we would like to accomplish by this RFC is to gather 
feedback if our approach for glib modifications is sound
for you (we do not know glib code that well).


In short:

 - This patchset adds ability for glib programs to connect
   to kdbus busses via

 DBUS_SESSION_BUS_ADDRESS=(kernel|kdbus):/dev/kdbus/0-kdbus/bus 

 - Library modifications are not all, it's required to have
   service handling org.freedesktop.DBus requests in userspace.

   Currently we use modified[3] dbus-daemon to for that
   purpose.

 - Basic functionality works - sending/receiving messages,
   signals, name registration, etc.

 - Last patch contains basic tests accompanied with README,
   please take a look there too.


We will be happy to hear any and all of your comments.

Thanks!


Notes:
==

This code originates from Tizen[1], and was imported[2] by
Ryan Lortie into glib's tizen/kdbus-dev branch.

  [1] 
https://review.tizen.org/gerrit/gitweb?p=platform%2Fupstream%2Fglib.git;a=summary
  
  git://review.tizen.org/platform/upstream/glib kdbus-dev

  [2] https://git.gnome.org/browse/glib/log/?h=tizen/kdbus-dev

We are the same people that did that work, precisely Lukasz Skalski
and Michal Eljasiewicz wrote all the code, I just gave it finishing
touches.

We think this patchset could replace glibs tizen/kdbus-dev iff you
think that it's worth to keep kdbus support code in main repo at
all. ;)   (At this point in time, that is!)

Moreover, we would be more than happy to work directly on that
branch, if you find it feasible.


kdbus-enabled dbus-daemon is available here:

  [3]  git://review.tizen.org/platform/upstream/dbus kdbus-dev

We are aware that in future it will be probably systemd role
to provide it (I've seen that Daniel Mack is already working
on it).


Karol Lewandowski (4):
  gdbus: Import kdbus interface header
  gdbus: Add preliminary implementation of kdbus support
  gdbus: Integrate kdbus into GDBus core
  gdbus: Add basic kdbus tests

 configure.ac  |   11 +
 gio/Makefile.am   |4 +
 gio/gdbusaddress.c|   80 +-
 gio/gdbusconnection.c |   20 +-
 gio/gdbusprivate.c|  211 +++-
 gio/gdbusprivate.h|8 +-
 gio/giotypes.h|   33 +
 gio/gkdbus.c  | 1112 +
 gio/gkdbus.h  |  113 +++
 gio/gkdbusconnection.c|  196 
 gio/gkdbusconnection.h|   91 ++
 gio/kdbus.h   |  436 
 gio/tests/Makefile.am |   13 +
 gio/tests/kdbus-test/README   |  108 ++
 gio/tests/kdbus-test/gdbus-example-kdbus-client.c |   51 +
 gio/tests/kdbus-test/gdbus-example-kdbus-server.c |  117 +++
 16 files changed, 2572 insertions(+), 32 deletions(-)
 create mode 100644 gio/gkdbus.c
 create mode 100644 gio/gkdbus.h
 create mode 100644 gio/gkdbusconnection.c
 create mode 100644 gio/gkdbusconnection.h
 create mode 100644 gio/kdbus.h
 create mode 100644 gio/tests/kdbus-test/README
 create mode 100644 gio/tests/kdbus-test/gdbus-example-kdbus-client.c
 create mode 100644 gio/tests/kdbus-test/gdbus-example-kdbus-server.c

-- 
1.8.4.rc3

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 3/4] gdbus: Integrate kdbus into GDBus core

2013-11-21 Thread Karol Lewandowski
This commit hooks kdbus into GDBus and provides
--enable-kdbus-transport configure switch.
---
 configure.ac  |  10 +++
 gio/Makefile.am   |   4 +
 gio/gdbusaddress.c|  80 +++
 gio/gdbusconnection.c |  20 -
 gio/gdbusprivate.c| 211 ++
 gio/gdbusprivate.h|   8 +-
 gio/giotypes.h|  33 
 7 files changed, 334 insertions(+), 32 deletions(-)

diff --git a/configure.ac b/configure.ac
index deacdc1..413c9f2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -242,6 +242,10 @@ AC_ARG_ENABLE(gc_friendly,
   [AS_HELP_STRING([--enable-gc-friendly],
   [turn on garbage collector friendliness 
[default=no]])],,
   [enable_gc_friendly=no])
+AC_ARG_ENABLE(kdbus_transport,
+  [AS_HELP_STRING([--enable-kdbus-transport],
+ [enable kdbus transport [default=no]])],,
+  [enable_kdbus_transport=no])
 AC_ARG_ENABLE(mem_pools,
   [AS_HELP_STRING([--disable-mem-pools],
  [disable all glib memory pools])],,
@@ -259,6 +263,12 @@ AS_IF([test x$enable_gc_friendly = xyes], [
   AC_MSG_RESULT([yes])
 ], [ AC_MSG_RESULT([no]) ])
 
+AC_MSG_CHECKING([kdbus transport])
+AS_IF([test x$enable_kdbus_transport = xyes], [
+  AC_DEFINE(KDBUS_TRANSPORT, 1, [Define if kdbus transport is enabled])
+  AC_MSG_RESULT([yes])
+], [ AC_MSG_RESULT([no]) ])
+
 AC_MSG_CHECKING([whether to disable memory pools])
 AS_IF([test x$disable_mem_pools = xno], [
   AC_MSG_RESULT([no])
diff --git a/gio/Makefile.am b/gio/Makefile.am
index 5b6cda1..c060ef2 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -394,6 +394,8 @@ libgio_2_0_la_SOURCES = \
giostream.c \
gioprivate.h\
giowin32-priv.h \
+   gkdbus.c\
+   gkdbusconnection.c  \
gloadableicon.c \
gmount.c\
gmemoryinputstream.c\
@@ -569,6 +571,8 @@ gio_headers =   \
giomodule.h \
gioscheduler.h  \
giostream.h \
+   gkdbus.h\
+   gkdbusconnection.h  \
gloadableicon.h \
gmount.h\
gmemoryinputstream.h\
diff --git a/gio/gdbusaddress.c b/gio/gdbusaddress.c
index b5143cf..bed0bbe 100644
--- a/gio/gdbusaddress.c
+++ b/gio/gdbusaddress.c
@@ -1,6 +1,7 @@
 /* GDBus - GLib D-Bus Library
  *
  * Copyright (C) 2008-2010 Red Hat, Inc.
+ * Copyright (C) 2013 Samsung Electronics
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -17,7 +18,9 @@
  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  * Boston, MA 02111-1307, USA.
  *
- * Author: David Zeuthen dav...@redhat.com
+ * Author: David Zeuthendav...@redhat.com
+ * Author: Lukasz Skalski   l.skal...@partner.samsung.com
+ * Author: Michal Eljasiewicz   m.eljasie...@samsung.com
  */
 
 #include config.h
@@ -44,6 +47,7 @@
 
 #ifdef G_OS_UNIX
 #include gio/gunixsocketaddress.h
+#include gio/gkdbusconnection.h
 #endif
 
 #ifdef G_OS_WIN32
@@ -360,6 +364,18 @@ is_valid_tcp (const gchar  *address_entry,
   return ret;
 }
 
+static int
+g_dbus_is_supported_address_kdbus (const gchar  *transport_name)
+{
+  int supported = 0;
+
+#if defined (G_OS_UNIX)  (KDBUS_TRANSPORT)
+  supported = (g_strcmp0 (transport_name, kdbus) == 0) || (g_strcmp0 
(transport_name, kernel) == 0);
+#endif
+
+  return supported;
+}
+
 /**
  * g_dbus_is_supported_address:
  * @string: A string.
@@ -401,7 +417,8 @@ g_dbus_is_supported_address (const gchar  *string,
 goto out;
 
   supported = FALSE;
-  if (g_strcmp0 (transport_name, unix) == 0)
+  if ((g_strcmp0 (transport_name, unix) == 0)
+  || g_dbus_is_supported_address_kdbus (transport_name))
 supported = is_valid_unix (a[n], key_value_pairs, error);
   else if (g_strcmp0 (transport_name, tcp) == 0)
 supported = is_valid_tcp (a[n], key_value_pairs, error);
@@ -553,7 +570,8 @@ g_dbus_address_connect (const gchar   *address_entry,
 {
 }
 #ifdef G_OS_UNIX
-  else if (g_strcmp0 (transport_name, unix) == 0)
+  if ((g_strcmp0 (transport_name, unix) == 0)
+  || g_dbus_is_supported_address_kdbus (transport_name))
 {
   const gchar *path;
   const gchar *abstract;
@@ -664,21 +682,49 @@ g_dbus_address_connect (const gchar   *address_entry,
 
   if (connectable != NULL)
 {
-  GSocketClient *client;
-  GSocketConnection *connection;
-
-  g_assert (ret == NULL);
-  client = g_socket_client_new ();
-  connection = g_socket_client_connect (client,
-connectable,
-cancellable,
-error);
-