Browse Source

include windows.h globally in libnetdata (#18878)

* include windows.h globally in libnetdata

* LF newlines

* global static variable only if needed

* remove individual includes of windows.h and related headers

* fixes for nt internals
Costa Tsaousis 4 months ago
parent
commit
c7b9f5235e

+ 19 - 19
src/aclk/mqtt_websockets/mqtt_ng.c

@@ -64,12 +64,12 @@ struct transaction_buffer {
 };
 
 enum mqtt_client_state {
-    RAW = 0,
-    CONNECT_PENDING,
-    CONNECTING,
-    CONNECTED, 
-    ERROR,
-    DISCONNECTED
+    MQTT_STATE_RAW = 0,
+    MQTT_STATE_CONNECT_PENDING,
+    MQTT_STATE_CONNECTING,
+    MQTT_STATE_CONNECTED,
+    MQTT_STATE_ERROR,
+    MQTT_STATE_DISCONNECTED
 };
 
 enum parser_state {
@@ -957,7 +957,7 @@ int mqtt_ng_connect(struct mqtt_ng_client *client,
                     uint8_t clean_start,
                     uint16_t keep_alive)
 {
-    client->client_state = RAW;
+    client->client_state = MQTT_STATE_RAW;
     client->parser.state = MQTT_PARSE_FIXED_HEADER_PACKET_TYPE;
 
     LOCK_HDR_BUFFER(&client->main_buffer);
@@ -992,7 +992,7 @@ int mqtt_ng_connect(struct mqtt_ng_client *client,
     client->stats.rx_messages_rcvd = 0;
     spinlock_unlock(&client->stats_spinlock);
 
-    client->client_state = CONNECT_PENDING;
+    client->client_state = MQTT_STATE_CONNECT_PENDING;
     return 0;
 }
 
@@ -1834,12 +1834,12 @@ static int parse_data(struct mqtt_ng_client *client)
 // return -1 on error
 // return 0 if there is fragment set
 static int mqtt_ng_next_to_send(struct mqtt_ng_client *client) {
-    if (client->client_state == CONNECT_PENDING) {
+    if (client->client_state == MQTT_STATE_CONNECT_PENDING) {
         client->main_buffer.sending_frag = client->connect_msg;
-        client->client_state = CONNECTING;
+        client->client_state = MQTT_STATE_CONNECTING;
         return 0;
     }
-    if (client->client_state != CONNECTED)
+    if (client->client_state != MQTT_STATE_CONNECTED)
         return -1;
 
     struct buffer_fragment *frag = BUFFER_FIRST_FRAG(&client->main_buffer.hdr_buffer);
@@ -1970,9 +1970,9 @@ int handle_incoming_traffic(struct mqtt_ng_client *client)
 
             client->connect_msg = NULL;
 
-            if (client->client_state != CONNECTING) {
+            if (client->client_state != MQTT_STATE_CONNECTING) {
                 nd_log(NDLS_DAEMON, NDLP_ERR, "Received unexpected CONNACK");
-                client->client_state = ERROR;
+                client->client_state = MQTT_STATE_ERROR;
                 return MQTT_NG_CLIENT_PROTOCOL_ERROR;
             }
 
@@ -1985,10 +1985,10 @@ int handle_incoming_traffic(struct mqtt_ng_client *client)
                 client->connack_callback(client->user_ctx, client->parser.mqtt_packet.connack.reason_code);
             if (!client->parser.mqtt_packet.connack.reason_code) {
                 nd_log(NDLS_DAEMON, NDLP_INFO, "MQTT Connection Accepted By Server");
-                client->client_state = CONNECTED;
+                client->client_state = MQTT_STATE_CONNECTED;
                 break;
             }
-            client->client_state = ERROR;
+            client->client_state = MQTT_STATE_ERROR;
             return MQTT_NG_CLIENT_SERVER_RETURNED_ERROR;
 
         case MQTT_CPT_PUBACK:
@@ -2016,7 +2016,7 @@ int handle_incoming_traffic(struct mqtt_ng_client *client)
             }
 
             if ( pub->qos == 1 && ((rc = mqtt_ng_puback(client, pub->packet_id, 0))) ) {
-                client->client_state = ERROR;
+                client->client_state = MQTT_STATE_ERROR;
                 nd_log(NDLS_DAEMON, NDLP_ERR, "Error generating PUBACK reply for PUBLISH");
                 return rc;
             }
@@ -2050,7 +2050,7 @@ int handle_incoming_traffic(struct mqtt_ng_client *client)
 
         case MQTT_CPT_DISCONNECT:
             nd_log(NDLS_DAEMON, NDLP_INFO, "Got MQTT DISCONNECT control packet from server. Reason code: %d", (int)client->parser.mqtt_packet.disconnect.reason_code);
-            client->client_state = DISCONNECTED;
+            client->client_state = MQTT_STATE_DISCONNECTED;
             break;
 
         default:
@@ -2063,10 +2063,10 @@ int handle_incoming_traffic(struct mqtt_ng_client *client)
 
 int mqtt_ng_sync(struct mqtt_ng_client *client)
 {
-    if (client->client_state == RAW || client->client_state == DISCONNECTED)
+    if (client->client_state == MQTT_STATE_RAW || client->client_state == MQTT_STATE_DISCONNECTED)
         return 0;
     
-    if (client->client_state == ERROR)
+    if (client->client_state == MQTT_STATE_ERROR)
         return 1;
 
     LOCK_HDR_BUFFER(&client->main_buffer);

+ 0 - 5
src/aclk/mqtt_websockets/ws_client.c

@@ -5,11 +5,6 @@
 #include "ws_client.h"
 #include "common_internal.h"
 
-#ifdef OS_WINDOWS
-#include <windows.h>
-#include <bcrypt.h>  // For BCryptGenRandom
-#endif
-
 static uint32_t generate_random_32bit(void) {
     uint32_t random_number = 0;
 

+ 41 - 44
src/collectors/apps.plugin/apps_os_windows_nt.c

@@ -1,44 +1,41 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// this must not include libnetdata.h because STRING is defined in winternl.h
-
-#include "config.h"
-#if defined(OS_WINDOWS)
-
-#include <windows.h>
-#include <winternl.h>
-#include <psapi.h>
-#include <stdint.h>
-
-// --------------------------------------------------------------------------------------------------------------------
-// Get the full windows command line
-
-WCHAR* GetProcessCommandLine(HANDLE hProcess) {
-    PROCESS_BASIC_INFORMATION pbi;
-    ULONG len;
-    NTSTATUS status = NtQueryInformationProcess(hProcess, 0, &pbi, sizeof(pbi), &len);
-    if (status != 0)
-        return NULL;
-
-    // The rest of the function remains the same as before
-    PEB peb;
-    if (!ReadProcessMemory(hProcess, pbi.PebBaseAddress, &peb, sizeof(peb), NULL))
-        return NULL;
-
-    RTL_USER_PROCESS_PARAMETERS procParams;
-    if (!ReadProcessMemory(hProcess, peb.ProcessParameters, &procParams, sizeof(procParams), NULL))
-        return NULL;
-
-    WCHAR* commandLine = (WCHAR*)malloc(procParams.CommandLine.MaximumLength);
-    if (!commandLine)
-        return NULL;
-
-    if (!ReadProcessMemory(hProcess, procParams.CommandLine.Buffer, commandLine, procParams.CommandLine.MaximumLength, NULL)) {
-        free(commandLine);
-        return NULL;
-    }
-
-    return commandLine;
-}
-
-#endif
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+// this must not include libnetdata.h because STRING is defined in winternl.h
+
+#include "libnetdata/common.h"
+
+#if defined(OS_WINDOWS)
+#include <winternl.h>
+
+// --------------------------------------------------------------------------------------------------------------------
+// Get the full windows command line
+
+WCHAR* GetProcessCommandLine(HANDLE hProcess) {
+    PROCESS_BASIC_INFORMATION pbi;
+    ULONG len;
+    NTSTATUS status = NtQueryInformationProcess(hProcess, 0, &pbi, sizeof(pbi), &len);
+    if (status != 0)
+        return NULL;
+
+    // The rest of the function remains the same as before
+    PEB peb;
+    if (!ReadProcessMemory(hProcess, pbi.PebBaseAddress, &peb, sizeof(peb), NULL))
+        return NULL;
+
+    RTL_USER_PROCESS_PARAMETERS procParams;
+    if (!ReadProcessMemory(hProcess, peb.ProcessParameters, &procParams, sizeof(procParams), NULL))
+        return NULL;
+
+    WCHAR* commandLine = (WCHAR*)malloc(procParams.CommandLine.MaximumLength);
+    if (!commandLine)
+        return NULL;
+
+    if (!ReadProcessMemory(hProcess, procParams.CommandLine.Buffer, commandLine, procParams.CommandLine.MaximumLength, NULL)) {
+        free(commandLine);
+        return NULL;
+    }
+
+    return commandLine;
+}
+
+#endif

+ 0 - 2
src/collectors/apps.plugin/apps_plugin.h

@@ -85,8 +85,6 @@ struct pid_info {
 #define OS_FUNCTION(func) OS_FUNC_CONCAT(func, _macos)
 
 #elif defined(OS_WINDOWS)
-#include <windows.h>
-
 #define OS_INIT_PID                          0 // dynamic, is set during data collection
 #define ALL_PIDS_ARE_READ_INSTANTLY          1
 #define PROCESSES_HAVE_CPU_GUEST_TIME        0

+ 0 - 2
src/collectors/windows-events.plugin/windows-events-unicode.h

@@ -4,8 +4,6 @@
 #define NETDATA_WINDOWS_EVENTS_UNICODE_H
 
 #include "libnetdata/libnetdata.h"
-#include <windows.h>
-#include <wchar.h>
 
 #define WINEVENT_NAME_KEYWORDS_SEPARATOR    ", "
 static inline void txt_utf8_add_keywords_separator_if_needed(TXT_UTF8 *dst) {

+ 0 - 3
src/collectors/windows-events.plugin/windows-events.h

@@ -5,9 +5,6 @@
 
 #include "libnetdata/libnetdata.h"
 #include "collectors/all.h"
-#include <windows.h>
-#include <winevt.h>
-#include <wchar.h>
 
 typedef enum {
     WEVT_NO_CHANNEL_MATCHED,

+ 0 - 1
src/collectors/windows.plugin/perflib-rrd.c

@@ -1,7 +1,6 @@
 // SPDX-License-Identifier: GPL-3.0-or-later
 
 #include "perflib-rrd.h"
-#include <windows.h>
 
 #define COLLECTED_NUMBER_PRECISION 10000
 

+ 1 - 1
src/collectors/windows.plugin/windows-internals.h

@@ -3,7 +3,7 @@
 #ifndef NETDATA_WINDOWS_INTERNALS_H
 #define NETDATA_WINDOWS_INTERNALS_H
 
-#include <windows.h>
+#include "libnetdata/common.h"
 
 static inline ULONGLONG FileTimeToULL(FILETIME ft) {
     ULARGE_INTEGER ul;

+ 0 - 2
src/daemon/winsvc.cc

@@ -8,8 +8,6 @@ void nd_process_signals(void);
 
 }
 
-#include <windows.h>
-
 __attribute__((format(printf, 1, 2)))
 static void netdata_service_log(const char *fmt, ...)
 {

+ 420 - 394
src/libnetdata/common.h

@@ -1,394 +1,420 @@
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-#ifndef LIBNETDATA_COMMON_H
-#define LIBNETDATA_COMMON_H
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-#include "config.h"
-
-#if defined(NETDATA_DEV_MODE) && !defined(NETDATA_INTERNAL_CHECKS)
-#define NETDATA_INTERNAL_CHECKS 1
-#endif
-
-#ifndef SIZEOF_VOID_P
-#error SIZEOF_VOID_P is not defined
-#endif
-
-#if SIZEOF_VOID_P == 4
-#define ENV32BIT 1
-#else
-#define ENV64BIT 1
-#endif
-
-#ifdef HAVE_LIBDATACHANNEL
-#define ENABLE_WEBRTC 1
-#endif
-
-#define STRINGIFY(x) #x
-#define TOSTRING(x) STRINGIFY(x)
-
-// --------------------------------------------------------------------------------------------------------------------
-// NETDATA_OS_TYPE
-
-#if defined(__FreeBSD__)
-#include <pthread_np.h>
-#define NETDATA_OS_TYPE "freebsd"
-#elif defined(__APPLE__)
-#define NETDATA_OS_TYPE "macos"
-#elif defined(OS_WINDOWS)
-#define NETDATA_OS_TYPE "windows"
-#else
-#define NETDATA_OS_TYPE "linux"
-#endif /* __FreeBSD__, __APPLE__*/
-
-// --------------------------------------------------------------------------------------------------------------------
-// memory allocators
-
-/* select the memory allocator, based on autoconf findings */
-#if defined(ENABLE_JEMALLOC)
-
-#if defined(HAVE_JEMALLOC_JEMALLOC_H)
-#include <jemalloc/jemalloc.h>
-#else // !defined(HAVE_JEMALLOC_JEMALLOC_H)
-#include <malloc.h>
-#endif // !defined(HAVE_JEMALLOC_JEMALLOC_H)
-
-#elif defined(ENABLE_TCMALLOC)
-
-#include <google/tcmalloc.h>
-
-#else /* !defined(ENABLE_JEMALLOC) && !defined(ENABLE_TCMALLOC) */
-
-#if !(defined(__FreeBSD__) || defined(__APPLE__))
-#include <malloc.h>
-#endif /* __FreeBSD__ || __APPLE__ */
-
-#endif /* !defined(ENABLE_JEMALLOC) && !defined(ENABLE_TCMALLOC) */
-
-// --------------------------------------------------------------------------------------------------------------------
-
-#include <pthread.h>
-#include <errno.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <ctype.h>
-#include <string.h>
-#include <strings.h>
-#include <libgen.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <getopt.h>
-#include <limits.h>
-#include <locale.h>
-#include <signal.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <time.h>
-#include <unistd.h>
-#include <uv.h>
-#include <assert.h>
-
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
-#ifdef HAVE_NETINET_TCP_H
-#include <netinet/tcp.h>
-#endif
-
-#ifdef HAVE_SYS_IOCTL_H
-#include <sys/ioctl.h>
-#endif
-
-#ifdef HAVE_GRP_H
-#include <grp.h>
-#else
-typedef uint32_t gid_t;
-#endif
-
-#ifdef HAVE_PWD_H
-#include <pwd.h>
-#else
-typedef uint32_t uid_t;
-#endif
-
-#ifdef HAVE_NET_IF_H
-#include <net/if.h>
-#endif
-
-#ifdef HAVE_POLL_H
-#include <poll.h>
-#endif
-
-#ifdef HAVE_SYSLOG_H
-#include <syslog.h>
-#else
-/* priorities */
-#define	LOG_EMERG	0	/* system is unusable */
-#define	LOG_ALERT	1	/* action must be taken immediately */
-#define	LOG_CRIT	2	/* critical conditions */
-#define	LOG_ERR		3	/* error conditions */
-#define	LOG_WARNING	4	/* warning conditions */
-#define	LOG_NOTICE	5	/* normal but significant condition */
-#define	LOG_INFO	6	/* informational */
-#define	LOG_DEBUG	7	/* debug-level messages */
-
-/* facility codes */
-#define	LOG_KERN	(0<<3)	/* kernel messages */
-#define	LOG_USER	(1<<3)	/* random user-level messages */
-#define	LOG_MAIL	(2<<3)	/* mail system */
-#define	LOG_DAEMON	(3<<3)	/* system daemons */
-#define	LOG_AUTH	(4<<3)	/* security/authorization messages */
-#define	LOG_SYSLOG	(5<<3)	/* messages generated internally by syslogd */
-#define	LOG_LPR		(6<<3)	/* line printer subsystem */
-#define	LOG_NEWS	(7<<3)	/* network news subsystem */
-#define	LOG_UUCP	(8<<3)	/* UUCP subsystem */
-#define	LOG_CRON	(9<<3)	/* clock daemon */
-#define	LOG_AUTHPRIV	(10<<3)	/* security/authorization messages (private) */
-#define	LOG_FTP		(11<<3)	/* ftp daemon */
-
-/* other codes through 15 reserved for system use */
-#define	LOG_LOCAL0	(16<<3)	/* reserved for local use */
-#define	LOG_LOCAL1	(17<<3)	/* reserved for local use */
-#define	LOG_LOCAL2	(18<<3)	/* reserved for local use */
-#define	LOG_LOCAL3	(19<<3)	/* reserved for local use */
-#define	LOG_LOCAL4	(20<<3)	/* reserved for local use */
-#define	LOG_LOCAL5	(21<<3)	/* reserved for local use */
-#define	LOG_LOCAL6	(22<<3)	/* reserved for local use */
-#define	LOG_LOCAL7	(23<<3)	/* reserved for local use */
-#endif
-
-#ifdef HAVE_SYS_MMAN_H
-#include <sys/mman.h>
-#endif
-
-#ifdef HAVE_SYS_RESOURCE_H
-#include <sys/resource.h>
-#endif
-
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#ifdef HAVE_SYS_WAIT_H
-#include <sys/wait.h>
-#endif
-
-#ifdef HAVE_SYS_UN_H
-#include <sys/un.h>
-#endif
-
-#ifdef HAVE_SPAWN_H
-#include <spawn.h>
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-#ifdef HAVE_RESOLV_H
-#include <resolv.h>
-#endif
-
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif
-
-#ifdef HAVE_SYS_PRCTL_H
-#include <sys/prctl.h>
-#endif
-
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
-#ifdef HAVE_SYS_VFS_H
-#include <sys/vfs.h>
-#endif
-
-#ifdef HAVE_SYS_STATFS_H
-#include <sys/statfs.h>
-#endif
-
-#ifdef HAVE_LINUX_MAGIC_H
-#include <linux/magic.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
-#include <sys/mount.h>
-#endif
-
-#ifdef HAVE_SYS_STATVFS_H
-#include <sys/statvfs.h>
-#endif
-
-// #1408
-#ifdef MAJOR_IN_MKDEV
-#include <sys/mkdev.h>
-#endif
-#ifdef MAJOR_IN_SYSMACROS
-#include <sys/sysmacros.h>
-#endif
-
-#include <math.h>
-#include <float.h>
-
-#if defined(HAVE_INTTYPES_H)
-#include <inttypes.h>
-#elif defined(HAVE_STDINT_H)
-#include <stdint.h>
-#endif
-
-#include <zlib.h>
-
-#ifdef HAVE_SYS_CAPABILITY_H
-#include <sys/capability.h>
-#endif
-
-#define XXH_INLINE_ALL
-#include "xxHash/xxhash.h"
-
-// --------------------------------------------------------------------------------------------------------------------
-// OpenSSL
-
-#define OPENSSL_VERSION_095 0x00905100L
-#define OPENSSL_VERSION_097 0x0907000L
-#define OPENSSL_VERSION_110 0x10100000L
-#define OPENSSL_VERSION_111 0x10101000L
-#define OPENSSL_VERSION_300 0x30000000L
-
-#include <openssl/ssl.h>
-#include <openssl/rand.h>
-#include <openssl/err.h>
-#include <openssl/evp.h>
-#include <openssl/pem.h>
-#if (SSLEAY_VERSION_NUMBER >= OPENSSL_VERSION_097) && (OPENSSL_VERSION_NUMBER < OPENSSL_VERSION_110)
-#include <openssl/conf.h>
-#endif
-
-#if OPENSSL_VERSION_NUMBER >= OPENSSL_VERSION_300
-#include <openssl/core_names.h>
-#include <openssl/decoder.h>
-#endif
-
-// --------------------------------------------------------------------------------------------------------------------
-
-#ifndef O_CLOEXEC
-#define O_CLOEXEC (0)
-#endif
-
-// --------------------------------------------------------------------------------------------------------------------
-// FUNCTION ATTRIBUTES
-
-#define _cleanup_(x) __attribute__((__cleanup__(x)))
-
-#ifdef HAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL
-#define NEVERNULL __attribute__((returns_nonnull))
-#else
-#define NEVERNULL
-#endif
-
-#ifdef HAVE_FUNC_ATTRIBUTE_NOINLINE
-#define NOINLINE __attribute__((noinline))
-#else
-#define NOINLINE
-#endif
-
-#ifdef HAVE_FUNC_ATTRIBUTE_MALLOC
-#define MALLOCLIKE __attribute__((malloc))
-#else
-#define MALLOCLIKE
-#endif
-
-#if defined(HAVE_FUNC_ATTRIBUTE_FORMAT_GNU_PRINTF)
-#define PRINTFLIKE(f, a) __attribute__ ((format(gnu_printf, f, a)))
-#elif defined(HAVE_FUNC_ATTRIBUTE_FORMAT_PRINTF)
-#define PRINTFLIKE(f, a) __attribute__ ((format(printf, f, a)))
-#else
-#define PRINTFLIKE(f, a)
-#endif
-
-#ifdef HAVE_FUNC_ATTRIBUTE_NORETURN
-#define NORETURN __attribute__ ((noreturn))
-#else
-#define NORETURN
-#endif
-
-#ifdef HAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT
-#define WARNUNUSED __attribute__ ((warn_unused_result))
-#else
-#define WARNUNUSED
-#endif
-
-#define UNUSED(x) (void)(x)
-
-#ifdef __GNUC__
-#define UNUSED_FUNCTION(x) __attribute__((unused)) UNUSED_##x
-#else
-#define UNUSED_FUNCTION(x) UNUSED_##x
-#endif
-
-// --------------------------------------------------------------------------------------------------------------------
-// fix for alpine linux
-
-#if !defined(RUSAGE_THREAD) && defined(RUSAGE_CHILDREN)
-#define RUSAGE_THREAD RUSAGE_CHILDREN
-#endif
-
-// --------------------------------------------------------------------------------------------------------------------
-// HELPFUL MACROS
-
-#define ABS(x) (((x) < 0)? (-(x)) : (x))
-#define MIN(a,b) (((a)<(b))?(a):(b))
-#define MAX(a,b) (((a)>(b))?(a):(b))
-#define SWAP(a, b) do { \
-    typeof(a) _tmp = b; \
-    b = a;              \
-    a = _tmp;           \
-} while(0)
-
-// --------------------------------------------------------------------------------------------------------------------
-// NETDATA CLOUD
-
-// BEWARE: this exists in alarm-notify.sh
-#define DEFAULT_CLOUD_BASE_URL "https://app.netdata.cloud"
-
-// --------------------------------------------------------------------------------------------------------------------
-// DBENGINE
-
-#define RRD_STORAGE_TIERS 5
-
-// --------------------------------------------------------------------------------------------------------------------
-// PIPES
-
-#define PIPE_READ 0
-#define PIPE_WRITE 1
-
-// --------------------------------------------------------------------------------------------------------------------
-// UUIDs
-
-#define GUID_LEN 36
-
-// --------------------------------------------------------------------------------------------------------------------
-// Macro-only includes
-
-#include "linked_lists/linked_lists.h"
-
-// --------------------------------------------------------------------------------------------------------------------
-
-// Taken from linux kernel
-#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
-
-// --------------------------------------------------------------------------------------------------------------------
-
-# ifdef __cplusplus
-}
-# endif
-
-#endif //LIBNETDATA_COMMON_H
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+/*
+ * This file should include everything from the operating system needed to compile Netdata,
+ * without any Netdata specific includes.
+ *
+ * It should be the baseline of includes (operating system and common libraries related).
+ */
+
+#ifndef LIBNETDATA_COMMON_H
+#define LIBNETDATA_COMMON_H
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+#include "config.h"
+
+#if defined(NETDATA_DEV_MODE) && !defined(NETDATA_INTERNAL_CHECKS)
+#define NETDATA_INTERNAL_CHECKS 1
+#endif
+
+#ifndef SIZEOF_VOID_P
+#error SIZEOF_VOID_P is not defined
+#endif
+
+#if SIZEOF_VOID_P == 4
+#define ENV32BIT 1
+#else
+#define ENV64BIT 1
+#endif
+
+#ifdef HAVE_LIBDATACHANNEL
+#define ENABLE_WEBRTC 1
+#endif
+
+#define STRINGIFY(x) #x
+#define TOSTRING(x) STRINGIFY(x)
+
+// --------------------------------------------------------------------------------------------------------------------
+// NETDATA_OS_TYPE
+
+#if defined(__FreeBSD__)
+#include <pthread_np.h>
+#define NETDATA_OS_TYPE "freebsd"
+#elif defined(__APPLE__)
+#define NETDATA_OS_TYPE "macos"
+#elif defined(OS_WINDOWS)
+#define NETDATA_OS_TYPE "windows"
+#else
+#define NETDATA_OS_TYPE "linux"
+#endif /* __FreeBSD__, __APPLE__*/
+
+// --------------------------------------------------------------------------------------------------------------------
+// memory allocators
+
+/* select the memory allocator, based on autoconf findings */
+#if defined(ENABLE_JEMALLOC)
+
+#if defined(HAVE_JEMALLOC_JEMALLOC_H)
+#include <jemalloc/jemalloc.h>
+#else // !defined(HAVE_JEMALLOC_JEMALLOC_H)
+#include <malloc.h>
+#endif // !defined(HAVE_JEMALLOC_JEMALLOC_H)
+
+#elif defined(ENABLE_TCMALLOC)
+
+#include <google/tcmalloc.h>
+
+#else /* !defined(ENABLE_JEMALLOC) && !defined(ENABLE_TCMALLOC) */
+
+#if !(defined(__FreeBSD__) || defined(__APPLE__))
+#include <malloc.h>
+#endif /* __FreeBSD__ || __APPLE__ */
+
+#endif /* !defined(ENABLE_JEMALLOC) && !defined(ENABLE_TCMALLOC) */
+
+// --------------------------------------------------------------------------------------------------------------------
+
+#include <pthread.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <ctype.h>
+#include <string.h>
+#include <strings.h>
+#include <libgen.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <limits.h>
+#include <locale.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
+#include <uv.h>
+#include <assert.h>
+
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+
+#ifdef HAVE_NETINET_TCP_H
+#include <netinet/tcp.h>
+#endif
+
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+
+#ifdef HAVE_GRP_H
+#include <grp.h>
+#else
+typedef uint32_t gid_t;
+#endif
+
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#else
+typedef uint32_t uid_t;
+#endif
+
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+
+#ifdef HAVE_POLL_H
+#include <poll.h>
+#endif
+
+#ifdef HAVE_SYSLOG_H
+#include <syslog.h>
+#else
+/* priorities */
+#define	LOG_EMERG	0	/* system is unusable */
+#define	LOG_ALERT	1	/* action must be taken immediately */
+#define	LOG_CRIT	2	/* critical conditions */
+#define	LOG_ERR		3	/* error conditions */
+#define	LOG_WARNING	4	/* warning conditions */
+#define	LOG_NOTICE	5	/* normal but significant condition */
+#define	LOG_INFO	6	/* informational */
+#define	LOG_DEBUG	7	/* debug-level messages */
+
+/* facility codes */
+#define	LOG_KERN	(0<<3)	/* kernel messages */
+#define	LOG_USER	(1<<3)	/* random user-level messages */
+#define	LOG_MAIL	(2<<3)	/* mail system */
+#define	LOG_DAEMON	(3<<3)	/* system daemons */
+#define	LOG_AUTH	(4<<3)	/* security/authorization messages */
+#define	LOG_SYSLOG	(5<<3)	/* messages generated internally by syslogd */
+#define	LOG_LPR		(6<<3)	/* line printer subsystem */
+#define	LOG_NEWS	(7<<3)	/* network news subsystem */
+#define	LOG_UUCP	(8<<3)	/* UUCP subsystem */
+#define	LOG_CRON	(9<<3)	/* clock daemon */
+#define	LOG_AUTHPRIV	(10<<3)	/* security/authorization messages (private) */
+#define	LOG_FTP		(11<<3)	/* ftp daemon */
+
+/* other codes through 15 reserved for system use */
+#define	LOG_LOCAL0	(16<<3)	/* reserved for local use */
+#define	LOG_LOCAL1	(17<<3)	/* reserved for local use */
+#define	LOG_LOCAL2	(18<<3)	/* reserved for local use */
+#define	LOG_LOCAL3	(19<<3)	/* reserved for local use */
+#define	LOG_LOCAL4	(20<<3)	/* reserved for local use */
+#define	LOG_LOCAL5	(21<<3)	/* reserved for local use */
+#define	LOG_LOCAL6	(22<<3)	/* reserved for local use */
+#define	LOG_LOCAL7	(23<<3)	/* reserved for local use */
+#endif
+
+#ifdef HAVE_SYS_MMAN_H
+#include <sys/mman.h>
+#endif
+
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
+
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#ifdef HAVE_SYS_WAIT_H
+#include <sys/wait.h>
+#endif
+
+#ifdef HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
+
+#ifdef HAVE_SPAWN_H
+#include <spawn.h>
+#endif
+
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
+#ifdef HAVE_RESOLV_H
+#include <resolv.h>
+#endif
+
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#ifdef HAVE_SYS_VFS_H
+#include <sys/vfs.h>
+#endif
+
+#ifdef HAVE_SYS_STATFS_H
+#include <sys/statfs.h>
+#endif
+
+#ifdef HAVE_LINUX_MAGIC_H
+#include <linux/magic.h>
+#endif
+
+#ifdef HAVE_SYS_MOUNT_H
+#include <sys/mount.h>
+#endif
+
+#ifdef HAVE_SYS_STATVFS_H
+#include <sys/statvfs.h>
+#endif
+
+// #1408
+#ifdef MAJOR_IN_MKDEV
+#include <sys/mkdev.h>
+#endif
+#ifdef MAJOR_IN_SYSMACROS
+#include <sys/sysmacros.h>
+#endif
+
+#include <math.h>
+#include <float.h>
+
+#if defined(HAVE_INTTYPES_H)
+#include <inttypes.h>
+#elif defined(HAVE_STDINT_H)
+#include <stdint.h>
+#endif
+
+#include <zlib.h>
+
+#ifdef HAVE_SYS_CAPABILITY_H
+#include <sys/capability.h>
+#endif
+
+#define XXH_INLINE_ALL
+#include "xxHash/xxhash.h"
+
+// --------------------------------------------------------------------------------------------------------------------
+// OpenSSL
+
+#define OPENSSL_VERSION_095 0x00905100L
+#define OPENSSL_VERSION_097 0x0907000L
+#define OPENSSL_VERSION_110 0x10100000L
+#define OPENSSL_VERSION_111 0x10101000L
+#define OPENSSL_VERSION_300 0x30000000L
+
+#include <openssl/ssl.h>
+#include <openssl/rand.h>
+#include <openssl/err.h>
+#include <openssl/evp.h>
+#include <openssl/pem.h>
+#if (SSLEAY_VERSION_NUMBER >= OPENSSL_VERSION_097) && (OPENSSL_VERSION_NUMBER < OPENSSL_VERSION_110)
+#include <openssl/conf.h>
+#endif
+
+#if OPENSSL_VERSION_NUMBER >= OPENSSL_VERSION_300
+#include <openssl/core_names.h>
+#include <openssl/decoder.h>
+#endif
+
+// --------------------------------------------------------------------------------------------------------------------
+
+#ifndef O_CLOEXEC
+#define O_CLOEXEC (0)
+#endif
+
+// --------------------------------------------------------------------------------------------------------------------
+// FUNCTION ATTRIBUTES
+
+#define _cleanup_(x) __attribute__((__cleanup__(x)))
+
+#ifdef HAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL
+#define NEVERNULL __attribute__((returns_nonnull))
+#else
+#define NEVERNULL
+#endif
+
+#ifdef HAVE_FUNC_ATTRIBUTE_NOINLINE
+#define NOINLINE __attribute__((noinline))
+#else
+#define NOINLINE
+#endif
+
+#ifdef HAVE_FUNC_ATTRIBUTE_MALLOC
+#define MALLOCLIKE __attribute__((malloc))
+#else
+#define MALLOCLIKE
+#endif
+
+#if defined(HAVE_FUNC_ATTRIBUTE_FORMAT_GNU_PRINTF)
+#define PRINTFLIKE(f, a) __attribute__ ((format(gnu_printf, f, a)))
+#elif defined(HAVE_FUNC_ATTRIBUTE_FORMAT_PRINTF)
+#define PRINTFLIKE(f, a) __attribute__ ((format(printf, f, a)))
+#else
+#define PRINTFLIKE(f, a)
+#endif
+
+#ifdef HAVE_FUNC_ATTRIBUTE_NORETURN
+#define NORETURN __attribute__ ((noreturn))
+#else
+#define NORETURN
+#endif
+
+#ifdef HAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT
+#define WARNUNUSED __attribute__ ((warn_unused_result))
+#else
+#define WARNUNUSED
+#endif
+
+#define UNUSED(x) (void)(x)
+
+#ifdef __GNUC__
+#define UNUSED_FUNCTION(x) __attribute__((unused)) UNUSED_##x
+#else
+#define UNUSED_FUNCTION(x) UNUSED_##x
+#endif
+
+// --------------------------------------------------------------------------------------------------------------------
+// fix for alpine linux
+
+#if !defined(RUSAGE_THREAD) && defined(RUSAGE_CHILDREN)
+#define RUSAGE_THREAD RUSAGE_CHILDREN
+#endif
+
+// --------------------------------------------------------------------------------------------------------------------
+// HELPFUL MACROS
+
+#define ABS(x) (((x) < 0)? (-(x)) : (x))
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+#define SWAP(a, b) do { \
+    typeof(a) _tmp = b; \
+    b = a;              \
+    a = _tmp;           \
+} while(0)
+
+// --------------------------------------------------------------------------------------------------------------------
+// NETDATA CLOUD
+
+// BEWARE: this exists in alarm-notify.sh
+#define DEFAULT_CLOUD_BASE_URL "https://app.netdata.cloud"
+
+// --------------------------------------------------------------------------------------------------------------------
+// DBENGINE
+
+#define RRD_STORAGE_TIERS 5
+
+// --------------------------------------------------------------------------------------------------------------------
+// PIPES
+
+#define PIPE_READ 0
+#define PIPE_WRITE 1
+
+// --------------------------------------------------------------------------------------------------------------------
+// UUIDs
+
+#define GUID_LEN 36
+
+// --------------------------------------------------------------------------------------------------------------------
+// Macro-only includes
+
+#include "linked_lists/linked_lists.h"
+
+// --------------------------------------------------------------------------------------------------------------------
+
+// Taken from linux kernel
+#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
+
+// --------------------------------------------------------------------------------------------------------------------
+
+#if defined(OS_WINDOWS)
+#include <windows.h>
+#include <wctype.h>
+#include <wchar.h>
+#include <tchar.h>
+#include <guiddef.h>
+#include <bcrypt.h>  // For BCryptGenRandom
+#include <io.h>
+#include <fcntl.h>
+#include <process.h>
+#include <tlhelp32.h>
+#include <sys/cygwin.h>
+#include <winevt.h>
+#include <evntprov.h>
+#include <wbemidl.h>
+#include <sddl.h>
+// #include <winternl.h> // conflicts on STRING,
+#endif
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif //LIBNETDATA_COMMON_H

Some files were not shown because too many files changed in this diff