]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: disable journald logging backend if struct msghdr is not found 40607/head
authorKefu Chai <kchai@redhat.com>
Tue, 6 Apr 2021 05:09:13 +0000 (13:09 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 6 Apr 2021 06:46:33 +0000 (14:46 +0800)
* 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 <kchai@redhat.com>
cmake/modules/CephChecks.cmake
src/common/CMakeLists.txt
src/common/Journald.h
src/include/config-h.in.cmake
src/test/CMakeLists.txt
src/test/common/CMakeLists.txt

index ca86dcbc73de8f7082d4da6eaa91c6fbacf3cd0e..ed1d2c827af5976836d39d177929dd48146b959e 100644 (file)
@@ -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)
index 687eb1a3c791ebe69161d8b12edfe776170447d9..807f8a23b4430bb441cb0d44058a4d0e4a0df1e5 100644 (file)
@@ -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
index 59a9c4421a48156520c71f848ec4164a6a43d24d..deb415731283f180755c440669b771ffeef5c56c 100644 (file)
@@ -4,17 +4,19 @@
 #ifndef CEPH_COMMON_JOURNALD_H
 #define CEPH_COMMON_JOURNALD_H
 
+#include "acconfig.h"
 #include <memory>
 #include <sys/types.h>
 #include <sys/socket.h>
 
 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<detail::LogEntryEncoder> 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
index 5c1d3d41d506bd899db897fa43cc86a28c723716..4425ae97bec16de053cf28ab33b82a018bce6c46 100644 (file)
@@ -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
 
index a86af70cdb838a21881cb91e80a85cb259c9a9e7..5ead748421326802921553185675dc8aac8bfd63 100644 (file)
@@ -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
index b0e922af2f78c1105dcc6fa3d8fde89ed76eb095..28b226addc317ab661a048e15dd3369d26333235 100644 (file)
@@ -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()