Skip to content

Commit

Permalink
fix(broker/rrd): Wrong rights on rrd files after a rebuild (#1089)
Browse files Browse the repository at this point in the history
* MON-23624 rrd files have group rw permissions (#978)
* c++17 and fixes

REFS:MON-23624
  • Loading branch information
jean-christophe81 authored Feb 7, 2024
1 parent 6921686 commit e2e1a1f
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 29 deletions.
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,7 @@ endif()
# set(CMAKE_CXX_COMPILER "clang++")
add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1")

option(NG "C++17 build." OFF)

if(NG)
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_STANDARD 14)
endif()
set(CMAKE_CXX_STANDARD 17)

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
Expand Down
3 changes: 2 additions & 1 deletion broker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,8 @@ target_link_libraries(
${CONAN_LIBS_PROTOBUF}
"-Wl,--no-whole-archive"
CONAN_PKG::spdlog
CONAN_PKG::grpc)
CONAN_PKG::grpc
stdc++fs)

# Centreon Broker Watchdog
option(WITH_CBWD "Build centreon broker watchdog." ON)
Expand Down
23 changes: 19 additions & 4 deletions broker/rrd/src/creator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <filesystem>

#include "bbdo/storage/metric.hh"
#include "com/centreon/broker/log_v2.hh"
Expand All @@ -45,7 +46,8 @@ using namespace com::centreon::broker::rrd;
*/
creator::creator(std::string const& tmpl_path, uint32_t cache_size)
: _cache_size(cache_size), _tmpl_path(tmpl_path) {
log_v2::rrd()->debug(
SPDLOG_LOGGER_DEBUG(
log_v2::rrd(),
"RRD: file creator will maintain at most {} templates in '{}'",
_cache_size, _tmpl_path);
}
Expand Down Expand Up @@ -261,15 +263,28 @@ void creator::_open(std::string const& filename,

// Debug message.
argv[argc] = nullptr;
log_v2::rrd()->debug("RRD: opening file '{}' ({}, {}, {}, step 1, from {})",
filename, argv[0], argv[1],
(argv[2] ? argv[2] : "(null)"), from);
SPDLOG_LOGGER_DEBUG(
log_v2::rrd(), "RRD: create file '{}' ({}, {}, {}, step 1, from {})",
filename, argv[0], argv[1], (argv[2] ? argv[2] : "(null)"), from);

// Create RRD file.
rrd_clear_error();
if (rrd_create_r(filename.c_str(), 1, from, argc, argv))
throw exceptions::open("RRD: could not create file '{}: {}", filename,
rrd_get_error());

// by default rrd_create_r create rw-r----- files group write is mandatory
// for rrdcached
std::error_code err;
std::filesystem::permissions(
filename,
std::filesystem::perms::group_read | std::filesystem::perms::group_write,
std::filesystem::perm_options::add, err);
if (err) {
SPDLOG_LOGGER_ERROR(log_v2::rrd(),
"RRD: fail to add access rights (660) to {}: {}",
filename, err.message());
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion broker/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ target_link_libraries(
CONAN_PKG::gtest
CONAN_PKG::mariadb-connector-c
CONAN_PKG::openssl
CONAN_PKG::grpc)
CONAN_PKG::grpc
stdc++fs)

add_dependencies(ut_broker
test_util
Expand Down
19 changes: 4 additions & 15 deletions cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ for i in $(cat conanfile.txt) ; do
fi
done

STD=gnu14
STD=gnu17
COMPILER=gcc
CC=gcc
CXX=g++
Expand All @@ -42,11 +42,6 @@ do
force=1
shift
;;
-ng)
echo "C++17 applied on this compilation"
STD="gnu17"
shift
;;
-r|--release)
echo "Release build"
BUILD_TYPE="Release"
Expand Down Expand Up @@ -315,16 +310,10 @@ cd build
echo "$conan install .. --build=missing"
$conan install .. --build=missing

if [[ $STD -eq gnu17 ]] ; then
NG="-DNG=ON"
else
NG="-DNG=OFF"
fi

if [[ "$maj" == "Raspbian" ]] ; then
CC=$CC CXX=$CXX CXXFLAGS="-Wall -Wextra" $cmake -DWITH_CLANG=$WITH_CLANG -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_TESTING=On -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF $NG $* ..
CC=$CC CXX=$CXX CXXFLAGS="-Wall -Wextra" $cmake -DWITH_CLANG=$WITH_CLANG -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_TESTING=On -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF $* ..
elif [[ "$maj" == "Debian" ]] ; then
CC=$CC CXX=$CXX CXXFLAGS="-Wall -Wextra" $cmake -DWITH_CLANG=$WITH_CLANG -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_LIB_CLIB=/usr/lib64/ -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF -DWITH_CONF=OFF $NG $* ..
CC=$CC CXX=$CXX CXXFLAGS="-Wall -Wextra" $cmake -DWITH_CLANG=$WITH_CLANG -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_PREFIX_LIB_CLIB=/usr/lib64/ -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF -DWITH_CONF=OFF $* ..
else
CC=$CC CXX=$CXX CXXFLAGS="-Wall -Wextra" $cmake -DWITH_CLANG=$WITH_CLANG -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF -DWITH_CONF=OFF $NG $* ..
CC=$CC CXX=$CXX CXXFLAGS="-Wall -Wextra" $cmake -DWITH_CLANG=$WITH_CLANG -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_USER_BROKER=centreon-broker -DWITH_USER_ENGINE=centreon-engine -DWITH_GROUP_BROKER=centreon-broker -DWITH_GROUP_ENGINE=centreon-engine -DWITH_TESTING=On -DWITH_MODULE_SIMU=On -DWITH_BENCH=On -DWITH_CREATE_FILES=OFF -DWITH_CONF=OFF $* ..
fi
7 changes: 6 additions & 1 deletion tests/broker-engine/rrd.robot
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,10 @@ BRRDRMU1
${result} Compare RRD Average Value ${m} ${value}
Should Be True
... ${result}
... msg=Data before RRD rebuild contain alternatively the metric ID and 0. The expected average is metric_id / 2.
... Data before RRD rebuild contain alternatively the metric ID and 0. The expected average is metric_id / 2.
# 48 = 60(octal)
${result} Has File Permissions ${VarRoot}/lib/centreon/metrics/${m}.rrd 48
Should Be True ${result} ${VarRoot}/lib/centreon/metrics/${m}.rrd has not RW group permission
END

Rrd_1
Expand Down Expand Up @@ -420,3 +423,5 @@ Rrd_1
${content1} Create List mysql_connection: You have an error in your SQL syntax
${result} Find In Log With Timeout ${rrdLog} ${start} ${content1} 45
Should Not Be True ${result} Database did not receive command to rebuild metrics


15 changes: 15 additions & 0 deletions tests/resources/Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1333,3 +1333,18 @@ def wait_until_file_modified(path: str, date: str, timeout: int = TIMEOUT):

logger.console(f"{path} not modified since {date}")
return False


def has_file_permissions(path: str, permission: int):
"""! test if file has permission passed in parameter
it does a AND with permission parameter
@param path path of the file
@permission mask to test file permission
@return True if the file has the requested permissions
"""
stat_res= os.stat(path)
if stat_res is None:
logger.console(f"fail to get permission of {path}")
return False
masked = stat_res.st_mode & permission
return masked == permission

0 comments on commit e2e1a1f

Please sign in to comment.