]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/log: allow errno values higher than 255
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 3 Jan 2022 16:53:29 +0000 (17:53 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 3 Jan 2022 22:46:32 +0000 (22:46 +0000)
When the support for "synthetic errno" was added, we started truncating
the errno value to just the least significant byte. This is generally OK,
because errno values are defined up to ~130.

The docs don't really say what the maximum value is. But at least in principle
higher values could be added in the future. So let's stop truncating
the values needlessly.

The kernel (or libbpf?) have an error where they return 524 as an errno
value (https://bugzilla.redhat.com/show_bug.cgi?id=2036145). We would
confusingly truncate this to 12 (ENOMEM). It seems much nicer to let
strerror() give us "Unknown error 524" rather than to print the bogus
message about ENOMEM.

src/basic/log.h

index 3bec4131a79ae527af0ed16236af082138a1eb5f..7218b4bf718f6e9080ca2bbb4e4064ab4f03dea7 100644 (file)
@@ -31,10 +31,10 @@ typedef enum LogTarget{
  * used a regular log level. */
 #define LOG_NULL (LOG_EMERG - 1)
 
-/* Note to readers: << and >> have lower precedence than & and | */
+/* Note to readers: << and >> have lower precedence (are evaluated earlier) than & and | */
 #define SYNTHETIC_ERRNO(num)                (1 << 30 | (num))
 #define IS_SYNTHETIC_ERRNO(val)             ((val) >> 30 & 1)
-#define ERRNO_VALUE(val)                    (abs(val) & 255)
+#define ERRNO_VALUE(val)                    (abs(val) & ~(1 << 30))
 
 /* The callback function to be invoked when syntax warnings are seen
  * in the unit files. */