1 /* SPDX-License-Identifier: LGPL-2.1+ */
12 static int inhibit(sd_bus *bus, const char *what) {
13 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
14 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
15 const char *who = "Test Tool", *reason = "Just because!", *mode = "block";
19 r = sd_bus_call_method(bus,
20 "org.freedesktop.login1",
21 "/org/freedesktop/login1",
22 "org.freedesktop.login1.Manager",
26 "ssss", what, who, reason, mode);
29 r = sd_bus_message_read_basic(reply, SD_BUS_TYPE_UNIX_FD, &fd);
36 static void print_inhibitors(sd_bus *bus) {
37 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
38 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
39 const char *what, *who, *why, *mode;
44 r = sd_bus_call_method(bus,
45 "org.freedesktop.login1",
46 "/org/freedesktop/login1",
47 "org.freedesktop.login1.Manager",
54 r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssssuu)");
57 while ((r = sd_bus_message_read(reply, "(ssssuu)", &what, &who, &why, &mode, &uid, &pid)) > 0) {
58 printf("what=<%s> who=<%s> why=<%s> mode=<%s> uid=<%"PRIu32"> pid=<%"PRIu32">\n",
59 what, who, why, mode, uid, pid);
65 printf("%u inhibitors\n", n);
68 int main(int argc, char*argv[]) {
69 _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
73 r = sd_bus_open_system(&bus);
76 print_inhibitors(bus);
78 fd1 = inhibit(bus, "sleep");
80 print_inhibitors(bus);
82 fd2 = inhibit(bus, "idle:shutdown");
84 print_inhibitors(bus);
88 print_inhibitors(bus);
92 print_inhibitors(bus);