Re: [systemd-devel] [PATCH] core: Filter by state behind the D-Bus API, not in the systemctl client.

2014-05-18 Thread Lennart Poettering
On Mon, 28.04.14 12:08, da...@davidstrauss.net (da...@davidstrauss.net) wrote:

 From: David Strauss da...@davidstrauss.net

Thanks! Applied!

(I do wonder though whether we should try harder to keep the client
tools compatible with the server side, so that systemctl -M and
systemctl -H continue to work, when server and client are not updated
simultaneously. I have merged the patch anyway, but would be very happy
to merge a patch that teaches the client to fallback to the old
ListUnits call if ListUnitsFiltered doesnt work...)

Lennart

 
 ---
  src/core/dbus-manager.c| 24 +++-
  src/core/org.freedesktop.systemd1.conf |  4 
  src/systemctl/systemctl.c  | 24 +---
  3 files changed, 40 insertions(+), 12 deletions(-)
 
 diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
 index 135d314..febf475 100644
 --- a/src/core/dbus-manager.c
 +++ b/src/core/dbus-manager.c
 @@ -728,7 +728,7 @@ static int method_reset_failed(sd_bus *bus, 
 sd_bus_message *message, void *userd
  return sd_bus_reply_method_return(message, NULL);
  }
  
 -static int method_list_units(sd_bus *bus, sd_bus_message *message, void 
 *userdata, sd_bus_error *error) {
 +static int list_units_filtered(sd_bus *bus, sd_bus_message *message, void 
 *userdata, sd_bus_error *error, char **states) {
  _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
  Manager *m = userdata;
  const char *k;
 @@ -761,6 +761,12 @@ static int method_list_units(sd_bus *bus, sd_bus_message 
 *message, void *userdat
  
  following = unit_following(u);
  
 +if (!strv_isempty(states) 
 +!strv_contains(states, 
 unit_load_state_to_string(u-load_state)) 
 +!strv_contains(states, 
 unit_active_state_to_string(unit_active_state(u))) 
 +!strv_contains(states, unit_sub_state_to_string(u)))
 +continue;
 +
  unit_path = unit_dbus_path(u);
  if (!unit_path)
  return -ENOMEM;
 @@ -794,6 +800,21 @@ static int method_list_units(sd_bus *bus, sd_bus_message 
 *message, void *userdat
  return sd_bus_send(bus, reply, NULL);
  }
  
 +static int method_list_units(sd_bus *bus, sd_bus_message *message, void 
 *userdata, sd_bus_error *error) {
 +return list_units_filtered(bus, message, userdata, error, NULL);
 +}
 +
 +static int method_list_units_filtered(sd_bus *bus, sd_bus_message *message, 
 void *userdata, sd_bus_error *error) {
 +_cleanup_strv_free_ char **states = NULL;
 +int r;
 +
 +r = sd_bus_message_read_strv(message, states);
 +if (r  0)
 +return r;
 +
 +return list_units_filtered(bus, message, userdata, error, states);
 +}
 +
  static int method_list_jobs(sd_bus *bus, sd_bus_message *message, void 
 *userdata, sd_bus_error *error) {
  _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
  Manager *m = userdata;
 @@ -1670,6 +1691,7 @@ const sd_bus_vtable bus_manager_vtable[] = {
  SD_BUS_METHOD(ClearJobs, NULL, NULL, method_clear_jobs, 0),
  SD_BUS_METHOD(ResetFailed, NULL, NULL, method_reset_failed, 0),
  SD_BUS_METHOD(ListUnits, NULL, a(ssouso), method_list_units, 
 SD_BUS_VTABLE_UNPRIVILEGED),
 +SD_BUS_METHOD(ListUnitsFiltered, as, a(ssouso), 
 method_list_units_filtered, SD_BUS_VTABLE_UNPRIVILEGED),
  SD_BUS_METHOD(ListJobs, NULL, a(usssoo), method_list_jobs, 
 SD_BUS_VTABLE_UNPRIVILEGED),
  SD_BUS_METHOD(Subscribe, NULL, NULL, method_subscribe, 
 SD_BUS_VTABLE_UNPRIVILEGED),
  SD_BUS_METHOD(Unsubscribe, NULL, NULL, method_unsubscribe, 
 SD_BUS_VTABLE_UNPRIVILEGED),
 diff --git a/src/core/org.freedesktop.systemd1.conf 
 b/src/core/org.freedesktop.systemd1.conf
 index a375dce..9dfca81 100644
 --- a/src/core/org.freedesktop.systemd1.conf
 +++ b/src/core/org.freedesktop.systemd1.conf
 @@ -64,6 +64,10 @@
  
  allow send_destination=org.freedesktop.systemd1
 send_interface=org.freedesktop.systemd1.Manager
 +   send_member=ListUnitsFiltered/
 +
 +allow send_destination=org.freedesktop.systemd1
 +   send_interface=org.freedesktop.systemd1.Manager
 send_member=ListUnitFiles/
  
  allow send_destination=org.freedesktop.systemd1
 diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
 index 7bc8ece..4b97cc0 100644
 --- a/src/systemctl/systemctl.c
 +++ b/src/systemctl/systemctl.c
 @@ -319,12 +319,6 @@ static int compare_unit_info(const void *a, const void 
 *b) {
  static bool output_show_unit(const UnitInfo *u, char **patterns) {
  const char *dot;
  
 -if (!strv_isempty(arg_states))
 -return
 -strv_contains(arg_states, u-load_state) ||
 -

Re: [systemd-devel] [PATCH] core: Filter by state behind the D-Bus API, not in the systemctl client.

2014-05-12 Thread David Timothy Strauss
Bumping this for review.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] core: Filter by state behind the D-Bus API, not in the systemctl client.

2014-04-28 Thread david
From: David Strauss da...@davidstrauss.net

---
 src/core/dbus-manager.c| 24 +++-
 src/core/org.freedesktop.systemd1.conf |  4 
 src/systemctl/systemctl.c  | 24 +---
 3 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index 135d314..febf475 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -728,7 +728,7 @@ static int method_reset_failed(sd_bus *bus, sd_bus_message 
*message, void *userd
 return sd_bus_reply_method_return(message, NULL);
 }
 
-static int method_list_units(sd_bus *bus, sd_bus_message *message, void 
*userdata, sd_bus_error *error) {
+static int list_units_filtered(sd_bus *bus, sd_bus_message *message, void 
*userdata, sd_bus_error *error, char **states) {
 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
 Manager *m = userdata;
 const char *k;
@@ -761,6 +761,12 @@ static int method_list_units(sd_bus *bus, sd_bus_message 
*message, void *userdat
 
 following = unit_following(u);
 
+if (!strv_isempty(states) 
+!strv_contains(states, 
unit_load_state_to_string(u-load_state)) 
+!strv_contains(states, 
unit_active_state_to_string(unit_active_state(u))) 
+!strv_contains(states, unit_sub_state_to_string(u)))
+continue;
+
 unit_path = unit_dbus_path(u);
 if (!unit_path)
 return -ENOMEM;
@@ -794,6 +800,21 @@ static int method_list_units(sd_bus *bus, sd_bus_message 
*message, void *userdat
 return sd_bus_send(bus, reply, NULL);
 }
 
+static int method_list_units(sd_bus *bus, sd_bus_message *message, void 
*userdata, sd_bus_error *error) {
+return list_units_filtered(bus, message, userdata, error, NULL);
+}
+
+static int method_list_units_filtered(sd_bus *bus, sd_bus_message *message, 
void *userdata, sd_bus_error *error) {
+_cleanup_strv_free_ char **states = NULL;
+int r;
+
+r = sd_bus_message_read_strv(message, states);
+if (r  0)
+return r;
+
+return list_units_filtered(bus, message, userdata, error, states);
+}
+
 static int method_list_jobs(sd_bus *bus, sd_bus_message *message, void 
*userdata, sd_bus_error *error) {
 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
 Manager *m = userdata;
@@ -1670,6 +1691,7 @@ const sd_bus_vtable bus_manager_vtable[] = {
 SD_BUS_METHOD(ClearJobs, NULL, NULL, method_clear_jobs, 0),
 SD_BUS_METHOD(ResetFailed, NULL, NULL, method_reset_failed, 0),
 SD_BUS_METHOD(ListUnits, NULL, a(ssouso), method_list_units, 
SD_BUS_VTABLE_UNPRIVILEGED),
+SD_BUS_METHOD(ListUnitsFiltered, as, a(ssouso), 
method_list_units_filtered, SD_BUS_VTABLE_UNPRIVILEGED),
 SD_BUS_METHOD(ListJobs, NULL, a(usssoo), method_list_jobs, 
SD_BUS_VTABLE_UNPRIVILEGED),
 SD_BUS_METHOD(Subscribe, NULL, NULL, method_subscribe, 
SD_BUS_VTABLE_UNPRIVILEGED),
 SD_BUS_METHOD(Unsubscribe, NULL, NULL, method_unsubscribe, 
SD_BUS_VTABLE_UNPRIVILEGED),
diff --git a/src/core/org.freedesktop.systemd1.conf 
b/src/core/org.freedesktop.systemd1.conf
index a375dce..9dfca81 100644
--- a/src/core/org.freedesktop.systemd1.conf
+++ b/src/core/org.freedesktop.systemd1.conf
@@ -64,6 +64,10 @@
 
 allow send_destination=org.freedesktop.systemd1
send_interface=org.freedesktop.systemd1.Manager
+   send_member=ListUnitsFiltered/
+
+allow send_destination=org.freedesktop.systemd1
+   send_interface=org.freedesktop.systemd1.Manager
send_member=ListUnitFiles/
 
 allow send_destination=org.freedesktop.systemd1
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 7bc8ece..4b97cc0 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -319,12 +319,6 @@ static int compare_unit_info(const void *a, const void *b) 
{
 static bool output_show_unit(const UnitInfo *u, char **patterns) {
 const char *dot;
 
-if (!strv_isempty(arg_states))
-return
-strv_contains(arg_states, u-load_state) ||
-strv_contains(arg_states, u-sub_state) ||
-strv_contains(arg_states, u-active_state);
-
 if (!strv_isempty(patterns)) {
 char **pattern;
 
@@ -513,6 +507,7 @@ static int get_unit_list(
 int c,
 sd_bus_message **_reply) {
 
+_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
 _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
 size_t size = c;
@@ -523,15 +518,22 @@ static int get_unit_list(
 

Re: [systemd-devel] [PATCH] core: Filter by state behind the D-Bus API, not in the systemctl client.

2014-04-28 Thread David Timothy Strauss
This is a completed version of the patch Lennart and I worked on at
the hackfest. The version we worked on had separate string arguments
for each type of state. This patch harmonizes it more with the way
systemctl --state already works, which is an array of possible states
to match across all state types. ListUnits is retained for API
compatibility, but systemctl is updated to always use
ListUnitsFiltered, even with an empty array.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel