Re: [systemd-devel] dbus-1/kdbus - question about 'queued owners'

2015-04-13 Thread Lukasz Skalski
On 04/13/2015 01:46 PM, Daniel Mack wrote:
> Hi Lukasz,
> 

Hi,

> [+dbus ML]
> 
> On 04/10/2015 04:20 PM, Lukasz Skalski wrote:
>> Currently I'm working on some testsuite (let's call it dbus1-spec-test)
>> for dbus-1 specification. My idea is to test dbus-1 specification
>> coverage on systems with dbus-daemon and on systems without dbus-daemon
>> (but with latest systemd, bus-proxyd and kdbus) which will allow us (and
>> all userspace apps) to smoothly switch to kdbus. First results of tests
>> are really good:
> 
> Nice, thanks a lot for doing this!
> 
>> My testsuite have found only one inconsistency between dbus-1 and
>> kdbus-enabled system. Problematic testcase (this one tests rather some
>> dbus-daemon/bus-proxyd behaviors than specification) is as follow:
>>
>> test_request_name_6 (void)
>> {
>>   GDBusConnection *connection_a;
>>   GDBusConnection *connection_b;
>>
>>   BusRequestNameFlagsReply request_reply;
>>   BusReleaseNameFlagsReply release_reply;
>>
>>   /* connect and set up two D-Bus client connections */
>>   connection_a = connect_to_bus();
>>   connection_b = connect_to_bus();
>>
>>   /* 'connection_a' - synchronously acquire name on the bus */
>>   request_reply = request_name (connection_a, "org.my.busname",
>> DBUS_NAME_FLAG_REPLACE_EXISTING |
>> DBUS_NAME_FLAG_DO_NOT_QUEUE);
>>
>>   /* 'connection_a' should be primary owner */
>>   CU_ASSERT (request_reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
>>
>>   /* 'connection_b' tries to own the same well-known name */
>>   request_reply = request_name (connection_b, "org.my.busname",
>> DBUS_NAME_FLAG_REPLACE_EXISTING);
>>
>>   /* 'connection_b' should be appended to the queue */
>>   CU_ASSERT (request_reply == DBUS_REQUEST_NAME_REPLY_IN_QUEUE);
>>
>>   /* once again 'connection_b' tries to own the same name */
>>   request_reply = request_name (connection_b, "org.my.busname",
>> DBUS_NAME_FLAG_REPLACE_EXISTING);
>>
>>   /* and once again we should get the same return code */
>>   CU_ASSERT (request_reply == DBUS_REQUEST_NAME_REPLY_IN_QUEUE);
> 
> The D-Bus spec isn't totally clear about the return code here, but it is
> about what should happen:
> 
> "If replacement is not possible, *and the method caller is currently not
> in the queue*, the method caller is appended to the queue."
> 
> dbus-daemon seems to return IN_QUEUE to inform the caller that the name
> is in the queue, no matter if the call it replies to was responsible for
> creating the queue entry or if that was already the case.
> 
>>   /* 'connection_a' releases name */
>>   release_reply = release_name (connection_a, "org.my.busname");
>>   CU_ASSERT (release_reply == DBUS_RELEASE_NAME_REPLY_RELEASED);
>>
>>   /* 'connection_b' (now primary owner) also release name
>>   release_reply = release_name (connection_b, "org.my.busname");
>>   CU_ASSERT (release_reply == DBUS_RELEASE_NAME_REPLY_RELEASED);
>>
>>   /* 'connection_b' tries to release once again the same name */
>>   release_reply = release_name (connection_b, "org.my.busname");
>>
>>   /* This assert is source of failure - what we should get
>>  here: REPLY_RELEASED or NON_EXISTENT ? */
>>   CU_ASSERT (release_reply == DBUS_RELEASE_NAME_REPLY_NON_EXISTENT);
> 
> As per the spec, the same connection can only be queued up once for a
> given well-known name, so the correct error code should be NON_EXISTENT.
> 
>> Which solution, kdbus or dbus-daemon, do it correctly?
> 
> kdbus is wrong here IMO. The kernel patch you sent me offlist looks
> resonable. Care to rebase and post it to LKML?

Sure. Thanks for clarification!

> 
> 
> Thanks,
> Daniel
> 
> 

Cheers,
-- 
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCHv3] bus-proxy: add support for "GetConnectionCredentials" method

2015-03-10 Thread Lukasz Skalski
GetConnectionCredentials method was added to dbus-1 specification
more than one year ago. This method should return "[...] as many
credentials as possible for the process connected to the server",
but at this moment only "UnixUserID", "LinuxSecurityLabel" and
"ProcessID" are defined by the specification. We should add support
for next credentials after extending dbus-1 spec.

diff --git a/src/bus-proxyd/driver.c b/src/bus-proxyd/driver.c
index 3c613e4..e63a95d 100644
--- a/src/bus-proxyd/driver.c
+++ b/src/bus-proxyd/driver.c
@@ -49,9 +49,6 @@ static int get_creds_by_name(sd_bus *bus, const char *name, 
uint64_t mask, sd_bu
 if (r < 0)
 return r;
 
-if ((c->mask & mask) != mask)
-return -ENOTSUP;
-
 *_creds = c;
 c = NULL;
 
@@ -109,6 +106,10 @@ int bus_proxy_process_driver(sd_bus *a, sd_bus *b, 
sd_bus_message *m, SharedPoli
 "  \n"
 "   \n"
 "  \n"
+"  \n"
+"   \n"
+"   \n"
+"  \n"
 "  \n"
 "   \n"
 "   \n"
@@ -212,6 +213,72 @@ int bus_proxy_process_driver(sd_bus *a, sd_bus *b, 
sd_bus_message *m, SharedPoli
 
 return synthetic_reply_method_return(m, NULL);
 
+} else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", 
"GetConnectionCredentials")) {
+_cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
+_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+_cleanup_bus_error_free_ sd_bus_error error = 
SD_BUS_ERROR_NULL;
+
+if (!sd_bus_message_has_signature(m, "s"))
+return synthetic_reply_method_error(m, 
&SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
+
+r = get_creds_by_message(a, m, 
SD_BUS_CREDS_PID|SD_BUS_CREDS_EUID|SD_BUS_CREDS_SELINUX_CONTEXT, &creds, 
&error);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, &error);
+
+r = sd_bus_message_new_method_return(m, &reply);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, NULL);
+
+r = sd_bus_message_open_container(reply, 'a', "{sv}");
+if (r < 0)
+return synthetic_reply_method_errno(m, r, NULL);
+
+/* Due to i.e. namespace translations some data might be 
missing */
+
+if (creds->mask & SD_BUS_CREDS_PID) {
+r = sd_bus_message_append(reply, "{sv}", "ProcessID", 
"u", (uint32_t) creds->pid);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, 
NULL);
+}
+
+if (creds->mask & SD_BUS_CREDS_EUID) {
+r = sd_bus_message_append(reply, "{sv}", "UnixUserID", 
"u", (uint32_t) creds->euid);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, 
NULL);
+}
+
+if (creds->mask & SD_BUS_CREDS_SELINUX_CONTEXT) {
+r = sd_bus_message_open_container(reply, 'e', "sv");
+if (r < 0)
+return synthetic_reply_method_errno(m, r, 
NULL);
+
+r = sd_bus_message_append(reply, "s", 
"LinuxSecurityLabel");
+if (r < 0)
+return synthetic_reply_method_errno(m, r, 
NULL);
+
+r = sd_bus_message_open_container(reply, 'v', "ay");
+if (r < 0)
+return synthetic_reply_method_errno(m, r, 
NULL);
+
+r = sd_bus_message_append_array(reply, 'y', 
creds->label, strlen(creds->label));
+if (r < 0)
+return synthetic_reply_method_errno(m, r, 
NULL);
+
+r = sd_bus_message_close_container(reply);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, 
NULL);
+
+r = sd_bus_message_close_container(reply);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, 
NULL);
+}
+
+r = sd_bus_message_close_container(reply);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, NULL);
+
+return synthetic_driver_send(m->bus, reply);
+
 } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", 
"GetConnectionSELinuxSecurityContext")) {
 _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
 _cleanup_bus_error_free_ sd_bus_error err

[systemd-devel] [PATCH] doc: replace 'reply_cookie' with 'cookie_reply'

2015-03-06 Thread Lukasz Skalski
Signed-off-by: Lukasz Skalski 

diff --git a/doc/kdbus.message.xml b/doc/kdbus.message.xml
index c25000d..5e7c7a3 100644
--- a/doc/kdbus.message.xml
+++ b/doc/kdbus.message.xml
@@ -393,7 +393,7 @@ struct kdbus_msg {
   For a message to be accepted as reply, it must be a direct
   message to the original sender (not a broadcast and not a
   signal message), and its
-  kdbus_msg.reply_cookie must match the
+  kdbus_msg.cookie_reply must match the
   previous message's kdbus_msg.cookie.
 
   Expected replies also temporarily open the policy of the
-- 
1.9.3

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


[systemd-devel] [PATCH] doc: replace 'reply_cookie' with 'cookie_reply'

2015-03-06 Thread Lukasz Skalski
diff --git a/doc/kdbus.message.xml b/doc/kdbus.message.xml
index c25000d..5e7c7a3 100644
--- a/doc/kdbus.message.xml
+++ b/doc/kdbus.message.xml
@@ -393,7 +393,7 @@ struct kdbus_msg {
   For a message to be accepted as reply, it must be a direct
   message to the original sender (not a broadcast and not a
   signal message), and its
-  kdbus_msg.reply_cookie must match the
+  kdbus_msg.cookie_reply must match the
   previous message's kdbus_msg.cookie.
 
   Expected replies also temporarily open the policy of the
-- 
1.9.3

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


[systemd-devel] [PATCHv2][RFC] bus-proxy: add support for "GetConnectionCredentials" method

2015-02-23 Thread Lukasz Skalski
GetConnectionCredentials method was added to dbus-1 specification
more than one year ago. This method should return "[...] as many
credentials as possible for the process connected to the server",
but at this moment only "UnixUserID", "LinuxSecurityLabel" and
"ProcessID" are defined by the specification. We should add support
for next credentials after extending dbus-1 spec.

diff --git a/src/bus-proxyd/driver.c b/src/bus-proxyd/driver.c
index bc2c0c8..dc864f0 100644
--- a/src/bus-proxyd/driver.c
+++ b/src/bus-proxyd/driver.c
@@ -56,9 +56,6 @@ static int get_creds_by_name(sd_bus *bus, const char *name, 
uint64_t mask, sd_bu
 if (r < 0)
 return r;
 
-if ((c->mask & mask) != mask)
-return -ENOTSUP;
-
 *_creds = c;
 c = NULL;
 
@@ -116,6 +113,10 @@ int bus_proxy_process_driver(sd_bus *a, sd_bus *b, 
sd_bus_message *m, SharedPoli
 "  \n"
 "   \n"
 "  \n"
+"  \n"
+"   \n"
+"   \n"
+"  \n"
 "  \n"
 "   \n"
 "   \n"
@@ -219,6 +220,72 @@ int bus_proxy_process_driver(sd_bus *a, sd_bus *b, 
sd_bus_message *m, SharedPoli
 
 return synthetic_reply_method_return(m, NULL);
 
+} else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", 
"GetConnectionCredentials")) {
+_cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
+_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+_cleanup_bus_error_free_ sd_bus_error error = 
SD_BUS_ERROR_NULL;
+
+if (!sd_bus_message_has_signature(m, "s"))
+return synthetic_reply_method_error(m, 
&SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
+
+r = get_creds_by_message(a, m, 
SD_BUS_CREDS_PID|SD_BUS_CREDS_EUID|SD_BUS_CREDS_SELINUX_CONTEXT, &creds, 
&error);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, &error);
+
+r = sd_bus_message_new_method_return(m, &reply);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, NULL);
+
+r = sd_bus_message_open_container(reply, 'a', "{sv}");
+if (r < 0)
+return synthetic_reply_method_errno(m, r, NULL);
+
+/* Due to i.e. namespace translations some data might be 
missing */
+
+if (creds->mask & SD_BUS_CREDS_PID) {
+r = sd_bus_message_append(reply, "{sv}", "ProcessID", 
"u", (uint32_t) creds->pid);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, 
NULL);
+}
+
+if (creds->mask & SD_BUS_CREDS_EUID) {
+r = sd_bus_message_append(reply, "{sv}", "UnixUserID", 
"u", (uint32_t) creds->euid);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, 
NULL);
+}
+
+if (creds->mask & SD_BUS_CREDS_SELINUX_CONTEXT) {
+r = sd_bus_message_open_container(reply, 'e', "sv");
+if (r < 0)
+return synthetic_reply_method_errno(m, r, 
NULL);
+
+r = sd_bus_message_append(reply, "s", 
"LinuxSecurityLabel");
+if (r < 0)
+return synthetic_reply_method_errno(m, r, 
NULL);
+
+r = sd_bus_message_open_container(reply, 'v', "ay");
+if (r < 0)
+return synthetic_reply_method_errno(m, r, 
NULL);
+
+r = sd_bus_message_append_array(reply, 'y', 
creds->label, strlen(creds->label));
+if (r < 0)
+return synthetic_reply_method_errno(m, r, 
NULL);
+
+r = sd_bus_message_close_container(reply);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, 
NULL);
+
+r = sd_bus_message_close_container(reply);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, 
NULL);
+}
+
+r = sd_bus_message_close_container(reply);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, NULL);
+
+return synthetic_driver_send(m->bus, reply);
+
 } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", 
"GetConnectionSELinuxSecurityContext")) {
 _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
 _cleanup_bus_error_free_ sd_bus_error err

Re: [systemd-devel] [PATCH][RFC] bus-proxy: add support for "GetConnectionCredentials" method

2015-02-19 Thread Lukasz Skalski
On 02/19/2015 02:05 PM, Simon McVittie wrote:
> On 19/02/15 12:43, Lukasz Skalski wrote:
>> GetConnectionCredentials method was added to dbus-1 specification
>> more than one year ago. This method should return "[...] as many
>> credentials as possible for the process connected to the server",
>> but at this moment only "UnixUserID" and "ProcessID" are defined
>> by the specification. We should add support for next credentials
>> after extending dbus-1 spec.
> 
> As of dbus master (soon to be 1.9.12), LinuxSecurityLabel is also
> defined. It's the bytestring from SO_PEERSEC, whatever that means for
> the current LSM(s), with a trailing '\0' appended if there wasn't
> already one there. AppArmor, SELinux and Smack developers have all told
> me this is valid for their LSMs.

Ok, now I see that LinuxSecurityLabel is a part of 0.26 spec, so I'll
add this field and resend new version of my patch.

@Lennart, what do you think about adding GetConnectionCredentials to
bus-proxy?

> 
> Spec patches welcome for others, but I don't think there's a great deal
> of point in adding GetConnectionCredentials support for additional
> credentials that can be transferred over kdbus but not (securely) over
> AF_UNIX: anything with enough kdbus knowledge to know about those might
> as well be using kdbus directly.
> 
>> +r = get_creds_by_message(a, m,
>> SD_BUS_CREDS_PID|SD_BUS_CREDS_EUID, &creds, &error);
> 
> Can this ever return "unknown" (-1?) for creds->pid or creds->euid? If
> it can, then ProcessID and UnixUserID should be omitted from the map
> when that happens, instead of being included with a dummy value.
> 
>> +r = sd_bus_message_append(reply, "{sv}", "ProcessID",
>> "u", (uint32_t) creds->pid);
> 
> If the pid is out of range for uint32 it should be omitted from the map
> (although that can't actually happen on current Linux). Same for the uid.
> 

-- 
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH][RFC] bus-proxy: add support for "GetConnectionCredentials" method

2015-02-19 Thread Lukasz Skalski
GetConnectionCredentials method was added to dbus-1 specification
more than one year ago. This method should return "[...] as many
credentials as possible for the process connected to the server",
but at this moment only "UnixUserID" and "ProcessID" are defined
by the specification. We should add support for next credentials
after extending dbus-1 spec.

diff --git a/src/bus-proxyd/driver.c b/src/bus-proxyd/driver.c
index bc2c0c8..8ab4a16 100644
--- a/src/bus-proxyd/driver.c
+++ b/src/bus-proxyd/driver.c
@@ -116,6 +116,10 @@ int bus_proxy_process_driver(sd_bus *a, sd_bus *b, 
sd_bus_message *m, SharedPoli
 "  \n"
 "   \n"
 "  \n"
+"  \n"
+"   \n"
+"   \n"
+"  \n"
 "  \n"
 "   \n"
 "   \n"
@@ -219,6 +223,40 @@ int bus_proxy_process_driver(sd_bus *a, sd_bus *b, 
sd_bus_message *m, SharedPoli
 
 return synthetic_reply_method_return(m, NULL);
 
+} else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", 
"GetConnectionCredentials")) {
+_cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
+_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+_cleanup_bus_error_free_ sd_bus_error error = 
SD_BUS_ERROR_NULL;
+
+if (!sd_bus_message_has_signature(m, "s"))
+return synthetic_reply_method_error(m, 
&SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
+
+r = get_creds_by_message(a, m, 
SD_BUS_CREDS_PID|SD_BUS_CREDS_EUID, &creds, &error);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, &error);
+
+r = sd_bus_message_new_method_return(m, &reply);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, NULL);
+
+r = sd_bus_message_open_container(reply, 'a', "{sv}");
+if (r < 0)
+return synthetic_reply_method_errno(m, r, NULL);
+
+r = sd_bus_message_append(reply, "{sv}", "ProcessID", "u", 
(uint32_t) creds->pid);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, NULL);
+
+r = sd_bus_message_append(reply, "{sv}", "UnixUserID", "u", 
(uint32_t) creds->euid);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, NULL);
+
+r = sd_bus_message_close_container(reply);
+if (r < 0)
+return synthetic_reply_method_errno(m, r, NULL);
+
+return synthetic_driver_send(m->bus, reply);
+
 } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", 
