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 <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2021-04-06 13:09:13 +08:00
parent 9f94d27752
commit 80c4a1cd37
6 changed files with 45 additions and 13 deletions

View 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)

View 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

View 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

View 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

View 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

View 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()