1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-25 23:21:33 +03:00

tree-wide: use STRERROR()

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-10-07 15:28:05 +02:00
parent 2c5d05b3cd
commit a6e016af01
6 changed files with 27 additions and 21 deletions

View File

@ -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",

View File

@ -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));

View File

@ -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);

View File

@ -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);

View File

@ -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) {

View File

@ -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) {