@cryptotaxi247 / netdata-1 / commits / dca98ffaf

Windows compatibility (P1) (#21972)

thiagoftsm committed Jun 3, 2026 at 17:20 UTC dca98ffaf021485d5f1a20ae1b37ebc2f2ac2b1b
31 files changed +302 -204
CMakeLists.txt
+3
@@ -1166,6 +1166,9 @@ set(LIBNETDATA_FILES
1166 src/libnetdata/log/nd_log-common.h
1167 src/libnetdata/log/nd_log-to-windows-common.h
1168 src/libnetdata/common.h
1169 + src/libnetdata/libnetdata-base.h
1170 + src/libnetdata/libnetdata-types.h
1171 + src/libnetdata/libnetdata-platform-fwd.h
1172 src/libnetdata/xxHash/xxhash.h
1173 src/libnetdata/os/random.c
1174 src/libnetdata/os/random.h
src/libnetdata/common.h
+3 -147
@@ -14,43 +14,13 @@
14 extern "C" {
15 # endif
16
17 -#include "config.h"
18 -
19 -#if defined(NETDATA_DEV_MODE) && !defined(NETDATA_INTERNAL_CHECKS)
20 -#define NETDATA_INTERNAL_CHECKS 1
21 -#endif
22 -
23 -#ifndef SIZEOF_VOID_P
24 -#error SIZEOF_VOID_P is not defined
25 -#endif
26 -
27 -#if SIZEOF_VOID_P == 4
28 -#define ENV32BIT 1
29 -#else
30 -#define ENV64BIT 1
31 -#endif
32 -
33 -#ifdef HAVE_LIBDATACHANNEL
34 -#define ENABLE_WEBRTC 1
35 -#endif
36 -
37 -#define STRINGIFY(x) #x
38 -#define TOSTRING(x) STRINGIFY(x)
17 +#include "libnetdata-base.h"
18 +#include "libnetdata-types.h"
19 +#include "libnetdata-platform-fwd.h"
20
21 // --------------------------------------------------------------------------------------------------------------------
22 // NETDATA_OS_TYPE
23
43 -#if defined(__FreeBSD__)
44 -#include <pthread_np.h>
45 -#define NETDATA_OS_TYPE "freebsd"
46 -#elif defined(__APPLE__)
47 -#define NETDATA_OS_TYPE "macos"
48 -#elif defined(OS_WINDOWS)
49 -#define NETDATA_OS_TYPE "windows"
50 -#else
51 -#define NETDATA_OS_TYPE "linux"
52 -#endif /* __FreeBSD__, __APPLE__*/
53 -
24 // --------------------------------------------------------------------------------------------------------------------
25 // memory allocators
26
@@ -246,12 +216,6 @@ typedef uint32_t uid_t;
216 #include <math.h>
217 #include <float.h>
218
249 -#if defined(HAVE_INTTYPES_H)
250 -#include <inttypes.h>
251 -#elif defined(HAVE_STDINT_H)
252 -#include <stdint.h>
253 -#endif
254 -
219 #include <zlib.h>
220
221 #ifdef HAVE_CAPABILITY
@@ -290,69 +254,6 @@ typedef uint32_t uid_t;
254 #define O_CLOEXEC (0)
255 #endif
256
293 -// --------------------------------------------------------------------------------------------------------------------
294 -// FUNCTION ATTRIBUTES
295 -
296 -#define _cleanup_(x) __attribute__((__cleanup__(x)))
297 -
298 -#ifdef HAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL
299 -#define NEVERNULL __attribute__((returns_nonnull))
300 -#else
301 -#define NEVERNULL
302 -#endif
303 -
304 -#ifdef HAVE_FUNC_ATTRIBUTE_NOINLINE
305 -#define NOINLINE __attribute__((noinline))
306 -#else
307 -#define NOINLINE
308 -#endif
309 -
310 -#ifdef HAVE_FUNC_ATTRIBUTE_MALLOC
311 -#define MALLOCLIKE __attribute__((malloc))
312 -#else
313 -#define MALLOCLIKE
314 -#endif
315 -
316 -#if defined(HAVE_FUNC_ATTRIBUTE_FORMAT_GNU_PRINTF)
317 -#define PRINTFLIKE(f, a) __attribute__ ((format(gnu_printf, f, a)))
318 -#elif defined(HAVE_FUNC_ATTRIBUTE_FORMAT_PRINTF)
319 -#define PRINTFLIKE(f, a) __attribute__ ((format(printf, f, a)))
320 -#else
321 -#define PRINTFLIKE(f, a)
322 -#endif
323 -
324 -#ifdef HAVE_FUNC_ATTRIBUTE_NORETURN
325 -#define NORETURN __attribute__ ((noreturn))
326 -#else
327 -#define NORETURN
328 -#endif
329 -
330 -#ifdef HAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT
331 -#define WARNUNUSED __attribute__ ((warn_unused_result))
332 -#else
333 -#define WARNUNUSED
334 -#endif
335 -
336 -#define UNUSED(x) (void)(x)
337 -
338 -#if defined(__GNUC__) && !defined(FSANITIZE_ADDRESS)
339 -#define UNUSED_FUNCTION(x) __attribute__((unused)) UNUSED_##x
340 -#define ALWAYS_INLINE_ONLY __attribute__((always_inline))
341 -#define ALWAYS_INLINE inline __attribute__((always_inline)) // Forces inlining
342 -#define ALWAYS_INLINE_HOT inline __attribute__((hot, always_inline)) // Encourages optimization and forces inlining
343 -#define ALWAYS_INLINE_HOT_FLATTEN inline __attribute__((hot, always_inline, flatten)) // Encourages optimization and forces inlining and flattening
344 -#define NOT_INLINE_HOT __attribute__((hot)) // Encourages optimization but doesn’t force inlining.
345 -#define NEVER_INLINE __attribute__((noinline))
346 -#else
347 -#define UNUSED_FUNCTION(x) UNUSED_##x
348 -#define ALWAYS_INLINE_ONLY
349 -#define ALWAYS_INLINE inline
350 -#define ALWAYS_INLINE_HOT inline
351 -#define ALWAYS_INLINE_HOT_FLATTEN inline
352 -#define NOT_INLINE_HOT
353 -#define NEVER_INLINE
354 -#endif
355 -
257 // --------------------------------------------------------------------------------------------------------------------
258 // fix for alpine linux
259
@@ -360,34 +261,6 @@ typedef uint32_t uid_t;
261 #define RUSAGE_THREAD RUSAGE_CHILDREN
262 #endif
263
363 -// --------------------------------------------------------------------------------------------------------------------
364 -// HELPFUL MACROS
365 -
366 -#define ABS(x) (((x) < 0)? (-(x)) : (x))
367 -#define MIN(a,b) (((a)<(b))?(a):(b))
368 -#define MAX(a,b) (((a)>(b))?(a):(b))
369 -#define SWAP(a, b) do { \
370 - typeof(a) _tmp = b; \
371 - b = a; \
372 - a = _tmp; \
373 -} while(0)
374 -
375 -// returns the number of times the divider fits into the total
376 -// if the divider is 0, it is treated as 1 (it returns total)
377 -#define HOWMANY(total, divider) ({ \
378 - typeof(total) _t = (total); \
379 - typeof(total) _d = (divider); \
380 - _d = _d ? _d : 1; \
381 - (_t + (_d - 1)) / _d; \
382 -})
383 -
384 -#define FIT_IN_RANGE(value, min, max) ({ \
385 - typeof(value) _v = (value); \
386 - typeof(min) _min = (min); \
387 - typeof(max) _max = (max); \
388 - (_v < _min) ? _min : ((_v > _max) ? _max : _v); \
389 -})
390 -
264 // --------------------------------------------------------------------------------------------------------------------
265 // NETDATA CLOUD
266
@@ -399,12 +272,6 @@ typedef uint32_t uid_t;
272
273 #define RRD_STORAGE_TIERS 5
274
402 -// --------------------------------------------------------------------------------------------------------------------
403 -// PIPES
404 -
405 -#define PIPE_READ 0
406 -#define PIPE_WRITE 1
407 -
275 // --------------------------------------------------------------------------------------------------------------------
276 // UUIDs
277
@@ -417,17 +284,6 @@ typedef uint32_t uid_t;
284
285 // --------------------------------------------------------------------------------------------------------------------
286
420 -// Taken from linux kernel
421 -#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
422 -
423 -// --------------------------------------------------------------------------------------------------------------------
424 -
425 -#define CONCAT_INDIRECT(a, b) a##b
426 -#define CONCAT(a, b) CONCAT_INDIRECT(a, b)
427 -#define PAD64(type) uint8_t CONCAT(padding, __COUNTER__)[64 - sizeof(type)]; type
428 -
429 -// --------------------------------------------------------------------------------------------------------------------
430 -
287 #define FUNCTION_RUN_ONCE() { \
288 static bool __run_once = false; \
289 if (!__sync_bool_compare_and_swap(&__run_once, false, true)) { \
src/libnetdata/exit/exit_initiated.h
+1 -1
@@ -3,7 +3,7 @@
3 #ifndef NETDATA_EXIT_INITIATED_H
4 #define NETDATA_EXIT_INITIATED_H
5
6 -#include "../common.h"
6 +#include "../libnetdata-base.h"
7 #include "../template-enum.h"
8
9 typedef enum {
src/libnetdata/libnetdata-base.h new
+128
@@ -0,0 +1,128 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef LIBNETDATA_BASE_H
4 +#define LIBNETDATA_BASE_H
5 +
6 +#include "config.h"
7 +#include <stdbool.h>
8 +#include <stddef.h>
9 +#if defined(HAVE_INTTYPES_H)
10 +#include <inttypes.h>
11 +#elif defined(HAVE_STDINT_H)
12 +#include <stdint.h>
13 +#endif
14 +
15 +#if defined(NETDATA_DEV_MODE) && !defined(NETDATA_INTERNAL_CHECKS)
16 +#define NETDATA_INTERNAL_CHECKS 1
17 +#endif
18 +
19 +#ifndef SIZEOF_VOID_P
20 +#error SIZEOF_VOID_P is not defined
21 +#endif
22 +
23 +#if SIZEOF_VOID_P == 4
24 +#define ENV32BIT 1
25 +#else
26 +#define ENV64BIT 1
27 +#endif
28 +
29 +#ifdef HAVE_LIBDATACHANNEL
30 +#define ENABLE_WEBRTC 1
31 +#endif
32 +
33 +#define STRINGIFY(x) #x
34 +#define TOSTRING(x) STRINGIFY(x)
35 +
36 +#define _cleanup_(x) __attribute__((__cleanup__(x)))
37 +
38 +#ifdef HAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL
39 +#define NEVERNULL __attribute__((returns_nonnull))
40 +#else
41 +#define NEVERNULL
42 +#endif
43 +
44 +#ifdef HAVE_FUNC_ATTRIBUTE_NOINLINE
45 +#define NOINLINE __attribute__((noinline))
46 +#else
47 +#define NOINLINE
48 +#endif
49 +
50 +#ifdef HAVE_FUNC_ATTRIBUTE_MALLOC
51 +#define MALLOCLIKE __attribute__((malloc))
52 +#else
53 +#define MALLOCLIKE
54 +#endif
55 +
56 +#if defined(HAVE_FUNC_ATTRIBUTE_FORMAT_GNU_PRINTF)
57 +#define PRINTFLIKE(f, a) __attribute__ ((format(gnu_printf, f, a)))
58 +#elif defined(HAVE_FUNC_ATTRIBUTE_FORMAT_PRINTF)
59 +#define PRINTFLIKE(f, a) __attribute__ ((format(printf, f, a)))
60 +#else
61 +#define PRINTFLIKE(f, a)
62 +#endif
63 +
64 +#ifdef HAVE_FUNC_ATTRIBUTE_NORETURN
65 +#define NORETURN __attribute__ ((noreturn))
66 +#else
67 +#define NORETURN
68 +#endif
69 +
70 +#ifdef HAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT
71 +#define WARNUNUSED __attribute__ ((warn_unused_result))
72 +#else
73 +#define WARNUNUSED
74 +#endif
75 +
76 +#define UNUSED(x) (void)(x)
77 +
78 +#if defined(__GNUC__) && !defined(FSANITIZE_ADDRESS)
79 +#define UNUSED_FUNCTION(x) __attribute__((unused)) UNUSED_##x
80 +#define ALWAYS_INLINE_ONLY __attribute__((always_inline))
81 +#define ALWAYS_INLINE inline __attribute__((always_inline))
82 +#define ALWAYS_INLINE_HOT inline __attribute__((hot, always_inline))
83 +#define ALWAYS_INLINE_HOT_FLATTEN inline __attribute__((hot, always_inline, flatten))
84 +#define NOT_INLINE_HOT __attribute__((hot))
85 +#define NEVER_INLINE __attribute__((noinline))
86 +#else
87 +#define UNUSED_FUNCTION(x) UNUSED_##x
88 +#define ALWAYS_INLINE_ONLY
89 +#define ALWAYS_INLINE inline
90 +#define ALWAYS_INLINE_HOT inline
91 +#define ALWAYS_INLINE_HOT_FLATTEN inline
92 +#define NOT_INLINE_HOT
93 +#define NEVER_INLINE
94 +#endif
95 +
96 +#define ABS(x) (((x) < 0)? (-(x)) : (x))
97 +#define MIN(a,b) (((a)<(b))?(a):(b))
98 +#define MAX(a,b) (((a)>(b))?(a):(b))
99 +#define SWAP(a, b) do { \
100 + typeof(a) _tmp = b; \
101 + b = a; \
102 + a = _tmp; \
103 +} while(0)
104 +
105 +#define HOWMANY(total, divider) ({ \
106 + typeof(total) _t = (total); \
107 + typeof(total) _d = (divider); \
108 + _d = _d ? _d : 1; \
109 + (_t + (_d - 1)) / _d; \
110 +})
111 +
112 +#define FIT_IN_RANGE(value, min, max) ({ \
113 + typeof(value) _v = (value); \
114 + typeof(min) _min = (min); \
115 + typeof(max) _max = (max); \
116 + (_v < _min) ? _min : ((_v > _max) ? _max : _v); \
117 +})
118 +
119 +#define PIPE_READ 0
120 +#define PIPE_WRITE 1
121 +
122 +#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
123 +
124 +#define CONCAT_INDIRECT(a, b) a##b
125 +#define CONCAT(a, b) CONCAT_INDIRECT(a, b)
126 +#define PAD64(type) uint8_t CONCAT(padding, __COUNTER__)[64 - sizeof(type)]; type
127 +
128 +#endif // LIBNETDATA_BASE_H
src/libnetdata/libnetdata-platform-fwd.h new
+31
@@ -0,0 +1,31 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef LIBNETDATA_PLATFORM_FWD_H
4 +#define LIBNETDATA_PLATFORM_FWD_H
5 +
6 +#include "config.h"
7 +
8 +#if !defined(OS_LINUX) && !defined(OS_FREEBSD) && !defined(OS_MACOS) && !defined(OS_WINDOWS)
9 +#if defined(_WIN32)
10 +#define OS_WINDOWS 1
11 +#elif defined(__APPLE__)
12 +#define OS_MACOS 1
13 +#elif defined(__FreeBSD__)
14 +#define OS_FREEBSD 1
15 +#else
16 +#define OS_LINUX 1
17 +#endif
18 +#endif
19 +
20 +#if defined(OS_FREEBSD)
21 +#include <pthread_np.h>
22 +#define NETDATA_OS_TYPE "freebsd"
23 +#elif defined(OS_MACOS)
24 +#define NETDATA_OS_TYPE "macos"
25 +#elif defined(OS_WINDOWS)
26 +#define NETDATA_OS_TYPE "windows"
27 +#else
28 +#define NETDATA_OS_TYPE "linux"
29 +#endif
30 +
31 +#endif // LIBNETDATA_PLATFORM_FWD_H
src/libnetdata/libnetdata-types.h new
+14
@@ -0,0 +1,14 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef LIBNETDATA_TYPES_H
4 +#define LIBNETDATA_TYPES_H
5 +
6 +#include "config.h"
7 +
8 +#if defined(HAVE_INTTYPES_H)
9 +#include <inttypes.h>
10 +#elif defined(HAVE_STDINT_H)
11 +#include <stdint.h>
12 +#endif
13 +
14 +#endif // LIBNETDATA_TYPES_H
src/libnetdata/libnetdata.h
+5
@@ -65,6 +65,11 @@ struct web_buffer *run_command_and_get_output_to_buffer(const char *command, int
65 #include "string/string.h"
66 #include "buffer/buffer.h"
67
68 +#include "socket/security.h" // must be before windows.h
69 +
70 +// this may include windows.h
71 +#include "os/os.h"
72 +
73 #include "uuid/uuid.h"
74 #include "uuid/uuidmap.h"
75 #include "http/content_type.h"
src/libnetdata/log/systemd-journal-helpers.h
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "../common.h"
3 +#include "../libnetdata-base.h"
4
5 #ifndef NETDATA_LOG_SYSTEMD_JOURNAL_HELPERS_H
6 #define NETDATA_LOG_SYSTEMD_JOURNAL_HELPERS_H
src/libnetdata/memory/alignment.h
+1 -1
@@ -3,7 +3,7 @@
3 #ifndef NETDATA_ALIGNMENT_H
4 #define NETDATA_ALIGNMENT_H
5
6 -#include "../common.h"
6 +#include "../libnetdata-base.h"
7
8 #if ENV32BIT
9 #define SYSTEM_REQUIRED_ALIGNMENT (sizeof(uintptr_t) * 2)
src/libnetdata/os/boot_id.h
+1 -1
@@ -3,7 +3,7 @@
3 #ifndef NETDATA_OS_BOOT_ID_H
4 #define NETDATA_OS_BOOT_ID_H
5
6 -#include "libnetdata/common.h"
6 +#include "libnetdata/libnetdata-base.h"
7 #include "libnetdata/uuid/uuid.h"
8
9 /**
src/libnetdata/os/boottime.h
+2 -1
@@ -3,7 +3,8 @@
3 #ifndef NETDATA_BOOTTIME_H
4 #define NETDATA_BOOTTIME_H
5
6 -#include "libnetdata/common.h"
6 +#include "libnetdata/libnetdata-base.h"
7 +#include <time.h>
8
9 /**
10 * Get system boot time
src/libnetdata/os/file_lock.c
+48 -10
@@ -10,6 +10,51 @@
10
11 #if defined(OS_WINDOWS)
12 #include <windows.h>
13 +#include <stdlib.h>
14 +
15 +#if defined(__CYGWIN__) || defined(__MSYS__)
16 +#include <sys/types.h>
17 +#include <sys/cygwin.h>
18 +#endif
19 +
20 +static wchar_t *file_lock_utf8_to_utf16(const char *filename) {
21 + int wpath_size = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0);
22 + if(wpath_size <= 0)
23 + return NULL;
24 +
25 + wchar_t *wpath = malloc((size_t)wpath_size * sizeof(*wpath));
26 + if(!wpath)
27 + return NULL;
28 +
29 + if(MultiByteToWideChar(CP_UTF8, 0, filename, -1, wpath, wpath_size) <= 0) {
30 + free(wpath);
31 + return NULL;
32 + }
33 +
34 + return wpath;
35 +}
36 +
37 +static wchar_t *file_lock_windows_path(const char *filename) {
38 +#if defined(__CYGWIN__) || defined(__MSYS__)
39 + ssize_t wpath_size = cygwin_conv_path(CCP_POSIX_TO_WIN_W, filename, NULL, 0);
40 + if(wpath_size > 0) {
41 + wchar_t *wpath = malloc((size_t)wpath_size);
42 + if(!wpath)
43 + return NULL;
44 +
45 + if(cygwin_conv_path(CCP_POSIX_TO_WIN_W, filename, wpath, wpath_size) == 0)
46 + return wpath;
47 +
48 + free(wpath);
49 + }
50 +
51 + // Absolute POSIX-style paths require runtime translation before Win32 APIs can use them.
52 + if(filename[0] == '/')
53 + return NULL;
54 +#endif
55 +
56 + return file_lock_utf8_to_utf16(filename);
57 +}
58 #endif
59
60 FILE_LOCK file_lock_get(const char *filename) {
@@ -31,17 +76,10 @@ FILE_LOCK file_lock_get(const char *filename) {
76 return (FILE_LOCK){ .fd = fd };
77
78 #elif defined(OS_WINDOWS)
34 - // Convert MSYS2/Cygwin path directly to Windows wide-char path
35 - ssize_t wpath_size = cygwin_conv_path(CCP_POSIX_TO_WIN_W, filename, NULL, 0);
36 - if(wpath_size < 0)
79 + wchar_t *wpath = file_lock_windows_path(filename);
80 + if(!wpath)
81 return FILE_LOCK_INVALID;
82
39 - wchar_t *wpath = mallocz(wpath_size);
40 - if(cygwin_conv_path(CCP_POSIX_TO_WIN_W, filename, wpath, wpath_size) != 0) {
41 - freez(wpath);
42 - return FILE_LOCK_INVALID;
43 - }
44 -
83 // Open existing file or create new one
84 HANDLE hFile = CreateFileW(
85 wpath,
@@ -53,7 +91,7 @@ FILE_LOCK file_lock_get(const char *filename) {
91 NULL
92 );
93
56 - freez(wpath);
94 + free(wpath);
95
96 if(hFile == INVALID_HANDLE_VALUE)
97 return FILE_LOCK_INVALID;
src/libnetdata/os/file_lock.h
+6 -2
@@ -3,7 +3,11 @@
3 #ifndef NETDATA_FILE_LOCK_H
4 #define NETDATA_FILE_LOCK_H
5
6 -#include "libnetdata/libnetdata.h"
6 +#include "libnetdata/libnetdata-platform-fwd.h"
7 +
8 +#if defined(OS_WINDOWS)
9 +#include <windows.h>
10 +#endif
11
12 typedef struct file_lock {
13 #if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_MACOS)
@@ -31,7 +35,7 @@ typedef struct file_lock {
35 * when the process exits or if the process crashes. Only one process can hold the lock
36 * at a time.
37 *
34 - * @param filename UTF-8 encoded filename (MSYS2 path format on Windows)
38 + * @param filename UTF-8 encoded filename (MSYS2/Cygwin path format or native Windows path on Windows)
39 * @return FILE_LOCK The lock handle. Use FILE_LOCK_OK() to check if lock was acquired
40 */
41 FILE_LOCK file_lock_get(const char *filename);
src/libnetdata/os/get_system_pagesize.c
+3 -1
@@ -21,6 +21,8 @@ size_t os_get_system_page_size(void) {
21
22 #else
23
24 +#include <unistd.h>
25 +
26 size_t os_get_system_page_size(void) {
27 static long int page_size = 0;
28
@@ -33,4 +35,4 @@ size_t os_get_system_page_size(void) {
35 return page_size;
36 }
37
36 -#endif
\ No newline at end of file
38 +#endif
src/libnetdata/os/get_system_pagesize.h
+1 -1
@@ -3,7 +3,7 @@
3 #ifndef NETDATA_GET_SYSTEM_PAGESIZE_H
4 #define NETDATA_GET_SYSTEM_PAGESIZE_H
5
6 -#include "../common.h"
6 +#include "../libnetdata-base.h"
7
8 size_t os_get_system_page_size(void) __attribute__((const));
9
src/libnetdata/os/mmap_limit.h
+1 -1
@@ -3,7 +3,7 @@
3 #ifndef NETDATA_MMAP_LIMIT_H
4 #define NETDATA_MMAP_LIMIT_H
5
6 -#include "libnetdata/common.h"
6 +#include "libnetdata/libnetdata-base.h"
7
8 unsigned long long os_mmap_limit(void);
9
src/libnetdata/os/os.h
+3
@@ -56,6 +56,9 @@ extern const char *os_type;
56 extern unsigned int system_hz;
57 void os_get_system_HZ(void);
58
59 +// Forward declaration needed because this header uses strncpyz() before inlined.h is included.
60 +static char *strncpyz(char *dst, const char *src, size_t dst_size_minus_1);
61 +
62 #if defined(OS_WINDOWS)
63 char *os_translate_path(char *dst, const char *src, size_t dst_size);
64 char *os_translate_msys_to_windows_path(const char *src);
src/libnetdata/os/random.h
+1 -1
@@ -3,7 +3,7 @@
3 #ifndef NETDATA_RANDOM_H
4 #define NETDATA_RANDOM_H
5
6 -#include "libnetdata/common.h"
6 +#include "libnetdata/libnetdata-base.h"
7
8 // fill a buffer with random bytes
9 void os_random_bytes(void *buf, size_t bytes);
src/libnetdata/os/uuid_generate.c
+12 -8
@@ -6,19 +6,23 @@
6 #undef uuid_generate_time
7
8 #ifdef OS_WINDOWS
9 -void os_uuid_generate(void *out) {
10 - RPC_STATUS status = UuidCreate(out);
9 +void os_uuid_generate(nd_uuid_t out) {
10 + // nd_uuid_t is byte-aligned storage, so use aligned local UUID storage
11 + // before copying the generated bytes to the caller's output buffer.
12 + UUID uuid;
13 + RPC_STATUS status = UuidCreate(&uuid);
14 while (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) {
15 tinysleep();
13 - status = UuidCreate(out);
16 + status = UuidCreate(&uuid);
17 }
18 + memcpy(out, &uuid, sizeof(uuid));
19 }
20
17 -void os_uuid_generate_random(void *out) {
21 +void os_uuid_generate_random(nd_uuid_t out) {
22 os_uuid_generate(out);
23 }
24
21 -void os_uuid_generate_time(void *out) {
25 +void os_uuid_generate_time(nd_uuid_t out) {
26 os_uuid_generate(out);
27 }
28
@@ -30,17 +34,17 @@ void os_uuid_generate_time(void *out) {
34 #include <uuid.h>
35 #endif
36
33 -void os_uuid_generate(void *out) {
37 +void os_uuid_generate(nd_uuid_t out) {
38 // IMPORTANT: this generates a UUIDv4, which is random
39 // and falls back to uuid_generate_time() if high resolution random generated is not available
40 uuid_generate(out);
41 }
42
39 -void os_uuid_generate_random(void *out) {
43 +void os_uuid_generate_random(nd_uuid_t out) {
44 uuid_generate_random(out);
45 }
46
43 -void os_uuid_generate_time(void *out) {
47 +void os_uuid_generate_time(nd_uuid_t out) {
48 // IMPORTANT: this generates a UUIDv1, which is not random and may suffer from collisions
49 uuid_generate_time(out);
50 }
src/libnetdata/os/uuid_generate.h
+5 -3
@@ -3,8 +3,10 @@
3 #ifndef NETDATA_UUID_GENERATE_H
4 #define NETDATA_UUID_GENERATE_H
5
6 -void os_uuid_generate(void *out);
7 -void os_uuid_generate_random(void *out);
8 -void os_uuid_generate_time(void *out);
6 +#include "libnetdata/uuid/uuid.h"
7 +
8 +void os_uuid_generate(nd_uuid_t out);
9 +void os_uuid_generate_random(nd_uuid_t out);
10 +void os_uuid_generate_time(nd_uuid_t out);
11
12 #endif //NETDATA_UUID_GENERATE_H
src/libnetdata/signals/signal-code.h
+2 -2
@@ -3,7 +3,7 @@
3 #ifndef NETDATA_SIGNAL_CODE_H
4 #define NETDATA_SIGNAL_CODE_H
5
6 -#include "libnetdata/common.h"
6 +#include "libnetdata/libnetdata-base.h"
7 #include "../template-enum.h"
8
9 // SIGNAL_CODE combines signal number and signal code into a single 64-bit identifier
@@ -24,4 +24,4 @@ void SIGNAL_CODE_2str_h(SIGNAL_CODE code, char *buf, size_t size);
24 // parse a signal code from a string, by name or hex
25 SIGNAL_CODE SIGNAL_CODE_2id_h(const char *str);
26
27 -#endif /* NETDATA_SIGNAL_CODE_H */
\ No newline at end of file
27 +#endif /* NETDATA_SIGNAL_CODE_H */
src/libnetdata/signals/signals.h
+1 -1
@@ -3,7 +3,7 @@
3 #ifndef NETDATA_SIGNALS_H
4 #define NETDATA_SIGNALS_H
5
6 -#include "../common.h"
6 +#include "../libnetdata-base.h"
7
8 void signals_block_all_except_deadly(void);
9 void signals_block_all(void);
src/libnetdata/socket/nd-poll.c
+1
@@ -1,5 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 +#include "../libnetdata.h"
4 #include "nd-poll.h"
5
6 #ifndef POLLRDHUP
src/libnetdata/socket/nd-poll.h
+1 -3
@@ -3,7 +3,7 @@
3 #ifndef NETDATA_ND_POLL_H
4 #define NETDATA_ND_POLL_H
5
6 -#include "libnetdata/common.h"
6 +#include "libnetdata/libnetdata-base.h"
7
8 typedef enum __attribute__((packed)) {
9 ND_POLL_NONE = 0,
@@ -41,6 +41,4 @@ bool nd_poll_upd(nd_poll_t *ndpl, int fd, nd_poll_event_t events);
41 // returns -1 = error, 0 = timeout, 1 = event in result
42 int nd_poll_wait(nd_poll_t *ndpl, int timeout_ms, nd_poll_result_t *result);
43
44 -#include "libnetdata/libnetdata.h"
45 -
44 #endif //NETDATA_ND_POLL_H
src/libnetdata/spawn_server/log-forwarder.h
+1 -1
@@ -3,7 +3,7 @@
3 #ifndef NETDATA_LOG_FORWARDER_H
4 #define NETDATA_LOG_FORWARDER_H
5
6 -#include "../libnetdata.h"
6 +#include "../common.h"
7
8 typedef struct LOG_FORWARDER LOG_FORWARDER;
9
src/libnetdata/spawn_server/spawn_library.c
+1
@@ -1,5 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 +#include "../libnetdata.h"
4 #include "spawn_library.h"
5
6 BUFFER *argv_to_cmdline_buffer(const char **argv) {
src/libnetdata/spawn_server/spawn_library.h
+1 -1
@@ -3,7 +3,7 @@
3 #ifndef NETDATA_SPAWN_LIBRARY_H
4 #define NETDATA_SPAWN_LIBRARY_H
5
6 -#include "../libnetdata.h"
6 +#include "../exit/exit_initiated.h"
7
8 BUFFER *argv_to_cmdline_buffer(const char **argv);
9
src/libnetdata/spawn_server/spawn_server.h
+2
@@ -3,6 +3,8 @@
3 #ifndef SPAWN_SERVER_H
4 #define SPAWN_SERVER_H
5
6 +#include "../common.h"
7 +
8 #define SPAWN_SERVER_TRANSFER_FDS 4
9
10 typedef enum __attribute__((packed)) {
src/libnetdata/stacktrace/stacktrace.h
+2 -1
@@ -3,7 +3,7 @@
3 #ifndef NETDATA_STACKTRACE_H
4 #define NETDATA_STACKTRACE_H 1
5
6 -#include "libnetdata/common.h"
6 +#include "libnetdata/libnetdata-base.h"
7
8 #define STACK_TRACE_INFO_PREFIX "info: "
9
@@ -30,6 +30,7 @@ bool stacktrace_available(void);
30
31 // Capture a stacktrace to a buffer
32 struct web_buffer;
33 +typedef struct web_buffer BUFFER;
34 void stacktrace_capture(BUFFER *wb);
35
36 // Return a string describing the backend used for capturing stacktraces
src/libnetdata/threads/threads.h
+18 -16
@@ -3,7 +3,9 @@
3 #ifndef NETDATA_THREADS_H
4 #define NETDATA_THREADS_H 1
5
6 -#include "../libnetdata.h"
6 +#include "../libnetdata-base.h"
7 +#include <pthread.h>
8 +#include <signal.h>
9
10 typedef enum __attribute__((packed)) {
11 NETDATA_THREAD_OPTION_DEFAULT = 0 << 0,
@@ -56,9 +58,9 @@ struct netdata_static_thread {
58 bool *global_variable;
59 };
60
59 -#define NETDATA_MAIN_THREAD_RUNNING CONFIG_BOOLEAN_YES
60 -#define NETDATA_MAIN_THREAD_EXITING (CONFIG_BOOLEAN_YES + 1)
61 -#define NETDATA_MAIN_THREAD_EXITED CONFIG_BOOLEAN_NO
61 +#define NETDATA_MAIN_THREAD_RUNNING 1
62 +#define NETDATA_MAIN_THREAD_EXITING 2
63 +#define NETDATA_MAIN_THREAD_EXITED 0
64
65 #define NETDATA_THREAD_TAG_MAX 100
66 const char *nd_thread_tag(void);
@@ -109,18 +111,18 @@ void nd_thread_rwspinlock_read_unlocked(void);
111 void nd_thread_rwspinlock_write_locked(void);
112 void nd_thread_rwspinlock_write_unlocked(void);
113 #else
112 -#define nd_thread_rwlock_read_locked() debug_dummy()
113 -#define nd_thread_rwlock_read_unlocked() debug_dummy()
114 -#define nd_thread_rwlock_write_locked() debug_dummy()
115 -#define nd_thread_rwlock_write_unlocked() debug_dummy()
116 -#define nd_thread_mutex_locked() debug_dummy()
117 -#define nd_thread_mutex_unlocked() debug_dummy()
118 -#define nd_thread_spinlock_locked() debug_dummy()
119 -#define nd_thread_spinlock_unlocked() debug_dummy()
120 -#define nd_thread_rwspinlock_read_locked() debug_dummy()
121 -#define nd_thread_rwspinlock_read_unlocked() debug_dummy()
122 -#define nd_thread_rwspinlock_write_locked() debug_dummy()
123 -#define nd_thread_rwspinlock_write_unlocked() debug_dummy()
114 +#define nd_thread_rwlock_read_locked() ((void)0)
115 +#define nd_thread_rwlock_read_unlocked() ((void)0)
116 +#define nd_thread_rwlock_write_locked() ((void)0)
117 +#define nd_thread_rwlock_write_unlocked() ((void)0)
118 +#define nd_thread_mutex_locked() ((void)0)
119 +#define nd_thread_mutex_unlocked() ((void)0)
120 +#define nd_thread_spinlock_locked() ((void)0)
121 +#define nd_thread_spinlock_unlocked() ((void)0)
122 +#define nd_thread_rwspinlock_read_locked() ((void)0)
123 +#define nd_thread_rwspinlock_read_unlocked() ((void)0)
124 +#define nd_thread_rwspinlock_write_locked() ((void)0)
125 +#define nd_thread_rwspinlock_write_unlocked() ((void)0)
126 #endif
127
128 void nd_thread_can_run_sql(bool exclude);
src/libnetdata/uuid/uuid.h
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_UUID_H
4 #define NETDATA_UUID_H
5
6 +#include <string.h>
7 +
8 // for compatibility with libuuid
9 typedef unsigned char nd_uuid_t[16];
10