Browse Source

Fix compilation warnings on macOS (#12082)

Vladimir Kobal 3 years ago
parent
commit
d8b7b6a25f

+ 1 - 1
aclk/https_client.c

@@ -587,7 +587,7 @@ void https_req_response_init(https_req_response_t *res) {
     res->payload_size = 0;
 }
 
-static inline char *min_non_null(char *a, char *b) {
+static inline char *UNUSED_FUNCTION(min_non_null)(char *a, char *b) {
     if (!a)
         return b;
     if (!b)

+ 8 - 5
collectors/macos.plugin/macos_fw.c

@@ -35,7 +35,7 @@ int do_macos_iokit(int update_every, usec_t dt) {
 
     RRDSET *st;
 
-    mach_port_t         master_port;
+    mach_port_t         main_port;
     io_registry_entry_t drive, drive_media;
     io_iterator_t       drive_list;
     CFDictionaryRef     properties, statistics;
@@ -73,19 +73,22 @@ int do_macos_iokit(int update_every, usec_t dt) {
     // NEEDED BY: do_space, do_inodes
     struct statfs *mntbuf;
     int mntsize, i;
-    char mntonname[MNAMELEN + 1];
     char title[4096 + 1];
 
     // NEEDED BY: do_bandwidth
     struct ifaddrs *ifa, *ifap;
 
+#if !__is_identifier(IOMainPort) /* macOS >= 12.0 */
+#define IOMainPort IOMasterPort
+#endif
+
     /* Get ports and services for drive statistics. */
-    if (unlikely(IOMasterPort(bootstrap_port, &master_port))) {
+    if (unlikely(IOMainPort(bootstrap_port, &main_port))) {
         error("MACOS: IOMasterPort() failed");
         do_io = 0;
         error("DISABLED: system.io");
     /* Get the list of all drive objects. */
-    } else if (unlikely(IOServiceGetMatchingServices(master_port, IOServiceMatching("IOBlockStorageDriver"), &drive_list))) {
+    } else if (unlikely(IOServiceGetMatchingServices(main_port, IOServiceMatching("IOBlockStorageDriver"), &drive_list))) {
         error("MACOS: IOServiceGetMatchingServices() failed");
         do_io = 0;
         error("DISABLED: system.io");
@@ -115,7 +118,7 @@ int do_macos_iokit(int update_every, usec_t dt) {
             CFRelease(properties);
             IOObjectRelease(drive_media);
 
-            if(unlikely(!diskstat.name || !*diskstat.name)) {
+            if(unlikely(!*diskstat.name)) {
                 IOObjectRelease(drive);
                 continue;
             }

+ 2 - 5
collectors/macos.plugin/macos_sysctl.c

@@ -70,11 +70,9 @@ int do_macos_sysctl(int update_every, usec_t dt) {
         do_uptime               = config_get_boolean("plugin:macos:sysctl", "system uptime", 1);
     }
 
-    RRDSET *st;
+    RRDSET *st = NULL;
 
-    int system_pagesize = getpagesize(); // wouldn't it be better to get value directly from hw.pagesize?
-    int i, n;
-    int common_error = 0;
+    int i;
     size_t size;
 
     // NEEDED BY: do_loadavg
@@ -96,7 +94,6 @@ int do_macos_sysctl(int update_every, usec_t dt) {
 
     // NEEDED BY: do_tcp...
     struct tcpstat tcpstat;
-    uint64_t tcps_states[TCP_NSTATES];
 
     // NEEDED BY: do_udp...
     struct udpstat udpstat;

+ 7 - 9
daemon/daemon.c

@@ -102,7 +102,11 @@ int become_user(const char *username, int pid_fd) {
     gid_t *supplementary_groups = NULL;
     if(ngroups > 0) {
         supplementary_groups = mallocz(sizeof(gid_t) * ngroups);
+#ifdef __APPLE__
+        if(getgrouplist(username, gid, (int *)supplementary_groups, &ngroups) == -1) {
+#else
         if(getgrouplist(username, gid, supplementary_groups, &ngroups) == -1) {
+#endif /* __APPLE__ */
             if(am_i_root)
                 error("Cannot get supplementary groups of user '%s'.", username);
 
@@ -339,13 +343,7 @@ static void sched_getscheduler_report(void) {
         }
     }
 }
-#else // !HAVE_SCHED_GETSCHEDULER
-static void sched_getscheduler_report(void) {
-#ifdef HAVE_GETPRIORITY
-    info("Running with priority %d", getpriority(PRIO_PROCESS, 0));
-#endif // HAVE_GETPRIORITY
-}
-#endif // !HAVE_SCHED_GETSCHEDULER
+#endif /* HAVE_SCHED_GETSCHEDULER */
 
 #ifdef HAVE_SCHED_SETSCHEDULER
 
@@ -418,11 +416,11 @@ fallback:
 report:
     sched_getscheduler_report();
 }
-#else // !HAVE_SCHED_SETSCHEDULER
+#else /* HAVE_SCHED_SETSCHEDULER */
 static void sched_setscheduler_set(void) {
     process_nice_level();
 }
-#endif // !HAVE_SCHED_SETSCHEDULER
+#endif /* HAVE_SCHED_SETSCHEDULER */
 
 int become_daemon(int dont_fork, const char *user)
 {

+ 1 - 1
database/engine/journalfile.c

@@ -428,7 +428,7 @@ static uint64_t iterate_transactions(struct rrdengine_instance *ctx, struct rrde
         iov = uv_buf_init(buf, size_bytes);
         ret = uv_fs_read(NULL, &req, file, &iov, 1, pos, NULL);
         if (ret < 0) {
-            error("uv_fs_read: pos=%lu, %s", pos, uv_strerror(ret));
+            error("uv_fs_read: pos=%"PRIu64", %s", pos, uv_strerror(ret));
             uv_fs_req_cleanup(&req);
             goto skip_file;
         }

+ 8 - 1
database/rrdset.c

@@ -1475,7 +1475,14 @@ void rrdset_done(RRDSET *st) {
     // check if we will re-write the entire page
     if(unlikely(st->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE &&
                 dt_usec(&st->last_collected_time, &st->last_updated) > (RRDENG_BLOCK_SIZE / sizeof(storage_number)) * update_every_ut)) {
-        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);
+        info(
+            "%s: too old data (last updated at %" PRId64 ".%" PRId64 ", last collected at %" PRId64 ".%" PRId64 "). "
+            "Resetting it. Will not store the next entry.",
+            st->name,
+            (int64_t)st->last_updated.tv_sec,
+            (int64_t)st->last_updated.tv_usec,
+            (int64_t)st->last_collected_time.tv_sec,
+            (int64_t)st->last_collected_time.tv_usec);
         rrdset_reset(st);
         rrdset_init_last_updated_time(st);
 

+ 7 - 0
libnetdata/libnetdata.h

@@ -304,6 +304,13 @@ extern char *find_and_replace(const char *src, const char *find, const char *rep
 /* misc. */
 
 #define UNUSED(x) (void)(x)
+
+#ifdef __GNUC__
+#define UNUSED_FUNCTION(x) __attribute__((unused)) UNUSED_##x
+#else
+#define UNUSED_FUNCTION(x) UNUSED_##x
+#endif
+
 #define error_report(x, args...) do { errno = 0; error(x, ##args); } while(0)
 
 // Taken from linux kernel

+ 1 - 0
libnetdata/threads/threads.c

@@ -147,6 +147,7 @@ void uv_thread_set_name_np(uv_thread_t ut, const char* name) {
     pthread_set_name_np(ut, threadname);
 #elif defined(__APPLE__)
     // Apple can only set its own name
+    UNUSED(ut);
 #else
     ret = pthread_setname_np(ut, threadname);
 #endif

+ 2 - 2
web/api/queries/query.c

@@ -347,11 +347,11 @@ static void rrdr_disable_not_selected_dimensions(RRDR *r, RRDR_OPTIONS options,
 // ----------------------------------------------------------------------------
 // helpers to find our way in RRDR
 
-static inline RRDR_VALUE_FLAGS *rrdr_line_options(RRDR *r, long rrdr_line) {
+static inline RRDR_VALUE_FLAGS *UNUSED_FUNCTION(rrdr_line_options)(RRDR *r, long rrdr_line) {
     return &r->o[ rrdr_line * r->d ];
 }
 
-static inline calculated_number *rrdr_line_values(RRDR *r, long rrdr_line) {
+static inline calculated_number *UNUSED_FUNCTION(rrdr_line_values)(RRDR *r, long rrdr_line) {
     return &r->v[ rrdr_line * r->d ];
 }
 

+ 3 - 3
web/server/web_client.c

@@ -439,7 +439,7 @@ int mysendfile(struct web_client *w, char *filename) {
     sock_setnonblock(w->ifd);
 
     w->response.data->contenttype = contenttype_for_filename(webfilename);
-    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);
+    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);
 
     w->mode = WEB_CLIENT_MODE_FILECOPY;
     web_client_enable_wait_receive(w);
@@ -582,14 +582,14 @@ static inline int check_host_and_call(RRDHOST *host, struct web_client *w, char
     return func(host, w, url);
 }
 
-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 *)) {
+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 *)) {
     if(!web_client_can_access_dashboard(w))
         return web_client_permission_denied(w);
 
     return check_host_and_call(host, w, url, func);
 }
 
-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 *)) {
+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 *)) {
     if(!web_client_can_access_mgmt(w))
         return web_client_permission_denied(w);