@cryptotaxi247 / netdata-1 / commits / 8720c4ceb

Fix compilation warnings in FreeBSD (#12887)

Vladimir Kobal committed May 14, 2022 at 17:45 UTC 8720c4ceb32e6ee7708dad68bf006ba556bb469e
4 files changed +28 -8
collectors/apps.plugin/apps_plugin.c
+16 -5
@@ -118,6 +118,7 @@ typedef enum {
118 PROC_STATUS_END, //place holder for ending enum fields
119 } proc_state;
120
121 +#ifndef __FreeBSD__
122 static proc_state proc_state_count[PROC_STATUS_END];
123 static const char *proc_states[] = {
124 [PROC_STATUS_RUNNING] = "running",
@@ -126,6 +127,7 @@ static const char *proc_states[] = {
127 [PROC_STATUS_ZOMBIE] = "zombie",
128 [PROC_STATUS_STOPPED] = "stopped",
129 };
130 +#endif
131
132 // ----------------------------------------------------------------------------
133 // internal flags
@@ -1252,7 +1254,6 @@ void arl_callback_status_rssshmem(const char *name, uint32_t hash, const char *v
1254
1255 aptr->p->status_rssshmem = str2kernel_uint_t(procfile_lineword(aptr->ff, aptr->line, 1));
1256 }
1255 -#endif // !__FreeBSD__
1257
1258 static void update_proc_state_count(char proc_state) {
1259 switch (proc_state) {
@@ -1275,6 +1276,7 @@ static void update_proc_state_count(char proc_state) {
1276 break;
1277 }
1278 }
1279 +#endif // !__FreeBSD__
1280
1281 static inline int read_proc_pid_status(struct pid_stat *p, void *ptr) {
1282 p->status_vmsize = 0;
@@ -1495,7 +1497,9 @@ static inline int read_proc_pid_stat(struct pid_stat *p, void *ptr) {
1497 p->cstime = 0;
1498 p->cgtime = 0;
1499 }
1500 +#ifndef __FreeBSD__
1501 update_proc_state_count(p->state);
1502 +#endif
1503 return 1;
1504
1505 cleanup:
@@ -1640,7 +1644,7 @@ cleanup:
1644 }
1645 #else
1646 static inline int read_global_time() {
1643 - static kernel_uint_t utime_raw = 0, stime_raw = 0, gtime_raw = 0, ntime_raw = 0;
1647 + static kernel_uint_t utime_raw = 0, stime_raw = 0, ntime_raw = 0;
1648 static usec_t collected_usec = 0, last_collected_usec = 0;
1649 long cp_time[CPUSTATES];
1650
@@ -1958,6 +1962,8 @@ static inline int read_pid_file_descriptors(struct pid_stat *p, void *ptr) {
1962 static char *fdsbuf;
1963 char *bfdsbuf, *efdsbuf;
1964 char fdsname[FILENAME_MAX + 1];
1965 +#define SHM_FORMAT_LEN 31 // format: 21 + size: 10
1966 + char shm_name[FILENAME_MAX - SHM_FORMAT_LEN + 1];
1967
1968 // we make all pid fds negative, so that
1969 // we can detect unused file descriptors
@@ -1995,7 +2001,7 @@ static inline int read_pid_file_descriptors(struct pid_stat *p, void *ptr) {
2001 }
2002
2003 // get file descriptors array index
1998 - int fdid = fds->kf_fd;
2004 + size_t fdid = fds->kf_fd;
2005
2006 // check if the fds array is small
2007 if (unlikely(fdid >= p->fds_size)) {
@@ -2055,7 +2061,8 @@ static inline int read_pid_file_descriptors(struct pid_stat *p, void *ptr) {
2061 #endif
2062 break;
2063 case KF_TYPE_SHM:
2058 - sprintf(fdsname, "other: shm: %s size: %lu", fds->kf_path, fds->kf_un.kf_file.kf_file_size);
2064 + strncpyz(shm_name, fds->kf_path, FILENAME_MAX - SHM_FORMAT_LEN);
2065 + sprintf(fdsname, "other: shm: %s size: %lu", shm_name, fds->kf_un.kf_file.kf_file_size);
2066 break;
2067 case KF_TYPE_SEM:
2068 sprintf(fdsname, "other: sem: %u", fds->kf_un.kf_sem.kf_sem_value);
@@ -2575,9 +2582,10 @@ static inline int collect_data_for_pid(pid_t pid, void *ptr) {
2582 static int collect_data_for_all_processes(void) {
2583 struct pid_stat *p = NULL;
2584
2585 +#ifndef __FreeBSD__
2586 // clear process state counter
2587 memset(proc_state_count, 0, sizeof proc_state_count);
2580 -#ifdef __FreeBSD__
2588 +#else
2589 int i, procnum;
2590
2591 static size_t procbase_size = 0;
@@ -3849,6 +3857,8 @@ static void send_charts_updates_to_netdata(struct target *root, const char *type
3857 }
3858 }
3859
3860 +
3861 +#ifndef __FreeBSD__
3862 static void send_proc_states_count(usec_t dt)
3863 {
3864 static bool chart_added = false;
@@ -3872,6 +3882,7 @@ static void send_proc_states_count(usec_t dt)
3882 }
3883 send_END();
3884 }
3885 +#endif
3886
3887 // ----------------------------------------------------------------------------
3888 // parse command line arguments
collectors/freebsd.plugin/freebsd_ipfw.c
+1 -1
@@ -233,7 +233,7 @@ int do_ipfw(int update_every, usec_t dt) {
233 break;
234
235 if (likely(do_static)) {
236 - sprintf(rule_num_str, "%d_%d", rule->rulenum, rule->id);
236 + sprintf(rule_num_str, "%"PRIu32"_%"PRIu32"", (uint32_t)rule->rulenum, (uint32_t)rule->id);
237
238 rd_packets = rrddim_find_active(st_packets, rule_num_str);
239 if (unlikely(!rd_packets))
collectors/freebsd.plugin/freebsd_sysctl.c
+8 -2
@@ -972,8 +972,14 @@ int do_vm_swap_info(int update_every, usec_t dt) {
972
973 int do_system_ram(int update_every, usec_t dt) {
974 (void)dt;
975 - static int mib_active_count[4] = {0, 0, 0, 0}, mib_inactive_count[4] = {0, 0, 0, 0}, mib_wire_count[4] = {0, 0, 0, 0},
976 - mib_cache_count[4] = {0, 0, 0, 0}, mib_vfs_bufspace[2] = {0, 0}, mib_free_count[4] = {0, 0, 0, 0};
975 + static int mib_active_count[4] = {0, 0, 0, 0},
976 + mib_inactive_count[4] = {0, 0, 0, 0},
977 + mib_wire_count[4] = {0, 0, 0, 0},
978 +#if __FreeBSD_version < 1200016
979 + mib_cache_count[4] = {0, 0, 0, 0},
980 +#endif
981 + mib_vfs_bufspace[2] = {0, 0},
982 + mib_free_count[4] = {0, 0, 0, 0};
983 vmmeter_t vmmeter_data;
984 size_t vfs_bufspace_count;
985
libnetdata/libnetdata.c
+3
@@ -982,6 +982,9 @@ static inline int madvise_mergeable(void *mem, size_t len) {
982 if (ret != 0 && logger-- > 0) error("madvise(MADV_MERGEABLE) failed.");
983 return ret;
984 #else
985 + UNUSED(mem);
986 + UNUSED(len);
987 +
988 return 0;
989 #endif
990 }