- 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;
- int r;
- const char *text;
-
- dbus_error_init(&error);
-
- if (!(m = dbus_message_new_method_call(
- "org.freedesktop.systemd1",
- "/org/freedesktop/systemd1",
- "org.freedesktop.systemd1.Manager",
- "Dump"))) {
- log_error("Could not allocate message.");
- return -ENOMEM;
- }
-
- 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;
- }
-
- if (!dbus_message_get_args(reply, &error,
- DBUS_TYPE_STRING, &text,
- DBUS_TYPE_INVALID)) {
- log_error("Failed to parse reply: %s", bus_error_message(&error));
- r = -EIO;
- goto finish;
- }
-
- fputs(text, stdout);
-
- r = 0;
-
-finish:
- if (m)
- dbus_message_unref(m);
-
- if (reply)
- dbus_message_unref(reply);
-
- dbus_error_free(&error);
-
- return r;
-}
-
-static int snapshot(DBusConnection *bus, char **args, unsigned n) {
- DBusMessage *m = NULL, *reply = NULL;
- DBusError error;
- int r;
- const char *name = "", *path, *id;
- dbus_bool_t cleanup = FALSE;
- DBusMessageIter iter, sub;
- const char
- *interface = "org.freedesktop.systemd1.Unit",
- *property = "Id";
-
- dbus_error_init(&error);
-
- if (!(m = dbus_message_new_method_call(