1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-27 17:18:33 +00:00

Make cstyle.pl(1) happy.

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@601 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Roman Bogorodskiy 2006-03-20 11:44:29 +00:00
parent c2fb9f583a
commit 1fb0efb5f1

View File

@ -48,14 +48,14 @@ static int getsysctl(char *name, void *ptr, size_t len)
{
size_t nlen = len;
if (sysctlbyname(name, ptr, &nlen, NULL, 0) == -1) {
return -1;
return (-1);
}
if (nlen != len) {
return -1;
return (-1);
}
return 0;
return (0);
}
static kvm_t *kd = NULL;
@ -74,12 +74,12 @@ static int swapmode(int *retavail, int *retfree)
if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
O_RDONLY, "kvm_open")) == NULL) {
(void) fprintf(stderr, "Cannot read kvm.");
return -1;
return (-1);
}
}
if (kd == NULL) {
return -1;
return (-1);
}
*retavail = 0;
@ -97,14 +97,16 @@ static int swapmode(int *retavail, int *retfree)
n = (int) ((double) swapary[0].ksw_used * 100.0 /
(double) swapary[0].ksw_total);
return n;
return (n);
}
void prepare_update()
void
prepare_update()
{
}
void update_uptime()
void
update_uptime()
{
int mib[2] = { CTL_KERN, KERN_BOOTTIME };
struct timeval boottime;
@ -116,12 +118,13 @@ void update_uptime()
time(&now);
info.uptime = now - boottime.tv_sec;
} else {
(void)fprintf(stderr, "Could not get uptime\n");
fprintf(stderr, "Could not get uptime\n");
info.uptime = 0;
}
}
void update_meminfo()
void
update_meminfo()
{
int total_pages, inactive_pages, free_pages;
int swap_avail, swap_free;
@ -129,15 +132,15 @@ void update_meminfo()
int pagesize = getpagesize();
if (GETSYSCTL("vm.stats.vm.v_page_count", total_pages))
(void)fprintf(stderr,
fprintf(stderr,
"Cannot read sysctl \"vm.stats.vm.v_page_count\"");
if (GETSYSCTL("vm.stats.vm.v_free_count", free_pages))
(void)fprintf(stderr,
fprintf(stderr,
"Cannot read sysctl \"vm.stats.vm.v_free_count\"");
if (GETSYSCTL("vm.stats.vm.v_inactive_count", inactive_pages))
(void)fprintf(stderr,
fprintf(stderr,
"Cannot read sysctl \"vm.stats.vm.v_inactive_count\"");
info.memmax = (total_pages * pagesize) >> 10;
@ -154,7 +157,8 @@ void update_meminfo()
}
}
void update_net_stats()
void
update_net_stats()
{
struct net_stat *ns;
double delta;
@ -213,7 +217,8 @@ void update_net_stats()
freeifaddrs(ifap);
}
void update_total_processes()
void
update_total_processes()
{
int n_processes;
static int kd_init = 1;
@ -222,7 +227,7 @@ void update_total_processes()
kd_init = 0;
if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
O_RDONLY, "kvm_open")) == NULL) {
(void)fprintf(stderr, "Cannot read kvm.");
fprintf(stderr, "Cannot read kvm.");
return;
}
}
@ -236,7 +241,8 @@ void update_total_processes()
info.procs = n_processes;
}
void update_running_processes()
void
update_running_processes()
{
static int kd_init = 1;
struct kinfo_proc *p;
@ -245,8 +251,7 @@ void update_running_processes()
if (kd_init) {
kd_init = 0;
if ((kd =
kvm_open("/dev/null", "/dev/null", "/dev/null",
if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
O_RDONLY, "kvm_open")) == NULL) {
(void) fprintf(stderr, "Cannot read kvm.");
}
@ -275,11 +280,13 @@ struct cpu_load_struct {
struct cpu_load_struct fresh = { {0, 0, 0, 0, 0} };
long cpu_used, oldtotal, oldused;
void get_cpu_count()
void
get_cpu_count()
{
/* int cpu_count = 0; */
/* XXX
/*
* XXX
* FreeBSD doesn't allow to get per CPU load stats
* on SMP machines. It's possible to get a CPU count,
* but as we fulfil only info.cpu_usage[0], it's better
@ -298,7 +305,8 @@ void get_cpu_count()
}
/* XXX: SMP support */
void update_cpu_usage()
void
update_cpu_usage()
{
long used, total;
long cp_time[CPUSTATES];
@ -324,7 +332,8 @@ void update_cpu_usage()
fresh.load[0] + fresh.load[1] + fresh.load[2] + fresh.load[3];
if ((total - oldtotal) != 0) {
info.cpu_usage[0] = ((double) (used - oldused)) / (double) (total - oldtotal);
info.cpu_usage[0] = ((double) (used - oldused)) /
(double) (total - oldtotal);
} else {
info.cpu_usage[0] = 0;
}
@ -333,12 +342,14 @@ void update_cpu_usage()
oldtotal = total;
}
double get_i2c_info(int *fd, int arg, char *devtype, char *type)
double
get_i2c_info(int *fd, int arg, char *devtype, char *type)
{
return 0;
return (0);
}
void update_load_average()
void
update_load_average()
{
double v[3];
getloadavg(v, 3);
@ -348,20 +359,22 @@ void update_load_average()
info.loadavg[2] = (float) v[2];
}
double get_acpi_temperature(int fd)
double
get_acpi_temperature(int fd)
{
int temp;
if (GETSYSCTL("hw.acpi.thermal.tz0.temperature", temp)) {
(void)fprintf(stderr,
fprintf(stderr,
"Cannot read sysctl \"hw.acpi.thermal.tz0.temperature\"\n");
return 0.0;
return (0.0);
}
return KELVTOC(temp);
return (KELVTOC(temp));
}
void get_battery_stuff(char *buf, unsigned int n, const char *bat)
void
get_battery_stuff(char *buf, unsigned int n, const char *bat)
{
int battime;
@ -380,15 +393,17 @@ int
open_i2c_sensor(const char *dev, const char *type, int n, int *div,
char *devtype)
{
return 0;
return (0);
}
int open_acpi_temperature(const char *name)
int
open_acpi_temperature(const char *name)
{
return 0;
return (0);
}
void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size)
void
get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size)
{
int state;
@ -396,66 +411,67 @@ void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size)
return;
if (GETSYSCTL("hw.acpi.acline", state)) {
(void)fprintf(stderr,
fprintf(stderr,
"Cannot read sysctl \"hw.acpi.acline\"\n");
return;
}
if (state)
strncpy(p_client_buffer, "Running on AC Power", client_buffer_size);
strncpy(p_client_buffer, "Running on AC Power",
client_buffer_size);
else
strncpy(p_client_buffer, "Running on battery", client_buffer_size);
strncpy(p_client_buffer, "Running on battery",
client_buffer_size);
return;
}
void get_acpi_fan(char *p_client_buffer, size_t client_buffer_size)
void
get_acpi_fan(char *p_client_buffer, size_t client_buffer_size)
{
if (!p_client_buffer || client_buffer_size <= 0)
return;
/* not implemented */
memset(p_client_buffer, 0, client_buffer_size);
return;
}
void get_adt746x_cpu(char *p_client_buffer, size_t client_buffer_size)
void
get_adt746x_cpu(char *p_client_buffer, size_t client_buffer_size)
{
if (!p_client_buffer || client_buffer_size <= 0)
return;
/* not implemented */
memset(p_client_buffer, 0, client_buffer_size);
return;
}
void get_adt746x_fan(char *p_client_buffer, size_t client_buffer_size)
void
get_adt746x_fan(char *p_client_buffer, size_t client_buffer_size)
{
if (!p_client_buffer || client_buffer_size <= 0)
return;
/* not implemented */
memset(p_client_buffer, 0, client_buffer_size);
return;
}
/* rdtsc() and get_freq_dynamic() copied from linux.c */
#if defined(__i386) || defined(__x86_64)
__inline__ unsigned long long int rdtsc()
__inline__ unsigned long long int
rdtsc()
{
unsigned long long int x;
__asm__ volatile(".byte 0x0f, 0x31":"=A" (x));
return x;
return (x);
}
#endif
/* return system frequency in MHz (use divisor=1) or GHz (use divisor=1000) */
void get_freq_dynamic(char * p_client_buffer, size_t client_buffer_size, char * p_format, int divisor)
void
get_freq_dynamic(char *p_client_buffer, size_t client_buffer_size,
char *p_format, int divisor)
{
#if defined(__i386) || defined(__x86_64)
struct timezone tz;
@ -479,43 +495,42 @@ void get_freq_dynamic(char * p_client_buffer, size_t client_buffer_size, char *
snprintf(p_client_buffer, client_buffer_size, p_format,
(float)((cycles[1] - cycles[0]) / microseconds) / divisor);
return;
#else
get_freq(p_client_buffer, client_buffer_size, p_format, divisor);
return;
#endif
}
/* return system frequency in MHz (use divisor=1) or GHz (use divisor=1000) */
void get_freq(char *p_client_buffer, size_t client_buffer_size, char *p_format, int divisor)
void
get_freq(char *p_client_buffer, size_t client_buffer_size,
char *p_format, int divisor)
{
int freq;
if (!p_client_buffer || client_buffer_size <= 0 || !p_format || divisor <= 0)
if (!p_client_buffer || client_buffer_size <= 0
|| !p_format || divisor <= 0)
return;
if (GETSYSCTL("dev.cpu.0.freq", freq) == 0)
{
snprintf(p_client_buffer, client_buffer_size, p_format, freq/divisor);
}
snprintf(p_client_buffer, client_buffer_size,
p_format, freq/divisor);
else
{
snprintf(p_client_buffer, client_buffer_size, p_format, (float)0);
snprintf(p_client_buffer, client_buffer_size, p_format, 0f);
}
return;
}
void update_top()
void
update_top()
{
proc_find_top(info.cpu, info.memu);
}
void update_wifi_stats()
void
update_wifi_stats()
{
/* XXX */
}
void update_diskio()
void
update_diskio()
{
int devs_count,
num_selected,
@ -545,7 +560,8 @@ void update_diskio()
di = dev_select[dn].position;
dev = &statinfo_cur.dinfo->devices[di];
diskio_current += dev->bytes[DEVSTAT_READ] + dev->bytes[DEVSTAT_WRITE];
diskio_CUrrent += dev->bytes[DEVSTAT_READ] +
dev->bytes[DEVSTAT_WRITE];
}
free(dev_select);
@ -553,14 +569,16 @@ void update_diskio()
/*
* Since we return (diskio_total_current - diskio_total_old), first
* frame will be way too high (it will be equal to diskio_total_current, i.e.
* all disk I/O since boot). That's why it is better to return 0 first time;
* frame will be way too high (it will be equal to
* diskio_total_current, i.e. all disk I/O since boot). That's why
* it is better to return 0 first time;
*/
if (diskio_setup == 0) {
diskio_setup = 1;
diskio_value = 0;
} else
diskio_value = (unsigned int)((diskio_current - diskio_prev)/1024);
diskio_value = (unsigned int)((diskio_current - diskio_prev)/
1024);
diskio_prev = diskio_current;
free(statinfo_cur.dinfo);
@ -570,29 +588,32 @@ void update_diskio()
* While topless is obviously better, top is also not bad.
*/
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)
return -1;
return (-1);
if (((struct process *)a)->amount < ((struct process *)b)->amount)
return 1;
return (1);
return 0;
return (0);
}
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)
return -1;
return (-1);
if (((struct process *)a)->totalmem < ((struct process *)b)->totalmem)
return 1;
return (1);
return 0;
return (0);
}
inline void proc_find_top(struct process **cpu, struct process **mem)
inline void
proc_find_top(struct process **cpu, struct process **mem)
{
static int kd_init = 1;
struct kinfo_proc *p;
@ -602,10 +623,9 @@ inline void proc_find_top(struct process **cpu, struct process **mem)
if (kd_init) {
kd_init = 0;
if ((kd =
kvm_open("/dev/null", "/dev/null", "/dev/null",
if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null",
O_RDONLY, "kvm_open")) == NULL) {
(void)fprintf(stderr, "Cannot read kvm.");
fprintf(stderr, "Cannot read kvm.");
}
}
@ -614,17 +634,21 @@ inline void proc_find_top(struct process **cpu, struct process **mem)
/* we get total pages count again to be sure it is up to date */
if (GETSYSCTL("vm.stats.vm.v_page_count", total_pages) != 0)
CRIT_ERR("Cannot read sysctl \"vm.stats.vm.v_page_count\"");
CRIT_ERR("Cannot read sysctl"
"\"vm.stats.vm.v_page_count\"");
p = kvm_getprocs(kd, KERN_PROC_PROC, 0, &n_processes);
processes = malloc(n_processes * sizeof (struct process));
for (i = 0; i < n_processes; i++) {
if (!((p[i].ki_flag & P_SYSTEM)) && p[i].ki_comm != NULL) {
if (!((p[i].ki_flag & P_SYSTEM)) &&
p[i].ki_comm != NULL) {
processes[j].pid = p[i].ki_pid;
processes[j].name = strdup(p[i].ki_comm);
processes[j].amount = 100.0 * p[i].ki_pctcpu / FSCALE;
processes[j].totalmem = (float)(p[i].ki_rssize / (float)total_pages) * 100.0;
processes[j].amount = 100.0 *
p[i].ki_pctcpu / FSCALE;
processes[j].totalmem = (float)(p[i].ki_rssize /
(float)total_pages) * 100.0;
j++;
}
}
@ -658,64 +682,61 @@ inline void proc_find_top(struct process **cpu, struct process **mem)
#if defined(FREEBSD_DEBUG)
printf("=====\nmem\n");
for (i = 0; i < 10; i++) {
printf("%d: %s(%d) %.2f\n", i, mem[i]->name, mem[i]->pid, mem[i]->totalmem);
printf("%d: %s(%d) %.2f\n", i, mem[i]->name,
mem[i]->pid, mem[i]->totalmem);
}
/* printf("=====\ncpu\n");
for (i = 0; i <= 10; i++) {
printf("%d: %s\n", i, cpu[i]->name);
}*/
#endif
free(processes);
} else
return;
}
}
#if defined(i386) || defined(__i386__)
#define APMDEV "/dev/apm"
#define APM_UNKNOWN 255
int apm_getinfo(int fd, apm_info_t aip)
int
apm_getinfo(int fd, apm_info_t aip)
{
if (ioctl(fd, APMIO_GETINFO, aip) == -1)
return -1;
return (-1);
return 0;
return (0);
}
char *get_apm_adapter()
char
*get_apm_adapter()
{
int fd;
struct apm_info info;
fd = open(APMDEV, O_RDONLY);
if (fd < 0)
return "ERR";
return ("ERR");
if (apm_getinfo(fd, &info) != 0) {
close(fd);
return "ERR";
return ("ERR");
}
close(fd);
switch (info.ai_acline) {
case 0:
return "off-line";
return ("off-line");
break;
case 1:
if (info.ai_batt_stat == 3)
return "charging";
return ("charging");
else
return "on-line";
return ("on-line");
break;
default:
return "unknown";
return ("unknown");
break;
}
}
char *get_apm_battery_life()
char
*get_apm_battery_life()
{
int fd;
u_int batt_life;
@ -724,17 +745,16 @@ char *get_apm_battery_life()
out = (char *)calloc(16, sizeof (char));
fd = open(APMDEV, O_RDONLY);
if (fd < 0) {
strncpy(out, "ERR", 16);
return out;
return (out);
}
if (apm_getinfo(fd, &info) != 0) {
close(fd);
strncpy(out, "ERR", 16);
return out;
return (out);
}
close(fd);
@ -742,16 +762,16 @@ char *get_apm_battery_life()
if (batt_life == APM_UNKNOWN)
strncpy(out, "unknown", 16);
else if (batt_life <= 100) {
snprintf(out, 20,"%d%%", batt_life);
return out;
}
else
snprintf(out, 16, "%d%%", batt_life);
return (out);
} else
strncpy(out, "ERR", 16);
return out;
return (out);
}
char *get_apm_battery_time()
char
*get_apm_battery_time()
{
int fd;
int batt_time;
@ -764,13 +784,13 @@ char *get_apm_battery_time()
fd = open(APMDEV, O_RDONLY);
if (fd < 0) {
strncpy(out, "ERR", 16);
return out;
return (out);
}
if (apm_getinfo(fd, &info) != 0) {
close(fd);
strncpy(out, "ERR", 16);
return out;
return (out);
}
close(fd);
@ -787,12 +807,13 @@ char *get_apm_battery_time()
snprintf(out, 16, "%2d:%02d:%02d", h, m, s);
}
return out;
return (out);
}
#endif
/* empty stub so conky links */
void free_all_processes(void)
void
free_all_processes(void)
{
}