X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flogin%2Ftest-inhibit.c;h=a3cf9d293b4d5c1b39040d5f50a7da6e66a1b6a6;hp=70b8314e3f8481d47600804891e89e38c5d56ef7;hb=3388ec3d75fe3000f63514d118a5783ccee0bb3d;hpb=997d4ae7f2d59c2f624f0856e70d448c4f98bc96 diff --git a/src/login/test-inhibit.c b/src/login/test-inhibit.c index 70b8314e3..a3cf9d293 100644 --- a/src/login/test-inhibit.c +++ b/src/login/test-inhibit.c @@ -1,5 +1,3 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - /*** This file is part of systemd. @@ -21,15 +19,16 @@ #include -#include "macro.h" -#include "util.h" #include "sd-bus.h" + #include "bus-util.h" -#include "bus-error.h" +#include "fd-util.h" +#include "macro.h" +#include "util.h" static int inhibit(sd_bus *bus, const char *what) { - _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; const char *who = "Test Tool", *reason = "Just because!", *mode = "block"; int fd; int r; @@ -42,18 +41,18 @@ static int inhibit(sd_bus *bus, const char *what) { &error, &reply, "ssss", what, who, reason, mode); - assert(r >= 0); + assert_se(r >= 0); r = sd_bus_message_read_basic(reply, SD_BUS_TYPE_UNIX_FD, &fd); - assert(r >= 0); - assert(fd >= 0); + assert_se(r >= 0); + assert_se(fd >= 0); return dup(fd); } static void print_inhibitors(sd_bus *bus) { - _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; const char *what, *who, *why, *mode; uint32_t uid, pid; unsigned n = 0; @@ -67,45 +66,45 @@ static void print_inhibitors(sd_bus *bus) { &error, &reply, ""); - assert(r >= 0); + assert_se(r >= 0); r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssssuu)"); - assert(r >= 0); + assert_se(r >= 0); while ((r = sd_bus_message_read(reply, "(ssssuu)", &what, &who, &why, &mode, &uid, &pid)) > 0) { - printf("what=<%s> who=<%s> why=<%s> mode=<%s> uid=<%lu> pid=<%lu>\n", - what, who, why, mode, (unsigned long) uid, (unsigned long) pid); + printf("what=<%s> who=<%s> why=<%s> mode=<%s> uid=<%"PRIu32"> pid=<%"PRIu32">\n", + what, who, why, mode, uid, pid); n++; } - assert(r >= 0); + assert_se(r >= 0); printf("%u inhibitors\n", n); } int main(int argc, char*argv[]) { - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL; int fd1, fd2; int r; r = sd_bus_open_system(&bus); - assert(r >= 0); + assert_se(r >= 0); print_inhibitors(bus); fd1 = inhibit(bus, "sleep"); - assert(fd1 >= 0); + assert_se(fd1 >= 0); print_inhibitors(bus); fd2 = inhibit(bus, "idle:shutdown"); - assert(fd2 >= 0); + assert_se(fd2 >= 0); print_inhibitors(bus); - close_nointr_nofail(fd1); + safe_close(fd1); sleep(1); print_inhibitors(bus); - close_nointr_nofail(fd2); + safe_close(fd2); sleep(1); print_inhibitors(bus);