From: Zbigniew Jędrzejewski-Szmek Date: Mon, 5 Aug 2019 14:36:45 +0000 (+0200) Subject: shared/exit-status: fix lookup X-Git-Tag: v243-rc2~63^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=00d27e5dd74a6c67759def1e958a71aae0650976;p=thirdparty%2Fsystemd.git shared/exit-status: fix lookup 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 --- diff --git a/src/shared/exit-status.c b/src/shared/exit-status.c index 44b1c9b749e..3704f5d481d 100644 --- a/src/shared/exit-status.c +++ b/src/shared/exit-status.c @@ -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) { diff --git a/src/test/test-exit-status.c b/src/test/test-exit-status.c index 3bcebd06a48..a007bda5c41 100644 --- a/src/test/test-exit-status.c +++ b/src/test/test-exit-status.c @@ -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; }