From: Lennart Poettering Date: Wed, 19 Sep 2018 17:53:22 +0000 (+0300) Subject: inhibit: normalize when we log about failures to list inhibitors X-Git-Tag: v240~690^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0e6872cdfcfefcee20f566bde25a89b74e55eef3;p=thirdparty%2Fsystemd.git inhibit: normalize when we log about failures to list inhibitors let's print log messages about all types of errors inside of the function, since otherwise we might sometimes log twice about some specific cases. --- diff --git a/src/login/inhibit.c b/src/login/inhibit.c index 1daaa8b450b..b19369aa76d 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -60,7 +60,8 @@ static int inhibit(sd_bus *bus, sd_bus_error *error) { return r; } -static int print_inhibitors(sd_bus *bus, sd_bus_error *error) { +static int print_inhibitors(sd_bus *bus) { + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; const char *what, *who, *why, *mode; unsigned int uid, pid; @@ -75,11 +76,11 @@ static int print_inhibitors(sd_bus *bus, sd_bus_error *error) { "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "ListInhibitors", - error, + &error, &reply, ""); if (r < 0) - return r; + return log_error_errno(r, "Could not get active inhibitors: %s", bus_error_message(&error, r)); r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssssuu)"); if (r < 0) @@ -227,7 +228,6 @@ static int parse_argv(int argc, char *argv[]) { } int main(int argc, char *argv[]) { - _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; int r; @@ -248,14 +248,13 @@ int main(int argc, char *argv[]) { if (arg_action == ACTION_LIST) { - r = print_inhibitors(bus, &error); + r = print_inhibitors(bus); pager_close(); - if (r < 0) { - log_error("Failed to list inhibitors: %s", bus_error_message(&error, -r)); + if (r < 0) return EXIT_FAILURE; - } } else { + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_close_ int fd = -1; _cleanup_free_ char *w = NULL; pid_t pid;