Skip to content

Commit 3a00680

Browse files
madpilot78brndnmtthws
authored andcommitted
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.
1 parent 2e4839e commit 3a00680

File tree

6 files changed

+18
-36
lines changed

6 files changed

+18
-36
lines changed

src/c++wrap.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "c++wrap.hh"
2727

2828
#include <unistd.h>
29+
#include <stdio.h>
2930

3031
/* force use of POSIX strerror_r instead of non-portable GNU specific */
3132
#ifdef _GNU_SOURCE

src/conky.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -728,13 +728,6 @@ int percent_print(char *buf, int size, unsigned value)
728728
return spaced_print(buf, size, "%u", pad_percents.get(*state), value);
729729
}
730730

731-
#if defined(__FreeBSD__)
732-
unsigned long long llabs(long long num) {
733-
if(num < 0) return -num;
734-
else return num;
735-
}
736-
#endif
737-
738731
/* converts from bytes to human readable format (K, M, G, T)
739732
*
740733
* The algorithm always divides by 1024, as unit-conversion of byte

src/core.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,11 +898,12 @@ struct text_object *construct_text_object(char *s, const char *arg,
898898
return NULL;
899899
}
900900
} else
901-
#ifdef __linux__
902901
OBJ(addr, &update_net_stats)
903902
parse_net_stat_arg(obj, arg, free_at_crash);
904903
obj->callbacks.print = &print_addr;
905-
END OBJ(addrs, &update_net_stats)
904+
END
905+
#ifdef __linux__
906+
OBJ(addrs, &update_net_stats)
906907
parse_net_stat_arg(obj, arg, free_at_crash);
907908
obj->callbacks.print = &print_addrs;
908909
#ifdef BUILD_IPV6

src/freebsd.cc

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,7 @@ int update_running_processes(void)
295295
std::lock_guard<std::mutex> guard(kvm_proc_mutex);
296296
p = kvm_getprocs(kd, KERN_PROC_ALL, 0, &n_processes);
297297
for (i = 0; i < n_processes; i++) {
298-
#if (__FreeBSD__ < 5) && !defined(__FreeBSD_kernel__)
299-
if (p[i].kp_proc.p_stat == SRUN) {
300-
#else
301298
if (p[i].ki_stat == SRUN) {
302-
#endif
303299
cnt++;
304300
}
305301
}
@@ -475,7 +471,7 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
475471
break;
476472
case BATTERY_STATUS:
477473
if (batstate == 1) // Discharging
478-
snprintf(buf, n, "remaining %d%%", batcapacity);
474+
snprintf(buf, n, "remaining (%d%%)", batcapacity);
479475
else
480476
snprintf(buf, n, batstate == 2 ? "charging (%d%%)" :
481477
(batstate == 7 ? "absent/on AC" : "charged (%d%%)"),
@@ -508,26 +504,10 @@ static int check_bat(const char *bat)
508504

509505
int get_battery_perct(const char *bat)
510506
{
511-
union acpi_battery_ioctl_arg battio;
512-
int batnum, acpifd;
513-
int designcap, lastfulcap, batperct;
507+
int batcapacity;
514508

515-
if ((battio.unit = batnum = check_bat(bat)) < 0)
516-
return 0;
517-
if ((acpifd = open("/dev/acpi", O_RDONLY)) < 0) {
518-
fprintf(stderr, "Can't open ACPI device\n");
519-
return 0;
520-
}
521-
if (ioctl(acpifd, ACPIIO_BATT_GET_BIF, &battio) == -1) {
522-
fprintf(stderr, "Unable to get info for battery unit %d\n", batnum);
523-
return 0;
524-
}
525-
close(acpifd);
526-
designcap = battio.bif.dcap;
527-
lastfulcap = battio.bif.lfcap;
528-
batperct = (designcap > 0 && lastfulcap > 0) ?
529-
(int) (((float) lastfulcap / designcap) * 100) : 0;
530-
return batperct > 100 ? 100 : batperct;
509+
get_battery_stats(NULL, &batcapacity, NULL, NULL);
510+
return batcapacity;
531511
}
532512

533513
double get_battery_perct_bar(struct text_object *obj)
@@ -729,6 +709,7 @@ void get_top_info(void)
729709

730710
proc->time_stamp = g_time;
731711
proc->name = strndup(p[i].ki_comm, text_buffer_size.get(*state));
712+
proc->basename = strndup(p[i].ki_comm, text_buffer_size.get(*state));
732713
proc->amount = 100.0 * p[i].ki_pctcpu / FSCALE;
733714
proc->vsize = p[i].ki_size;
734715
proc->rss = (p[i].ki_rssize * getpagesize());
@@ -745,11 +726,14 @@ void get_battery_short_status(char *buffer, unsigned int n, const char *bat)
745726
if (0 == strncmp("charging", buffer, 8)) {
746727
buffer[0] = 'C';
747728
memmove(buffer + 1, buffer + 8, n - 8);
748-
} else if (0 == strncmp("discharging", buffer, 11)) {
729+
} else if (0 == strncmp("remaining", buffer, 9)) {
749730
buffer[0] = 'D';
750-
memmove(buffer + 1, buffer + 11, n - 11);
731+
memmove(buffer + 1, buffer + 9, n - 9);
732+
} else if (0 == strncmp("charged", buffer, 7)) {
733+
buffer[0] = 'F';
734+
memmove(buffer + 1, buffer + 7, n - 7);
751735
} else if (0 == strncmp("absent/on AC", buffer, 12)) {
752-
buffer[0] = 'A';
736+
buffer[0] = 'N';
753737
memmove(buffer + 1, buffer + 12, n - 12);
754738
}
755739
}

src/freebsd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <sys/param.h>
88
#include <sys/mount.h>
99
#include <sys/ucred.h>
10+
#include <strings.h>
1011
#include <fcntl.h>
1112
#include <kvm.h>
1213
#if (defined(i386) || defined(__i386__))

src/luamm.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#include <assert.h>
2626
#include <memory>
2727
#include <mutex>
28+
#include <exception>
2829
#include <stdexcept>
30+
#include <string>
2931

3032
#include <lua.hpp>
3133

0 commit comments

Comments
 (0)