From 83a3018e20d7e637e662fb98e05b41162aef54ac Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 16 Jan 2025 13:46:18 +0100 Subject: nss-systemd: work around -Werror=zero-as-null-pointer-constant issue with PTHREAD_MUTEX_INITIALIZER This fixes builds on Fedora: ../src/nss-systemd/nss-systemd.c:105:18: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant] 105 | .mutex = PTHREAD_MUTEX_INITIALIZER, | ^~~~~~~~~~~~~~~~~~~~~~~~~ ../src/nss-systemd/nss-systemd.c:105:18: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant] ../src/nss-systemd/nss-systemd.c:109:18: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant] 109 | .mutex = PTHREAD_MUTEX_INITIALIZER, | ^~~~~~~~~~~~~~~~~~~~~~~~~ ../src/nss-systemd/nss-systemd.c:109:18: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant] ../src/nss-systemd/nss-systemd.c:113:18: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant] 113 | .mutex = PTHREAD_MUTEX_INITIALIZER, | ^~~~~~~~~~~~~~~~~~~~~~~~~ ../src/nss-systemd/nss-systemd.c:113:18: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant] ../src/nss-systemd/nss-systemd.c:117:18: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant] 117 | .mutex = PTHREAD_MUTEX_INITIALIZER, | ^~~~~~~~~~~~~~~~~~~~~~~~~ ../src/nss-systemd/nss-systemd.c:117:18: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant] cc1: all warnings being treated as errors --- src/fundamental/macro-fundamental.h | 4 ++++ src/nss-systemd/nss-systemd.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index 6122a0a92b..7bee2915e1 100644 --- a/src/fundamental/macro-fundamental.h +++ b/src/fundamental/macro-fundamental.h @@ -56,6 +56,10 @@ _Pragma("GCC diagnostic push"); \ _Pragma("GCC diagnostic ignored \"-Wzero-length-bounds\"") +#define DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT \ + _Pragma("GCC diagnostic push"); \ + _Pragma("GCC diagnostic ignored \"-Wzero-as-null-pointer-constant\"") + #define REENABLE_WARNING \ _Pragma("GCC diagnostic pop") diff --git a/src/nss-systemd/nss-systemd.c b/src/nss-systemd/nss-systemd.c index d686d920fc..683352fab9 100644 --- a/src/nss-systemd/nss-systemd.c +++ b/src/nss-systemd/nss-systemd.c @@ -101,6 +101,9 @@ typedef struct GetentData { bool by_membership; } GetentData; +/* On current glibc PTHREAD_MUTEX_INITIALIZER is defined in a way incompatible with + * -Wzero-as-null-pointer-constant, work around this for now. */ +DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT; static GetentData getpwent_data = { .mutex = PTHREAD_MUTEX_INITIALIZER, }; @@ -116,6 +119,7 @@ static GetentData getspent_data = { static GetentData getsgent_data = { .mutex = PTHREAD_MUTEX_INITIALIZER, }; +REENABLE_WARNING; static void setup_logging_once(void) { static pthread_once_t once = PTHREAD_ONCE_INIT; -- cgit v1.2.3