From: Kefu Chai Date: Tue, 6 Apr 2021 05:09:13 +0000 (+0800) Subject: common: disable journald logging backend if struct msghdr is not found X-Git-Tag: v17.1.0~2342^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F40607%2Fhead;p=ceph.git common: disable journald logging backend if struct msghdr is not found * cmake/modules/CephChecks.cmake: detect the existence of struct msghdr, define HAVE_MSGHDR if it is found * src/common/CMakeLists.txt: do not compile journald.cc if HAVE_MSGHDR is FALSE. as in that case, we cannot use sendmsg() to write to journald unix domain socket * src/test/CMakeLists.txt, src/test/common/CMakeLists.txt: disable test exercising journald logging backend if HAVE_MSGHDR is not defined * src/common/Journald.h: define a dummy JournaldLogger and a dummy JournaldClusterLogger when HAVE_MSGHDR is not defined, in order to minimize the change in Log.h and Log.cc, otherwise the source code of Log.h and Log.cc would be segmented into smaller chunks by `ifdef HAVE_MSGHDR` macros. * src/include/config-h.in.cmake: define a new macro named HAVE_MSGHDR. Signed-off-by: Kefu Chai --- diff --git a/cmake/modules/CephChecks.cmake b/cmake/modules/CephChecks.cmake index ca86dcbc73de..ed1d2c827af5 100644 --- a/cmake/modules/CephChecks.cmake +++ b/cmake/modules/CephChecks.cmake @@ -64,7 +64,9 @@ CHECK_TYPE_SIZE(__u64 __U64) CHECK_TYPE_SIZE(__s8 __S8) CHECK_TYPE_SIZE(__s16 __S16) CHECK_TYPE_SIZE(__s32 __S32) -CHECK_TYPE_SIZE(__s64 __S64) +CHECK_TYPE_SIZE(__s64 __S64) +set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h" "sys/socket.h") +CHECK_TYPE_SIZE("struct msghdr" MSGHDR) unset(CMAKE_EXTRA_INCLUDE_FILES) include(CheckSymbolExists) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 687eb1a3c791..807f8a23b443 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -25,7 +25,6 @@ set(common_srcs Graylog.cc HTMLFormatter.cc HeartbeatMap.cc - Journald.cc LogClient.cc LogEntry.cc ostream_temp.cc @@ -101,6 +100,11 @@ set(common_srcs util.cc version.cc) +if(HAVE_MSGHDR) + list(APPEND common_srcs + Journald.cc) +endif() + if(WITH_CEPH_DEBUG_MUTEX) list(APPEND common_srcs lockdep.cc diff --git a/src/common/Journald.h b/src/common/Journald.h index 59a9c4421a48..deb415731283 100644 --- a/src/common/Journald.h +++ b/src/common/Journald.h @@ -4,17 +4,19 @@ #ifndef CEPH_COMMON_JOURNALD_H #define CEPH_COMMON_JOURNALD_H +#include "acconfig.h" #include #include #include struct LogEntry; -namespace ceph { +namespace ceph::logging { -namespace logging { +#ifdef HAVE_MSGHDR namespace detail { + class EntryEncoder; class LogEntryEncoder; @@ -84,7 +86,25 @@ class JournaldClusterLogger { std::unique_ptr m_log_entry_encoder; }; -} -} +#else // HAVE_MSGHDR + +class JournaldLogger { +public: + JournaldLogger(const SubsystemMap *) {} + int log_entry(const Entry &) { + return 0; + } +}; + +class JournaldClusterLogger { +public: + int log_log_entry(const LogEntry &le) { + return 0; + } +}; + +#endif // HAVE_MSGHDR + +} // ceph::logging #endif diff --git a/src/include/config-h.in.cmake b/src/include/config-h.in.cmake index 5c1d3d41d506..4425ae97bec1 100644 --- a/src/include/config-h.in.cmake +++ b/src/include/config-h.in.cmake @@ -63,6 +63,9 @@ /* Define to 1 if the system has the type `__u8'. */ #cmakedefine HAVE___U8 1 +/* Define to 1 if the system has the type `msghdr` */ +#cmakedefine HAVE_MSGHDR 1 + /* Define if you have res_nquery */ #cmakedefine HAVE_RES_NQUERY diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index a86af70cdb83..5ead74842132 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -153,10 +153,11 @@ if(NOT WIN32) target_link_libraries(ceph_bench_log rt) endif() -add_executable(ceph_bench_journald_logger - bench_journald_logger.cc - ) -target_link_libraries(ceph_bench_journald_logger ceph-common) +if(HAVE_MSGHDR) + add_executable(ceph_bench_journald_logger + bench_journald_logger.cc) + target_link_libraries(ceph_bench_journald_logger ceph-common) +endif() # ceph_test_mutate add_executable(ceph_test_mutate diff --git a/src/test/common/CMakeLists.txt b/src/test/common/CMakeLists.txt index b0e922af2f78..28b226addc31 100644 --- a/src/test/common/CMakeLists.txt +++ b/src/test/common/CMakeLists.txt @@ -361,6 +361,8 @@ target_link_libraries(unittest_blocked_completion Boost::system GTest::GTest) add_executable(unittest_allocate_unique test_allocate_unique.cc) add_ceph_unittest(unittest_allocate_unique) -add_executable(unittest_journald_logger test_journald_logger.cc) -target_link_libraries(unittest_journald_logger ceph-common) -add_ceph_unittest(unittest_journald_logger) +if(HAVE_MSGHDR) + add_executable(unittest_journald_logger test_journald_logger.cc) + target_link_libraries(unittest_journald_logger ceph-common) + add_ceph_unittest(unittest_journald_logger) +endif()