File pacemaker-libcrmservice-list-systemd-unit-files.patch of Package pacemaker.14737
commit 59a3dd2f5a9ae218d1064e02188d4d83a6771b01
Author: Ken Gaillot <kgaillot@redhat.com>
Date: Fri Oct 13 11:04:50 2017 -0500
Fix: libcrmservice: list systemd unit files, not only active units
The typical use case of listing agents is to see what can be used,
and if a systemd unit isn't active, it won't be listed by ListUnits.
Use ListUnitFiles instead, and filter them by the types of units
we can manage (service, mount, and socket).
Closes CLBZ#5299
Index: pacemaker/lib/services/systemd.c
===================================================================
--- pacemaker.orig/lib/services/systemd.c
+++ pacemaker/lib/services/systemd.c
@@ -318,14 +318,14 @@ systemd_unit_by_name(const gchar * arg_n
GList *
systemd_unit_listall(void)
{
- int lpc = 0;
+ int nfiles = 0;
GList *units = NULL;
DBusMessageIter args;
DBusMessageIter unit;
DBusMessageIter elem;
DBusMessage *msg = NULL;
DBusMessage *reply = NULL;
- const char *method = "ListUnits";
+ const char *method = "ListUnitFiles";
DBusError error;
if (systemd_init() == FALSE) {
@@ -333,8 +333,8 @@ systemd_unit_listall(void)
}
/*
- " <method name=\"ListUnits\">\n" \
- " <arg name=\"units\" type=\"a(ssssssouso)\" direction=\"out\"/>\n" \
+ " <method name=\"ListUnitfiles\">\n" \
+ " <arg name=\"files\" type=\"a(ss)\" direction=\"out\"/>\n" \
" </method>\n" \
*/
@@ -379,21 +379,36 @@ systemd_unit_listall(void)
}
dbus_message_iter_get_basic(&elem, &value);
- crm_trace("DBus ListUnits listed: %s", value.str);
+ crm_trace("DBus ListUnitFiles listed: %s", value.str);
if(value.str) {
const char *match = systemd_unit_extension(value.str);
if (match) {
- char *unit_name;
+ char *unit_name = NULL;
+ char *basename = NULL;
- if (!strcmp(match, ".service")) {
- /* service is the "default" unit type, so strip it */
- unit_name = strndup(value.str, match - value.str);
+ // ListUnitFiles returns full path names
+ basename = strrchr(value.str, '/');
+ if (basename) {
+ basename = basename + 1;
} else {
- unit_name = strdup(value.str);
+ basename = value.str;
+ }
+
+ if (!strcmp(match, ".service")) {
+ // Service is the "default" unit type, so strip it
+ unit_name = strndup(basename, match - basename);
+
+ } else if (!strcmp(match, ".mount")
+ || !strcmp(match, ".socket")) {
+ // Only list things we can start and stop
+ unit_name = strdup(basename);
+ }
+ if (unit_name) {
+ nfiles++;
+ // @TODO sort alphabetically
+ units = g_list_prepend(units, unit_name);
}
- lpc++;
- units = g_list_append(units, unit_name);
}
}
dbus_message_iter_next (&unit);
@@ -401,7 +416,7 @@ systemd_unit_listall(void)
dbus_message_unref(reply);
- crm_trace("Found %d systemd services", lpc);
+ crm_trace("Found %d manageable systemd unit files", nfiles);
return units;
}