1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2012 Lennart Poettering
15 static int inhibit(sd_bus *bus, const char *what) {
16 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
17 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
18 const char *who = "Test Tool", *reason = "Just because!", *mode = "block";
22 r = sd_bus_call_method(bus,
23 "org.freedesktop.login1",
24 "/org/freedesktop/login1",
25 "org.freedesktop.login1.Manager",
29 "ssss", what, who, reason, mode);
32 r = sd_bus_message_read_basic(reply, SD_BUS_TYPE_UNIX_FD, &fd);
39 static void print_inhibitors(sd_bus *bus) {
40 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
41 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
42 const char *what, *who, *why, *mode;
47 r = sd_bus_call_method(bus,
48 "org.freedesktop.login1",
49 "/org/freedesktop/login1",
50 "org.freedesktop.login1.Manager",
57 r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssssuu)");
60 while ((r = sd_bus_message_read(reply, "(ssssuu)", &what, &who, &why, &mode, &uid, &pid)) > 0) {
61 printf("what=<%s> who=<%s> why=<%s> mode=<%s> uid=<%"PRIu32"> pid=<%"PRIu32">\n",
62 what, who, why, mode, uid, pid);
68 printf("%u inhibitors\n", n);
71 int main(int argc, char*argv[]) {
72 _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
76 r = sd_bus_open_system(&bus);
79 print_inhibitors(bus);
81 fd1 = inhibit(bus, "sleep");
83 print_inhibitors(bus);
85 fd2 = inhibit(bus, "idle:shutdown");
87 print_inhibitors(bus);
91 print_inhibitors(bus);
95 print_inhibitors(bus);