Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect cygwin or foreign OSes #17440

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 18 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,21 +221,31 @@ set(LINUX False)
set(FREEBSD False)
set(MACOS False)

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(MACOS True)
set(COMPILED_FOR_MACOS True)

find_library(IOKIT IOKit)
find_library(FOUNDATION Foundation)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
set(FREEBSD True)
set(COMPILED_FOR_FREEBSD True)
else()
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(LINUX True)
set(COMPILED_FOR_LINUX True)
add_definitions(-D_GNU_SOURCE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN")
set(CYGWIN True)
set(COMPILED_FOR_CYGWIN True)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "MSYS")
set(MSYS True)
set(COMPILED_FOR_MSYS True)
else()
set(FOREIGN_OS True)
set(COMPILED_FOR_FOREIGN_OS True)
endif()

message(INFO "Detected CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}")

#
# Libm
#
Expand Down Expand Up @@ -1313,6 +1323,10 @@ elseif(FREEBSD)
${FREEBSD_PLUGIN_FILES}
${TIMEX_PLUGIN_FILES}
)
elseif(FOREIGN_OS)
list(APPEND NETDATA_FILES
src/daemon/static_threads_windows.c
)
endif()

set(MQTT_WEBSOCKETS_FILES
Expand Down
30 changes: 30 additions & 0 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

set -exu -o pipefail

Check warning on line 3 in compile.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] reported by reviewdog 🐶 In POSIX sh, set option pipefail is undefined. Raw Output: ./compile.sh:3:13: warning: In POSIX sh, set option pipefail is undefined. (ShellCheck.SC3040)

export PATH="/usr/local/bin:${PATH}"

WT_ROOT="$(pwd)"
WT_PREFIX="/tmp"
BUILD_TYPE="Debug"

if [ -d "${WT_ROOT}/build" ]
then
rm -rf "${WT_ROOT}/build"
fi

/usr/bin/cmake -S "${WT_ROOT}" -B "${WT_ROOT}/build" \
-G Ninja \
-DCMAKE_INSTALL_PREFIX="${WT_PREFIX}" \
-DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \
-DCMAKE_C_FLAGS="-O0 -ggdb -Wall -Wextra -Wno-char-subscripts -DNETDATA_INTERNAL_CHECKS=1" \
-DNETDATA_USER="${USER}" \
-DDEFAULT_FEATURE_STATE=Off \
-DENABLE_H2O=Off \
-DENABLE_LOGS_MANAGEMENT_TESTS=Off \
-DENABLE_ACLK=On \
-DENABLE_BUNDLED_PROTOBUF=Off \
# -DENABLE_MQTTWEBSOCKETS=On \

Check failure on line 27 in compile.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] reported by reviewdog 🐶 This backslash is part of a comment and does not continue the line. Raw Output: ./compile.sh:27:34: error: This backslash is part of a comment and does not continue the line. (ShellCheck.SC1143)


ninja -v -C build || ninja -v -C build -j 1
17 changes: 11 additions & 6 deletions packaging/cmake/Modules/NetdataProtobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ macro(netdata_detect_protobuf)
# logic for the old FindProtobuf module while others do not.
#
# Upstream bug reference: https://gitlab.kitware.com/cmake/cmake/-/issues/24321
find_package(Protobuf CONFIG)
# find_package(Protobuf CONFIG)

if(NOT TARGET protobuf::libprotobuf)
message(STATUS "Could not find Protobuf using Config mode, falling back to Module mode")
find_package(Protobuf REQUIRED)
# find_package(Protobuf REQUIRED)
endif()
endif()

Expand Down Expand Up @@ -163,10 +163,15 @@ macro(netdata_detect_protobuf)
set(NETDATA_PROTOBUF_INCLUDE_DIRS "")
endif()
else()
set(NETDATA_PROTOBUF_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE})
set(NETDATA_PROTOBUF_CFLAGS_OTHER ${PROTOBUF_CFLAGS_OTHER})
set(NETDATA_PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS})
set(NETDATA_PROTOBUF_LIBS ${PROTOBUF_LIBRARIES})
# set(NETDATA_PROTOBUF_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE})
# set(NETDATA_PROTOBUF_CFLAGS_OTHER ${PROTOBUF_CFLAGS_OTHER})
# set(NETDATA_PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS})
# set(NETDATA_PROTOBUF_LIBS ${PROTOBUF_LIBRARIES})

set(NETDATA_PROTOBUF_PROTOC_EXECUTABLE "/bin/protoc")
set(NETDATA_PROTOBUF_CFLAGS_OTHER "")
set(NETDATA_PROTOBUF_INCLUDE_DIRS "")
set(NETDATA_PROTOBUF_LIBS "-lprotobuf")
endif()

set(ENABLE_PROTOBUF True)
Expand Down
3 changes: 3 additions & 0 deletions packaging/cmake/config.cmake.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#cmakedefine COMPILED_FOR_FREEBSD
#cmakedefine COMPILED_FOR_LINUX
#cmakedefine COMPILED_FOR_MACOS
#cmakedefine COMPILED_FOR_CYGWIN
#cmakedefine COMPILED_FOR_MSYS
#cmakedefine COMPILED_FOR_FOREIGN_OS

