- "ListInhibitors");
- if (!m)
- return -ENOMEM;
-
- reply = dbus_connection_send_with_reply_and_block(bus, m, -1, error);
- if (!reply) {
- r = -EIO;
- goto finish;
- }
-
- if (!dbus_message_iter_init(reply, &iter)) {
- r = -ENOMEM;
- goto finish;
- }
-
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
- r = -EIO;
- goto finish;
- }
- dbus_message_iter_recurse(&iter, &sub);
-
- printf("%-21s %-20s %-20s %-5s %6s %6s\n",
- "WHAT",
- "WHO",
- "WHY",
- "MODE",
- "UID",
- "PID");
-
-
- while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
- const char *what, *who, *why, *mode;
- char *ewho, *ewhy;
- dbus_uint32_t uid, pid;
-
- if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) {
- r = -EIO;
- goto finish;
- }
-
- dbus_message_iter_recurse(&sub, &sub2);
-
- if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &what, true) < 0 ||
- bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &who, true) < 0 ||
- bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &why, true) < 0 ||
- bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &mode, true) < 0 ||
- bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_UINT32, &uid, true) < 0 ||
- bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_UINT32, &pid, false) < 0) {
- r = -EIO;
- goto finish;
- }
-
- ewho = ellipsize(who, 20, 66);
- ewhy = ellipsize(why, 20, 66);
-
- printf("%-21s %-20s %-20s %-5s %6lu %6lu\n",
- what, ewho ? ewho : who, ewhy ? ewhy : why, mode, (unsigned long) uid, (unsigned long) pid);
-
- free(ewho);
- free(ewhy);
-
- dbus_message_iter_next(&sub);
+ "ListInhibitors",
+ error,
+ &reply,
+ "");
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssssuu)");
+ if (r < 0)
+ return bus_log_parse_error(r);
+
+ while ((r = sd_bus_message_read(reply, "(ssssuu)", &what, &who, &why, &mode, &uid, &pid)) > 0) {
+ _cleanup_free_ char *comm = NULL, *u = NULL;
+
+ get_process_comm(pid, &comm);
+ u = uid_to_name(uid);
+
+ printf(" Who: %s (UID %lu/%s, PID %lu/%s)\n"
+ " What: %s\n"
+ " Why: %s\n"
+ " Mode: %s\n\n",
+ who, (unsigned long) uid, strna(u), (unsigned long) pid, strna(comm),
+ what,
+ why,
+ mode);