]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use ERRNO_NAME almost everywhere
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 29 Jul 2025 15:59:04 +0000 (17:59 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 29 Jul 2025 16:05:20 +0000 (18:05 +0200)
We had errno_to_name() which works for "known" errnos, and returns NULL for
unknown ones, and then ERRNO_NAME which always returns an answer, possibly just
a number as a string, but requires a helper buffer.

It is possible for the kernel to add a new errno. We recently learned that some
architectures define custom errno names. Or for some function to unexpectedly
return a bogus errno value. In almost all cases it's better to print that value
rather than "n/a" or "(null)". So let's use ERRNO_NAME is most error handling
code. Noteably, our code wasn't very good in handling the potential NULL, so
in various places we could print "(null)". Since this is supposed to be used
most of the time, let's shorten the names to ERRNO_NAME/errno_name.

There are a few places where we don't want to use the fallback path, in
particular for D-Bus error names or when saving the error name. Let's rename
errno_to_name() to errno_name_no_fallback() to make the distinction clearer.

22 files changed:
src/basic/errno-list.c
src/basic/errno-list.h
src/core/socket.c
src/home/homed-home.c
src/libsystemd/sd-bus/bus-error.c
src/libsystemd/sd-bus/test-bus-error.c
src/libsystemd/sd-login/test-login.c
src/libsystemd/sd-varlink/sd-varlink.c
src/resolve/resolvectl.c
src/resolve/resolved-dns-transaction.c
src/shared/seccomp-util.c
src/shared/tests.h
src/test/test-bpf-devices.c
src/test/test-bus-unit-util.c
src/test/test-errno-list.c
src/test/test-nss-hosts.c
src/test/test-nss-users.c
src/test/test-process-util.c
src/test/test-stat-util.c
src/udev/udev-error.c
src/udev/udev-worker.c
src/userdb/userdbctl.c

index 8de9888083980ea04ab952a20da0135d3da1d760..a67b6087000ed2807a3e5a1fe3e62d80d15406c3 100644 (file)
@@ -25,8 +25,8 @@ int errno_from_name(const char *name) {
 }
 
 #if HAVE_STRERRORNAME_NP
-const char* errno_to_name(int id) {
-        if (id == 0) /* To stay in line with our own impl */
+const char* errno_name_no_fallback(int id) {
+        if (id == 0) /* To stay in line with our implementation below.  */
                 return NULL;
 
         return strerrorname_np(ABS(id));
@@ -34,7 +34,7 @@ const char* errno_to_name(int id) {
 #else
 #  include "errno-to-name.inc"
 
-const char* errno_to_name(int id) {
+const char* errno_name_no_fallback(int id) {
         if (id < 0)
                 id = -id;
 
@@ -45,8 +45,8 @@ const char* errno_to_name(int id) {
 }
 #endif
 
-const char* errno_name_full(int id, char buf[static ERRNO_NAME_BUF_LEN]) {
-        const char *a = errno_to_name(id);
+const char* errno_name(int id, char buf[static ERRNO_NAME_BUF_LEN]) {
+        const char *a = errno_name_no_fallback(id);
         if (a)
                 return a;
         snprintf(buf, ERRNO_NAME_BUF_LEN, "%d", abs(id));
index 6ce2d75c09a8cec49cfb1a6a01925e201661cce2..2064afa0f4acf04da23751ba64a720e932afa772 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "forward.h"
 
-const char* errno_to_name(int id) _const_;
+const char* errno_name_no_fallback(int id) _const_;
 int errno_from_name(const char *name) _pure_;
 
 static inline bool errno_is_valid(int n) {
@@ -12,7 +12,7 @@ static inline bool errno_is_valid(int n) {
 
 #define ERRNO_NAME_BUF_LEN DECIMAL_STR_MAX(int)
 /* Like errno_name, but always returns a string. */
-const char* errno_name_full(int id, char buf[static ERRNO_NAME_BUF_LEN]);
+const char* errno_name(int id, char buf[static ERRNO_NAME_BUF_LEN]);
 
 /* A helper to print the errno "name" or number if name is not defined. */
-#define ERRNO_NAME_FULL(errnum) errno_name_full(errnum, (char[ERRNO_NAME_BUF_LEN]){})
+#define ERRNO_NAME(errnum) errno_name(errnum, (char[ERRNO_NAME_BUF_LEN]){})
index 34f3e3ea4de917f77cb40cc0981b47f653e5484c..f108d4db8ae2a40cf89d1f3b86591427ab7f6aa6 100644 (file)
@@ -1460,8 +1460,8 @@ int socket_load_service_unit(Socket *s, int cfd, Unit **ret) {
                         /* ENOTCONN is legitimate if TCP RST was received. Other socket families might return
                          * different errors. This connection is over, but the socket unit lives on. */
                         return log_unit_debug_errno(UNIT(s), r,
-                                                    "Got %s on incoming socket, assuming aborted connection attempt, ignoring.",
-                                                    errno_to_name(r));
+                                                    "Got error %s on incoming socket, assuming aborted connection attempt, ignoring.",
+                                                    ERRNO_NAME(r));
                 if (r < 0)
                         return r;
         }
index d8683b82114122533eccf5a087907d842cd26a3e..a359baea591070c054c8bb42b2a30178c6a05446 100644 (file)
@@ -1159,7 +1159,7 @@ static int home_on_worker_process(sd_event_source *s, const siginfo_t *si, void
         } else if (si->si_status != EXIT_SUCCESS) {
                 /* If we received an error code via sd_notify(), use it */
                 if (h->worker_error_code != 0)
-                        ret = log_debug_errno(h->worker_error_code, "Worker reported error code %s.", errno_to_name(h->worker_error_code));
+                        ret = log_debug_errno(h->worker_error_code, "Worker reported error code %s.", ERRNO_NAME(h->worker_error_code));
                 else
                         ret = log_debug_errno(SYNTHETIC_ERRNO(EPROTO), "Worker exited with exit code %i.", si->si_status);
         } else
index cf501c33c9fb0c81cbb5dbd1015d33a2ea993307..e5c9eb64a4ee45ba003a60de6c0bc64239cac84d 100644 (file)
@@ -168,7 +168,11 @@ static int errno_to_bus_error_name_new(int error, char **ret) {
         if (error < 0)
                 error = -error;
 
-        name = errno_to_name(error);
+        /* D-Bus names must not start with a digit. Thus, an name like System.Error.500 would not be legal.
+         * Let's just return 0 if an unknown errno is encountered, which will cause the caller to fall back
+         * to BUS_ERROR_FAILED.
+         */
+        name = errno_name_no_fallback(error);
         if (!name)
                 return 0;
 
index 91045c06c2aebb3e64d0f19c5ccf23e9d24dff9d..c6b86be621dc7c719ef747d964e8c80af3aa618e 100644 (file)
@@ -139,7 +139,7 @@ static int dump_mapping_table(void) {
                         continue;
                 }
 
-                printf("%s -> %i/%s\n", strna(m->name), m->code, strna(errno_to_name(m->code)));
+                printf("%s -> %i/%s\n", strna(m->name), m->code, ERRNO_NAME(m->code));
                 m++;
         }
         printf("---------------------------\n");
index a4ab2659b21e290f25d007c6e741d2b06b2ce79d..98846d1011e0f73c18e08f319d8c279177cacf61 100644 (file)
@@ -36,9 +36,7 @@ static char* format_uids(char **buf, uid_t* uids, int count) {
         return *buf;
 }
 
-static const char *e(int r) {
-        return r == 0 ? "OK" : errno_to_name(r);
-}
+#define e(r) (r == 0 ? "OK" : ERRNO_NAME(r))
 
 TEST(login) {
         _cleanup_close_pair_ int pair[2] = EBADF_PAIR;
index 7679cc11e574ba982c89811b5054c52119806499..1666162e890592c076aea58ad5d2f7cfbbc8d2ba 100644 (file)
@@ -2699,7 +2699,7 @@ _public_ int sd_varlink_error_errno(sd_varlink *v, int error) {
          * open, even to foreign systems. */
 
         error = abs(error);
-        const char *name = errno_to_name(error);
+        const char *name = errno_name_no_fallback(error);
 
         return sd_varlink_errorbo(
                         v,
index 3edf87b321ddca578dbf7db473927aad7e0da7d3..bdfc8230585dae317c292d65323433d11a80e933 100644 (file)
@@ -3146,9 +3146,9 @@ static void monitor_query_dump(sd_json_variant *v) {
                streq_ptr(p.state, "success") ? ansi_highlight_green() : ansi_highlight_red(),
                glyph(GLYPH_ARROW_LEFT),
                ansi_normal(),
-               strna(streq_ptr(p.state, "errno") ? errno_to_name(p.error) :
-                     streq_ptr(p.state, "rcode-failure") ? dns_rcode_to_string(p.rcode) :
-                     p.state));
+               streq_ptr(p.state, "errno") ? ERRNO_NAME(p.error) :
+               streq_ptr(p.state, "rcode-failure") ? strna(dns_rcode_to_string(p.rcode)) :
+               strna(p.state));
 
         if (!isempty(p.result))
                 printf(": %s", p.result);
index 2e183d15fe6d33ccf6aaed37569612df1bca7648..00fbe27e33deeca3ef140dc0a49d789d20299c3a 100644 (file)
@@ -406,7 +406,6 @@ void dns_transaction_complete(DnsTransaction *t, DnsTransactionState state) {
         DnsQueryCandidate *c;
         DnsZoneItem *z;
         DnsTransaction *d;
-        const char *st;
         char key_str[DNS_RESOURCE_KEY_STRING_MAX];
 
         assert(t);
@@ -430,11 +429,6 @@ void dns_transaction_complete(DnsTransaction *t, DnsTransactionState state) {
          * should hence not attempt to access the query or transaction
          * after calling this function. */
 
-        if (state == DNS_TRANSACTION_ERRNO)
-                st = errno_to_name(t->answer_errno);
-        else
-                st = dns_transaction_state_to_string(state);
-
         log_debug("%s transaction %" PRIu16 " for <%s> on scope %s on %s/%s now complete with <%s> from %s (%s; %s).",
                   t->bypass ? "Bypass" : "Regular",
                   t->id,
@@ -442,7 +436,7 @@ void dns_transaction_complete(DnsTransaction *t, DnsTransactionState state) {
                   dns_protocol_to_string(t->scope->protocol),
                   t->scope->link ? t->scope->link->ifname : "*",
                   af_to_name_short(t->scope->family),
-                  st,
+                  state == DNS_TRANSACTION_ERRNO ? ERRNO_NAME(t->answer_errno) : dns_transaction_state_to_string(state),
                   t->answer_source < 0 ? "none" : dns_transaction_source_to_string(t->answer_source),
                   FLAGS_SET(t->query_flags, SD_RESOLVED_NO_VALIDATE) ? "not validated" :
                   (FLAGS_SET(t->answer_query_flags, SD_RESOLVED_AUTHENTICATED) ? "authenticated" : "unsigned"),
index 1925f92e53658bdfe1e283a2dfa9fa6976a9d248..53d18dada5feb35731dbbfab9be7d98be948f1b8 100644 (file)
@@ -2541,5 +2541,5 @@ int seccomp_parse_errno_or_action(const char *p) {
 const char* seccomp_errno_or_action_to_string(int num) {
         if (num == SECCOMP_ERROR_NUMBER_KILL)
                 return "kill";
-        return errno_to_name(num);
+        return errno_name_no_fallback(num);
 }
index ece0503095b58c8b38f8fcad24af4ebff5bdb17f..33304903ba14a7de19abbba26750f64d8473461b 100644 (file)
@@ -174,28 +174,28 @@ _noreturn_ void log_test_failed_internal(const char *file, int line, const char
 #ifdef __COVERITY__
 #  define ASSERT_OK(expr) __coverity_check__((expr) >= 0)
 #else
-#  define ASSERT_OK(expr)                                                                                               \
-        ({                                                                                                              \
-                typeof(expr) _result = (expr);                                                                          \
-                if (_result < 0)                                                                                        \
-                        log_test_failed("Expected \"%s\" to succeed, but got error: %"PRIiMAX"/%s",                     \
-                                        #expr, (intmax_t) _result, ERRNO_NAME_FULL(_result));                           \
+#  define ASSERT_OK(expr)                                                                                       \
+        ({                                                                                                      \
+                typeof(expr) _result = (expr);                                                                  \
+                if (_result < 0)                                                                                \
+                        log_test_failed("Expected \"%s\" to succeed, but got error: %"PRIiMAX"/%s",             \
+                                        #expr, (intmax_t) _result, ERRNO_NAME(_result));                        \
          })
 #endif
 
 #ifdef __COVERITY__
-#  define ASSERT_OK_OR(expr, ...)                                                                                       \
-        ({                                                                                                              \
-                typeof(expr) _result = (expr);                                                                          \
-                __coverity_check__(_result >= 0 || IN_SET(_result, 0, __VA_ARGS__)                                      \
+#  define ASSERT_OK_OR(expr, ...)                                                                               \
+        ({                                                                                                      \
+                typeof(expr) _result = (expr);                                                                  \
+                __coverity_check__(_result >= 0 || IN_SET(_result, 0, __VA_ARGS__)                              \
         })
 #else
-#  define ASSERT_OK_OR(expr, ...)                                                                                       \
-        ({                                                                                                              \
-                typeof(expr) _result = (expr);                                                                          \
-                if (_result < 0 && !IN_SET(_result, 0, __VA_ARGS__))                                                    \
-                        log_test_failed("\"%s\" failed with unexpected error: %"PRIiMAX"/%s",                           \
-                                        #expr, (intmax_t) _result, ERRNO_NAME_FULL(_result));                           \
+#  define ASSERT_OK_OR(expr, ...)                                                                               \
+        ({                                                                                                      \
+                typeof(expr) _result = (expr);                                                                  \
+                if (_result < 0 && !IN_SET(_result, 0, __VA_ARGS__))                                            \
+                        log_test_failed("\"%s\" failed with unexpected error: %"PRIiMAX"/%s",                   \
+                                        #expr, (intmax_t) _result, ERRNO_NAME(_result));                        \
          })
 #endif
 
@@ -203,45 +203,45 @@ _noreturn_ void log_test_failed_internal(const char *file, int line, const char
 #ifdef __COVERITY__
 #  define ASSERT_OK_POSITIVE(expr) __coverity_check__((expr) > 0)
 #else
-#  define ASSERT_OK_POSITIVE(expr)                                                                                      \
-        ({                                                                                                              \
-                typeof(expr) _result = (expr);                                                                          \
-                if (_result < 0)                                                                                        \
-                        log_test_failed("Expected \"%s\" to succeed, but got error: %"PRIiMAX"/%s",                     \
-                                        #expr, (intmax_t) _result, ERRNO_NAME_FULL(_result));                           \
-                if (_result == 0)                                                                                       \
-                        log_test_failed("Expected \"%s\" to be positive, but it is zero.", #expr);                      \
+#  define ASSERT_OK_POSITIVE(expr)                                                                              \
+        ({                                                                                                      \
+                typeof(expr) _result = (expr);                                                                  \
+                if (_result < 0)                                                                                \
+                        log_test_failed("Expected \"%s\" to succeed, but got error: %"PRIiMAX"/%s",             \
+                                        #expr, (intmax_t) _result, ERRNO_NAME(_result));                        \
+                if (_result == 0)                                                                               \
+                        log_test_failed("Expected \"%s\" to be positive, but it is zero.", #expr);              \
          })
 #endif
 
 #ifdef __COVERITY__
 #  define ASSERT_OK_ZERO(expr) __coverity_check__((expr) == 0)
 #else
-#  define ASSERT_OK_ZERO(expr)                                                                                          \
-        ({                                                                                                              \
-                typeof(expr) _result = (expr);                                                                          \
-                if (_result < 0)                                                                                        \
-                        log_test_failed("Expected \"%s\" to succeed, but got error: %"PRIiMAX"/%s",                     \
-                                        #expr, (intmax_t) _result, ERRNO_NAME_FULL(_result));                           \
-                if (_result != 0)                                                                                       \
-                        log_test_failed("Expected \"%s\" to be zero, but it is %"PRIiMAX".",                            \
-                                        #expr, (intmax_t) _result);                                                     \
+#  define ASSERT_OK_ZERO(expr)                                                                                  \
+        ({                                                                                                      \
+                typeof(expr) _result = (expr);                                                                  \
+                if (_result < 0)                                                                                \
+                        log_test_failed("Expected \"%s\" to succeed, but got error: %"PRIiMAX"/%s",             \
+                                        #expr, (intmax_t) _result, ERRNO_NAME(_result));                        \
+                if (_result != 0)                                                                               \
+                        log_test_failed("Expected \"%s\" to be zero, but it is %"PRIiMAX".",                    \
+                                        #expr, (intmax_t) _result);                                             \
          })
 #endif
 
 #ifdef __COVERITY__
 #  define ASSERT_OK_EQ(expr1, expr2) __coverity_check__((expr1) == (expr2))
 #else
-#  define ASSERT_OK_EQ(expr1, expr2)                                                                                    \
-        ({                                                                                                              \
-                typeof(expr1) _expr1 = (expr1);                                                                         \
-                typeof(expr2) _expr2 = (expr2);                                                                         \
-                if (_expr1 < 0)                                                                                         \
-                        log_test_failed("Expected \"%s\" to succeed, but got error: %"PRIiMAX"/%s",                     \
-                                        #expr1, (intmax_t) _expr1, ERRNO_NAME_FULL(_expr1));                            \
-                if (_expr1 != _expr2)                                                                                   \
-                        log_test_failed("Expected \"%s == %s\", got %"PRIiMAX" != %"PRIiMAX,                            \
-                                        #expr1, #expr2, (intmax_t) _expr1, (intmax_t) _expr2);                          \
+#  define ASSERT_OK_EQ(expr1, expr2)                                                                            \
+        ({                                                                                                      \
+                typeof(expr1) _expr1 = (expr1);                                                                 \
+                typeof(expr2) _expr2 = (expr2);                                                                 \
+                if (_expr1 < 0)                                                                                 \
+                        log_test_failed("Expected \"%s\" to succeed, but got error: %"PRIiMAX"/%s",             \
+                                        #expr1, (intmax_t) _expr1, ERRNO_NAME(_expr1));                         \
+                if (_expr1 != _expr2)                                                                           \
+                        log_test_failed("Expected \"%s == %s\", got %"PRIiMAX" != %"PRIiMAX,                    \
+                                        #expr1, #expr2, (intmax_t) _expr1, (intmax_t) _expr2);                  \
         })
 #endif
 
@@ -249,153 +249,153 @@ _noreturn_ void log_test_failed_internal(const char *file, int line, const char
 #ifdef __COVERITY__
 #  define ASSERT_OK_ERRNO(expr) __coverity_check__((expr) >= 0)
 #else
-#  define ASSERT_OK_ERRNO(expr)                                                                                         \
-        ({                                                                                                              \
-                typeof(expr) _result = (expr);                                                                          \
-                if (_result < 0)                                                                                        \
-                        log_test_failed("Expected \"%s\" to succeed, but got errno: %d/%s",                             \
-                                        #expr, errno, ERRNO_NAME_FULL(errno));                                          \
+#  define ASSERT_OK_ERRNO(expr)                                                                                 \
+        ({                                                                                                      \
+                typeof(expr) _result = (expr);                                                                  \
+                if (_result < 0)                                                                                \
+                        log_test_failed("Expected \"%s\" to succeed, but got errno: %d/%s",                     \
+                                        #expr, errno, ERRNO_NAME(errno));                                       \
         })
 #endif
 
 #ifdef __COVERITY__
 #  define ASSERT_OK_ZERO_ERRNO(expr) __coverity_check__((expr) == 0)
 #else
-#  define ASSERT_OK_ZERO_ERRNO(expr)                                                                                    \
-        ({                                                                                                              \
-                typeof(expr) _result = (expr);                                                                          \
-                if (_result < 0)                                                                                        \
-                        log_test_failed("Expected \"%s\" to succeed, but got errno: %d/%s",                             \
-                                        #expr, errno, ERRNO_NAME_FULL(errno));                                          \
-                if (_result != 0)                                                                                       \
-                        log_test_failed("Expected \"%s\" to be zero, but it is %"PRIiMAX".",                            \
-                                        #expr, (intmax_t) _result);                                                     \
+#  define ASSERT_OK_ZERO_ERRNO(expr)                                                                            \
+        ({                                                                                                      \
+                typeof(expr) _result = (expr);                                                                  \
+                if (_result < 0)                                                                                \
+                        log_test_failed("Expected \"%s\" to succeed, but got errno: %d/%s",                     \
+                                        #expr, errno, ERRNO_NAME(errno));                                       \
+                if (_result != 0)                                                                               \
+                        log_test_failed("Expected \"%s\" to be zero, but it is %"PRIiMAX".",                    \
+                                        #expr, (intmax_t) _result);                                             \
         })
 #endif
 
 #ifdef __COVERITY__
 #  define ASSERT_OK_EQ_ERRNO(expr1, expr2) __coverity_check__((expr1) == (expr2))
 #else
-#  define ASSERT_OK_EQ_ERRNO(expr1, expr2)                                                                              \
-        ({                                                                                                              \
-                typeof(expr1) _expr1 = (expr1);                                                                         \
-                typeof(expr2) _expr2 = (expr2);                                                                         \
-                if (_expr1 < 0)                                                                                         \
-                        log_test_failed("Expected \"%s\" to succeed, but got errno: %d/%s",                             \
-                                        #expr1, errno, ERRNO_NAME_FULL(errno));                                         \
-                if (_expr1 != _expr2)                                                                                   \
-                        log_test_failed("Expected \"%s == %s\", but %"PRIiMAX" != %"PRIiMAX,                            \
-                                        #expr1, #expr2, (intmax_t) _expr1, (intmax_t) _expr2);                          \
+#  define ASSERT_OK_EQ_ERRNO(expr1, expr2)                                                                      \
+        ({                                                                                                      \
+                typeof(expr1) _expr1 = (expr1);                                                                 \
+                typeof(expr2) _expr2 = (expr2);                                                                 \
+                if (_expr1 < 0)                                                                                 \
+                        log_test_failed("Expected \"%s\" to succeed, but got errno: %d/%s",                     \
+                                        #expr1, errno, ERRNO_NAME(errno));                                      \
+                if (_expr1 != _expr2)                                                                           \
+                        log_test_failed("Expected \"%s == %s\", but %"PRIiMAX" != %"PRIiMAX,                    \
+                                        #expr1, #expr2, (intmax_t) _expr1, (intmax_t) _expr2);                  \
         })
 #endif
 
 #ifdef __COVERITY__
 #  define ASSERT_FAIL(expr) __coverity_check__((expr) < 0)
 #else
-#  define ASSERT_FAIL(expr)                                                                                             \
-        ({                                                                                                              \
-                typeof(expr) _result = (expr);                                                                          \
-                if (_result >= 0)                                                                                       \
-                        log_test_failed("Expected \"%s\" to fail, but it succeeded.", #expr);                           \
+#  define ASSERT_FAIL(expr)                                                                                     \
+        ({                                                                                                      \
+                typeof(expr) _result = (expr);                                                                  \
+                if (_result >= 0)                                                                               \
+                        log_test_failed("Expected \"%s\" to fail, but it succeeded.", #expr);                   \
         })
 #endif
 
 #ifdef __COVERITY__
 #  define ASSERT_ERROR(expr1, expr2) __coverity_check__((expr1) == -(expr2))
 #else
-#  define ASSERT_ERROR(expr1, expr2)                                                                                    \
-        ({                                                                                                              \
-                int _expr1 = (expr1);                                                                                   \
-                int _expr2 = (expr2);                                                                                   \
-                if (_expr1 >= 0)                                                                                        \
-                        log_test_failed("Expected \"%s\" to fail with error %d/%s, but it succeeded",                   \
-                                        #expr1, -_expr2, ERRNO_NAME_FULL(_expr2));                                      \
-                else if (-_expr1 != _expr2)                                                                             \
-                        log_test_failed("Expected \"%s\" to fail with error %d/%s, but got %d/%s",                      \
-                                        #expr1, -_expr2, ERRNO_NAME_FULL(_expr2), _expr1, ERRNO_NAME_FULL(_expr1));     \
+#  define ASSERT_ERROR(expr1, expr2)                                                                            \
+        ({                                                                                                      \
+                int _expr1 = (expr1);                                                                           \
+                int _expr2 = (expr2);                                                                           \
+                if (_expr1 >= 0)                                                                                \
+                        log_test_failed("Expected \"%s\" to fail with error %d/%s, but it succeeded",           \
+                                        #expr1, -_expr2, ERRNO_NAME(_expr2));                                   \
+                else if (-_expr1 != _expr2)                                                                     \
+                        log_test_failed("Expected \"%s\" to fail with error %d/%s, but got %d/%s",              \
+                                        #expr1, -_expr2, ERRNO_NAME(_expr2), _expr1, ERRNO_NAME(_expr1));       \
         })
 #endif
 
 #ifdef __COVERITY__
 #  define ASSERT_ERROR_ERRNO(expr1, expr2) __coverity_check__((expr1) < 0 && errno == (expr2))
 #else
-#  define ASSERT_ERROR_ERRNO(expr1, expr2)                                                                              \
-        ({                                                                                                              \
-                int _expr1 = (expr1);                                                                                   \
-                int _expr2 = (expr2);                                                                                   \
-                if (_expr1 >= 0)                                                                                        \
-                        log_test_failed("Expected \"%s\" to fail with errno %d/%s, but it succeeded",                   \
-                                        #expr1, _expr2, ERRNO_NAME_FULL(_expr2));                                       \
-                else if (errno != _expr2)                                                                               \
-                        log_test_failed("Expected \"%s\" to fail with errno %d/%s, but got %d/%s",                      \
-                                        #expr1, _expr2, ERRNO_NAME_FULL(_expr2), errno, ERRNO_NAME_FULL(errno));        \
+#  define ASSERT_ERROR_ERRNO(expr1, expr2)                                                                      \
+        ({                                                                                                      \
+                int _expr1 = (expr1);                                                                           \
+                int _expr2 = (expr2);                                                                           \
+                if (_expr1 >= 0)                                                                                \
+                        log_test_failed("Expected \"%s\" to fail with errno %d/%s, but it succeeded",           \
+                                        #expr1, _expr2, ERRNO_NAME(_expr2));                                    \
+                else if (errno != _expr2)                                                                       \
+                        log_test_failed("Expected \"%s\" to fail with errno %d/%s, but got %d/%s",              \
+                                        #expr1, _expr2, ERRNO_NAME(_expr2), errno, ERRNO_NAME(errno));          \
         })
 #endif
 
 #ifdef __COVERITY__
 #  define ASSERT_TRUE(expr) __coverity_check__(!!(expr))
 #else
-#  define ASSERT_TRUE(expr)                                                                                             \
-        ({                                                                                                              \
-                if (!(expr))                                                                                            \
-                        log_test_failed("Expected \"%s\" to be true", #expr);                                           \
+#  define ASSERT_TRUE(expr)                                                                                     \
+        ({                                                                                                      \
+                if (!(expr))                                                                                    \
+                        log_test_failed("Expected \"%s\" to be true", #expr);                                   \
         })
 #endif
 
 #ifdef __COVERITY__
 #  define ASSERT_FALSE(expr) __coverity_check__(!(expr))
 #else
-#  define ASSERT_FALSE(expr)                                                                                            \
-        ({                                                                                                              \
-                if ((expr))                                                                                             \
-                        log_test_failed("Expected \"%s\" to be false", #expr);                                          \
+#  define ASSERT_FALSE(expr)                                                                                    \
+        ({                                                                                                      \
+                if ((expr))                                                                                     \
+                        log_test_failed("Expected \"%s\" to be false", #expr);                                  \
         })
 #endif
 
 #ifdef __COVERITY__
 #  define ASSERT_NULL(expr) __coverity_check__((expr) == NULL)
 #else
-#  define ASSERT_NULL(expr)                                                                                             \
-        ({                                                                                                              \
-                typeof(expr) _result = (expr);                                                                          \
-                if (_result != NULL)                                                                                    \
-                        log_test_failed("Expected \"%s\" to be NULL, got \"%p\" != NULL", #expr, _result);              \
+#  define ASSERT_NULL(expr)                                                                                     \
+        ({                                                                                                      \
+                typeof(expr) _result = (expr);                                                                  \
+                if (_result != NULL)                                                                            \
+                        log_test_failed("Expected \"%s\" to be NULL, got \"%p\" != NULL", #expr, _result);      \
         })
 #endif
 
 #ifdef __COVERITY__
 #  define ASSERT_NOT_NULL(expr) __coverity_check__((expr) != NULL)
 #else
-#  define ASSERT_NOT_NULL(expr)                                                                                         \
-        ({                                                                                                              \
-                typeof(expr) _result = (expr);                                                                          \
-                if (_result == NULL)                                                                                    \
-                        log_test_failed("Expected \"%s\" to be not NULL", #expr);                                       \
-                _result;                                                                                                \
+#  define ASSERT_NOT_NULL(expr)                                                                                 \
+        ({                                                                                                      \
+                typeof(expr) _result = (expr);                                                                  \
+                if (_result == NULL)                                                                            \
+                        log_test_failed("Expected \"%s\" to be not NULL", #expr);                               \
+                _result;                                                                                        \
         })
 #endif
 
 #ifdef __COVERITY__
 #  define ASSERT_STREQ(expr1, expr2) __coverity_check__(streq_ptr((expr1), (expr2)))
 #else
-#  define ASSERT_STREQ(expr1, expr2)                                                                                    \
-        ({                                                                                                              \
-                const char *_expr1 = (expr1), *_expr2 = (expr2);                                                        \
-                if (!streq_ptr(_expr1, _expr2))                                                                         \
-                        log_test_failed("Expected \"%s == %s\", got \"%s != %s\"",                                      \
-                                        #expr1, #expr2, strnull(_expr1), strnull(_expr2));                              \
+#  define ASSERT_STREQ(expr1, expr2)                                                                            \
+        ({                                                                                                      \
+                const char *_expr1 = (expr1), *_expr2 = (expr2);                                                \
+                if (!streq_ptr(_expr1, _expr2))                                                                 \
+                        log_test_failed("Expected \"%s == %s\", got \"%s != %s\"",                              \
+                                        #expr1, #expr2, strnull(_expr1), strnull(_expr2));                      \
         })
 #endif
 
 #ifdef __COVERITY__
 #  define ASSERT_PTR_EQ(expr1, expr2) __coverity_check__((expr1) == (expr2))
 #else
-#  define ASSERT_PTR_EQ(expr1, expr2)                                                                                   \
-        ({                                                                                                              \
-                const void *_expr1 = (expr1), *_expr2 = (expr2);                                                        \
-                if (_expr1 != _expr2)                                                                                   \
-                        log_test_failed("Expected \"%s == %s\", got \"0x%p != 0x%p\"",                                  \
-                                        #expr1, #expr2, _expr1, _expr2);                                                \
+#  define ASSERT_PTR_EQ(expr1, expr2)                                                                           \
+        ({                                                                                                      \
+                const void *_expr1 = (expr1), *_expr2 = (expr2);                                                \
+                if (_expr1 != _expr2)                                                                           \
+                        log_test_failed("Expected \"%s == %s\", got \"0x%p != 0x%p\"",                          \
+                                        #expr1, #expr2, _expr1, _expr2);                                        \
         })
 #endif
 
index 2694b1eebc83b6e1f5c3b3c3c76cd60a1dd366cf..74e58fd41dd973f931739ef7196b2ce1c5944854 100644 (file)
@@ -40,12 +40,12 @@ static void test_policy_closed(const char *cgroup_path, BPFProgram **installed_p
                 _cleanup_close_ int fd = -EBADF, fd2 = -EBADF;
 
                 fd = open(s, O_CLOEXEC|O_RDONLY|O_NOCTTY);
-                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd < 0 && errno == EPERM;
                 /* We ignore errors other than EPERM, e.g. ENOENT or ENXIO */
 
                 fd2 = open(s, O_CLOEXEC|O_WRONLY|O_NOCTTY);
-                log_debug("open(%s, \"w\") = %d/%s", s, fd2, fd2 < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"w\") = %d/%s", s, fd2, fd2 < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd2 < 0 && errno == EPERM;
         }
         assert_se(wrong == 0);
@@ -78,11 +78,11 @@ static void test_policy_strict(const char *cgroup_path, BPFProgram **installed_p
                 const char *s = "/dev/null";
 
                 fd = open(s, O_CLOEXEC|O_RDONLY|O_NOCTTY);
-                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd < 0;
 
                 fd2 = open(s, O_CLOEXEC|O_WRONLY|O_NOCTTY);
-                log_debug("open(%s, \"w\") = %d/%s", s, fd2, fd2 < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"w\") = %d/%s", s, fd2, fd2 < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd2 < 0;
         }
 
@@ -91,11 +91,11 @@ static void test_policy_strict(const char *cgroup_path, BPFProgram **installed_p
                 const char *s = "/dev/random";
 
                 fd = open(s, O_CLOEXEC|O_RDONLY|O_NOCTTY);
-                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd < 0;
 
                 fd2 = open(s, O_CLOEXEC|O_WRONLY|O_NOCTTY);
-                log_debug("open(%s, \"w\") = %d/%s", s, fd2, fd2 < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"w\") = %d/%s", s, fd2, fd2 < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd2 >= 0;
         }
 
@@ -104,11 +104,11 @@ static void test_policy_strict(const char *cgroup_path, BPFProgram **installed_p
                 const char *s = "/dev/zero";
 
                 fd = open(s, O_CLOEXEC|O_RDONLY|O_NOCTTY);
-                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd >= 0;
 
                 fd2 = open(s, O_CLOEXEC|O_WRONLY|O_NOCTTY);
-                log_debug("open(%s, \"w\") = %d/%s", s, fd2, fd2 < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"w\") = %d/%s", s, fd2, fd2 < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd2 < 0;
         }
 
@@ -117,11 +117,11 @@ static void test_policy_strict(const char *cgroup_path, BPFProgram **installed_p
                 const char *s = "/dev/full";
 
                 fd = open(s, O_CLOEXEC|O_RDONLY|O_NOCTTY);
-                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd >= 0;
 
                 fd2 = open(s, O_CLOEXEC|O_WRONLY|O_NOCTTY);
-                log_debug("open(%s, \"w\") = %d/%s", s, fd2, fd2 < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"w\") = %d/%s", s, fd2, fd2 < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd2 >= 0;
         }
 
@@ -150,11 +150,11 @@ static void test_policy_allow_list_major(const char *pattern, const char *cgroup
                 const char *s = "/dev/null";
 
                 fd = open(s, O_CLOEXEC|O_RDONLY|O_NOCTTY);
-                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd < 0;
 
                 fd2 = open(s, O_CLOEXEC|O_WRONLY|O_NOCTTY);
-                log_debug("open(%s, \"w\") = %d/%s", s, fd2, fd2 < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"w\") = %d/%s", s, fd2, fd2 < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd2 < 0;
         }
 
@@ -163,11 +163,11 @@ static void test_policy_allow_list_major(const char *pattern, const char *cgroup
                 const char *s = "/dev/full";
 
                 fd = open(s, O_CLOEXEC|O_RDONLY|O_NOCTTY);
-                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd < 0;
 
                 fd2 = open(s, O_CLOEXEC|O_WRONLY|O_NOCTTY);
-                log_debug("open(%s, \"w\") = %d/%s", s, fd2, fd2 < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"w\") = %d/%s", s, fd2, fd2 < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd2 < 0;
         }
 
@@ -176,11 +176,11 @@ static void test_policy_allow_list_major(const char *pattern, const char *cgroup
                 const char *s = "/dev/tty";
 
                 fd = open(s, O_CLOEXEC|O_RDONLY|O_NOCTTY);
-                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd >= 0;
 
                 fd2 = open(s, O_CLOEXEC|O_WRONLY|O_NOCTTY);
-                log_debug("open(%s, \"w\") = %d/%s", s, fd2, fd2 < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"w\") = %d/%s", s, fd2, fd2 < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd2 >= 0;
         }
 
@@ -208,7 +208,7 @@ static void test_policy_allow_list_major_star(char type, const char *cgroup_path
                 const char *s = "/dev/null";
 
                 fd = open(s, O_CLOEXEC|O_RDWR|O_NOCTTY);
-                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? ERRNO_NAME(errno) : "-");
                 if (type == 'c')
                         wrong += fd < 0;
                 else
@@ -241,7 +241,7 @@ static void test_policy_empty(bool add_mismatched, const char *cgroup_path, BPFP
                 const char *s = "/dev/null";
 
                 fd = open(s, O_CLOEXEC|O_RDWR|O_NOCTTY);
-                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? errno_to_name(errno) : "-");
+                log_debug("open(%s, \"r\") = %d/%s", s, fd, fd < 0 ? ERRNO_NAME(errno) : "-");
                 wrong += fd >= 0;
         }
 
index 2b21f119e542e54f47940db9a8b876bd7edacf17..d713a52b814af6d66a4b20410ff8ba231c8aa469 100644 (file)
@@ -32,7 +32,7 @@ static void test_transient_settings_one(UnitType type, const char* const* lines)
                 }
 
                 r = bus_append_unit_property_assignment(m, type, t);
-                log_debug("%s → %d/%s", t, r, r < 0 ? ERRNO_NAME_FULL(r) : yes_no(r));
+                log_debug("%s → %d/%s", t, r, r < 0 ? ERRNO_NAME(r) : yes_no(r));
                 ASSERT_EQ(r, expect);
         }
 }
index c72f657123f093bd64c165c35a6e9d7ffc9e41d5..f7d3c5ce944491d309ef89cab3918447f4cfe506 100644 (file)
@@ -5,49 +5,54 @@
 
 #include "errno-to-name.inc"
 
-TEST(errno_list) {
+TEST(errno_name_no_fallback) {
         ASSERT_NULL(errno_names[0]);
-        ASSERT_NULL(errno_to_name(0));
+        ASSERT_NULL(errno_name_no_fallback(0));
 
-        for (size_t i = 0; i < ELEMENTSOF(errno_names); i++) {
+        for (size_t i = 0; i < ELEMENTSOF(errno_names); i++)
                 if (errno_names[i]) {
-                        ASSERT_STREQ(errno_to_name(i), errno_names[i]);
+                        const char *mapped = errno_name_no_fallback(i);
+
+                        if (mapped)
+                                /* glibc might not know some errno names.
+                                 * This is not an error. */
+                                ASSERT_STREQ(mapped, errno_names[i]);
+
                         assert_se(errno_from_name(errno_names[i]) == (int) i);
                 }
-        }
 
 #ifdef ECANCELLED
         /* ECANCELLED is an alias of ECANCELED. */
-        ASSERT_STREQ(errno_to_name(ECANCELLED), "ECANCELED");
+        ASSERT_STREQ(errno_name_no_fallback(ECANCELLED), "ECANCELED");
 #endif
-        ASSERT_STREQ(errno_to_name(ECANCELED), "ECANCELED");
+        ASSERT_STREQ(errno_name_no_fallback(ECANCELED), "ECANCELED");
 
 #ifdef EREFUSED
         /* EREFUSED is an alias of ECONNREFUSED. */
-        ASSERT_STREQ(errno_to_name(EREFUSED), "ECONNREFUSED");
+        ASSERT_STREQ(errno_name_no_fallback(EREFUSED), "ECONNREFUSED");
 #endif
-        ASSERT_STREQ(errno_to_name(ECONNREFUSED), "ECONNREFUSED");
+        ASSERT_STREQ(errno_name_no_fallback(ECONNREFUSED), "ECONNREFUSED");
 }
 
 TEST(errno_name_full) {
         char buf[ERRNO_NAME_BUF_LEN];
 
-        ASSERT_STREQ(errno_name_full(0, buf), "0");
-        ASSERT_STREQ(errno_name_full(EPERM, buf), "EPERM");
-        ASSERT_STREQ(errno_name_full(ENOENT, buf), "ENOENT");
-        ASSERT_STREQ(errno_name_full(200, buf), "200");
-        ASSERT_STREQ(errno_name_full(-200, buf), "200");
+        ASSERT_STREQ(errno_name(0, buf), "0");
+        ASSERT_STREQ(errno_name(EPERM, buf), "EPERM");
+        ASSERT_STREQ(errno_name(ENOENT, buf), "ENOENT");
+        ASSERT_STREQ(errno_name(200, buf), "200");
+        ASSERT_STREQ(errno_name(-200, buf), "200");
 }
 
 TEST(ERRNO_NAME_FULL) {
-        ASSERT_STREQ(ERRNO_NAME_FULL(0), "0");
-        ASSERT_STREQ(ERRNO_NAME_FULL(EPERM), "EPERM");
-        ASSERT_STREQ(ERRNO_NAME_FULL(ENOENT), "ENOENT");
-        ASSERT_STREQ(ERRNO_NAME_FULL(200), "200");
-        ASSERT_STREQ(ERRNO_NAME_FULL(-200), "200");
+        ASSERT_STREQ(ERRNO_NAME(0), "0");
+        ASSERT_STREQ(ERRNO_NAME(EPERM), "EPERM");
+        ASSERT_STREQ(ERRNO_NAME(ENOENT), "ENOENT");
+        ASSERT_STREQ(ERRNO_NAME(200), "200");
+        ASSERT_STREQ(ERRNO_NAME(-200), "200");
 
         int x = 0;
-        ASSERT_STREQ(ERRNO_NAME_FULL(++x), "EPERM");  /* Confirm that eval happens just once. */
+        ASSERT_STREQ(ERRNO_NAME(++x), "EPERM");  /* Confirm that eval happens just once. */
         ASSERT_EQ(x, 1);
 }
 
index df93a7b5285d62fc5fc7498a36552efd22e866dd..8756fcd39403339517cac19f8e3b7a7fb6e8cf5b 100644 (file)
@@ -115,7 +115,7 @@ static void test_gethostbyname4_r(void *handle, const char *module, const char *
                          fname, name,
                          nss_status_to_string(status, pretty_status, sizeof pretty_status), "\n",
                          pat ? (uintptr_t) pat - (uintptr_t) buffer : 0,
-                         errno1, errno_to_name(errno1) ?: "---",
+                         errno1, errno1 > 0 ? ERRNO_NAME(errno1) : "---",
                          errno2, hstrerror(errno2),
                          ttl);
                 n = print_gaih_addrtuples(pat);
@@ -124,7 +124,7 @@ static void test_gethostbyname4_r(void *handle, const char *module, const char *
                          fname, name,
                          nss_status_to_string(status, pretty_status, sizeof pretty_status), "\n",
                          pat,
-                         errno1, errno_to_name(errno1) ?: "---",
+                         errno1, errno1 > 0 ? ERRNO_NAME(errno1) : "---",
                          errno2, hstrerror(errno2));
                 n = 0;
         }
@@ -175,7 +175,7 @@ static void test_gethostbyname3_r(void *handle, const char *module, const char *
         log_info("%s(\"%s\", %s) → status=%s%-20serrno=%d/%s h_errno=%d/%s ttl=%"PRIi32,
                  fname, name, af_to_string(af, family_name, sizeof family_name),
                  nss_status_to_string(status, pretty_status, sizeof pretty_status), "\n",
-                 errno1, errno_to_name(errno1) ?: "---",
+                 errno1, errno1 > 0 ? ERRNO_NAME(errno1) : "---",
                  errno2, hstrerror(errno2),
                  ttl);
         if (status == NSS_STATUS_SUCCESS)
@@ -204,7 +204,7 @@ static void test_gethostbyname2_r(void *handle, const char *module, const char *
         log_info("%s(\"%s\", %s) → status=%s%-20serrno=%d/%s h_errno=%d/%s",
                  fname, name, af_to_string(af, family_name, sizeof family_name),
                  nss_status_to_string(status, pretty_status, sizeof pretty_status), "\n",
-                 errno1, errno_to_name(errno1) ?: "---",
+                 errno1, errno1 > 0 ? ERRNO_NAME(errno1) : "---",
                  errno2, hstrerror(errno2));
         if (status == NSS_STATUS_SUCCESS)
                 print_struct_hostent(&host, NULL);
@@ -231,7 +231,7 @@ static void test_gethostbyname_r(void *handle, const char *module, const char *n
         log_info("%s(\"%s\") → status=%s%-20serrno=%d/%s h_errno=%d/%s",
                  fname, name,
                  nss_status_to_string(status, pretty_status, sizeof pretty_status), "\n",
-                 errno1, errno_to_name(errno1) ?: "---",
+                 errno1, errno1 > 0 ? ERRNO_NAME(errno1) : "---",
                  errno2, hstrerror(errno2));
         if (status == NSS_STATUS_SUCCESS)
                 print_struct_hostent(&host, NULL);
@@ -268,7 +268,7 @@ static void test_gethostbyaddr2_r(void *handle,
         log_info("%s(\"%s\") → status=%s%-20serrno=%d/%s h_errno=%d/%s ttl=%"PRIi32,
                  fname, addr_pretty,
                  nss_status_to_string(status, pretty_status, sizeof pretty_status), "\n",
-                 errno1, errno_to_name(errno1) ?: "---",
+                 errno1, errno1 > 0 ? ERRNO_NAME(errno1) : "---",
                  errno2, hstrerror(errno2),
                  ttl);
         if (status == NSS_STATUS_SUCCESS)
@@ -305,7 +305,7 @@ static void test_gethostbyaddr_r(void *handle,
         log_info("%s(\"%s\") → status=%s%-20serrno=%d/%s h_errno=%d/%s",
                  fname, addr_pretty,
                  nss_status_to_string(status, pretty_status, sizeof pretty_status), "\n",
-                 errno1, errno_to_name(errno1) ?: "---",
+                 errno1, errno1 > 0 ? ERRNO_NAME(errno1) : "---",
                  errno2, hstrerror(errno2));
         if (status == NSS_STATUS_SUCCESS)
                 print_struct_hostent(&host, NULL);
index 0f78995fb72b90b06b9e8308f422de0fb3000b50..f253b53c1f015a2274393ea1c118f78c53f9432a 100644 (file)
@@ -61,7 +61,7 @@ static void test_getpwnam_r(void *handle, const char *module, const char *name)
         log_info("%s(\"%s\") → status=%s%-20serrno=%d/%s",
                  fname, name,
                  nss_status_to_string(status, pretty_status, sizeof pretty_status), "\n",
-                 errno1, errno_to_name(errno1) ?: "---");
+                 errno1, errno1 > 0 ? ERRNO_NAME(errno1) : "---");
         if (status == NSS_STATUS_SUCCESS)
                 print_struct_passwd(&pwd);
 }
@@ -87,7 +87,7 @@ static void test_getgrnam_r(void *handle, const char *module, const char *name)
         log_info("%s(\"%s\") → status=%s%-20serrno=%d/%s",
                  fname, name,
                  nss_status_to_string(status, pretty_status, sizeof pretty_status), "\n",
-                 errno1, errno_to_name(errno1) ?: "---");
+                 errno1, errno1 > 0 ? ERRNO_NAME(errno1) : "---");
         if (status == NSS_STATUS_SUCCESS)
                 print_struct_group(&gr);
 }
@@ -113,7 +113,7 @@ static void test_getpwuid_r(void *handle, const char *module, uid_t uid) {
         log_info("%s("UID_FMT") → status=%s%-20serrno=%d/%s",
                  fname, uid,
                  nss_status_to_string(status, pretty_status, sizeof pretty_status), "\n",
-                 errno1, errno_to_name(errno1) ?: "---");
+                 errno1, errno1 > 0 ? ERRNO_NAME(errno1) : "---");
         if (status == NSS_STATUS_SUCCESS)
                 print_struct_passwd(&pwd);
 }
@@ -139,7 +139,7 @@ static void test_getgrgid_r(void *handle, const char *module, gid_t gid) {
         log_info("%s("GID_FMT") → status=%s%-20serrno=%d/%s",
                  fname, gid,
                  nss_status_to_string(status, pretty_status, sizeof pretty_status), "\n",
-                 errno1, errno_to_name(errno1) ?: "---");
+                 errno1, errno1 > 0 ? ERRNO_NAME(errno1) : "---");
         if (status == NSS_STATUS_SUCCESS)
                 print_struct_group(&gr);
 }
index 9c14d99a8201224362cb113543ca380e323f2a73..5723f2a07416386e04296ede51d83268dbb0eafd 100644 (file)
@@ -123,34 +123,34 @@ static void test_pid_get_cmdline_one(pid_t pid) {
         int r;
 
         r = pid_get_cmdline(pid, SIZE_MAX, 0, &c);
-        log_info("PID "PID_FMT": %s", pid, r >= 0 ? c : errno_to_name(r));
+        log_info("PID "PID_FMT": %s", pid, r >= 0 ? c : ERRNO_NAME(r));
 
         r = pid_get_cmdline(pid, SIZE_MAX, PROCESS_CMDLINE_COMM_FALLBACK, &d);
-        log_info("      %s", r >= 0 ? d : errno_to_name(r));
+        log_info("      %s", r >= 0 ? d : ERRNO_NAME(r));
 
         r = pid_get_cmdline(pid, SIZE_MAX, PROCESS_CMDLINE_QUOTE, &e);
-        log_info("      %s", r >= 0 ? e : errno_to_name(r));
+        log_info("      %s", r >= 0 ? e : ERRNO_NAME(r));
 
         r = pid_get_cmdline(pid, SIZE_MAX, PROCESS_CMDLINE_QUOTE | PROCESS_CMDLINE_COMM_FALLBACK, &f);
-        log_info("      %s", r >= 0 ? f : errno_to_name(r));
+        log_info("      %s", r >= 0 ? f : ERRNO_NAME(r));
 
         r = pid_get_cmdline(pid, SIZE_MAX, PROCESS_CMDLINE_QUOTE_POSIX, &g);
-        log_info("      %s", r >= 0 ? g : errno_to_name(r));
+        log_info("      %s", r >= 0 ? g : ERRNO_NAME(r));
 
         r = pid_get_cmdline(pid, SIZE_MAX, PROCESS_CMDLINE_QUOTE_POSIX | PROCESS_CMDLINE_COMM_FALLBACK, &h);
-        log_info("      %s", r >= 0 ? h : errno_to_name(r));
+        log_info("      %s", r >= 0 ? h : ERRNO_NAME(r));
 
         r = pid_get_cmdline_strv(pid, 0, &strv_a);
         if (r >= 0)
                 ASSERT_NOT_NULL((joined = strv_join(strv_a, "\", \"")));
-        log_info("      \"%s\"", r >= 0 ? joined : errno_to_name(r));
+        log_info("      \"%s\"", r >= 0 ? joined : ERRNO_NAME(r));
 
         joined = mfree(joined);
 
         r = pid_get_cmdline_strv(pid, PROCESS_CMDLINE_COMM_FALLBACK, &strv_b);
         if (r >= 0)
                 ASSERT_NOT_NULL((joined = strv_join(strv_b, "\", \"")));
-        log_info("      \"%s\"", r >= 0 ? joined : errno_to_name(r));
+        log_info("      \"%s\"", r >= 0 ? joined : ERRNO_NAME(r));
 }
 
 TEST(pid_get_cmdline) {
index fc8bad256f0c6bd84fb95d3221b2c84bfb913f6e..cbaa29d5a9adf4ec987322e907071ce43482a37d 100644 (file)
@@ -169,7 +169,7 @@ TEST(path_is_temporary_fs) {
                 r = path_is_temporary_fs(s);
 
                 log_info_errno(r, "path_is_temporary_fs(\"%s\"): %d, %s",
-                               s, r, r < 0 ? errno_to_name(r) : yes_no(r));
+                               s, r, r < 0 ? ERRNO_NAME(r) : yes_no(r));
         }
 
         /* run might not be a mount point in build chroots */
@@ -186,7 +186,7 @@ TEST(path_is_read_only_fs) {
                 r = path_is_read_only_fs(s);
 
                 log_info_errno(r, "path_is_read_only_fs(\"%s\"): %d, %s",
-                               s, r, r < 0 ? errno_to_name(r) : yes_no(r));
+                               s, r, r < 0 ? ERRNO_NAME(r) : yes_no(r));
         }
 
         if (path_is_mount_point_full("/sys", NULL, AT_SYMLINK_FOLLOW) > 0)
index b7cadbd9a49938f2df7c92d4f8bb127846b61388..c61df6fbaac8acb91c168e645f59f984e59a4c0f 100644 (file)
@@ -21,7 +21,7 @@ int device_add_errno(sd_device *dev, int error) {
         r = device_add_property(dev, "UDEV_WORKER_FAILED", "1");
         RET_GATHER(r, device_add_propertyf(dev, "UDEV_WORKER_ERRNO", "%i", error));
 
-        const char *str = errno_to_name(error);
+        const char *str = errno_name_no_fallback(error);
         if (str)
                 RET_GATHER(r, device_add_property(dev, "UDEV_WORKER_ERRNO_NAME", str));
 
index c75947a0cbca3af63be7b37bf95cabadeb0eb925..27addfa7f10cd10ee6bee59122af4ca62ddbf707 100644 (file)
@@ -296,7 +296,7 @@ static int worker_device_monitor_handler(sd_device_monitor *monitor, sd_device *
                         return 0;
                 }
 
-                const char *e = errno_to_name(r);
+                const char *e = errno_name_no_fallback(r);
                 r = sd_notifyf(/* unset_environment = */ false, "ERRNO=%i%s%s", -r, e ? "\nERRNO_NAME=" : "", strempty(e));
                 if (r < 0) {
                         log_device_warning_errno(dev, r, "Failed to send notification message to manager process, ignoring: %m");
index f16d835f8a7c9ea70b21baa3d0e1c1fffd2aa6be..285b3565fab806e14ca33a4312cca29424508e59 100644 (file)
@@ -1069,7 +1069,7 @@ static int display_services(int argc, char *argv[], void *userdata) {
 
                 r = connect_unix_path(fd, dirfd(d), de->d_name);
                 if (r < 0) {
-                        no = strjoin("No (", errno_to_name(r), ")");
+                        no = strjoin("No (", ERRNO_NAME(r), ")");
                         if (!no)
                                 return log_oom();
                 }