diff options
Diffstat (limited to 'src/systemctl.c')
-rw-r--r-- | src/systemctl.c | 230 |
1 files changed, 0 insertions, 230 deletions
diff --git a/src/systemctl.c b/src/systemctl.c index d94105e93c..9f5ba8a202 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -2692,234 +2692,6 @@ finish: return ret; } -static DBusHandlerResult monitor_filter(DBusConnection *connection, DBusMessage *message, void *data) { - DBusError error; - DBusMessage *m = NULL, *reply = NULL; - - assert(connection); - assert(message); - - dbus_error_init(&error); - - log_debug("Got D-Bus request: %s.%s() on %s", - dbus_message_get_interface(message), - dbus_message_get_member(message), - dbus_message_get_path(message)); - - if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) { - log_error("Warning! D-Bus connection terminated."); - dbus_connection_close(connection); - - } else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Manager", "UnitNew") || - dbus_message_is_signal(message, "org.freedesktop.systemd1.Manager", "UnitRemoved")) { - const char *id, *path; - - if (!dbus_message_get_args(message, &error, - DBUS_TYPE_STRING, &id, - DBUS_TYPE_OBJECT_PATH, &path, - DBUS_TYPE_INVALID)) - log_error("Failed to parse message: %s", bus_error_message(&error)); - else if (streq(dbus_message_get_member(message), "UnitNew")) - printf("Unit %s added.\n", id); - else - printf("Unit %s removed.\n", id); - - } else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Manager", "JobNew")) { - uint32_t id; - const char *path; - - if (!dbus_message_get_args(message, &error, - DBUS_TYPE_UINT32, &id, - DBUS_TYPE_OBJECT_PATH, &path, - DBUS_TYPE_INVALID)) - log_error("Failed to parse message: %s", bus_error_message(&error)); - else - printf("Job %u added.\n", id); - - - } else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Manager", "JobRemoved")) { - uint32_t id; - const char *path, *result; - - if (!dbus_message_get_args(message, &error, - DBUS_TYPE_UINT32, &id, - DBUS_TYPE_OBJECT_PATH, &path, - DBUS_TYPE_STRING, &result, - DBUS_TYPE_INVALID)) - log_error("Failed to parse message: %s", bus_error_message(&error)); - else - printf("Job %u removed (result=%s).\n", id, result); - - - } else if (dbus_message_is_signal(message, "org.freedesktop.DBus.Properties", "PropertiesChanged")) { - - const char *path, *interface, *property = "Id"; - DBusMessageIter iter, sub; - - path = dbus_message_get_path(message); - - if (!dbus_message_get_args(message, &error, - DBUS_TYPE_STRING, &interface, - DBUS_TYPE_INVALID)) { - log_error("Failed to parse message: %s", bus_error_message(&error)); - goto finish; - } - - if (!streq(interface, "org.freedesktop.systemd1.Job") && - !streq(interface, "org.freedesktop.systemd1.Unit")) - goto finish; - - if (!(m = dbus_message_new_method_call( - "org.freedesktop.systemd1", - path, - "org.freedesktop.DBus.Properties", - "Get"))) { - log_error("Could not allocate message."); - goto oom; - } - - if (!dbus_message_append_args(m, - DBUS_TYPE_STRING, &interface, - DBUS_TYPE_STRING, &property, - DBUS_TYPE_INVALID)) { - log_error("Could not append arguments to message."); - goto finish; - } - - if (!(reply = dbus_connection_send_with_reply_and_block(connection, m, -1, &error))) { - log_error("Failed to issue method call: %s", bus_error_message(&error)); - goto finish; - } - - if (!dbus_message_iter_init(reply, &iter) || - dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) { - log_error("Failed to parse reply."); - goto finish; - } - - dbus_message_iter_recurse(&iter, &sub); - - if (streq(interface, "org.freedesktop.systemd1.Unit")) { - const char *id; - - if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRING) { - log_error("Failed to parse reply."); - goto finish; - } - - dbus_message_iter_get_basic(&sub, &id); - printf("Unit %s changed.\n", id); - } else { - uint32_t id; - - if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_UINT32) { - log_error("Failed to parse reply."); - goto finish; - } - - dbus_message_iter_get_basic(&sub, &id); - printf("Job %u changed.\n", id); - } - } - -finish: - if (m) - dbus_message_unref(m); - - if (reply) - dbus_message_unref(reply); - - dbus_error_free(&error); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - -oom: - if (m) - dbus_message_unref(m); - - if (reply) - dbus_message_unref(reply); - - dbus_error_free(&error); - return DBUS_HANDLER_RESULT_NEED_MEMORY; -} - -static int monitor(DBusConnection *bus, char **args, unsigned n) { - DBusMessage *m = NULL, *reply = NULL; - DBusError error; - int r; - - dbus_error_init(&error); - - if (!private_bus) { - dbus_bus_add_match(bus, - "type='signal'," - "sender='org.freedesktop.systemd1'," - "interface='org.freedesktop.systemd1.Manager'," - "path='/org/freedesktop/systemd1'", - &error); - - if (dbus_error_is_set(&error)) { - log_error("Failed to add match: %s", bus_error_message(&error)); - r = -EIO; - goto finish; - } - - dbus_bus_add_match(bus, - "type='signal'," - "sender='org.freedesktop.systemd1'," - "interface='org.freedesktop.DBus.Properties'," - "member='PropertiesChanged'", - &error); - - if (dbus_error_is_set(&error)) { - log_error("Failed to add match: %s", bus_error_message(&error)); - r = -EIO; - goto finish; - } - } - - if (!dbus_connection_add_filter(bus, monitor_filter, NULL, NULL)) { - log_error("Failed to add filter."); - r = -ENOMEM; - goto finish; - } - - if (!(m = dbus_message_new_method_call( - "org.freedesktop.systemd1", - "/org/freedesktop/systemd1", - "org.freedesktop.systemd1.Manager", - "Subscribe"))) { - log_error("Could not allocate message."); - r = -ENOMEM; - goto finish; - } - - if (!(reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error))) { - log_error("Failed to issue method call: %s", bus_error_message(&error)); - r = -EIO; - goto finish; - } - - while (dbus_connection_read_write_dispatch(bus, -1)) - ; - - r = 0; - -finish: - - /* This is slightly dirty, since we don't undo the filter or the matches. */ - - if (m) - dbus_message_unref(m); - - if (reply) - dbus_message_unref(reply); - - dbus_error_free(&error); - - return r; -} - static int dump(DBusConnection *bus, char **args, unsigned n) { DBusMessage *m = NULL, *reply = NULL; DBusError error; @@ -4293,7 +4065,6 @@ static int systemctl_help(void) { " list-jobs List jobs\n" " cancel [JOB...] Cancel all, one, or more jobs\n\n" "Status Commands:\n" - " monitor Monitor unit/job changes\n" " dump Dump server status\n" " dot Dump dependency graph for dot(1)\n\n" "Snapshot Commands:\n" @@ -5208,7 +4979,6 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError { "check", MORE, 2, check_unit }, { "show", MORE, 1, show }, { "status", MORE, 2, show }, - { "monitor", EQUAL, 1, monitor }, { "dump", EQUAL, 1, dump }, { "dot", EQUAL, 1, dot }, { "snapshot", LESS, 2, snapshot }, |