|
|
7100e8 |
commit c7ca5eccb5709c75797579f508c3f9ae968cd55e
|
|
|
7100e8 |
Author: Andrew Beekhof <andrew@beekhof.net>
|
|
|
7100e8 |
Date: Fri Jan 31 10:53:35 2014 +1100
|
|
|
7100e8 |
|
|
|
7100e8 |
Fix: Bug rhbz#1057697 - Use native DBus library for systemd async support to avoid problematic use of threads
|
|
|
7100e8 |
|
|
|
7100e8 |
(cherry picked from commit 2f90aad962c63eba313ed466580703434c80bd1a)
|
|
|
7100e8 |
|
|
|
7100e8 |
diff --git a/lib/services/dbus.c b/lib/services/dbus.c
|
|
|
7100e8 |
index 69ea6ac..a3286f2 100644
|
|
|
7100e8 |
--- a/lib/services/dbus.c
|
|
|
7100e8 |
+++ b/lib/services/dbus.c
|
|
|
7100e8 |
@@ -4,6 +4,9 @@
|
|
|
7100e8 |
#include <dbus/dbus.h>
|
|
|
7100e8 |
#include <pcmk-dbus.h>
|
|
|
7100e8 |
|
|
|
7100e8 |
+#define BUS_PROPERTY_IFACE "org.freedesktop.DBus.Properties"
|
|
|
7100e8 |
+
|
|
|
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 |
@@ -43,36 +46,18 @@ bool pcmk_dbus_append_arg(DBusMessage *msg, int dtype, const void *value)
|
|
|
7100e8 |
return TRUE;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
-DBusMessage *pcmk_dbus_send_recv(DBusMessage *msg, DBusConnection *connection, char **e)
|
|
|
7100e8 |
+bool
|
|
|
7100e8 |
+pcmk_dbus_find_error(const char *method, DBusPendingCall* pending, DBusMessage *reply, DBusError *ret)
|
|
|
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 |
+ if(pending == NULL) {
|
|
|
7100e8 |
+ error.name = "org.clusterlabs.pacemaker.NoRequest";
|
|
|
7100e8 |
+ error.message = "No request sent";
|
|
|
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 |
+ } else if(reply == NULL) {
|
|
|
7100e8 |
error.name = "org.clusterlabs.pacemaker.NoReply";
|
|
|
7100e8 |
error.message = "No reply";
|
|
|
7100e8 |
|
|
|
7100e8 |
@@ -80,7 +65,6 @@ DBusMessage *pcmk_dbus_send_recv(DBusMessage *msg, DBusConnection *connection, c
|
|
|
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 |
@@ -104,7 +88,7 @@ DBusMessage *pcmk_dbus_send_recv(DBusMessage *msg, DBusConnection *connection, c
|
|
|
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 |
+ crm_info("%s error '%s': %s", method, error.name, error.message);
|
|
|
7100e8 |
break;
|
|
|
7100e8 |
default:
|
|
|
7100e8 |
error.message = "Unknown reply type";
|
|
|
7100e8 |
@@ -113,23 +97,86 @@ DBusMessage *pcmk_dbus_send_recv(DBusMessage *msg, DBusConnection *connection, c
|
|
|
7100e8 |
}
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
- if(error.name) {
|
|
|
7100e8 |
- if(e) {
|
|
|
7100e8 |
- *e = strdup(error.name);
|
|
|
7100e8 |
+ if(ret && (error.name || error.message)) {
|
|
|
7100e8 |
+ *ret = error;
|
|
|
7100e8 |
+ return TRUE;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ return FALSE;
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+DBusMessage *pcmk_dbus_send_recv(DBusMessage *msg, DBusConnection *connection, DBusError *error)
|
|
|
7100e8 |
+{
|
|
|
7100e8 |
+ const char *method = NULL;
|
|
|
7100e8 |
+ DBusMessage *reply = NULL;
|
|
|
7100e8 |
+ DBusPendingCall* pending = NULL;
|
|
|
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 |
+ if(error) {
|
|
|
7100e8 |
+ error->message = "Call to dbus_connection_send_with_reply() failed";
|
|
|
7100e8 |
+ error->name = "org.clusterlabs.pacemaker.SendFailed";
|
|
|
7100e8 |
}
|
|
|
7100e8 |
+ crm_err("Error sending %s request", method);
|
|
|
7100e8 |
+ return NULL;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ dbus_connection_flush(connection);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if(pending) {
|
|
|
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 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if(pcmk_dbus_find_error(method, pending, reply, error)) {
|
|
|
7100e8 |
+ crm_trace("Was error: '%s' '%s'", error->name, error->message);
|
|
|
7100e8 |
if(reply) {
|
|
|
7100e8 |
dbus_message_unref(reply);
|
|
|
7100e8 |
reply = NULL;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
- } else if(e) {
|
|
|
7100e8 |
- *e = NULL;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ crm_trace("Was error: '%s' '%s'", error->name, error->message);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if(pending) {
|
|
|
7100e8 |
+ /* free the pending message handle */
|
|
|
7100e8 |
+ dbus_pending_call_unref(pending);
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
- /* free the pending message handle */
|
|
|
7100e8 |
- dbus_pending_call_unref(pending);
|
|
|
7100e8 |
return reply;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
+bool pcmk_dbus_send(DBusMessage *msg, DBusConnection *connection,
|
|
|
7100e8 |
+ void(*done)(DBusPendingCall *pending, void *user_data), void *user_data)
|
|
|
7100e8 |
+{
|
|
|
7100e8 |
+ DBusError error;
|
|
|
7100e8 |
+ const char *method = 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 for %s", method);
|
|
|
7100e8 |
+ return FALSE;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ } else if (pending == NULL) {
|
|
|
7100e8 |
+ crm_err("No pending call found for %s", method);
|
|
|
7100e8 |
+ return FALSE;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ CRM_ASSERT(dbus_pending_call_set_notify(pending, done, user_data, NULL));
|
|
|
7100e8 |
+ return TRUE;
|
|
|
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 |
@@ -147,8 +194,6 @@ bool pcmk_dbus_type_check(DBusMessage *msg, DBusMessageIter *field, int expected
|
|
|
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 |
@@ -160,10 +205,11 @@ pcmk_dbus_get_property(
|
|
|
7100e8 |
/* DBusBasicValue value; */
|
|
|
7100e8 |
const char *method = "GetAll";
|
|
|
7100e8 |
char *output = NULL;
|
|
|
7100e8 |
- char *error = NULL;
|
|
|
7100e8 |
+ DBusError error;
|
|
|
7100e8 |
|
|
|
7100e8 |
/* desc = systemd_unit_property(path, BUS_NAME ".Unit", "Description"); */
|
|
|
7100e8 |
|
|
|
7100e8 |
+ dbus_error_init(&error);
|
|
|
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 |
@@ -180,7 +226,7 @@ pcmk_dbus_get_property(
|
|
|
7100e8 |
reply = pcmk_dbus_send_recv(msg, connection, &error);
|
|
|
7100e8 |
dbus_message_unref(msg);
|
|
|
7100e8 |
|
|
|
7100e8 |
- if(reply == NULL) {
|
|
|
7100e8 |
+ if(error.name) {
|
|
|
7100e8 |
crm_err("Call to %s for %s failed: No reply", method, iface);
|
|
|
7100e8 |
return NULL;
|
|
|
7100e8 |
|
|
|
7100e8 |
@@ -242,20 +288,105 @@ pcmk_dbus_get_property(
|
|
|
7100e8 |
return output;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
+static void pcmk_dbus_connection_dispatch(DBusConnection *connection, DBusDispatchStatus new_status, void *data){
|
|
|
7100e8 |
+ crm_trace("status %d for %p", new_status, data);
|
|
|
7100e8 |
+ if (new_status == DBUS_DISPATCH_DATA_REMAINS){
|
|
|
7100e8 |
+ dbus_connection_dispatch(connection);
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+static int
|
|
|
7100e8 |
+pcmk_dbus_watch_dispatch(gpointer userdata)
|
|
|
7100e8 |
+{
|
|
|
7100e8 |
+ DBusWatch *watch = userdata;
|
|
|
7100e8 |
+ int flags = dbus_watch_get_flags(watch);
|
|
|
7100e8 |
|
|
|
7100e8 |
+ crm_trace("Dispatching %p with flags %d", watch, flags);
|
|
|
7100e8 |
+ if(flags & DBUS_WATCH_READABLE) {
|
|
|
7100e8 |
+ dbus_watch_handle(watch, DBUS_WATCH_READABLE);
|
|
|
7100e8 |
+ } else {
|
|
|
7100e8 |
+ dbus_watch_handle(watch, DBUS_WATCH_ERROR);
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ return 0;
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+static void
|
|
|
7100e8 |
+pcmk_dbus_watch_destroy(gpointer userdata)
|
|
|
7100e8 |
+{
|
|
|
7100e8 |
+ crm_trace("Destroyed %p", userdata);
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
|
|
|
7100e8 |
|
|
|
7100e8 |
+struct mainloop_fd_callbacks pcmk_dbus_cb = {
|
|
|
7100e8 |
+ .dispatch = pcmk_dbus_watch_dispatch,
|
|
|
7100e8 |
+ .destroy = pcmk_dbus_watch_destroy,
|
|
|
7100e8 |
+};
|
|
|
7100e8 |
|
|
|
7100e8 |
-int dbus_watch_get_unix_fd ( DBusWatch * watch );
|
|
|
7100e8 |
+static dbus_bool_t
|
|
|
7100e8 |
+pcmk_dbus_watch_add(DBusWatch *watch, void *data){
|
|
|
7100e8 |
+ int fd = dbus_watch_get_unix_fd(watch);
|
|
|
7100e8 |
|
|
|
7100e8 |
+ mainloop_io_t *client = mainloop_add_fd(
|
|
|
7100e8 |
+ "dbus", G_PRIORITY_DEFAULT, fd, watch, &pcmk_dbus_cb);
|
|
|
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 |
+ crm_trace("Added %p with fd=%d", watch, fd);
|
|
|
7100e8 |
+ dbus_watch_set_data(watch, client, NULL);
|
|
|
7100e8 |
+ return TRUE;
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+static void
|
|
|
7100e8 |
+pcmk_dbus_watch_remove(DBusWatch *watch, void *data){
|
|
|
7100e8 |
+ mainloop_io_t *client = dbus_watch_get_data(watch);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ crm_trace("Removed %p", watch);
|
|
|
7100e8 |
+ mainloop_del_fd(client);
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+static gboolean
|
|
|
7100e8 |
+pcmk_dbus_timeout_dispatch(gpointer data)
|
|
|
7100e8 |
+{
|
|
|
7100e8 |
+ crm_trace("Timeout for %p");
|
|
|
7100e8 |
+ dbus_timeout_handle(data);
|
|
|
7100e8 |
+ return FALSE;
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+static dbus_bool_t
|
|
|
7100e8 |
+pcmk_dbus_timeout_add(DBusTimeout *timeout, void *data){
|
|
|
7100e8 |
+ guint id = g_timeout_add(dbus_timeout_get_interval(timeout), pcmk_dbus_timeout_dispatch, timeout);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if(id) {
|
|
|
7100e8 |
+ dbus_timeout_set_data(timeout, GUINT_TO_POINTER(id), NULL);
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ return TRUE;
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+static void
|
|
|
7100e8 |
+pcmk_dbus_timeout_remove(DBusTimeout *timeout, void *data){
|
|
|
7100e8 |
+ void *vid = dbus_timeout_get_data(timeout);
|
|
|
7100e8 |
+ guint id = GPOINTER_TO_UINT(vid);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if(id) {
|
|
|
7100e8 |
+ g_source_remove(id);
|
|
|
7100e8 |
+ dbus_timeout_set_data(timeout, 0, NULL);
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+static void
|
|
|
7100e8 |
+pcmk_dbus_timeout_toggle(DBusTimeout *timeout, void *data){
|
|
|
7100e8 |
+ if(dbus_timeout_get_enabled(timeout)) {
|
|
|
7100e8 |
+ pcmk_dbus_timeout_add(timeout, data);
|
|
|
7100e8 |
+ } else {
|
|
|
7100e8 |
+ pcmk_dbus_timeout_remove(timeout, data);
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+/* Inspired by http://www.kolej.mff.cuni.cz/~vesej3am/devel/dbus-select.c */
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+void pcmk_dbus_connection_setup_with_select(DBusConnection *c){
|
|
|
7100e8 |
+ dbus_connection_set_timeout_functions(
|
|
|
7100e8 |
+ c, pcmk_dbus_timeout_add, pcmk_dbus_timeout_remove, pcmk_dbus_timeout_toggle, NULL, NULL);
|
|
|
7100e8 |
+ dbus_connection_set_watch_functions(c, pcmk_dbus_watch_add, pcmk_dbus_watch_remove, NULL, NULL, NULL);
|
|
|
7100e8 |
+ dbus_connection_set_dispatch_status_function(c, pcmk_dbus_connection_dispatch, NULL, NULL);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ pcmk_dbus_connection_dispatch(c, dbus_connection_get_dispatch_status(c), NULL);
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
diff --git a/lib/services/pcmk-dbus.h b/lib/services/pcmk-dbus.h
|
|
|
7100e8 |
index 27ac737..c8d2234 100644
|
|
|
7100e8 |
--- a/lib/services/pcmk-dbus.h
|
|
|
7100e8 |
+++ b/lib/services/pcmk-dbus.h
|
|
|
7100e8 |
@@ -1,7 +1,13 @@
|
|
|
7100e8 |
DBusConnection *pcmk_dbus_connect(void);
|
|
|
7100e8 |
+void pcmk_dbus_connection_setup_with_select(DBusConnection *c);
|
|
|
7100e8 |
void pcmk_dbus_disconnect(DBusConnection *connection);
|
|
|
7100e8 |
|
|
|
7100e8 |
-DBusMessage *pcmk_dbus_send_recv(DBusMessage *msg, DBusConnection *connection, char **error);
|
|
|
7100e8 |
+bool pcmk_dbus_send(DBusMessage *msg, DBusConnection *connection,
|
|
|
7100e8 |
+ void(*done)(DBusPendingCall *pending, void *user_data), void *user_data);
|
|
|
7100e8 |
+DBusMessage *pcmk_dbus_send_recv(DBusMessage *msg, DBusConnection *connection, DBusError *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 |
+
|
|
|
7100e8 |
+bool pcmk_dbus_find_error(const char *method, DBusPendingCall* pending, DBusMessage *reply, DBusError *error);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
diff --git a/lib/services/systemd.c b/lib/services/systemd.c
|
|
|
7100e8 |
index 9aa5b03..a06d547 100644
|
|
|
7100e8 |
--- a/lib/services/systemd.c
|
|
|
7100e8 |
+++ b/lib/services/systemd.c
|
|
|
7100e8 |
@@ -69,6 +69,7 @@ systemd_init(void)
|
|
|
7100e8 |
if (need_init) {
|
|
|
7100e8 |
need_init = 0;
|
|
|
7100e8 |
systemd_proxy = pcmk_dbus_connect();
|
|
|
7100e8 |
+ pcmk_dbus_connection_setup_with_select(systemd_proxy);
|
|
|
7100e8 |
}
|
|
|
7100e8 |
if (systemd_proxy == NULL) {
|
|
|
7100e8 |
return FALSE;
|
|
|
7100e8 |
@@ -122,7 +123,7 @@ systemd_unit_by_name(const gchar * arg_name, gchar ** out_unit)
|
|
|
7100e8 |
DBusMessage *reply = NULL;
|
|
|
7100e8 |
const char *method = "GetUnit";
|
|
|
7100e8 |
char *name = NULL;
|
|
|
7100e8 |
- char *error = NULL;
|
|
|
7100e8 |
+ DBusError error;
|
|
|
7100e8 |
|
|
|
7100e8 |
/*
|
|
|
7100e8 |
<method name="GetUnit">
|
|
|
7100e8 |
@@ -144,13 +145,12 @@ systemd_unit_by_name(const gchar * arg_name, gchar ** out_unit)
|
|
|
7100e8 |
|
|
|
7100e8 |
pcmk_dbus_append_arg(msg, DBUS_TYPE_STRING, &name);
|
|
|
7100e8 |
|
|
|
7100e8 |
+ dbus_error_init(&error);
|
|
|
7100e8 |
reply = pcmk_dbus_send_recv(msg, systemd_proxy, &error);
|
|
|
7100e8 |
dbus_message_unref(msg);
|
|
|
7100e8 |
|
|
|
7100e8 |
- if(error) {
|
|
|
7100e8 |
- crm_info("Call to %s failed: %s", method, error);
|
|
|
7100e8 |
- free(error);
|
|
|
7100e8 |
- error = NULL;
|
|
|
7100e8 |
+ if(error.name) {
|
|
|
7100e8 |
+ crm_info("Call to %s failed: %s", method, error.name);
|
|
|
7100e8 |
|
|
|
7100e8 |
} else if (dbus_message_iter_init(reply, &args)) {
|
|
|
7100e8 |
|
|
|
7100e8 |
@@ -192,7 +192,7 @@ systemd_unit_listall(void)
|
|
|
7100e8 |
DBusMessage *msg = NULL;
|
|
|
7100e8 |
DBusMessage *reply = NULL;
|
|
|
7100e8 |
const char *method = "ListUnits";
|
|
|
7100e8 |
- char *error = NULL;
|
|
|
7100e8 |
+ DBusError error;
|
|
|
7100e8 |
|
|
|
7100e8 |
if (systemd_init() == FALSE) {
|
|
|
7100e8 |
return NULL;
|
|
|
7100e8 |
@@ -204,15 +204,15 @@ systemd_unit_listall(void)
|
|
|
7100e8 |
" </method>\n" \
|
|
|
7100e8 |
*/
|
|
|
7100e8 |
|
|
|
7100e8 |
+ dbus_error_init(&error);
|
|
|
7100e8 |
msg = systemd_new_method(BUS_NAME".Manager", method);
|
|
|
7100e8 |
CRM_ASSERT(msg != NULL);
|
|
|
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 |
+ if(error.name) {
|
|
|
7100e8 |
+ crm_err("Call to %s failed: %s", method, error.name);
|
|
|
7100e8 |
return NULL;
|
|
|
7100e8 |
|
|
|
7100e8 |
} else if (!dbus_message_iter_init(reply, &args)) {
|
|
|
7100e8 |
@@ -318,64 +318,84 @@ systemd_unit_metadata(const char *name)
|
|
|
7100e8 |
return meta;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
-#if 0
|
|
|
7100e8 |
+static bool
|
|
|
7100e8 |
+systemd_mask_error(svc_action_t *op, const char *error)
|
|
|
7100e8 |
+{
|
|
|
7100e8 |
+ crm_trace("Could not issue %s for %s: %s", op->action, op->rsc, error);
|
|
|
7100e8 |
+ if(strstr(error, "org.freedesktop.systemd1.InvalidName")
|
|
|
7100e8 |
+ || strstr(error, "org.freedesktop.systemd1.LoadFailed")
|
|
|
7100e8 |
+ || strstr(error, "org.freedesktop.systemd1.NoSuchUnit")) {
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if (safe_str_eq(op->action, "stop")) {
|
|
|
7100e8 |
+ crm_trace("Masking %s failure for %s: unknown services are stopped", op->action, op->rsc);
|
|
|
7100e8 |
+ op->rc = PCMK_OCF_OK;
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ } else {
|
|
|
7100e8 |
+ crm_trace("Mapping %s failure for %s: unknown services are not installed", op->action, op->rsc);
|
|
|
7100e8 |
+ op->rc = PCMK_OCF_NOT_INSTALLED;
|
|
|
7100e8 |
+ op->status = PCMK_LRM_OP_NOT_INSTALLED;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ return TRUE;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ return FALSE;
|
|
|
7100e8 |
+}
|
|
|
7100e8 |
+
|
|
|
7100e8 |
static void
|
|
|
7100e8 |
-systemd_unit_exec_done(GObject * source_object, GAsyncResult * res, gpointer user_data)
|
|
|
7100e8 |
+systemd_async_dispatch(DBusPendingCall *pending, void *user_data)
|
|
|
7100e8 |
{
|
|
|
7100e8 |
- GError *error = NULL;
|
|
|
7100e8 |
- GVariant *_ret = NULL;
|
|
|
7100e8 |
+ DBusError error;
|
|
|
7100e8 |
+ DBusMessage *reply = NULL;
|
|
|
7100e8 |
svc_action_t *op = user_data;
|
|
|
7100e8 |
- GDBusProxy *proxy = G_DBUS_PROXY(source_object);
|
|
|
7100e8 |
|
|
|
7100e8 |
- /* Obtain rc and stderr/out */
|
|
|
7100e8 |
- _ret = g_dbus_proxy_call_finish(proxy, res, &error);
|
|
|
7100e8 |
+ dbus_error_init(&error);
|
|
|
7100e8 |
+ if(pending) {
|
|
|
7100e8 |
+ reply = dbus_pending_call_steal_reply(pending);
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ if(pcmk_dbus_find_error(op->action, pending, reply, &error)) {
|
|
|
7100e8 |
|
|
|
7100e8 |
- if (error) {
|
|
|
7100e8 |
/* ignore "already started" or "not running" errors */
|
|
|
7100e8 |
- crm_trace("Could not issue %s for %s: %s", op->action, op->rsc, error->message);
|
|
|
7100e8 |
- if (strstr(error->message, "systemd1.LoadFailed")
|
|
|
7100e8 |
- || strstr(error->message, "systemd1.InvalidName")) {
|
|
|
7100e8 |
+ if (!systemd_mask_error(op, error.name)) {
|
|
|
7100e8 |
+ crm_err("%s for %s: %s", op->action, op->rsc, error.message);
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
|
|
|
7100e8 |
- if (safe_str_eq(op->action, "stop")) {
|
|
|
7100e8 |
- crm_trace("Masking Stop failure for %s: unknown services are stopped", op->rsc);
|
|
|
7100e8 |
- op->rc = PCMK_OCF_OK;
|
|
|
7100e8 |
+ } else {
|
|
|
7100e8 |
+ DBusMessageIter args;
|
|
|
7100e8 |
|
|
|
7100e8 |
- } else {
|
|
|
7100e8 |
- op->rc = PCMK_OCF_NOT_INSTALLED;
|
|
|
7100e8 |
- op->status = PCMK_LRM_OP_NOT_INSTALLED;
|
|
|
7100e8 |
- }
|
|
|
7100e8 |
+ if(!dbus_message_iter_init(reply, &args)) {
|
|
|
7100e8 |
+ crm_err("Call to %s failed: no arguments", op->action);
|
|
|
7100e8 |
|
|
|
7100e8 |
- } else {
|
|
|
7100e8 |
- crm_err("Could not issue %s for %s: %s", op->action, op->rsc, error->message);
|
|
|
7100e8 |
- }
|
|
|
7100e8 |
- g_error_free(error);
|
|
|
7100e8 |
-
|
|
|
7100e8 |
- } else if(g_variant_is_of_type (_ret, G_VARIANT_TYPE("(o)"))) {
|
|
|
7100e8 |
- char *path = NULL;
|
|
|
7100e8 |
+ } else if(!pcmk_dbus_type_check(reply, &args, DBUS_TYPE_OBJECT_PATH, __FUNCTION__, __LINE__)) {
|
|
|
7100e8 |
+ crm_warn("Call to %s passed but return type was unexpected", op->action);
|
|
|
7100e8 |
+ op->rc = PCMK_OCF_OK;
|
|
|
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 |
+ } else {
|
|
|
7100e8 |
+ const char *path = NULL;
|
|
|
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 |
- op->rc = PCMK_OCF_OK;
|
|
|
7100e8 |
+ dbus_message_get_args (reply, NULL,
|
|
|
7100e8 |
+ DBUS_TYPE_OBJECT_PATH, &path,
|
|
|
7100e8 |
+ DBUS_TYPE_INVALID);
|
|
|
7100e8 |
+ crm_info("Call to %s passed: %s", op->action, path);
|
|
|
7100e8 |
+ op->rc = PCMK_OCF_OK;
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
operation_finalize(op);
|
|
|
7100e8 |
- if (_ret) {
|
|
|
7100e8 |
- g_variant_unref(_ret);
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ if(pending) {
|
|
|
7100e8 |
+ dbus_pending_call_unref(pending);
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+ if(reply) {
|
|
|
7100e8 |
+ dbus_message_unref(reply);
|
|
|
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 |
+ DBusError error;
|
|
|
7100e8 |
char *unit = NULL;
|
|
|
7100e8 |
const char *replace_s = "replace";
|
|
|
7100e8 |
gboolean pass = FALSE;
|
|
|
7100e8 |
@@ -384,7 +404,8 @@ systemd_unit_exec(svc_action_t * op, gboolean synchronous)
|
|
|
7100e8 |
DBusMessage *msg = NULL;
|
|
|
7100e8 |
DBusMessage *reply = NULL;
|
|
|
7100e8 |
DBusMessageIter args;
|
|
|
7100e8 |
-
|
|
|
7100e8 |
+
|
|
|
7100e8 |
+ dbus_error_init(&error);
|
|
|
7100e8 |
op->rc = PCMK_OCF_UNKNOWN_ERROR;
|
|
|
7100e8 |
CRM_ASSERT(systemd_init());
|
|
|
7100e8 |
|
|
|
7100e8 |
@@ -465,16 +486,6 @@ systemd_unit_exec(svc_action_t * op, gboolean synchronous)
|
|
|
7100e8 |
|
|
|
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, 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 |
msg = systemd_new_method(BUS_NAME".Manager", method);
|
|
|
7100e8 |
CRM_ASSERT(msg != NULL);
|
|
|
7100e8 |
|
|
|
7100e8 |
@@ -482,43 +493,47 @@ systemd_unit_exec(svc_action_t * op, gboolean synchronous)
|
|
|
7100e8 |
pcmk_dbus_append_arg(msg, DBUS_TYPE_STRING, &name);
|
|
|
7100e8 |
pcmk_dbus_append_arg(msg, DBUS_TYPE_STRING, &replace_s);
|
|
|
7100e8 |
|
|
|
7100e8 |
+ if (synchronous == FALSE) {
|
|
|
7100e8 |
+ free(unit);
|
|
|
7100e8 |
+ free(name);
|
|
|
7100e8 |
+ return pcmk_dbus_send(msg, systemd_proxy, systemd_async_dispatch, op);
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
reply = pcmk_dbus_send_recv(msg, systemd_proxy, &error);
|
|
|
7100e8 |
- dbus_message_unref(msg);
|
|
|
7100e8 |
|
|
|
7100e8 |
- if(error) {
|
|
|
7100e8 |
+ if(error.name) {
|
|
|
7100e8 |
/* ignore "already started" or "not running" errors */
|
|
|
7100e8 |
- if (safe_str_eq(op->action, "stop")
|
|
|
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)", method, op->rsc, error, unit);
|
|
|
7100e8 |
+ if(!systemd_mask_error(op, error.name)) {
|
|
|
7100e8 |
+ crm_err("Could not issue %s for %s: %s (%s)", method, op->rsc, error.name, unit);
|
|
|
7100e8 |
}
|
|
|
7100e8 |
goto cleanup;
|
|
|
7100e8 |
|
|
|
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 |
- /* (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 |
+ } else if(!pcmk_dbus_type_check(reply, &args, DBUS_TYPE_OBJECT_PATH, __FUNCTION__, __LINE__)) {
|
|
|
7100e8 |
+ crm_warn("Call to %s passed but return type was unexpected", op->action);
|
|
|
7100e8 |
+ op->rc = PCMK_OCF_OK;
|
|
|
7100e8 |
|
|
|
7100e8 |
} else {
|
|
|
7100e8 |
- DBusBasicValue value;
|
|
|
7100e8 |
+ const char *path = NULL;
|
|
|
7100e8 |
|
|
|
7100e8 |
- dbus_message_iter_get_basic(&args, &value);
|
|
|
7100e8 |
- crm_info("Call to %s passed: %s", op->action, value.str);
|
|
|
7100e8 |
+ dbus_message_get_args (reply, NULL,
|
|
|
7100e8 |
+ DBUS_TYPE_OBJECT_PATH, &path,
|
|
|
7100e8 |
+ DBUS_TYPE_INVALID);
|
|
|
7100e8 |
+ crm_info("Call to %s passed: %s", op->action, path);
|
|
|
7100e8 |
op->rc = PCMK_OCF_OK;
|
|
|
7100e8 |
}
|
|
|
7100e8 |
|
|
|
7100e8 |
cleanup:
|
|
|
7100e8 |
- free(error);
|
|
|
7100e8 |
free(unit);
|
|
|
7100e8 |
free(name);
|
|
|
7100e8 |
|
|
|
7100e8 |
+ if(msg) {
|
|
|
7100e8 |
+ dbus_message_unref(msg);
|
|
|
7100e8 |
+ }
|
|
|
7100e8 |
+
|
|
|
7100e8 |
if(reply) {
|
|
|
7100e8 |
dbus_message_unref(reply);
|
|
|
7100e8 |
}
|