1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-18 02:55:12 +00:00

fix for testing and debug on FreeBSD

(Probably not complete yet)
This commit is contained in:
Phil Sutter 2009-06-21 23:44:48 +02:00
parent 912ed67d03
commit 867a842b3f
4 changed files with 48 additions and 38 deletions

View File

@ -26,6 +26,7 @@
*/ */
#define _GNU_SOURCE #define _GNU_SOURCE
#include "config.h" #include "config.h"
#include "conky.h"
#include "algebra.h" #include "algebra.h"
#include "logging.h" #include "logging.h"
#include <ctype.h> #include <ctype.h>

View File

@ -5875,7 +5875,11 @@ static void generate_text_internal(char *p, int p_max_size,
&& (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) { && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
int bytes; int bytes;
size_t dummy1, dummy2; size_t dummy1, dummy2;
#ifdef __FreeBSD__
const char *ptr = buff_in;
#else
char *ptr = buff_in; char *ptr = buff_in;
#endif
char *outptr = p; char *outptr = p;
dummy1 = dummy2 = a; dummy1 = dummy2 = a;

View File

@ -62,11 +62,12 @@
#define FREEBSD_DEBUG #define FREEBSD_DEBUG
#endif #endif
inline void proc_find_top(struct process **cpu, struct process **mem); __attribute__((gnu_inline)) inline void
proc_find_top(struct process **cpu, struct process **mem);
static short cpu_setup = 0; static short cpu_setup = 0;
static int getsysctl(char *name, void *ptr, size_t len) static int getsysctl(const char *name, void *ptr, size_t len)
{ {
size_t nlen = len; size_t nlen = len;
@ -109,11 +110,11 @@ static int swapmode(unsigned long *retavail, unsigned long *retfree)
return n; return n;
} }
void prepare_update() void prepare_update(void)
{ {
} }
void update_uptime() void update_uptime(void)
{ {
int mib[2] = { CTL_KERN, KERN_BOOTTIME }; int mib[2] = { CTL_KERN, KERN_BOOTTIME };
struct timeval boottime; struct timeval boottime;
@ -145,7 +146,7 @@ int check_mount(char *s)
return 0; return 0;
} }
void update_meminfo() void update_meminfo(void)
{ {
u_int total_pages, inactive_pages, free_pages; u_int total_pages, inactive_pages, free_pages;
unsigned long swap_avail, swap_free; unsigned long swap_avail, swap_free;
@ -177,7 +178,7 @@ void update_meminfo()
} }
} }
void update_net_stats() void update_net_stats(void)
{ {
struct net_stat *ns; struct net_stat *ns;
double delta; double delta;
@ -250,7 +251,7 @@ void update_net_stats()
freeifaddrs(ifap); freeifaddrs(ifap);
} }
void update_total_processes() void update_total_processes(void)
{ {
int n_processes; int n_processes;
@ -259,7 +260,7 @@ void update_total_processes()
info.procs = n_processes; info.procs = n_processes;
} }
void update_running_processes() void update_running_processes(void)
{ {
struct kinfo_proc *p; struct kinfo_proc *p;
int n_processes; int n_processes;
@ -286,7 +287,7 @@ struct cpu_load_struct {
struct cpu_load_struct fresh = { {0, 0, 0, 0, 0} }; struct cpu_load_struct fresh = { {0, 0, 0, 0, 0} };
long cpu_used, oldtotal, oldused; long cpu_used, oldtotal, oldused;
void get_cpu_count() void get_cpu_count(void)
{ {
/* int cpu_count = 0; */ /* int cpu_count = 0; */
@ -308,11 +309,11 @@ void get_cpu_count()
} }
/* XXX: SMP support */ /* XXX: SMP support */
void update_cpu_usage() void update_cpu_usage(void)
{ {
long used, total; long used, total;
long cp_time[CPUSTATES]; long cp_time[CPUSTATES];
size_t len = sizeof(cp_time); size_t cp_len = sizeof(cp_time);
/* add check for !info.cpu_usage since that mem is freed on a SIGUSR1 */ /* add check for !info.cpu_usage since that mem is freed on a SIGUSR1 */
if ((cpu_setup == 0) || (!info.cpu_usage)) { if ((cpu_setup == 0) || (!info.cpu_usage)) {
@ -320,7 +321,7 @@ void update_cpu_usage()
cpu_setup = 1; cpu_setup = 1;
} }
if (sysctlbyname("kern.cp_time", &cp_time, &len, NULL, 0) < 0) { if (sysctlbyname("kern.cp_time", &cp_time, &cp_len, NULL, 0) < 0) {
fprintf(stderr, "Cannot get kern.cp_time"); fprintf(stderr, "Cannot get kern.cp_time");
} }
@ -344,7 +345,7 @@ void update_cpu_usage()
oldtotal = total; oldtotal = total;
} }
void update_load_average() void update_load_average(void)
{ {
double v[3]; double v[3];
@ -358,6 +359,7 @@ void update_load_average()
double get_acpi_temperature(int fd) double get_acpi_temperature(int fd)
{ {
int temp; int temp;
(void)fd;
if (GETSYSCTL("hw.acpi.thermal.tz0.temperature", temp)) { if (GETSYSCTL("hw.acpi.thermal.tz0.temperature", temp)) {
fprintf(stderr, fprintf(stderr,
@ -386,6 +388,7 @@ static void get_battery_stats(int *battime, int *batcapacity, int *batstate, int
void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item) void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
{ {
int battime, batcapacity, batstate, ac; int battime, batcapacity, batstate, ac;
(void)bat;
get_battery_stats(&battime, &batcapacity, &batstate, &ac); get_battery_stats(&battime, &batcapacity, &batstate, &ac);
@ -466,6 +469,7 @@ int get_battery_perct_bar(const char *bar)
int open_acpi_temperature(const char *name) int open_acpi_temperature(const char *name)
{ {
(void)name;
/* Not applicable for FreeBSD. */ /* Not applicable for FreeBSD. */
return 0; return 0;
} }
@ -517,7 +521,7 @@ void get_adt746x_fan(char *p_client_buffer, size_t client_buffer_size)
/* rdtsc() and get_freq_dynamic() copied from linux.c */ /* rdtsc() and get_freq_dynamic() copied from linux.c */
#if defined(__i386) || defined(__x86_64) #if defined(__i386) || defined(__x86_64)
__inline__ unsigned long long int rdtsc() __attribute__((gnu_inline)) inline unsigned long long int rdtsc(void)
{ {
unsigned long long int x; unsigned long long int x;
@ -587,13 +591,13 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, const char *p_fo
return 1; return 1;
} }
void update_top() void update_top(void)
{ {
proc_find_top(info.cpu, info.memu); proc_find_top(info.cpu, info.memu);
} }
#if 0 #if 0
void update_wifi_stats() void update_wifi_stats(void)
{ {
struct ifreq ifr; /* interface stats */ struct ifreq ifr; /* interface stats */
struct wi_req wireq; struct wi_req wireq;
@ -647,7 +651,7 @@ cleanup:
} }
#endif #endif
void update_diskio() void update_diskio(void)
{ {
int devs_count, num_selected, num_selections, dn; int devs_count, num_selected, num_selections, dn;
struct device_selection *dev_select = NULL; struct device_selection *dev_select = NULL;
@ -703,9 +707,9 @@ void update_diskio()
int comparecpu(const void *a, const void *b) int comparecpu(const void *a, const void *b)
{ {
if (((struct process *)a)->amount > ((struct process *)b)->amount) { if (((const struct process *)a)->amount > ((const struct process *)b)->amount) {
return -1; return -1;
} else if (((struct process *)a)->amount < ((struct process *)b)->amount) { } else if (((const struct process *)a)->amount < ((const struct process *)b)->amount) {
return 1; return 1;
} else { } else {
return 0; return 0;
@ -714,16 +718,17 @@ int comparecpu(const void *a, const void *b)
int comparemem(const void *a, const void *b) int comparemem(const void *a, const void *b)
{ {
if (((struct process *)a)->totalmem > ((struct process *)b)->totalmem) { if (((const struct process *)a)->totalmem > ((const struct process *)b)->totalmem) {
return -1; return -1;
} else if (((struct process *)a)->totalmem < ((struct process *)b)->totalmem) { } else if (((const struct process *)a)->totalmem < ((const struct process *)b)->totalmem) {
return 1; return 1;
} else { } else {
return 0; return 0;
} }
} }
inline void proc_find_top(struct process **cpu, struct process **mem) __attribute__((gnu_inline)) inline void
proc_find_top(struct process **cpu, struct process **mem)
{ {
struct kinfo_proc *p; struct kinfo_proc *p;
int n_processes; int n_processes;
@ -820,10 +825,10 @@ int apm_getinfo(int fd, apm_info_t aip)
return 0; return 0;
} }
char *get_apm_adapter() char *get_apm_adapter(void)
{ {
int fd; int fd;
struct apm_info info; struct apm_info a_info;
char *out; char *out;
out = (char *) calloc(16, sizeof(char)); out = (char *) calloc(16, sizeof(char));
@ -834,20 +839,20 @@ char *get_apm_adapter()
return out; return out;
} }
if (apm_getinfo(fd, &info) != 0) { if (apm_getinfo(fd, &a_info) != 0) {
close(fd); close(fd);
strncpy(out, "ERR", 16); strncpy(out, "ERR", 16);
return out; return out;
} }
close(fd); close(fd);
switch (info.ai_acline) { switch (a_info.ai_acline) {
case 0: case 0:
strncpy(out, "off-line", 16); strncpy(out, "off-line", 16);
return out; return out;
break; break;
case 1: case 1:
if (info.ai_batt_stat == 3) { if (a_info.ai_batt_stat == 3) {
strncpy(out, "charging", 16); strncpy(out, "charging", 16);
return out; return out;
} else { } else {
@ -862,11 +867,11 @@ char *get_apm_adapter()
} }
} }
char *get_apm_battery_life() char *get_apm_battery_life(void)
{ {
int fd; int fd;
u_int batt_life; u_int batt_life;
struct apm_info info; struct apm_info a_info;
char *out; char *out;
out = (char *) calloc(16, sizeof(char)); out = (char *) calloc(16, sizeof(char));
@ -877,14 +882,14 @@ char *get_apm_battery_life()
return out; return out;
} }
if (apm_getinfo(fd, &info) != 0) { if (apm_getinfo(fd, &a_info) != 0) {
close(fd); close(fd);
strncpy(out, "ERR", 16); strncpy(out, "ERR", 16);
return out; return out;
} }
close(fd); close(fd);
batt_life = info.ai_batt_life; batt_life = a_info.ai_batt_life;
if (batt_life == APM_UNKNOWN) { if (batt_life == APM_UNKNOWN) {
strncpy(out, "unknown", 16); strncpy(out, "unknown", 16);
} else if (batt_life <= 100) { } else if (batt_life <= 100) {
@ -897,12 +902,12 @@ char *get_apm_battery_life()
return out; return out;
} }
char *get_apm_battery_time() char *get_apm_battery_time(void)
{ {
int fd; int fd;
int batt_time; int batt_time;
int h, m, s; int h, m, s;
struct apm_info info; struct apm_info a_info;
char *out; char *out;
out = (char *) calloc(16, sizeof(char)); out = (char *) calloc(16, sizeof(char));
@ -913,14 +918,14 @@ char *get_apm_battery_time()
return out; return out;
} }
if (apm_getinfo(fd, &info) != 0) { if (apm_getinfo(fd, &a_info) != 0) {
close(fd); close(fd);
strncpy(out, "ERR", 16); strncpy(out, "ERR", 16);
return out; return out;
} }
close(fd); close(fd);
batt_time = info.ai_batt_time; batt_time = a_info.ai_batt_time;
if (batt_time == -1) { if (batt_time == -1) {
strncpy(out, "unknown", 16); strncpy(out, "unknown", 16);

View File

@ -37,13 +37,13 @@
#include <sys/stat.h> #include <sys/stat.h>
#ifndef HAVE_MEMRCHR #ifndef HAVE_MEMRCHR
static void *memrchr(const void *buffer, char c, size_t n) static const void *memrchr(const void *buffer, char c, size_t n)
{ {
const unsigned char *p = buffer; const unsigned char *p = buffer;
for (p += n; n; n--) { for (p += n; n; n--) {
if (*--p == c) { if (*--p == c) {
return (void *) p; return p;
} }
} }
return NULL; return NULL;
@ -223,7 +223,7 @@ static long rev_fcharfind(FILE *fp, char val, unsigned int step)
long buf_pos = -1; long buf_pos = -1;
long file_pos = orig_pos; long file_pos = orig_pos;
long buf_size = BUFSZ; long buf_size = BUFSZ;
char *cur_found; const char *cur_found;
while (count < step) { while (count < step) {
if (buf_pos <= 0) { if (buf_pos <= 0) {