79 lines
2.9 KiB
Diff
79 lines
2.9 KiB
Diff
|
|
From 9463b376bcbb1a177bf46d64845b52eae79af739 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Mike Yuan <me@yhndnzj.com>
|
||
|
|
Date: Wed, 24 Jul 2024 16:28:48 +0200
|
||
|
|
Subject: [PATCH] basic/log: do not treat all negative errnos as synthetic
|
||
|
|
|
||
|
|
Currently, IS_SYNTHETIC_ERRNO() evaluates to true for all negative errnos,
|
||
|
|
because of the two's-complement negative value representation.
|
||
|
|
Subsequently, ERRNO= is not logged for most of our own code.
|
||
|
|
Let's fix this, by formatting all synthetic errnos as positive.
|
||
|
|
Then, treat all negative values as non-synthetic.
|
||
|
|
|
||
|
|
While at it, mark the evaluation order explicitly, and remove
|
||
|
|
unneeded comment.
|
||
|
|
|
||
|
|
Fixes #33800
|
||
|
|
|
||
|
|
(cherry picked from commit 268f58076f7e0258dce75f521d08199092279853)
|
||
|
|
(cherry picked from commit 4ad6b2631d73a574859a62d33715a7bdef810bcf)
|
||
|
|
(cherry picked from commit 1fc7e3473c2fec27bdc0b19753e4ea84cd39644f)
|
||
|
|
|
||
|
|
Conflict:code context adaptation
|
||
|
|
Reference:https://github.com/systemd/systemd/commit/268f58076f7e0258dce75f521d08199092279853
|
||
|
|
---
|
||
|
|
src/basic/log.h | 5 ++---
|
||
|
|
src/test/test-log.c | 14 +++++++++-----
|
||
|
|
2 files changed, 11 insertions(+), 8 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/src/basic/log.h b/src/basic/log.h
|
||
|
|
index 9008d47390..12b310575e 100644
|
||
|
|
--- a/src/basic/log.h
|
||
|
|
+++ b/src/basic/log.h
|
||
|
|
@@ -34,9 +34,8 @@ typedef enum LogTarget{
|
||
|
|
_LOG_TARGET_INVALID = -EINVAL,
|
||
|
|
} LogTarget;
|
||
|
|
|
||
|
|
-/* 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 SYNTHETIC_ERRNO(num) (abs(num) | (1 << 30))
|
||
|
|
+#define IS_SYNTHETIC_ERRNO(val) (((val) >> 30) == 1)
|
||
|
|
#define ERRNO_VALUE(val) (abs(val) & ~(1 << 30))
|
||
|
|
|
||
|
|
const char *log_target_to_string(LogTarget target) _const_;
|
||
|
|
diff --git a/src/test/test-log.c b/src/test/test-log.c
|
||
|
|
index e337a3c7df..e8c004681b 100644
|
||
|
|
--- a/src/test/test-log.c
|
||
|
|
+++ b/src/test/test-log.c
|
||
|
|
@@ -10,11 +10,6 @@
|
||
|
|
#include "string-util.h"
|
||
|
|
#include "util.h"
|
||
|
|
|
||
|
|
-assert_cc(IS_SYNTHETIC_ERRNO(SYNTHETIC_ERRNO(EINVAL)));
|
||
|
|
-assert_cc(!IS_SYNTHETIC_ERRNO(EINVAL));
|
||
|
|
-assert_cc(IS_SYNTHETIC_ERRNO(SYNTHETIC_ERRNO(0)));
|
||
|
|
-assert_cc(!IS_SYNTHETIC_ERRNO(0));
|
||
|
|
-
|
||
|
|
#define X10(x) x x x x x x x x x x
|
||
|
|
#define X100(x) X10(X10(x))
|
||
|
|
#define X1000(x) X100(X10(x))
|
||
|
|
@@ -68,6 +63,15 @@ static void test_log_syntax(void) {
|
||
|
|
int main(int argc, char* argv[]) {
|
||
|
|
int target;
|
||
|
|
|
||
|
|
+ assert_se(IS_SYNTHETIC_ERRNO(SYNTHETIC_ERRNO(EINVAL)));
|
||
|
|
+ assert_se(IS_SYNTHETIC_ERRNO(SYNTHETIC_ERRNO(-EINVAL)));
|
||
|
|
+ assert_cc(!IS_SYNTHETIC_ERRNO(EINVAL));
|
||
|
|
+ assert_cc(!IS_SYNTHETIC_ERRNO(-EINVAL));
|
||
|
|
+ assert_se(IS_SYNTHETIC_ERRNO(SYNTHETIC_ERRNO(0)));
|
||
|
|
+ assert_cc(!IS_SYNTHETIC_ERRNO(0));
|
||
|
|
+ assert_se(ERRNO_VALUE(EINVAL) == EINVAL);
|
||
|
|
+ assert_se(ERRNO_VALUE(SYNTHETIC_ERRNO(-EINVAL)) == EINVAL);
|
||
|
|
+
|
||
|
|
test_file();
|
||
|
|
|
||
|
|
for (target = 0; target < _LOG_TARGET_MAX; target++) {
|
||
|
|
--
|
||
|
|
2.33.0
|
||
|
|
|