mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-15 17:47:09 +00:00
FreeBSD changes (#327)
* llabs() is included in FreeBSD since FreeBSD 5.0. Oldest supported FreeBSD version is 9.3 now. * stdio.h needs to be explicitly included here for FreeBSD. I can wrap it in #ifdefs if needed, but I don't think it can hurt other OSes. * addr config variable works fine on FreeBSD. * FreeBSD 5.x is really an ancient version and long unsupported, so I think this check for it can be dropped. * Fix and simplify code to get battery state and charge. * Add required include on FreeBSD. * Add needed include on FreeBSD. * Also populate basename to avoid printing (null) process names. Repored by fellow FreeBSD user Szabolcs Grof.
This commit is contained in:
parent
2e4839e601
commit
3a00680689
@ -26,6 +26,7 @@
|
||||
#include "c++wrap.hh"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* force use of POSIX strerror_r instead of non-portable GNU specific */
|
||||
#ifdef _GNU_SOURCE
|
||||
|
@ -728,13 +728,6 @@ int percent_print(char *buf, int size, unsigned value)
|
||||
return spaced_print(buf, size, "%u", pad_percents.get(*state), value);
|
||||
}
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
unsigned long long llabs(long long num) {
|
||||
if(num < 0) return -num;
|
||||
else return num;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* converts from bytes to human readable format (K, M, G, T)
|
||||
*
|
||||
* The algorithm always divides by 1024, as unit-conversion of byte
|
||||
|
@ -898,11 +898,12 @@ struct text_object *construct_text_object(char *s, const char *arg,
|
||||
return NULL;
|
||||
}
|
||||
} else
|
||||
#ifdef __linux__
|
||||
OBJ(addr, &update_net_stats)
|
||||
parse_net_stat_arg(obj, arg, free_at_crash);
|
||||
obj->callbacks.print = &print_addr;
|
||||
END OBJ(addrs, &update_net_stats)
|
||||
END
|
||||
#ifdef __linux__
|
||||
OBJ(addrs, &update_net_stats)
|
||||
parse_net_stat_arg(obj, arg, free_at_crash);
|
||||
obj->callbacks.print = &print_addrs;
|
||||
#ifdef BUILD_IPV6
|
||||
|
@ -295,11 +295,7 @@ int update_running_processes(void)
|
||||
std::lock_guard<std::mutex> guard(kvm_proc_mutex);
|
||||
p = kvm_getprocs(kd, KERN_PROC_ALL, 0, &n_processes);
|
||||
for (i = 0; i < n_processes; i++) {
|
||||
#if (__FreeBSD__ < 5) && !defined(__FreeBSD_kernel__)
|
||||
if (p[i].kp_proc.p_stat == SRUN) {
|
||||
#else
|
||||
if (p[i].ki_stat == SRUN) {
|
||||
#endif
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
@ -475,7 +471,7 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
|
||||
break;
|
||||
case BATTERY_STATUS:
|
||||
if (batstate == 1) // Discharging
|
||||
snprintf(buf, n, "remaining %d%%", batcapacity);
|
||||
snprintf(buf, n, "remaining (%d%%)", batcapacity);
|
||||
else
|
||||
snprintf(buf, n, batstate == 2 ? "charging (%d%%)" :
|
||||
(batstate == 7 ? "absent/on AC" : "charged (%d%%)"),
|
||||
@ -508,26 +504,10 @@ static int check_bat(const char *bat)
|
||||
|
||||
int get_battery_perct(const char *bat)
|
||||
{
|
||||
union acpi_battery_ioctl_arg battio;
|
||||
int batnum, acpifd;
|
||||
int designcap, lastfulcap, batperct;
|
||||
int batcapacity;
|
||||
|
||||
if ((battio.unit = batnum = check_bat(bat)) < 0)
|
||||
return 0;
|
||||
if ((acpifd = open("/dev/acpi", O_RDONLY)) < 0) {
|
||||
fprintf(stderr, "Can't open ACPI device\n");
|
||||
return 0;
|
||||
}
|
||||
if (ioctl(acpifd, ACPIIO_BATT_GET_BIF, &battio) == -1) {
|
||||
fprintf(stderr, "Unable to get info for battery unit %d\n", batnum);
|
||||
return 0;
|
||||
}
|
||||
close(acpifd);
|
||||
designcap = battio.bif.dcap;
|
||||
lastfulcap = battio.bif.lfcap;
|
||||
batperct = (designcap > 0 && lastfulcap > 0) ?
|
||||
(int) (((float) lastfulcap / designcap) * 100) : 0;
|
||||
return batperct > 100 ? 100 : batperct;
|
||||
get_battery_stats(NULL, &batcapacity, NULL, NULL);
|
||||
return batcapacity;
|
||||
}
|
||||
|
||||
double get_battery_perct_bar(struct text_object *obj)
|
||||
@ -729,6 +709,7 @@ void get_top_info(void)
|
||||
|
||||
proc->time_stamp = g_time;
|
||||
proc->name = strndup(p[i].ki_comm, text_buffer_size.get(*state));
|
||||
proc->basename = strndup(p[i].ki_comm, text_buffer_size.get(*state));
|
||||
proc->amount = 100.0 * p[i].ki_pctcpu / FSCALE;
|
||||
proc->vsize = p[i].ki_size;
|
||||
proc->rss = (p[i].ki_rssize * getpagesize());
|
||||
@ -745,11 +726,14 @@ void get_battery_short_status(char *buffer, unsigned int n, const char *bat)
|
||||
if (0 == strncmp("charging", buffer, 8)) {
|
||||
buffer[0] = 'C';
|
||||
memmove(buffer + 1, buffer + 8, n - 8);
|
||||
} else if (0 == strncmp("discharging", buffer, 11)) {
|
||||
} else if (0 == strncmp("remaining", buffer, 9)) {
|
||||
buffer[0] = 'D';
|
||||
memmove(buffer + 1, buffer + 11, n - 11);
|
||||
memmove(buffer + 1, buffer + 9, n - 9);
|
||||
} else if (0 == strncmp("charged", buffer, 7)) {
|
||||
buffer[0] = 'F';
|
||||
memmove(buffer + 1, buffer + 7, n - 7);
|
||||
} else if (0 == strncmp("absent/on AC", buffer, 12)) {
|
||||
buffer[0] = 'A';
|
||||
buffer[0] = 'N';
|
||||
memmove(buffer + 1, buffer + 12, n - 12);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/ucred.h>
|
||||
#include <strings.h>
|
||||
#include <fcntl.h>
|
||||
#include <kvm.h>
|
||||
#if (defined(i386) || defined(__i386__))
|
||||
|
@ -25,7 +25,9 @@
|
||||
#include <assert.h>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include <lua.hpp>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user