From a6e016af0106d4204ec4718ecfdc137355656241 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 7 Oct 2022 15:28:05 +0200 Subject: [PATCH] tree-wide: use STRERROR() --- src/journal/journalctl.c | 2 +- src/libsystemd/sd-bus/test-bus-error.c | 2 +- src/test/test-calendarspec.c | 8 ++++---- src/test/test-path-util.c | 16 ++++++++-------- src/test/test-sleep.c | 8 ++++---- src/test/test-tmpfile-util.c | 12 +++++++++--- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index f0d28fd48bf..11de07fcfa1 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -1460,7 +1460,7 @@ static int add_boot(sd_journal *j) { r = get_boots(j, NULL, &boot_id, arg_boot_offset); assert(r <= 1); if (r <= 0) { - const char *reason = (r == 0) ? "No such boot ID in journal" : strerror_safe(r); + const char *reason = (r == 0) ? "No such boot ID in journal" : STRERROR(r); if (sd_id128_is_null(arg_boot_id)) log_error("Data from the specified boot (%+i) is not available: %s", diff --git a/src/libsystemd/sd-bus/test-bus-error.c b/src/libsystemd/sd-bus/test-bus-error.c index cc59de12b4d..a55f3f9856a 100644 --- a/src/libsystemd/sd-bus/test-bus-error.c +++ b/src/libsystemd/sd-bus/test-bus-error.c @@ -99,7 +99,7 @@ TEST(error) { assert_se(!sd_bus_error_is_set(&error)); assert_se(sd_bus_error_set_errno(&error, EBUSY) == -EBUSY); assert_se(streq(error.name, "System.Error.EBUSY")); - assert_se(streq(error.message, strerror_safe(EBUSY))); + assert_se(streq(error.message, STRERROR(EBUSY))); assert_se(sd_bus_error_has_name(&error, "System.Error.EBUSY")); assert_se(sd_bus_error_get_errno(&error) == EBUSY); assert_se(sd_bus_error_is_set(&error)); diff --git a/src/test/test-calendarspec.c b/src/test/test-calendarspec.c index 8a0684ed669..564983b6992 100644 --- a/src/test/test-calendarspec.c +++ b/src/test/test-calendarspec.c @@ -27,7 +27,7 @@ static void _test_one(int line, const char *input, const char *output) { u = now(CLOCK_REALTIME); r = calendar_spec_next_usec(c, u, &u); - log_info("Next: %s", r < 0 ? strerror_safe(r) : FORMAT_TIMESTAMP(u)); + log_info("Next: %s", r < 0 ? STRERROR(r) : FORMAT_TIMESTAMP(u)); calendar_spec_free(c); assert_se(calendar_spec_from_string(p, &c) >= 0); @@ -60,7 +60,7 @@ static void _test_next(int line, const char *input, const char *new_tz, usec_t a u = after; r = calendar_spec_next_usec(c, after, &u); - log_info("At: %s", r < 0 ? strerror_safe(r) : FORMAT_TIMESTAMP_STYLE(u, TIMESTAMP_US)); + log_info("At: %s", r < 0 ? STRERROR(r) : FORMAT_TIMESTAMP_STYLE(u, TIMESTAMP_US)); if (expect != USEC_INFINITY) assert_se(r >= 0 && u == expect); else @@ -104,10 +104,10 @@ TEST(hourly_bug_4031) { assert_se((r = calendar_spec_next_usec(c, n, &u)) >= 0); log_info("Now: %s (%"PRIu64")", FORMAT_TIMESTAMP_STYLE(n, TIMESTAMP_US), n); - log_info("Next hourly: %s (%"PRIu64")", r < 0 ? strerror_safe(r) : FORMAT_TIMESTAMP_STYLE(u, TIMESTAMP_US), u); + log_info("Next hourly: %s (%"PRIu64")", r < 0 ? STRERROR(r) : FORMAT_TIMESTAMP_STYLE(u, TIMESTAMP_US), u); assert_se((r = calendar_spec_next_usec(c, u, &w)) >= 0); - log_info("Next hourly: %s (%"PRIu64")", r < 0 ? strerror_safe(r) : FORMAT_TIMESTAMP_STYLE(w, TIMESTAMP_US), w); + log_info("Next hourly: %s (%"PRIu64")", r < 0 ? STRERROR(r) : FORMAT_TIMESTAMP_STYLE(w, TIMESTAMP_US), w); assert_se(n < u); assert_se(u <= n + USEC_PER_HOUR); diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index e3fcbd45136..f3987619826 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -806,10 +806,10 @@ static void test_path_extract_filename_one(const char *input, const char *output int r; r = path_extract_filename(input, &k); - log_info_errno(r, "%s → %s/%m [expected: %s/%s]", - strnull(input), - strnull(k), /* strerror(r) is printed via %m, to avoid that the two strerror()'s overwrite each other's buffers */ - strnull(output), ret < 0 ? strerror_safe(ret) : "-"); + log_info("%s → %s/%s [expected: %s/%s]", + strnull(input), + strnull(k), r < 0 ? STRERROR(r) : "-", + strnull(output), ret < 0 ? STRERROR(ret) : "-"); assert_se(streq_ptr(k, output)); assert_se(r == ret); } @@ -850,10 +850,10 @@ static void test_path_extract_directory_one(const char *input, const char *outpu int r; r = path_extract_directory(input, &k); - log_info_errno(r, "%s → %s/%m [expected: %s/%s]", - strnull(input), - strnull(k), /* we output strerror_safe(r) via %m here, since otherwise the error buffer might be overwritten twice */ - strnull(output), strerror_safe(ret)); + log_info("%s → %s/%s [expected: %s/%s]", + strnull(input), + strnull(k), r < 0 ? STRERROR(r) : "-", + strnull(output), STRERROR(ret)); assert_se(streq_ptr(k, output)); assert_se(r == ret); diff --git a/src/test/test-sleep.c b/src/test/test-sleep.c index 6bac115f717..799e93dcedc 100644 --- a/src/test/test-sleep.c +++ b/src/test/test-sleep.c @@ -109,13 +109,13 @@ TEST(sleep) { log_info("/= high-level sleep verbs =/"); r = can_sleep(SLEEP_SUSPEND); - log_info("Suspend configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r)); + log_info("Suspend configured and possible: %s", r >= 0 ? yes_no(r) : STRERROR(r)); r = can_sleep(SLEEP_HIBERNATE); - log_info("Hibernation configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r)); + log_info("Hibernation configured and possible: %s", r >= 0 ? yes_no(r) : STRERROR(r)); r = can_sleep(SLEEP_HYBRID_SLEEP); - log_info("Hybrid-sleep configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r)); + log_info("Hybrid-sleep configured and possible: %s", r >= 0 ? yes_no(r) : STRERROR(r)); r = can_sleep(SLEEP_SUSPEND_THEN_HIBERNATE); - log_info("Suspend-then-Hibernate configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r)); + log_info("Suspend-then-Hibernate configured and possible: %s", r >= 0 ? yes_no(r) : STRERROR(r)); } static int intro(void) { diff --git a/src/test/test-tmpfile-util.c b/src/test/test-tmpfile-util.c index 002bd461621..415f185a817 100644 --- a/src/test/test-tmpfile-util.c +++ b/src/test/test-tmpfile-util.c @@ -13,7 +13,9 @@ static void test_tempfn_random_one(const char *p, const char *extra, const char int r; r = tempfn_random(p, extra, &s); - log_info_errno(r, "%s+%s → %s vs. %s (%i/%m vs. %i/%s)", p, strna(extra), strna(s), strna(expect), r, ret, strerror_safe(ret)); + log_info("%s+%s → %s vs. %s (%i/%s vs. %i/%s)", + p, strna(extra), strna(s), strna(expect), + r, STRERROR(r), ret, STRERROR(ret)); assert_se(!s == !expect); if (s) { @@ -89,7 +91,9 @@ static void test_tempfn_xxxxxx_one(const char *p, const char *extra, const char int r; r = tempfn_xxxxxx(p, extra, &s); - log_info_errno(r, "%s+%s → %s vs. %s (%i/%m vs. %i/%s)", p, strna(extra), strna(s), strna(expect), r, ret, strerror_safe(ret)); + log_info("%s+%s → %s vs. %s (%i/%s vs. %i/%s)", + p, strna(extra), strna(s), strna(expect), + r, STRERROR(r), ret, STRERROR(ret)); assert_se(!s == !expect); if (s) { @@ -164,7 +168,9 @@ static void test_tempfn_random_child_one(const char *p, const char *extra, const int r; r = tempfn_random_child(p, extra, &s); - log_info_errno(r, "%s+%s → %s vs. %s (%i/%m vs. %i/%s)", p, strna(extra), strna(s), strna(expect), r, ret, strerror_safe(ret)); + log_info_errno(r, "%s+%s → %s vs. %s (%i/%s vs. %i/%s)", + p, strna(extra), strna(s), strna(expect), + r, STRERROR(r), ret, STRERROR(ret)); assert_se(!s == !expect); if (s) { -- 2.47.3