@cryptotaxi247 / netdata-1 / commits / 522d37ed9

Some fixes for macOS < 11 (#20145)

Sergey Fedorov committed Apr 26, 2025 at 07:15 UTC 522d37ed924c2113b729a507f400c71e948fb656
10 files changed +65 -4
src/collectors/apps.plugin/apps_os_macos.c
+8
@@ -136,6 +136,7 @@ bool apps_os_get_pid_cmdline_macos(struct pid_stat *p, char *cmdline, size_t max
136 return true;
137 }
138
139 +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 110000
140 bool apps_os_read_pid_io_macos(struct pid_stat *p, void *ptr) {
141 struct pid_info *pi = ptr;
142
@@ -146,6 +147,11 @@ bool apps_os_read_pid_io_macos(struct pid_stat *p, void *ptr) {
147
148 return true;
149 }
150 +#else
151 +bool apps_os_read_pid_io_macos(struct pid_stat *p __maybe_unused, void *ptr __maybe_unused) {
152 + return false;
153 +}
154 +#endif
155
156 bool apps_os_read_pid_limits_macos(struct pid_stat *p __maybe_unused, void *ptr __maybe_unused) {
157 return false;
@@ -319,11 +325,13 @@ bool apps_os_collect_all_pids_macos(void) {
325 continue;
326 }
327
328 +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 110000
329 st = proc_pid_rusage(pid, RUSAGE_INFO_V4, (rusage_info_t *)&pi.rusageinfo);
330 if (st < 0) {
331 netdata_log_error("Failed to get resource usage info for PID %d", pid);
332 continue;
333 }
334 +#endif
335
336 incrementally_collect_data_for_pid(pid, &pi);
337 }
src/collectors/apps.plugin/apps_plugin.h
+3
@@ -47,12 +47,15 @@
47 #include <sys/proc_info.h>
48 #include <sys/sysctl.h>
49 #include <mach/mach_time.h> // For mach_timebase_info_data_t and mach_timebase_info
50 +#include <AvailabilityMacros.h>
51
52 struct pid_info {
53 struct kinfo_proc proc;
54 struct proc_taskinfo taskinfo;
55 struct proc_bsdinfo bsdinfo;
56 +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 110000
57 struct rusage_info_v4 rusageinfo;
58 +#endif
59 };
60
61 #define OS_INIT_PID 1
src/collectors/timex.plugin/plugin_timex.c
+8
@@ -2,6 +2,12 @@
2
3 #include "database/rrd.h"
4
5 +#ifdef OS_MACOS
6 +#include <AvailabilityMacros.h>
7 +#endif
8 +
9 +#if !defined(OS_MACOS) || (MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)
10 +
11 #define PLUGIN_TIMEX_NAME "timex.plugin"
12
13 #define CONFIG_SECTION_TIMEX "plugin:timex"
@@ -182,3 +188,5 @@ void *timex_main(void *ptr)
188 exit:
189 return NULL;
190 }
191 +
192 +#endif // !defined(OS_MACOS) || (MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)
src/daemon/static_threads_macos.c
+8 -1
@@ -2,10 +2,16 @@
2
3 #include "common.h"
4
5 +#include <AvailabilityMacros.h>
6 +
7 void *macos_main(void *ptr);
6 -void *timex_main(void *ptr);
8 +
9 +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
10 + void *timex_main(void *ptr);
11 +#endif
12
13 static const struct netdata_static_thread static_threads_macos[] = {
14 +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
15 {
16 .name = "P[timex]",
17 .config_section = CONFIG_SECTION_PLUGINS,
@@ -15,6 +21,7 @@ static const struct netdata_static_thread static_threads_macos[] = {
21 .init_routine = NULL,
22 .start_routine = timex_main
23 },
24 +#endif
25 {
26 .name = "P[macos]",
27 .config_section = CONFIG_SECTION_PLUGINS,
src/database/rrddim.h
+7
@@ -11,6 +11,13 @@ typedef struct rrddim_acquired RRDDIM_ACQUIRED;
11 typedef struct ml_dimension rrd_ml_dimension_t;
12 typedef struct rrdmetric_acquired RRDMETRIC_ACQUIRED;
13
14 +// gcc with libstdc++ may require this,
15 +// but with libc++ it does not work correctly.
16 +#if defined(__cplusplus) && !defined(_LIBCPP_VERSION)
17 +#include <cmath>
18 +using std::isnan;
19 +#endif
20 +
21 #include "rrdset.h"
22
23 // options are permanent configuration options (no atomics to alter/access them)
src/libnetdata/buffer/buffer.h
+8
@@ -10,6 +10,14 @@
10
11 #define BUFFER_JSON_MAX_DEPTH 32 // max is 255
12
13 +// gcc with libstdc++ may require this,
14 +// but with libc++ it does not work correctly.
15 +#if defined(__cplusplus) && !defined(_LIBCPP_VERSION)
16 +#include <cmath>
17 +using std::isinf;
18 +using std::isnan;
19 +#endif
20 +
21 extern const char hex_digits[16];
22 extern const char hex_digits_lower[16];
23 extern const char base64_digits[64];
src/libnetdata/os/adjtimex.c
+6 -1
@@ -2,8 +2,13 @@
2
3 #include "../libnetdata.h"
4
5 +#ifdef OS_MACOS
6 +#include <AvailabilityMacros.h>
7 +#endif
8 +
9 int os_adjtimex(struct timex *buf __maybe_unused) {
6 -#if defined(OS_MACOS) || defined(OS_FREEBSD)
10 +#if (defined(OS_MACOS) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)) || \
11 + defined(OS_FREEBSD)
12 return ntp_adjtime(buf);
13 #endif
14
src/libnetdata/os/adjtimex.h
+6 -1
@@ -3,7 +3,12 @@
3 #ifndef NETDATA_ADJTIMEX_H
4 #define NETDATA_ADJTIMEX_H
5
6 -#if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_MACOS)
6 +#ifdef OS_MACOS
7 +#include <AvailabilityMacros.h>
8 +#endif
9 +
10 +#if defined(OS_LINUX) || defined(OS_FREEBSD) || \
11 + (defined(OS_MACOS) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 101300))
12 #include <sys/timex.h>
13 #endif
14
src/libnetdata/os/uuid_generate.c
+3 -1
@@ -24,7 +24,9 @@ void os_uuid_generate_time(void *out) {
24
25 #else
26
27 -#if !defined(OS_MACOS)
27 +#if defined(OS_MACOS)
28 +#include <uuid/uuid.h>
29 +#else
30 #include <uuid.h>
31 #endif
32
src/ml/ml_kmeans.cc
+8
@@ -4,6 +4,14 @@
4 #include "libnetdata/libnetdata.h"
5 #include <dlib/clustering.h>
6
7 +// gcc with libstdc++ may require this,
8 +// but with libc++ it does not work correctly.
9 +#if !defined(_LIBCPP_VERSION)
10 +#include <cmath>
11 +using std::isinf;
12 +using std::isnan;
13 +#endif
14 +
15 void
16 ml_kmeans_init(ml_kmeans_t *kmeans)
17 {