tree-wide: use ERRNO_NAME almost everywhere

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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2025-07-29 18:05:20 +02:00
parent 225450d043
commit 858cb6e49e
22 changed files with 216 additions and 215 deletions
+1 -1
View 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();
}