|
|
7100e8 |
commit 6b3f1e2e65db9d6fe229ccda22567a80d14efc3c
|
|
|
7100e8 |
Author: Andrew Beekhof <andrew@beekhof.net>
|
|
|
7100e8 |
Date: Thu Jan 30 08:23:35 2014 +1100
|
|
|
7100e8 |
|
|
|
7100e8 |
Fix: Bug rhbz#1057697 - Use native DBus library for systemd support to avoid problematic use of threads
|
|
|
7100e8 |
|
|
|
7100e8 |
(cherry picked from commit 24404bfa83f32357e8fa2d7e80b1dd7c6a893244)
|
|
|
7100e8 |
|
|
|
7100e8 |
diff --git a/configure.ac b/configure.ac
|
|
|
7100e8 |
index b94c26e..628f46f 100644
|
|
|
7100e8 |
--- a/configure.ac
|
|
|
7100e8 |
+++ b/configure.ac
|
|
|
7100e8 |
@@ -1157,20 +1157,22 @@ AC_DEFINE_UNQUOTED(BUILD_VERSION, "$BUILD_VERSION", Build version)
|
|
|
7100e8 |
AC_SUBST(BUILD_VERSION)
|
|
|
7100e8 |
|
|
|
7100e8 |
|
|
|
7100e8 |
-HAVE_gio=1
|
|
|
7100e8 |
+HAVE_dbus=1
|
|
|
7100e8 |
HAVE_upstart=0
|
|
|
7100e8 |
HAVE_systemd=0
|
|
|
7100e8 |
-PKG_CHECK_MODULES(GIO, gio-2.0, ,HAVE_gio=0)
|
|
|
7100e8 |
+PKG_CHECK_MODULES(DBUS, dbus-1, ,HAVE_dbus=0)
|
|
|
7100e8 |
|
|
|
7100e8 |
-AC_CHECK_TYPE([GDBusProxy],,,[[#include <gio/gio.h>]])
|
|
|
7100e8 |
-
|
|
|
7100e8 |
-if test x$ac_cv_type_GDBusProxy != xyes; then
|
|
|
7100e8 |
- HAVE_gio=0
|
|
|
7100e8 |
- AC_MSG_WARN(Unable to support systemd/upstart. You need to use glib >= 2.26)
|
|
|
7100e8 |
+if test $HAVE_dbus = 1; then
|
|
|
7100e8 |
+ CFLAGS="$CFLAGS `$PKGCONFIG --cflags dbus-1`"
|
|
|
7100e8 |
fi
|
|
|
7100e8 |
|
|
|
7100e8 |
-if test $HAVE_gio = 1 -a "x${enable_upstart}" != xno; then
|
|
|
7100e8 |
- HAVE_upstart=1
|
|
|
7100e8 |
+DBUS_LIBS="$CFLAGS `$PKGCONFIG --libs dbus-1`"
|
|
|
7100e8 |
+AC_SUBST(DBUS_LIBS)
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+AC_CHECK_TYPES([DBusBasicValue],,,[[#include <dbus/dbus.h>]])
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+if test $HAVE_dbus = 1 -a "x${enable_upstart}" != xno; then
|
|
|
7100e8 |
+ HAVE_upstart=0
|
|
|
7100e8 |
PCMK_FEATURES="$PCMK_FEATURES upstart"
|
|
|
7100e8 |
fi
|
|
|
7100e8 |
|
|
|
7100e8 |
@@ -1186,7 +1188,7 @@ else
|
|
|
7100e8 |
enable_systemd=no
|
|
|
7100e8 |
fi
|
|
|
7100e8 |
|
|
|
7100e8 |
-if test $HAVE_gio = 1 -a "x${enable_systemd}" != xno; then
|
|
|
7100e8 |
+if test $HAVE_dbus = 1 -a "x${enable_systemd}" != xno; then
|
|
|
7100e8 |
if test -n "$systemdunitdir" -a "x$systemdunitdir" != xno; then
|
|
|
7100e8 |
HAVE_systemd=1
|
|
|
7100e8 |
PCMK_FEATURES="$PCMK_FEATURES systemd"
|
|
|
7100e8 |
diff --git a/include/portability.h b/include/portability.h
|
|
|
7100e8 |
index b0f9f1c..29d1177 100644
|
|
|
7100e8 |
--- a/include/portability.h
|
|
|
7100e8 |
+++ b/include/portability.h
|
|
|
7100e8 |
@@ -177,6 +177,48 @@ g_list_free_full(GList * list, GDestroyNotify free_func)
|
|
|
7100e8 |
}
|
|
|
7100e8 |
# endif
|
|
|
7100e8 |
|
|
|
7100e8 |
+# ifndef HAVE_DBUSBASICVALUE
|
|
|
7100e8 |
+# include <dbus/dbus.h>
|
|
|
7100e8 |
+/**
|
|
|
7100e8 |
+ * An 8-byte struct you could use to access int64 without having
|
|
|
7100e8 |
+ * int64 support
|
|
|
7100e8 |
+ */
|
|
|
7100e8 |
+typedef struct
|
|
|
7100e8 |
+{
|
|
|
7100e8 |
+ dbus_uint32_t first32; /**< first 32 bits in the 8 bytes (beware endian issues) */
|
|
|
7100e8 |
+ dbus_uint32_t second32; /**< second 32 bits in the 8 bytes (beware endian issues) */
|
|
|
7100e8 |
+} DBus8ByteStruct;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+/**
|
|
|
7100e8 |
+ * A simple value union that lets you access bytes as if they
|
|
|
7100e8 |
+ * were various types; useful when dealing with basic types via
|
|
|
7100e8 |
+ * void pointers and varargs.
|
|
|
7100e8 |
+ *
|
|
|
7100e8 |
+ * This union also contains a pointer member (which can be used
|
|
|
7100e8 |
+ * to retrieve a string from dbus_message_iter_get_basic(), for
|
|
|
7100e8 |
+ * instance), so on future platforms it could conceivably be larger
|
|
|
7100e8 |
+ * than 8 bytes.
|
|
|
7100e8 |
+ */
|
|
|
7100e8 |
+typedef union
|
|
|
7100e8 |
+{
|
|
|
7100e8 |
+ unsigned char bytes[8]; /**< as 8 individual bytes */
|
|
|
7100e8 |
+ dbus_int16_t i16; /**< as int16 */
|
|
|
7100e8 |
+ dbus_uint16_t u16; /**< as int16 */
|
|
|
7100e8 |
+ dbus_int32_t i32; /**< as int32 */
|
|
|
7100e8 |
+ dbus_uint32_t u32; /**< as int32 */
|
|
|
7100e8 |
+ dbus_bool_t bool_val; /**< as boolean */
|
|
|
7100e8 |
+# ifdef DBUS_HAVE_INT64
|
|
|
7100e8 |
+ dbus_int64_t i64; /**< as int64 */
|
|
|
7100e8 |
+ dbus_uint64_t u64; /**< as int64 */
|
|
|
7100e8 |
+# endif
|
|
|
7100e8 |
+ DBus8ByteStruct eight; /**< as 8-byte struct */
|
|
|
7100e8 |
+ double dbl; /**< as double */
|
|
|
7100e8 |
+ unsigned char byt; /**< as byte */
|
|
|
7100e8 |
+ char *str; /**< as char* (string, object path or signature) */
|
|
|
7100e8 |
+ int fd; /**< as Unix file descriptor */
|
|
|
7100e8 |
+} DBusBasicValue;
|
|
|
7100e8 |
+# endif
|
|
|
7100e8 |
+
|
|
|
7100e8 |
/* Replacement error codes for non-linux */
|
|
|
7100e8 |
# ifndef ENOTUNIQ
|
|
|
7100e8 |
# define ENOTUNIQ 190
|
|
|
7100e8 |
diff --git a/lib/services/Makefile.am b/lib/services/Makefile.am
|
|
|
7100e8 |
index 67d7237..6ed4d01 100644
|
|
|
7100e8 |
--- a/lib/services/Makefile.am
|
|
|
7100e8 |
+++ b/lib/services/Makefile.am
|
|
|
7100e8 |
@@ -23,10 +23,10 @@ INCLUDES = -I$(top_builddir)/include
|
|
|
7100e8 |
lib_LTLIBRARIES = libcrmservice.la
|
|
|
7100e8 |
noinst_HEADERS = upstart.h systemd.h services_private.h
|
|
|
7100e8 |
|
|
|
7100e8 |
-libcrmservice_la_SOURCES = services.c services_linux.c
|
|
|
7100e8 |
+libcrmservice_la_SOURCES = services.c services_linux.c dbus.c
|
|
|
7100e8 |
libcrmservice_la_LDFLAGS = -version-info 1:0:0
|
|
|
7100e8 |
libcrmservice_la_CFLAGS = $(GIO_CFLAGS) -DOCF_ROOT_DIR=\"@OCF_ROOT_DIR@\"
|
|
|
7100e8 |
-libcrmservice_la_LIBADD = $(GIO_LIBS) $(top_builddir)/lib/common/libcrmcommon.la
|
|
|
7100e8 |
+libcrmservice_la_LIBADD = $(GIO_LIBS) $(top_builddir)/lib/common/libcrmcommon.la $(DBUS_LIBS)
|
|
|
7100e8 |
|
|
|
7100e8 |
if BUILD_UPSTART
|
|
|
7100e8 |
libcrmservice_la_SOURCES += upstart.c
|
|
|
7100e8 |
diff --git a/lib/services/dbus.c b/lib/services/dbus.c
|
|
|
7100e8 |
new file mode 100644
|
|
|
7100e8 |
index 0000000..69ea6ac
|
|
|
7100e8 |
--- /dev/null
|
|
|
7100e8 |
+++ b/lib/services/dbus.c
|
|
|
7100e8 |
@@ -0,0 +1,261 @@
|
|
|
7100e8 |
+#include <crm_internal.h>
|
|
|
7100e8 |
+#include <crm/crm.h>
|
|
|
7100e8 |
+#include <crm/services.h>
|
|
|
7100e8 |
+#include <dbus/dbus.h>
|
|
|
7100e8 |
+#include <pcmk-dbus.h>
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+static bool pcmk_dbus_error_check(DBusError *err, const char *prefix, const char *function, int line)
|
|
|
7100e8 |
+{
|
|
|
7100e8 |
+ if (err && dbus_error_is_set(err)) {
|
|
|
7100e8 |
+ do_crm_log_alias(LOG_ERR, __FILE__, function, line, "%s: DBus error '%s'", prefix, err->message);
|
|
|
7100e8 |
+ dbus_error_free(err);
|
|
|
7100e8 |
+ return TRUE;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ return FALSE;
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+DBusConnection *pcmk_dbus_connect(void)
|
|
|
7100e8 |
+{
|
|
|
7100e8 |
+ DBusError err;
|
|
|
7100e8 |
+ DBusConnection *connection;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ dbus_error_init(&err;;
|
|
|
7100e8 |
+ connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err;;
|
|
|
7100e8 |
+ pcmk_dbus_error_check(&err, "Could not connect to System DBus", __FUNCTION__, __LINE__);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ return connection;
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+void pcmk_dbus_disconnect(DBusConnection *connection)
|
|
|
7100e8 |
+{
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+bool pcmk_dbus_append_arg(DBusMessage *msg, int dtype, const void *value)
|
|
|
7100e8 |
+{
|
|
|
7100e8 |
+ DBusMessageIter args;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ dbus_message_iter_init_append(msg, &args);
|
|
|
7100e8 |
+ if (!dbus_message_iter_append_basic(&args, dtype, value)) {
|
|
|
7100e8 |
+ crm_err("dbus_message_iter_append_basic(%c) failed", dtype);
|
|
|
7100e8 |
+ return FALSE;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ return TRUE;
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+DBusMessage *pcmk_dbus_send_recv(DBusMessage *msg, DBusConnection *connection, char **e)
|
|
|
7100e8 |
+{
|
|
|
7100e8 |
+ DBusError error;
|
|
|
7100e8 |
+ const char *method = NULL;
|
|
|
7100e8 |
+ DBusMessage *reply = NULL;
|
|
|
7100e8 |
+ DBusPendingCall* pending = NULL;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ dbus_error_init(&error);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ CRM_ASSERT(dbus_message_get_type (msg) == DBUS_MESSAGE_TYPE_METHOD_CALL);
|
|
|
7100e8 |
+ method = dbus_message_get_member (msg);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ // send message and get a handle for a reply
|
|
|
7100e8 |
+ if (!dbus_connection_send_with_reply (connection, msg, &pending, -1)) { // -1 is default timeout
|
|
|
7100e8 |
+ crm_err("Send with reply failed");
|
|
|
7100e8 |
+ return NULL;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ if (NULL == pending) {
|
|
|
7100e8 |
+ crm_err("No pending call found");
|
|
|
7100e8 |
+ return NULL;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ dbus_connection_flush(connection);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ /* block until we receive a reply */
|
|
|
7100e8 |
+ dbus_pending_call_block(pending);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ /* get the reply message */
|
|
|
7100e8 |
+ reply = dbus_pending_call_steal_reply(pending);
|
|
|
7100e8 |
+ if(reply == NULL) {
|
|
|
7100e8 |
+ error.name = "org.clusterlabs.pacemaker.NoReply";
|
|
|
7100e8 |
+ error.message = "No reply";
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ } else {
|
|
|
7100e8 |
+ DBusMessageIter args;
|
|
|
7100e8 |
+ int dtype = dbus_message_get_type(reply);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ switch(dtype) {
|
|
|
7100e8 |
+ case DBUS_MESSAGE_TYPE_METHOD_RETURN:
|
|
|
7100e8 |
+ dbus_message_iter_init(reply, &args);
|
|
|
7100e8 |
+ crm_trace("Call to %s returned '%s'", method, dbus_message_iter_get_signature(&args));
|
|
|
7100e8 |
+ break;
|
|
|
7100e8 |
+ case DBUS_MESSAGE_TYPE_INVALID:
|
|
|
7100e8 |
+ error.message = "Invalid reply";
|
|
|
7100e8 |
+ error.name = "org.clusterlabs.pacemaker.InvalidReply";
|
|
|
7100e8 |
+ crm_err("Error processing %s response: %s", method, error.message);
|
|
|
7100e8 |
+ break;
|
|
|
7100e8 |
+ case DBUS_MESSAGE_TYPE_METHOD_CALL:
|
|
|
7100e8 |
+ error.message = "Invalid reply (method call)";
|
|
|
7100e8 |
+ error.name = "org.clusterlabs.pacemaker.InvalidReply.Method";
|
|
|
7100e8 |
+ crm_err("Error processing %s response: %s", method, error.message);
|
|
|
7100e8 |
+ break;
|
|
|
7100e8 |
+ case DBUS_MESSAGE_TYPE_SIGNAL:
|
|
|
7100e8 |
+ error.message = "Invalid reply (signal)";
|
|
|
7100e8 |
+ error.name = "org.clusterlabs.pacemaker.InvalidReply.Signal";
|
|
|
7100e8 |
+ crm_err("Error processing %s response: %s", method, error.message);
|
|
|
7100e8 |
+ break;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ case DBUS_MESSAGE_TYPE_ERROR:
|
|
|
7100e8 |
+ dbus_set_error_from_message (&error, reply);
|
|
|
7100e8 |
+ crm_err("%s error '%s': %s", method, error.name, error.message);
|
|
|
7100e8 |
+ break;
|
|
|
7100e8 |
+ default:
|
|
|
7100e8 |
+ error.message = "Unknown reply type";
|
|
|
7100e8 |
+ error.name = "org.clusterlabs.pacemaker.InvalidReply.Type";
|
|
|
7100e8 |
+ crm_err("Error processing %s response: %s (%d)", method, error.message, dtype);
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if(error.name) {
|
|
|
7100e8 |
+ if(e) {
|
|
|
7100e8 |
+ *e = strdup(error.name);
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ if(reply) {
|
|
|
7100e8 |
+ dbus_message_unref(reply);
|
|
|
7100e8 |
+ reply = NULL;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ } else if(e) {
|
|
|
7100e8 |
+ *e = NULL;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ /* free the pending message handle */
|
|
|
7100e8 |
+ dbus_pending_call_unref(pending);
|
|
|
7100e8 |
+ return reply;
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+bool pcmk_dbus_type_check(DBusMessage *msg, DBusMessageIter *field, int expected, const char *function, int line)
|
|
|
7100e8 |
+{
|
|
|
7100e8 |
+ int dtype = dbus_message_iter_get_arg_type(field);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if(dtype != expected) {
|
|
|
7100e8 |
+ DBusMessageIter args;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ dbus_message_iter_init(msg, &args);
|
|
|
7100e8 |
+ do_crm_log_alias(LOG_ERR, __FILE__, function, line,
|
|
|
7100e8 |
+ "Unexepcted DBus type, expected %c instead of %c in '%s'",
|
|
|
7100e8 |
+ expected, dtype, dbus_message_iter_get_signature(&args));
|
|
|
7100e8 |
+ return FALSE;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ return TRUE;
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+#define BUS_PROPERTY_IFACE "org.freedesktop.DBus.Properties"
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+char *
|
|
|
7100e8 |
+pcmk_dbus_get_property(
|
|
|
7100e8 |
+ DBusConnection *connection, const char *target, const char *obj, const gchar * iface, const char *name)
|
|
|
7100e8 |
+{
|
|
|
7100e8 |
+ DBusMessage *msg;
|
|
|
7100e8 |
+ DBusMessageIter args;
|
|
|
7100e8 |
+ DBusMessageIter dict;
|
|
|
7100e8 |
+ DBusMessage *reply = NULL;
|
|
|
7100e8 |
+ /* DBusBasicValue value; */
|
|
|
7100e8 |
+ const char *method = "GetAll";
|
|
|
7100e8 |
+ char *output = NULL;
|
|
|
7100e8 |
+ char *error = NULL;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ /* desc = systemd_unit_property(path, BUS_NAME ".Unit", "Description"); */
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ crm_info("Calling: %s on %s", method, target);
|
|
|
7100e8 |
+ msg = dbus_message_new_method_call(target, // target for the method call
|
|
|
7100e8 |
+ obj, // object to call on
|
|
|
7100e8 |
+ BUS_PROPERTY_IFACE, // interface to call on
|
|
|
7100e8 |
+ method); // method name
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if (NULL == msg) {
|
|
|
7100e8 |
+ crm_err("Call to %s failed: No message", method);
|
|
|
7100e8 |
+ return NULL;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ pcmk_dbus_append_arg(msg, DBUS_TYPE_STRING, &iface);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ reply = pcmk_dbus_send_recv(msg, connection, &error);
|
|
|
7100e8 |
+ dbus_message_unref(msg);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if(reply == NULL) {
|
|
|
7100e8 |
+ crm_err("Call to %s for %s failed: No reply", method, iface);
|
|
|
7100e8 |
+ return NULL;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ } else if (!dbus_message_iter_init(reply, &args)) {
|
|
|
7100e8 |
+ crm_err("Cannot get properties for %s from %s", obj, iface);
|
|
|
7100e8 |
+ return NULL;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if(!pcmk_dbus_type_check(reply, &args, DBUS_TYPE_ARRAY, __FUNCTION__, __LINE__)) {
|
|
|
7100e8 |
+ crm_err("Call to %s failed: Message has invalid arguments", method);
|
|
|
7100e8 |
+ dbus_message_unref(reply);
|
|
|
7100e8 |
+ return NULL;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ dbus_message_iter_recurse(&args, &dict);
|
|
|
7100e8 |
+ while (dbus_message_iter_get_arg_type (&dict) != DBUS_TYPE_INVALID) {
|
|
|
7100e8 |
+ DBusMessageIter sv;
|
|
|
7100e8 |
+ DBusMessageIter v;
|
|
|
7100e8 |
+ DBusBasicValue value;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if(!pcmk_dbus_type_check(reply, &dict, DBUS_TYPE_DICT_ENTRY, __FUNCTION__, __LINE__)) {
|
|
|
7100e8 |
+ dbus_message_iter_next (&dict);
|
|
|
7100e8 |
+ continue;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ dbus_message_iter_recurse(&dict, &sv;;
|
|
|
7100e8 |
+ while (dbus_message_iter_get_arg_type (&sv) != DBUS_TYPE_INVALID) {
|
|
|
7100e8 |
+ int dtype = dbus_message_iter_get_arg_type(&sv;;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ switch(dtype) {
|
|
|
7100e8 |
+ case DBUS_TYPE_STRING:
|
|
|
7100e8 |
+ dbus_message_iter_get_basic(&sv, &value);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ crm_trace("Got: %s", value.str);
|
|
|
7100e8 |
+ if(strcmp(value.str, name) != 0) {
|
|
|
7100e8 |
+ dbus_message_iter_next (&sv;; /* Skip the value */
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ break;
|
|
|
7100e8 |
+ case DBUS_TYPE_VARIANT:
|
|
|
7100e8 |
+ dbus_message_iter_recurse(&sv, &v);
|
|
|
7100e8 |
+ if(pcmk_dbus_type_check(reply, &v, DBUS_TYPE_STRING, __FUNCTION__, __LINE__)) {
|
|
|
7100e8 |
+ dbus_message_iter_get_basic(&v, &value);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ crm_trace("Result: %s", value.str);
|
|
|
7100e8 |
+ output = strdup(value.str);
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ break;
|
|
|
7100e8 |
+ default:
|
|
|
7100e8 |
+ pcmk_dbus_type_check(reply, &sv, DBUS_TYPE_STRING, __FUNCTION__, __LINE__);
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ dbus_message_iter_next (&sv;;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ dbus_message_iter_next (&dict);
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ crm_trace("Property %s[%s] is '%s'", obj, name, output);
|
|
|
7100e8 |
+ return output;
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+int dbus_watch_get_unix_fd ( DBusWatch * watch );
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+/* http://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html#gaebf031eb444b4f847606aa27daa3d8e6 */
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+DBUS_EXPORT dbus_bool_t dbus_connection_set_watch_functions(
|
|
|
7100e8 |
+ DBusConnection * connection,
|
|
|
7100e8 |
+ DBusAddWatchFunction add_function,
|
|
|
7100e8 |
+ DBusRemoveWatchFunction remove_function,
|
|
|
7100e8 |
+ DBusWatchToggledFunction toggled_function,
|
|
|
7100e8 |
+ void * data,
|
|
|
7100e8 |
+ DBusFreeFunction free_data_function
|
|
|
7100e8 |
+ );
|
|
|
7100e8 |
diff --git a/lib/services/pcmk-dbus.h b/lib/services/pcmk-dbus.h
|
|
|
7100e8 |
new file mode 100644
|
|
|
7100e8 |
index 0000000..27ac737
|
|
|
7100e8 |
--- /dev/null
|
|
|
7100e8 |
+++ b/lib/services/pcmk-dbus.h
|
|
|
7100e8 |
@@ -0,0 +1,7 @@
|
|
|
7100e8 |
+DBusConnection *pcmk_dbus_connect(void);
|
|
|
7100e8 |
+void pcmk_dbus_disconnect(DBusConnection *connection);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+DBusMessage *pcmk_dbus_send_recv(DBusMessage *msg, DBusConnection *connection, char **error);
|
|
|
7100e8 |
+bool pcmk_dbus_append_arg(DBusMessage *msg, int dtype, const void *value);
|
|
|
7100e8 |
+bool pcmk_dbus_type_check(DBusMessage *msg, DBusMessageIter *field, int expected, const char *function, int line);
|
|
|
7100e8 |
+char *pcmk_dbus_get_property(DBusConnection *connection, const char *target, const char *obj, const gchar * iface, const char *name);
|
|
|
7100e8 |
diff --git a/lib/services/systemd.c b/lib/services/systemd.c
|
|
|
7100e8 |
index ea804c8..9aa5b03 100644
|
|
|
7100e8 |
--- a/lib/services/systemd.c
|
|
|
7100e8 |
+++ b/lib/services/systemd.c
|
|
|
7100e8 |
@@ -24,6 +24,8 @@
|
|
|
7100e8 |
#include <gio/gio.h>
|
|
|
7100e8 |
#include <services_private.h>
|
|
|
7100e8 |
#include <systemd.h>
|
|
|
7100e8 |
+#include <dbus/dbus.h>
|
|
|
7100e8 |
+#include <pcmk-dbus.h>
|
|
|
7100e8 |
|
|
|
7100e8 |
#define BUS_NAME "org.freedesktop.systemd1"
|
|
|
7100e8 |
#define BUS_PATH "/org/freedesktop/systemd1"
|
|
|
7100e8 |
@@ -47,42 +49,26 @@ struct unit_info {
|
|
|
7100e8 |
const char *job_path;
|
|
|
7100e8 |
};
|
|
|
7100e8 |
|
|
|
7100e8 |
-static GDBusProxy *systemd_proxy = NULL;
|
|
|
7100e8 |
-
|
|
|
7100e8 |
-static GDBusProxy *
|
|
|
7100e8 |
-get_proxy(const char *path, const char *interface)
|
|
|
7100e8 |
+static DBusMessage *systemd_new_method(const char *iface, const char *method)
|
|
|
7100e8 |
{
|
|
|
7100e8 |
- GError *error = NULL;
|
|
|
7100e8 |
- GDBusProxy *proxy = NULL;
|
|
|
7100e8 |
-
|
|
|
7100e8 |
-#ifndef GLIB_DEPRECATED_IN_2_36
|
|
|
7100e8 |
- g_type_init();
|
|
|
7100e8 |
-#endif
|
|
|
7100e8 |
-
|
|
|
7100e8 |
- if (path == NULL) {
|
|
|
7100e8 |
- path = BUS_PATH;
|
|
|
7100e8 |
- }
|
|
|
7100e8 |
-
|
|
|
7100e8 |
- proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, /* GDBusInterfaceInfo */
|
|
|
7100e8 |
- BUS_NAME, path, interface,
|
|
|
7100e8 |
- NULL, /* GCancellable */ &error);
|
|
|
7100e8 |
-
|
|
|
7100e8 |
- if (error) {
|
|
|
7100e8 |
- crm_err("Can't connect obtain proxy to %s interface: %s", interface, error->message);
|
|
|
7100e8 |
- g_error_free(error);
|
|
|
7100e8 |
- proxy = NULL;
|
|
|
7100e8 |
- }
|
|
|
7100e8 |
- return proxy;
|
|
|
7100e8 |
+ crm_trace("Calling: %s on %s", method, iface);
|
|
|
7100e8 |
+ return dbus_message_new_method_call(BUS_NAME, // target for the method call
|
|
|
7100e8 |
+ BUS_PATH, // object to call on
|
|
|
7100e8 |
+ iface, // interface to call on
|
|
|
7100e8 |
+ method); // method name
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+static DBusConnection* systemd_proxy = NULL;
|
|
|
7100e8 |
static gboolean
|
|
|
7100e8 |
systemd_init(void)
|
|
|
7100e8 |
{
|
|
|
7100e8 |
static int need_init = 1;
|
|
|
7100e8 |
+ /* http://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html */
|
|
|
7100e8 |
|
|
|
7100e8 |
if (need_init) {
|
|
|
7100e8 |
need_init = 0;
|
|
|
7100e8 |
- systemd_proxy = get_proxy(NULL, BUS_NAME ".Manager");
|
|
|
7100e8 |
+ systemd_proxy = pcmk_dbus_connect();
|
|
|
7100e8 |
}
|
|
|
7100e8 |
if (systemd_proxy == NULL) {
|
|
|
7100e8 |
return FALSE;
|
|
|
7100e8 |
@@ -94,7 +80,7 @@ void
|
|
|
7100e8 |
systemd_cleanup(void)
|
|
|
7100e8 |
{
|
|
|
7100e8 |
if (systemd_proxy) {
|
|
|
7100e8 |
- g_object_unref(systemd_proxy);
|
|
|
7100e8 |
+ pcmk_dbus_disconnect(systemd_proxy);
|
|
|
7100e8 |
systemd_proxy = NULL;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
}
|
|
|
7100e8 |
@@ -112,130 +98,87 @@ systemd_service_name(const char *name)
|
|
|
7100e8 |
return g_strdup_printf("%s.service", name);
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
-static void
|
|
|
7100e8 |
-systemd_daemon_reload(GDBusProxy * proxy, GError ** error)
|
|
|
7100e8 |
+static bool
|
|
|
7100e8 |
+systemd_daemon_reload(void)
|
|
|
7100e8 |
{
|
|
|
7100e8 |
- GVariant *_ret = g_dbus_proxy_call_sync(proxy, "Reload", g_variant_new("()"),
|
|
|
7100e8 |
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, error);
|
|
|
7100e8 |
-
|
|
|
7100e8 |
- if (_ret) {
|
|
|
7100e8 |
- g_variant_unref(_ret);
|
|
|
7100e8 |
+ const char *method = "Reload";
|
|
|
7100e8 |
+ DBusMessage *reply = NULL;
|
|
|
7100e8 |
+ DBusMessage *msg = systemd_new_method(BUS_NAME".Manager", method);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ CRM_ASSERT(msg != NULL);
|
|
|
7100e8 |
+ reply = pcmk_dbus_send_recv(msg, systemd_proxy, NULL);
|
|
|
7100e8 |
+ dbus_message_unref(msg);
|
|
|
7100e8 |
+ if(reply) {
|
|
|
7100e8 |
+ dbus_message_unref(reply);
|
|
|
7100e8 |
}
|
|
|
7100e8 |
+ return TRUE;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
static gboolean
|
|
|
7100e8 |
-systemd_unit_by_name(GDBusProxy * proxy,
|
|
|
7100e8 |
- const gchar * arg_name,
|
|
|
7100e8 |
- gchar ** out_unit, GCancellable * cancellable, GError ** error)
|
|
|
7100e8 |
+systemd_unit_by_name(const gchar * arg_name, gchar ** out_unit)
|
|
|
7100e8 |
{
|
|
|
7100e8 |
- GError *reload_error = NULL;
|
|
|
7100e8 |
- GVariant *_ret = NULL;
|
|
|
7100e8 |
+ DBusMessage *msg;
|
|
|
7100e8 |
+ DBusMessageIter args;
|
|
|
7100e8 |
+ DBusMessage *reply = NULL;
|
|
|
7100e8 |
+ const char *method = "GetUnit";
|
|
|
7100e8 |
char *name = NULL;
|
|
|
7100e8 |
- int retry = 0;
|
|
|
7100e8 |
+ char *error = NULL;
|
|
|
7100e8 |
|
|
|
7100e8 |
/*
|
|
|
7100e8 |
- " <method name=\"GetUnit\">\n" \
|
|
|
7100e8 |
- " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
|
|
|
7100e8 |
- " <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \
|
|
|
7100e8 |
- " </method>\n" \
|
|
|
7100e8 |
-*/
|
|
|
7100e8 |
-
|
|
|
7100e8 |
- name = systemd_service_name(arg_name);
|
|
|
7100e8 |
- crm_debug("Calling GetUnit");
|
|
|
7100e8 |
- _ret = g_dbus_proxy_call_sync(proxy, "GetUnit", g_variant_new("(s)", name),
|
|
|
7100e8 |
- G_DBUS_CALL_FLAGS_NONE, -1, cancellable, error);
|
|
|
7100e8 |
-
|
|
|
7100e8 |
- if (_ret) {
|
|
|
7100e8 |
- crm_debug("Checking output");
|
|
|
7100e8 |
- g_variant_get(_ret, "(o)", out_unit);
|
|
|
7100e8 |
- crm_debug("%s = %s", arg_name, *out_unit);
|
|
|
7100e8 |
- g_variant_unref(_ret);
|
|
|
7100e8 |
- goto done;
|
|
|
7100e8 |
- }
|
|
|
7100e8 |
-
|
|
|
7100e8 |
- crm_debug("Reloading the systemd manager configuration");
|
|
|
7100e8 |
- systemd_daemon_reload(proxy, &reload_error);
|
|
|
7100e8 |
- retry++;
|
|
|
7100e8 |
-
|
|
|
7100e8 |
- if (reload_error) {
|
|
|
7100e8 |
- crm_err("Cannot reload the systemd manager configuration: %s", reload_error->message);
|
|
|
7100e8 |
- g_error_free(reload_error);
|
|
|
7100e8 |
- goto done;
|
|
|
7100e8 |
- }
|
|
|
7100e8 |
-
|
|
|
7100e8 |
- if (*error) {
|
|
|
7100e8 |
- crm_debug("Cannot find %s: %s", name, (*error)->message);
|
|
|
7100e8 |
- g_error_free(*error);
|
|
|
7100e8 |
- *error = NULL;
|
|
|
7100e8 |
- }
|
|
|
7100e8 |
+ <method name="GetUnit">
|
|
|
7100e8 |
+ <arg name="name" type="s" direction="in"/>
|
|
|
7100e8 |
+ <arg name="unit" type="o" direction="out"/>
|
|
|
7100e8 |
+ </method>
|
|
|
7100e8 |
|
|
|
7100e8 |
-/*
|
|
|
7100e8 |
<method name="LoadUnit">
|
|
|
7100e8 |
<arg name="name" type="s" direction="in"/>
|
|
|
7100e8 |
<arg name="unit" type="o" direction="out"/>
|
|
|
7100e8 |
</method>
|
|
|
7100e8 |
*/
|
|
|
7100e8 |
- crm_debug("Calling LoadUnit");
|
|
|
7100e8 |
- _ret = g_dbus_proxy_call_sync(proxy, "LoadUnit", g_variant_new("(s)", name),
|
|
|
7100e8 |
- G_DBUS_CALL_FLAGS_NONE, -1, cancellable, error);
|
|
|
7100e8 |
|
|
|
7100e8 |
- if (_ret) {
|
|
|
7100e8 |
- crm_debug("Checking output");
|
|
|
7100e8 |
- g_variant_get(_ret, "(o)", out_unit);
|
|
|
7100e8 |
- crm_debug("%s = %s", arg_name, *out_unit);
|
|
|
7100e8 |
- g_variant_unref(_ret);
|
|
|
7100e8 |
- }
|
|
|
7100e8 |
+ name = systemd_service_name(arg_name);
|
|
|
7100e8 |
|
|
|
7100e8 |
- done:
|
|
|
7100e8 |
- free(name);
|
|
|
7100e8 |
- return _ret != NULL;
|
|
|
7100e8 |
-}
|
|
|
7100e8 |
+ while(*out_unit == NULL) {
|
|
|
7100e8 |
+ msg = systemd_new_method(BUS_NAME".Manager", method);
|
|
|
7100e8 |
+ CRM_ASSERT(msg != NULL);
|
|
|
7100e8 |
|
|
|
7100e8 |
-static char *
|
|
|
7100e8 |
-systemd_unit_property(const char *obj, const gchar * iface, const char *name)
|
|
|
7100e8 |
-{
|
|
|
7100e8 |
- GError *error = NULL;
|
|
|
7100e8 |
- GDBusProxy *proxy;
|
|
|
7100e8 |
- GVariant *asv = NULL;
|
|
|
7100e8 |
- GVariant *value = NULL;
|
|
|
7100e8 |
- GVariant *_ret = NULL;
|
|
|
7100e8 |
- char *output = NULL;
|
|
|
7100e8 |
+ pcmk_dbus_append_arg(msg, DBUS_TYPE_STRING, &name);
|
|
|
7100e8 |
|
|
|
7100e8 |
- crm_trace("Calling GetAll on %s", obj);
|
|
|
7100e8 |
- proxy = get_proxy(obj, BUS_PROPERTY_IFACE);
|
|
|
7100e8 |
+ reply = pcmk_dbus_send_recv(msg, systemd_proxy, &error);
|
|
|
7100e8 |
+ dbus_message_unref(msg);
|
|
|
7100e8 |
|
|
|
7100e8 |
- if (!proxy) {
|
|
|
7100e8 |
- return NULL;
|
|
|
7100e8 |
- }
|
|
|
7100e8 |
+ if(error) {
|
|
|
7100e8 |
+ crm_info("Call to %s failed: %s", method, error);
|
|
|
7100e8 |
+ free(error);
|
|
|
7100e8 |
+ error = NULL;
|
|
|
7100e8 |
|
|
|
7100e8 |
- _ret = g_dbus_proxy_call_sync(proxy, "GetAll", g_variant_new("(s)", iface),
|
|
|
7100e8 |
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
|
|
|
7100e8 |
+ } else if (dbus_message_iter_init(reply, &args)) {
|
|
|
7100e8 |
|
|
|
7100e8 |
- if (error) {
|
|
|
7100e8 |
- crm_err("Cannot get properties for %s: %s", g_dbus_proxy_get_object_path(proxy),
|
|
|
7100e8 |
- error->message);
|
|
|
7100e8 |
- g_error_free(error);
|
|
|
7100e8 |
- g_object_unref(proxy);
|
|
|
7100e8 |
- return NULL;
|
|
|
7100e8 |
- }
|
|
|
7100e8 |
- crm_debug("Call to GetAll passed: type '%s' %d\n", g_variant_get_type_string(_ret),
|
|
|
7100e8 |
- g_variant_n_children(_ret));
|
|
|
7100e8 |
+ if(pcmk_dbus_type_check(reply, &args, DBUS_TYPE_OBJECT_PATH, __FUNCTION__, __LINE__)) {
|
|
|
7100e8 |
+ DBusBasicValue value;
|
|
|
7100e8 |
|
|
|
7100e8 |
- asv = g_variant_get_child_value(_ret, 0);
|
|
|
7100e8 |
- crm_trace("asv type '%s' %d\n", g_variant_get_type_string(asv), g_variant_n_children(asv));
|
|
|
7100e8 |
+ dbus_message_iter_get_basic(&args, &value);
|
|
|
7100e8 |
+ *out_unit = strdup(value.str);
|
|
|
7100e8 |
+ dbus_message_unref(reply);
|
|
|
7100e8 |
+ free(name);
|
|
|
7100e8 |
+ return TRUE;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
|
|
|
7100e8 |
- value = g_variant_lookup_value(asv, name, NULL);
|
|
|
7100e8 |
- if (value && g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
|
|
|
7100e8 |
- crm_info("Got value '%s' for %s[%s]", g_variant_get_string(value, NULL), obj, name);
|
|
|
7100e8 |
- output = g_variant_dup_string(value, NULL);
|
|
|
7100e8 |
+ if(strcmp(method, "LoadUnit") != 0) {
|
|
|
7100e8 |
+ method = "LoadUnit";
|
|
|
7100e8 |
+ crm_debug("Cannot find %s, reloading the systemd manager configuration", name);
|
|
|
7100e8 |
+ systemd_daemon_reload();
|
|
|
7100e8 |
+ if(reply) {
|
|
|
7100e8 |
+ dbus_message_unref(reply);
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
|
|
|
7100e8 |
- } else {
|
|
|
7100e8 |
- crm_info("No value for %s[%s]", obj, name);
|
|
|
7100e8 |
+ } else {
|
|
|
7100e8 |
+ free(name);
|
|
|
7100e8 |
+ return FALSE;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
}
|
|
|
7100e8 |
-
|
|
|
7100e8 |
- g_object_unref(proxy);
|
|
|
7100e8 |
- g_variant_unref(_ret);
|
|
|
7100e8 |
- return output;
|
|
|
7100e8 |
+ return FALSE;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
GList *
|
|
|
7100e8 |
@@ -243,11 +186,13 @@ systemd_unit_listall(void)
|
|
|
7100e8 |
{
|
|
|
7100e8 |
int lpc = 0;
|
|
|
7100e8 |
GList *units = NULL;
|
|
|
7100e8 |
- GError *error = NULL;
|
|
|
7100e8 |
- GVariant *out_units = NULL;
|
|
|
7100e8 |
- GVariantIter iter;
|
|
|
7100e8 |
- struct unit_info u;
|
|
|
7100e8 |
- GVariant *_ret = NULL;
|
|
|
7100e8 |
+ DBusMessageIter args;
|
|
|
7100e8 |
+ DBusMessageIter unit;
|
|
|
7100e8 |
+ DBusMessageIter elem;
|
|
|
7100e8 |
+ DBusMessage *msg = NULL;
|
|
|
7100e8 |
+ DBusMessage *reply = NULL;
|
|
|
7100e8 |
+ const char *method = "ListUnits";
|
|
|
7100e8 |
+ char *error = NULL;
|
|
|
7100e8 |
|
|
|
7100e8 |
if (systemd_init() == FALSE) {
|
|
|
7100e8 |
return NULL;
|
|
|
7100e8 |
@@ -259,40 +204,60 @@ systemd_unit_listall(void)
|
|
|
7100e8 |
" </method>\n" \
|
|
|
7100e8 |
*/
|
|
|
7100e8 |
|
|
|
7100e8 |
- _ret = g_dbus_proxy_call_sync(systemd_proxy, "ListUnits", g_variant_new("()"),
|
|
|
7100e8 |
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
|
|
|
7100e8 |
+ msg = systemd_new_method(BUS_NAME".Manager", method);
|
|
|
7100e8 |
+ CRM_ASSERT(msg != NULL);
|
|
|
7100e8 |
|
|
|
7100e8 |
- if (error || _ret == NULL) {
|
|
|
7100e8 |
- crm_info("Call to ListUnits failed: %s", error ? error->message : "unknown");
|
|
|
7100e8 |
- if(error) {
|
|
|
7100e8 |
- g_error_free(error);
|
|
|
7100e8 |
- }
|
|
|
7100e8 |
+ reply = pcmk_dbus_send_recv(msg, systemd_proxy, &error);
|
|
|
7100e8 |
+ dbus_message_unref(msg);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if(error) {
|
|
|
7100e8 |
+ crm_err("Call to %s failed: %s", method, error);
|
|
|
7100e8 |
+ free(error);
|
|
|
7100e8 |
+ return NULL;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ } else if (!dbus_message_iter_init(reply, &args)) {
|
|
|
7100e8 |
+ crm_err("Call to %s failed: Message has no arguments", method);
|
|
|
7100e8 |
+ dbus_message_unref(reply);
|
|
|
7100e8 |
return NULL;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
- g_variant_get(_ret, "(@a(ssssssouso))", &out_units);
|
|
|
7100e8 |
-
|
|
|
7100e8 |
- g_variant_iter_init(&iter, out_units);
|
|
|
7100e8 |
- while (g_variant_iter_loop(&iter, "(ssssssouso)",
|
|
|
7100e8 |
- &u.id,
|
|
|
7100e8 |
- &u.description,
|
|
|
7100e8 |
- &u.load_state,
|
|
|
7100e8 |
- &u.active_state,
|
|
|
7100e8 |
- &u.sub_state,
|
|
|
7100e8 |
- &u.following, &u.unit_path, &u.job_id, &u.job_type, &u.job_path)) {
|
|
|
7100e8 |
- char *match = strstr(u.id, ".service");
|
|
|
7100e8 |
-
|
|
|
7100e8 |
- if (match) {
|
|
|
7100e8 |
- lpc++;
|
|
|
7100e8 |
- match[0] = 0;
|
|
|
7100e8 |
- crm_trace("Got %s[%s] = %s", u.id, u.active_state, u.description);
|
|
|
7100e8 |
- units = g_list_append(units, strdup(u.id));
|
|
|
7100e8 |
+ if(!pcmk_dbus_type_check(reply, &args, DBUS_TYPE_ARRAY, __FUNCTION__, __LINE__)) {
|
|
|
7100e8 |
+ crm_err("Call to %s failed: Message has invalid arguments", method);
|
|
|
7100e8 |
+ dbus_message_unref(reply);
|
|
|
7100e8 |
+ return NULL;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ dbus_message_iter_recurse(&args, &unit);
|
|
|
7100e8 |
+ while (dbus_message_iter_get_arg_type (&unit) != DBUS_TYPE_INVALID) {
|
|
|
7100e8 |
+ DBusBasicValue value;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if(!pcmk_dbus_type_check(reply, &unit, DBUS_TYPE_STRUCT, __FUNCTION__, __LINE__)) {
|
|
|
7100e8 |
+ continue;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ dbus_message_iter_recurse(&unit, &elem);
|
|
|
7100e8 |
+ if(!pcmk_dbus_type_check(reply, &elem, DBUS_TYPE_STRING, __FUNCTION__, __LINE__)) {
|
|
|
7100e8 |
+ continue;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ dbus_message_iter_get_basic(&elem, &value);
|
|
|
7100e8 |
+ crm_trace("Got: %s", value.str);
|
|
|
7100e8 |
+ if(value.str) {
|
|
|
7100e8 |
+ char *match = strstr(value.str, ".service");
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if (match) {
|
|
|
7100e8 |
+ lpc++;
|
|
|
7100e8 |
+ match[0] = 0;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ units = g_list_append(units, strdup(value.str));
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ dbus_message_iter_next (&unit);
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
- crm_info("Call to ListUnits passed: type '%s' count %d", g_variant_get_type_string(out_units),
|
|
|
7100e8 |
- lpc);
|
|
|
7100e8 |
- g_variant_unref(_ret);
|
|
|
7100e8 |
+ dbus_message_unref(reply);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ crm_trace("Found %d systemd services", lpc);
|
|
|
7100e8 |
return units;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
@@ -300,26 +265,18 @@ gboolean
|
|
|
7100e8 |
systemd_unit_exists(const char *name)
|
|
|
7100e8 |
{
|
|
|
7100e8 |
char *path = NULL;
|
|
|
7100e8 |
- GError *error = NULL;
|
|
|
7100e8 |
gboolean pass = FALSE;
|
|
|
7100e8 |
|
|
|
7100e8 |
if (systemd_init() == FALSE) {
|
|
|
7100e8 |
return FALSE;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
- pass = systemd_unit_by_name(systemd_proxy, name, &path, NULL, &error);
|
|
|
7100e8 |
-
|
|
|
7100e8 |
- if (error || pass == FALSE) {
|
|
|
7100e8 |
- pass = FALSE;
|
|
|
7100e8 |
- crm_err("Call to ListUnits failed: %s", error ? error->message : "unknown");
|
|
|
7100e8 |
- if(error) {
|
|
|
7100e8 |
- g_error_free(error);
|
|
|
7100e8 |
- }
|
|
|
7100e8 |
-
|
|
|
7100e8 |
- } else {
|
|
|
7100e8 |
+ if(systemd_unit_by_name(name, &path) && path) {
|
|
|
7100e8 |
crm_trace("Got %s", path);
|
|
|
7100e8 |
+ pass = TRUE;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
- /* free(path) */
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ free(path);
|
|
|
7100e8 |
return pass;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
@@ -329,11 +286,10 @@ systemd_unit_metadata(const char *name)
|
|
|
7100e8 |
char *path = NULL;
|
|
|
7100e8 |
char *meta = NULL;
|
|
|
7100e8 |
char *desc = NULL;
|
|
|
7100e8 |
- GError *error = NULL;
|
|
|
7100e8 |
|
|
|
7100e8 |
CRM_ASSERT(systemd_init());
|
|
|
7100e8 |
- if (systemd_unit_by_name(systemd_proxy, name, &path, NULL, &error)) {
|
|
|
7100e8 |
- desc = systemd_unit_property(path, BUS_NAME ".Unit", "Description");
|
|
|
7100e8 |
+ if (systemd_unit_by_name(name, &path)) {
|
|
|
7100e8 |
+ desc = pcmk_dbus_get_property(systemd_proxy, BUS_NAME, path, BUS_NAME ".Unit", "Description");
|
|
|
7100e8 |
} else {
|
|
|
7100e8 |
desc = g_strdup_printf("systemd unit file for %s", name);
|
|
|
7100e8 |
}
|
|
|
7100e8 |
@@ -362,6 +318,7 @@ systemd_unit_metadata(const char *name)
|
|
|
7100e8 |
return meta;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
+#if 0
|
|
|
7100e8 |
static void
|
|
|
7100e8 |
systemd_unit_exec_done(GObject * source_object, GAsyncResult * res, gpointer user_data)
|
|
|
7100e8 |
{
|
|
|
7100e8 |
@@ -411,19 +368,23 @@ systemd_unit_exec_done(GObject * source_object, GAsyncResult * res, gpointer use
|
|
|
7100e8 |
g_variant_unref(_ret);
|
|
|
7100e8 |
}
|
|
|
7100e8 |
}
|
|
|
7100e8 |
+#endif
|
|
|
7100e8 |
|
|
|
7100e8 |
#define SYSTEMD_OVERRIDE_ROOT "/run/systemd/system/"
|
|
|
7100e8 |
|
|
|
7100e8 |
gboolean
|
|
|
7100e8 |
systemd_unit_exec(svc_action_t * op, gboolean synchronous)
|
|
|
7100e8 |
{
|
|
|
7100e8 |
+ char *error = NULL;
|
|
|
7100e8 |
char *unit = NULL;
|
|
|
7100e8 |
- GError *error = NULL;
|
|
|
7100e8 |
+ const char *replace_s = "replace";
|
|
|
7100e8 |
gboolean pass = FALSE;
|
|
|
7100e8 |
- GVariant *_ret = NULL;
|
|
|
7100e8 |
- const char *action = op->action;
|
|
|
7100e8 |
+ const char *method = op->action;
|
|
|
7100e8 |
char *name = systemd_service_name(op->agent);
|
|
|
7100e8 |
-
|
|
|
7100e8 |
+ DBusMessage *msg = NULL;
|
|
|
7100e8 |
+ DBusMessage *reply = NULL;
|
|
|
7100e8 |
+ DBusMessageIter args;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
op->rc = PCMK_OCF_UNKNOWN_ERROR;
|
|
|
7100e8 |
CRM_ASSERT(systemd_init());
|
|
|
7100e8 |
|
|
|
7100e8 |
@@ -436,22 +397,20 @@ systemd_unit_exec(svc_action_t * op, gboolean synchronous)
|
|
|
7100e8 |
goto cleanup;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
- pass = systemd_unit_by_name(systemd_proxy, op->agent, &unit, NULL, &error);
|
|
|
7100e8 |
- if (error || pass == FALSE) {
|
|
|
7100e8 |
- crm_debug("Could not obtain unit named '%s': %s", op->agent,
|
|
|
7100e8 |
- error ? error->message : "unknown");
|
|
|
7100e8 |
+ pass = systemd_unit_by_name(op->agent, &unit);
|
|
|
7100e8 |
+ if (pass == FALSE) {
|
|
|
7100e8 |
+ crm_debug("Could not obtain unit named '%s'", op->agent);
|
|
|
7100e8 |
+#if 0
|
|
|
7100e8 |
if (error && strstr(error->message, "systemd1.NoSuchUnit")) {
|
|
|
7100e8 |
op->rc = PCMK_OCF_NOT_INSTALLED;
|
|
|
7100e8 |
op->status = PCMK_LRM_OP_NOT_INSTALLED;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
- if(error) {
|
|
|
7100e8 |
- g_error_free(error);
|
|
|
7100e8 |
- }
|
|
|
7100e8 |
+#endif
|
|
|
7100e8 |
goto cleanup;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
- if (safe_str_eq(op->action, "monitor") || safe_str_eq(action, "status")) {
|
|
|
7100e8 |
- char *state = systemd_unit_property(unit, BUS_NAME ".Unit", "ActiveState");
|
|
|
7100e8 |
+ if (safe_str_eq(op->action, "monitor") || safe_str_eq(method, "status")) {
|
|
|
7100e8 |
+ char *state = pcmk_dbus_get_property(systemd_proxy, BUS_NAME, unit, BUS_NAME ".Unit", "ActiveState");
|
|
|
7100e8 |
|
|
|
7100e8 |
if (g_strcmp0(state, "active") == 0) {
|
|
|
7100e8 |
op->rc = PCMK_OCF_OK;
|
|
|
7100e8 |
@@ -462,12 +421,12 @@ systemd_unit_exec(svc_action_t * op, gboolean synchronous)
|
|
|
7100e8 |
free(state);
|
|
|
7100e8 |
goto cleanup;
|
|
|
7100e8 |
|
|
|
7100e8 |
- } else if (g_strcmp0(action, "start") == 0) {
|
|
|
7100e8 |
+ } else if (g_strcmp0(method, "start") == 0) {
|
|
|
7100e8 |
FILE *file_strm = NULL;
|
|
|
7100e8 |
char *override_dir = g_strdup_printf("%s/%s", SYSTEMD_OVERRIDE_ROOT, unit);
|
|
|
7100e8 |
char *override_file = g_strdup_printf("%s/50-pacemaker.conf", override_dir);
|
|
|
7100e8 |
|
|
|
7100e8 |
- action = "StartUnit";
|
|
|
7100e8 |
+ method = "StartUnit";
|
|
|
7100e8 |
crm_build_path(override_dir, 0755);
|
|
|
7100e8 |
|
|
|
7100e8 |
file_strm = fopen(override_file, "w");
|
|
|
7100e8 |
@@ -485,74 +444,85 @@ systemd_unit_exec(svc_action_t * op, gboolean synchronous)
|
|
|
7100e8 |
fflush(file_strm);
|
|
|
7100e8 |
fclose(file_strm);
|
|
|
7100e8 |
}
|
|
|
7100e8 |
- systemd_daemon_reload(systemd_proxy, &error);
|
|
|
7100e8 |
- if(error) {
|
|
|
7100e8 |
- g_error_free(error);
|
|
|
7100e8 |
- }
|
|
|
7100e8 |
+ systemd_daemon_reload();
|
|
|
7100e8 |
free(override_file);
|
|
|
7100e8 |
free(override_dir);
|
|
|
7100e8 |
|
|
|
7100e8 |
- } else if (g_strcmp0(action, "stop") == 0) {
|
|
|
7100e8 |
+ } else if (g_strcmp0(method, "stop") == 0) {
|
|
|
7100e8 |
char *override_file = g_strdup_printf("%s/%s/50-pacemaker.conf", SYSTEMD_OVERRIDE_ROOT, unit);
|
|
|
7100e8 |
|
|
|
7100e8 |
- action = "StopUnit";
|
|
|
7100e8 |
+ method = "StopUnit";
|
|
|
7100e8 |
unlink(override_file);
|
|
|
7100e8 |
free(override_file);
|
|
|
7100e8 |
- systemd_daemon_reload(systemd_proxy, &error);
|
|
|
7100e8 |
- if(error) {
|
|
|
7100e8 |
- g_error_free(error);
|
|
|
7100e8 |
- }
|
|
|
7100e8 |
+ systemd_daemon_reload();
|
|
|
7100e8 |
|
|
|
7100e8 |
- } else if (g_strcmp0(action, "restart") == 0) {
|
|
|
7100e8 |
- action = "RestartUnit";
|
|
|
7100e8 |
+ } else if (g_strcmp0(method, "restart") == 0) {
|
|
|
7100e8 |
+ method = "RestartUnit";
|
|
|
7100e8 |
} else {
|
|
|
7100e8 |
op->rc = PCMK_OCF_UNIMPLEMENT_FEATURE;
|
|
|
7100e8 |
goto cleanup;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
- crm_debug("Calling %s for %s: %s", action, op->rsc, unit);
|
|
|
7100e8 |
+ crm_debug("Calling %s for %s: %s", method, op->rsc, unit);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+#if 0
|
|
|
7100e8 |
if (synchronous == FALSE) {
|
|
|
7100e8 |
- g_dbus_proxy_call(systemd_proxy, action, g_variant_new("(ss)", name, "replace"),
|
|
|
7100e8 |
+ g_dbus_proxy_call(systemd_proxy, method, g_variant_new("(ss)", name, "replace"),
|
|
|
7100e8 |
G_DBUS_CALL_FLAGS_NONE, op->timeout, NULL, systemd_unit_exec_done, op);
|
|
|
7100e8 |
free(unit);
|
|
|
7100e8 |
free(name);
|
|
|
7100e8 |
return TRUE;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
+#endif
|
|
|
7100e8 |
|
|
|
7100e8 |
- _ret = g_dbus_proxy_call_sync(systemd_proxy, action, g_variant_new("(ss)", name, "replace"),
|
|
|
7100e8 |
- G_DBUS_CALL_FLAGS_NONE, op->timeout, NULL, &error);
|
|
|
7100e8 |
+ msg = systemd_new_method(BUS_NAME".Manager", method);
|
|
|
7100e8 |
+ CRM_ASSERT(msg != NULL);
|
|
|
7100e8 |
|
|
|
7100e8 |
- if (error) {
|
|
|
7100e8 |
+ /* (ss) */
|
|
|
7100e8 |
+ pcmk_dbus_append_arg(msg, DBUS_TYPE_STRING, &name);
|
|
|
7100e8 |
+ pcmk_dbus_append_arg(msg, DBUS_TYPE_STRING, &replace_s);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ reply = pcmk_dbus_send_recv(msg, systemd_proxy, &error);
|
|
|
7100e8 |
+ dbus_message_unref(msg);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if(error) {
|
|
|
7100e8 |
/* ignore "already started" or "not running" errors */
|
|
|
7100e8 |
if (safe_str_eq(op->action, "stop")
|
|
|
7100e8 |
- && strstr(error->message, "systemd1.InvalidName")) {
|
|
|
7100e8 |
+ && (strstr(error, "org.freedesktop.systemd1.InvalidName")
|
|
|
7100e8 |
+ || strstr(error, "org.freedesktop.systemd1.NoSuchUnit"))) {
|
|
|
7100e8 |
crm_trace("Masking Stop failure for %s: unknown services are stopped", op->rsc);
|
|
|
7100e8 |
op->rc = PCMK_OCF_OK;
|
|
|
7100e8 |
} else {
|
|
|
7100e8 |
- crm_err("Could not issue %s for %s: %s (%s)", action, op->rsc, error->message, unit);
|
|
|
7100e8 |
+ crm_err("Could not issue %s for %s: %s (%s)", method, op->rsc, error, unit);
|
|
|
7100e8 |
}
|
|
|
7100e8 |
- g_error_free(error);
|
|
|
7100e8 |
+ goto cleanup;
|
|
|
7100e8 |
|
|
|
7100e8 |
- } else if(g_variant_is_of_type (_ret, G_VARIANT_TYPE("(o)"))) {
|
|
|
7100e8 |
- char *path = NULL;
|
|
|
7100e8 |
+ } else if(!dbus_message_iter_init(reply, &args)) {
|
|
|
7100e8 |
+ crm_err("Call to %s failed: no arguments", method);
|
|
|
7100e8 |
+ goto cleanup;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
|
|
|
7100e8 |
- g_variant_get(_ret, "(o)", &path);
|
|
|
7100e8 |
- crm_info("Call to %s passed: type '%s' %s", op->action, g_variant_get_type_string(_ret),
|
|
|
7100e8 |
- path);
|
|
|
7100e8 |
- op->rc = PCMK_OCF_OK;
|
|
|
7100e8 |
+ /* (o) */
|
|
|
7100e8 |
+ if(!pcmk_dbus_type_check(reply, &args, DBUS_TYPE_OBJECT_PATH, __FUNCTION__, __LINE__)) {
|
|
|
7100e8 |
+ crm_err("Call to %s failed: Message has invalid arguments", method);
|
|
|
7100e8 |
|
|
|
7100e8 |
} else {
|
|
|
7100e8 |
- crm_err("Call to %s passed but return type was '%s' not '(o)'", op->action, g_variant_get_type_string(_ret));
|
|
|
7100e8 |
+ DBusBasicValue value;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ dbus_message_iter_get_basic(&args, &value);
|
|
|
7100e8 |
+ crm_info("Call to %s passed: %s", op->action, value.str);
|
|
|
7100e8 |
op->rc = PCMK_OCF_OK;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
cleanup:
|
|
|
7100e8 |
+ free(error);
|
|
|
7100e8 |
free(unit);
|
|
|
7100e8 |
free(name);
|
|
|
7100e8 |
|
|
|
7100e8 |
- if (_ret) {
|
|
|
7100e8 |
- g_variant_unref(_ret);
|
|
|
7100e8 |
+ if(reply) {
|
|
|
7100e8 |
+ dbus_message_unref(reply);
|
|
|
7100e8 |
}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
if (synchronous == FALSE) {
|
|
|
7100e8 |
operation_finalize(op);
|
|
|
7100e8 |
return TRUE;
|