"GetConnectionSELinuxSecurityContext")) {
 _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
 _cleanup_bus_error_free_ sd_bus_error error = 
SD_BUS_ERROR_NULL;
diff --git a/src/bus-proxyd/synthesize.c b/src/bus-proxyd/synthesize.c
index e1b0fd3..d370a05 100644
--- a/src/bus-proxyd/synthesize.c
+++ b/src/bus-proxyd/synthesize.c
@@ -38,7 +38,7 @@
 #include "bus-control.h"
 #include "synthesize.h"
 
-static int synthetic_driver_send(sd_bus *b, sd_bus_message *m) {
+int synthetic_driver_send(sd_bus *b, sd_bus_message *m) {
 int r;
 
 assert(b);
diff --git a/src/bus-proxyd/synthesize.h b/src/bus-proxyd/synthesize.h
index a55f171..e850350 100644
--- a/src/bus-proxyd/synthesize.h
+++ b/src/bus-proxyd/synthesize.h
@@ -23,6 +23,8 @@
 
 #include "sd-bus.h"
 
+int synthetic_driver_send(sd_bus *b, sd_bus_message *m);
+
 int synthetic_reply_method_return(sd_bus_message *call, const char *types, 
...);
 int synthetic_reply_method_return_strv(sd_bus_message *call, char **l);
 
-- 
1.9.3

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


Re: [systemd-devel] [PATCH] test: bump KDBUS_CONN_MAX_MSGS_PER_USER value

2015-02-17 Thread Lukasz Skalski
On 02/17/2015 12:20 PM, Djalal Harouni wrote:
> Hi Lukasz,
> 

Hi Djalal,

> On Tue, Feb 17, 2015 at 11:37:53AM +0100, Lukasz Skalski wrote:
>> diff --git a/test/test-message.c b/test/test-message.c
>> index 03ac71e..0cae942 100644
>> --- a/test/test-message.c
>> +++ b/test/test-message.c
>> @@ -28,7 +28,7 @@
>>   * maximum number of queued messages from the same indvidual user after the
>>   * the un-accounted value has been hit
>>   */
>> -#define KDBUS_CONN_MAX_MSGS_PER_USER16
>> +#define KDBUS_CONN_MAX_MSGS_PER_USER128
> Actually, the limit bump is just a temporary solution, to inspect or fix
> other bugs related to Gnome. David is working on this, I will let him
> decide if he wants to apply this patch or let it as it...
> 

Yes, I know that it is temporary solution, but at this moment, after
bumping KDBUS_CONN_MAX_MSGS_PER_USER value we have some new errors in
tests - for example in test-message.c:736 we get EXFULL errno
(queue.c:287 says that we can't take more than half of the remaining
space) instead of ENOBUFS. IMO we should align tests with latest changes.

> Thank you Lukasz!
> 
> 
>>  #define MAX_USER_TOTAL_MSGS  (KDBUS_CONN_MAX_MSGS_UNACCOUNTED + \
>>  KDBUS_CONN_MAX_MSGS_PER_USER)
>> diff --git a/test/test-policy-ns.c b/test/test-policy-ns.c
>> index 3437012..3c8b78e 100644
>> --- a/test/test-policy-ns.c
>> +++ b/test/test-policy-ns.c
>> @@ -38,7 +38,7 @@
>>  #define MAX_CONN64
>>  #define POLICY_NAME "foo.test.policy-test"
>>  
>> -#define KDBUS_CONN_MAX_MSGS_PER_USER16
>> +#define KDBUS_CONN_MAX_MSGS_PER_USER128
>>  
>>  /**
>>   * Note: this test can be used to inspect policy_db->talk_access_hash
>> -- 
>> 1.9.3
>>
>> ___
>> systemd-devel mailing list
>> systemd-devel@lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/systemd-devel
> 

-- 
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] test: bump KDBUS_CONN_MAX_MSGS_PER_USER value

2015-02-17 Thread Lukasz Skalski
diff --git a/test/test-message.c b/test/test-message.c
index 03ac71e..0cae942 100644
--- a/test/test-message.c
+++ b/test/test-message.c
@@ -28,7 +28,7 @@
  * maximum number of queued messages from the same indvidual user after the
  * the un-accounted value has been hit
  */
-#define KDBUS_CONN_MAX_MSGS_PER_USER   16
+#define KDBUS_CONN_MAX_MSGS_PER_USER   128
 
 #define MAX_USER_TOTAL_MSGS  (KDBUS_CONN_MAX_MSGS_UNACCOUNTED + \
KDBUS_CONN_MAX_MSGS_PER_USER)
diff --git a/test/test-policy-ns.c b/test/test-policy-ns.c
index 3437012..3c8b78e 100644
--- a/test/test-policy-ns.c
+++ b/test/test-policy-ns.c
@@ -38,7 +38,7 @@
 #define MAX_CONN   64
 #define POLICY_NAME"foo.test.policy-test"
 
-#define KDBUS_CONN_MAX_MSGS_PER_USER16
+#define KDBUS_CONN_MAX_MSGS_PER_USER128
 
 /**
  * Note: this test can be used to inspect policy_db->talk_access_hash
-- 
1.9.3

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


[systemd-devel] [PATCH] test: check what happens if we forget about KDBUS_CMD_FREE call

2015-02-11 Thread Lukasz Skalski
diff --git a/test/test-free.c b/test/test-free.c
index 01dca80..f666da3 100644
--- a/test/test-free.c
+++ b/test/test-free.c
@@ -14,6 +14,22 @@
 #include "kdbus-enum.h"
 #include "kdbus-test.h"
 
+static int sample_ioctl_call(struct kdbus_test_env *env)
+{
+   int ret;
+   struct kdbus_cmd_list cmd_list = {
+   .flags = KDBUS_LIST_QUEUED,
+   .size = sizeof(cmd_list),
+   };
+
+   ret = kdbus_cmd_list(env->conn->fd, &cmd_list);
+   ASSERT_RETURN(ret == 0);
+
+   /* DON'T FREE THIS SLICE OF MEMORY! */
+
+   return TEST_OK;
+}
+
 int kdbus_test_free(struct kdbus_test_env *env)
 {
int ret;
@@ -32,5 +48,17 @@ int kdbus_test_free(struct kdbus_test_env *env)
ret = kdbus_cmd_free(env->conn->fd, &cmd_free);
ASSERT_RETURN(ret == -ENXIO);
 
+   /*
+* The user application is responsible for freeing the allocated
+* memory with the KDBUS_CMD_FREE ioctl, so let's test what happens
+* if we forget about it.
+*/
+
+   ret = sample_ioctl_call(env);
+   ASSERT_RETURN(ret == 0);
+
+   ret = sample_ioctl_call(env);
+   ASSERT_RETURN(ret == 0);
+
return TEST_OK;
 }
-- 
1.9.3

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


[systemd-devel] [PATCH] names: return EADDRINUSE if name is owned by a different connection and can't be released

2015-02-09 Thread Lukasz Skalski
This patch fixes also problem with "ReleaseName" call in
systemd-bus-proxyd.

