]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/exit-status: fix lookup
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 5 Aug 2019 14:36:45 +0000 (16:36 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 5 Aug 2019 14:38:17 +0000 (16:38 +0200)
FLAGS_SET() is the wrong operator here, because we want to see if
*any* bits are set. Add test.

https://github.com/systemd/systemd/pull/12884#issuecomment-518238410

src/shared/exit-status.c
src/test/test-exit-status.c

index 44b1c9b749e457f48b88d1c34b789c05888ddd76..3704f5d481d8fa756913497da477c518abb5a1dd 100644 (file)
@@ -99,7 +99,7 @@ const ExitStatusMapping exit_status_mappings[256] = {
 const char* exit_status_to_string(int code, ExitStatusClass class) {
         if (code < 0 || (size_t) code >= ELEMENTSOF(exit_status_mappings))
                 return NULL;
-        return FLAGS_SET(exit_status_mappings[code].class, class) ? exit_status_mappings[code].name : NULL;
+        return class & exit_status_mappings[code].class ? exit_status_mappings[code].name : NULL;
 }
 
 const char* exit_status_class(int code) {
index 3bcebd06a481d87ac3e978fc9d4796c2c9a8581e..a007bda5c414ea8f965881e41633a585131cb7b4 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
 #include "exit-status.h"
+#include "string-util.h"
 #include "tests.h"
 
 static void test_exit_status_to_string(void) {
@@ -31,11 +32,21 @@ static void test_exit_status_from_string(void) {
         assert_se(exit_status_from_string("FAILURE") == 1);
 }
 
+static void test_exit_status_NUMA_POLICY(void) {
+        log_info("/* %s */", __func__);
+
+        assert_se(streq(exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_FULL), "NUMA_POLICY"));
+        assert_se(streq(exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_SYSTEMD), "NUMA_POLICY"));
+        assert_se(!exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_BSD));
+        assert_se(!exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_LSB));
+}
+
 int main(int argc, char *argv[]) {
         test_setup_logging(LOG_DEBUG);
 
         test_exit_status_to_string();
         test_exit_status_from_string();
+        test_exit_status_NUMA_POLICY();
 
         return 0;
 }