@cryptotaxi247 / netdata-1 / commits / d8b7b6a25

Fix compilation warnings on macOS (#12082)

Vladimir Kobal committed Feb 21, 2022 at 12:23 UTC d8b7b6a25f7fc0ec4d79a7f8a72c779e3bf4afd7
10 files changed +40 -27
aclk/https_client.c
+1 -1
@@ -587,7 +587,7 @@ void https_req_response_init(https_req_response_t *res) {
587 res->payload_size = 0;
588 }
589
590 -static inline char *min_non_null(char *a, char *b) {
590 +static inline char *UNUSED_FUNCTION(min_non_null)(char *a, char *b) {
591 if (!a)
592 return b;
593 if (!b)
collectors/macos.plugin/macos_fw.c
+8 -5
@@ -35,7 +35,7 @@ int do_macos_iokit(int update_every, usec_t dt) {
35
36 RRDSET *st;
37
38 - mach_port_t master_port;
38 + mach_port_t main_port;
39 io_registry_entry_t drive, drive_media;
40 io_iterator_t drive_list;
41 CFDictionaryRef properties, statistics;
@@ -73,19 +73,22 @@ int do_macos_iokit(int update_every, usec_t dt) {
73 // NEEDED BY: do_space, do_inodes
74 struct statfs *mntbuf;
75 int mntsize, i;
76 - char mntonname[MNAMELEN + 1];
76 char title[4096 + 1];
77
78 // NEEDED BY: do_bandwidth
79 struct ifaddrs *ifa, *ifap;
80
81 +#if !__is_identifier(IOMainPort) /* macOS >= 12.0 */
82 +#define IOMainPort IOMasterPort
83 +#endif
84 +
85 /* Get ports and services for drive statistics. */
83 - if (unlikely(IOMasterPort(bootstrap_port, &master_port))) {
86 + if (unlikely(IOMainPort(bootstrap_port, &main_port))) {
87 error("MACOS: IOMasterPort() failed");
88 do_io = 0;
89 error("DISABLED: system.io");
90 /* Get the list of all drive objects. */
88 - } else if (unlikely(IOServiceGetMatchingServices(master_port, IOServiceMatching("IOBlockStorageDriver"), &drive_list))) {
91 + } else if (unlikely(IOServiceGetMatchingServices(main_port, IOServiceMatching("IOBlockStorageDriver"), &drive_list))) {
92 error("MACOS: IOServiceGetMatchingServices() failed");
93 do_io = 0;
94 error("DISABLED: system.io");
@@ -115,7 +118,7 @@ int do_macos_iokit(int update_every, usec_t dt) {
118 CFRelease(properties);
119 IOObjectRelease(drive_media);
120
118 - if(unlikely(!diskstat.name || !*diskstat.name)) {
121 + if(unlikely(!*diskstat.name)) {
122 IOObjectRelease(drive);
123 continue;
124 }
collectors/macos.plugin/macos_sysctl.c
+2 -5
@@ -70,11 +70,9 @@ int do_macos_sysctl(int update_every, usec_t dt) {
70 do_uptime = config_get_boolean("plugin:macos:sysctl", "system uptime", 1);
71 }
72
73 - RRDSET *st;
73 + RRDSET *st = NULL;
74
75 - int system_pagesize = getpagesize(); // wouldn't it be better to get value directly from hw.pagesize?
76 - int i, n;
77 - int common_error = 0;
75 + int i;
76 size_t size;
77
78 // NEEDED BY: do_loadavg
@@ -96,7 +94,6 @@ int do_macos_sysctl(int update_every, usec_t dt) {
94
95 // NEEDED BY: do_tcp...
96 struct tcpstat tcpstat;
99 - uint64_t tcps_states[TCP_NSTATES];
97
98 // NEEDED BY: do_udp...
99 struct udpstat udpstat;
daemon/daemon.c
+7 -9
@@ -102,7 +102,11 @@ int become_user(const char *username, int pid_fd) {
102 gid_t *supplementary_groups = NULL;
103 if(ngroups > 0) {
104 supplementary_groups = mallocz(sizeof(gid_t) * ngroups);
105 +#ifdef __APPLE__
106 + if(getgrouplist(username, gid, (int *)supplementary_groups, &ngroups) == -1) {
107 +#else
108 if(getgrouplist(username, gid, supplementary_groups, &ngroups) == -1) {
109 +#endif /* __APPLE__ */
110 if(am_i_root)
111 error("Cannot get supplementary groups of user '%s'.", username);
112
@@ -339,13 +343,7 @@ static void sched_getscheduler_report(void) {
343 }
344 }
345 }
342 -#else // !HAVE_SCHED_GETSCHEDULER
343 -static void sched_getscheduler_report(void) {
344 -#ifdef HAVE_GETPRIORITY
345 - info("Running with priority %d", getpriority(PRIO_PROCESS, 0));
346 -#endif // HAVE_GETPRIORITY
347 -}
348 -#endif // !HAVE_SCHED_GETSCHEDULER
346 +#endif /* HAVE_SCHED_GETSCHEDULER */
347
348 #ifdef HAVE_SCHED_SETSCHEDULER
349
@@ -418,11 +416,11 @@ fallback:
416 report:
417 sched_getscheduler_report();
418 }
421 -#else // !HAVE_SCHED_SETSCHEDULER
419 +#else /* HAVE_SCHED_SETSCHEDULER */
420 static void sched_setscheduler_set(void) {
421 process_nice_level();
422 }
425 -#endif // !HAVE_SCHED_SETSCHEDULER
423 +#endif /* HAVE_SCHED_SETSCHEDULER */
424
425 int become_daemon(int dont_fork, const char *user)
426 {
database/engine/journalfile.c
+1 -1
@@ -428,7 +428,7 @@ static uint64_t iterate_transactions(struct rrdengine_instance *ctx, struct rrde
428 iov = uv_buf_init(buf, size_bytes);
429 ret = uv_fs_read(NULL, &req, file, &iov, 1, pos, NULL);
430 if (ret < 0) {
431 - error("uv_fs_read: pos=%lu, %s", pos, uv_strerror(ret));
431 + error("uv_fs_read: pos=%"PRIu64", %s", pos, uv_strerror(ret));
432 uv_fs_req_cleanup(&req);
433 goto skip_file;
434 }
database/rrdset.c
+8 -1
@@ -1475,7 +1475,14 @@ void rrdset_done(RRDSET *st) {
1475 // check if we will re-write the entire page
1476 if(unlikely(st->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE &&
1477 dt_usec(&st->last_collected_time, &st->last_updated) > (RRDENG_BLOCK_SIZE / sizeof(storage_number)) * update_every_ut)) {
1478 - info("%s: too old data (last updated at %ld.%ld, last collected at %ld.%ld). Resetting it. Will not store the next entry.", st->name, st->last_updated.tv_sec, st->last_updated.tv_usec, st->last_collected_time.tv_sec, st->last_collected_time.tv_usec);
1478 + info(
1479 + "%s: too old data (last updated at %" PRId64 ".%" PRId64 ", last collected at %" PRId64 ".%" PRId64 "). "
1480 + "Resetting it. Will not store the next entry.",
1481 + st->name,
1482 + (int64_t)st->last_updated.tv_sec,
1483 + (int64_t)st->last_updated.tv_usec,
1484 + (int64_t)st->last_collected_time.tv_sec,
1485 + (int64_t)st->last_collected_time.tv_usec);
1486 rrdset_reset(st);
1487 rrdset_init_last_updated_time(st);
1488
libnetdata/libnetdata.h
+7
@@ -304,6 +304,13 @@ extern char *find_and_replace(const char *src, const char *find, const char *rep
304 /* misc. */
305
306 #define UNUSED(x) (void)(x)
307 +
308 +#ifdef __GNUC__
309 +#define UNUSED_FUNCTION(x) __attribute__((unused)) UNUSED_##x
310 +#else
311 +#define UNUSED_FUNCTION(x) UNUSED_##x
312 +#endif
313 +
314 #define error_report(x, args...) do { errno = 0; error(x, ##args); } while(0)
315
316 // Taken from linux kernel
libnetdata/threads/threads.c
+1
@@ -147,6 +147,7 @@ void uv_thread_set_name_np(uv_thread_t ut, const char* name) {
147 pthread_set_name_np(ut, threadname);
148 #elif defined(__APPLE__)
149 // Apple can only set its own name
150 + UNUSED(ut);
151 #else
152 ret = pthread_setname_np(ut, threadname);
153 #endif
web/api/queries/query.c
+2 -2
@@ -347,11 +347,11 @@ static void rrdr_disable_not_selected_dimensions(RRDR *r, RRDR_OPTIONS options,
347 // ----------------------------------------------------------------------------
348 // helpers to find our way in RRDR
349
350 -static inline RRDR_VALUE_FLAGS *rrdr_line_options(RRDR *r, long rrdr_line) {
350 +static inline RRDR_VALUE_FLAGS *UNUSED_FUNCTION(rrdr_line_options)(RRDR *r, long rrdr_line) {
351 return &r->o[ rrdr_line * r->d ];
352 }
353
354 -static inline calculated_number *rrdr_line_values(RRDR *r, long rrdr_line) {
354 +static inline calculated_number *UNUSED_FUNCTION(rrdr_line_values)(RRDR *r, long rrdr_line) {
355 return &r->v[ rrdr_line * r->d ];
356 }
357
web/server/web_client.c
+3 -3
@@ -439,7 +439,7 @@ int mysendfile(struct web_client *w, char *filename) {
439 sock_setnonblock(w->ifd);
440
441 w->response.data->contenttype = contenttype_for_filename(webfilename);
442 - debug(D_WEB_CLIENT_ACCESS, "%llu: Sending file '%s' (%ld bytes, ifd %d, ofd %d).", w->id, webfilename, statbuf.st_size, w->ifd, w->ofd);
442 + debug(D_WEB_CLIENT_ACCESS, "%llu: Sending file '%s' (%"PRId64" bytes, ifd %d, ofd %d).", w->id, webfilename, (int64_t)statbuf.st_size, w->ifd, w->ofd);
443
444 w->mode = WEB_CLIENT_MODE_FILECOPY;
445 web_client_enable_wait_receive(w);
@@ -582,14 +582,14 @@ static inline int check_host_and_call(RRDHOST *host, struct web_client *w, char
582 return func(host, w, url);
583 }
584
585 -static inline int check_host_and_dashboard_acl_and_call(RRDHOST *host, struct web_client *w, char *url, int (*func)(RRDHOST *, struct web_client *, char *)) {
585 +static inline int UNUSED_FUNCTION(check_host_and_dashboard_acl_and_call)(RRDHOST *host, struct web_client *w, char *url, int (*func)(RRDHOST *, struct web_client *, char *)) {
586 if(!web_client_can_access_dashboard(w))
587 return web_client_permission_denied(w);
588
589 return check_host_and_call(host, w, url, func);
590 }
591
592 -static inline int check_host_and_mgmt_acl_and_call(RRDHOST *host, struct web_client *w, char *url, int (*func)(RRDHOST *, struct web_client *, char *)) {
592 +static inline int UNUSED_FUNCTION(check_host_and_mgmt_acl_and_call)(RRDHOST *host, struct web_client *w, char *url, int (*func)(RRDHOST *, struct web_client *, char *)) {
593 if(!web_client_can_access_mgmt(w))
594 return web_client_permission_denied(w);
595