diff --git a/names.c b/names.c
index 5f57aa3..e85ba45 100644
--- a/names.c
+++ b/names.c
@@ -266,6 +266,7 @@ static int kdbus_name_release(struct kdbus_name_registry 
*reg,
 * for items for connection.
 */
 
+   ret = -EADDRINUSE;
list_for_each_entry_safe(q, tmp, &e->queue_list, entry_entry) {
if (q->conn != conn)
continue;
diff --git a/test/test-names.c b/test/test-names.c
index 00c8ba0..66ebb47 100644
--- a/test/test-names.c
+++ b/test/test-names.c
@@ -54,6 +54,7 @@ static int conn_is_name_owner(const struct kdbus_conn *conn,
 
 int kdbus_test_name_basic(struct kdbus_test_env *env)
 {
+   struct kdbus_conn *conn;
char *name, *dot_name, *invalid_name, *wildcard_name;
int ret;
 
@@ -62,6 +63,14 @@ int kdbus_test_name_basic(struct kdbus_test_env *env)
invalid_name = "foo";
wildcard_name = "foo.bla.bl.*";
 
+   /* create a 2nd connection */
+   conn = kdbus_hello(env->buspath, 0, NULL, 0);
+   ASSERT_RETURN(conn != NULL);
+
+   /* acquire name "foo.bar.xxx" name */
+   ret = kdbus_name_acquire(conn, "foo.bar.xxx", NULL);
+   ASSERT_RETURN(ret == 0);
+
/* Name is not valid, must fail */
ret = kdbus_name_acquire(env->conn, dot_name, NULL);
ASSERT_RETURN(ret == -EINVAL);
@@ -92,7 +101,7 @@ int kdbus_test_name_basic(struct kdbus_test_env *env)
 
/* check that we can't release a name that we don't own */
ret = kdbus_name_release(env->conn, "foo.bar.xxx");
-   ASSERT_RETURN(ret == -ESRCH);
+   ASSERT_RETURN(ret == -EADDRINUSE);
 
/* Name is not valid, must fail */
ret = kdbus_name_release(env->conn, dot_name);
@@ -104,6 +113,8 @@ int kdbus_test_name_basic(struct kdbus_test_env *env)
ret = kdbus_name_release(env->conn, wildcard_name);
ASSERT_RETURN(ret == -ESRCH);
 
+   kdbus_conn_free(conn);
+
return TEST_OK;
 }
 
-- 
1.9.3

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


[systemd-devel] [PATCH] bus-proxyd: fix 'ListQueuedOwners' call

2015-02-06 Thread Lukasz Skalski
Set proper kdbus_cmd_list object size, otherwise:

dbus-send --system --dest=org.freedesktop.DBus --type=method_call \
print-reply / org.freedesktop.DBus.ListQueuedOwners 
string:org.freedesktop.systemd1

Error org.freedesktop.DBus.Error.InvalidArgs: Invalid argument

diff --git a/src/bus-proxyd/driver.c b/src/bus-proxyd/driver.c
index 23911c6..b275839 100644
--- a/src/bus-proxyd/driver.c
+++ b/src/bus-proxyd/driver.c
@@ -350,6 +350,7 @@ int bus_proxy_process_driver(sd_bus *a, sd_bus *b, 
sd_bus_message *m, SharedPoli
 return synthetic_reply_method_errno(m, r, NULL);
 
 cmd.flags = KDBUS_LIST_QUEUED;
+cmd.size = sizeof(cmd);
 r = ioctl(a->input_fd, KDBUS_CMD_LIST, &cmd);
 if (r < 0)
 return synthetic_reply_method_errno(m, -errno, NULL);
-- 
1.9.3

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


[systemd-devel] [PATCH] sd-bus: fix copy-paste error

2015-01-08 Thread Lukasz Skalski
---
 src/libsystemd/sd-bus/bus-control.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libsystemd/sd-bus/bus-control.c 
b/src/libsystemd/sd-bus/bus-control.c
index 2db1afb..b450140 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -219,7 +219,7 @@ _public_ int sd_bus_release_name(sd_bus *bus, const char 
*name) {
 assert_return(service_name_is_valid(name), -EINVAL);
 assert_return(name[0] != ':', -EINVAL);
 
-/* Don't allow requesting the special driver and local names */
+/* Don't allow releasing the special driver and local names */
 if (STR_IN_SET(name, "org.freedesktop.DBus", 
"org.freedesktop.DBus.Local"))
 return -EINVAL;
 
-- 
1.9.3

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


Re: [systemd-devel] [PATCH] bus-proxyd: overwrite 'sender' field in process_driver() function

2015-01-07 Thread Lukasz Skalski
This patch doesn't work as I expected so please skip it - sorry for the
confusion.

On 01/05/2015 05:03 PM, Lukasz Skalski wrote:
> To keep compatibility with dbus-1, before we use synthetic_reply_method_*()
> functions, we should overwrite 'sender' field - otherwise functions
> sd_bus_message_new_method_return() and sd_bus_message_new_method_error() never
> set 'destination' field.
> 
> Thanks to this we have proper 'destination' value:
> 
> dbus-send --session --dest=org.freedesktop.DBus --type=method_call 
> --print-reply / org.freedesktop.DBus.ListNames
> method return sender=org.freedesktop.DBus -> dest=:1.338 reply_serial=2
>array [
>   string ":1.1"
>   string ":1.18"
>   string ":1.27"
>   string ":1.338"
>   string ":1.35"
>   string "org.freedesktop.DBus"
>   string "org.freedesktop.login1"
>   string "org.freedesktop.systemd1"
>]
> 
> instead of '(null destination)':
> 
> dbus-send --session --dest=org.freedesktop.DBus --type=method_call 
> --print-reply / org.freedesktop.DBus.ListNames
> method return sender=org.freedesktop.DBus -> dest=(null destination) 
> reply_serial=2
> 
> ---
>  src/bus-proxyd/bus-proxyd.c | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
> index fc70cce..add1ccb 100644
> --- a/src/bus-proxyd/bus-proxyd.c
> +++ b/src/bus-proxyd/bus-proxyd.c
> @@ -456,6 +456,7 @@ static int get_creds_by_message(sd_bus *bus, 
> sd_bus_message *m, uint64_t mask, s
>  
>  static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy 
> *policy, const struct ucred *ucred, Set *owned_names) {
>  int r;
> +_cleanup_free_ const char *unique;
>  
>  assert(a);
>  assert(b);
> @@ -467,6 +468,11 @@ static int process_driver(sd_bus *a, sd_bus *b, 
> sd_bus_message *m, Policy *polic
>  if (!streq_ptr(sd_bus_message_get_destination(m), 
> "org.freedesktop.DBus"))
>  return 0;
>  
> +r = sd_bus_get_unique_name(a, &unique);
> +if (r < 0)
> +return 0;
> +m->sender = unique;
> +
>  /* The "Hello()" call is is handled in process_hello() */
>  
>  if (sd_bus_message_is_method_call(m, 
> "org.freedesktop.DBus.Introspectable", "Introspect")) {
> 

-- 
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] bus-proxyd: overwrite 'sender' field in process_driver() function

2015-01-05 Thread Lukasz Skalski
To keep compatibility with dbus-1, before we use synthetic_reply_method_*()
functions, we should overwrite 'sender' field - otherwise functions
sd_bus_message_new_method_return() and sd_bus_message_new_method_error() never
set 'destination' field.

Thanks to this we have proper 'destination' value:

dbus-send --session --dest=org.freedesktop.DBus --type=method_call 
--print-reply / org.freedesktop.DBus.ListNames
method return sender=org.freedesktop.DBus -> dest=:1.338 reply_serial=2
   array [
  string ":1.1"
  string ":1.18"
  string ":1.27"
  string ":1.338"
  string ":1.35"
  string "org.freedesktop.DBus"
  string "org.freedesktop.login1"
  string "org.freedesktop.systemd1"
   ]

instead of '(null destination)':

dbus-send --session --dest=org.freedesktop.DBus --type=method_call 
--print-reply / org.freedesktop.DBus.ListNames
method return sender=org.freedesktop.DBus -> dest=(null destination) 
reply_serial=2

---
 src/bus-proxyd/bus-proxyd.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
index fc70cce..add1ccb 100644
--- a/src/bus-proxyd/bus-proxyd.c
+++ b/src/bus-proxyd/bus-proxyd.c
@@ -456,6 +456,7 @@ static int get_creds_by_message(sd_bus *bus, sd_bus_message 
*m, uint64_t mask, s
 
 static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy 
*policy, const struct ucred *ucred, Set *owned_names) {
 int r;
+_cleanup_free_ const char *unique;
 
 assert(a);
 assert(b);
@@ -467,6 +468,11 @@ static int process_driver(sd_bus *a, sd_bus *b, 
sd_bus_message *m, Policy *polic
 if (!streq_ptr(sd_bus_message_get_destination(m), 
"org.freedesktop.DBus"))
 return 0;
 
+r = sd_bus_get_unique_name(a, &unique);
+if (r < 0)
+return 0;
+m->sender = unique;
+
 /* The "Hello()" call is is handled in process_hello() */
 
 if (sd_bus_message_is_method_call(m, 
"org.freedesktop.DBus.Introspectable", "Introspect")) {
-- 
1.9.3

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


[systemd-devel] [PATCH] bus-proxyd: don't allow to acquire org.freedesktop.DBus name

2015-01-05 Thread Lukasz Skalski
---
 src/bus-proxyd/bus-proxyd.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
index a7818f5..fc70cce 100644
--- a/src/bus-proxyd/bus-proxyd.c
+++ b/src/bus-proxyd/bus-proxyd.c
@@ -829,6 +829,10 @@ static int process_driver(sd_bus *a, sd_bus *b, 
sd_bus_message *m, Policy *polic
 if (r < 0)
 return synthetic_reply_method_errno(m, r, NULL);
 
+if (streq(name, "org.freedesktop.DBus"))
+return synthetic_reply_method_error(m, 
&SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS,
+"Connection is not 
allowed to own the org.freedesktop.DBus service."));
+
 if (policy && !policy_check_own(policy, ucred->uid, 
ucred->gid, name))
 return synthetic_reply_method_errno(m, -EPERM, NULL);
 
-- 
1.9.3

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


[systemd-devel] [PATCH] kdbus: free returned buffer when the memory is no longer needed

2014-10-16 Thread Lukasz Skalski
---
 src/libsystemd/sd-bus/bus-control.c | 43 -
 1 file changed, 28 insertions(+), 15 deletions(-)

diff --git a/src/libsystemd/sd-bus/bus-control.c 
b/src/libsystemd/sd-bus/bus-control.c
index 7b106a3..9bb6e5b 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -265,12 +265,14 @@ static int kernel_get_list(sd_bus *bus, uint64_t flags, 
char ***x) {
 if ((flags & KDBUS_NAME_LIST_UNIQUE) && name->owner_id != 
previous_id) {
 char *n;
 
-if (asprintf(&n, ":1.%llu", (unsigned long long) 
name->owner_id) < 0)
-return -ENOMEM;
+if (asprintf(&n, ":1.%llu", (unsigned long long) 
name->owner_id) < 0) {
+r = -ENOMEM;
+goto fail;
+}
 
 r = strv_consume(x, n);
 if (r < 0)
-return r;
+goto fail;
 
 previous_id = name->owner_id;
 }
@@ -281,16 +283,18 @@ static int kernel_get_list(sd_bus *bus, uint64_t flags, 
char ***x) {
 
 if (entry_name && service_name_is_valid(entry_name)) {
 r = strv_extend(x, entry_name);
-if (r < 0)
-return -ENOMEM;
+if (r < 0) {
+r = -ENOMEM;
+goto fail;
+}
 }
 }
 
-r = kernel_cmd_free(bus, cmd.offset);
-if (r < 0)
-return r;
+r = 0;
 
-return 0;
+fail:
+kernel_cmd_free(bus, cmd.offset);
+return r;
 }
 
 static int bus_list_names_kernel(sd_bus *bus, char ***acquired, char 
***activatable) {
@@ -428,16 +432,25 @@ static int bus_get_owner_kdbus(
 conn_info = (struct kdbus_conn_info *) ((uint8_t *) bus->kdbus_buffer 
+ cmd->offset);
 
 /* Non-activated names are considered not available */
-if (conn_info->flags & KDBUS_HELLO_ACTIVATOR)
-return name[0] == ':' ? -ENXIO : -ESRCH;
+if (conn_info->flags & KDBUS_HELLO_ACTIVATOR) {
+if (name[0] == ':')
+r = -ENXIO;
+else
+r = -ESRCH;
+goto fail;
+}
 
 c = bus_creds_new();
-if (!c)
-return -ENOMEM;
+if (!c) {
+r = -ENOMEM;
+goto fail;
+}
 
 if (mask & SD_BUS_CREDS_UNIQUE_NAME) {
-if (asprintf(&c->unique_name, ":1.%llu", (unsigned long long) 
conn_info->id) < 0)
-return -ENOMEM;
+if (asprintf(&c->unique_name, ":1.%llu", (unsigned long long) 
conn_info->id) < 0) {
+r = -ENOMEM;
+goto fail;
+}
 
 c->mask |= SD_BUS_CREDS_UNIQUE_NAME;
 }
-- 
1.9.3

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


[systemd-devel] [PATCH] resolve: add missing header

2014-10-16 Thread Lukasz Skalski
Change-Id: I64f7c6b446f6d92057c35cc3d4e29bd2bad8f75b
---
 src/resolve/resolved.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/resolve/resolved.c b/src/resolve/resolved.c
index ef416e5..abd6314 100644
--- a/src/resolve/resolved.c
+++ b/src/resolve/resolved.c
@@ -22,6 +22,7 @@
 #include "sd-event.h"
 #include "sd-daemon.h"
 #include "mkdir.h"
+#include "label.h"
 #include "capability.h"
 
 #include "resolved-manager.h"
-- 
1.9.3

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


[systemd-devel] [PATCH] bus-proxyd: add missing flag translation for RequestName

2014-10-14 Thread Lukasz Skalski
---
 src/bus-proxyd/bus-proxyd.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
index 52498f3..6ff0e8c 100644
--- a/src/bus-proxyd/bus-proxyd.c
+++ b/src/bus-proxyd/bus-proxyd.c
@@ -845,7 +845,7 @@ static int process_driver(sd_bus *a, sd_bus *b, 
sd_bus_message *m) {
 
 } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", 
"RequestName")) {
 const char *name;
-uint32_t flags;
+uint32_t flags, param;
 
 r = sd_bus_message_read(m, "su", &name, &flags);
 if (r < 0)
@@ -856,7 +856,15 @@ static int process_driver(sd_bus *a, sd_bus *b, 
sd_bus_message *m) {
 if ((flags & 
~(BUS_NAME_ALLOW_REPLACEMENT|BUS_NAME_REPLACE_EXISTING|BUS_NAME_DO_NOT_QUEUE)) 
!= 0)
 return synthetic_reply_method_errno(m, -EINVAL, NULL);
 
-r = sd_bus_request_name(a, name, flags);
+param = 0;
+if (flags & BUS_NAME_ALLOW_REPLACEMENT)
+param |= SD_BUS_NAME_ALLOW_REPLACEMENT;
+if (flags & BUS_NAME_REPLACE_EXISTING)
+param |= SD_BUS_NAME_REPLACE_EXISTING;
+if (!(flags & BUS_NAME_DO_NOT_QUEUE))
+param |= SD_BUS_NAME_QUEUE;
+
+r = sd_bus_request_name(a, name, param);
 if (r < 0) {
 if (r == -EEXIST)
 return synthetic_reply_method_return(m, "u", 
BUS_NAME_EXISTS);
-- 
1.9.3

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


[systemd-devel] [PATCH] bus-proxyd: improve compatibility with dbus-1

2014-10-13 Thread Lukasz Skalski
'GetConnectionUnixProcessID', 'GetConnectionUnixUser' and
'GetConnectionSELinuxSecurityContext' methods should return
'NameHasNoOwner' error (if chosen name is not available on bus)
with more detailed description - like dbus-1:

Could not get PID of name 'org.freedesktop.test': no such name.
Could not get UID of name 'org.freedesktop.test': no such name.
Could not get security context of name 'org.freedesktop.test': no such name.

Otherwise we have only laconic message without proper dbus error:

Error System.Error.ENXIO: No such device or address

---
 src/bus-proxyd/bus-proxyd.c | 36 +---
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
index 52498f3..1bd7fee 100644
--- a/src/bus-proxyd/bus-proxyd.c
+++ b/src/bus-proxyd/bus-proxyd.c
@@ -643,27 +643,57 @@ static int process_driver(sd_bus *a, sd_bus *b, 
sd_bus_message *m) {
 return synthetic_reply_method_return(m, NULL);
 
 } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", 
"GetConnectionSELinuxSecurityContext")) {
+const char *name;
 _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
+_cleanup_bus_error_free_ sd_bus_error error = 
SD_BUS_ERROR_NULL;
 
-r = get_creds_by_message(a, m, SD_BUS_CREDS_SELINUX_CONTEXT, 
&creds, NULL);
+r = sd_bus_message_read(m, "s", &name);
+if (r < 0)
+return r;
+
+r = get_creds_by_name(a, name, SD_BUS_CREDS_SELINUX_CONTEXT, 
&creds, NULL);
+if (r == -ESRCH || r == -ENXIO) {
+sd_bus_error_setf(&error, 
SD_BUS_ERROR_NAME_HAS_NO_OWNER, "Could not get security context of name '%s': 
no such name.", name);
+return synthetic_reply_method_errno(m, r, &error);
+}
 if (r < 0)
 return synthetic_reply_method_errno(m, r, NULL);
 
 return synthetic_reply_method_return(m, "y", creds->label, 
strlen(creds->label));
 
 } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", 
"GetConnectionUnixProcessID")) {
+const char *name;
 _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
+_cleanup_bus_error_free_ sd_bus_error error = 
SD_BUS_ERROR_NULL;
 
-r = get_creds_by_message(a, m, SD_BUS_CREDS_PID, &creds, NULL);
+r = sd_bus_message_read(m, "s", &name);
+if (r < 0)
+return r;
+
+r = get_creds_by_name(a, name, SD_BUS_CREDS_PID, &creds, NULL);
+if (r == -ESRCH || r == -ENXIO) {
+sd_bus_error_setf(&error, 
SD_BUS_ERROR_NAME_HAS_NO_OWNER, "Could not get PID of name '%s': no such 
name.", name);
+return synthetic_reply_method_errno(m, r, &error);
+}
 if (r < 0)
 return synthetic_reply_method_errno(m, r, NULL);
 
 return synthetic_reply_method_return(m, "u", (uint32_t) 
creds->pid);
 
 } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", 
"GetConnectionUnixUser")) {
+const char *name;
 _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
+_cleanup_bus_error_free_ sd_bus_error error = 
SD_BUS_ERROR_NULL;
 
-r = get_creds_by_message(a, m, SD_BUS_CREDS_UID, &creds, NULL);
+r = sd_bus_message_read(m, "s", &name);
+if (r < 0)
+return r;
+
+r = get_creds_by_name(a, name, SD_BUS_CREDS_UID, &creds, NULL);
+if (r == -ESRCH || r == -ENXIO) {
+sd_bus_error_setf(&error, 
SD_BUS_ERROR_NAME_HAS_NO_OWNER, "Could not get UID of name '%s': no such 
name.", name);
+return synthetic_reply_method_errno(m, r, &error);
+}
 if (r < 0)
 return synthetic_reply_method_errno(m, r, NULL);
 
-- 
1.9.3

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


[systemd-devel] [PATCH] bus-proxyd: fix compatibility with old dbus-1

2014-10-10 Thread Lukasz Skalski
'ListQueuedOwners' method should return 'NameHasNoOwner' error
if chosen name is not available on bus.

---
 src/bus-proxyd/bus-proxyd.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
index 4f44825..52498f3 100644
--- a/src/bus-proxyd/bus-proxyd.c
+++ b/src/bus-proxyd/bus-proxyd.c
@@ -733,6 +733,7 @@ static int process_driver(sd_bus *a, sd_bus *b, 
sd_bus_message *m) {
 struct kdbus_cmd_free cmd_free;
 struct kdbus_cmd_name *name;
 _cleanup_strv_free_ char **owners = NULL;
+_cleanup_bus_error_free_ sd_bus_error error = 
SD_BUS_ERROR_NULL;
 char *arg0;
 int err = 0;
 
@@ -743,6 +744,14 @@ static int process_driver(sd_bus *a, sd_bus *b, 
sd_bus_message *m) {
 if (!service_name_is_valid(arg0))
 return synthetic_reply_method_errno(m, -EINVAL, NULL);
 
+r = sd_bus_get_owner(a, arg0, 0, NULL);
+if (r == -ESRCH || r == -ENXIO) {
+sd_bus_error_setf(&error, 
SD_BUS_ERROR_NAME_HAS_NO_OWNER, "Could not get owners of name '%s': no such 
name.", arg0);
+return synthetic_reply_method_errno(m, r, &error);
+}
+if (r < 0)
+return synthetic_reply_method_errno(m, r, NULL);
+
 cmd.flags = KDBUS_NAME_LIST_QUEUED;
 r = ioctl(a->input_fd, KDBUS_CMD_NAME_LIST, &cmd);
 if (r < 0)
-- 
1.9.3

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


[systemd-devel] [PATCH] kdbus: fix buffer overflow in bus_get_owner_kdbus() function

2014-10-10 Thread Lukasz Skalski
Commit 710fc9779b7c (kdbus repo) introduced attaching items[]
instead of name[] in kdbus_cmd_conn_info struct. Commit 581fe6c81
(systemd repo) caught up with this change, but item size was not
properly calculated.

---
 src/libsystemd/sd-bus/bus-control.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/libsystemd/sd-bus/bus-control.c 
b/src/libsystemd/sd-bus/bus-control.c
index dbd94fc..7b106a3 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -398,7 +398,7 @@ static int bus_get_owner_kdbus(
 struct kdbus_cmd_conn_info *cmd;
 struct kdbus_conn_info *conn_info;
 struct kdbus_item *item;
-size_t size;
+size_t size, l;
 uint64_t m, id;
 int r;
 
@@ -410,13 +410,12 @@ static int bus_get_owner_kdbus(
 cmd = alloca0_align(size, 8);
 cmd->id = id;
 } else {
-size_t item_size = KDBUS_ITEM_HEADER_SIZE + strlen(name) + 1;
-
-size = offsetof(struct kdbus_cmd_conn_info, items) + item_size;
+l = strlen(name) + 1;
+size = offsetof(struct kdbus_cmd_conn_info, items) + 
KDBUS_ITEM_SIZE(l);
 cmd = alloca0_align(size, 8);
-cmd->items[0].size = item_size;
+cmd->items[0].size = KDBUS_ITEM_HEADER_SIZE + l;
 cmd->items[0].type = KDBUS_ITEM_NAME;
-strcpy(cmd->items[0].str, name);
+memcpy(cmd->items[0].str, name, l);
 }
 
 cmd->size = size;
-- 
1.9.3

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


[systemd-devel] [PATCH] logind: mount per-user tmpfs with 'smackfsroot=*' for smack enabled systems

2014-10-09 Thread Lukasz Skalski
---
 src/login/logind-user.c | 8 +++-
 units/systemd-logind.service.in | 2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index d48eca4..3847496 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -37,6 +37,7 @@
 #include "conf-parser.h"
 #include "clean-ipc.h"
 #include "logind-user.h"
+#include "smack-util.h"
 
 User* user_new(Manager *m, uid_t uid, gid_t gid, const char *name) {
 User *u;
@@ -325,7 +326,12 @@ static int user_mkdir_runtime_path(User *u) {
 
 mkdir(p, 0700);
 
-if (asprintf(&t, "mode=0700,uid=" UID_FMT ",gid=" GID_FMT 
",size=%zu", u->uid, u->gid, u->manager->runtime_dir_size) < 0) {
+if (use_smack())
+r = asprintf(&t, "mode=0700,smackfsroot=*,uid=" 
UID_FMT ",gid=" GID_FMT ",size=%zu", u->uid, u->gid, 
u->manager->runtime_dir_size);
+else
+r = asprintf(&t, "mode=0700,uid=" UID_FMT ",gid=" 
GID_FMT ",size=%zu", u->uid, u->gid, u->manager->runtime_dir_size);
+
+if (r < 0) {
 r = log_oom();
 goto fail;
 }
diff --git a/units/systemd-logind.service.in b/units/systemd-logind.service.in
index c6cbd1c..f087e99 100644
--- a/units/systemd-logind.service.in
+++ b/units/systemd-logind.service.in
@@ -23,7 +23,7 @@ ExecStart=@rootlibexecdir@/systemd-logind
 Restart=always
 RestartSec=0
 BusName=org.freedesktop.login1
-CapabilityBoundingSet=CAP_SYS_ADMIN CAP_AUDIT_CONTROL CAP_CHOWN CAP_KILL 
CAP_DAC_READ_SEARCH CAP_DAC_OVERRIDE CAP_FOWNER CAP_SYS_TTY_CONFIG
+CapabilityBoundingSet=CAP_SYS_ADMIN CAP_MAC_ADMIN CAP_AUDIT_CONTROL CAP_CHOWN 
CAP_KILL CAP_DAC_READ_SEARCH CAP_DAC_OVERRIDE CAP_FOWNER CAP_SYS_TTY_CONFIG
 WatchdogSec=1min
 
 # Increase the default a bit in order to allow many simultaneous
-- 
1.9.3

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


Re: [systemd-devel] Run script before the first systemd-timer is triggered? Systemd-timer in UTC?

2014-04-28 Thread Lukasz Skalski

On 04/28/2014 02:22 PM, Manuel Reimer wrote:

Lukasz Skalski  samsung.com> writes:

You can define which RTC (/dev/rtcX) should be read -
"(rtc1) RTC used to set the system time" option in kernel menuconfig.


Yes, this is possible. But my RTC does not exist until I do the following on
shell:

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device

Is there some other config option to tell the kernel to auto-initialize the
I2C clock module?


One of possibilities is add i2c_board_info struct in 
../arch/arm/XXX-mach/your_device.c file. For example:


static struct i2c_board_info __initdata XXX_i2c_devices[] = {
   {
  I2C_BOARD_INFO("rtc-ds1307", 0x68),
  .type = "ds1307",
   },
};

And in the same file (in __init XXX_init(void) function):

i2c_register_board_info(1,bcm2708_i2c_devices,ARRAY_SIZE(XXX_i2c_devices));

BR,
--
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@samsung.com



Thanks in advance.

Greetings,

Manuel

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




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


Re: [systemd-devel] Run script before the first systemd-timer is triggered? Systemd-timer in UTC?

2014-04-28 Thread Lukasz Skalski

On 04/28/2014 01:36 PM, Manuel Reimer wrote:

Mantas MikulÄ—nas  gmail.com> writes:

Doesn't the kernel already do the same via CONFIG_RTC_HCTOSYS_DEVICE?


The kernel reads from "/dev/rtc0" which is the CPU built-in RTC (iMX233). My
added RTC has to be registered first and then appears as /dev/rtc1.


Hi,

You can define which RTC (/dev/rtcX) should be read -
"(rtc1) RTC used to set the system time" option in kernel menuconfig.



Greetings,

Manuel



BR,
--
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@samsung.com


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




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


Re: [systemd-devel] bus driver on kdbus

2014-04-16 Thread Lukasz Skalski
oesn't want
to introduce a chunk of ugly code into GLib that will cause
compatibility headaches going forward if we ever need to change it.


Let's turn this around: i can see that with your gdbus design requiring
us to remarshall everything to gvaraint makes things a lot easier for
you, but it puts the work on us to do the remarshalling. If we now
conversely ask you to smply remarshall the driver msgs differently, then
you tell us that that wouldn't be dbus anymore... Jeezus...


This is not "simply remarshalling", as I mentioned above.

I'm not arguing that what you've done here is not better than D-Bus --
it clearly is; but it's different.  I'm really starting to think a good
way forward might be to get people to opt-in to this new API knowing
that there are compatibility hitches that they'll have to deal with as
they do so.  On systems that don't have kdbus, or in the event that we
cannot support it (network transparency, for example) you'd get an
oldschool dbus-1 connection, but you would still be forbidden (by API
contract) from directly sending org.freedesktop.DBus messages on it.

If we present this as a new kind of bus, perhaps we'd call it a "user
bus".

(and some new name for the system one as well, of course -- I feel a lot
less clever for that one)

It's possibly worth considering at that point if we even need the
bridge.  We could just let the people who don't opt-in to the new bus
type connect to the oldschool dbus-1 daemon.  The only problem here is
that it means that every given public protocol would need to have a
'flag day' to switch buses, and it might be nice to avoid that.  On the
other hand, in some cases, having the additional clarity might be nice,
and it may also give people a natural opportunity to fix other issues
that they have in their various APIs.



At this moment the most important is find common approach to kdbus
userspace implementation. I know that kdbus is still quite young
project and still evolving, but it would be good to have some certain
points. IMHO kdbus support in libraries shouldn't be visible outside
gdbus/libdbus- library should hide all kdbus aspects and keep dbus-1
compatibility - app developers shouldn't really notice the difference.
Next, we have to ensure that all unmodified apps will continue to work
the way they currently do.

Now we should also keep this discussion focused on technical solutions
rather than some "politics" (drop the gvariant and speak only dbus1
marshalling again or not?).



Cheers



Thanks,

--
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] bus driver on kdbus

2014-04-14 Thread Lukasz Skalski

On 04/14/2014 08:39 AM, Lennart Poettering wrote:

Lukas, Ryan,



Hi Lennart, Ryan


just wanted to let you know that I am working to get rid of the bus
driverd in systemd after all, for kdbus. The reason is that leaving it
in, as it is now, is very racy, and not just theorectically, but
IRL. Ryan, you might remember the "mouse cursor" bug when running gnome
on kdbus, we showed you two weeks ago in Nuremberg, this was caused by a
race between AddMatch being processed by the driver and a subsequent
method call to another service. Quite possibly, if the driver is
otherwise busy the method call might get executed earlier, possibly
triggering a signal, which is then not subject to the match that was to
be created. This bug only showed on gdbus since only there AddMatch is
called asychronously.



Yes, you're right, I also noticed that something is wrong with AddMatch.


Anyway, I fixed this now by making the requirement that driver calls are
executed in order on the sender side (ie. the client translates driver
bus calls into ioctls). This means the bus proxy will execute them when
a legacy dbus1 client is connected, but it is expected that a native
kdbus client will process them locally instead of ever letting them onto
the bus. Lukas, this effectively means that your initial gdbus patch was
the right way to go after all, and my request to let the driverd be in
charge was quite mislead. Sorry!


Ok, so I'll prepare and upload [1] new version of my patchset for gdbus
(with translating all bus calls into ioctls directly in library), as
soon as it's possible.



I will now remove the entirety of the driver daemon, not just
AddMatch/RemoveMatch as all but two of those calls are subject to
similar (theoretical...) races.

Ryan, I know that you really don't like having to translate the bus
driver calls on the client side, but I don't see any other way that
fixes the race and was somewhat clean to me.



Ryan, what do you think about it?


Note that in our new sd-bus.h API we won't do any translations for
this. We simply expect people to invoke our high-level C APIs rather
than construct bus calls for the driver interfaces. We can do this,
since we our C library interface is entirely new anyway. This means that
the bus driver interface is thus kinda bound to using the AF_UNIX
transport. And where the kdbus transports is used ioctls are the way to
go.

A nice side effect of this change is actually that things are a bit
faster for legacy dbus1 clients. The bus driver service so far was the
one service on the system so far got the most traffic during
startup. With this change we can entirely eliminate this.

Lennart



[1] https://bugzilla.gnome.org/show_bug.cgi?id=721861

Thanks,
--
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] doc: fix items' names in PORTING-DBUS1

2014-04-10 Thread Lukasz Skalski
---
 src/libsystemd/sd-bus/PORTING-DBUS1 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libsystemd/sd-bus/PORTING-DBUS1 
b/src/libsystemd/sd-bus/PORTING-DBUS1
index f2ebcd7..6205e32 100644
--- a/src/libsystemd/sd-bus/PORTING-DBUS1
+++ b/src/libsystemd/sd-bus/PORTING-DBUS1
@@ -342,7 +342,7 @@ items of the same type as the kernel messages include,
 i.e. KDBUS_ITEM_NAME_ADD, KDBUS_ITEM_NAME_REMOVE,
 KDBUS_ITEM_NAME_CHANGE, KDBUS_ITEM_ID_ADD, KDBUS_ITEM_ID_REMOVE and
 fill them out. Note however, that you have some wildcards in this
-case, for example the .id field of KDBUS_ITEM_ADD/KDBUS_ITEM_REMOVE
+case, for example the .id field of KDBUS_ITEM_ID_ADD/KDBUS_ITEM_ID_REMOVE
 structures may be set to 0 to match against any id addition/removal.
 
 Note that dbus match strings do no map 1:1 to these ioctl() calls. In
-- 
1.8.3.2

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


[systemd-devel] [PATCH] doc: fix items' names in PORTING-DBUS1

2014-03-31 Thread Lukasz Skalski
---
 src/libsystemd/sd-bus/PORTING-DBUS1 | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/libsystemd/sd-bus/PORTING-DBUS1 
b/src/libsystemd/sd-bus/PORTING-DBUS1
index 0253a42..f2ebcd7 100644
--- a/src/libsystemd/sd-bus/PORTING-DBUS1
+++ b/src/libsystemd/sd-bus/PORTING-DBUS1
@@ -123,8 +123,8 @@ at the same time!
 This pretty much explains the ioctl header. The actual payload of the
 data is now referenced in additional items that are attached to this
 ioctl header structure at the end. When sending a message, you attach
-items of the type PAYLOAD_VEC, PAYLOAD_MEMFD, FDS, BLOOM, DST_NAME to
-it:
+items of the type PAYLOAD_VEC, PAYLOAD_MEMFD, FDS, BLOOM_FILTER,
+DST_NAME to it:
 
KDBUS_ITEM_PAYLOAD_VEC: contains a pointer + length pair for
referencing arbitrary user memory. This is how you reference most
@@ -134,15 +134,15 @@ it:
to send prepared "memfds" (see below) over. This item contains an
fd for a memfd plus a size.
 
-   KDBUS_ITEM_PAYLOAD_FDS: for sending over fds attach an item of this
-   type with an array of fds.
+   KDBUS_ITEM_FDS: for sending over fds attach an item of this type with
+   an array of fds.
 
-   KDBUS_ITEM_BLOOM: the calculated bloom filter of this message, only
-   for undirected (broadcast) message.
+   KDBUS_ITEM_BLOOM_FILTER: the calculated bloom filter of this message,
+   only for undirected (broadcast) message.
 
-   KDBUS_DST_NAME: for messages that are directed to a well-known name
-   (instead of a unique name), this item contains the well-known name
-   field.
+   KDBUS_ITEM_DST_NAME: for messages that are directed to a well-known
+   name (instead of a unique name), this item contains the well-known
+   name field.
 
 A single message may consists of no, one or more payload items of type
 PAYLOAD_VEC or PAYLOAD_MEMFD. D-Bus protocol implementations should
-- 
1.8.3.2

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


Re: [systemd-devel] [PATCH] busctl: install bash completion

2014-02-19 Thread Lukasz Skalski

On 02/19/2014 06:58 PM, Michael Biebl wrote:

2014-02-19 17:45 GMT+01:00 Thomas H.P. Andersen :

From: Thomas Hindoe Paaboel Andersen 

---
  Makefile.am | 1 +
  1 file changed, 1 insertion(+)

diff --git a/Makefile.am b/Makefile.am
index b36b42d..8d58c52 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -348,6 +348,7 @@ systemgenerator_PROGRAMS = \
 systemd-system-update-generator

  dist_bashcompletion_DATA = \
+   shell-completion/bash/busctl \
 shell-completion/bash/journalctl \
 shell-completion/bash/systemctl \
 shell-completion/bash/systemd-analyze \


Shouldn't we install those files conditionally, based on --enable-kdbus ?




No, busctl can be used also with standard dbus.

BR,
--
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2014-01-17 Thread Lukasz Skalski

On 12/20/2013 04:23 PM, Yin Kangkai wrote:


Will it be more interesting to show some real benchmarking numbers? ;)

  - results with vanilla GIO;
  - results with GIO with kdbus transport, talking to kdbus
dbus-daemon;
  - results with GIO with kdbus transport, talking through systemd-bus-proxyd
to systemd-bus-driverd;

Regards,
Kangkai



Hi Kangkai,

Here you can find some real benchmarking numbers:

http://lists.freedesktop.org/archives/dbus/2014-January/016074.html

--
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@partner.samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] bus: Fix read_word_le() function

2014-01-17 Thread Lukasz Skalski
---
 src/libsystemd/bus-message.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libsystemd/bus-message.c b/src/libsystemd/bus-message.c
index 0c8604c..1a2039b 100644
--- a/src/libsystemd/bus-message.c
+++ b/src/libsystemd/bus-message.c
@@ -1935,7 +1935,7 @@ static size_t read_word_le(void *p, size_t sz) {
 return le16toh(x.u16);
 else if (sz == 4)
 return le32toh(x.u32);
-else if (sz == 4)
+else if (sz == 8)
 return le64toh(x.u64);
 
 assert_not_reached("unknown word width");
-- 
1.8.3.2

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


Re: [systemd-devel] libsystemd-bus and glib port - problem with GVariant Serialization

2014-01-14 Thread Lukasz Skalski

On 01/11/2014 11:48 PM, Zbigniew Jędrzejewski-Szmek wrote:

On Thu, Jan 02, 2014 at 10:52:44AM +0100, Lukasz Skalski wrote:

As you can see above, path name, interface name and others string
are in the same place. Problem is with signature positions. Any
ideas on what could be causing the problem?


http://cgit.freedesktop.org/systemd/systemd/commit/?id=ec260ed ?

Zbyszek



The  problem has been now solved. Thanks for link Zbyszek, but it wasn't 
the cause of the problem.


Tomorrow first test my glib without bus-proxyd :)

--
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@partner.samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] libsystemd-bus and glib port - problem with GVariant Serialization

2014-01-02 Thread Lukasz Skalski

Hi,

I'm working on port gdbus natively onto kdbus. I've already done most 
part of this project - Hello, RequestName, ReleaseName, List*, Get*, 
NameHasOwner and others org.freedesktop.DBus methods are implemented and 
works great, what is still missing at this moment are AddMatch and 
RemoveMatch, but it shouldn't be problem and it will be done as soon as 
I solve the current problem with serialization. So...


In glib, I changed header protocol version to '2' (header already has 
field with information about length of the additional header fields 
array - everything is as described it in GVARIANT-SERIALIZATION 
document), but if I try send method call from my gio test apllication to 
second application (which uses libsystemd-bus) I get "Bad message" from 
libsystemd-bus. It is probably problem with serialization in my glib...


I did some research. I prepared two applications - first uses my glib 
with kdbus interface, second uses libsystemd-bus. Both applications 
invoke the same method call as below:


1) Application 1 (GLIB)

  result = g_dbus_connection_call_sync (connection,
"org.freedesktop.systemd.test",
"/",
"org.freedesktop.systemd.test",
"Slow",
NULL,
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);

2) Application 2 (LIBSYSTEMD-BUS)

r = sd_bus_message_new_method_call(
bus,
"org.freedesktop.systemd.test",
"/",
"org.freedesktop.systemd.test",
"Slow",
&m);
if (r < 0) {
log_error("Failed to allocate method call: %s", 
strerror(-r));

goto finish;co je
}

sd_bus_message_unref(reply);
reply = NULL;

r = sd_bus_call(bus, m, 0, &error, &reply);


After that I added hexdump() function to libsystemd-bus and compared the 
same method invocation in glib and libsystemd-bus after serialization:


1) Application 1 (GLIB)

: 6c 01 00 02 00 00 00 00 02 00 00 00 6d 00 00 00 l...m...
0010: 01 01 6f 00 01 00 00 00 2f 00 00 00 00 00 00 00 ..o./...
0020: 03 01 73 00 04 00 00 00 53 6c 6f 77 00 00 00 00 ..s.Slow
0030: 02 01 73 00 1c 00 00 00 6f 72 67 2e 66 72 65 65 ..s.org.free
0040: 64 65 73 6b 74 6f 70 2e 73 79 73 74 65 6d 64 2e desktop.systemd.
0050: 74 65 73 74 00 00 00 00 06 01 73 00 1c 00 00 00 test..s.
0060: 6f 72 67 2e 66 72 65 65 64 65 73 6b 74 6f 70 2e org.freedesktop.
0070: 73 79 73 74 65 6d 64 2e 74 65 73 74 00 00 00 00 systemd.test

2) Application 2 (LIBSYSTEMD-BUS)

: 6c 01 00 02 00 00 00 00 01 00 00 00 73 00 00 00 l...s...
0010: 01 00 00 00 00 00 00 00 2f 00 00 6f 00 00 00 00 /..o
0020: 03 00 00 00 00 00 00 00 53 6c 6f 77 00 00 73 00 Slow..s.
0030: 02 00 00 00 00 00 00 00 6f 72 67 2e 66 72 65 65 org.free
0040: 64 65 73 6b 74 6f 70 2e 73 79 73 74 65 6d 64 2e desktop.systemd.
0050: 74 65 73 74 00 00 73 00 06 00 00 00 00 00 00 00 test..s.
0060: 6f 72 67 2e 66 72 65 65 64 65 73 6b 74 6f 70 2e org.freedesktop.
0070: 73 79 73 74 65 6d 64 2e 74 65 73 74 00 00 73 0c systemd.test..s.
0080: 1f 47 6f 00 00 00 00 00 .Go.

As you can see above, path name, interface name and others string are in 
the same place. Problem is with signature positions. Any ideas on what 
could be causing the problem?


BR,
--
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@partner.samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] bus-driverd: fix flags translation in driver_request_name

2013-12-18 Thread Lukasz Skalski
Flags for a name entry (KDBUS_NAME_*) should be set for
cmd_name->flags (not conn_flags)
---
 src/bus-driverd/bus-driverd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/bus-driverd/bus-driverd.c b/src/bus-driverd/bus-driverd.c
index b11eb55..f28dc57 100644
--- a/src/bus-driverd/bus-driverd.c
+++ b/src/bus-driverd/bus-driverd.c
@@ -303,7 +303,7 @@ static int driver_request_name(sd_bus *bus, sd_bus_message 
*m, void *userdata, s
 n = alloca0(size);
 n->size = size;
 memcpy(n->name, name, l+1);
-kdbus_translate_request_name_flags(flags, (uint64_t *) &n->conn_flags);
+kdbus_translate_request_name_flags(flags, (uint64_t *) &n->flags);
 
 /* This function is open-coded because we request the name 'on behalf'
  * of the requesting connection */
-- 
1.8.3.2

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


[systemd-devel] [PATCHv3] bus-driverd: Fix return code in driver_request_name

2013-12-17 Thread Lukasz Skalski
RequestName return codes should be consistent with Dbus Specification.

VALUE - DESCRIPTION
1-The caller is now the primary owner of the name, replacing any previous owner,
2-The name already had an owner (QUEUE flag was not specified),
3-The name already has an owner (QUEUE flag was specified),
4-Application trying to request ownership of a name is already the owner of it.
---
 src/bus-driverd/bus-driverd.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/bus-driverd/bus-driverd.c b/src/bus-driverd/bus-driverd.c
index 11bd2f9..a1ad050 100644
--- a/src/bus-driverd/bus-driverd.c
+++ b/src/bus-driverd/bus-driverd.c
@@ -348,10 +348,19 @@ static int driver_request_name(sd_bus *bus, 
sd_bus_message *m, void *userdata, s
 cmd_name->id = id;
 
 r = ioctl(sd_bus_get_fd(bus), KDBUS_CMD_NAME_ACQUIRE, cmd_name);
-if (r < 0)
-return r;
+if (r < 0) {
+if (errno == EEXIST)
+return sd_bus_reply_method_return(m, "u", 
BUS_NAME_EXISTS);
+else if (errno == EALREADY)
+return sd_bus_reply_method_return(m, "u", 
BUS_NAME_ALREADY_OWNER);
+else
+return sd_bus_reply_method_return(m, "u", -errno);
+}
+
+if (cmd_name->flags & KDBUS_NAME_IN_QUEUE)
+return sd_bus_reply_method_return(m, "u", BUS_NAME_IN_QUEUE);
 
-return sd_bus_reply_method_return(m, "u", 0);
+return sd_bus_reply_method_return(m, "u", BUS_NAME_PRIMARY_OWNER);
 }
 
 static int driver_start_service_by_name(sd_bus *bus, sd_bus_message *m, void 
*userdata, sd_bus_error *error) {
-- 
1.8.3.2

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


Re: [systemd-devel] [PATCHv2] bus-driverd: Fix return code in driver_request_name

2013-12-17 Thread Lukasz Skalski

On 12/17/2013 05:16 PM, Lennart Poettering wrote:

On Tue, 17.12.13 15:54, Zbigniew Jędrzejewski-Szmek (zbys...@in.waw.pl) wrote:



On Tue, Dec 17, 2013 at 02:31:42PM +0100, Lukasz Skalski wrote:

RequestName return codes should be consistent with Dbus Specification.

VALUE - DESCRIPTION
1-The caller is now the primary owner of the name, replacing any previous owner,
2-The name already had an owner (QUEUE flag was not specified),
3-The name already has an owner (QUEUE flag was specified),
4-Application trying to request ownership of a name is already the owner of it.

Please turn this into an enum.


We already have an enum for that, defined in bus-protocol.h

Lennart



Ok, thanks for info. I'll use enum vale from bus-protocol.h

--
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@partner.samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCHv2] bus-driverd: Fix return code in driver_request_name

2013-12-17 Thread Lukasz Skalski
RequestName return codes should be consistent with Dbus Specification.

VALUE - DESCRIPTION
1-The caller is now the primary owner of the name, replacing any previous owner,
2-The name already had an owner (QUEUE flag was not specified),
3-The name already has an owner (QUEUE flag was specified),
4-Application trying to request ownership of a name is already the owner of it.
---
 src/bus-driverd/bus-driverd.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/bus-driverd/bus-driverd.c b/src/bus-driverd/bus-driverd.c
index d2b3e08..dd5eb33 100644
--- a/src/bus-driverd/bus-driverd.c
+++ b/src/bus-driverd/bus-driverd.c
@@ -403,10 +403,19 @@ static int driver_request_name(sd_bus *bus, 
sd_bus_message *m, void *userdata, s
 cmd_name->id = id;
 
 r = ioctl(sd_bus_get_fd(bus), KDBUS_CMD_NAME_ACQUIRE, cmd_name);
-if (r < 0)
-return r;
+if (r < 0) {
+if (errno == EEXIST)
+return sd_bus_reply_method_return(m, "u", 3);
+else if (errno == EALREADY)
+return sd_bus_reply_method_return(m, "u", 4);
+else
+return sd_bus_reply_method_return(m, "u", -r);
+}
+
+if (cmd_name->flags & KDBUS_NAME_IN_QUEUE)
+return sd_bus_reply_method_return(m, "u", 2);
 
-return sd_bus_reply_method_return(m, "u", 0);
+return sd_bus_reply_method_return(m, "u", 1);
 }
 
 static int driver_start_service_by_name(sd_bus *bus, sd_bus_message *m, void 
*userdata, sd_bus_error *error) {
-- 
1.8.3.2

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


Re: [systemd-devel] [PATCH] bus-driverd: Fix return code in driver_request_name

2013-12-17 Thread Lukasz Skalski

Please ignore this patch - it contains errors. Sorry.

BR,
Lukasz

On 12/17/2013 01:48 PM, Lukasz Skalski wrote:

RequestName return codes should be consistent with
Dbus Specification.

VALUE - DESCRIPTION
1 - The caller is now the primary owner of the name, replacing any previous 
owner,
2 - The name already had an owner (QUEUE flag was not specified),
3 - The name already has an owner (QUEUE flag was specified),
4 - Application trying to request ownership of a name is already the owner of 
it.
---
  src/bus-driverd/bus-driverd.c | 12 +---
  1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/bus-driverd/bus-driverd.c b/src/bus-driverd/bus-driverd.c
index d2b3e08..36d90df 100644
--- a/src/bus-driverd/bus-driverd.c
+++ b/src/bus-driverd/bus-driverd.c
@@ -403,10 +403,16 @@ static int driver_request_name(sd_bus *bus, 
sd_bus_message *m, void *userdata, s
  cmd_name->id = id;

  r = ioctl(sd_bus_get_fd(bus), KDBUS_CMD_NAME_ACQUIRE, cmd_name);
-if (r < 0)
-return r;

-return sd_bus_reply_method_return(m, "u", 0);
+if (r == EEXIST)
+return sd_bus_reply_method_return(m, "u", 3);
+else if (r == EALREADY)
+return sd_bus_reply_method_return(m, "u", 4);
+else if (r == 0)
+return sd_bus_reply_method_return(m, "u", 2);
+else
+return sd_bus_reply_method_return(m, "u", 1);
+
  }

  static int driver_start_service_by_name(sd_bus *bus, sd_bus_message *m, void 
*userdata, sd_bus_error *error) {




--
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@partner.samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] bus-driverd: Fix return code in driver_request_name

2013-12-17 Thread Lukasz Skalski
RequestName return codes should be consistent with
Dbus Specification.

VALUE - DESCRIPTION
1 - The caller is now the primary owner of the name, replacing any previous 
owner,
2 - The name already had an owner (QUEUE flag was not specified),
3 - The name already has an owner (QUEUE flag was specified),
4 - Application trying to request ownership of a name is already the owner of 
it.
---
 src/bus-driverd/bus-driverd.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/bus-driverd/bus-driverd.c b/src/bus-driverd/bus-driverd.c
index d2b3e08..36d90df 100644
--- a/src/bus-driverd/bus-driverd.c
+++ b/src/bus-driverd/bus-driverd.c
@@ -403,10 +403,16 @@ static int driver_request_name(sd_bus *bus, 
sd_bus_message *m, void *userdata, s
 cmd_name->id = id;
 
 r = ioctl(sd_bus_get_fd(bus), KDBUS_CMD_NAME_ACQUIRE, cmd_name);
-if (r < 0)
-return r;
 
-return sd_bus_reply_method_return(m, "u", 0);
+if (r == EEXIST)
+return sd_bus_reply_method_return(m, "u", 3);
+else if (r == EALREADY)
+return sd_bus_reply_method_return(m, "u", 4);
+else if (r == 0)
+return sd_bus_reply_method_return(m, "u", 2);
+else
+return sd_bus_reply_method_return(m, "u", 1);
+
 }
 
 static int driver_start_service_by_name(sd_bus *bus, sd_bus_message *m, void 
*userdata, sd_bus_error *error) {
-- 
1.8.3.2

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


[systemd-devel] [PATCH] [RFC] libsystemd-bus: true/false instead of yes/no in msg dump

2013-12-17 Thread Lukasz Skalski
Due to this patch, message dump (for message which includes boolean
type) is more consistent with dbus-send (which display true/false
instead of yes/no for boolean). It's only simple 'cosmetics change'.

** For dbus-send **

dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply 
/ org.freedesktop.DBus.NameHasOwner string:org.freedesktop.login1

method return sender=org.freedesktop.DBus -> dest=:1.97 reply_serial=2
   boolean true

** For libsystemd-bus (without this patch) **

‣ Type=method_call  Endian=l  Flags=0  Version=2 Serial=8
  Destination=org.freedesktop.DBus  Path=/org/freedesktop/DBus  
Interface=org.freedesktop.DBus  Member=NameHasOwner
  MESSAGE "s" {
STRING "org.freedesktop.login1";
  };

‣ Type=method_return  Endian=l  Flags=1  Version=2 Serial=51  ReplySerial=8
  Sender=:1.59  Destination=:1.67
  UniqueName=:1.59  WellKnownNames={org.freedesktop.DBus}
  MESSAGE "b" {
BOOLEAN yes;
  };

For me true/false seems to be better readable than yes/no for BOOLEAN.
---
 src/libsystemd-bus/bus-dump.c | 2 +-
 src/shared/util.h | 4 
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/libsystemd-bus/bus-dump.c b/src/libsystemd-bus/bus-dump.c
index ddad418..7b61479 100644
--- a/src/libsystemd-bus/bus-dump.c
+++ b/src/libsystemd-bus/bus-dump.c
@@ -200,7 +200,7 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool 
with_header) {
 break;
 
 case SD_BUS_TYPE_BOOLEAN:
-fprintf(f, "%sBOOLEAN %s%s%s;\n", prefix, 
ansi_highlight(), yes_no(basic.i), ansi_highlight_off());
+fprintf(f, "%sBOOLEAN %s%s%s;\n", prefix, 
ansi_highlight(), true_false(basic.i), ansi_highlight_off());
 break;
 
 case SD_BUS_TYPE_INT16:
diff --git a/src/shared/util.h b/src/shared/util.h
index dd51e89..1d17826 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -92,6 +92,10 @@ static inline const char* yes_no(bool b) {
 return b ? "yes" : "no";
 }
 
+static inline const char* true_false(bool b) {
+return b ? "true" : "false";
+}
+
 static inline const char* strempty(const char *s) {
 return s ? s : "";
 }
-- 
1.8.3.2

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


[systemd-devel] [PATCH] bus-driverd: Fix unique name return in driver_get_name_owner

2013-12-17 Thread Lukasz Skalski
---
 src/bus-driverd/bus-driverd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/bus-driverd/bus-driverd.c b/src/bus-driverd/bus-driverd.c
index ce2e1b2..d2b3e08 100644
--- a/src/bus-driverd/bus-driverd.c
+++ b/src/bus-driverd/bus-driverd.c
@@ -247,7 +247,7 @@ static int driver_get_name_owner(sd_bus *bus, 
sd_bus_message *m, void *userdata,
 if (r < 0)
 return r;
 
-r = sd_bus_get_owner(bus, arg0, 0, &creds);
+r = sd_bus_get_owner(bus, arg0, SD_BUS_CREDS_UNIQUE_NAME, &creds);
 if (r < 0) {
 if (r == -ENOENT)
 return driver_name_info_error(bus, m, arg0, r);
-- 
1.8.3.2

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


[systemd-devel] [PATCH] libsystemd-bus: the same error codes for sd_bus_release_name() (for kdbus and dbus1)

2013-12-13 Thread Lukasz Skalski
Due to this patch, sd_bus_release_name() function
returns the same code errors for kdbus and dbus1
if we try release non-existing name or foreign
name.
---
 src/libsystemd-bus/bus-control.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
index 5125fd9..0072c37 100644
--- a/src/libsystemd-bus/bus-control.c
+++ b/src/libsystemd-bus/bus-control.c
@@ -184,9 +184,9 @@ static int bus_release_name_dbus1(sd_bus *bus, const char 
*name) {
 if (r < 0)
 return r;
 if (ret == BUS_NAME_NON_EXISTENT)
-return -ENOENT;
+return -ESRCH;
 if (ret == BUS_NAME_NOT_OWNER)
-return -EADDRNOTAVAIL;
+return -EADDRINUSE;
 if (ret == BUS_NAME_RELEASED)
 return 0;
 
-- 
1.8.3.2

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


[systemd-devel] [PATCH] build-sys: fix help text for --enable-kdbus

2013-12-13 Thread Lukasz Skalski
---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 6ada38a..f85e86e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -801,7 +801,7 @@ AM_CONDITIONAL(ENABLE_MULTI_SEAT_X, [test 
"$have_multi_seat_x" = "yes"])
 
 # 
--
 have_kdbus=no
-AC_ARG_ENABLE(kdbus, AS_HELP_STRING([--enable-kdbus], [do not connect to kdbus 
by default]))
+AC_ARG_ENABLE(kdbus, AS_HELP_STRING([--enable-kdbus], [do connect to kdbus by 
default]))
 if test "x$enable_kdbus" == "xyes"; then
 AC_DEFINE(ENABLE_KDBUS, 1, [Define if kdbus support is to be enabled])
 have_kdbus=yes
-- 
1.8.3.2

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


Re: [systemd-devel] [PATCH] bus: Add support for eavesdrop in sd_bus_add_match()

2013-12-12 Thread Lukasz Skalski

On 12/12/2013 04:22 PM, Simon McVittie wrote:

On 12/12/13 14:28, Lennart Poettering wrote:

kay and Daniel are working on changing the semantics of monitoring
entirely. Instead of turning monitoring on and off on an existing
connection they want this to be an entirely new connection type


Colin Walters wanted to do this in dbus-daemon too (a separate
/var/run/dbus/system_bus_monitor_socket that's only accessible by root,
or something), but nobody has got round to it yet.



I didn't know nothing about above plans - new connection type in kdbus 
and /var/run/dbus/system_bus_monitor_socket in dbus, so support for 
eavesdrop seemed to be missing in libsystemd-bus for me (especially that 
at this moment busctl prints infos only about signals).


Thanks for explanations.


Another possibility might be to make the eavesdropped stream obviously
not the same thing as the normal D-Bus stream, for instance by wrapping
it in pcap format as used by bustle(1) (as in my proof-of-concept
dbus-daemon patches on
<https://bugs.freedesktop.org/show_bug.cgi?id=60859>). bustle-pcap(1) is
a standalone implementation of "connect, eavesdrop, produce a pcap
stream" for traditional D-Bus, similar to dbus-monitor.


the
same way as "starter" (i.e. those which may be used to take a well-known
name and get notified when the service behind it needs to be activated)
connections are different from normal connections


Please consider naming this differently: "starter" in the D-Bus
Specification (e.g. DBUS_STARTER_ADDRESS) is something rather different.
Maybe "placeholder"?


(Which would break compat wit traditional dbus I figure, but that should
be OK given that monitoring is a debugging feature anyway.)


Yes, I think anyone using eavesdropping for purposes other than a
debugging tool is wrong; when we added eavesdrop="true" to dbus-daemon,
it broke compatibility with older client libraries anyway.

 S

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



--
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@partner.samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] bus: Add support for eavesdrop in sd_bus_add_match()

2013-12-12 Thread Lukasz Skalski
Due to this patch, 'busctl monitor' prints all method calls,
method errors and signals both for dbus and kdbus.
---
 src/libsystemd-bus/bus-control.c |  6 ++
 src/libsystemd-bus/bus-match.c   | 10 ++
 src/libsystemd-bus/bus-match.h   |  1 +
 src/libsystemd-bus/busctl.c  |  2 +-
 4 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
index 2682439..525e452 100644
--- a/src/libsystemd-bus/bus-control.c
+++ b/src/libsystemd-bus/bus-control.c
@@ -958,6 +958,12 @@ static int bus_add_match_internal_kernel(
 }
 break;
 
+case BUS_MATCH_EAVESDROP:
+if (streq(c->value_str, "true")) {
+bus_kernel_monitor(bus);
+}
+break;
+
 case BUS_MATCH_ARG...BUS_MATCH_ARG_LAST: {
 char buf[sizeof("arg")-1 + 2 + 1];
 
diff --git a/src/libsystemd-bus/bus-match.c b/src/libsystemd-bus/bus-match.c
index f7fca5f..3da401c 100644
--- a/src/libsystemd-bus/bus-match.c
+++ b/src/libsystemd-bus/bus-match.c
@@ -163,6 +163,7 @@ static bool value_node_test(
 case BUS_MATCH_INTERFACE:
 case BUS_MATCH_MEMBER:
 case BUS_MATCH_PATH:
+case BUS_MATCH_EAVESDROP:
 case BUS_MATCH_ARG ... BUS_MATCH_ARG_LAST:
 return streq_ptr(node->value.str, value_str);
 
@@ -203,6 +204,7 @@ static bool value_node_same(
 case BUS_MATCH_INTERFACE:
 case BUS_MATCH_MEMBER:
 case BUS_MATCH_PATH:
+case BUS_MATCH_EAVESDROP:
 case BUS_MATCH_ARG ... BUS_MATCH_ARG_LAST:
 case BUS_MATCH_ARG_NAMESPACE ... BUS_MATCH_ARG_NAMESPACE_LAST:
 case BUS_MATCH_PATH_NAMESPACE:
@@ -310,6 +312,9 @@ int bus_match_run(
 test_str = m->path;
 break;
 
+case BUS_MATCH_EAVESDROP:
+break;
+
 case BUS_MATCH_ARG ... BUS_MATCH_ARG_LAST:
 test_str = bus_message_get_arg(m, node->type - BUS_MATCH_ARG);
 break;
@@ -590,6 +595,8 @@ enum bus_match_node_type 
bus_match_node_type_from_string(const char *k, size_t n
 return BUS_MATCH_PATH;
 if (n == 14 && startswith(k, "path_namespace"))
 return BUS_MATCH_PATH_NAMESPACE;
+if (n == 9 && startswith(k, "eavesdrop"))
+return BUS_MATCH_EAVESDROP;
 
 if (n == 4 && startswith(k, "arg")) {
 int j;
@@ -949,6 +956,9 @@ const char* bus_match_node_type_to_string(enum 
bus_match_node_type t, char buf[]
 case BUS_MATCH_PATH_NAMESPACE:
 return "path_namespace";
 
+case BUS_MATCH_EAVESDROP:
+return "eavesdrop";
+
 case BUS_MATCH_ARG ... BUS_MATCH_ARG_LAST:
 snprintf(buf, l, "arg%i", t - BUS_MATCH_ARG);
 return buf;
diff --git a/src/libsystemd-bus/bus-match.h b/src/libsystemd-bus/bus-match.h
index 1d38126..17b50cb 100644
--- a/src/libsystemd-bus/bus-match.h
+++ b/src/libsystemd-bus/bus-match.h
@@ -38,6 +38,7 @@ enum bus_match_node_type {
 BUS_MATCH_MEMBER,
 BUS_MATCH_PATH,
 BUS_MATCH_PATH_NAMESPACE,
+BUS_MATCH_EAVESDROP,
 BUS_MATCH_ARG,
 BUS_MATCH_ARG_LAST = BUS_MATCH_ARG + 63,
 BUS_MATCH_ARG_PATH,
diff --git a/src/libsystemd-bus/busctl.c b/src/libsystemd-bus/busctl.c
index 57bc83d..5f86e0d 100644
--- a/src/libsystemd-bus/busctl.c
+++ b/src/libsystemd-bus/busctl.c
@@ -206,7 +206,7 @@ static int monitor(sd_bus *bus, char *argv[]) {
 }
 
 if (!added_something) {
-r = sd_bus_add_match(bus, "", NULL, NULL);
+r = sd_bus_add_match(bus, "eavesdrop='true'", NULL, NULL);
 if (r < 0) {
 log_error("Failed to add match: %s", strerror(-r));
 return r;
-- 
1.8.3.2

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


[systemd-devel] [PATCH] libsystemd-bus: Add checking masks creds in bus_creds_dump() function

2013-12-11 Thread Lukasz Skalski
log_assert_failed_return macro generates a lot of logs when we use
bus_message_dump() function without checking masks in creds.
---
 src/libsystemd-bus/bus-dump.c | 93 +++
 1 file changed, 59 insertions(+), 34 deletions(-)

diff --git a/src/libsystemd-bus/bus-dump.c b/src/libsystemd-bus/bus-dump.c
index ddad418..85396aa 100644
--- a/src/libsystemd-bus/bus-dump.c
+++ b/src/libsystemd-bus/bus-dump.c
@@ -322,9 +322,12 @@ int bus_creds_dump(sd_bus_creds *c, FILE *f) {
 fprintf(f, "  TID=%lu", (unsigned long) c->tid);
 if (c->mask & SD_BUS_CREDS_UID)
 fprintf(f, "  UID=%lu", (unsigned long) c->uid);
-r = sd_bus_creds_get_owner_uid(c, &owner);
-if (r >= 0)
-fprintf(f, "  OwnerUID=%lu", (unsigned long) owner);
+if (c->mask & SD_BUS_CREDS_OWNER_UID) {
+r = sd_bus_creds_get_owner_uid(c, &owner);
+if (r >= 0)
+fprintf(f, "  OwnerUID=%lu", (unsigned long) owner);
+}
+
 if (c->mask & SD_BUS_CREDS_GID)
 fprintf(f, "  GID=%lu", (unsigned long) c->gid);
 
@@ -359,29 +362,45 @@ int bus_creds_dump(sd_bus_creds *c, FILE *f) {
 
 if (c->mask & SD_BUS_CREDS_CGROUP)
 fprintf(f, "  CGroup=%s", c->cgroup);
-sd_bus_creds_get_unit(c, &u);
-if (u)
-fprintf(f, "  Unit=%s", u);
-sd_bus_creds_get_user_unit(c, &uu);
-if (uu)
-fprintf(f, "  UserUnit=%s", uu);
-sd_bus_creds_get_slice(c, &sl);
-if (sl)
-fprintf(f, "  Slice=%s", sl);
-sd_bus_creds_get_session(c, &s);
-if (s)
-fprintf(f, "  Session=%s", s);
+if (c->mask & SD_BUS_CREDS_UNIT) {
+sd_bus_creds_get_unit(c, &u);
+if (u)
+fprintf(f, "  Unit=%s", u);
+}
+
+if (c->mask & SD_BUS_CREDS_USER_UNIT) {
+sd_bus_creds_get_user_unit(c, &uu);
+if (uu)
+fprintf(f, "  UserUnit=%s", uu);
+}
+
+if (c->mask & SD_BUS_CREDS_SLICE) {
+sd_bus_creds_get_slice(c, &sl);
+if (sl)
+fprintf(f, "  Slice=%s", sl);
+}
+
+if (c->mask & SD_BUS_CREDS_SESSION) {
+sd_bus_creds_get_session(c, &s);
+if (s)
+fprintf(f, "  Session=%s", s);
+}
 
 if ((c->mask & SD_BUS_CREDS_CGROUP) || u || uu || sl || s)
 fputs("\n", f);
 
-if (sd_bus_creds_get_audit_login_uid(c, &audit_loginuid) >= 0) {
-audit_loginuid_is_set = true;
-fprintf(f, "  AuditLoginUID=%lu", (unsigned long) 
audit_loginuid);
+if (c->mask & SD_BUS_CREDS_AUDIT_LOGIN_UID) {
+if (sd_bus_creds_get_audit_login_uid(c, &audit_loginuid) >= 0) 
{
+audit_loginuid_is_set = true;
+fprintf(f, "  AuditLoginUID=%lu", (unsigned long) 
audit_loginuid);
+}
 }
-if (sd_bus_creds_get_audit_session_id(c, &audit_sessionid) >= 0) {
-audit_sessionid_is_set = true;
-fprintf(f, "  AuditSessionID=%lu", (unsigned long) 
audit_sessionid);
+
+if (c->mask & SD_BUS_CREDS_AUDIT_SESSION_ID) {
+if (sd_bus_creds_get_audit_session_id(c, &audit_sessionid) >= 
0) {
+audit_sessionid_is_set = true;
+fprintf(f, "  AuditSessionID=%lu", (unsigned long) 
audit_sessionid);
+}
 }
 
 if (audit_loginuid_is_set || audit_sessionid_is_set)
@@ -390,27 +409,33 @@ int bus_creds_dump(sd_bus_creds *c, FILE *f) {
 if (c->mask & SD_BUS_CREDS_UNIQUE_NAME)
 fprintf(f, "  UniqueName=%s", c->unique_name);
 
-if (sd_bus_creds_get_well_known_names(c, &well_known) >= 0) {
-char **i;
+if (c->mask & SD_BUS_CREDS_WELL_KNOWN_NAMES) {
+if (sd_bus_creds_get_well_known_names(c, &well_known) >= 0) {
+char **i;
 
-fputs("  WellKnownNames={", f);
-STRV_FOREACH(i, well_known) {
-if (i != well_known)
-fputc(' ', f);
+fputs("  WellKnownNames={", f);
+STRV_FOREACH(i, well_known) {
+if (i != well_known)
+fputc(' ', f);
 
-fputs(*i, f);
-}
+fputs(*i, f);
+}
 
-fputc('}', f);
+fputc('}', f);
+}
 }
 
 if (c->mask & SD_BUS_CREDS_UNIQUE_NAME || well_known)
 fputc('\n', f);
 
-dump_capabilities(c, f, "EffectiveCapabilities", 

Re: [systemd-devel] [PATCH] libsystemd-bus: Add return error msg for unicast signals when well-known name is not available

2013-12-10 Thread Lukasz Skalski

On 12/10/2013 09:42 PM, Lennart Poettering wrote:

On Tue, 10.12.13 21:27, Lukasz Skalski (lukasz.skal...@op.pl) wrote:



On 12/10/2013 08:24 PM, Lennart Poettering wrote:

On Wed, 04.12.13 14:44, Lukasz Skalski (l.skal...@partner.samsung.com) wrote:


ENXIO, ESRCH and EADDRNOTAVAIL are also returned by ioctl(KDBUS_CMD_MSG_SEND)
when we have unicast signal messages (signals with a DESTINATION
field).


Well, but you cannot respond to signals. They are supposed to be these
one-time things you send out, where no response is coming back. Method
calls otoh are supposed to have responses where either method success or
method failure is returned.


Yes, I know that we cannot respond to signals, but this could be
useful for further (of course if you'll plan this kind of
functionality) messages/signals monitoring.


Hmm, printing a log_debug() message when delivery fails would certainly
be a good idea. I have changed the code like that now.


For example, in GDBUS we can set G_DBUS_DEBUG variable to a list of
debug options, which cause GLib to print out different types of
debugging information. When we send unicast signal to non-exist
destination (in this example test.bus.glib) we can see:



Above error message is not visible in user application, but is very
useful for debugging purposes (we can easily check what happen with
our signal).

IMHO it would be nice to have similar functionality in
libsystemd-bus. What is your opinion about this idea?


Hmm, do you need more than the log_debug() bits I added now?


No, log_debug() with information that "destination isn't know" seems to 
be good enough solution.




Something else I'd like to see added to kdbus is that we install PID
matches for messages. i.e. a way to subscribe to all messages sent by or
delivered to a specific PID. This could then be used for "busctl
monitor" to give it an almost "strace"-like feel, how one could watch at
any time what specific processes log.

Lennart



--
BR,
Lukasz Skalski
lukasz.skal...@op.pl
www.lukasz-skalski.com

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


Re: [systemd-devel] [PATCH] libsystemd-bus: Add return error msg for unicast signals when well-known name is not available

2013-12-10 Thread Lukasz Skalski

On 12/10/2013 08:24 PM, Lennart Poettering wrote:

On Wed, 04.12.13 14:44, Lukasz Skalski (l.skal...@partner.samsung.com) wrote:


ENXIO, ESRCH and EADDRNOTAVAIL are also returned by ioctl(KDBUS_CMD_MSG_SEND)
when we have unicast signal messages (signals with a DESTINATION
field).


Well, but you cannot respond to signals. They are supposed to be these
one-time things you send out, where no response is coming back. Method
calls otoh are supposed to have responses where either method success or
method failure is returned.


Yes, I know that we cannot respond to signals, but this could be useful 
for further (of course if you'll plan this kind of functionality) 
messages/signals monitoring.


For example, in GDBUS we can set G_DBUS_DEBUG variable to a list of 
debug options, which cause GLib to print out different types of 
debugging information. When we send unicast signal to non-exist 
destination (in this example test.bus.glib) we can see:



GDBus-debug:Message:
  >>>> SENT D-Bus message (112 bytes)
  Type:signal
  Flags:   no-reply-expected
  Version: 0
  Serial:  2
  Headers:
path -> objectpath '/test/bus/glib'
interface -> 'test.bus.glib'
member -> 'SampleSignal'
destination -> 'test.bus.glib'
  Body: ()


GDBus-debug:Message:
  <<<< RECEIVED D-Bus message (202 bytes)
  Type:error
  Flags:   no-reply-expected
  Version: 0
  Serial:  3
  Headers:
error-name -> 'org.freedesktop.DBus.Error.ServiceUnknown'
reply-serial -> uint32 2
destination -> ':1.66'
sender -> 'org.freedesktop.DBus'
signature -> signature 's'
  Body: ('The name test.bus.glib was not provided by any .service files',)

Above error message is not visible in user application, but is very 
useful for debugging purposes (we can easily check what happen with our 
signal).


IMHO it would be nice to have similar functionality in libsystemd-bus. 
What is your opinion about this idea?


P.S. Of course my previously patch isn't complete at this moment, it's 
the starting point to implement something similar.




The code in question will generate an error reply for method calls on
failure, but simply eat up the error when sending a signal fails. Which
is the right thing to do...


---
  src/libsystemd-bus/bus-kernel.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index b85a10d..1499830 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -414,7 +414,7 @@ int bus_kernel_write_message(sd_bus *bus, sd_bus_message 
*m) {
  /* ENXIO: unique name not known
   * ESRCH: well-known name not known */

-if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL)
+if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL || 
m->header->type == SD_BUS_MESSAGE_SIGNAL)
  sd_bus_error_setf(&error, SD_BUS_ERROR_SERVICE_UNKNOWN, 
"Destination %s not known", m->destination);
  else
  return 0;
@@ -423,7 +423,7 @@ int bus_kernel_write_message(sd_bus *bus, sd_bus_message 
*m) {

  /* EADDRNOTAVAIL: activation is possible, but turned 
off in request flags */

-if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL)
+if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL || 
m->header->type == SD_BUS_MESSAGE_SIGNAL)
  sd_bus_error_setf(&error, SD_BUS_ERROR_SERVICE_UNKNOWN, 
"Activation of %s not requested", m->destination);
  else
  return 0;



Lennart



--
BR,
Lukasz Skalski
lukasz.skal...@op.pl
www.lukasz-skalski.com
https://plus.google.com/+LukaszSkalski
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] libsystemd-bus: Clean up code

2013-12-10 Thread Lukasz Skalski

On 12/10/2013 05:24 AM, Zbigniew Jędrzejewski-Szmek wrote:

On Mon, Dec 09, 2013 at 09:22:43PM +0100, Thomas H.P. Andersen wrote:

If I understood correctly then the assert_return was meant to be used
only on the public library functions. I can't seem to find the
reference to it so maybe I am wrong though.

There's no strong reason to limit usage to public functions. It's just
a simple macro really.


On Mon, Dec 9, 2013 at 2:09 PM, Lukasz Skalski
 wrote:

---
  src/libsystemd-bus/bus-dump.c  |  2 +-
  src/libsystemd-bus/bus-error.c |  3 +--
  src/libsystemd-bus/bus-kernel.c| 12 +++-
  src/libsystemd-bus/bus-message.c   | 12 +++-
  src/libsystemd-bus/bus-signature.c | 13 -
  5 files changed, 12 insertions(+), 30 deletions(-)

diff --git a/src/libsystemd-bus/bus-dump.c b/src/libsystemd-bus/bus-dump.c
index ddad418..a999683 100644
--- a/src/libsystemd-bus/bus-dump.c
+++ b/src/libsystemd-bus/bus-dump.c
@@ -56,7 +56,7 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool 
with_header) {

  if (with_header) {
  fprintf(f,
-"%s%s%sType=%s%s%s  Endian=%c  Flags=%u  Version=%u",
+"%s%s%sType=%s%s%s  Endian=%c  Flags=%u  Version=%u ",

I don't get this part, since a space is added in the messages right below.



There should be two blank spaces (between Version and Serial fields, 
like between Type, Endian and Flags), so this part is also ok.



  m->header->type == SD_BUS_MESSAGE_METHOD_ERROR ? 
ansi_highlight_red() :
  m->header->type == SD_BUS_MESSAGE_METHOD_RETURN ? 
ansi_highlight_green() :
  m->header->type != SD_BUS_MESSAGE_SIGNAL ? ansi_highlight() : 
"", draw_special_char(DRAW_TRIANGULAR_BULLET), ansi_highlight_off(),
diff --git a/src/libsystemd-bus/bus-error.c b/src/libsystemd-bus/bus-error.c
index 25eaf0e..4f18629 100644
--- a/src/libsystemd-bus/bus-error.c
+++ b/src/libsystemd-bus/bus-error.c
@@ -39,8 +39,7 @@ static int bus_error_name_to_errno(const char *name) {
  const char *p;
  int r;

-if (!name)
-return EINVAL;
+assert_return(name, EINVAL);

  p = startswith(name, "System.Error.");
  if (p) {
diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index 495d7e5..d5574ce 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -321,9 +321,7 @@ int bus_kernel_take_fd(sd_bus *b) {
  int r;

  assert(b);
-
-if (b->is_server)
-return -EINVAL;
+assert_return(!b->is_server, -EINVAL);

  b->use_memfd = 1;

@@ -374,9 +372,7 @@ int bus_kernel_connect(sd_bus *b) {
  assert(b->input_fd < 0);
  assert(b->output_fd < 0);
  assert(b->kernel);
-
-if (b->is_server)
-return -EINVAL;
+assert_return(!b->is_server, -EINVAL);

  b->input_fd = open(b->kernel, O_RDWR|O_NOCTTY|O_CLOEXEC);
  if (b->input_fd < 0)
@@ -904,9 +900,7 @@ int bus_kernel_pop_memfd(sd_bus *bus, void **address, 
size_t *size) {

  assert(address);
  assert(size);
-
-if (!bus || !bus->is_kernel)
-return -ENOTSUP;
+assert_return(bus || bus->is_kernel, -ENOTSUP);

You should && them here.

Good catch. Fixed up and applied.


Thanks.



Zbyszek



--
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@partner.samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] libsystemd-bus: Clean up code

2013-12-09 Thread Lukasz Skalski
---
 src/libsystemd-bus/bus-dump.c  |  2 +-
 src/libsystemd-bus/bus-error.c |  3 +--
 src/libsystemd-bus/bus-kernel.c| 12 +++-
 src/libsystemd-bus/bus-message.c   | 12 +++-
 src/libsystemd-bus/bus-signature.c | 13 -
 5 files changed, 12 insertions(+), 30 deletions(-)

diff --git a/src/libsystemd-bus/bus-dump.c b/src/libsystemd-bus/bus-dump.c
index ddad418..a999683 100644
--- a/src/libsystemd-bus/bus-dump.c
+++ b/src/libsystemd-bus/bus-dump.c
@@ -56,7 +56,7 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool 
with_header) {
 
 if (with_header) {
 fprintf(f,
-"%s%s%sType=%s%s%s  Endian=%c  Flags=%u  Version=%u",
+"%s%s%sType=%s%s%s  Endian=%c  Flags=%u  Version=%u ",
 m->header->type == SD_BUS_MESSAGE_METHOD_ERROR ? 
ansi_highlight_red() :
 m->header->type == SD_BUS_MESSAGE_METHOD_RETURN ? 
ansi_highlight_green() :
 m->header->type != SD_BUS_MESSAGE_SIGNAL ? 
ansi_highlight() : "", draw_special_char(DRAW_TRIANGULAR_BULLET), 
ansi_highlight_off(),
diff --git a/src/libsystemd-bus/bus-error.c b/src/libsystemd-bus/bus-error.c
index 25eaf0e..4f18629 100644
--- a/src/libsystemd-bus/bus-error.c
+++ b/src/libsystemd-bus/bus-error.c
@@ -39,8 +39,7 @@ static int bus_error_name_to_errno(const char *name) {
 const char *p;
 int r;
 
-if (!name)
-return EINVAL;
+assert_return(name, EINVAL);
 
 p = startswith(name, "System.Error.");
 if (p) {
diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index 495d7e5..d5574ce 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -321,9 +321,7 @@ int bus_kernel_take_fd(sd_bus *b) {
 int r;
 
 assert(b);
-
-if (b->is_server)
-return -EINVAL;
+assert_return(!b->is_server, -EINVAL);
 
 b->use_memfd = 1;
 
@@ -374,9 +372,7 @@ int bus_kernel_connect(sd_bus *b) {
 assert(b->input_fd < 0);
 assert(b->output_fd < 0);
 assert(b->kernel);
-
-if (b->is_server)
-return -EINVAL;
+assert_return(!b->is_server, -EINVAL);
 
 b->input_fd = open(b->kernel, O_RDWR|O_NOCTTY|O_CLOEXEC);
 if (b->input_fd < 0)
@@ -904,9 +900,7 @@ int bus_kernel_pop_memfd(sd_bus *bus, void **address, 
size_t *size) {
 
 assert(address);
 assert(size);
-
-if (!bus || !bus->is_kernel)
-return -ENOTSUP;
+assert_return(bus || bus->is_kernel, -ENOTSUP);
 
 assert_se(pthread_mutex_lock(&bus->memfd_cache_mutex) >= 0);
 
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index 4c0e27f..041dfba 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -158,9 +158,7 @@ static void *message_extend_fields(sd_bus_message *m, 
size_t align, size_t sz, b
 size_t old_size, new_size, start;
 
 assert(m);
-
-if (m->poisoned)
-return NULL;
+assert_return(!m->poisoned, NULL);
 
 old_size = sizeof(struct bus_header) + m->header->fields_size;
 start = ALIGN_TO(old_size, align);
@@ -985,9 +983,7 @@ struct bus_body_part *message_append_part(sd_bus_message 
*m) {
 struct bus_body_part *part;
 
 assert(m);
-
-if (m->poisoned)
-return NULL;
+assert_return(!m->poisoned, NULL);
 
 if (m->n_body_parts <= 0) {
 part = &m->body;
@@ -1136,9 +1132,7 @@ static void *message_extend_body(sd_bus_message *m, 
size_t align, size_t sz, boo
 assert(m);
 assert(align > 0);
 assert(!m->sealed);
-
-if (m->poisoned)
-return NULL;
+assert_return(!m->poisoned, NULL);
 
 start_body = ALIGN_TO((size_t) m->header->body_size, align);
 end_body = start_body + sz;
diff --git a/src/libsystemd-bus/bus-signature.c 
b/src/libsystemd-bus/bus-signature.c
index 1e5bf48..3fb0794 100644
--- a/src/libsystemd-bus/bus-signature.c
+++ b/src/libsystemd-bus/bus-signature.c
@@ -33,9 +33,7 @@ static int signature_element_length_internal(
 
 int r;
 
-if (!s)
-return -EINVAL;
-
+assert_return(s, -EINVAL);
 assert(l);
 
 if (bus_type_is_basic(*s) || *s == SD_BUS_TYPE_VARIANT) {
@@ -117,8 +115,7 @@ bool signature_is_single(const char *s, bool 
allow_dict_entry) {
 int r;
 size_t t;
 
-if (!s)
-return false;
+assert_return(s, false);
 
 r = signature_element_length_internal(s, allow_dict_entry, 0, 0, &t);
 if (r < 0)
@@ -129,8 +126,7 @@ bool signature_is_single(const char *s, bool 
allow_dict_entry) {
 
 bool signature_is_pair(const char *s) {
 
-if (!s)
-return false;
+assert_return(s, false);
 
  

[systemd-devel] [RFC][PATCH] bus: Add destination field to sd_bus_message_new_signal() and sd_bus_emit_signal()

2013-12-05 Thread Lukasz Skalski
destination - the unique bus name for the destination for the signal
or NULL to emit to all listeners.

This path makes libsystemd-bus API more consistent and similar
to GDBUS API, for reference:

gboolean   g_dbus_connection_emit_signal  (GDBusConnection *connection,
   const gchar *destination_bus_name,
   const gchar *object_path,
   const gchar *interface_name,
   const gchar *signal_name,
   GVariant *parameters,
   GError **error);
---
 src/cgroups-agent/cgroups-agent.c  |  1 +
 src/core/dbus-job.c|  6 --
 src/core/dbus-manager.c| 12 ++--
 src/core/dbus-unit.c   |  6 --
 src/core/dbus.c|  4 ++--
 src/libsystemd-bus/bus-convenience.c   |  3 ++-
 src/libsystemd-bus/bus-kernel.c|  1 +
 src/libsystemd-bus/bus-message.c   |  8 
 src/libsystemd-bus/bus-objects.c   |  6 +++---
 src/libsystemd-bus/sd-bus.c|  1 +
 src/libsystemd-bus/test-bus-chat.c |  1 +
 src/libsystemd-bus/test-bus-kernel-bloom.c |  2 +-
 src/libsystemd-bus/test-bus-kernel.c   |  2 +-
 src/libsystemd-bus/test-bus-match.c|  2 +-
 src/login/logind-dbus.c|  1 +
 src/login/logind-seat-dbus.c   |  1 +
 src/login/logind-session-dbus.c|  2 ++
 src/login/logind-session-device.c  |  8 +++-
 src/login/logind-user-dbus.c   |  1 +
 src/machine/machine-dbus.c |  1 +
 src/systemd/sd-bus.h   |  4 ++--
 21 files changed, 47 insertions(+), 26 deletions(-)

diff --git a/src/cgroups-agent/cgroups-agent.c 
b/src/cgroups-agent/cgroups-agent.c
index d1d843b..8c7237f 100644
--- a/src/cgroups-agent/cgroups-agent.c
+++ b/src/cgroups-agent/cgroups-agent.c
@@ -53,6 +53,7 @@ int main(int argc, char *argv[]) {
 }
 
 r = sd_bus_emit_signal(bus,
+   NULL,
"/org/freedesktop/systemd1/agent",
"org.freedesktop.systemd1.Agent",
"Released",
diff --git a/src/core/dbus-job.c b/src/core/dbus-job.c
index 8c12b52..c689751 100644
--- a/src/core/dbus-job.c
+++ b/src/core/dbus-job.c
@@ -137,6 +137,7 @@ static int send_new_signal(sd_bus *bus, const char 
*destination, Job *j) {
 
 r = sd_bus_message_new_signal(
 bus,
+destination,
 "/org/freedesktop/systemd1",
 "org.freedesktop.systemd1.Manager",
 "JobNew",
@@ -148,7 +149,7 @@ static int send_new_signal(sd_bus *bus, const char 
*destination, Job *j) {
 if (r < 0)
 return r;
 
-return sd_bus_send_to(bus, m, destination, NULL);
+return sd_bus_send(bus, m, NULL);
 }
 
 static int send_changed_signal(sd_bus *bus, const char *destination, Job *j) {
@@ -196,6 +197,7 @@ static int send_removed_signal(sd_bus *bus, const char 
*destination, Job *j) {
 
 r = sd_bus_message_new_signal(
 bus,
+destination,
 "/org/freedesktop/systemd1",
 "org.freedesktop.systemd1.Manager",
 "JobRemoved",
@@ -207,7 +209,7 @@ static int send_removed_signal(sd_bus *bus, const char 
*destination, Job *j) {
 if (r < 0)
 return r;
 
-return sd_bus_send_to(bus, m, destination, NULL);
+return sd_bus_send(bus, m, NULL);
 }
 
 void bus_job_send_removed_signal(Job *j) {
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index a2707ee..718d383 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -1338,11 +1338,11 @@ static int send_unit_files_changed(sd_bus *bus, const 
char *destination, void *u
 
 assert(bus);
 
-r = sd_bus_message_new_signal(bus, "/org/freedesktop/systemd1", 
"org.freedesktop.systemd1.Manager", "UnitFilesChanged", &message);
+r = sd_bus_message_new_signal(bus, destination, 
"/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", 
"UnitFilesChanged", &message);
 if (r < 0)
 return r;
 
-return sd_bus_send_to(bus, message, destination, NULL);
+return sd_bus_send(bus, message, NULL);
 }
 
 static int reply_unit_file_changes_and_free(
@@ -1668,7 +1668,7 @@ static int send_finished(sd_bus *bus, const char 
*destination, void *userdata) {
 assert(bus);
 assert(times);
 
-r = sd_bus_message_new_signal(bus, "/org/freedesktop/systemd1", 
"org.freedesktop.systemd1.Manager", "StartupFinished", &message);
+r = sd_bus_message_new_signal(bus, dest

[systemd-devel] [PATCH] libsystemd-bus: Add return error msg for unicast signals when well-known name is not available

2013-12-04 Thread Lukasz Skalski
ENXIO, ESRCH and EADDRNOTAVAIL are also returned by ioctl(KDBUS_CMD_MSG_SEND)
when we have unicast signal messages (signals with a DESTINATION field).
---
 src/libsystemd-bus/bus-kernel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index b85a10d..1499830 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -414,7 +414,7 @@ int bus_kernel_write_message(sd_bus *bus, sd_bus_message 
*m) {
 /* ENXIO: unique name not known
  * ESRCH: well-known name not known */
 
-if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL)
+if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL || 
m->header->type == SD_BUS_MESSAGE_SIGNAL)
 sd_bus_error_setf(&error, 
SD_BUS_ERROR_SERVICE_UNKNOWN, "Destination %s not known", m->destination);
 else
 return 0;
@@ -423,7 +423,7 @@ int bus_kernel_write_message(sd_bus *bus, sd_bus_message 
*m) {
 
 /* EADDRNOTAVAIL: activation is possible, but turned 
off in request flags */
 
-if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL)
+if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL || 
m->header->type == SD_BUS_MESSAGE_SIGNAL)
 sd_bus_error_setf(&error, 
SD_BUS_ERROR_SERVICE_UNKNOWN, "Activation of %s not requested", m->destination);
 else
 return 0;
-- 
1.8.3.2

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


[systemd-devel] [PATCH 1/2] bus: Add bus_kernel_monitor function

2013-12-03 Thread Lukasz Skalski
---
 src/libsystemd-bus/bus-kernel.c | 16 
 src/libsystemd-bus/bus-kernel.h |  2 ++
 2 files changed, 18 insertions(+)

diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index ca36eb8..603aa97 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -1196,3 +1196,19 @@ int bus_kernel_create_namespace(const char *name, char 
**s) {
 
 return fd;
 }
+
+int bus_kernel_monitor(sd_bus *bus) {
+struct kdbus_cmd_monitor cmd_monitor;
+int r;
+
+assert(bus);
+
+cmd_monitor.id = 0;
+cmd_monitor.flags = KDBUS_MONITOR_ENABLE;
+
+r = ioctl(bus->input_fd, KDBUS_CMD_MONITOR, &cmd_monitor);
+if (r < 0)
+return -errno;
+
+return 1;
+}
diff --git a/src/libsystemd-bus/bus-kernel.h b/src/libsystemd-bus/bus-kernel.h
index a9dddc2..7ad49a5 100644
--- a/src/libsystemd-bus/bus-kernel.h
+++ b/src/libsystemd-bus/bus-kernel.h
@@ -73,3 +73,5 @@ int bus_kernel_parse_unique_name(const char *s, uint64_t *id);
 
 int kdbus_translate_request_name_flags(uint64_t sd_bus_flags, uint64_t 
*kdbus_flags);
 int kdbus_translate_attach_flags(uint64_t sd_bus_flags, uint64_t *kdbus_flags);
+
+int bus_kernel_monitor(sd_bus *bus);
-- 
1.8.3.2

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


[systemd-devel] [PATCH 2/2] tests: Add test-bus-kernel-monitor

2013-12-03 Thread Lukasz Skalski
test-bus-kernel-monitor is very simple program used to monitor all
messages/signals going through a kdbus message bus. It allows
monitor an arbitrary kernel bus given at --bus_path parameter and
also monitor system and session kernel bus (implemented but disabled
at this moment).
---
 Makefile.am  |  12 ++
 src/libsystemd-bus/test-bus-kernel-monitor.c | 179 +++
 2 files changed, 191 insertions(+)
 create mode 100644 src/libsystemd-bus/test-bus-kernel-monitor.c

diff --git a/Makefile.am b/Makefile.am
index 7c62414..a4752a2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2058,6 +2058,7 @@ tests += \
test-bus-kernel \
test-bus-kernel-bloom \
test-bus-kernel-benchmark \
+   test-bus-kernel-monitor \
test-bus-memfd \
test-bus-zero-copy \
test-bus-introspect \
@@ -2202,6 +2203,17 @@ test_bus_kernel_benchmark_LDADD = \
libsystemd-daemon-internal.la \
libsystemd-shared.la
 
+test_bus_kernel_monitor_SOURCES = \
+   src/libsystemd-bus/test-bus-kernel-monitor.c
+
+test_bus_kernel_monitor_LDADD = \
+   libsystemd-bus-internal.la \
+   libsystemd-id128-internal.la \
+   libsystemd-daemon-internal.la \
+   libsystemd-shared.la \
+   libsystemd-bus-dump.la \
+   libsystemd-capability.la
+
 test_bus_memfd_SOURCES = \
src/libsystemd-bus/test-bus-memfd.c
 
diff --git a/src/libsystemd-bus/test-bus-kernel-monitor.c 
b/src/libsystemd-bus/test-bus-kernel-monitor.c
new file mode 100644
index 000..27642d2
--- /dev/null
+++ b/src/libsystemd-bus/test-bus-kernel-monitor.c
@@ -0,0 +1,179 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2013 Lukasz Skalski
+
+  systemd 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.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include 
+#include 
+
+#include "log.h"
+#include "sd-bus.h"
+#include "bus-message.h"
+#include "bus-kernel.h"
+#include "bus-util.h"
+#include "bus-dump.h"
+
+#define DEFAULT_BUS_KERNEL_PATH "kernel:path=/dev/kdbus/deine-mutter/bus"
+
+sd_bus *bus = NULL;
+sd_bus_message *msg = NULL;
+const char *arg_address = DEFAULT_BUS_KERNEL_PATH;
+//static bool arg_user = false;
+
+
+static int help(void) {
+
+printf("%s [OPTIONS...]\n\n"
+   "Monitor the kernel bus.\n\n"
+   " --help   Show this help\n"
+   " --bus_path=PATH  Path to the kernel bus (default: 
%s)\n",
+   //" --system Connect to system bus\n"
+   //" --user   Connect to user bus\n"
+   program_invocation_short_name, DEFAULT_BUS_KERNEL_PATH);
+
+return 0;
+}
+
+static int parse_argv(int argc, char *argv[]) {
+
+enum {
+ARG_ADDRESS,
+ARG_SYSTEM,
+ARG_USER,
+};
+
+static const struct option options[] = {
+{ "help",   no_argument,   NULL, 'h'},
+{ "bus_path",   required_argument, NULL, ARG_ADDRESS},
+{ "system", no_argument,   NULL, ARG_SYSTEM },
+{ "user",   no_argument,   NULL, ARG_USER   },
+{},
+};
+
+int c;
+
+assert(argc >= 0);
+assert(argv);
+
+while ((c = getopt_long(argc, argv, "", options, NULL)) >= 0) {
+
+switch (c) {
+
+case 'h':
+return help();
+
+case ARG_ADDRESS:
+arg_address = optarg;
+break;
+
+/*
+case ARG_USER:
+arg_user = true;
+break;
+
+case ARG_SYSTEM:
+arg_user = false;
+break;
+*/
+
+case '?':
+return -EINVAL;
+
+default:
+assert_not_reached("Unhandled option");
+}
+}
+
+return 1;
+}
+
+static void do_exit(int sig_no) {
+

[systemd-devel] [PATCH] Display synthetic message serial number in a more readable format than (uint32_t) -1

2013-12-02 Thread Lukasz Skalski
Serial=4294967295 field in message dump generated by bus_message_dump()
function for synthetic messages isn't good readable.
---
 src/libsystemd-bus/bus-dump.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/libsystemd-bus/bus-dump.c b/src/libsystemd-bus/bus-dump.c
index 469f7ba..71de081 100644
--- a/src/libsystemd-bus/bus-dump.c
+++ b/src/libsystemd-bus/bus-dump.c
@@ -56,15 +56,21 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool 
with_header) {
 
 if (with_header) {
 fprintf(f,
-"%s%s%sType=%s%s%s  Endian=%c  Flags=%u  Version=%u  
Serial=%u ",
+"%s%s%sType=%s%s%s  Endian=%c  Flags=%u  Version=%u",
 m->header->type == SD_BUS_MESSAGE_METHOD_ERROR ? 
ansi_highlight_red() :
 m->header->type == SD_BUS_MESSAGE_METHOD_RETURN ? 
ansi_highlight_green() :
 m->header->type != SD_BUS_MESSAGE_SIGNAL ? 
ansi_highlight() : "", draw_special_char(DRAW_TRIANGULAR_BULLET), 
ansi_highlight_off(),
 ansi_highlight(), 
bus_message_type_to_string(m->header->type), ansi_highlight_off(),
 m->header->endian,
 m->header->flags,
-m->header->version,
-BUS_MESSAGE_SERIAL(m));
+m->header->version);
+
+/* Display synthetic message serial number in a more readable
+ * format than (uint32_t) -1 */
+if (BUS_MESSAGE_SERIAL(m) == 0xULL)
+fprintf(f, " Serial=-1");
+else
+fprintf(f, " Serial=%u", BUS_MESSAGE_SERIAL(m));
 
 if (m->reply_serial != 0)
 fprintf(f, "  ReplySerial=%u", m->reply_serial);
-- 
1.8.3.2

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


[systemd-devel] [PATCH] libsystemd-bus: clean up bus-control.c file

2013-11-29 Thread Lukasz Skalski
I added also assert_return(!bus->is_kernel, -ENOTSUP) to sd_bus_get_owner()
function until ioctl(KDBUS_CMD_NAME_QUERY) is not implemented yet.
---
 src/libsystemd-bus/bus-control.c | 52 ++--
 1 file changed, 18 insertions(+), 34 deletions(-)

diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
index b222175..90bdce2 100644
--- a/src/libsystemd-bus/bus-control.c
+++ b/src/libsystemd-bus/bus-control.c
@@ -38,12 +38,9 @@
 _public_ int sd_bus_get_unique_name(sd_bus *bus, const char **unique) {
 int r;
 
-if (!bus)
-return -EINVAL;
-if (!unique)
-return -EINVAL;
-if (bus_pid_changed(bus))
-return -ECHILD;
+assert_return(bus, -EINVAL);
+assert_return(unique, -EINVAL);
+assert_return(!bus_pid_changed(bus), -ECHILD);
 
 r = bus_ensure_running(bus);
 if (r < 0)
@@ -58,16 +55,11 @@ _public_ int sd_bus_request_name(sd_bus *bus, const char 
*name, int flags) {
 uint32_t ret;
 int r;
 
-if (!bus)
-return -EINVAL;
-if (!name)
-return -EINVAL;
-if (!bus->bus_client)
-return -EINVAL;
-if (!BUS_IS_OPEN(bus->state))
-return -ENOTCONN;
-if (bus_pid_changed(bus))
-return -ECHILD;
+assert_return(bus, -EINVAL);
+assert_return(name, -EINVAL);
+assert_return(bus->bus_client, -EINVAL);
+assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
+assert_return(!bus_pid_changed(bus), -ECHILD);
 
 if (bus->is_kernel) {
 struct kdbus_cmd_name *n;
@@ -126,16 +118,11 @@ _public_ int sd_bus_release_name(sd_bus *bus, const char 
*name) {
 uint32_t ret;
 int r;
 
-if (!bus)
-return -EINVAL;
-if (!name)
-return -EINVAL;
-if (!bus->bus_client)
-return -EINVAL;
-if (!BUS_IS_OPEN(bus->state))
-return -ENOTCONN;
-if (bus_pid_changed(bus))
-return -ECHILD;
+assert_return(bus, -EINVAL);
+assert_return(name, -EINVAL);
+assert_return(bus->bus_client, -EINVAL);
+assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
+assert_return(!bus_pid_changed(bus), -ECHILD);
 
 if (bus->is_kernel) {
 struct kdbus_cmd_name *n;
@@ -181,14 +168,10 @@ _public_ int sd_bus_list_names(sd_bus *bus, char ***l) {
 char **x = NULL;
 int r;
 
-if (!bus)
-return -EINVAL;
-if (!l)
-return -EINVAL;
-if (!BUS_IS_OPEN(bus->state))
-return -ENOTCONN;
-if (bus_pid_changed(bus))
-return -ECHILD;
+assert_return(bus, -EINVAL);
+assert_return(l, -EINVAL);
+assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
+assert_return(!bus_pid_changed(bus), -ECHILD);
 
 if (bus->is_kernel) {
 _cleanup_free_ struct kdbus_cmd_names *names = NULL;
@@ -296,6 +279,7 @@ _public_ int sd_bus_get_owner(
 assert_return(mask == 0 || creds, -EINVAL);
 assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
 assert_return(!bus_pid_changed(bus), -ECHILD);
+assert_return(!bus->is_kernel, -ENOTSUP);
 
 /* Only query the owner if the caller wants to know it or if
  * the caller just wants to check whether a name exists */
-- 
1.8.3.2

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


[systemd-devel] [PATCH] bus: Add KDBUS_MSG_SRC_NAMES to bus_kernel_make_message() function

2013-11-29 Thread Lukasz Skalski
---
 src/libsystemd-bus/bus-kernel.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index 84d84df..f2b130b 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -593,7 +593,8 @@ static int bus_kernel_make_message(sd_bus *bus, struct 
kdbus_msg *k, sd_bus_mess
 } else if (d->type == KDBUS_MSG_DST_NAME)
 destination = d->str;
 else if (d->type != KDBUS_MSG_FDS &&
-   d->type != KDBUS_MSG_SRC_SECLABEL)
+   d->type != KDBUS_MSG_SRC_SECLABEL &&
+ d->type != KDBUS_MSG_SRC_NAMES)
 log_debug("Got unknown field from kernel %llu", 
d->type);
 }
 
-- 
1.8.3.2

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


Re: [systemd-devel] [PATCH 3/7] libsystemd-bus: add kdbus support for sd_bus_list_names()

2013-11-27 Thread Lukasz Skalski

My 2 cents inline.

On 11/15/2013 07:32 PM, Daniel Mack wrote:

kdbus will tell us the minimum buffer size it needs in case the default
8kb buffer doesn't suffice.
---
  src/libsystemd-bus/bus-control.c | 100 ++-
  1 file changed, 68 insertions(+), 32 deletions(-)

diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
index 5c9e746..562513b 100644
--- a/src/libsystemd-bus/bus-control.c
+++ b/src/libsystemd-bus/bus-control.c
@@ -180,43 +180,79 @@ _public_ int sd_bus_list_names(sd_bus *bus, char ***l) {
  if (bus_pid_changed(bus))
  return -ECHILD;

-r = sd_bus_call_method(
-bus,
-"org.freedesktop.DBus",
-"/",
-"org.freedesktop.DBus",
-"ListNames",
-NULL,
-&reply1,
-NULL);
-if (r < 0)
-return r;
+if (bus->is_kernel) {
+_cleanup_free_ struct kdbus_cmd_names *names = NULL;
+struct kdbus_cmd_name *name;
+size_t size;
+
+/* assume 8k size first. If that doesn't suffice, kdbus will 
tell us
+ * how big the buffer needs to be.  */
+size = 8192;
+
+retry:
+names = realloc(names, size);
+if (!names)
+return log_oom();
+
+names->size = size;


+ names->flags=KDBUS_NAME_LIST_UNIQUE_NAMES;

"ListNames" should returns a list of all (both well-known and unique 
names) currently-owned names on the bus.



+
+r = ioctl(sd_bus_get_fd(bus), KDBUS_CMD_NAME_LIST, names);
+if (r < 0) {
+if (errno == ENOBUFS && size != names->size) {
+size = names->size;
+goto retry;
+}

-r = sd_bus_call_method(
-bus,
-"org.freedesktop.DBus",
-"/",
-"org.freedesktop.DBus",
-"ListActivatableNames",
-NULL,
-&reply2,
-NULL);
-if (r < 0)
-return r;
+return -errno;
+}

-r = bus_message_read_strv_extend(reply1, &x);
-if (r < 0) {
-strv_free(x);
-return r;
-}
+KDBUS_PART_FOREACH(name, names, names) {
+r = strv_extend(&x, name->name);
+if (r < 0)
+return log_oom();
+}

-r = bus_message_read_strv_extend(reply2, &x);
-if (r < 0) {
-strv_free(x);
-return r;
+*l = x;
+} else {
+r = sd_bus_call_method(
+bus,
+"org.freedesktop.DBus",
+"/",
+"org.freedesktop.DBus",
+"ListNames",
+NULL,
+&reply1,
+NULL);
+if (r < 0)
+return r;
+
+r = sd_bus_call_method(
+bus,
+"org.freedesktop.DBus",
+"/",
+"org.freedesktop.DBus",
+"ListActivatableNames",
+NULL,
+&reply2,
+NULL);
+if (r < 0)
+return r;
+
+r = bus_message_read_strv_extend(reply1, &x);
+if (r < 0) {
+strv_free(x);
+return r;
+}
+
+r = bus_message_read_strv_extend(reply2, &x);
+if (r < 0) {
+strv_free(x);
+return r;
+}
+
+*l = strv_uniq(x);
  }

-*l = strv_uniq(x);
  return 0;
  }




--
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@partner.samsung.com

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


[systemd-devel] [PATCH] updates for TODO and README

2013-11-27 Thread Lukasz Skalski
* library support for setns() system call was added to glibc
version 2.14 (setns() call is use in src/machine/machinectl.c
and src/libsystemd-bus-container.c)

* utf8 validation call are already exported (via sd-utf8.c file) -
commit - 369c583b3fb3d672ef469d53141e274ec9d2e8a7
---
 README |1 +
 TODO   |2 --
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/README b/README
index 2321849..65b6f5f 100644
--- a/README
+++ b/README
@@ -92,6 +92,7 @@ REQUIREMENTS:
 turn it off at kernel compile time using:
   CONFIG_AUDIT=n
 
+   glibc >= 2.14
 dbus >= 1.4.0
 libcap
 libblkid >= 2.20 (from util-linux) (optional)
diff --git a/TODO b/TODO
index 3383f35..225fe58 100644
--- a/TODO
+++ b/TODO
@@ -121,8 +121,6 @@ Features:
 
 * move config_parse_path_strv() out of conf-parser.c
 
-* libdsystemd-bus should expose utf8 validation calls
-
 * After coming back from hibernation reset hibernation swap partition using 
the /dev/snapshot ioctl APIs
 
 * If we try to find a unit via a dangling symlink, generate a clean
-- 
1.7.10.4

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


[systemd-devel] [PATCH v2] build: fix problems with undefined references in tests

2013-11-25 Thread Lukasz Skalski
Now code form src/shared don't use code of shared libs directly.
It solves cyclic dependencies in the same way as sd_utf_is_valid()
from src/libsystemd-bus/sd-utf8.c and src/shared/utf8.c.
---
 src/libsystemd-bus/sd-bus.c   |   64 +
 src/libsystemd-bus/test-bus-marshal.c |   25 
 src/shared/unit-name.c|5 +--
 src/shared/util.c |   72 +
 src/shared/util.h |3 ++
 src/test/test-util.c  |   24 +++
 6 files changed, 103 insertions(+), 90 deletions(-)

diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 1207d5a..3042802 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -2741,73 +2741,13 @@ _public_ int sd_bus_get_tid(sd_bus *b, pid_t *tid) {
 }
 
 _public_ char *sd_bus_label_escape(const char *s) {
-char *r, *t;
-const char *f;
-
 assert_return(s, NULL);
 
-/* Escapes all chars that D-Bus' object path cannot deal
- * with. Can be reversed with bus_path_unescape(). We special
- * case the empty string. */
-
-if (*s == 0)
-return strdup("_");
-
-r = new(char, strlen(s)*3 + 1);
-if (!r)
-return NULL;
-
-for (f = s, t = r; *f; f++) {
-
-/* Escape everything that is not a-zA-Z0-9. We also
- * escape 0-9 if it's the first character */
-
-if (!(*f >= 'A' && *f <= 'Z') &&
-!(*f >= 'a' && *f <= 'z') &&
-!(f > s && *f >= '0' && *f <= '9')) {
-*(t++) = '_';
-*(t++) = hexchar(*f >> 4);
-*(t++) = hexchar(*f);
-} else
-*(t++) = *f;
-}
-
-*t = 0;
-
-return r;
+return bus_path_escape(s);
 }
 
 _public_ char *sd_bus_label_unescape(const char *f) {
-char *r, *t;
-
 assert_return(f, NULL);
 
-/* Special case for the empty string */
-if (streq(f, "_"))
-return strdup("");
-
-r = new(char, strlen(f) + 1);
-if (!r)
-return NULL;
-
-for (t = r; *f; f++) {
-
-if (*f == '_') {
-int a, b;
-
-if ((a = unhexchar(f[1])) < 0 ||
-(b = unhexchar(f[2])) < 0) {
-/* Invalid escape code, let's take it literal 
then */
-*(t++) = '_';
-} else {
-*(t++) = (char) ((a << 4) | b);
-f += 2;
-}
-} else
-*(t++) = *f;
-}
-
-*t = 0;
-
-return r;
+return bus_path_unescape(f);
 }
diff --git a/src/libsystemd-bus/test-bus-marshal.c 
b/src/libsystemd-bus/test-bus-marshal.c
index da072c7..b6e2c7b 100644
--- a/src/libsystemd-bus/test-bus-marshal.c
+++ b/src/libsystemd-bus/test-bus-marshal.c
@@ -39,29 +39,6 @@
 #include "bus-util.h"
 #include "bus-dump.h"
 
-static void test_bus_label_escape_one(const char *a, const char *b) {
-_cleanup_free_ char *t = NULL, *x = NULL, *y = NULL;
-
-assert_se(t = sd_bus_label_escape(a));
-assert_se(streq(t, b));
-
-assert_se(x = sd_bus_label_unescape(t));
-assert_se(streq(a, x));
-
-assert_se(y = sd_bus_label_unescape(b));
-assert_se(streq(a, y));
-}
-
-static void test_bus_label_escape(void) {
-test_bus_label_escape_one("foo123bar", "foo123bar");
-test_bus_label_escape_one("foo.bar", "foo_2ebar");
-test_bus_label_escape_one("foo_2ebar", "foo_5f2ebar");
-test_bus_label_escape_one("", "_");
-test_bus_label_escape_one("_", "_5f");
-test_bus_label_escape_one("1", "_31");
-test_bus_label_escape_one(":1", "_3a1");
-}
-
 int main(int argc, char *argv[]) {
 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *copy = NULL;
 int r, boolean;
@@ -317,7 +294,5 @@ int main(int argc, char *argv[]) {
 assert_se(streq(c, "ccc"));
 assert_se(streq(d, "3"));
 
-test_bus_label_escape();
-
 return 0;
 }
diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c
index 2335463..bc8094d 100644
--- a/src/shared/unit-name.c
+++ b/src/shared/unit-name.c
@@ -23,7 +23,6 @@
 #include 
 #include 
 
-#include "sd-bus.h"
 #include "path-util.h"
 #include "util.h"
 #include "unit-name.h"
@@ -460,7 +459,7 @@ char *unit_dbus_path_from_name(const char *name) {
 
 assert(name);
 
-e = sd_bus_label_escape(name);
+e = bus_path_escape(name);
 if (!e)
 return NULL;
 
@@ -475,7 +474,7 @@ int unit_name_from_dbus_path(const char *path, char **name) 
{
 if (!e)
 return -E

Re: [systemd-devel] [PATCH] build: fix problems with undefined references in tests

2013-11-25 Thread Lukasz Skalski

On 11/25/2013 02:03 PM, Kay Sievers wrote:

On Mon, Nov 25, 2013 at 1:56 PM, Lukasz Skalski
 wrote:

Please find patch in attachement for review - it fix problem
with undefined references in some test-libsystemd-*-sym.c tests.


It looks a bit weird to add library requirements, theses libs should
not need the other libraries. What exactly fails on your side?

Kay



Hi,

Yes I know, but otherwise:

  CCLD   test-libsystemd-daemon-sym
  CC test-libsystemd-id128-sym.o
  CCLD   test-libsystemd-id128-sym
./.libs/libsystemd-id128.so: undefined reference to `sd_bus_label_escape'
./.libs/libsystemd-id128.so: undefined reference to `sd_bus_label_unescape'
collect2: ld returned 1 exit status
make[2]: *** [test-libsystemd-id128-sym] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2


--
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@partner.samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] build: fix problems with undefined references in tests

2013-11-25 Thread Lukasz Skalski
Please find patch in attachement for review - it fix problem
with undefined references in some test-libsystemd-*-sym.c tests.
---
 Makefile.am |5 +
 1 file changed, 5 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index 728b860..9e03f0a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2257,6 +2257,7 @@ libudev_la_LDFLAGS = \
 
 libudev_la_LIBADD = \
libsystemd-daemon-internal.la \
+   libsystemd-bus-internal.la \
libsystemd-id128-internal.la \
libsystemd-shared.la
 
@@ -2826,6 +2827,7 @@ libsystemd_id128_la_LDFLAGS = \

-Wl,--version-script=$(top_srcdir)/src/libsystemd-id128/libsystemd-id128.sym
 
 libsystemd_id128_la_LIBADD = \
+   libsystemd-bus-internal.la \
libsystemd-daemon-internal.la \
libsystemd-shared.la
 
@@ -3027,6 +3029,7 @@ libsystemd_journal_la_LDFLAGS = \
 
 libsystemd_journal_la_LIBADD = \
libsystemd-label.la \
+   libsystemd-bus-internal.la \
libsystemd-daemon-internal.la \
libsystemd-id128-internal.la \
libsystemd-shared.la
@@ -4038,6 +4041,8 @@ libsystemd_login_la_LDFLAGS = \
-Wl,--version-script=$(top_srcdir)/src/login/libsystemd-login.sym
 
 libsystemd_login_la_LIBADD = \
+   libsystemd-bus-internal.la \
+   libsystemd-id128-internal.la \
libsystemd-daemon-internal.la \
libsystemd-shared.la
 
-- 
1.7.9.5

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


Re: [systemd-devel] [PATCH] include: fix problem with __LINE__ macro expansion

2013-11-22 Thread Lukasz Skalski

On 11/22/2013 02:46 PM, David Herrmann wrote:

Hi



Hi,


On Fri, Nov 22, 2013 at 2:09 PM, Lennart Poettering
 wrote:

On Thu, 21.11.13 17:26, Lukasz Skalski (l.skal...@partner.samsung.com) wrote:


Hi all,

Macro __LINE__ in #define assert_cc() (src/shared/macro.h) is not
properly expanded.

Please find patch in attachment for review.


Thanks! Seems David Herrmann has now fixed this thing slightly
differently.


I just noticed the compile-failure and fixed it up myself. But this
patch definitely looks nicer. I now changed the helper-name to
XCONCATENATE similar to XSTRINGIFY and added a UNIQUE macro to
generate a unique name. Might be useful in other macros, too.

Thanks
David



Thanks. Solution with XCONCATENATE seems to be more generic than 
assert___cc(expr,line) macro and can be re-used.


BR,
--
Lukasz Skalski
Samsung R&D Institute Poland
Samsung Electronics
l.skal...@partner.samsung.com
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel