2 This file is part of systemd.
4 Copyright 2012 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
29 static int inhibit(sd_bus *bus, const char *what) {
30 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
31 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
32 const char *who = "Test Tool", *reason = "Just because!", *mode = "block";
36 r = sd_bus_call_method(bus,
37 "org.freedesktop.login1",
38 "/org/freedesktop/login1",
39 "org.freedesktop.login1.Manager",
43 "ssss", what, who, reason, mode);
46 r = sd_bus_message_read_basic(reply, SD_BUS_TYPE_UNIX_FD, &fd);
53 static void print_inhibitors(sd_bus *bus) {
54 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
55 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
56 const char *what, *who, *why, *mode;
61 r = sd_bus_call_method(bus,
62 "org.freedesktop.login1",
63 "/org/freedesktop/login1",
64 "org.freedesktop.login1.Manager",
71 r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssssuu)");
74 while ((r = sd_bus_message_read(reply, "(ssssuu)", &what, &who, &why, &mode, &uid, &pid)) > 0) {
75 printf("what=<%s> who=<%s> why=<%s> mode=<%s> uid=<%"PRIu32"> pid=<%"PRIu32">\n",
76 what, who, why, mode, uid, pid);
82 printf("%u inhibitors\n", n);
85 int main(int argc, char*argv[]) {
86 _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
90 r = sd_bus_open_system(&bus);
93 print_inhibitors(bus);
95 fd1 = inhibit(bus, "sleep");
97 print_inhibitors(bus);
99 fd2 = inhibit(bus, "idle:shutdown");
101 print_inhibitors(bus);
105 print_inhibitors(bus);
109 print_inhibitors(bus);