Merge pull request #5958 from keszybz/explicit-log-errno

Use explicit errno in log calls
This commit is contained in:
Lennart Poettering
2017-05-22 10:12:18 +02:00
committed by GitHub
20 changed files with 172 additions and 69 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ int main(int argc, char* argv[]) {
r = loopback_setup();
if (r < 0)
log_error("loopback: %m");
log_error_errno(r, "loopback: %m");
return r >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
+1 -1
View File
@@ -105,7 +105,7 @@ static int print_gaih_addrtuples(const struct gaih_addrtuple *tuples) {
goto numerical_index;
if (if_indextoname(it->scopeid, ifname) == NULL) {
log_warning("if_indextoname(%d) failed: %m", it->scopeid);
log_warning_errno(errno, "if_indextoname(%d) failed: %m", it->scopeid);
numerical_index:
xsprintf(ifname, "%i", it->scopeid);
};
+69
View File
@@ -395,6 +395,9 @@ static void test_safe_atou16(void) {
r = safe_atou16("junk", &l);
assert_se(r == -EINVAL);
r = safe_atou16("123x", &l);
assert_se(r == -EINVAL);
}
static void test_safe_atoi16(void) {
@@ -425,6 +428,70 @@ static void test_safe_atoi16(void) {
r = safe_atoi16("junk", &l);
assert_se(r == -EINVAL);
r = safe_atoi16("123x", &l);
assert_se(r == -EINVAL);
}
static void test_safe_atou64(void) {
int r;
uint64_t l;
r = safe_atou64("12345", &l);
assert_se(r == 0);
assert_se(l == 12345);
r = safe_atou64(" 12345", &l);
assert_se(r == 0);
assert_se(l == 12345);
r = safe_atou64("18446744073709551617", &l);
assert_se(r == -ERANGE);
r = safe_atou64("-1", &l);
assert_se(r == -ERANGE);
r = safe_atou64(" -1", &l);
assert_se(r == -ERANGE);
r = safe_atou64("junk", &l);
assert_se(r == -EINVAL);
r = safe_atou64("123x", &l);
assert_se(r == -EINVAL);
}
static void test_safe_atoi64(void) {
int r;
int64_t l;
r = safe_atoi64("-12345", &l);
assert_se(r == 0);
assert_se(l == -12345);
r = safe_atoi64(" -12345", &l);
assert_se(r == 0);
assert_se(l == -12345);
r = safe_atoi64("32767", &l);
assert_se(r == 0);
assert_se(l == 32767);
r = safe_atoi64(" 32767", &l);
assert_se(r == 0);
assert_se(l == 32767);
r = safe_atoi64("9223372036854775813", &l);
assert_se(r == -ERANGE);
r = safe_atoi64("-9223372036854775813", &l);
assert_se(r == -ERANGE);
r = safe_atoi64("junk", &l);
assert_se(r == -EINVAL);
r = safe_atoi64("123x", &l);
assert_se(r == -EINVAL);
}
static void test_safe_atod(void) {
@@ -538,6 +605,8 @@ int main(int argc, char *argv[]) {
test_safe_atolli();
test_safe_atou16();
test_safe_atoi16();
test_safe_atou64();
test_safe_atoi64();
test_safe_atod();
test_parse_percent();
test_parse_percent_unbounded();
+38
View File
@@ -273,6 +273,43 @@ static void test_format_timestamp_utc(void) {
test_format_timestamp_utc_one(USEC_INFINITY, NULL);
}
static void test_dual_timestamp_deserialize(void) {
int r;
dual_timestamp t;
r = dual_timestamp_deserialize("1234 5678", &t);
assert_se(r == 0);
assert_se(t.realtime == 1234);
assert_se(t.monotonic == 5678);
r = dual_timestamp_deserialize("1234x 5678", &t);
assert_se(r == -EINVAL);
r = dual_timestamp_deserialize("1234 5678y", &t);
assert_se(r == -EINVAL);
r = dual_timestamp_deserialize("-1234 5678", &t);
assert_se(r == -EINVAL);
r = dual_timestamp_deserialize("1234 -5678", &t);
assert_se(r == -EINVAL);
/* Check that output wasn't modified. */
assert_se(t.realtime == 1234);
assert_se(t.monotonic == 5678);
r = dual_timestamp_deserialize("+123 567", &t);
assert_se(r == 0);
assert_se(t.realtime == 123);
assert_se(t.monotonic == 567);
/* Check that we get "infinity" on overflow. */
r = dual_timestamp_deserialize("18446744073709551617 0", &t);
assert_se(r == 0);
assert_se(t.realtime == USEC_INFINITY);
assert_se(t.monotonic == 0);
}
int main(int argc, char *argv[]) {
uintmax_t x;
@@ -288,6 +325,7 @@ int main(int argc, char *argv[]) {
test_usec_sub();
test_format_timestamp();
test_format_timestamp_utc();
test_dual_timestamp_deserialize();
/* Ensure time_t is signed */
assert_cc((time_t) -1 < (time_t) 1);