- assert(path);
- assert(new_line);
-
- zero(session_info);
- zero(user_info);
- zero(seat_info);
-
- dbus_error_init(&error);
-
- m = dbus_message_new_method_call(
- "org.freedesktop.login1",
- path,
- "org.freedesktop.DBus.Properties",
- "GetAll");
- if (!m) {
- log_error("Could not allocate message.");
- r = -ENOMEM;
- goto finish;
- }
-
- if (!dbus_message_append_args(m,
- DBUS_TYPE_STRING, &interface,
- DBUS_TYPE_INVALID)) {
- log_error("Could not append arguments to message.");
- r = -ENOMEM;
- goto finish;
- }
-
- reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
- if (!reply) {
- log_error("Failed to issue method call: %s", bus_error_message(&error));
- r = -EIO;
- goto finish;
- }
-
- if (!dbus_message_iter_init(reply, &iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
- dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_DICT_ENTRY) {
- log_error("Failed to parse reply.");
- r = -EIO;
- goto finish;
- }
-
- dbus_message_iter_recurse(&iter, &sub);
-
- if (*new_line)
- printf("\n");
-
- *new_line = true;
-
- while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
- const char *name;
-
- if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_DICT_ENTRY) {
- log_error("Failed to parse reply.");
- r = -EIO;
- goto finish;
- }
-
- dbus_message_iter_recurse(&sub, &sub2);
-
- if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &name, true) < 0) {
- log_error("Failed to parse reply.");
- r = -EIO;
- goto finish;
- }
-
- if (dbus_message_iter_get_arg_type(&sub2) != DBUS_TYPE_VARIANT) {
- log_error("Failed to parse reply.");
- r = -EIO;
- goto finish;
- }
-
- dbus_message_iter_recurse(&sub2, &sub3);
-
- if (show_properties)
- r = print_property(name, &sub3);
- else if (strstr(verb, "session"))
- r = status_property_session(name, &sub3, &session_info);
- else if (strstr(verb, "user"))
- r = status_property_user(name, &sub3, &user_info);
- else
- r = status_property_seat(name, &sub3, &seat_info);
-
- if (r < 0) {
- log_error("Failed to parse reply.");
- r = -EIO;
- goto finish;
- }
-
- dbus_message_iter_next(&sub);
- }
-
- if (!show_properties) {
- if (strstr(verb, "session"))
- print_session_status_info(&session_info);
- else if (strstr(verb, "user"))
- print_user_status_info(&user_info);
- else
- print_seat_status_info(&seat_info);
- }
-
- strv_free(seat_info.sessions);
- strv_free(user_info.sessions);
-
- r = 0;
-
-finish:
- if (m)
- dbus_message_unref(m);
-
- if (reply)
- dbus_message_unref(reply);
-
- dbus_error_free(&error);
-
- return r;
-}
-
-static int show(DBusConnection *bus, char **args, unsigned n) {
- DBusMessage *m = NULL, *reply = NULL;
- int r, ret = 0;
- DBusError error;
- unsigned i;
- bool show_properties, new_line = false;
-
- assert(bus);
- assert(args);
-
- dbus_error_init(&error);
-
- show_properties = !strstr(args[0], "status");
-
- if (show_properties)
- pager_open_if_enabled();
-
- if (show_properties && n <= 1) {
- /* If not argument is specified inspect the manager
- * itself */
-
- ret = show_one(args[0], bus, "/org/freedesktop/login1", show_properties, &new_line);
- goto finish;
- }
-
- for (i = 1; i < n; i++) {
- const char *path = NULL;
-
- if (strstr(args[0], "session")) {
-
- m = dbus_message_new_method_call(
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "GetSession");
- if (!m) {
- log_error("Could not allocate message.");
- ret = -ENOMEM;
- goto finish;
- }
-
- if (!dbus_message_append_args(m,
- DBUS_TYPE_STRING, &args[i],
- DBUS_TYPE_INVALID)) {
- log_error("Could not append arguments to message.");
- ret = -ENOMEM;
- goto finish;
- }
-
- } else if (strstr(args[0], "user")) {
- uid_t uid;
- uint32_t u;
-
- ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL);
- if (ret < 0) {
- log_error("User %s unknown.", args[i]);
- goto finish;
- }
-
- m = dbus_message_new_method_call(
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "GetUser");
- if (!m) {
- log_error("Could not allocate message.");
- ret = -ENOMEM;
- goto finish;
- }
-
- u = (uint32_t) uid;
- if (!dbus_message_append_args(m,
- DBUS_TYPE_UINT32, &u,
- DBUS_TYPE_INVALID)) {
- log_error("Could not append arguments to message.");
- ret = -ENOMEM;
- goto finish;
- }
- } else {
-
- m = dbus_message_new_method_call(
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "GetSeat");
- if (!m) {
- log_error("Could not allocate message.");
- ret = -ENOMEM;
- goto finish;
- }
-
- if (!dbus_message_append_args(m,
- DBUS_TYPE_STRING, &args[i],
- DBUS_TYPE_INVALID)) {
- log_error("Could not append arguments to message.");
- ret = -ENOMEM;
- goto finish;
- }
- }