From 647288c374ae12de34295a8e0f3a4e6a9e3f79b9 Mon Sep 17 00:00:00 2001 From: David Boucher Date: Fri, 19 Jul 2024 05:09:37 -0400 Subject: [PATCH] fix(engine/tests): gettimeofday changed its signature since alma9 --- CMakeLists.txt | 11 +++++++++- engine/tests/timeperiod/utils.cc | 4 ++++ engine/tests/timeperiod/utils.hh | 36 ++++++++++++++++---------------- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d1d77a11b5..3259d1f05dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,7 +105,7 @@ set(BUILD_ARGS "-w" "dupbuild=warn") # Get distributions name # if(CMAKE_SYSTEM_NAME STREQUAL "Linux") - file(STRINGS "/etc/os-release" release REGEX "^ID") + file(STRINGS "/etc/os-release" release REGEX "ID") foreach(line ${release}) if(${line} MATCHES "ID_LIKE=.*") @@ -115,6 +115,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") if(${line} MATCHES "ID=.*") string(REGEX REPLACE "ID=\"(.*)\"" "\\1" id ${line}) endif() + + if(${line} MATCHES "VERSION_ID=.*") + string(REGEX REPLACE "VERSION_ID=\"([0-9]+)\..*" "\\1" os_version ${line}) + endif() endforeach() string(TOLOWER "${like}" like) @@ -135,6 +139,11 @@ else() set(OS_DISTRIBUTOR "${CMAKE_SYSTEM_NAME}") endif() +if(OS_DISTRIBUTOR STREQUAL "CentOS" AND os_version STREQUAL "8") + message(STATUS "Legacy gettimeofday") + add_definitions("-DLEGACY_GETTIMEOFDAY") +endif() + message(STATUS "${id} detected (compatible with ${OS_DISTRIBUTOR})") # set -latomic if OS is Raspbian. diff --git a/engine/tests/timeperiod/utils.cc b/engine/tests/timeperiod/utils.cc index c1c2113953e..bd77c4f7b85 100644 --- a/engine/tests/timeperiod/utils.cc +++ b/engine/tests/timeperiod/utils.cc @@ -368,7 +368,11 @@ extern "C" time_t time(time_t* t) __THROW { return (gl_now); } +#ifdef LEGACY_GETTIMEOFDAY +extern "C" int gettimeofday(struct timeval* tv, struct timezone*) __THROW { +#else extern "C" int gettimeofday(struct timeval* tv, void*) __THROW { +#endif // extern "C" int gettimeofday(struct timeval* tv, struct timezone*) __THROW { if (tv) { tv->tv_sec = gl_now; diff --git a/engine/tests/timeperiod/utils.hh b/engine/tests/timeperiod/utils.hh index 964e3ec0d5d..da07b395dbb 100644 --- a/engine/tests/timeperiod/utils.hh +++ b/engine/tests/timeperiod/utils.hh @@ -1,21 +1,21 @@ -/* -** Copyright 2016 Centreon -** -** This file is part of Centreon Engine. -** -** Centreon Engine is free software: you can redistribute it and/or -** modify it under the terms of the GNU General Public License version 2 -** as published by the Free Software Foundation. -** -** Centreon Engine is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Centreon Engine. If not, see -** . -*/ +/** + * Copyright 2016-2024 Centreon + * + * This file is part of Centreon Engine. + * + * Centreon Engine is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * Centreon Engine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Centreon Engine. If not, see + * . + */ #ifndef TESTS_TIMEPERIOD_UTILS_HH #define TESTS_TIMEPERIOD_UTILS_HH