// checked headers

Expand Down
8 changes: 8 additions & 0 deletions src/daemon/buildinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,14 @@ __attribute__((constructor)) void initialize_build_info(void) {
build_info_set_value(BIB_FEATURE_BUILT_FOR, "MacOS");
build_info_set_status(BIB_PLUGIN_MACOS, true);
#endif
#ifdef COMPILED_FOR_CYGWIN
build_info_set_status(BIB_FEATURE_BUILT_FOR, true);
build_info_set_value(BIB_FEATURE_BUILT_FOR, "Cygwin");
#endif
#ifdef COMPILED_FOR_MSYS
build_info_set_status(BIB_FEATURE_BUILT_FOR, true);
build_info_set_value(BIB_FEATURE_BUILT_FOR, "MSYS");
#endif

#ifdef ENABLE_ACLK
build_info_set_status(BIB_FEATURE_CLOUD, true);
Expand Down
8 changes: 8 additions & 0 deletions src/daemon/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static void prepare_required_directories(uid_t uid, gid_t gid) {
clean_directory(netdata_configured_lock_dir);
}

#if 0
static int become_user(const char *username, int pid_fd) {
int am_i_root = (getuid() == 0)?1:0;

Expand Down Expand Up @@ -186,6 +187,13 @@ static int become_user(const char *username, int pid_fd) {

return(0);
}
#else
static int become_user(const char *username, int pid_fd) {
UNUSED(username);
UNUSED(pid_fd);
return 0;
}
#endif

#ifndef OOM_SCORE_ADJ_MAX
#define OOM_SCORE_ADJ_MAX (1000)
Expand Down
2 changes: 2 additions & 0 deletions src/daemon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2104,8 +2104,10 @@ int main(int argc, char **argv) {
delta_startup_time("become daemon");

// fork, switch user, create pid file, set process priority
#if 0
if(become_daemon(dont_fork, user) == -1)
fatal("Cannot daemonize myself.");
#endif

watcher_thread_start();

Expand Down
1 change: 1 addition & 0 deletions src/daemon/static_threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern const struct netdata_static_thread static_threads_common[];
extern const struct netdata_static_thread static_threads_linux[];
extern const struct netdata_static_thread static_threads_freebsd[];
extern const struct netdata_static_thread static_threads_macos[];
extern const struct netdata_static_thread static_threads_windows[];

struct netdata_static_thread *
static_threads_concat(const struct netdata_static_thread *lhs,
Expand Down
4 changes: 4 additions & 0 deletions src/daemon/static_threads_freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const struct netdata_static_thread static_threads_macos[] = {
{NULL, NULL, NULL, 0, NULL, NULL, NULL}
};

const struct netdata_static_thread static_threads_windows[] = {
{NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL}
};

struct netdata_static_thread *static_threads_get() {
return static_threads_concat(static_threads_common, static_threads_freebsd);
}
4 changes: 4 additions & 0 deletions src/daemon/static_threads_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ const struct netdata_static_thread static_threads_macos[] = {
}
};

const struct netdata_static_thread static_threads_windows[] = {
{NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL}
};

struct netdata_static_thread *static_threads_get() {
return static_threads_concat(static_threads_common, static_threads_linux);
}
4 changes: 4 additions & 0 deletions src/daemon/static_threads_macos.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ const struct netdata_static_thread static_threads_linux[] = {
{NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL}
};

const struct netdata_static_thread static_threads_windows[] = {
{NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL}
};

struct netdata_static_thread *static_threads_get() {
return static_threads_concat(static_threads_common, static_threads_macos);
}
63 changes: 63 additions & 0 deletions src/daemon/static_threads_windows.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "common.h"

const struct netdata_static_thread static_threads_linux[] = {
// terminator
{
.name = NULL,
.config_section = NULL,
.config_name = NULL,
.env_name = NULL,
.enabled = 0,
.thread = NULL,
.init_routine = NULL,
.start_routine = NULL
}
};

const struct netdata_static_thread static_threads_freebsd[] = {
// terminator
{
.name = NULL,
.config_section = NULL,
.config_name = NULL,
.env_name = NULL,
.enabled = 0,
.thread = NULL,
.init_routine = NULL,
.start_routine = NULL
}
};

const struct netdata_static_thread static_threads_macos[] = {
// terminator
{
.name = NULL,
.config_section = NULL,
.config_name = NULL,
.env_name = NULL,
.enabled = 0,
.thread = NULL,
.init_routine = NULL,
.start_routine = NULL
}
};

const struct netdata_static_thread static_threads_windows[] = {
// terminator
{
.name = NULL,
.config_section = NULL,
.config_name = NULL,
.env_name = NULL,
.enabled = 0,
.thread = NULL,
.init_routine = NULL,
.start_routine = NULL
}
};

struct netdata_static_thread *static_threads_get() {
return static_threads_concat(static_threads_common, static_threads_windows);
}
16 changes: 10 additions & 6 deletions src/database/engine/rrdengineapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
#include "dbengine-compression.h"

/* Default global database instance */
struct rrdengine_instance multidb_ctx_storage_tier0;
struct rrdengine_instance multidb_ctx_storage_tier1;
struct rrdengine_instance multidb_ctx_storage_tier2;
struct rrdengine_instance multidb_ctx_storage_tier3;
struct rrdengine_instance multidb_ctx_storage_tier4;
struct rrdengine_instance multidb_ctx_storage_tier0 = { 0 };
struct rrdengine_instance multidb_ctx_storage_tier1 = { 0 };
struct rrdengine_instance multidb_ctx_storage_tier2 = { 0 };
struct rrdengine_instance multidb_ctx_storage_tier3 = { 0 };
struct rrdengine_instance multidb_ctx_storage_tier4 = { 0 };

#define mrg_metric_ctx(metric) (struct rrdengine_instance *)mrg_metric_section(main_mrg, metric)

#if RRD_STORAGE_TIERS != 5
#error RRD_STORAGE_TIERS is not 5 - you need to add allocations here
#endif
struct rrdengine_instance *multidb_ctx[RRD_STORAGE_TIERS];
struct rrdengine_instance *multidb_ctx[RRD_STORAGE_TIERS] = { 0 };
uint8_t tier_page_type[RRD_STORAGE_TIERS] = {
RRDENG_PAGE_TYPE_GORILLA_32BIT,
RRDENG_PAGE_TYPE_ARRAY_TIER1,
Expand Down Expand Up @@ -46,6 +46,10 @@ __attribute__((constructor)) void initialize_multidb_ctx(void) {
multidb_ctx[2] = &multidb_ctx_storage_tier2;
multidb_ctx[3] = &multidb_ctx_storage_tier3;
multidb_ctx[4] = &multidb_ctx_storage_tier4;

for(int i = 0; i < RRD_STORAGE_TIERS ; i++) {
uv_rwlock_init(&multidb_ctx[i]->datafiles.rwlock);
}
}

int db_engine_journal_check = 0;
Expand Down
4 changes: 4 additions & 0 deletions src/libnetdata/libnetdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,12 +1125,16 @@ inline int madvise_random(void *mem, size_t len) {
}

inline int madvise_dontfork(void *mem, size_t len) {
#ifdef MADV_DONTFORK
static int logger = 1;
int ret = madvise(mem, len, MADV_DONTFORK);

if (ret != 0 && logger-- > 0)
netdata_log_error("madvise(MADV_DONTFORK) failed.");
return ret;
#else
return 0;
#endif
}

inline int madvise_willneed(void *mem, size_t len) {
Expand Down
2 changes: 1 addition & 1 deletion src/libnetdata/libnetdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ extern "C" {
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/syscall.h>
// #include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
Expand Down
5 changes: 5 additions & 0 deletions src/libnetdata/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,8 @@ int getsysctl_by_name(const char *name, void *ptr, size_t len) {
const char *os_type = "linux";

#endif


#ifdef COMPILED_FOR_FOREIGN_OS
const char *os_type = "windows";
#endif
2 changes: 1 addition & 1 deletion src/libnetdata/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pid_t get_system_pid_max(void);
extern unsigned int system_hz;
void get_system_HZ(void);

#include <sys/timex.h>
// #include <sys/timex.h>
#if defined(__FreeBSD__) || defined(__APPLE__)
#define ADJUST_TIMEX(x) ntp_adjtime(x)
#else
Expand Down
2 changes: 1 addition & 1 deletion src/libnetdata/popen/popen.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int netdata_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) {
}
else {
// we haven't reaped this child yet
ret = waitid(idtype, id, infop, options);
// ret = waitid(idtype, id, infop, options);

if(mp && !mp->reaped) {
mp->reaped = true;
Expand Down
15 changes: 15 additions & 0 deletions src/libnetdata/popen/popen.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

#include "../libnetdata.h"

# define WSTOPPED 2 /* Report stopped child (same as WUNTRACED). */
# define WEXITED 4 /* Report dead child. */
# define WCONTINUED 8 /* Report continued child. */
# define WNOWAIT 0x01000000 /* Don't reap, just poll status. */

#define PIPE_READ 0
#define PIPE_WRITE 1

Expand All @@ -28,6 +33,16 @@ int netdata_popene_variadic_internal_dont_use_directly(volatile pid_t *pidptr, c
int netdata_pclose(FILE *fp_child_input, FILE *fp_child_output, pid_t pid);

int netdata_spawn(const char *command, volatile pid_t *pidptr);

typedef enum
{
P_ALL, /* Wait for any child. */
P_PID, /* Wait for specified process. */
P_PGID, /* Wait for members of process group. */
P_PIDFD, /* Wait for the child referred by the PID file
descriptor. */
} idtype_t;

int netdata_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);

#endif /* NETDATA_POPEN_H */